Skip to content

Gossip filtration fix #3390

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 6, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 27 additions & 1 deletion lightning/src/ln/peer_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -509,9 +509,18 @@ impl fmt::Display for PeerHandleError {
}
}

/// Internal struct for keeping track of the gossip syncing progress with a given peer
enum InitSyncTracker{
/// Only sync ad-hoc gossip as it comes in, do not send historical gossip.
/// Upon receipt of a GossipTimestampFilter message, this is the default initial state if the
/// contained timestamp is less than 6 hours old.
NoSyncRequested,
/// Send historical gossip starting at the given channel id, which gets incremented as the
/// gossiping progresses.
/// Upon receipt of a GossipTimestampFilter message, this is the default initial state if the
/// contained timestamp is at least 6 hours old, and the initial channel id is set to 0.
ChannelsSyncing(u64),
/// Once the channel announcements and updates finish syncing, the node announcements are synced.
NodesSyncing(NodeId),
}

Expand Down Expand Up @@ -1727,7 +1736,24 @@ impl<Descriptor: SocketDescriptor, CM: Deref, RM: Deref, OM: Deref, L: Deref, CM
if peer_lock.their_features.as_ref().unwrap().supports_gossip_queries() &&
!peer_lock.sent_gossip_timestamp_filter {
peer_lock.sent_gossip_timestamp_filter = true;
peer_lock.sync_status = InitSyncTracker::ChannelsSyncing(0);

#[allow(unused_mut)]
let mut should_do_full_sync = true;
#[cfg(feature = "std")]
{
// Forward ad-hoc gossip if the timestamp range is less than six hours ago.
// Otherwise, do a full sync.
use std::time::{SystemTime, UNIX_EPOCH};
let full_sync_threshold = SystemTime::now().duration_since(UNIX_EPOCH).expect("Time must be > 1970").as_secs() - 6 * 3600;
if (_msg.first_timestamp as u64) > full_sync_threshold {
should_do_full_sync = false;
}
}
if should_do_full_sync {
peer_lock.sync_status = InitSyncTracker::ChannelsSyncing(0);
} else {
peer_lock.sync_status = InitSyncTracker::NoSyncRequested;
}
}
return Ok(None);
}
Expand Down
Loading