From 8bcfd027cba2838a0762756e682a9265715d2ecb Mon Sep 17 00:00:00 2001 From: Matt Corallo Date: Mon, 24 Feb 2020 13:18:50 -0500 Subject: [PATCH] Allow relaying of only one direction in a channel, log on recv --- lightning/src/ln/msgs.rs | 2 +- lightning/src/ln/peer_handler.rs | 10 +++++++--- lightning/src/ln/router.rs | 12 +++++------- lightning/src/util/test_utils.rs | 2 +- 4 files changed, 14 insertions(+), 12 deletions(-) diff --git a/lightning/src/ln/msgs.rs b/lightning/src/ln/msgs.rs index 3ebbc7edf..054901fd6 100644 --- a/lightning/src/ln/msgs.rs +++ b/lightning/src/ln/msgs.rs @@ -653,7 +653,7 @@ pub trait RoutingMessageHandler : Send + Sync { /// Gets a subset of the channel announcements and updates required to dump our routing table /// to a remote node, starting at the short_channel_id indicated by starting_point and /// including the batch_amount entries immediately higher in numerical value than starting_point. - fn get_next_channel_announcements(&self, starting_point: u64, batch_amount: u8) -> Vec<(ChannelAnnouncement, ChannelUpdate, ChannelUpdate)>; + fn get_next_channel_announcements(&self, starting_point: u64, batch_amount: u8) -> Vec<(ChannelAnnouncement, Option, Option)>; /// Gets a subset of the node announcements required to dump our routing table to a remote node, /// starting at the node *after* the provided publickey and including batch_amount entries /// immediately higher (as defined by ::cmp) than starting_point. diff --git a/lightning/src/ln/peer_handler.rs b/lightning/src/ln/peer_handler.rs index 5e5f1f8b8..7eabab10e 100644 --- a/lightning/src/ln/peer_handler.rs +++ b/lightning/src/ln/peer_handler.rs @@ -355,10 +355,14 @@ impl PeerManager where InitSyncTracker::ChannelsSyncing(c) if c < 0xffff_ffff_ffff_ffff => { let steps = ((MSG_BUFF_SIZE - peer.pending_outbound_buffer.len() + 2) / 3) as u8; let all_messages = self.message_handler.route_handler.get_next_channel_announcements(c, steps); - for &(ref announce, ref update_a, ref update_b) in all_messages.iter() { + for &(ref announce, ref update_a_option, ref update_b_option) in all_messages.iter() { encode_and_send_msg!(announce); - encode_and_send_msg!(update_a); - encode_and_send_msg!(update_b); + if let &Some(ref update_a) = update_a_option { + encode_and_send_msg!(update_a); + } + if let &Some(ref update_b) = update_b_option { + encode_and_send_msg!(update_b); + } peer.sync_status = InitSyncTracker::ChannelsSyncing(announce.contents.short_channel_id + 1); } if all_messages.is_empty() || all_messages.len() != steps as usize { diff --git a/lightning/src/ln/router.rs b/lightning/src/ln/router.rs index e99a5f76e..3bff05d95 100644 --- a/lightning/src/ln/router.rs +++ b/lightning/src/ln/router.rs @@ -581,6 +581,7 @@ impl RoutingMessageHandler for Router { add_channel_to_node!(msg.contents.node_id_1); add_channel_to_node!(msg.contents.node_id_2); + log_trace!(self, "Added channel_announcement for {}{}", msg.contents.short_channel_id, if !should_relay { " with excess uninterpreted data!" } else { "" }); Ok(should_relay) } @@ -685,19 +686,16 @@ impl RoutingMessageHandler for Router { Ok(msg.contents.excess_data.is_empty()) } - - fn get_next_channel_announcements(&self, starting_point: u64, batch_amount: u8) -> Vec<(msgs::ChannelAnnouncement, msgs::ChannelUpdate,msgs::ChannelUpdate)> { + fn get_next_channel_announcements(&self, starting_point: u64, batch_amount: u8) -> Vec<(msgs::ChannelAnnouncement, Option, Option)> { let mut result = Vec::with_capacity(batch_amount as usize); let network = self.network_map.read().unwrap(); let mut iter = network.channels.range(starting_point..); while result.len() < batch_amount as usize { if let Some((_, ref chan)) = iter.next() { - if chan.announcement_message.is_some() && - chan.one_to_two.last_update_message.is_some() && - chan.two_to_one.last_update_message.is_some() { + if chan.announcement_message.is_some() { result.push((chan.announcement_message.clone().unwrap(), - chan.one_to_two.last_update_message.clone().unwrap(), - chan.two_to_one.last_update_message.clone().unwrap())); + chan.one_to_two.last_update_message.clone(), + chan.two_to_one.last_update_message.clone())); } else { // TODO: We may end up sending un-announced channel_updates if we are sending // initial sync data while receiving announce/updates for this channel. diff --git a/lightning/src/util/test_utils.rs b/lightning/src/util/test_utils.rs index 9af8d5cf2..13853d391 100644 --- a/lightning/src/util/test_utils.rs +++ b/lightning/src/util/test_utils.rs @@ -186,7 +186,7 @@ impl msgs::RoutingMessageHandler for TestRoutingMessageHandler { Err(LightningError { err: "", action: msgs::ErrorAction::IgnoreError }) } fn handle_htlc_fail_channel_update(&self, _update: &msgs::HTLCFailChannelUpdate) {} - fn get_next_channel_announcements(&self, _starting_point: u64, _batch_amount: u8) -> Vec<(msgs::ChannelAnnouncement, msgs::ChannelUpdate,msgs::ChannelUpdate)> { + fn get_next_channel_announcements(&self, _starting_point: u64, _batch_amount: u8) -> Vec<(msgs::ChannelAnnouncement, Option, Option)> { Vec::new() } fn get_next_node_announcements(&self, _starting_point: Option<&PublicKey>, _batch_amount: u8) -> Vec { -- 2.39.5