Skip to content

Commit b2a7d2c

Browse files
committed
fixup: Improve prediction of commitment stats in can_accept_incoming_htlc
Turn the unwrap_or(0) into an expect; `can_accept_incoming_htlc` is called when the inbound HTLC is already irrevocably committed to the channel, so we should have rejected the HTLC at `update_add_htlc` if it exhausts the counterparty's balance.
1 parent c4068d7 commit b2a7d2c

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

lightning/src/ln/channel.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4586,7 +4586,9 @@ where
45864586
if !funding.get_channel_type().supports_anchors_zero_fee_htlc_tx() {
45874587
remote_fee_incl_fee_spike_buffer_htlc_msat *= FEE_SPIKE_BUFFER_FEE_INCREASE_MULTIPLE;
45884588
}
4589-
let remote_balance_before_fee_msat = next_remote_commitment_stats.counterparty_balance_msat.unwrap_or(0);
4589+
// We unwrap here; if the HTLC exhausts the counterparty's balance, we should have rejected it at `update_add_htlc`, here the HTLC is already
4590+
// irrevocably committed to the channel.
4591+
let remote_balance_before_fee_msat = next_remote_commitment_stats.counterparty_balance_msat.expect("The counterparty's balance before fees should never underflow");
45904592
if remote_balance_before_fee_msat.saturating_sub(funding.holder_selected_channel_reserve_satoshis * 1000) < remote_fee_incl_fee_spike_buffer_htlc_msat {
45914593
log_info!(logger, "Attempting to fail HTLC due to fee spike buffer violation in channel {}. Rebalancing is required.", &self.channel_id());
45924594
return Err(LocalHTLCFailureReason::FeeSpikeBuffer);

0 commit comments

Comments
 (0)