Skip to content

Use UserConfig to determine advertised InitFeatures by ChannelManager #1946

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

Conversation

wpaulino
Copy link
Contributor

This is purely a refactor that does not change the InitFeatures advertised by a ChannelManager. This allows users to configure which features should be advertised based on the values of UserConfig. While there aren't any existing features currently leveraging this behavior, it will be used by the upcoming anchors_zero_fee_htlc_tx feature.

The UserConfig dependency on provided_init_features caused most callsites of the main test methods responsible for opening channels to be updated. This commit foregos that completely by no longer requiring the InitFeatures of each side to be provided to these methods. The methods already require a reference to each node's ChannelManager to open the channel, so we use that same reference to obtain their InitFeatures. A way to override such features was required for some tests, so a new override_init_features config option now exists on the test harness.

Motivated by the discussion in #1860 (comment).

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.

Nice, thanks. Honestly probably should have done this when the code was added, but oh well. One comment but otherwise LGTM, note CI is failing.

@wpaulino wpaulino force-pushed the init-features-user-config branch 3 times, most recently from 07be198 to a6c69b0 Compare January 13, 2023 20:04
let create_chan_id = node_a.node.create_channel(node_b.node.get_our_node_id(), channel_value, push_msat, 42, None).unwrap();
let open_channel_msg = get_event_msg!(node_a, MessageSendEvent::SendOpenChannel, node_b.node.get_our_node_id());
assert_eq!(open_channel_msg.temporary_channel_id, create_chan_id);
assert_eq!(node_a.node.list_channels().iter().find(|channel| channel.channel_id == create_chan_id).unwrap().user_channel_id, 42);
let a_flags = node_a.override_init_features.borrow().clone().unwrap_or_else(|| node_a.node.init_features());
Copy link
Contributor

Choose a reason for hiding this comment

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

wouldn't unwrap_or do the trick?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

With unwrap_or, its argument will always be evaluated, whereas with unwrap_or_else, it's only evaluated if None. Doesn't really matter since it's just a test.

Copy link
Contributor

Choose a reason for hiding this comment

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

Good point. I'd lean towards legibility > (imo premature) optimization in this case, but am fine either way.

@wpaulino wpaulino force-pushed the init-features-user-config branch from a6c69b0 to 69fd9d0 Compare January 13, 2023 23:12
@codecov-commenter
Copy link

codecov-commenter commented Jan 13, 2023

Codecov Report

Base: 90.73% // Head: 90.70% // Decreases project coverage by -0.03% ⚠️

Coverage data is based on head (69fd9d0) compared to base (ac6e0b3).
Patch coverage: 98.64% of modified lines in pull request are covered.

❗ Current head 69fd9d0 differs from pull request most recent head abf4e79. Consider uploading reports for the commit abf4e79 to get more accurate results

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1946      +/-   ##
==========================================
- Coverage   90.73%   90.70%   -0.04%     
==========================================
  Files          97       97              
  Lines       50548    50568      +20     
  Branches    50548    50568      +20     
==========================================
+ Hits        45864    45866       +2     
- Misses       4684     4702      +18     
Impacted Files Coverage Δ
lightning/src/ln/functional_tests.rs 96.91% <ø> (-0.15%) ⬇️
lightning/src/util/test_utils.rs 71.30% <50.00%> (-0.22%) ⬇️
lightning/src/ln/channelmanager.rs 87.11% <94.54%> (-0.06%) ⬇️
lightning/src/routing/router.rs 90.91% <94.87%> (+<0.01%) ⬆️
lightning/src/ln/functional_test_utils.rs 91.49% <96.42%> (+0.02%) ⬆️
lightning-background-processor/src/lib.rs 95.45% <100.00%> (ø)
lightning-invoice/src/payment.rs 89.48% <100.00%> (ø)
lightning-invoice/src/utils.rs 97.76% <100.00%> (ø)
lightning-persister/src/lib.rs 93.49% <100.00%> (ø)
lightning/src/chain/chainmonitor.rs 97.82% <100.00%> (-0.01%) ⬇️
... and 32 more

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

☔ View full report at Codecov.
📢 Do you have feedback about the report comment? Let us know in this issue.

@TheBlueMatt
Copy link
Collaborator

Needs rebase, sorry.

This is purely a refactor that does not change the InitFeatures
advertised by a ChannelManager. This allows users to configure which
features should be advertised based on the values of `UserConfig`. While
there aren't any existing features currently leveraging this behavior,
it will be used by the upcoming anchors_zero_fee_htlc_tx feature.

The UserConfig dependency on provided_init_features caused most
callsites of the main test methods responsible for opening channels to
be updated. This commit foregos that completely by no longer requiring
the InitFeatures of each side to be provided to these methods. The
methods already require a reference to each node's ChannelManager to
open the channel, so we use that same reference to obtain their
InitFeatures. A way to override such features was required for some
tests, so a new `override_init_features` config option now exists on
the test harness.
@arik-so
Copy link
Contributor

arik-so commented Jan 14, 2023

Sorry about the labels. Looks good to me, but I'll rereview after rebase.

@wpaulino wpaulino force-pushed the init-features-user-config branch from 69fd9d0 to abf4e79 Compare January 14, 2023 22:01
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.

We should also do #1954.

@@ -5348,7 +5348,7 @@ impl<Signer: Sign> Channel<Signer> {
let were_node_one = node_id.serialize()[..] < self.counterparty_node_id.serialize()[..];

let msg = msgs::UnsignedChannelAnnouncement {
features: channelmanager::provided_channel_features(),
features: channelmanager::provided_channel_features(&user_config),
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is fine for now, but we'll need to tweak this further once we get to things like PTLC as we'll need the provided-channel-flags to include some info about the channel_type as well.

let mut accept_channel = get_event_msg!(nodes[1], MessageSendEvent::SendAcceptChannel, nodes[0].node.get_our_node_id());
accept_channel.to_self_delay = 200;
nodes[0].node.handle_accept_channel(&nodes[1].node.get_our_node_id(), channelmanager::provided_init_features(), &accept_channel);
nodes[0].node.handle_accept_channel(&nodes[1].node.get_our_node_id(), nodes[0].node.init_features(), &accept_channel);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Heh, finally caught one with the wrong node passed :)

@TheBlueMatt TheBlueMatt merged commit de783e0 into lightningdevkit:main Jan 15, 2023
@wpaulino wpaulino deleted the init-features-user-config branch January 16, 2023 20:24
@wpaulino wpaulino mentioned this pull request Mar 3, 2023
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.

4 participants