Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions PR_DESCRIPTION_splice_feerate_overflow.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Use overflow-safe arithmetic for splice fee ceilings

Replace the overflowing `feerate * 3 / 2` calculation with a saturating 1.5× calculation. This prevents debug panics and avoids wrapped ceilings for extreme fee rates; add boundary coverage.

Validation: `cargo fmt --all`; `cargo test fee_estimator::tests`; live regtest `splice_in(FeeRate::MAX)` returns an error without panicking.

AI-assisted draft and implementation.
12 changes: 11 additions & 1 deletion src/fee_estimator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,8 @@ pub(crate) fn apply_post_estimation_adjustments(
/// The most we are willing to pay for a channel funding transaction: `1.5x` our funding feerate
/// estimate. Used as the `max_feerate` ceiling for splices and their RBF fee bumps.
pub(crate) fn max_funding_feerate(estimate: FeeRate) -> FeeRate {
FeeRate::from_sat_per_kwu(estimate.to_sat_per_kwu() * 3 / 2)
let sats_per_kwu = estimate.to_sat_per_kwu();
FeeRate::from_sat_per_kwu(sats_per_kwu.saturating_add(sats_per_kwu / 2))
}

/// Picks the `(target, max)` feerates for replacing a pending splice's in-flight funding
Expand Down Expand Up @@ -214,4 +215,13 @@ mod tests {
// RBF minimum above our max (1.5x a fallen estimate): we can't RBF within our ceiling.
assert_eq!(rbf_splice_feerates(kwu(100), kwu(278)), None);
}

#[test]
fn max_funding_feerate_saturates_without_overflow() {
let kwu = FeeRate::from_sat_per_kwu;
let just_above_mul_limit = u64::MAX / 3 + 1;

assert_eq!(max_funding_feerate(kwu(just_above_mul_limit)), kwu(9_223_372_036_854_775_809));
assert_eq!(max_funding_feerate(FeeRate::MAX), FeeRate::MAX);
}
}
Loading