]> git.bitcoin.ninja Git - rust-lightning/commitdiff
Move commit_upfront_shutdown_pubkey to ChannelHandshakeConfig
authorWilmer Paulino <wilmer.paulino@gmail.com>
Wed, 8 Jun 2022 22:40:58 +0000 (15:40 -0700)
committerWilmer Paulino <wilmer.paulino@gmail.com>
Thu, 9 Jun 2022 23:18:01 +0000 (16:18 -0700)
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`.

lightning/src/ln/chanmon_update_fail_tests.rs
lightning/src/ln/channel.rs
lightning/src/ln/shutdown_tests.rs
lightning/src/util/config.rs

index 495b507426c19bd7f31d6709da30db79c13f0dd9..710027706b066501c1b59e03a19967a869304599 100644 (file)
@@ -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);
index c2b33759f40df48410dc47bad43f5791620e3ef5..c9e5000073249deea92b746131270b9ac9a9369e 100644 (file)
@@ -918,7 +918,7 @@ impl<Signer: Sign> Channel<Signer> {
                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<Signer: Sign> Channel<Signer> {
                        }
                } 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 };
 
index 3e45c2c7681b13e2a554ade28ec0239c8181489e..edfa596f685db685a492906c9800dfcea5e74168 100644 (file)
@@ -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);
index 1410767f894934e9b37dd1991e82d83bd42c4cee..c2c73d8cb6c8bffb589a23e7c8e55d8725696922 100644 (file)
@@ -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,
                }
        }
 }