From: Matt Corallo Date: Mon, 24 Feb 2020 18:18:50 +0000 (-0500) Subject: Allow relaying of only one direction in a channel, log on recv X-Git-Url: http://git.bitcoin.ninja/?a=commitdiff_plain;h=d8997dd866e859c82efe6d07cf313e8f2be84d77;p=rust-lightning Allow relaying of only one direction in a channel, log on recv --- diff --git a/lightning-net-tokio/src/lib.rs b/lightning-net-tokio/src/lib.rs index 94c3eee15..dd0b861c1 100644 --- a/lightning-net-tokio/src/lib.rs +++ b/lightning-net-tokio/src/lib.rs @@ -507,7 +507,7 @@ mod tests { fn handle_channel_announcement(&self, _msg: &ChannelAnnouncement) -> Result { Ok(false) } fn handle_channel_update(&self, _msg: &ChannelUpdate) -> Result { Ok(false) } fn handle_htlc_fail_channel_update(&self, _update: &HTLCFailChannelUpdate) { } - fn get_next_channel_announcements(&self, _starting_point: u64, _batch_amount: u8) -> Vec<(ChannelAnnouncement, ChannelUpdate, ChannelUpdate)> { Vec::new() } + fn get_next_channel_announcements(&self, _starting_point: u64, _batch_amount: u8) -> Vec<(ChannelAnnouncement, Option, Option)> { Vec::new() } fn get_next_node_announcements(&self, _starting_point: Option<&PublicKey>, _batch_amount: u8) -> Vec { Vec::new() } fn should_request_full_sync(&self, _node_id: &PublicKey) -> bool { false } } diff --git a/lightning/src/ln/msgs.rs b/lightning/src/ln/msgs.rs index 1ad798fd4..85f3026ea 100644 --- a/lightning/src/ln/msgs.rs +++ b/lightning/src/ln/msgs.rs @@ -601,7 +601,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 fc6d1cbcd..15fa105d0 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 { @@ -1313,7 +1317,7 @@ mod tests { Err(msgs::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)> { let mut chan_anns = Vec::new(); const TOTAL_UPDS: u64 = 100; let end: u64 = min(starting_point + batch_amount as u64, TOTAL_UPDS - self.chan_anns_sent.load(Ordering::Acquire) as u64); @@ -1322,7 +1326,7 @@ mod tests { let chan_upd_2 = get_dummy_channel_update(i); let chan_ann = get_dummy_channel_announcement(i); - chan_anns.push((chan_ann, chan_upd_1, chan_upd_2)); + chan_anns.push((chan_ann, Some(chan_upd_1), Some(chan_upd_2))); } self.chan_anns_sent.fetch_add(chan_anns.len(), Ordering::AcqRel); diff --git a/lightning/src/ln/router.rs b/lightning/src/ln/router.rs index 39e8e6114..04ba31a76 100644 --- a/lightning/src/ln/router.rs +++ b/lightning/src/ln/router.rs @@ -559,6 +559,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) } @@ -663,19 +664,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 78b81fa63..b6d90b3ed 100644 --- a/lightning/src/util/test_utils.rs +++ b/lightning/src/util/test_utils.rs @@ -176,7 +176,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 {