From dfd6266c7ad9f8d19aa4f67266ff72e2385c4008 Mon Sep 17 00:00:00 2001 From: Joost Jager Date: Mon, 11 May 2026 15:54:30 +0200 Subject: [PATCH] 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. --- lightning/src/ln/channel.rs | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/lightning/src/ln/channel.rs b/lightning/src/ln/channel.rs index a9ef37f4c35..56226a55e21 100644 --- a/lightning/src/ln/channel.rs +++ b/lightning/src/ln/channel.rs @@ -6250,7 +6250,7 @@ impl ChannelContext { let dust_exposure_limiting_feerate = self.get_dust_exposure_limiting_feerate(&fee_estimator, funding.get_channel_type()); - let balances = self + let mut balances = self .get_next_remote_commitment_stats( funding, htlc_candidate, @@ -6261,11 +6261,14 @@ impl ChannelContext { ) .map(|(remote_stats, _)| remote_stats.available_balances)?; - #[cfg(debug_assertions)] if balances.next_outbound_htlc_limit_msat >= balances.next_outbound_htlc_minimum_msat && balances.next_outbound_htlc_limit_msat != 0 { - let (remote_stats, _remote_htlcs) = self + let reserve_msat = funding + .counterparty_selected_channel_reserve_satoshis + .unwrap_or(0) + .saturating_mul(1000); + let can_add_max_htlc = self .get_next_remote_commitment_stats( funding, Some(HTLCAmountDirection { @@ -6280,11 +6283,13 @@ impl ChannelContext { self.feerate_per_kw, dust_exposure_limiting_feerate, ) - .unwrap(); - assert!( - remote_stats.commitment_stats.holder_balance_msat - >= funding.counterparty_selected_channel_reserve_satoshis.unwrap_or(0) * 1000 - ); + .map(|(remote_stats, _remote_htlcs)| { + remote_stats.commitment_stats.holder_balance_msat >= reserve_msat + }) + .unwrap_or(false); + if !can_add_max_htlc { + balances.next_outbound_htlc_limit_msat = 0; + } } Ok(balances)