Skip to content
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

Gossip filtration fix #3390

Merged
merged 1 commit into from
Dec 6, 2024
Merged

Conversation

arik-so
Copy link
Contributor

@arik-so arik-so commented Oct 31, 2024

Previously, upon receipt of a GossipTimestampFilter message, we would immediately start unloading the entire network graph on our unsuspecting peer.

This PR modifies our behavior to only do so if the timestamp of the filter message is at least an hour old. Otherwise, we only send updated sync data as it comes in.

(f.first_timestamp, f.first_timestamp.saturating_add(f.timestamp_range))
});

if msg.contents.timestamp >= min && msg.contents.timestamp <= max {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You'll need to apply the same in NodesSyncing handling below.

lightning/src/ln/peer_handler.rs Outdated Show resolved Hide resolved
lightning/src/ln/peer_handler.rs Outdated Show resolved Hide resolved
lightning/src/ln/peer_handler.rs Outdated Show resolved Hide resolved
Copy link

codecov bot commented Nov 7, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 90.94%. Comparing base (8da30df) to head (249cf2c).
Report is 40 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3390      +/-   ##
==========================================
+ Coverage   89.61%   90.94%   +1.33%     
==========================================
  Files         129      130       +1     
  Lines      105506   114915    +9409     
  Branches   105506   114915    +9409     
==========================================
+ Hits        94544   104508    +9964     
+ Misses       8208     7986     -222     
+ Partials     2754     2421     -333     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@arik-so arik-so force-pushed the gossip-filtration-fix branch from 268ecea to 3854be0 Compare November 15, 2024 21:41
lightning/src/ln/peer_handler.rs Outdated Show resolved Hide resolved
lightning/src/ln/peer_handler.rs Outdated Show resolved Hide resolved
@arik-so arik-so force-pushed the gossip-filtration-fix branch from 47f4228 to e5f9a11 Compare November 21, 2024 16:25
@arik-so
Copy link
Contributor Author

arik-so commented Nov 21, 2024

And if the newly added check doesn't pass, we won't send any gossip.

I have split the check in two to address that, @jkczyz.

Copy link
Contributor

@jkczyz jkczyz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. May want to add a test as mentioned offline. Also, would be good to document InitSyncTracker as otherwise you need to read the code to figure out the behavior.

@arik-so
Copy link
Contributor Author

arik-so commented Dec 2, 2024

peer_connected in test_utils sets the gossip start time for the GossipTimestampFilter message to either an hour ago for no sync, or two weeks ago for a full sync, which basically covers the two scenarios this change discerns. Only additional thing we could test would be 6 hours ± 1 second, but I'm not sure that's even worth it.

@arik-so arik-so requested a review from jkczyz December 4, 2024 01:48
lightning/src/ln/peer_handler.rs Show resolved Hide resolved
lightning/src/ln/peer_handler.rs Outdated Show resolved Hide resolved
use std::time::{SystemTime, UNIX_EPOCH};
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 {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for non-std builds, full_sync_threshold will be left unchanged to 0, and we will never trigger a full gossip sync even if message contained now-2weeks ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

my understanding is that for non-std builds, we rather always trigger a full gossip sync

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I made the code a bit clearer for default no-std behavior.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

iiuc, it wouldn't have worked as expected earlier. lmk if that was not the case.

Copy link
Contributor

@G8XSU G8XSU left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does what it says, and handles non-std behavior correctly.
Lgtm, unless other reviewers have more feedback!

@@ -1724,10 +1733,26 @@ impl<Descriptor: SocketDescriptor, CM: Deref, RM: Deref, OM: Deref, L: Deref, CM
if let wire::Message::GossipTimestampFilter(_msg) = message {
// When supporting gossip messages, start initial gossip sync only after we receive
// a GossipTimestampFilter

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: newline not required.

#[cfg(feature = "std")]
{
// if the timestamp range starts more than six hours ago, do a full sync
// otherwise, start at the current time
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: "otherwise, do not send historical gossip."

lightning/src/ln/peer_handler.rs Show resolved Hide resolved
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, unused_assignments)]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: unused_assignments should no longer be required.

@TheBlueMatt TheBlueMatt added this to the 0.1 milestone Dec 5, 2024
@arik-so arik-so force-pushed the gossip-filtration-fix branch 2 times, most recently from 249cf2c to e582222 Compare December 5, 2024 06:39
Copy link
Collaborator

@TheBlueMatt TheBlueMatt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Presumably the second commit should be squashed as a fixup?

lightning/src/ln/peer_handler.rs Show resolved Hide resolved
@arik-so arik-so force-pushed the gossip-filtration-fix branch from e582222 to 0247ad0 Compare December 5, 2024 17:08
@arik-so
Copy link
Contributor Author

arik-so commented Dec 5, 2024

squashed

Copy link
Contributor

@jkczyz jkczyz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM other than re-wording a comment.

Comment on lines 1744 to 1745
// if the timestamp range starts more than six hours ago, do a full sync
// otherwise, only forward ad-hoc gossip
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment would be less confusing if it was re-phrased to say "less than six hours ago" as that is the condition where should_do_full_sync is modified below.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

eh, I think it's quite clear honestly

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It describes the opposite of the if clause as worded.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how about this phrasing I just pushed:

// determine if the timestamp range starts more than six hours ago
// if it doesn't, only forward ad-hoc gossip

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Eh, I mean, I read the comment then see if the code does what it says, but I need to reverse the logic to determine that. Can't we just say: "Forward ad-hoc gossip if the timestamp range is less than six hours ago. Otherwise, do a full sync."?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, done.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks the same?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oops, push had failed. Worked now

@arik-so arik-so force-pushed the gossip-filtration-fix branch 2 times, most recently from b7a7ef6 to b350233 Compare December 5, 2024 17:45
@G8XSU
Copy link
Contributor

G8XSU commented Dec 5, 2024

Current git commit message is confusing though.
"Trigger full sync on old GossipTimestampFilter",
The real thing we wanted to achieve/fix was "Do not trigger full gossip sync on every GossipTimestampFilter."

@arik-so
Copy link
Contributor Author

arik-so commented Dec 5, 2024

Would you like me to add an "only" to the commit message? Or rephrase it?

@G8XSU
Copy link
Contributor

G8XSU commented Dec 5, 2024

anything is fine i guess, upto you

@arik-so arik-so force-pushed the gossip-filtration-fix branch from b350233 to a837f2b Compare December 5, 2024 17:53
@arik-so
Copy link
Contributor Author

arik-so commented Dec 5, 2024

ok, sure, I rephrased it

@G8XSU
Copy link
Contributor

G8XSU commented Dec 5, 2024

Waiting on ci to merge.

Previously, upon receipt of a GossipTimestampFilter message, we would
immediately start unloading the entire network graph on our
unsuspecting peer.

This commit modifies our behavior to only do so if the timestamp of
the filter message is at least six hour old. Otherwise, we only send
updated sync data as it comes in.
@arik-so arik-so force-pushed the gossip-filtration-fix branch from a837f2b to 145e1ab Compare December 5, 2024 18:06
@jkczyz
Copy link
Contributor

jkczyz commented Dec 5, 2024

Let's expanded the commit message with the why from the PR description, as discussed offline.

@arik-so
Copy link
Contributor Author

arik-so commented Dec 5, 2024

hm, the expanded message seems to show up for me, maybe Github doesn't auto-refresh?

@G8XSU
Copy link
Contributor

G8XSU commented Dec 5, 2024

There is a fuzz test failure for 'test_gossip_exchange_breakage', looks like it is related.

@valentinewallace
Copy link
Contributor

There is a fuzz test failure for 'test_gossip_exchange_breakage', looks like it is related.

I believe this is from #3439, working on a fix for this

@G8XSU
Copy link
Contributor

G8XSU commented Dec 5, 2024

I believe this is from #3439, working on a fix for this

Sounds good, will merge this after ci completes in that case.

@G8XSU G8XSU merged commit 8a54da6 into lightningdevkit:main Dec 6, 2024
17 of 19 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants