Skip to content

Commit 04d8f5e

Browse files
committed
Track the txid that resolves HTLCs even after resolution completes
We need this information when we look up if we still need to spend a revoked output from an HTLC-Success/HTLC-Timeout transaction for balance calculation.
1 parent 9469ce0 commit 04d8f5e

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

lightning/src/chain/channelmonitor.rs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -588,12 +588,17 @@ pub enum Balance {
588588
#[derive(PartialEq)]
589589
struct IrrevocablyResolvedHTLC {
590590
commitment_tx_output_idx: u32,
591+
/// The txid of the transaction which resolved the HTLC, this may be a commitment (if the HTLC
592+
/// was not present in the confirmed commitment transaction), HTLC-Success, or HTLC-Timeout
593+
/// transaction.
594+
resolving_txid: Option<Txid>, // Added as optional, but always filled in, in 0.0.110
591595
/// Only set if the HTLC claim was ours using a payment preimage
592596
payment_preimage: Option<PaymentPreimage>,
593597
}
594598

595599
impl_writeable_tlv_based!(IrrevocablyResolvedHTLC, {
596600
(0, commitment_tx_output_idx, required),
601+
(1, resolving_txid, option),
597602
(2, payment_preimage, option),
598603
});
599604

@@ -2727,7 +2732,10 @@ impl<Signer: Sign> ChannelMonitorImpl<Signer> {
27272732
htlc_value_satoshis,
27282733
}));
27292734
if let Some(idx) = commitment_tx_output_idx {
2730-
self.htlcs_resolved_on_chain.push(IrrevocablyResolvedHTLC { commitment_tx_output_idx: idx, payment_preimage: None });
2735+
self.htlcs_resolved_on_chain.push(IrrevocablyResolvedHTLC {
2736+
commitment_tx_output_idx: idx, resolving_txid: Some(entry.txid),
2737+
payment_preimage: None,
2738+
});
27312739
}
27322740
},
27332741
OnchainEvent::MaturingOutput { descriptor } => {
@@ -2737,7 +2745,10 @@ impl<Signer: Sign> ChannelMonitorImpl<Signer> {
27372745
});
27382746
},
27392747
OnchainEvent::HTLCSpendConfirmation { commitment_tx_output_idx, preimage, .. } => {
2740-
self.htlcs_resolved_on_chain.push(IrrevocablyResolvedHTLC { commitment_tx_output_idx, payment_preimage: preimage });
2748+
self.htlcs_resolved_on_chain.push(IrrevocablyResolvedHTLC {
2749+
commitment_tx_output_idx, resolving_txid: Some(entry.txid),
2750+
payment_preimage: preimage,
2751+
});
27412752
},
27422753
OnchainEvent::FundingSpendConfirmation { commitment_tx_to_counterparty_output, .. } => {
27432754
self.funding_spend_confirmed = Some(entry.txid);

0 commit comments

Comments
 (0)