From: Alec Chen Date: Sun, 23 Apr 2023 06:03:15 +0000 (-0500) Subject: Add payment preimage and hash to `ContentiousClaimable` X-Git-Tag: v0.0.116-alpha1~61^2~2 X-Git-Url: http://git.bitcoin.ninja/?a=commitdiff_plain;h=0f933efc58e3bd9e0dce15146671a171433199f1;p=rust-lightning Add payment preimage and hash to `ContentiousClaimable` --- diff --git a/lightning/src/chain/channelmonitor.rs b/lightning/src/chain/channelmonitor.rs index 5ff297b1a..00fd1405a 100644 --- a/lightning/src/chain/channelmonitor.rs +++ b/lightning/src/chain/channelmonitor.rs @@ -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 ChannelMonitorImpl { 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 ChannelMonitorImpl { 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() { diff --git a/lightning/src/ln/monitor_tests.rs b/lightning/src/ln/monitor_tests.rs index f8508a829..a5f88dfbb 100644 --- a/lightning/src/ln/monitor_tests.rs +++ b/lightning/src/ln/monitor_tests.rs @@ -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