From 145e1aba389917272e5d1c2efdaaeb5a797af677 Mon Sep 17 00:00:00 2001 From: Arik Sosman Date: Fri, 15 Nov 2024 12:32:38 -0800 Subject: [PATCH] Trigger full sync only on old GossipTimestampFilters Previously, upon receipt of a GossipTimestampFilter message, we would immediately start unloading the entire network graph on our unsuspecting peer. This commit modifies our behavior to only do so if the timestamp of the filter message is at least six hour old. Otherwise, we only send updated sync data as it comes in. --- lightning/src/ln/peer_handler.rs | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/lightning/src/ln/peer_handler.rs b/lightning/src/ln/peer_handler.rs index 96a5df3b464..56b6aabf538 100644 --- a/lightning/src/ln/peer_handler.rs +++ b/lightning/src/ln/peer_handler.rs @@ -509,9 +509,18 @@ impl fmt::Display for PeerHandleError { } } +/// Internal struct for keeping track of the gossip syncing progress with a given peer enum InitSyncTracker{ + /// Only sync ad-hoc gossip as it comes in, do not send historical gossip. + /// Upon receipt of a GossipTimestampFilter message, this is the default initial state if the + /// contained timestamp is less than 6 hours old. NoSyncRequested, + /// Send historical gossip starting at the given channel id, which gets incremented as the + /// gossiping progresses. + /// Upon receipt of a GossipTimestampFilter message, this is the default initial state if the + /// contained timestamp is at least 6 hours old, and the initial channel id is set to 0. ChannelsSyncing(u64), + /// Once the channel announcements and updates finish syncing, the node announcements are synced. NodesSyncing(NodeId), } @@ -1727,7 +1736,24 @@ impl 1970").as_secs() - 6 * 3600; + if (_msg.first_timestamp as u64) > full_sync_threshold { + should_do_full_sync = false; + } + } + if should_do_full_sync { + peer_lock.sync_status = InitSyncTracker::ChannelsSyncing(0); + } else { + peer_lock.sync_status = InitSyncTracker::NoSyncRequested; + } } return Ok(None); }