@@ -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,26 @@ 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
1736+
17271737 if peer_lock. their_features . as_ref ( ) . unwrap ( ) . supports_gossip_queries ( ) &&
17281738 !peer_lock. sent_gossip_timestamp_filter {
17291739 peer_lock. sent_gossip_timestamp_filter = true ;
1730- peer_lock. sync_status = InitSyncTracker :: ChannelsSyncing ( 0 ) ;
1740+
1741+ #[ allow( unused_mut, unused_assignments) ]
1742+ let mut full_sync_threshold = 0 ;
1743+ #[ cfg( feature = "std" ) ]
1744+ {
1745+ // if the timestamp range starts more than six hours ago, do a full sync
1746+ // otherwise, start at the current time
1747+ use std:: time:: { SystemTime , UNIX_EPOCH } ;
1748+ full_sync_threshold = SystemTime :: now ( ) . duration_since ( UNIX_EPOCH ) . expect ( "Time must be > 1970" ) . as_secs ( ) - 6 * 3600 ;
1749+ }
1750+ if ( msg. first_timestamp as u64 ) <= full_sync_threshold {
1751+ peer_lock. sync_status = InitSyncTracker :: ChannelsSyncing ( 0 ) ;
1752+ }
17311753 }
17321754 return Ok ( None ) ;
17331755 }
0 commit comments