From c2cf1afb3e587e86b716a7b5c38ed4f4e174787e Mon Sep 17 00:00:00 2001 From: Elias Rohrer Date: Mon, 30 May 2022 14:04:12 -0700 Subject: [PATCH] Implement `ZeroConf` channel type. --- lightning/src/ln/channelmanager.rs | 9 ++++++++- lightning/src/ln/features.rs | 6 ++++-- lightning/src/util/events.rs | 4 ++++ 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/lightning/src/ln/channelmanager.rs b/lightning/src/ln/channelmanager.rs index 17a52e29..d557eb90 100644 --- a/lightning/src/ln/channelmanager.rs +++ b/lightning/src/ln/channelmanager.rs @@ -4252,7 +4252,11 @@ impl ChannelMana if *counterparty_node_id != channel.get().get_counterparty_node_id() { return Err(APIError::APIMisuseError { err: "The passed counterparty_node_id doesn't match the channel's counterparty node_id".to_owned() }); } - if accept_0conf { channel.get_mut().set_0conf(); } + if accept_0conf { + channel.get_mut().set_0conf(); + } else if channel.get().get_channel_type().requires_zero_conf() { + return Err(APIError::APIMisuseError { err: "This channel requires 0conf. Please use accept_inbound_channel_from_trusted_peer_0conf to accept.".to_owned() }); + } channel_state.pending_msg_events.push(events::MessageSendEvent::SendAcceptChannel { node_id: channel.get().get_counterparty_node_id(), msg: channel.get_mut().accept_inbound_channel(user_channel_id), @@ -4294,6 +4298,9 @@ impl ChannelMana }, hash_map::Entry::Vacant(entry) => { if !self.default_configuration.manually_accept_inbound_channels { + if channel.get_channel_type().requires_zero_conf() { + return Err(MsgHandleErrInternal::send_err_msg_no_close("No zero confirmation channels accepted".to_owned(), msg.temporary_channel_id.clone())); + } channel_state.pending_msg_events.push(events::MessageSendEvent::SendAcceptChannel { node_id: counterparty_node_id.clone(), msg: channel.accept_inbound_channel(0), diff --git a/lightning/src/ln/features.rs b/lightning/src/ln/features.rs index 5c4a94da..90db27c0 100644 --- a/lightning/src/ln/features.rs +++ b/lightning/src/ln/features.rs @@ -217,7 +217,7 @@ mod sealed { // Byte 4 , // Byte 5 - SCIDPrivacy, + SCIDPrivacy | ZeroConf, ], optional_features: [ // Byte 0 @@ -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], + "Feature flags for accepting channels with zero confirmations. Called `option_zeroconf` in the BOLTs", + set_zero_conf_optional, set_zero_conf_required, supports_zero_conf, requires_zero_conf); define_feature!(55, Keysend, [NodeContext], "Feature flags for keysend payments.", set_keysend_optional, set_keysend_required, supports_keysend, requires_keysend); diff --git a/lightning/src/util/events.rs b/lightning/src/util/events.rs index 0a886b93..6dcedec9 100644 --- a/lightning/src/util/events.rs +++ b/lightning/src/util/events.rs @@ -499,6 +499,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, + /// the resulting [`ChannelManager`] will not be readable by versions of LDK prior to + /// 0.0.107. + /// /// [`ChannelManager`]: crate::ln::channelmanager::ChannelManager channel_type: ChannelTypeFeatures, }, -- 2.30.2