]> git.bitcoin.ninja Git - rust-lightning/commitdiff
Reject rumors of channels that are from one node back to itself
authorMatt Corallo <git@bluematt.me>
Wed, 5 Sep 2018 02:24:46 +0000 (22:24 -0400)
committerMatt Corallo <git@bluematt.me>
Wed, 5 Sep 2018 02:56:25 +0000 (22:56 -0400)
src/ln/channelmanager.rs
src/ln/router.rs

index e365b048a205765b49c4ec8a56851ca25fa31f8b..508997833847898147c296aab491aaf666333e87 100644 (file)
@@ -3355,9 +3355,9 @@ mod tests {
                                        chain_hash: genesis_block(Network::Testnet).header.bitcoin_hash(),
                                        short_channel_id: as_chan.get_short_channel_id().unwrap(),
                                        node_id_1: if were_node_one { as_network_key } else { bs_network_key },
-                                       node_id_2: if !were_node_one { bs_network_key } else { as_network_key },
+                                       node_id_2: if were_node_one { bs_network_key } else { as_network_key },
                                        bitcoin_key_1: if were_node_one { as_bitcoin_key } else { bs_bitcoin_key },
-                                       bitcoin_key_2: if !were_node_one { bs_bitcoin_key } else { as_bitcoin_key },
+                                       bitcoin_key_2: if were_node_one { bs_bitcoin_key } else { as_bitcoin_key },
                                        excess_data: Vec::new(),
                                };
                        }
@@ -3372,9 +3372,9 @@ mod tests {
                                let bs_node_sig = secp_ctx.sign(&msghash, &nodes[1].node.our_network_key);
                                chan_announcement = msgs::ChannelAnnouncement {
                                        node_signature_1 : if were_node_one { as_node_sig } else { bs_node_sig},
-                                       node_signature_2 : if !were_node_one { bs_node_sig } else { as_node_sig},
+                                       node_signature_2 : if were_node_one { bs_node_sig } else { as_node_sig},
                                        bitcoin_signature_1: if were_node_one { as_bitcoin_sig } else { bs_bitcoin_sig },
-                                       bitcoin_signature_2 : if !were_node_one { bs_bitcoin_sig } else { as_bitcoin_sig },
+                                       bitcoin_signature_2 : if were_node_one { bs_bitcoin_sig } else { as_bitcoin_sig },
                                        contents: $unsigned_msg
                                }
                        }
index e3697147f0a6e0f1d34657d9024ef10b19a4608d..6bc319d59b8145de6162f47c7c78d746fd318a12 100644 (file)
@@ -199,6 +199,10 @@ impl RoutingMessageHandler for Router {
        }
 
        fn handle_channel_announcement(&self, msg: &msgs::ChannelAnnouncement) -> Result<bool, HandleError> {
+               if msg.contents.node_id_1 == msg.contents.node_id_2 || msg.contents.bitcoin_key_1 == msg.contents.bitcoin_key_2 {
+                       return Err(HandleError{err: "Channel announcement node had a channel with itself", action: Some(ErrorAction::IgnoreError)});
+               }
+
                let msg_hash = Message::from_slice(&Sha256dHash::from_data(&msg.contents.encode()[..])[..]).unwrap();
                secp_verify_sig!(self.secp_ctx, &msg_hash, &msg.node_signature_1, &msg.contents.node_id_1);
                secp_verify_sig!(self.secp_ctx, &msg_hash, &msg.node_signature_2, &msg.contents.node_id_2);