From 91b23a075442107a93d00c6db1d7f5ffe54f715b Mon Sep 17 00:00:00 2001 From: Matt Corallo Date: Tue, 4 Sep 2018 22:24:46 -0400 Subject: [PATCH] Reject rumors of channels that are from one node back to itself --- src/ln/channelmanager.rs | 8 ++++---- src/ln/router.rs | 4 ++++ 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/ln/channelmanager.rs b/src/ln/channelmanager.rs index e365b048a..508997833 100644 --- a/src/ln/channelmanager.rs +++ b/src/ln/channelmanager.rs @@ -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 } } diff --git a/src/ln/router.rs b/src/ln/router.rs index e3697147f..6bc319d59 100644 --- a/src/ln/router.rs +++ b/src/ln/router.rs @@ -199,6 +199,10 @@ impl RoutingMessageHandler for Router { } fn handle_channel_announcement(&self, msg: &msgs::ChannelAnnouncement) -> Result { + 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); -- 2.39.5