Skip to content

Conversation

@tnull
Copy link
Contributor

@tnull tnull commented Apr 26, 2022

For peers signalling support for gossip queries, this PR delays sending of gossip updates and the initial sync until we receive a GossipTimestampFilter from the counterparty.

Closes #1402.

As suggested there, this PR ignores the particular values in the set filter and only considers whether a filter is set or not (i.e., it provides a boolean option to disable receiving gossip messages).

@tnull
Copy link
Contributor Author

tnull commented Apr 26, 2022

A test case is currently failing since the peers are now signalling support for gossip queries but do not send a GossipTimestampFilter and therefore never start syncing. I'm still looking for a clean way to either inject such messages, or set the sent_gossip_timestamp_filter: bool field from the outside.

@tnull tnull changed the title Initiate initial gossip sync only after receiving GossipTimestampFilter. Initiate gossip sync only after receiving GossipTimestampFilter. Apr 26, 2022
pub struct TestRoutingMessageHandler {
pub chan_upds_recvd: AtomicUsize,
pub chan_anns_recvd: AtomicUsize,
pub request_full_sync: AtomicBool,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Seems like we should just fix this to honor request_full_sync and send a gossip filter on connected?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Well, the filter is currently already sent in peer_connected() and since request_full_sync was not used at all, I figured it would sense to simply remove it rather than to add much more logic to the so-far pretty slim TestRoutingMessageHandler. Or are you suggesting to introduce request_full_sync to other places, e.g., NetGraphMsgHandler, so it could be used by should_request_full_sync()?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Wait, who is sending the filter in peer_connected when we're using a TestRoutingMessageHandler? Its peer_connected method is empty.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah, now I get what you're saying. You're right, its probably easiest here to let the TestRoutingMessageHandler implementation of peer_connected mirror the functionality of NetGraphMsgHandler.

Copy link
Contributor Author

@tnull tnull Apr 28, 2022

Choose a reason for hiding this comment

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

I went that route (replicating the peer_connected functionality in TestRoutingMessgaeHandler) and it generally seems to work nicely. However, now the second peer receives only 86/100 channel updates and 43/50 channel announcements, i.e., the test now fails at the last two assert_eqs. I currently struggle to find why this would be the case, especially since the logs show that the gossip is indeed just postponed until the peers have received gossip_timestamp_filter messages. I'll come around to continue staring at the code next week.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, and before I adapt the test I at least would like to understand why suddenly not the same number of channel updates are delivered, because its not intuitive to me from the changes I made...

Copy link
Collaborator

Choose a reason for hiding this comment

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

I believe the channel updates will be delivered eventually, but the test currently handles a specific number of round-trips between the peers and then makes sure the messages were all delivered. We now need one more round-trip, I believe (but its not quite in the same set of steps as the existing loop, so we can't just add one).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In 7a99de2 I now moved some things in the loop around. This makes the test succeed hopefully without reducing the coverage too much (i.e., it now checks for B's empty outbound_data once in the end, not in every iteration).

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yea, I mean I think that's fine. That said, I'd kinda prefer to update the pre-loop code to add a few message delivery calls that match the new message flow, but if its too annoying to figure that out exactly I'd be okay landing this as-is. Its kinda nice to use this test to ensure that we don't write more gossip messages to the buffer after we reach our limit, even if it makes the test kinda brittle.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah, you're right. The gossip filter messages basically added half a round trip. a31362a should be a cleaner fix now.

@tnull tnull force-pushed the 2022-04-honor-gossip-timestamp-filters branch from 4d647d8 to b24ee4c Compare April 28, 2022 11:40
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.

Thanks, I'd be happy landing this as-is, but see comment.

pub struct TestRoutingMessageHandler {
pub chan_upds_recvd: AtomicUsize,
pub chan_anns_recvd: AtomicUsize,
pub request_full_sync: AtomicBool,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Yea, I mean I think that's fine. That said, I'd kinda prefer to update the pre-loop code to add a few message delivery calls that match the new message flow, but if its too annoying to figure that out exactly I'd be okay landing this as-is. Its kinda nice to use this test to ensure that we don't write more gossip messages to the buffer after we reach our limit, even if it makes the test kinda brittle.

@tnull tnull force-pushed the 2022-04-honor-gossip-timestamp-filters branch from 7a99de2 to a31362a Compare May 2, 2022 16:09
@codecov-commenter
Copy link

codecov-commenter commented May 2, 2022

Codecov Report

Merging #1452 (f8a196c) into main (72069bf) will increase coverage by 1.33%.
The diff coverage is 81.39%.

@@            Coverage Diff             @@
##             main    #1452      +/-   ##
==========================================
+ Coverage   90.87%   92.21%   +1.33%     
==========================================
  Files          75       75              
  Lines       41474    48770    +7296     
  Branches    41474    48770    +7296     
==========================================
+ Hits        37691    44971    +7280     
- Misses       3783     3799      +16     
Impacted Files Coverage Δ
lightning/src/ln/peer_handler.rs 55.94% <66.66%> (+3.32%) ⬆️
lightning/src/util/test_utils.rs 82.84% <95.45%> (+0.41%) ⬆️
lightning/src/chain/mod.rs 59.25% <0.00%> (-1.86%) ⬇️
lightning/src/util/config.rs 45.05% <0.00%> (-0.78%) ⬇️
lightning-net-tokio/src/lib.rs 75.17% <0.00%> (-0.71%) ⬇️
lightning/src/routing/scoring.rs 94.00% <0.00%> (-0.36%) ⬇️
lightning/src/ln/features.rs 99.59% <0.00%> (+0.15%) ⬆️
lightning/src/ln/msgs.rs 86.66% <0.00%> (+0.29%) ⬆️
lightning/src/ln/functional_test_utils.rs 95.96% <0.00%> (+0.40%) ⬆️
... and 9 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 72069bf...f8a196c. Read the comment docs.

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.

Good enough for me. LGTM. Lets get another reviewer, but feel free to squash the fixup commits down to clean up the git history in the meantime.

@tnull tnull force-pushed the 2022-04-honor-gossip-timestamp-filters branch from a31362a to f8a196c Compare May 3, 2022 07:13
@tnull
Copy link
Contributor Author

tnull commented May 3, 2022

Squashed!

Copy link
Contributor

@arik-so arik-so left a comment

Choose a reason for hiding this comment

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

lgtm

vec![]
let mut ret = Vec::new();
let mut pending_events = self.pending_events.lock().unwrap();
core::mem::swap(&mut ret, &mut pending_events);
Copy link
Contributor

Choose a reason for hiding this comment

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

purely out of curiosity, what's the benefit of mem::swap over drain?

Copy link
Collaborator

Choose a reason for hiding this comment

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

mem::swap exploits the Rust fact that an object's in-memory representation can always be copied for a move. Thus, this will just copy the (pointer, length, capacity) tuple from one to the other, drain(..) will (or could, I'm not sure how LLVM will optimize it in practice) actually allocate a new vec, move all the old vec elements, and then return that.

#[cfg(feature = "std")]
{
gossip_start_time = SystemTime::now().duration_since(UNIX_EPOCH).expect("Time must be > 1970").as_secs();
if should_request_full_sync {
Copy link
Contributor

@arik-so arik-so May 3, 2022

Choose a reason for hiding this comment

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

would it be more legible to write

let delta = if should_request_full_sync { 
    60 * 60 * 24 * 7 * 2 // two weeks ago
} else { 
    60 * 60 // an hour ago
};
gossip_start_time = SystemTime::now().duration_since(UNIX_EPOCH).expect("Time must be > 1970").as_secs() - delta;

?

Copy link
Collaborator

Choose a reason for hiding this comment

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

I believe it was copied from the non-test code, so presumably fine-enough.

@TheBlueMatt TheBlueMatt merged commit 171dfee into lightningdevkit:main May 3, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Honor gossip_timestamp_filter filters

4 participants