diff --git a/PR_DESCRIPTION_splice_feerate_overflow.md b/PR_DESCRIPTION_splice_feerate_overflow.md new file mode 100644 index 0000000000..1878d65c2f --- /dev/null +++ b/PR_DESCRIPTION_splice_feerate_overflow.md @@ -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. diff --git a/src/fee_estimator.rs b/src/fee_estimator.rs index 072fea15bd..fd0cec207c 100644 --- a/src/fee_estimator.rs +++ b/src/fee_estimator.rs @@ -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 @@ -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); + } }