Skip to content

Commit ceebf62

Browse files
committed
Limit external claim feerate bumps
Since we don't know the total input amount of an external claim (those which come anchor channels), we can't limit our feerate bumps by the amount of funds we have available to use. Instead, we choose to limit it by a margin of the new feerate estimate.
1 parent 36af1f0 commit ceebf62

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

lightning/src/chain/package.rs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -976,14 +976,23 @@ impl PackageTemplate {
976976
) -> u32 where F::Target: FeeEstimator {
977977
let feerate_estimate = fee_estimator.bounded_sat_per_1000_weight(conf_target);
978978
if self.feerate_previous != 0 {
979-
// If old feerate inferior to actual one given back by Fee Estimator, use it to compute new fee...
979+
// Use the new fee estimate if it's higher than the one previously used.
980980
if feerate_estimate as u64 > self.feerate_previous {
981981
feerate_estimate
982982
} else if !force_feerate_bump {
983983
self.feerate_previous.try_into().unwrap_or(u32::max_value())
984984
} else {
985-
// ...else just increase the previous feerate by 25% (because that's a nice number)
986-
(self.feerate_previous + (self.feerate_previous / 4)).try_into().unwrap_or(u32::max_value())
985+
// Our fee estimate has decreased, but our transaction remains unconfirmed after
986+
// using our previous fee estimate. This may point to an unreliable fee estimator,
987+
// so we choose to bump our previous feerate by 25%, making sure we don't use a
988+
// lower feerate or overpay by a large margin by limiting it to 5x the new fee
989+
// estimate.
990+
let previous_feerate = self.feerate_previous.try_into().unwrap_or(u32::max_value());
991+
let mut new_feerate = previous_feerate.saturating_add(previous_feerate / 4);
992+
if new_feerate > feerate_estimate * 5 {
993+
new_feerate = cmp::max(feerate_estimate * 5, previous_feerate);
994+
}
995+
new_feerate
987996
}
988997
} else {
989998
feerate_estimate

0 commit comments

Comments
 (0)