From 2549a4dddc580d610aa36cc85178ff3a4e2f1409 Mon Sep 17 00:00:00 2001 From: Joost Jager Date: Thu, 2 Apr 2026 08:30:58 +0200 Subject: [PATCH] Fix balance candidate selection during pending splices Mirror LDK's sentinel logic for confirmed_balance_candidate_index in ClaimableOnChannelClose: when the index is 0 (no specific alternative funding confirmed), use the last balance candidate (most current splice/RBF attempt) instead of the first. This aligns with LDK's claimable_amount_satoshis() behavior and fixes a mismatch where total_lightning_balance_sats could differ from the sum of individual LightningBalance amounts during pending splices. AI tools were used in preparing this commit. --- src/balance.rs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/balance.rs b/src/balance.rs index 6c6ad946d..1d6a328b8 100644 --- a/src/balance.rs +++ b/src/balance.rs @@ -231,8 +231,14 @@ impl LightningBalance { inbound_claiming_htlc_rounded_msat, inbound_htlc_rounded_msat, } => { - // unwrap safety: confirmed_balance_candidate_index is guaranteed to index into balance_candidates - let balance = balance_candidates.get(confirmed_balance_candidate_index).unwrap(); + // When confirmed_balance_candidate_index is 0, no specific alternative + // funding has been confirmed yet, so use the last candidate (most current + // splice/RBF attempt), matching LDK's claimable_amount_satoshis behavior. + let balance = if confirmed_balance_candidate_index != 0 { + &balance_candidates[confirmed_balance_candidate_index] + } else { + balance_candidates.last().unwrap() + }; Self::ClaimableOnChannelClose { channel_id,