From c49c0869829dbc8cc9eaf0ab786b184c734a97fb Mon Sep 17 00:00:00 2001 From: Joy Wang Date: Mon, 17 Jan 2022 18:12:24 -0800 Subject: [PATCH] Add cltv_expiry_delta to ChannelHandshakeConfig --- lightning/src/ln/channel.rs | 12 +++---- lightning/src/ln/functional_test_utils.rs | 2 +- lightning/src/util/config.rs | 43 +++++++++++------------ 3 files changed, 28 insertions(+), 29 deletions(-) diff --git a/lightning/src/ln/channel.rs b/lightning/src/ln/channel.rs index c05c6005242..dc9493af085 100644 --- a/lightning/src/ln/channel.rs +++ b/lightning/src/ln/channel.rs @@ -775,7 +775,7 @@ impl Channel { forwarding_fee_base_msat: handshake_config.forwarding_fee_base_msat, forwarding_fee_proportional_millionths: handshake_config.forwarding_fee_proportional_millionths, - cltv_expiry_delta: config.channel_options.clone().cltv_expiry_delta, + cltv_expiry_delta: handshake_config.cltv_expiry_delta, channel_id: keys_provider.get_secure_random_bytes(), channel_state: ChannelState::OurInitSent as u32, @@ -1078,7 +1078,7 @@ impl Channel { forwarding_fee_base_msat: handshake_config.forwarding_fee_base_msat, forwarding_fee_proportional_millionths: handshake_config.forwarding_fee_proportional_millionths, - cltv_expiry_delta: local_config.cltv_expiry_delta, + cltv_expiry_delta: handshake_config.cltv_expiry_delta, channel_id: msg.temporary_channel_id, channel_state: (ChannelState::OurInitSent as u32) | (ChannelState::TheirInitSent as u32), @@ -5206,7 +5206,7 @@ impl Writeable for Channel { // Write out the old serialization for the config object. This is read by version-1 // deserializers, but we will read the version in the TLV at the end instead. self.forwarding_fee_proportional_millionths.write(writer)?; - self.config.cltv_expiry_delta.write(writer)?; + self.cltv_expiry_delta.write(writer)?; self.config.announced_channel.write(writer)?; self.config.commit_upfront_shutdown_pubkey.write(writer)?; @@ -5471,14 +5471,14 @@ impl<'a, Signer: Sign, K: Deref> ReadableArgs<(&'a K, u32)> for Channel if ver == 1 { // Read the old serialization of the ChannelConfig from version 0.0.98.handshake_config.as_mut().unwrap().forwarding_fee_proportional_millionths = Readable::read(reader)?; - config.as_mut().unwrap().cltv_expiry_delta = Readable::read(reader)?; config.as_mut().unwrap().announced_channel = Readable::read(reader)?; config.as_mut().unwrap().commit_upfront_shutdown_pubkey = Readable::read(reader)?; } else { // Read the 8 bytes of backwards-compatibility ChannelConfig data. let mut _val: u64 = Readable::read(reader)?; } - + + let cltv_expiry_delta = Readable::read(reader)?; let channel_id = Readable::read(reader)?; let channel_state = Readable::read(reader)?; let channel_value_satoshis = Readable::read(reader)?; @@ -5728,7 +5728,7 @@ impl<'a, Signer: Sign, K: Deref> ReadableArgs<(&'a K, u32)> for Channel config: config.unwrap(), forwarding_fee_base_msat: handshake_config.unwrap().forwarding_fee_base_msat, forwarding_fee_proportional_millionths: handshake_config.unwrap().forwarding_fee_proportional_millionths, - cltv_expiry_delta: config.unwrap().cltv_expiry_delta, + cltv_expiry_delta: handshake_config.unwrap().cltv_expiry_delta, channel_id, channel_state, diff --git a/lightning/src/ln/functional_test_utils.rs b/lightning/src/ln/functional_test_utils.rs index 46d970d092f..4f7048dc804 100644 --- a/lightning/src/ln/functional_test_utils.rs +++ b/lightning/src/ln/functional_test_utils.rs @@ -1731,7 +1731,7 @@ pub fn test_default_channel_config() -> UserConfig { let mut default_config = UserConfig::default(); // Set cltv_expiry_delta slightly lower to keep the final CLTV values inside one byte in our // tests so that our script-length checks don't fail (see ACCEPTED_HTLC_SCRIPT_WEIGHT). - default_config.channel_options.cltv_expiry_delta = 6*6; + default_config.own_channel_config.cltv_expiry_delta = 6*6; default_config.channel_options.announced_channel = true; default_config.peer_channel_config_limits.force_announced_channel_preference = false; // When most of our tests were written, the default HTLC minimum was fixed at 1000. diff --git a/lightning/src/util/config.rs b/lightning/src/util/config.rs index 4b8c4c91fe7..3b32c7c7c6a 100644 --- a/lightning/src/util/config.rs +++ b/lightning/src/util/config.rs @@ -67,6 +67,26 @@ pub struct ChannelHandshakeConfig { /// /// [`forwarding_fee_proportional_millionths`]: ChannelHandshakeConfig::forwarding_fee_proportional_millionths pub forwarding_fee_base_msat: u32, + /// The difference in the CLTV value between incoming HTLCs and an outbound HTLC forwarded over + /// the channel this config applies to. + /// + /// This is analogous to [`ChannelHandshakeConfig::our_to_self_delay`] but applies to in-flight + /// HTLC balance when a channel appears on-chain whereas + /// [`ChannelHandshakeConfig::our_to_self_delay`] applies to the remaining + /// (non-HTLC-encumbered) balance. + /// + /// Thus, for HTLC-encumbered balances to be enforced on-chain when a channel is force-closed, + /// we (or one of our watchtowers) MUST be online to check for broadcast of the current + /// commitment transaction at least once per this many blocks (minus some margin to allow us + /// enough time to broadcast and confirm a transaction, possibly with time in between to RBF + /// the spending transaction). + /// + /// Default value: 72 (12 hours at an average of 6 blocks/hour). + /// Minimum value: [`MIN_CLTV_EXPIRY_DELTA`], any values less than this will be treated as + /// [`MIN_CLTV_EXPIRY_DELTA`] instead. + /// + /// [`MIN_CLTV_EXPIRY_DELTA`]: crate::ln::channelmanager::MIN_CLTV_EXPIRY_DELTA + pub cltv_expiry_delta: u16, } impl Default for ChannelHandshakeConfig { @@ -77,6 +97,7 @@ impl Default for ChannelHandshakeConfig { our_htlc_minimum_msat: 1, forwarding_fee_base_msat: 1000, forwarding_fee_proportional_millionths: 0, + cltv_expiry_delta: 6 * 12, // 6 blocks/hour * 12 hours } } } @@ -165,26 +186,6 @@ impl Default for ChannelHandshakeLimits { /// with our counterparty. #[derive(Copy, Clone, Debug)] pub struct ChannelConfig { - /// The difference in the CLTV value between incoming HTLCs and an outbound HTLC forwarded over - /// the channel this config applies to. - /// - /// This is analogous to [`ChannelHandshakeConfig::our_to_self_delay`] but applies to in-flight - /// HTLC balance when a channel appears on-chain whereas - /// [`ChannelHandshakeConfig::our_to_self_delay`] applies to the remaining - /// (non-HTLC-encumbered) balance. - /// - /// Thus, for HTLC-encumbered balances to be enforced on-chain when a channel is force-closed, - /// we (or one of our watchtowers) MUST be online to check for broadcast of the current - /// commitment transaction at least once per this many blocks (minus some margin to allow us - /// enough time to broadcast and confirm a transaction, possibly with time in between to RBF - /// the spending transaction). - /// - /// Default value: 72 (12 hours at an average of 6 blocks/hour). - /// Minimum value: [`MIN_CLTV_EXPIRY_DELTA`], any values less than this will be treated as - /// [`MIN_CLTV_EXPIRY_DELTA`] instead. - /// - /// [`MIN_CLTV_EXPIRY_DELTA`]: crate::ln::channelmanager::MIN_CLTV_EXPIRY_DELTA - pub cltv_expiry_delta: u16, /// Set to announce the channel publicly and notify all nodes that they can route via this /// channel. /// @@ -254,7 +255,6 @@ impl Default for ChannelConfig { /// Provides sane defaults for most configurations (but with zero relay fees!). fn default() -> Self { ChannelConfig { - cltv_expiry_delta: 6 * 12, // 6 blocks/hour * 12 hours announced_channel: false, commit_upfront_shutdown_pubkey: true, max_dust_htlc_exposure_msat: 5_000_000, @@ -265,7 +265,6 @@ impl Default for ChannelConfig { impl_writeable_tlv_based!(ChannelConfig, { (1, max_dust_htlc_exposure_msat, (default_value, 5_000_000)), - (2, cltv_expiry_delta, required), (3, force_close_avoidance_max_fee_satoshis, (default_value, 1000)), (4, announced_channel, required), (6, commit_upfront_shutdown_pubkey, required),