Skip to content

Commit 9854477

Browse files
authored
Merge pull request #2722 from benthecarman/dust-overflow
Fix potential cases where max_dust_htlc_exposure_msat overflows
2 parents 6e40e5f + 55da9c4 commit 9854477

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

lightning/src/ln/channel.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ use crate::util::scid_utils::scid_from_parts;
4848
use crate::io;
4949
use crate::prelude::*;
5050
use core::{cmp,mem,fmt};
51+
use core::convert::TryInto;
5152
use core::ops::Deref;
5253
#[cfg(any(test, fuzzing, debug_assertions))]
5354
use crate::sync::Mutex;
@@ -1195,8 +1196,8 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
11951196
match self.config.options.max_dust_htlc_exposure {
11961197
MaxDustHTLCExposure::FeeRateMultiplier(multiplier) => {
11971198
let feerate_per_kw = fee_estimator.bounded_sat_per_1000_weight(
1198-
ConfirmationTarget::OnChainSweep);
1199-
feerate_per_kw as u64 * multiplier
1199+
ConfirmationTarget::OnChainSweep) as u64;
1200+
feerate_per_kw.saturating_mul(multiplier)
12001201
},
12011202
MaxDustHTLCExposure::FixedLimitMsat(limit) => limit,
12021203
}
@@ -1780,14 +1781,14 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
17801781
context.holder_dust_limit_satoshis + dust_buffer_feerate * htlc_timeout_tx_weight(context.get_channel_type()) / 1000)
17811782
};
17821783
let on_counterparty_dust_htlc_exposure_msat = inbound_stats.on_counterparty_tx_dust_exposure_msat + outbound_stats.on_counterparty_tx_dust_exposure_msat;
1783-
if on_counterparty_dust_htlc_exposure_msat as i64 + htlc_success_dust_limit as i64 * 1000 - 1 > max_dust_htlc_exposure_msat as i64 {
1784+
if on_counterparty_dust_htlc_exposure_msat as i64 + htlc_success_dust_limit as i64 * 1000 - 1 > max_dust_htlc_exposure_msat.try_into().unwrap_or(i64::max_value()) {
17841785
remaining_msat_below_dust_exposure_limit =
17851786
Some(max_dust_htlc_exposure_msat.saturating_sub(on_counterparty_dust_htlc_exposure_msat));
17861787
dust_exposure_dust_limit_msat = cmp::max(dust_exposure_dust_limit_msat, htlc_success_dust_limit * 1000);
17871788
}
17881789

17891790
let on_holder_dust_htlc_exposure_msat = inbound_stats.on_holder_tx_dust_exposure_msat + outbound_stats.on_holder_tx_dust_exposure_msat;
1790-
if on_holder_dust_htlc_exposure_msat as i64 + htlc_timeout_dust_limit as i64 * 1000 - 1 > max_dust_htlc_exposure_msat as i64 {
1791+
if on_holder_dust_htlc_exposure_msat as i64 + htlc_timeout_dust_limit as i64 * 1000 - 1 > max_dust_htlc_exposure_msat.try_into().unwrap_or(i64::max_value()) {
17911792
remaining_msat_below_dust_exposure_limit = Some(cmp::min(
17921793
remaining_msat_below_dust_exposure_limit.unwrap_or(u64::max_value()),
17931794
max_dust_htlc_exposure_msat.saturating_sub(on_holder_dust_htlc_exposure_msat)));

0 commit comments

Comments
 (0)