]> 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)
committerUser <naumenko.gs@gmail.com>
Sat, 11 Apr 2020 12:30:21 +0000 (08:30 -0400)
lightning-net-tokio/src/lib.rs
lightning/src/ln/msgs.rs
lightning/src/ln/peer_handler.rs
lightning/src/ln/router.rs
lightning/src/util/test_utils.rs

index 94c3eee151164142668507a01d7081bac5c4fa04..dd0b861c197a54fcd45242bbd4250af919511c90 100644 (file)
@@ -507,7 +507,7 @@ mod tests {
                fn handle_channel_announcement(&self, _msg: &ChannelAnnouncement) -> Result<bool, LightningError> { Ok(false) }
                fn handle_channel_update(&self, _msg: &ChannelUpdate) -> Result<bool, LightningError> { 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<ChannelUpdate>, Option<ChannelUpdate>)> { Vec::new() }
                fn get_next_node_announcements(&self, _starting_point: Option<&PublicKey>, _batch_amount: u8) -> Vec<NodeAnnouncement> { Vec::new() }
                fn should_request_full_sync(&self, _node_id: &PublicKey) -> bool { false }
        }
index 1ad798fd4bfaf2417d20fdeb4030dd876d7dd77c..85f3026eafa7930d705b9d7cc1b1b8fed3517b39 100644 (file)
@@ -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<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 fc6d1cbcda13883864382bb0cb07d35e6c3e1d32..15fa105d0c0465e5d3dd27ac421bca59e8004f91 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 {
@@ -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<msgs::ChannelUpdate>, Option<msgs::ChannelUpdate>)> {
                        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);
index 666c859ee0c57e75ff51e16485234398048d6098..e9b5eb29a43e096eaab1f30f5a28c8f0818642c2 100644 (file)
@@ -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<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 78b81fa637bf292deda5b5a9244512cbbd2d6c8f..b6d90b3ed17b9b09c10420f2f18f3c59d23d71a7 100644 (file)
@@ -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<msgs::ChannelUpdate>, Option<msgs::ChannelUpdate>)> {
                Vec::new()
        }
        fn get_next_node_announcements(&self, _starting_point: Option<&PublicKey>, _batch_amount: u8) -> Vec<msgs::NodeAnnouncement> {