Skip to content

Commit 8a54da6

Browse files
authored
Merge pull request #3390 from arik-so/gossip-filtration-fix
Gossip filtration fix
2 parents 10f9123 + 145e1ab commit 8a54da6

File tree

1 file changed

+27
-1
lines changed

1 file changed

+27
-1
lines changed

lightning/src/ln/peer_handler.rs

+27-1
Original file line numberDiff line numberDiff line change
@@ -510,9 +510,18 @@ impl fmt::Display for PeerHandleError {
510510
}
511511
}
512512

513+
/// Internal struct for keeping track of the gossip syncing progress with a given peer
513514
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.
514518
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.
515523
ChannelsSyncing(u64),
524+
/// Once the channel announcements and updates finish syncing, the node announcements are synced.
516525
NodesSyncing(NodeId),
517526
}
518527

@@ -1728,7 +1737,24 @@ impl<Descriptor: SocketDescriptor, CM: Deref, RM: Deref, OM: Deref, L: Deref, CM
17281737
if peer_lock.their_features.as_ref().unwrap().supports_gossip_queries() &&
17291738
!peer_lock.sent_gossip_timestamp_filter {
17301739
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+
}
17321758
}
17331759
return Ok(None);
17341760
}

0 commit comments

Comments
 (0)