Skip to content

Commit

Permalink
-f move config value to a variation rate
Browse files Browse the repository at this point in the history
  • Loading branch information
Antoine Riard committed Dec 7, 2021
1 parent 464df56 commit eaabe00
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 11 deletions.
10 changes: 5 additions & 5 deletions lightning/src/ln/channel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2860,9 +2860,9 @@ impl<Signer: Sign> Channel<Signer> {
/// 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;
}

Expand Down Expand Up @@ -3403,7 +3403,7 @@ impl<Signer: Sign> Channel<Signer> {
// 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;
Expand All @@ -3420,8 +3420,8 @@ impl<Signer: Sign> Channel<Signer> {
}
}
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
Expand Down
15 changes: 9 additions & 6 deletions lightning/src/util/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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,
}
}
}
Expand All @@ -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.
Expand Down

0 comments on commit eaabe00

Please sign in to comment.