Skip to content

Commit c49c086

Browse files
committed
Add cltv_expiry_delta to ChannelHandshakeConfig
1 parent 333a226 commit c49c086

File tree

3 files changed

+28
-29
lines changed

3 files changed

+28
-29
lines changed

lightning/src/ln/channel.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -775,7 +775,7 @@ impl<Signer: Sign> Channel<Signer> {
775775

776776
forwarding_fee_base_msat: handshake_config.forwarding_fee_base_msat,
777777
forwarding_fee_proportional_millionths: handshake_config.forwarding_fee_proportional_millionths,
778-
cltv_expiry_delta: config.channel_options.clone().cltv_expiry_delta,
778+
cltv_expiry_delta: handshake_config.cltv_expiry_delta,
779779

780780
channel_id: keys_provider.get_secure_random_bytes(),
781781
channel_state: ChannelState::OurInitSent as u32,
@@ -1078,7 +1078,7 @@ impl<Signer: Sign> Channel<Signer> {
10781078

10791079
forwarding_fee_base_msat: handshake_config.forwarding_fee_base_msat,
10801080
forwarding_fee_proportional_millionths: handshake_config.forwarding_fee_proportional_millionths,
1081-
cltv_expiry_delta: local_config.cltv_expiry_delta,
1081+
cltv_expiry_delta: handshake_config.cltv_expiry_delta,
10821082

10831083
channel_id: msg.temporary_channel_id,
10841084
channel_state: (ChannelState::OurInitSent as u32) | (ChannelState::TheirInitSent as u32),
@@ -5206,7 +5206,7 @@ impl<Signer: Sign> Writeable for Channel<Signer> {
52065206
// Write out the old serialization for the config object. This is read by version-1
52075207
// deserializers, but we will read the version in the TLV at the end instead.
52085208
self.forwarding_fee_proportional_millionths.write(writer)?;
5209-
self.config.cltv_expiry_delta.write(writer)?;
5209+
self.cltv_expiry_delta.write(writer)?;
52105210
self.config.announced_channel.write(writer)?;
52115211
self.config.commit_upfront_shutdown_pubkey.write(writer)?;
52125212

@@ -5471,14 +5471,14 @@ impl<'a, Signer: Sign, K: Deref> ReadableArgs<(&'a K, u32)> for Channel<Signer>
54715471

54725472
if ver == 1 {
54735473
// Read the old serialization of the ChannelConfig from version 0.0.98.handshake_config.as_mut().unwrap().forwarding_fee_proportional_millionths = Readable::read(reader)?;
5474-
config.as_mut().unwrap().cltv_expiry_delta = Readable::read(reader)?;
54755474
config.as_mut().unwrap().announced_channel = Readable::read(reader)?;
54765475
config.as_mut().unwrap().commit_upfront_shutdown_pubkey = Readable::read(reader)?;
54775476
} else {
54785477
// Read the 8 bytes of backwards-compatibility ChannelConfig data.
54795478
let mut _val: u64 = Readable::read(reader)?;
54805479
}
5481-
5480+
5481+
let cltv_expiry_delta = Readable::read(reader)?;
54825482
let channel_id = Readable::read(reader)?;
54835483
let channel_state = Readable::read(reader)?;
54845484
let channel_value_satoshis = Readable::read(reader)?;
@@ -5728,7 +5728,7 @@ impl<'a, Signer: Sign, K: Deref> ReadableArgs<(&'a K, u32)> for Channel<Signer>
57285728
config: config.unwrap(),
57295729
forwarding_fee_base_msat: handshake_config.unwrap().forwarding_fee_base_msat,
57305730
forwarding_fee_proportional_millionths: handshake_config.unwrap().forwarding_fee_proportional_millionths,
5731-
cltv_expiry_delta: config.unwrap().cltv_expiry_delta,
5731+
cltv_expiry_delta: handshake_config.unwrap().cltv_expiry_delta,
57325732

57335733
channel_id,
57345734
channel_state,

lightning/src/ln/functional_test_utils.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1731,7 +1731,7 @@ pub fn test_default_channel_config() -> UserConfig {
17311731
let mut default_config = UserConfig::default();
17321732
// Set cltv_expiry_delta slightly lower to keep the final CLTV values inside one byte in our
17331733
// tests so that our script-length checks don't fail (see ACCEPTED_HTLC_SCRIPT_WEIGHT).
1734-
default_config.channel_options.cltv_expiry_delta = 6*6;
1734+
default_config.own_channel_config.cltv_expiry_delta = 6*6;
17351735
default_config.channel_options.announced_channel = true;
17361736
default_config.peer_channel_config_limits.force_announced_channel_preference = false;
17371737
// When most of our tests were written, the default HTLC minimum was fixed at 1000.

lightning/src/util/config.rs

Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,26 @@ pub struct ChannelHandshakeConfig {
6767
///
6868
/// [`forwarding_fee_proportional_millionths`]: ChannelHandshakeConfig::forwarding_fee_proportional_millionths
6969
pub forwarding_fee_base_msat: u32,
70+
/// The difference in the CLTV value between incoming HTLCs and an outbound HTLC forwarded over
71+
/// the channel this config applies to.
72+
///
73+
/// This is analogous to [`ChannelHandshakeConfig::our_to_self_delay`] but applies to in-flight
74+
/// HTLC balance when a channel appears on-chain whereas
75+
/// [`ChannelHandshakeConfig::our_to_self_delay`] applies to the remaining
76+
/// (non-HTLC-encumbered) balance.
77+
///
78+
/// Thus, for HTLC-encumbered balances to be enforced on-chain when a channel is force-closed,
79+
/// we (or one of our watchtowers) MUST be online to check for broadcast of the current
80+
/// commitment transaction at least once per this many blocks (minus some margin to allow us
81+
/// enough time to broadcast and confirm a transaction, possibly with time in between to RBF
82+
/// the spending transaction).
83+
///
84+
/// Default value: 72 (12 hours at an average of 6 blocks/hour).
85+
/// Minimum value: [`MIN_CLTV_EXPIRY_DELTA`], any values less than this will be treated as
86+
/// [`MIN_CLTV_EXPIRY_DELTA`] instead.
87+
///
88+
/// [`MIN_CLTV_EXPIRY_DELTA`]: crate::ln::channelmanager::MIN_CLTV_EXPIRY_DELTA
89+
pub cltv_expiry_delta: u16,
7090
}
7191

7292
impl Default for ChannelHandshakeConfig {
@@ -77,6 +97,7 @@ impl Default for ChannelHandshakeConfig {
7797
our_htlc_minimum_msat: 1,
7898
forwarding_fee_base_msat: 1000,
7999
forwarding_fee_proportional_millionths: 0,
100+
cltv_expiry_delta: 6 * 12, // 6 blocks/hour * 12 hours
80101
}
81102
}
82103
}
@@ -165,26 +186,6 @@ impl Default for ChannelHandshakeLimits {
165186
/// with our counterparty.
166187
#[derive(Copy, Clone, Debug)]
167188
pub struct ChannelConfig {
168-
/// The difference in the CLTV value between incoming HTLCs and an outbound HTLC forwarded over
169-
/// the channel this config applies to.
170-
///
171-
/// This is analogous to [`ChannelHandshakeConfig::our_to_self_delay`] but applies to in-flight
172-
/// HTLC balance when a channel appears on-chain whereas
173-
/// [`ChannelHandshakeConfig::our_to_self_delay`] applies to the remaining
174-
/// (non-HTLC-encumbered) balance.
175-
///
176-
/// Thus, for HTLC-encumbered balances to be enforced on-chain when a channel is force-closed,
177-
/// we (or one of our watchtowers) MUST be online to check for broadcast of the current
178-
/// commitment transaction at least once per this many blocks (minus some margin to allow us
179-
/// enough time to broadcast and confirm a transaction, possibly with time in between to RBF
180-
/// the spending transaction).
181-
///
182-
/// Default value: 72 (12 hours at an average of 6 blocks/hour).
183-
/// Minimum value: [`MIN_CLTV_EXPIRY_DELTA`], any values less than this will be treated as
184-
/// [`MIN_CLTV_EXPIRY_DELTA`] instead.
185-
///
186-
/// [`MIN_CLTV_EXPIRY_DELTA`]: crate::ln::channelmanager::MIN_CLTV_EXPIRY_DELTA
187-
pub cltv_expiry_delta: u16,
188189
/// Set to announce the channel publicly and notify all nodes that they can route via this
189190
/// channel.
190191
///
@@ -254,7 +255,6 @@ impl Default for ChannelConfig {
254255
/// Provides sane defaults for most configurations (but with zero relay fees!).
255256
fn default() -> Self {
256257
ChannelConfig {
257-
cltv_expiry_delta: 6 * 12, // 6 blocks/hour * 12 hours
258258
announced_channel: false,
259259
commit_upfront_shutdown_pubkey: true,
260260
max_dust_htlc_exposure_msat: 5_000_000,
@@ -265,7 +265,6 @@ impl Default for ChannelConfig {
265265

266266
impl_writeable_tlv_based!(ChannelConfig, {
267267
(1, max_dust_htlc_exposure_msat, (default_value, 5_000_000)),
268-
(2, cltv_expiry_delta, required),
269268
(3, force_close_avoidance_max_fee_satoshis, (default_value, 1000)),
270269
(4, announced_channel, required),
271270
(6, commit_upfront_shutdown_pubkey, required),

0 commit comments

Comments
 (0)