From: Matt Corallo Date: Sun, 24 Dec 2023 06:24:38 +0000 (+0000) Subject: Fix dust buffer feerate calculation overflow X-Git-Tag: v0.0.120~18^2~1 X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=commitdiff_plain;h=3b6a361ae76a087ac10c2e59f9163188fd5c20e1;p=rust-lightning Fix dust buffer feerate calculation overflow If a peer provides a feerate which nears `u32::MAX`, we may overflow calculating the dust buffer feerate, leading to spuriously keeping non-anchor channels open when they should be force-closed. --- diff --git a/lightning/src/ln/channel.rs b/lightning/src/ln/channel.rs index 6e283f086..721d65351 100644 --- a/lightning/src/ln/channel.rs +++ b/lightning/src/ln/channel.rs @@ -1872,7 +1872,8 @@ impl ChannelContext where SP::Target: SignerProvider { if let Some(feerate) = outbound_feerate_update { feerate_per_kw = cmp::max(feerate_per_kw, feerate); } - cmp::max(2530, feerate_per_kw * 1250 / 1000) + let feerate_plus_quarter = feerate_per_kw.checked_mul(1250).map(|v| v / 1000); + cmp::max(2530, feerate_plus_quarter.unwrap_or(u32::max_value())) } /// Get forwarding information for the counterparty.