Skip to content

Commit

Permalink
Add cltv_expiry_delta to ChannelHandshakeConfig
Browse files Browse the repository at this point in the history
  • Loading branch information
matchacactus committed Jan 18, 2022
1 parent 333a226 commit c49c086
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 29 deletions.
12 changes: 6 additions & 6 deletions lightning/src/ln/channel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -775,7 +775,7 @@ impl<Signer: Sign> Channel<Signer> {

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,
Expand Down Expand Up @@ -1078,7 +1078,7 @@ impl<Signer: Sign> Channel<Signer> {

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),
Expand Down Expand Up @@ -5206,7 +5206,7 @@ impl<Signer: Sign> Writeable for Channel<Signer> {
// 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)?;

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

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)?;
Expand Down Expand Up @@ -5728,7 +5728,7 @@ impl<'a, Signer: Sign, K: Deref> ReadableArgs<(&'a K, u32)> for Channel<Signer>
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,
Expand Down
2 changes: 1 addition & 1 deletion lightning/src/ln/functional_test_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
43 changes: 21 additions & 22 deletions lightning/src/util/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
}
}
}
Expand Down Expand Up @@ -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.
///
Expand Down Expand Up @@ -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,
Expand All @@ -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),
Expand Down

0 comments on commit c49c086

Please sign in to comment.