Skip to content

Commit 3bbd4f2

Browse files
committed
Move commit_upfront_shutdown_pubkey to ChannelHandshakeConfig
As like the previous commit, `commit_upfront_shutdown_pubkey` is another static field that cannot change after the initial channel handshake. We therefore move it out from its existing place in `ChannelConfig`. Here, we don't need to store the bit anywhere else as we did with `announced_channel`, since this bit is what determines whether a `Channel` stores a `shutdown_scriptpubkey` or not.
1 parent 3e21259 commit 3bbd4f2

File tree

4 files changed

+29
-24
lines changed

4 files changed

+29
-24
lines changed

lightning/src/ln/chanmon_update_fail_tests.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -2541,7 +2541,7 @@ fn test_temporary_error_during_shutdown() {
25412541
// Test that temporary failures when updating the monitor's shutdown script delay cooperative
25422542
// close.
25432543
let mut config = test_default_channel_config();
2544-
config.channel_options.commit_upfront_shutdown_pubkey = false;
2544+
config.own_channel_config.commit_upfront_shutdown_pubkey = false;
25452545

25462546
let chanmon_cfgs = create_chanmon_cfgs(2);
25472547
let node_cfgs = create_node_cfgs(2, &chanmon_cfgs);
@@ -2596,7 +2596,7 @@ fn test_permanent_error_during_sending_shutdown() {
25962596
// Test that permanent failures when updating the monitor's shutdown script result in a force
25972597
// close when initiating a cooperative close.
25982598
let mut config = test_default_channel_config();
2599-
config.channel_options.commit_upfront_shutdown_pubkey = false;
2599+
config.own_channel_config.commit_upfront_shutdown_pubkey = false;
26002600

26012601
let chanmon_cfgs = create_chanmon_cfgs(2);
26022602
let node_cfgs = create_node_cfgs(2, &chanmon_cfgs);
@@ -2617,7 +2617,7 @@ fn test_permanent_error_during_handling_shutdown() {
26172617
// Test that permanent failures when updating the monitor's shutdown script result in a force
26182618
// close when handling a cooperative close.
26192619
let mut config = test_default_channel_config();
2620-
config.channel_options.commit_upfront_shutdown_pubkey = false;
2620+
config.own_channel_config.commit_upfront_shutdown_pubkey = false;
26212621

26222622
let chanmon_cfgs = create_chanmon_cfgs(2);
26232623
let node_cfgs = create_node_cfgs(2, &chanmon_cfgs);

lightning/src/ln/channel.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -919,7 +919,7 @@ impl<Signer: Sign> Channel<Signer> {
919919
let mut secp_ctx = Secp256k1::new();
920920
secp_ctx.seeded_randomize(&keys_provider.get_secure_random_bytes());
921921

922-
let shutdown_scriptpubkey = if config.channel_options.commit_upfront_shutdown_pubkey {
922+
let shutdown_scriptpubkey = if config.own_channel_config.commit_upfront_shutdown_pubkey {
923923
Some(keys_provider.get_shutdown_scriptpubkey())
924924
} else { None };
925925

@@ -1252,7 +1252,7 @@ impl<Signer: Sign> Channel<Signer> {
12521252
}
12531253
} else { None };
12541254

1255-
let shutdown_scriptpubkey = if config.channel_options.commit_upfront_shutdown_pubkey {
1255+
let shutdown_scriptpubkey = if config.own_channel_config.commit_upfront_shutdown_pubkey {
12561256
Some(keys_provider.get_shutdown_scriptpubkey())
12571257
} else { None };
12581258

lightning/src/ln/shutdown_tests.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -411,7 +411,7 @@ fn test_upfront_shutdown_script() {
411411
let mut config = UserConfig::default();
412412
config.own_channel_config.announced_channel = true;
413413
config.peer_channel_config_limits.force_announced_channel_preference = false;
414-
config.channel_options.commit_upfront_shutdown_pubkey = false;
414+
config.own_channel_config.commit_upfront_shutdown_pubkey = false;
415415
let user_cfgs = [None, Some(config), None];
416416
let chanmon_cfgs = create_chanmon_cfgs(3);
417417
let node_cfgs = create_node_cfgs(3, &chanmon_cfgs);
@@ -576,7 +576,7 @@ fn test_segwit_v0_shutdown_script() {
576576
let mut config = UserConfig::default();
577577
config.own_channel_config.announced_channel = true;
578578
config.peer_channel_config_limits.force_announced_channel_preference = false;
579-
config.channel_options.commit_upfront_shutdown_pubkey = false;
579+
config.own_channel_config.commit_upfront_shutdown_pubkey = false;
580580
let user_cfgs = [None, Some(config), None];
581581
let chanmon_cfgs = create_chanmon_cfgs(3);
582582
let node_cfgs = create_node_cfgs(3, &chanmon_cfgs);
@@ -611,7 +611,7 @@ fn test_anysegwit_shutdown_script() {
611611
let mut config = UserConfig::default();
612612
config.own_channel_config.announced_channel = true;
613613
config.peer_channel_config_limits.force_announced_channel_preference = false;
614-
config.channel_options.commit_upfront_shutdown_pubkey = false;
614+
config.own_channel_config.commit_upfront_shutdown_pubkey = false;
615615
let user_cfgs = [None, Some(config), None];
616616
let chanmon_cfgs = create_chanmon_cfgs(3);
617617
let node_cfgs = create_node_cfgs(3, &chanmon_cfgs);
@@ -646,7 +646,7 @@ fn test_unsupported_anysegwit_shutdown_script() {
646646
let mut config = UserConfig::default();
647647
config.own_channel_config.announced_channel = true;
648648
config.peer_channel_config_limits.force_announced_channel_preference = false;
649-
config.channel_options.commit_upfront_shutdown_pubkey = false;
649+
config.own_channel_config.commit_upfront_shutdown_pubkey = false;
650650
let user_cfgs = [None, Some(config), None];
651651
let chanmon_cfgs = create_chanmon_cfgs(3);
652652
let mut node_cfgs = create_node_cfgs(3, &chanmon_cfgs);
@@ -688,7 +688,7 @@ fn test_invalid_shutdown_script() {
688688
let mut config = UserConfig::default();
689689
config.own_channel_config.announced_channel = true;
690690
config.peer_channel_config_limits.force_announced_channel_preference = false;
691-
config.channel_options.commit_upfront_shutdown_pubkey = false;
691+
config.own_channel_config.commit_upfront_shutdown_pubkey = false;
692692
let user_cfgs = [None, Some(config), None];
693693
let chanmon_cfgs = create_chanmon_cfgs(3);
694694
let node_cfgs = create_node_cfgs(3, &chanmon_cfgs);

lightning/src/util/config.rs

+19-14
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ pub struct ChannelHandshakeConfig {
8787
///
8888
/// If this option is set, channels may be created that will not be readable by LDK versions
8989
/// prior to 0.0.106, causing [`ChannelManager`]'s read method to return a
90-
/// [`DecodeError:InvalidValue`].
90+
/// [`DecodeError::InvalidValue`].
9191
///
9292
/// Note that setting this to true does *not* prevent us from opening channels with
9393
/// counterparties that do not support the `scid_alias` option; we will simply fall back to a
@@ -100,7 +100,7 @@ pub struct ChannelHandshakeConfig {
100100
/// Default value: false. This value is likely to change to true in the future.
101101
///
102102
/// [`ChannelManager`]: crate::ln::channelmanager::ChannelManager
103-
/// [`DecodeError:InvalidValue`]: crate::ln::msgs::DecodeError::InvalidValue
103+
/// [`DecodeError::InvalidValue`]: crate::ln::msgs::DecodeError::InvalidValue
104104
pub negotiate_scid_privacy: bool,
105105
/// Set to announce the channel publicly and notify all nodes that they can route via this
106106
/// channel.
@@ -112,6 +112,20 @@ pub struct ChannelHandshakeConfig {
112112
///
113113
/// Default value: false.
114114
pub announced_channel: bool,
115+
/// When set, we commit to an upfront shutdown_pubkey at channel open. If our counterparty
116+
/// supports it, they will then enforce the mutual-close output to us matches what we provided
117+
/// at intialization, preventing us from closing to an alternate pubkey.
118+
///
119+
/// This is set to true by default to provide a slight increase in security, though ultimately
120+
/// any attacker who is able to take control of a channel can just as easily send the funds via
121+
/// lightning payments, so we never require that our counterparties support this option.
122+
///
123+
/// The upfront key committed is provided from [`KeysInterface::get_shutdown_scriptpubkey`].
124+
///
125+
/// Default value: true.
126+
///
127+
/// [`KeysInterface::get_shutdown_scriptpubkey`]: crate::chain::keysinterface::KeysInterface::get_shutdown_scriptpubkey
128+
pub commit_upfront_shutdown_pubkey: bool,
115129
}
116130

117131
impl Default for ChannelHandshakeConfig {
@@ -123,6 +137,7 @@ impl Default for ChannelHandshakeConfig {
123137
max_inbound_htlc_value_in_flight_percent_of_channel: 10,
124138
negotiate_scid_privacy: false,
125139
announced_channel: false,
140+
commit_upfront_shutdown_pubkey: true,
126141
}
127142
}
128143
}
@@ -278,18 +293,8 @@ pub struct ChannelConfig {
278293
pub cltv_expiry_delta: u16,
279294
/// Deprecated, use [`ChannelHandshakeConfig::announced_channel`] instead.
280295
pub(crate) announced_channel: bool,
281-
/// When set, we commit to an upfront shutdown_pubkey at channel open. If our counterparty
282-
/// supports it, they will then enforce the mutual-close output to us matches what we provided
283-
/// at intialization, preventing us from closing to an alternate pubkey.
284-
///
285-
/// This is set to true by default to provide a slight increase in security, though ultimately
286-
/// any attacker who is able to take control of a channel can just as easily send the funds via
287-
/// lightning payments, so we never require that our counterparties support this option.
288-
///
289-
/// This cannot be changed after a channel has been initialized.
290-
///
291-
/// Default value: true.
292-
pub commit_upfront_shutdown_pubkey: bool,
296+
/// Deprecated, use [`ChannelHandshakeConfig::commit_upfront_shutdown_pubkey`] instead.
297+
pub(crate) commit_upfront_shutdown_pubkey: bool,
293298
/// Limit our total exposure to in-flight HTLCs which are burned to fees as they are too
294299
/// small to claim on-chain.
295300
///

0 commit comments

Comments
 (0)