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

Support ZeroConf channel type. #1505

Conversation

tnull
Copy link
Contributor

@tnull tnull commented May 30, 2022

Closes #1502

This PR implements a ZeroConf channel type feature, which is then considered when we receive inbound open channel requests.

Note that zero confirmation channels are rejected by default, and may only get manually accepted via accept_inbound_channel_from_trusted_peer_0conf.

@@ -402,7 +402,9 @@ mod sealed {
define_feature!(47, SCIDPrivacy, [InitContext, NodeContext, ChannelTypeContext],
"Feature flags for only forwarding with SCID aliasing. Called `option_scid_alias` in the BOLTs",
set_scid_privacy_optional, set_scid_privacy_required, supports_scid_privacy, requires_scid_privacy);

define_feature!(51, ZeroConf, [ChannelTypeContext],
Copy link
Contributor Author

@tnull tnull May 30, 2022

Choose a reason for hiding this comment

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

I still need to add a comment that points out using this feature will break backwards compatibility with versions prior to 0.0.107. Probably, this comment should be added to accept_inbound_channel_from_trusted_peer_0conf?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Probably on the Event::OpenChannelRequest, there's already a similar comment for the scid privacy flag.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done with 794a6c6.

@TheBlueMatt TheBlueMatt added this to the 0.0.107 milestone May 30, 2022
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.

LGTM aside from the one issue you already noted.

@codecov-commenter
Copy link

codecov-commenter commented May 30, 2022

Codecov Report

Merging #1505 (efad02b) into main (ce7b0b4) will increase coverage by 1.26%.
The diff coverage is 94.73%.

@@            Coverage Diff             @@
##             main    #1505      +/-   ##
==========================================
+ Coverage   90.97%   92.23%   +1.26%     
==========================================
  Files          80       80              
  Lines       43081    51324    +8243     
  Branches    43081    51324    +8243     
==========================================
+ Hits        39194    47340    +8146     
- Misses       3887     3984      +97     
Impacted Files Coverage Δ
lightning/src/util/events.rs 43.78% <ø> (+10.22%) ⬆️
lightning/src/ln/priv_short_conf_tests.rs 96.60% <91.37%> (-0.49%) ⬇️
lightning/src/ln/channel.rs 92.42% <96.66%> (+3.82%) ⬆️
lightning/src/ln/channelmanager.rs 87.72% <100.00%> (+3.01%) ⬆️
lightning/src/ln/features.rs 99.46% <100.00%> (+0.01%) ⬆️
lightning/src/chain/onchaintx.rs 93.98% <0.00%> (-0.93%) ⬇️
lightning/src/ln/payment_tests.rs 99.18% <0.00%> (-0.07%) ⬇️
lightning/src/lib.rs 100.00% <0.00%> (ø)
lightning/src/ln/reorg_tests.rs 100.00% <0.00%> (ø)
lightning/src/ln/monitor_tests.rs 100.00% <0.00%> (ø)
... and 11 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 ce7b0b4...efad02b. Read the comment docs.

TheBlueMatt
TheBlueMatt previously approved these changes May 30, 2022
@tnull
Copy link
Contributor Author

tnull commented May 30, 2022

Squashed.

@valentinewallace
Copy link
Contributor

Test? 😛

@@ -466,6 +466,10 @@ pub enum Event {
/// the resulting [`ChannelManager`] will not be readable by versions of LDK prior to
/// 0.0.106.
///
/// Also note that if [`ChannelTypeFeatures::supports_zero_conf`] returns true on this type,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Maybe also something about either accept the channel via accept_inbound_channel_from_trusted_peer_0conf or the channel will be force-closed?

@valentinewallace
Copy link
Contributor

Thanks for the features test.

In channel.rs, I see:

			let mut allowed_type = ChannelTypeFeatures::only_static_remote_key();
			if *channel_type != allowed_type {
				allowed_type.set_scid_privacy_required();
				if *channel_type != allowed_type {
					return Err(ChannelError::Close("Channel Type was not understood".to_owned()));
				}

I'm not sure if we'll accept channels with the 0-conf feature bit set, based on this? Either way, would be nice to either test or file an issue for a test for this case

@tnull
Copy link
Contributor Author

tnull commented May 31, 2022

Thanks for the features test.

In channel.rs, I see:

			let mut allowed_type = ChannelTypeFeatures::only_static_remote_key();
			if *channel_type != allowed_type {
				allowed_type.set_scid_privacy_required();
				if *channel_type != allowed_type {
					return Err(ChannelError::Close("Channel Type was not understood".to_owned()));
				}

I'm not sure if we'll accept channels with the 0-conf feature bit set, based on this? Either way, would be nice to either test or file an issue for a test for this case

Thanks, I'll have a look and add a proper test case.

allowed_type.set_scid_privacy_required();
if *channel_type != allowed_type {
if *channel_type != ChannelTypeFeatures::only_static_remote_key() {
if !channel_type.requires_scid_privacy() && !channel_type.requires_zero_conf() {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Wont this change imply we accept a channel_type that has some other unknown bit set?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Argh, right. Fixed this with 7f8bab5.

@tnull
Copy link
Contributor Author

tnull commented May 31, 2022

I'd generally like to add yet another test case in channelmanager.rs to check whether the behavior w.r.t. acceptance is the right one. However, I'm currently not sure what the best way to go about it would be, without making the channel type configurable.

@tnull tnull force-pushed the 2022-05-support-0conf-channeltype branch from a5d577f to 3c13abe Compare May 31, 2022 22:09
@tnull
Copy link
Contributor Author

tnull commented Jun 1, 2022

I'd generally like to add yet another test case in channelmanager.rs to check whether the behavior w.r.t. acceptance is the right one. However, I'm currently not sure what the best way to go about it would be, without making the channel type configurable.

Done with 9ca9dd0.

return Err(ChannelError::Close("Channel Type field contains unknown bits".to_owned()));
}

// We currently only allow three channel types, so write it all out here - we allow
Copy link
Collaborator

Choose a reason for hiding this comment

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

Technically 4 - you can also do SRC and privacy+0conf

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

nodes[1].node.handle_open_channel(&nodes[0].node.get_our_node_id(), InitFeatures::known(), &open_channel_msg);

let events = nodes[1].node.get_and_clear_pending_msg_events();
println!("EVENTS {:?}", events);
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit rm.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed in cfab760.

@tnull tnull force-pushed the 2022-05-support-0conf-channeltype branch 2 times, most recently from 526422a to cfab760 Compare June 1, 2022 00:43
@tnull
Copy link
Contributor Author

tnull commented Jun 1, 2022

Squashed.

/// the resulting [`ChannelManager`] will not be readable by versions of LDK prior to
/// 0.0.107. Channels setting this type also need to get manually accepted via
/// [`crate::ln::channelmanager::ChannelManager::accept_inbound_channel_from_trusted_peer_0conf`],
/// or will be rejected otherwise.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Hmm, so its not technically "rejected otherwise" the accept_inbound_channel call fails, and the channel is still there, which kinda sucks. Maybe we just force-close automatically if you call accept_inbound_channel?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

AFAICT, if the user calls the wrong method and the channel keeps 'lingering' in our channel_state, we would basically have the same situation as before he called. I'm not sure how this would be different from the 'normal' operation of lingering incoming channels when we set manually_accept_channels?
If we want to get rid of such stale request, we might generally need some kind of garbage collection for the state?

Also not entirely sure what 'force-close' would mean in this context? We'd probably just send an error over the wire and remove the channel from channel_state?

Copy link
Collaborator

Choose a reason for hiding this comment

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

AFAICT, if the user calls the wrong method and the channel keeps 'lingering' in our channel_state, we would basically have the same situation as before he called. I'm not sure how this would be different from the 'normal' operation of lingering incoming channels when we set manually_accept_channels?

Correct, though its pretty different in that the user handled the OpenChannelRequest event, they don't expect to have to handle it twice. In general, our users aren't going to manually handle an error - if we return an APIError here, the users' code probably just won't do anything else. The counterparty, however, may be waiting for an error to retry the channel open (this is the expected behavior for a channel_type "negotiation").

We can (generally) assume that users will try to handle OpenChannelRequest, my concern her is that they won't handle an error handling it.

If we want to get rid of such stale request, we might generally need some kind of garbage collection for the state?

Agreed - in general we should eventually time-out requests, but such requests may take some time to process (external API calls to third-party providers are not unlikely, I believe), so we have to be kinda conservative here, likely even too conservative for moving the channel_type negotiation forward.

Also not entirely sure what 'force-close' would mean in this context? We'd probably just send an error over the wire and remove the channel from channel_state?

Yep, that. I generally use "force-close" to mean "send error message and close channel", though, indeed, there's no broadcast associated here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Alright, I now reject the channel in accept_inbound_channel if it is 0conf. Also added a note explaining this behavior.

@tnull tnull force-pushed the 2022-05-support-0conf-channeltype branch from cfa656e to 6ec1d0a Compare June 1, 2022 20:03
@tnull
Copy link
Contributor Author

tnull commented Jun 1, 2022

Squashed again.

@tnull tnull force-pushed the 2022-05-support-0conf-channeltype branch from a28a5ae to efad02b Compare June 2, 2022 00:05
@TheBlueMatt
Copy link
Collaborator

Feel free to squash again (or split the commits up a bit).

@tnull
Copy link
Contributor Author

tnull commented Jun 2, 2022

Squashed.

@valentinewallace valentinewallace merged commit ab20284 into lightningdevkit:main Jun 2, 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.

Support 0Conf Feature
4 participants