Skip to content

Commit ba9e517

Browse files
committed
Add payment hash to MaybeTimeoutClaimableHTLC
1 parent 0f933ef commit ba9e517

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

lightning/src/chain/channelmonitor.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -621,6 +621,8 @@ pub enum Balance {
621621
/// The height at which we will be able to claim the balance if our counterparty has not
622622
/// done so.
623623
claimable_height: u32,
624+
/// The payment hash whose preimage our counterparty needs to claim this HTLC.
625+
payment_hash: PaymentHash,
624626
},
625627
/// HTLCs which we received from our counterparty which are claimable with a preimage which we
626628
/// do not currently have. This will only be claimable if we receive the preimage from the node
@@ -1606,6 +1608,7 @@ impl<Signer: WriteableEcdsaChannelSigner> ChannelMonitorImpl<Signer> {
16061608
return Some(Balance::MaybeTimeoutClaimableHTLC {
16071609
claimable_amount_satoshis: htlc.amount_msat / 1000,
16081610
claimable_height: htlc.cltv_expiry,
1611+
payment_hash: htlc.payment_hash,
16091612
});
16101613
}
16111614
} else if let Some(payment_preimage) = self.payment_preimages.get(&htlc.payment_hash) {
@@ -1793,6 +1796,7 @@ impl<Signer: WriteableEcdsaChannelSigner> ChannelMonitor<Signer> {
17931796
res.push(Balance::MaybeTimeoutClaimableHTLC {
17941797
claimable_amount_satoshis: htlc.amount_msat / 1000,
17951798
claimable_height: htlc.cltv_expiry,
1799+
payment_hash: htlc.payment_hash,
17961800
});
17971801
} else if us.payment_preimages.get(&htlc.payment_hash).is_some() {
17981802
claimable_inbound_htlc_value_sat += htlc.amount_msat / 1000;

lightning/src/ln/monitor_tests.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,10 +301,12 @@ fn do_test_claim_value_force_close(prev_commitment_tx: bool) {
301301
let sent_htlc_balance = Balance::MaybeTimeoutClaimableHTLC {
302302
claimable_amount_satoshis: 3_000,
303303
claimable_height: htlc_cltv_timeout,
304+
payment_hash,
304305
};
305306
let sent_htlc_timeout_balance = Balance::MaybeTimeoutClaimableHTLC {
306307
claimable_amount_satoshis: 4_000,
307308
claimable_height: htlc_cltv_timeout,
309+
payment_hash: timeout_payment_hash,
308310
};
309311
let received_htlc_balance = Balance::MaybePreimageClaimableHTLC {
310312
claimable_amount_satoshis: 3_000,
@@ -638,10 +640,12 @@ fn test_balances_on_local_commitment_htlcs() {
638640
let htlc_balance_known_preimage = Balance::MaybeTimeoutClaimableHTLC {
639641
claimable_amount_satoshis: 10_000,
640642
claimable_height: htlc_cltv_timeout,
643+
payment_hash,
641644
};
642645
let htlc_balance_unknown_preimage = Balance::MaybeTimeoutClaimableHTLC {
643646
claimable_amount_satoshis: 20_000,
644647
claimable_height: htlc_cltv_timeout,
648+
payment_hash: payment_hash_2,
645649
};
646650

647651
assert_eq!(sorted_vec(vec![Balance::ClaimableAwaitingConfirmations {
@@ -766,6 +770,7 @@ fn test_no_preimage_inbound_htlc_balances() {
766770
let a_sent_htlc_balance = Balance::MaybeTimeoutClaimableHTLC {
767771
claimable_amount_satoshis: 10_000,
768772
claimable_height: htlc_cltv_timeout,
773+
payment_hash: to_b_failed_payment_hash,
769774
};
770775
let a_received_htlc_balance = Balance::MaybePreimageClaimableHTLC {
771776
claimable_amount_satoshis: 20_000,
@@ -778,6 +783,7 @@ fn test_no_preimage_inbound_htlc_balances() {
778783
let b_sent_htlc_balance = Balance::MaybeTimeoutClaimableHTLC {
779784
claimable_amount_satoshis: 20_000,
780785
claimable_height: htlc_cltv_timeout,
786+
payment_hash: to_a_failed_payment_hash,
781787
};
782788

783789
// Both A and B will have an HTLC that's claimable on timeout and one that's claimable if they
@@ -1068,12 +1074,15 @@ fn do_test_revoked_counterparty_commitment_balances(confirm_htlc_spend_first: bo
10681074
}, Balance::MaybeTimeoutClaimableHTLC {
10691075
claimable_amount_satoshis: 2_000,
10701076
claimable_height: missing_htlc_cltv_timeout,
1077+
payment_hash: missing_htlc_payment_hash,
10711078
}, Balance::MaybeTimeoutClaimableHTLC {
10721079
claimable_amount_satoshis: 4_000,
10731080
claimable_height: htlc_cltv_timeout,
1081+
payment_hash: timeout_payment_hash,
10741082
}, Balance::MaybeTimeoutClaimableHTLC {
10751083
claimable_amount_satoshis: 5_000,
10761084
claimable_height: live_htlc_cltv_timeout,
1085+
payment_hash: live_payment_hash,
10771086
}]),
10781087
sorted_vec(nodes[1].chain_monitor.chain_monitor.get_monitor(funding_outpoint).unwrap().get_claimable_balances()));
10791088

@@ -1502,9 +1511,11 @@ fn test_revoked_counterparty_aggregated_claims() {
15021511
}, Balance::MaybeTimeoutClaimableHTLC {
15031512
claimable_amount_satoshis: 4_000,
15041513
claimable_height: htlc_cltv_timeout,
1514+
payment_hash: revoked_payment_hash,
15051515
}, Balance::MaybeTimeoutClaimableHTLC {
15061516
claimable_amount_satoshis: 3_000,
15071517
claimable_height: htlc_cltv_timeout,
1518+
payment_hash: claimed_payment_hash,
15081519
}]),
15091520
sorted_vec(nodes[1].chain_monitor.chain_monitor.get_monitor(funding_outpoint).unwrap().get_claimable_balances()));
15101521

0 commit comments

Comments
 (0)