]> git.bitcoin.ninja Git - rust-lightning/commitdiff
Allow relaying of only one direction in a channel, log on recv
authorMatt Corallo <git@bluematt.me>
Mon, 24 Feb 2020 18:18:50 +0000 (13:18 -0500)
committerMatt Corallo <git@bluematt.me>
Sun, 1 Mar 2020 04:26:16 +0000 (23:26 -0500)
lightning/src/ln/msgs.rs
lightning/src/ln/peer_handler.rs
lightning/src/ln/router.rs
lightning/src/util/test_utils.rs

index 3ebbc7edf6a05164c5592c41b1661cd166bff4af..054901fd69d47b636596a1103d2eebc17dea8736 100644 (file)
@@ -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<ChannelUpdate>, Option<ChannelUpdate>)>;
        /// 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 <PublicKey as Ord>::cmp) than starting_point.
index 5e5f1f8b86a5fc467f64d707afc4a0edb9e1861a..7eabab10ecd29f7fa77ab374bcb7e74a4ef4ad3f 100644 (file)
@@ -355,10 +355,14 @@ impl<Descriptor: SocketDescriptor, CM: Deref> PeerManager<Descriptor, CM> 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 {
index e99a5f76e66a595ef6fb03ca57a44ca44cb03ce3..3bff05d95025dfecadb1f8711143d015344115d0 100644 (file)
@@ -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<msgs::ChannelUpdate>, Option<msgs::ChannelUpdate>)> {
                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.
index 9af8d5cf2f3d92db21ab81a775ae4b1b03ad8860..13853d3917779e5faab4a7d0e1391eae6b383992 100644 (file)
@@ -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<msgs::ChannelUpdate>, Option<msgs::ChannelUpdate>)> {
                Vec::new()
        }
        fn get_next_node_announcements(&self, _starting_point: Option<&PublicKey>, _batch_amount: u8) -> Vec<msgs::NodeAnnouncement> {