From: Wilmer Paulino Date: Wed, 8 Jun 2022 22:40:58 +0000 (-0700) Subject: Move commit_upfront_shutdown_pubkey to ChannelHandshakeConfig X-Git-Tag: v0.0.109~19^2~1 X-Git-Url: http://git.bitcoin.ninja/?a=commitdiff_plain;h=8027c2ff06c790016b1a9e1d67af065c44d2995d;p=rust-lightning 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`. --- diff --git a/lightning/src/ln/chanmon_update_fail_tests.rs b/lightning/src/ln/chanmon_update_fail_tests.rs index 495b50742..710027706 100644 --- a/lightning/src/ln/chanmon_update_fail_tests.rs +++ b/lightning/src/ln/chanmon_update_fail_tests.rs @@ -2541,7 +2541,7 @@ fn test_temporary_error_during_shutdown() { // Test that temporary failures when updating the monitor's shutdown script delay cooperative // close. let mut config = test_default_channel_config(); - config.channel_options.commit_upfront_shutdown_pubkey = false; + config.own_channel_config.commit_upfront_shutdown_pubkey = false; let chanmon_cfgs = create_chanmon_cfgs(2); let node_cfgs = create_node_cfgs(2, &chanmon_cfgs); @@ -2596,7 +2596,7 @@ fn test_permanent_error_during_sending_shutdown() { // Test that permanent failures when updating the monitor's shutdown script result in a force // close when initiating a cooperative close. let mut config = test_default_channel_config(); - config.channel_options.commit_upfront_shutdown_pubkey = false; + config.own_channel_config.commit_upfront_shutdown_pubkey = false; let chanmon_cfgs = create_chanmon_cfgs(2); let node_cfgs = create_node_cfgs(2, &chanmon_cfgs); @@ -2617,7 +2617,7 @@ fn test_permanent_error_during_handling_shutdown() { // Test that permanent failures when updating the monitor's shutdown script result in a force // close when handling a cooperative close. let mut config = test_default_channel_config(); - config.channel_options.commit_upfront_shutdown_pubkey = false; + config.own_channel_config.commit_upfront_shutdown_pubkey = false; let chanmon_cfgs = create_chanmon_cfgs(2); let node_cfgs = create_node_cfgs(2, &chanmon_cfgs); diff --git a/lightning/src/ln/channel.rs b/lightning/src/ln/channel.rs index c2b33759f..c9e500007 100644 --- a/lightning/src/ln/channel.rs +++ b/lightning/src/ln/channel.rs @@ -918,7 +918,7 @@ impl Channel { let mut secp_ctx = Secp256k1::new(); secp_ctx.seeded_randomize(&keys_provider.get_secure_random_bytes()); - let shutdown_scriptpubkey = if config.channel_options.commit_upfront_shutdown_pubkey { + let shutdown_scriptpubkey = if config.own_channel_config.commit_upfront_shutdown_pubkey { Some(keys_provider.get_shutdown_scriptpubkey()) } else { None }; @@ -1239,7 +1239,7 @@ impl Channel { } } else { None }; - let shutdown_scriptpubkey = if config.channel_options.commit_upfront_shutdown_pubkey { + let shutdown_scriptpubkey = if config.own_channel_config.commit_upfront_shutdown_pubkey { Some(keys_provider.get_shutdown_scriptpubkey()) } else { None }; diff --git a/lightning/src/ln/shutdown_tests.rs b/lightning/src/ln/shutdown_tests.rs index 3e45c2c76..edfa596f6 100644 --- a/lightning/src/ln/shutdown_tests.rs +++ b/lightning/src/ln/shutdown_tests.rs @@ -411,7 +411,7 @@ fn test_upfront_shutdown_script() { let mut config = UserConfig::default(); config.own_channel_config.announced_channel = true; config.peer_channel_config_limits.force_announced_channel_preference = false; - config.channel_options.commit_upfront_shutdown_pubkey = false; + config.own_channel_config.commit_upfront_shutdown_pubkey = false; let user_cfgs = [None, Some(config), None]; let chanmon_cfgs = create_chanmon_cfgs(3); let node_cfgs = create_node_cfgs(3, &chanmon_cfgs); @@ -576,7 +576,7 @@ fn test_segwit_v0_shutdown_script() { let mut config = UserConfig::default(); config.own_channel_config.announced_channel = true; config.peer_channel_config_limits.force_announced_channel_preference = false; - config.channel_options.commit_upfront_shutdown_pubkey = false; + config.own_channel_config.commit_upfront_shutdown_pubkey = false; let user_cfgs = [None, Some(config), None]; let chanmon_cfgs = create_chanmon_cfgs(3); let node_cfgs = create_node_cfgs(3, &chanmon_cfgs); @@ -611,7 +611,7 @@ fn test_anysegwit_shutdown_script() { let mut config = UserConfig::default(); config.own_channel_config.announced_channel = true; config.peer_channel_config_limits.force_announced_channel_preference = false; - config.channel_options.commit_upfront_shutdown_pubkey = false; + config.own_channel_config.commit_upfront_shutdown_pubkey = false; let user_cfgs = [None, Some(config), None]; let chanmon_cfgs = create_chanmon_cfgs(3); let node_cfgs = create_node_cfgs(3, &chanmon_cfgs); @@ -646,7 +646,7 @@ fn test_unsupported_anysegwit_shutdown_script() { let mut config = UserConfig::default(); config.own_channel_config.announced_channel = true; config.peer_channel_config_limits.force_announced_channel_preference = false; - config.channel_options.commit_upfront_shutdown_pubkey = false; + config.own_channel_config.commit_upfront_shutdown_pubkey = false; let user_cfgs = [None, Some(config), None]; let chanmon_cfgs = create_chanmon_cfgs(3); let mut node_cfgs = create_node_cfgs(3, &chanmon_cfgs); @@ -688,7 +688,7 @@ fn test_invalid_shutdown_script() { let mut config = UserConfig::default(); config.own_channel_config.announced_channel = true; config.peer_channel_config_limits.force_announced_channel_preference = false; - config.channel_options.commit_upfront_shutdown_pubkey = false; + config.own_channel_config.commit_upfront_shutdown_pubkey = false; let user_cfgs = [None, Some(config), None]; let chanmon_cfgs = create_chanmon_cfgs(3); let node_cfgs = create_node_cfgs(3, &chanmon_cfgs); diff --git a/lightning/src/util/config.rs b/lightning/src/util/config.rs index 1410767f8..c2c73d8cb 100644 --- a/lightning/src/util/config.rs +++ b/lightning/src/util/config.rs @@ -87,7 +87,7 @@ pub struct ChannelHandshakeConfig { /// /// If this option is set, channels may be created that will not be readable by LDK versions /// prior to 0.0.106, causing [`ChannelManager`]'s read method to return a - /// [`DecodeError:InvalidValue`]. + /// [`DecodeError::InvalidValue`]. /// /// Note that setting this to true does *not* prevent us from opening channels with /// counterparties that do not support the `scid_alias` option; we will simply fall back to a @@ -100,7 +100,7 @@ pub struct ChannelHandshakeConfig { /// Default value: false. This value is likely to change to true in the future. /// /// [`ChannelManager`]: crate::ln::channelmanager::ChannelManager - /// [`DecodeError:InvalidValue`]: crate::ln::msgs::DecodeError::InvalidValue + /// [`DecodeError::InvalidValue`]: crate::ln::msgs::DecodeError::InvalidValue pub negotiate_scid_privacy: bool, /// Set to announce the channel publicly and notify all nodes that they can route via this /// channel. @@ -112,6 +112,20 @@ pub struct ChannelHandshakeConfig { /// /// Default value: false. pub announced_channel: bool, + /// When set, we commit to an upfront shutdown_pubkey at channel open. If our counterparty + /// supports it, they will then enforce the mutual-close output to us matches what we provided + /// at intialization, preventing us from closing to an alternate pubkey. + /// + /// This is set to true by default to provide a slight increase in security, though ultimately + /// any attacker who is able to take control of a channel can just as easily send the funds via + /// lightning payments, so we never require that our counterparties support this option. + /// + /// The upfront key committed is provided from [`KeysInterface::get_shutdown_scriptpubkey`]. + /// + /// Default value: true. + /// + /// [`KeysInterface::get_shutdown_scriptpubkey`]: crate::chain::keysinterface::KeysInterface::get_shutdown_scriptpubkey + pub commit_upfront_shutdown_pubkey: bool, } impl Default for ChannelHandshakeConfig { @@ -123,6 +137,7 @@ impl Default for ChannelHandshakeConfig { max_inbound_htlc_value_in_flight_percent_of_channel: 10, negotiate_scid_privacy: false, announced_channel: false, + commit_upfront_shutdown_pubkey: true, } } }