Skip to content

Commit f945ade

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 ca5e79c commit f945ade

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

src/balance.rs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -231,10 +231,16 @@ 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
236-
.get(confirmed_balance_candidate_index)
237-
.expect("LDK should provide a valid confirmed balance candidate index");
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
241+
.last()
242+
.expect("balance_candidates always contains at least the current funding")
243+
};
238244

239245
Self::ClaimableOnChannelClose {
240246
channel_id,

0 commit comments

Comments
 (0)