slightly refactor internal_announcement_signatures
authorjoe.miyamoto <joe.miyamoto@bitcoinbank.co.jp>
Mon, 13 Jul 2020 04:24:40 +0000 (13:24 +0900)
committerjoe.miyamoto <joe.miyamoto@bitcoinbank.co.jp>
Wed, 22 Jul 2020 01:34:47 +0000 (10:34 +0900)
For making debugging easy.
If the user gives a different node_secret for transport
layer (`PeerManager`) and for routing msg, internal_announcement_signatures
is the first place it causes an error.
By giving a detailed error message, user will be able to
fix the bug quickly.

lightning/src/ln/channelmanager.rs

index d668cdd59e0651a32b9d8a246fca0258d3e810fb..d591515c467ab34658fef44d4e97303f91c38a19 100644 (file)
@@ -2745,10 +2745,21 @@ impl<ChanSigner: ChannelKeys, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref>
 
                                let were_node_one = announcement.node_id_1 == our_node_id;
                                let msghash = hash_to_message!(&Sha256dHash::hash(&announcement.encode()[..])[..]);
-                               if self.secp_ctx.verify(&msghash, &msg.node_signature, if were_node_one { &announcement.node_id_2 } else { &announcement.node_id_1 }).is_err() ||
-                                               self.secp_ctx.verify(&msghash, &msg.bitcoin_signature, if were_node_one { &announcement.bitcoin_key_2 } else { &announcement.bitcoin_key_1 }).is_err() {
-                                       let chan_err: ChannelError = ChannelError::Close("Bad announcement_signatures node_signature".to_owned());
-                                       try_chan_entry!(self, Err(chan_err), channel_state, chan);
+                               {
+                                       let their_node_key = if were_node_one { &announcement.node_id_2 } else { &announcement.node_id_1 };
+                                       let their_bitcoin_key = if were_node_one { &announcement.bitcoin_key_2 } else { &announcement.bitcoin_key_1 };
+                                       match (self.secp_ctx.verify(&msghash, &msg.node_signature, their_node_key),
+                                                  self.secp_ctx.verify(&msghash, &msg.bitcoin_signature, their_bitcoin_key)) {
+                                               (Err(e), _) => {
+                                                       let chan_err: ChannelError = ChannelError::Close(format!("Bad announcement_signatures. Failed to verify node_signature: {:?}. Maybe using different node_secret for transport and routing msg? UnsignedChannelAnnouncement used for verification is {:?}. their_node_key is {:?}", e, &announcement, their_node_key));
+                                                       try_chan_entry!(self, Err(chan_err), channel_state, chan);
+                                               },
+                                               (_, Err(e)) => {
+                                                       let chan_err: ChannelError = ChannelError::Close(format!("Bad announcement_signatures. Failed to verify bitcoin_signature: {:?}. UnsignedChannelAnnouncement used for verification is {:?}. their_bitcoin_key is ({:?})", e, &announcement, their_bitcoin_key));
+                                                       try_chan_entry!(self, Err(chan_err), channel_state, chan);
+                                               },
+                                               _ => {}
+                                       }
                                }
 
                                let our_node_sig = self.secp_ctx.sign(&msghash, &self.our_network_key);