Skip to content

Commit 4769b94

Browse files
author
Antoine Riard
committed
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
1 parent 675cf4a commit 4769b94

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

src/ln/channel.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3081,7 +3081,7 @@ impl Channel {
30813081
htlc_basepoint: PublicKey::from_secret_key(&self.secp_ctx, &self.local_keys.htlc_base_key),
30823082
first_per_commitment_point: PublicKey::from_secret_key(&self.secp_ctx, &local_commitment_secret),
30833083
channel_flags: if self.config.announced_channel {1} else {0},
3084-
shutdown_scriptpubkey: OptionalField::Absent
3084+
shutdown_scriptpubkey: OptionalField::Present(if self.config.commit_upfront_shutdown_pubkey { self.get_closing_scriptpubkey() } else { Builder::new().into_script() })
30853085
}
30863086
}
30873087

@@ -3113,7 +3113,7 @@ impl Channel {
31133113
delayed_payment_basepoint: PublicKey::from_secret_key(&self.secp_ctx, &self.local_keys.delayed_payment_base_key),
31143114
htlc_basepoint: PublicKey::from_secret_key(&self.secp_ctx, &self.local_keys.htlc_base_key),
31153115
first_per_commitment_point: PublicKey::from_secret_key(&self.secp_ctx, &local_commitment_secret),
3116-
shutdown_scriptpubkey: OptionalField::Absent
3116+
shutdown_scriptpubkey: OptionalField::Present(if self.config.commit_upfront_shutdown_pubkey { self.get_closing_scriptpubkey() } else { Builder::new().into_script() })
31173117
}
31183118
}
31193119

src/util/config.rs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,14 @@ pub struct ChannelConfig {
129129
///
130130
/// This cannot be changed after the initial channel handshake.
131131
pub announced_channel: bool,
132+
/// Set to commit to an upfront shutdown_pubkey at channel opening. In case of mutual
133+
/// closing, the other peer will check that our closing transction output is encumbered
134+
/// by the provided script.
135+
///
136+
/// We set it by default as this ensure greater security to the user funds.
137+
///
138+
/// This cannot be changed after channel opening.
139+
pub commit_upfront_shutdown_pubkey: bool
132140
}
133141

134142
impl ChannelConfig {
@@ -137,12 +145,14 @@ impl ChannelConfig {
137145
ChannelConfig {
138146
fee_proportional_millionths: 0,
139147
announced_channel: false,
148+
commit_upfront_shutdown_pubkey: true,
140149
}
141150
}
142151
}
143152

144153
//Add write and readable traits to channelconfig
145-
impl_writeable!(ChannelConfig, 8+1, {
154+
impl_writeable!(ChannelConfig, 8+1+1, {
146155
fee_proportional_millionths,
147-
announced_channel
156+
announced_channel,
157+
commit_upfront_shutdown_pubkey
148158
});

0 commit comments

Comments
 (0)