Skip to content

Commit

Permalink
Support the channel_type feature bit.
Browse files Browse the repository at this point in the history
Note that this feature bit does absolutely nothing. We signal it
(as we already support channel type negotiation), but do not bother
to look to see if peers support it, as we don't care - we simply
look for the TLV entry and deduce if a peer supports channel type
negotiation from that.

The only behavioral change at all here is that we don't barf if a
peer sets channel type negotiation to required via the feature bit
(instead of failing the channel at open-time), but of course no
implementations do this, and likely won't for some time (if ever -
you can simply fail channels with unknown types later, and there's
no reason to refuse connections, really).

As defined in lightning/bolts#906
  • Loading branch information
TheBlueMatt committed Dec 7, 2021
1 parent aa5e5f9 commit 8f4a22f
Showing 1 changed file with 22 additions and 2 deletions.
24 changes: 22 additions & 2 deletions lightning/src/ln/features.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,10 @@ mod sealed {
,
// Byte 3
,
// Byte 4
,
// Byte 5
,
],
optional_features: [
// Byte 0
Expand All @@ -136,6 +140,10 @@ mod sealed {
BasicMPP,
// Byte 3
ShutdownAnySegwit,
// Byte 4
,
// Byte 5
ChannelType,
],
});
define_context!(NodeContext {
Expand Down Expand Up @@ -167,7 +175,7 @@ mod sealed {
// Byte 4
,
// Byte 5
,
ChannelType,
// Byte 6
Keysend,
],
Expand Down Expand Up @@ -379,6 +387,9 @@ mod sealed {
define_feature!(27, ShutdownAnySegwit, [InitContext, NodeContext],
"Feature flags for `opt_shutdown_anysegwit`.", set_shutdown_any_segwit_optional,
set_shutdown_any_segwit_required, supports_shutdown_anysegwit, requires_shutdown_anysegwit);
define_feature!(45, ChannelType, [InitContext, NodeContext],
"Feature flags for `option_channel_type`.", set_channel_type_optional,
set_channel_type_required, supports_channel_type, requires_channel_type);
define_feature!(55, Keysend, [NodeContext],
"Feature flags for keysend payments.", set_keysend_optional, set_keysend_required,
supports_keysend, requires_keysend);
Expand Down Expand Up @@ -807,6 +818,11 @@ mod tests {
assert!(!NodeFeatures::known().requires_basic_mpp());
assert!(!InvoiceFeatures::known().requires_basic_mpp());

assert!(InitFeatures::known().supports_channel_type());
assert!(NodeFeatures::known().supports_channel_type());
assert!(!InitFeatures::known().requires_channel_type());
assert!(!NodeFeatures::known().requires_channel_type());

assert!(InitFeatures::known().supports_shutdown_anysegwit());
assert!(NodeFeatures::known().supports_shutdown_anysegwit());

Expand Down Expand Up @@ -845,11 +861,15 @@ mod tests {
// - var_onion_optin (req) | static_remote_key (req) | payment_secret(req)
// - basic_mpp
// - opt_shutdown_anysegwit
assert_eq!(node_features.flags.len(), 4);
// -
// - option_channel_type
assert_eq!(node_features.flags.len(), 6);
assert_eq!(node_features.flags[0], 0b00000010);
assert_eq!(node_features.flags[1], 0b01010001);
assert_eq!(node_features.flags[2], 0b00000010);
assert_eq!(node_features.flags[3], 0b00001000);
assert_eq!(node_features.flags[4], 0b00000000);
assert_eq!(node_features.flags[5], 0b00100000);
}

// Check that cleared flags are kept blank when converting back:
Expand Down

0 comments on commit 8f4a22f

Please sign in to comment.