From: Matt Corallo <649246+TheBlueMatt@users.noreply.github.com> Date: Tue, 3 May 2022 19:16:29 +0000 (+0000) Subject: Merge pull request #1452 from tnull/2022-04-honor-gossip-timestamp-filters X-Git-Tag: v0.0.107~45 X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=commitdiff_plain;h=171dfeee07da7fd4c9ad8a081a91899b3a7268d0;hp=-c;p=rust-lightning Merge pull request #1452 from tnull/2022-04-honor-gossip-timestamp-filters Initiate gossip sync only after receiving GossipTimestampFilter. --- 171dfeee07da7fd4c9ad8a081a91899b3a7268d0 diff --combined lightning/src/ln/peer_handler.rs index c09df175,3207f3f1..07300fdf --- a/lightning/src/ln/peer_handler.rs +++ b/lightning/src/ln/peer_handler.rs @@@ -339,6 -339,7 +339,7 @@@ struct Peer msgs_sent_since_pong: usize, awaiting_pong_timer_tick_intervals: i8, received_message_since_timer_tick: bool, + sent_gossip_timestamp_filter: bool, } impl Peer { @@@ -348,7 -349,11 +349,11 @@@ /// announcements/updates for the given channel_id then we will send it when we get to that /// point and we shouldn't send it yet to avoid sending duplicate updates. If we've already /// sent the old versions, we should send the update, and so return true here. - fn should_forward_channel_announcement(&self, channel_id: u64)->bool{ + fn should_forward_channel_announcement(&self, channel_id: u64) -> bool { + if self.their_features.as_ref().unwrap().supports_gossip_queries() && + !self.sent_gossip_timestamp_filter { + return false; + } match self.sync_status { InitSyncTracker::NoSyncRequested => true, InitSyncTracker::ChannelsSyncing(i) => i < channel_id, @@@ -358,6 -363,10 +363,10 @@@ /// Similar to the above, but for node announcements indexed by node_id. fn should_forward_node_announcement(&self, node_id: PublicKey) -> bool { + if self.their_features.as_ref().unwrap().supports_gossip_queries() && + !self.sent_gossip_timestamp_filter { + return false; + } match self.sync_status { InitSyncTracker::NoSyncRequested => true, InitSyncTracker::ChannelsSyncing(_) => false, @@@ -619,6 -628,7 +628,7 @@@ impl { - // TODO: handle message + // When supporting gossip messages, start inital gossip sync only after we receive + // a GossipTimestampFilter + if peer.their_features.as_ref().unwrap().supports_gossip_queries() && + !peer.sent_gossip_timestamp_filter { + peer.sent_gossip_timestamp_filter = true; + peer.sync_status = InitSyncTracker::ChannelsSyncing(0); + } }, // Unknown messages: @@@ -1707,11 -1725,7 +1725,11 @@@ fn is_gossip_msg(type_id: u16) -> bool match type_id { msgs::ChannelAnnouncement::TYPE | msgs::ChannelUpdate::TYPE | - msgs::NodeAnnouncement::TYPE => true, + msgs::NodeAnnouncement::TYPE | + msgs::QueryChannelRange::TYPE | + msgs::ReplyChannelRange::TYPE | + msgs::QueryShortChannelIds::TYPE | + msgs::ReplyShortChannelIdsEnd::TYPE => true, _ => false } } @@@ -1803,6 -1817,8 +1821,8 @@@ mod tests assert_eq!(peer_b.read_event(&mut fd_b, &fd_a.outbound_data.lock().unwrap().split_off(0)).unwrap(), false); peer_b.process_events(); assert_eq!(peer_a.read_event(&mut fd_a, &fd_b.outbound_data.lock().unwrap().split_off(0)).unwrap(), false); + peer_a.process_events(); + assert_eq!(peer_b.read_event(&mut fd_b, &fd_a.outbound_data.lock().unwrap().split_off(0)).unwrap(), false); (fd_a.clone(), fd_b.clone()) } @@@ -1866,21 -1882,21 +1886,21 @@@ let (mut fd_a, mut fd_b) = establish_connection(&peers[0], &peers[1]); // Make each peer to read the messages that the other peer just wrote to them. Note that - // due to the max-messagse-before-ping limits this may take a few iterations to complete. + // due to the max-message-before-ping limits this may take a few iterations to complete. for _ in 0..150/super::BUFFER_DRAIN_MSGS_PER_TICK + 1 { - peers[0].process_events(); - let b_read_data = fd_a.outbound_data.lock().unwrap().split_off(0); - assert!(!b_read_data.is_empty()); - - peers[1].read_event(&mut fd_b, &b_read_data).unwrap(); peers[1].process_events(); - let a_read_data = fd_b.outbound_data.lock().unwrap().split_off(0); assert!(!a_read_data.is_empty()); + peers[0].read_event(&mut fd_a, &a_read_data).unwrap(); + peers[0].process_events(); - peers[1].process_events(); - assert_eq!(fd_b.outbound_data.lock().unwrap().len(), 0, "Until B receives data, it shouldn't send more messages"); + let b_read_data = fd_a.outbound_data.lock().unwrap().split_off(0); + assert!(!b_read_data.is_empty()); + peers[1].read_event(&mut fd_b, &b_read_data).unwrap(); + + peers[0].process_events(); + assert_eq!(fd_a.outbound_data.lock().unwrap().len(), 0, "Until A receives data, it shouldn't send more messages"); } // Check that each peer has received the expected number of channel updates and channel