Skip to content

Fetch InitFeatures from both Channel and Routing Message Handlers #1701

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 4 commits into from
Sep 9, 2022

Conversation

TheBlueMatt
Copy link
Collaborator

Based on #1699, this fetches the InitFeatures from both Channel and Routing Message Handlers and OR's them toegether. It then moves the relevant feature flags to our ChannelManager and P2PGossipHandlers.

It should tee us up nicely for #1688 to set the onion message features in the messenger itself.


fn provided_init_features(&self, _their_node_id: &PublicKey) -> InitFeatures {
let mut features = InitFeatures::empty();
features.set_gossip_queries_optional();
Copy link
Contributor

Choose a reason for hiding this comment

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

Should this also set initial_routing_sync since that is cleared in known_channel_features? Maybe it would be better to define known_channel_features as the set difference of InitFeatures::known with P2PGossipSync::provided_init_features (as a const somewhere). Then what is described in the comment on InitContext's optional features wouldn't be necessary.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

No, the fact that we were previously setting initial_routing_sync was an oversight, basically. If our peer supports gossip sync they'll ignore it, and we shouldnt be setting it on every connection anyway as it'll waste bandwidth.

Copy link
Contributor

@jkczyz jkczyz Sep 7, 2022

Choose a reason for hiding this comment

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

Should we call this out in the commit message and changelog since it is a behavioral change? Will / should we ever set initial_routing_sync now?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Sure added a note. We will no longer ever set it, no.

Copy link
Contributor

Choose a reason for hiding this comment

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

Any way we could still do something with set difference, though? Would need to special case removing initial_routing_sync, but I guess that is an unordinary feature anyhow.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I'm not sure what a set difference here gets us? If anything I'd be inclined to have the ChannelManager explicitly set all the features it wants, rather than having that logic in features.rs itself, I only didn't bother because it'd be very verbose.

I see the purpose of this change, ultimately as moving away from defining an LDK-global "known features" set, which was always a little awkward, and instead defining the "known features" set in each module that actually provides said features.

Copy link
Contributor

Choose a reason for hiding this comment

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

Discussed offline. My primary concern was to avoid relying on a comment to know when to update known_channel_features. Possible alternative could be to have a unit test asserting that the intersection of ChannelManager and P2PGossipSync's provided features is empty.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

See #1707

@TheBlueMatt TheBlueMatt force-pushed the 2022-09-feature-or branch 2 times, most recently from eced794 to ff3c0dc Compare September 7, 2022 22:08

fn provided_init_features(&self, _their_node_id: &PublicKey) -> InitFeatures {
let mut features = InitFeatures::empty();
features.set_gossip_queries_optional();
Copy link
Contributor

@jkczyz jkczyz Sep 7, 2022

Choose a reason for hiding this comment

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

Should we call this out in the commit message and changelog since it is a behavioral change? Will / should we ever set initial_routing_sync now?

@TheBlueMatt
Copy link
Collaborator Author

Rebased on #1699.

@codecov-commenter
Copy link

codecov-commenter commented Sep 8, 2022

Codecov Report

Merging #1701 (ba69536) into main (ba69536) will not change coverage.
The diff coverage is n/a.

❗ Current head ba69536 differs from pull request most recent head 1b67b0b. Consider uploading reports for the commit 1b67b0b to get more accurate results

@@           Coverage Diff           @@
##             main    #1701   +/-   ##
=======================================
  Coverage   90.87%   90.87%           
=======================================
  Files          86       86           
  Lines       46378    46378           
  Branches    46378    46378           
=======================================
  Hits        42146    42146           
  Misses       4232     4232           

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

/// Panics if `addresses` is absurdly large (more than 100).
///
/// [`get_and_clear_pending_msg_events`]: MessageSendEventsProvider::get_and_clear_pending_msg_events
pub fn broadcast_node_announcement(&self, rgb: [u8; 3], alias: [u8; 32], mut addresses: Vec<NetAddress>) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Unused import for NetAddress.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Oops, shit, this was from the previous PR. We have another warning introduced recently, I'll fix both in a followup.

jkczyz
jkczyz previously approved these changes Sep 9, 2022
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. Feel free to squash.

@valentinewallace
Copy link
Contributor

LGTM after squash

Like we now do for `NodeFeatures`, this converts to asking our
registered `ChannelMessageHandler` for our `InitFeatures` instead
of hard-coding them to the global LDK known set.

This allows handlers to set different feature bits based on what
our configuration actually supports rather than what LDK supports
in aggregate.
When we go to send an Init message to new peers, the features we
support are really a combination of all the various features our
different handlers support. This commit captures this concept by
OR'ing our InitFeatures across both our Channel and Routing
handlers.

Note that this also disables setting the `initial_routing_sync`
flag in init messages, as was intended in
e742894, per the comment added on
`clear_initial_routing_sync`, though this should not be a behavior
change in practice as nodes which support gossip queries ignore the
initial routing sync flag.
When `ChannelMessageHandler` implementations wish to return an
`InitFeatures` which contain all the known flags that are relevant
to channel handling, but not gossip handling, they currently need
to do so by manually constructing an InitFeatures with all known
flags and then clearing the ones they dont want.

Instead of spreading this logic out across the codebase, this
consolidates such construction to one place in features.rs.
@TheBlueMatt
Copy link
Collaborator Author

Squashed without further change.

@TheBlueMatt TheBlueMatt merged commit 3fb3218 into lightningdevkit:main Sep 9, 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.

4 participants