]> git.bitcoin.ninja Git - rust-lightning/commitdiff
Fix dust buffer feerate calculation overflow
authorMatt Corallo <git@bluematt.me>
Sun, 24 Dec 2023 06:24:38 +0000 (06:24 +0000)
committerMatt Corallo <git@bluematt.me>
Fri, 29 Dec 2023 06:24:18 +0000 (06:24 +0000)
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.

lightning/src/ln/channel.rs

index 6e283f08660de36e381fd11bbf870d125d5ed945..721d653519fa31df62f976d25e169d302c76d42e 100644 (file)
@@ -1872,7 +1872,8 @@ impl<SP: Deref> ChannelContext<SP> 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.