@@ -510,9 +510,18 @@ impl fmt::Display for PeerHandleError {
510
510
}
511
511
}
512
512
513
+ /// Internal struct for keeping track of the gossip syncing progress with a given peer
513
514
enum InitSyncTracker {
515
+ /// Only sync ad-hoc gossip as it comes in, do not send historical gossip.
516
+ /// Upon receipt of a GossipTimestampFilter message, this is the default initial state if the
517
+ /// contained timestamp is less than 6 hours old.
514
518
NoSyncRequested ,
519
+ /// Send historical gossip starting at the given channel id, which gets incremented as the
520
+ /// gossiping progresses.
521
+ /// Upon receipt of a GossipTimestampFilter message, this is the default initial state if the
522
+ /// contained timestamp is at least 6 hours old, and the initial channel id is set to 0.
515
523
ChannelsSyncing ( u64 ) ,
524
+ /// Once the channel announcements and updates finish syncing, the node announcements are synced.
516
525
NodesSyncing ( NodeId ) ,
517
526
}
518
527
@@ -1728,7 +1737,24 @@ impl<Descriptor: SocketDescriptor, CM: Deref, RM: Deref, OM: Deref, L: Deref, CM
1728
1737
if peer_lock. their_features . as_ref ( ) . unwrap ( ) . supports_gossip_queries ( ) &&
1729
1738
!peer_lock. sent_gossip_timestamp_filter {
1730
1739
peer_lock. sent_gossip_timestamp_filter = true ;
1731
- peer_lock. sync_status = InitSyncTracker :: ChannelsSyncing ( 0 ) ;
1740
+
1741
+ #[ allow( unused_mut) ]
1742
+ let mut should_do_full_sync = true ;
1743
+ #[ cfg( feature = "std" ) ]
1744
+ {
1745
+ // Forward ad-hoc gossip if the timestamp range is less than six hours ago.
1746
+ // Otherwise, do a full sync.
1747
+ use std:: time:: { SystemTime , UNIX_EPOCH } ;
1748
+ let full_sync_threshold = SystemTime :: now ( ) . duration_since ( UNIX_EPOCH ) . expect ( "Time must be > 1970" ) . as_secs ( ) - 6 * 3600 ;
1749
+ if ( _msg. first_timestamp as u64 ) > full_sync_threshold {
1750
+ should_do_full_sync = false ;
1751
+ }
1752
+ }
1753
+ if should_do_full_sync {
1754
+ peer_lock. sync_status = InitSyncTracker :: ChannelsSyncing ( 0 ) ;
1755
+ } else {
1756
+ peer_lock. sync_status = InitSyncTracker :: NoSyncRequested ;
1757
+ }
1732
1758
}
1733
1759
return Ok ( None ) ;
1734
1760
}
0 commit comments