Implement `ZeroConf` channel type.
authorElias Rohrer <ero@tnull.de>
Mon, 30 May 2022 21:04:12 +0000 (14:04 -0700)
committerMatt Corallo <git@bluematt.me>
Tue, 31 May 2022 21:26:01 +0000 (21:26 +0000)
lightning/src/ln/channelmanager.rs
lightning/src/ln/features.rs
lightning/src/util/events.rs

index 17a52e29e4a5eecb210fe9d3f10c2edc4306f233..d557eb907c9f4b73968019a35d41a131787c2e04 100644 (file)
@@ -4252,7 +4252,11 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> 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<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> 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),
index 5c4a94dabfd59c367a91012719d5b5c82de609f8..90db27c0648df7a02d06afacd04b5b9b79f24def 100644 (file)
@@ -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);
index 0a886b93f6e01eb3dc70c967bc8d439ee3805b84..6dcedec9fb6a3413ad42dfe95969c7c598a201ee 100644 (file)
@@ -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,
        },