]> git.bitcoin.ninja Git - rust-lightning/commitdiff
Add payment preimage and hash to `ContentiousClaimable`
authorAlec Chen <alecchendev@gmail.com>
Sun, 23 Apr 2023 06:03:15 +0000 (01:03 -0500)
committerAlec Chen <alecchendev@gmail.com>
Sun, 23 Apr 2023 06:56:05 +0000 (01:56 -0500)
lightning/src/chain/channelmonitor.rs
lightning/src/ln/monitor_tests.rs

index 5ff297b1af7477c4fee3cff8d8b5db6a7f428a48..00fd1405a9b53cc9e524a401d4b21d96371902be 100644 (file)
@@ -606,6 +606,10 @@ pub enum Balance {
                /// The height at which the counterparty may be able to claim the balance if we have not
                /// done so.
                timeout_height: u32,
+               /// The payment hash that locks this HTLC.
+               payment_hash: PaymentHash,
+               /// The preimage that can be used to claim this HTLC.
+               payment_preimage: PaymentPreimage,
        },
        /// HTLCs which we sent to our counterparty which are claimable after a timeout (less on-chain
        /// fees) if the counterparty does not know the preimage for the HTLCs. These are somewhat
@@ -1604,7 +1608,7 @@ impl<Signer: WriteableEcdsaChannelSigner> ChannelMonitorImpl<Signer> {
                                        claimable_height: htlc.cltv_expiry,
                                });
                        }
-               } else if self.payment_preimages.get(&htlc.payment_hash).is_some() {
+               } else if let Some(payment_preimage) = self.payment_preimages.get(&htlc.payment_hash) {
                        // Otherwise (the payment was inbound), only expose it as claimable if
                        // we know the preimage.
                        // Note that if there is a pending claim, but it did not use the
@@ -1620,6 +1624,8 @@ impl<Signer: WriteableEcdsaChannelSigner> ChannelMonitorImpl<Signer> {
                                return Some(Balance::ContentiousClaimable {
                                        claimable_amount_satoshis: htlc.amount_msat / 1000,
                                        timeout_height: htlc.cltv_expiry,
+                                       payment_hash: htlc.payment_hash,
+                                       payment_preimage: *payment_preimage,
                                });
                        }
                } else if htlc_resolved.is_none() {
index f8508a829bcc98e43e88fcab917a27fccc8af31f..a5f88dfbb7dd10ba4686fab0debf130259bfabdf 100644 (file)
@@ -317,10 +317,14 @@ fn do_test_claim_value_force_close(prev_commitment_tx: bool) {
        let received_htlc_claiming_balance = Balance::ContentiousClaimable {
                claimable_amount_satoshis: 3_000,
                timeout_height: htlc_cltv_timeout,
+               payment_hash,
+               payment_preimage,
        };
        let received_htlc_timeout_claiming_balance = Balance::ContentiousClaimable {
                claimable_amount_satoshis: 4_000,
                timeout_height: htlc_cltv_timeout,
+               payment_hash: timeout_payment_hash,
+               payment_preimage: timeout_payment_preimage,
        };
 
        // Before B receives the payment preimage, it only suggests the push_msat value of 1_000 sats