diff --git a/lightning/src/ln/channel.rs b/lightning/src/ln/channel.rs index 5dcba2a2a18..e00075026c3 100644 --- a/lightning/src/ln/channel.rs +++ b/lightning/src/ln/channel.rs @@ -2860,9 +2860,9 @@ impl Channel { /// Trigger the autoclose timer if it's in the starting position pub fn maybe_trigger_autoclose_timer(&mut self, current_feerate: u32, new_feerate: u32) -> bool { - // Verify the new feerate is at least superior by 30% of current feerate before to + // Verify the new feerate is at least superior by `autoclose_variation_rate` of current feerate before to // start a autoclose timer and current feerate has fallen behind background feerate. - if new_feerate > current_feerate * 1300 / 1000 { + if new_feerate > current_feerate * self.config.autoclose_variation_rate / 1000 { return false; } @@ -3403,7 +3403,7 @@ impl Channel { // Again, check at each autoclose tick that mempool feerate hasn't fall back // more in-sync to the current channel feerate. Otherwise, reset autoclose // timer from scratch. - if new_feerate < self.get_feerate() * 1300 / 1000 { + if new_feerate < self.get_feerate() * self.config.autoclose_variation_rate / 1000 { self.autoclose_timer += 1; } else { self.autoclose_timer = 0; @@ -3420,8 +3420,8 @@ impl Channel { } } let outbound_stats = self.get_outbound_pending_htlc_stats(None); - // If the channel has pending *included* HTLCs to claim on-chain and `should_autoclose`=y, close the channel - if (outbound_stats.on_holder_tx_included_htlcs > 0 || pending_inbound) && self.config.should_autoclose { + // If the channel has pending *included* HTLCs to claim on-chain and auto-close is enabled, close the channel + if (outbound_stats.on_holder_tx_included_htlcs > 0 || pending_inbound) && self.config.autoclose_variation_rate != 0 { return Err(ChannelError::Close("Channel has time-sensitive outputs and the auto-close timer has been reached".to_owned())); } // Otherwise, do not reset the autoclose timer as a substantial HTLC can be committed diff --git a/lightning/src/util/config.rs b/lightning/src/util/config.rs index e22e1ad1299..deedab8fb39 100644 --- a/lightning/src/util/config.rs +++ b/lightning/src/util/config.rs @@ -246,10 +246,13 @@ pub struct ChannelConfig { /// [`Normal`]: crate::chain::chaininterface::ConfirmationTarget::Normal /// [`Background`]: crate::chain::chaininterface::ConfirmationTarget::Background pub force_close_avoidance_max_fee_satoshis: u64, - /// If this is set to false, we do not auto-close channel with pending time-sensitive outputs, - /// of which the feerate has been detected as stalling. - /// Default value: true. - pub should_autoclose: bool, + /// Maximum feerate variation for a given `cltv_expiry_delta` period. Increasing the variation + /// rate, make the auto-close mechanism react faster to more sensitive fee spikes. + /// + /// Setting the value to 0 disable auto-close. + /// + /// Default value: 1300 (30%) + pub autoclose_variation_rate: u32, } impl Default for ChannelConfig { @@ -263,7 +266,7 @@ impl Default for ChannelConfig { commit_upfront_shutdown_pubkey: true, max_dust_htlc_exposure_msat: 5_000_000, force_close_avoidance_max_fee_satoshis: 1000, - should_autoclose: true, + autoclose_variation_rate: 1300, } } } @@ -276,7 +279,7 @@ impl_writeable_tlv_based!(ChannelConfig, { (4, announced_channel, required), (6, commit_upfront_shutdown_pubkey, required), (8, forwarding_fee_base_msat, required), - (10, should_autoclose, (default_value, true)), + (10, autoclose_variation_rate, (default_value, 1300)), }); /// Top-level config which holds ChannelHandshakeLimits and ChannelConfig.