Skip to content

Commit dfd6266

Browse files
committed
Clamp unsafe next outbound HTLC limit
Before reporting a next outbound HTLC limit, simulate adding that HTLC to the next remote commitment. If that simulation fails or would drop the holder below the selected channel reserve, report zero capacity instead.
1 parent c2955a0 commit dfd6266

1 file changed

Lines changed: 13 additions & 8 deletions

File tree

lightning/src/ln/channel.rs

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6250,7 +6250,7 @@ impl<SP: SignerProvider> ChannelContext<SP> {
62506250
let dust_exposure_limiting_feerate =
62516251
self.get_dust_exposure_limiting_feerate(&fee_estimator, funding.get_channel_type());
62526252

6253-
let balances = self
6253+
let mut balances = self
62546254
.get_next_remote_commitment_stats(
62556255
funding,
62566256
htlc_candidate,
@@ -6261,11 +6261,14 @@ impl<SP: SignerProvider> ChannelContext<SP> {
62616261
)
62626262
.map(|(remote_stats, _)| remote_stats.available_balances)?;
62636263

6264-
#[cfg(debug_assertions)]
62656264
if balances.next_outbound_htlc_limit_msat >= balances.next_outbound_htlc_minimum_msat
62666265
&& balances.next_outbound_htlc_limit_msat != 0
62676266
{
6268-
let (remote_stats, _remote_htlcs) = self
6267+
let reserve_msat = funding
6268+
.counterparty_selected_channel_reserve_satoshis
6269+
.unwrap_or(0)
6270+
.saturating_mul(1000);
6271+
let can_add_max_htlc = self
62696272
.get_next_remote_commitment_stats(
62706273
funding,
62716274
Some(HTLCAmountDirection {
@@ -6280,11 +6283,13 @@ impl<SP: SignerProvider> ChannelContext<SP> {
62806283
self.feerate_per_kw,
62816284
dust_exposure_limiting_feerate,
62826285
)
6283-
.unwrap();
6284-
assert!(
6285-
remote_stats.commitment_stats.holder_balance_msat
6286-
>= funding.counterparty_selected_channel_reserve_satoshis.unwrap_or(0) * 1000
6287-
);
6286+
.map(|(remote_stats, _remote_htlcs)| {
6287+
remote_stats.commitment_stats.holder_balance_msat >= reserve_msat
6288+
})
6289+
.unwrap_or(false);
6290+
if !can_add_max_htlc {
6291+
balances.next_outbound_htlc_limit_msat = 0;
6292+
}
62886293
}
62896294

62906295
Ok(balances)

0 commit comments

Comments
 (0)