@@ -509,9 +509,18 @@ impl fmt::Display for PeerHandleError {
509
509
}
510
510
}
511
511
512
+ /// Internal struct for keeping track of the gossip syncing progress with a given peer
512
513
enum 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.
513
517
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.
514
522
ChannelsSyncing ( u64 ) ,
523
+ /// Once the channel announcements and updates finish syncing, the node announcements are synced.
515
524
NodesSyncing ( NodeId ) ,
516
525
}
517
526
@@ -1721,13 +1730,26 @@ impl<Descriptor: SocketDescriptor, CM: Deref, RM: Deref, OM: Deref, L: Deref, CM
1721
1730
return Err ( PeerHandleError { } . into ( ) ) ;
1722
1731
}
1723
1732
1724
- if let wire:: Message :: GossipTimestampFilter ( _msg ) = message {
1733
+ if let wire:: Message :: GossipTimestampFilter ( msg ) = message {
1725
1734
// When supporting gossip messages, start initial gossip sync only after we receive
1726
1735
// a GossipTimestampFilter
1736
+
1727
1737
if peer_lock. their_features . as_ref ( ) . unwrap ( ) . supports_gossip_queries ( ) &&
1728
1738
!peer_lock. sent_gossip_timestamp_filter {
1729
1739
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
+ }
1731
1753
}
1732
1754
return Ok ( None ) ;
1733
1755
}
0 commit comments