@@ -509,9 +509,18 @@ impl fmt::Display for PeerHandleError {
509509 }
510510}
511511
512+ /// Internal struct for keeping track of the gossip syncing progress with a given peer
512513enum InitSyncTracker {
514+ /// Only sync ad-hoc gossip as it comes in, do not send historical gossip.
515+ /// Upon receipt of a GossipTimestampFilter message, this is the default initial state if the
516+ /// contained timestamp is less than 6 hours old.
513517 NoSyncRequested ,
518+ /// Send historical gossip starting at the given channel id, which gets incremented as the
519+ /// gossiping progresses.
520+ /// Upon receipt of a GossipTimestampFilter message, this is the default initial state if the
521+ /// contained timestamp is at least 6 hours old, and the initial channel id is set to 0.
514522 ChannelsSyncing ( u64 ) ,
523+ /// Once the channel announcements and updates finish syncing, the node announcements are synced.
515524 NodesSyncing ( NodeId ) ,
516525}
517526
@@ -1721,13 +1730,25 @@ impl<Descriptor: SocketDescriptor, CM: Deref, RM: Deref, OM: Deref, L: Deref, CM
17211730 return Err ( PeerHandleError { } . into ( ) ) ;
17221731 }
17231732
1724- if let wire:: Message :: GossipTimestampFilter ( _msg ) = message {
1733+ if let wire:: Message :: GossipTimestampFilter ( msg ) = message {
17251734 // When supporting gossip messages, start initial gossip sync only after we receive
17261735 // a GossipTimestampFilter
17271736 if peer_lock. their_features . as_ref ( ) . unwrap ( ) . supports_gossip_queries ( ) &&
17281737 !peer_lock. sent_gossip_timestamp_filter {
17291738 peer_lock. sent_gossip_timestamp_filter = true ;
1730- peer_lock. sync_status = InitSyncTracker :: ChannelsSyncing ( 0 ) ;
1739+
1740+ #[ allow( unused_mut, unused_assignments) ]
1741+ let mut full_sync_threshold = 0 ;
1742+ #[ cfg( feature = "std" ) ]
1743+ {
1744+ // if the timestamp range starts more than six hours ago, do a full sync
1745+ // otherwise, start at the current time
1746+ use std:: time:: { SystemTime , UNIX_EPOCH } ;
1747+ full_sync_threshold = SystemTime :: now ( ) . duration_since ( UNIX_EPOCH ) . expect ( "Time must be > 1970" ) . as_secs ( ) - 6 * 3600 ;
1748+ }
1749+ if ( msg. first_timestamp as u64 ) <= full_sync_threshold {
1750+ peer_lock. sync_status = InitSyncTracker :: ChannelsSyncing ( 0 ) ;
1751+ }
17311752 }
17321753 return Ok ( None ) ;
17331754 }
0 commit comments