From 4769b944de50f3819b4252353345009b1d810e90 Mon Sep 17 00:00:00 2001 From: Antoine Riard Date: Tue, 9 Jul 2019 14:44:17 -0400 Subject: [PATCH] Implement option_upfront_shutdown_script user-side We use user config to decide to commit to closing script in open_channel/accept_channel messages. We don't check that other peer supporting the option as including script without other peer public support is borne by the protocol. If user opt-out, following protocol and due to the fact we always signal, we provide a zero-length script --- src/ln/channel.rs | 4 ++-- src/util/config.rs | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/src/ln/channel.rs b/src/ln/channel.rs index bf5d35764..4d790cfc9 100644 --- a/src/ln/channel.rs +++ b/src/ln/channel.rs @@ -3081,7 +3081,7 @@ impl Channel { htlc_basepoint: PublicKey::from_secret_key(&self.secp_ctx, &self.local_keys.htlc_base_key), first_per_commitment_point: PublicKey::from_secret_key(&self.secp_ctx, &local_commitment_secret), channel_flags: if self.config.announced_channel {1} else {0}, - shutdown_scriptpubkey: OptionalField::Absent + shutdown_scriptpubkey: OptionalField::Present(if self.config.commit_upfront_shutdown_pubkey { self.get_closing_scriptpubkey() } else { Builder::new().into_script() }) } } @@ -3113,7 +3113,7 @@ impl Channel { delayed_payment_basepoint: PublicKey::from_secret_key(&self.secp_ctx, &self.local_keys.delayed_payment_base_key), htlc_basepoint: PublicKey::from_secret_key(&self.secp_ctx, &self.local_keys.htlc_base_key), first_per_commitment_point: PublicKey::from_secret_key(&self.secp_ctx, &local_commitment_secret), - shutdown_scriptpubkey: OptionalField::Absent + shutdown_scriptpubkey: OptionalField::Present(if self.config.commit_upfront_shutdown_pubkey { self.get_closing_scriptpubkey() } else { Builder::new().into_script() }) } } diff --git a/src/util/config.rs b/src/util/config.rs index f3b574b93..e1a7e5972 100644 --- a/src/util/config.rs +++ b/src/util/config.rs @@ -129,6 +129,14 @@ pub struct ChannelConfig { /// /// This cannot be changed after the initial channel handshake. pub announced_channel: bool, + /// Set to commit to an upfront shutdown_pubkey at channel opening. In case of mutual + /// closing, the other peer will check that our closing transction output is encumbered + /// by the provided script. + /// + /// We set it by default as this ensure greater security to the user funds. + /// + /// This cannot be changed after channel opening. + pub commit_upfront_shutdown_pubkey: bool } impl ChannelConfig { @@ -137,12 +145,14 @@ impl ChannelConfig { ChannelConfig { fee_proportional_millionths: 0, announced_channel: false, + commit_upfront_shutdown_pubkey: true, } } } //Add write and readable traits to channelconfig -impl_writeable!(ChannelConfig, 8+1, { +impl_writeable!(ChannelConfig, 8+1+1, { fee_proportional_millionths, - announced_channel + announced_channel, + commit_upfront_shutdown_pubkey }); -- 2.39.5