From ba9e51764d1049ffbc10c9f75fb9ba1b07e810f9 Mon Sep 17 00:00:00 2001 From: Alec Chen Date: Sun, 23 Apr 2023 01:03:51 -0500 Subject: [PATCH] Add payment hash to `MaybeTimeoutClaimableHTLC` --- lightning/src/chain/channelmonitor.rs | 4 ++++ lightning/src/ln/monitor_tests.rs | 11 +++++++++++ 2 files changed, 15 insertions(+) diff --git a/lightning/src/chain/channelmonitor.rs b/lightning/src/chain/channelmonitor.rs index 00fd1405a..865b2c55c 100644 --- a/lightning/src/chain/channelmonitor.rs +++ b/lightning/src/chain/channelmonitor.rs @@ -621,6 +621,8 @@ pub enum Balance { /// The height at which we will be able to claim the balance if our counterparty has not /// done so. claimable_height: u32, + /// The payment hash whose preimage our counterparty needs to claim this HTLC. + payment_hash: PaymentHash, }, /// HTLCs which we received from our counterparty which are claimable with a preimage which we /// do not currently have. This will only be claimable if we receive the preimage from the node @@ -1606,6 +1608,7 @@ impl ChannelMonitorImpl { return Some(Balance::MaybeTimeoutClaimableHTLC { claimable_amount_satoshis: htlc.amount_msat / 1000, claimable_height: htlc.cltv_expiry, + payment_hash: htlc.payment_hash, }); } } else if let Some(payment_preimage) = self.payment_preimages.get(&htlc.payment_hash) { @@ -1793,6 +1796,7 @@ impl ChannelMonitor { res.push(Balance::MaybeTimeoutClaimableHTLC { claimable_amount_satoshis: htlc.amount_msat / 1000, claimable_height: htlc.cltv_expiry, + payment_hash: htlc.payment_hash, }); } else if us.payment_preimages.get(&htlc.payment_hash).is_some() { claimable_inbound_htlc_value_sat += htlc.amount_msat / 1000; diff --git a/lightning/src/ln/monitor_tests.rs b/lightning/src/ln/monitor_tests.rs index a5f88dfbb..9b5dc10da 100644 --- a/lightning/src/ln/monitor_tests.rs +++ b/lightning/src/ln/monitor_tests.rs @@ -301,10 +301,12 @@ fn do_test_claim_value_force_close(prev_commitment_tx: bool) { let sent_htlc_balance = Balance::MaybeTimeoutClaimableHTLC { claimable_amount_satoshis: 3_000, claimable_height: htlc_cltv_timeout, + payment_hash, }; let sent_htlc_timeout_balance = Balance::MaybeTimeoutClaimableHTLC { claimable_amount_satoshis: 4_000, claimable_height: htlc_cltv_timeout, + payment_hash: timeout_payment_hash, }; let received_htlc_balance = Balance::MaybePreimageClaimableHTLC { claimable_amount_satoshis: 3_000, @@ -638,10 +640,12 @@ fn test_balances_on_local_commitment_htlcs() { let htlc_balance_known_preimage = Balance::MaybeTimeoutClaimableHTLC { claimable_amount_satoshis: 10_000, claimable_height: htlc_cltv_timeout, + payment_hash, }; let htlc_balance_unknown_preimage = Balance::MaybeTimeoutClaimableHTLC { claimable_amount_satoshis: 20_000, claimable_height: htlc_cltv_timeout, + payment_hash: payment_hash_2, }; assert_eq!(sorted_vec(vec![Balance::ClaimableAwaitingConfirmations { @@ -766,6 +770,7 @@ fn test_no_preimage_inbound_htlc_balances() { let a_sent_htlc_balance = Balance::MaybeTimeoutClaimableHTLC { claimable_amount_satoshis: 10_000, claimable_height: htlc_cltv_timeout, + payment_hash: to_b_failed_payment_hash, }; let a_received_htlc_balance = Balance::MaybePreimageClaimableHTLC { claimable_amount_satoshis: 20_000, @@ -778,6 +783,7 @@ fn test_no_preimage_inbound_htlc_balances() { let b_sent_htlc_balance = Balance::MaybeTimeoutClaimableHTLC { claimable_amount_satoshis: 20_000, claimable_height: htlc_cltv_timeout, + payment_hash: to_a_failed_payment_hash, }; // 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 }, Balance::MaybeTimeoutClaimableHTLC { claimable_amount_satoshis: 2_000, claimable_height: missing_htlc_cltv_timeout, + payment_hash: missing_htlc_payment_hash, }, Balance::MaybeTimeoutClaimableHTLC { claimable_amount_satoshis: 4_000, claimable_height: htlc_cltv_timeout, + payment_hash: timeout_payment_hash, }, Balance::MaybeTimeoutClaimableHTLC { claimable_amount_satoshis: 5_000, claimable_height: live_htlc_cltv_timeout, + payment_hash: live_payment_hash, }]), sorted_vec(nodes[1].chain_monitor.chain_monitor.get_monitor(funding_outpoint).unwrap().get_claimable_balances())); @@ -1502,9 +1511,11 @@ fn test_revoked_counterparty_aggregated_claims() { }, Balance::MaybeTimeoutClaimableHTLC { claimable_amount_satoshis: 4_000, claimable_height: htlc_cltv_timeout, + payment_hash: revoked_payment_hash, }, Balance::MaybeTimeoutClaimableHTLC { claimable_amount_satoshis: 3_000, claimable_height: htlc_cltv_timeout, + payment_hash: claimed_payment_hash, }]), sorted_vec(nodes[1].chain_monitor.chain_monitor.get_monitor(funding_outpoint).unwrap().get_claimable_balances())); -- 2.39.5