Skip to content

Commit c7622bb

Browse files
committed
Allow configuring different max fee rate from peer
We've run into issues a few times where channels will get force closed because CLN's fee estimator isn't as good as ours so the fee rate will be too high, resulting in a force close. It'd be nice if we'd have the ability to be able to increase this limit because generally this isn't malicious, just different views of the mempool. This also allows you to decrease the max fee if you think it is too high.
1 parent 20f287f commit c7622bb

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

lightning/src/chain/chaininterface.rs

+15
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,15 @@ pub trait FeeEstimator {
8585
/// * satoshis-per-byte * 250
8686
/// * satoshis-per-kbyte / 4
8787
fn get_est_sat_per_1000_weight(&self, confirmation_target: ConfirmationTarget) -> u32;
88+
89+
/// Gets the maximum fee rate we'd accept from a channel counterparty.
90+
/// By default we'll accept up to 25 sat/vByte or 10x our fee estimator's "High Priority" fee.
91+
/// This can be used to increase or decrease that limit.
92+
///
93+
/// Fee rate must be in satoshis per 1000 Weight-Units.
94+
fn max_counterparty_selected_feerate(&self) -> u64 {
95+
cmp::max(250 * 25, self.get_est_sat_per_1000_weight(ConfirmationTarget::HighPriority) as u64 * 10)
96+
}
8897
}
8998

9099
/// Minimum relay fee as required by bitcoin network mempool policy.
@@ -113,6 +122,12 @@ impl<F: Deref> LowerBoundedFeeEstimator<F> where F::Target: FeeEstimator {
113122
FEERATE_FLOOR_SATS_PER_KW,
114123
)
115124
}
125+
126+
pub fn bounded_max_counterparty_selected_feerate(&self) -> u64 {
127+
cmp::max(
128+
self.0.max_counterparty_selected_feerate(),
129+
FEERATE_FLOOR_SATS_PER_KW as u64)
130+
}
116131
}
117132

118133
#[cfg(test)]

lightning/src/ln/channel.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -2149,14 +2149,13 @@ impl<SP: Deref> Channel<SP> where
21492149
) -> Result<(), ChannelError> where F::Target: FeeEstimator, L::Target: Logger,
21502150
{
21512151
// We only bound the fee updates on the upper side to prevent completely absurd feerates,
2152-
// always accepting up to 25 sat/vByte or 10x our fee estimator's "High Priority" fee.
2152+
// by default accepting up to 25 sat/vByte or 10x our fee estimator's "High Priority" fee.
21532153
// We generally don't care too much if they set the feerate to something very high, but it
21542154
// could result in the channel being useless due to everything being dust. This doesn't
21552155
// apply to channels supporting anchor outputs since HTLC transactions are pre-signed with a
21562156
// zero fee, so their fee is no longer considered to determine dust limits.
21572157
if !channel_type.supports_anchors_zero_fee_htlc_tx() {
2158-
let upper_limit = cmp::max(250 * 25,
2159-
fee_estimator.bounded_sat_per_1000_weight(ConfirmationTarget::HighPriority) as u64 * 10);
2158+
let upper_limit = fee_estimator.bounded_max_counterparty_selected_feerate();
21602159
if feerate_per_kw as u64 > upper_limit {
21612160
return Err(ChannelError::Close(format!("Peer's feerate much too high. Actual: {}. Our expected upper limit: {}", feerate_per_kw, upper_limit)));
21622161
}

0 commit comments

Comments
 (0)