Skip to content

Commit c1e6a74

Browse files
committed
Add a debug_assert the newly-documented (but existing) requirement
If we add an entry to `claimable_payments` we have to ensure we actually accept the HTLC we're considering, otherwise we'll end up with an empty `claimable_payments` entry.
1 parent f57221b commit c1e6a74

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

lightning/src/ln/channelmanager.rs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3315,8 +3315,11 @@ where
33153315
onion_payload,
33163316
};
33173317

3318+
let mut committed_to_claimable = false;
3319+
33183320
macro_rules! fail_htlc {
33193321
($htlc: expr, $payment_hash: expr) => {
3322+
debug_assert!(!committed_to_claimable);
33203323
let mut htlc_msat_height_data = $htlc.value.to_be_bytes().to_vec();
33213324
htlc_msat_height_data.extend_from_slice(
33223325
&self.best_block.read().unwrap().height().to_be_bytes(),
@@ -3357,8 +3360,11 @@ where
33573360
let ref mut claimable_payment = claimable_payments.claimable_payments
33583361
.entry(payment_hash)
33593362
// Note that if we insert here we MUST NOT fail_htlc!()
3360-
.or_insert_with(|| ClaimablePayment {
3361-
purpose: purpose(), htlcs: Vec::new()
3363+
.or_insert_with(|| {
3364+
committed_to_claimable = true;
3365+
ClaimablePayment {
3366+
purpose: purpose(), htlcs: Vec::new()
3367+
}
33623368
});
33633369
let ref mut htlcs = &mut claimable_payment.htlcs;
33643370
if htlcs.len() == 1 {
@@ -3394,6 +3400,9 @@ where
33943400
log_bytes!(payment_hash.0));
33953401
fail_htlc!(claimable_htlc, payment_hash);
33963402
} else if total_value >= $payment_data.total_msat {
3403+
#[allow(unused_assignments)] {
3404+
committed_to_claimable = true;
3405+
}
33973406
let prev_channel_id = prev_funding_outpoint.to_channel_id();
33983407
htlcs.push(claimable_htlc);
33993408
let amount_msat = htlcs.iter().map(|htlc| htlc.value).sum();
@@ -3413,6 +3422,9 @@ where
34133422
// payment value yet, wait until we receive more
34143423
// MPP parts.
34153424
htlcs.push(claimable_htlc);
3425+
#[allow(unused_assignments)] {
3426+
committed_to_claimable = true;
3427+
}
34163428
}
34173429
payment_claimable_generated
34183430
}}

0 commit comments

Comments
 (0)