Skip to content

Commit eaabe00

Browse files
author
Antoine Riard
committed
-f move config value to a variation rate
1 parent 464df56 commit eaabe00

File tree

2 files changed

+14
-11
lines changed

2 files changed

+14
-11
lines changed

lightning/src/ln/channel.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -2860,9 +2860,9 @@ impl<Signer: Sign> Channel<Signer> {
28602860
/// Trigger the autoclose timer if it's in the starting position
28612861
pub fn maybe_trigger_autoclose_timer(&mut self, current_feerate: u32, new_feerate: u32) -> bool {
28622862

2863-
// Verify the new feerate is at least superior by 30% of current feerate before to
2863+
// Verify the new feerate is at least superior by `autoclose_variation_rate` of current feerate before to
28642864
// start a autoclose timer and current feerate has fallen behind background feerate.
2865-
if new_feerate > current_feerate * 1300 / 1000 {
2865+
if new_feerate > current_feerate * self.config.autoclose_variation_rate / 1000 {
28662866
return false;
28672867
}
28682868

@@ -3403,7 +3403,7 @@ impl<Signer: Sign> Channel<Signer> {
34033403
// Again, check at each autoclose tick that mempool feerate hasn't fall back
34043404
// more in-sync to the current channel feerate. Otherwise, reset autoclose
34053405
// timer from scratch.
3406-
if new_feerate < self.get_feerate() * 1300 / 1000 {
3406+
if new_feerate < self.get_feerate() * self.config.autoclose_variation_rate / 1000 {
34073407
self.autoclose_timer += 1;
34083408
} else {
34093409
self.autoclose_timer = 0;
@@ -3420,8 +3420,8 @@ impl<Signer: Sign> Channel<Signer> {
34203420
}
34213421
}
34223422
let outbound_stats = self.get_outbound_pending_htlc_stats(None);
3423-
// If the channel has pending *included* HTLCs to claim on-chain and `should_autoclose`=y, close the channel
3424-
if (outbound_stats.on_holder_tx_included_htlcs > 0 || pending_inbound) && self.config.should_autoclose {
3423+
// If the channel has pending *included* HTLCs to claim on-chain and auto-close is enabled, close the channel
3424+
if (outbound_stats.on_holder_tx_included_htlcs > 0 || pending_inbound) && self.config.autoclose_variation_rate != 0 {
34253425
return Err(ChannelError::Close("Channel has time-sensitive outputs and the auto-close timer has been reached".to_owned()));
34263426
}
34273427
// Otherwise, do not reset the autoclose timer as a substantial HTLC can be committed

lightning/src/util/config.rs

+9-6
Original file line numberDiff line numberDiff line change
@@ -246,10 +246,13 @@ pub struct ChannelConfig {
246246
/// [`Normal`]: crate::chain::chaininterface::ConfirmationTarget::Normal
247247
/// [`Background`]: crate::chain::chaininterface::ConfirmationTarget::Background
248248
pub force_close_avoidance_max_fee_satoshis: u64,
249-
/// If this is set to false, we do not auto-close channel with pending time-sensitive outputs,
250-
/// of which the feerate has been detected as stalling.
251-
/// Default value: true.
252-
pub should_autoclose: bool,
249+
/// Maximum feerate variation for a given `cltv_expiry_delta` period. Increasing the variation
250+
/// rate, make the auto-close mechanism react faster to more sensitive fee spikes.
251+
///
252+
/// Setting the value to 0 disable auto-close.
253+
///
254+
/// Default value: 1300 (30%)
255+
pub autoclose_variation_rate: u32,
253256
}
254257

255258
impl Default for ChannelConfig {
@@ -263,7 +266,7 @@ impl Default for ChannelConfig {
263266
commit_upfront_shutdown_pubkey: true,
264267
max_dust_htlc_exposure_msat: 5_000_000,
265268
force_close_avoidance_max_fee_satoshis: 1000,
266-
should_autoclose: true,
269+
autoclose_variation_rate: 1300,
267270
}
268271
}
269272
}
@@ -276,7 +279,7 @@ impl_writeable_tlv_based!(ChannelConfig, {
276279
(4, announced_channel, required),
277280
(6, commit_upfront_shutdown_pubkey, required),
278281
(8, forwarding_fee_base_msat, required),
279-
(10, should_autoclose, (default_value, true)),
282+
(10, autoclose_variation_rate, (default_value, 1300)),
280283
});
281284

282285
/// Top-level config which holds ChannelHandshakeLimits and ChannelConfig.

0 commit comments

Comments
 (0)