Skip to content

Commit 2549a4d

Browse files
committed
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.
1 parent 253dc13 commit 2549a4d

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

src/balance.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -231,8 +231,14 @@ impl LightningBalance {
231231
inbound_claiming_htlc_rounded_msat,
232232
inbound_htlc_rounded_msat,
233233
} => {
234-
// unwrap safety: confirmed_balance_candidate_index is guaranteed to index into balance_candidates
235-
let balance = balance_candidates.get(confirmed_balance_candidate_index).unwrap();
234+
// When confirmed_balance_candidate_index is 0, no specific alternative
235+
// funding has been confirmed yet, so use the last candidate (most current
236+
// splice/RBF attempt), matching LDK's claimable_amount_satoshis behavior.
237+
let balance = if confirmed_balance_candidate_index != 0 {
238+
&balance_candidates[confirmed_balance_candidate_index]
239+
} else {
240+
balance_candidates.last().unwrap()
241+
};
236242

237243
Self::ClaimableOnChannelClose {
238244
channel_id,

0 commit comments

Comments
 (0)