Skip to content

Commit 23c3cd2

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 4cc93b8 commit 23c3cd2

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

@@ -2723,7 +2728,10 @@ impl<Signer: Sign> ChannelMonitorImpl<Signer> {
27232728
htlc_value_satoshis,
27242729
}));
27252730
if let Some(idx) = commitment_tx_output_idx {
2726-
self.htlcs_resolved_on_chain.push(IrrevocablyResolvedHTLC { commitment_tx_output_idx: idx, payment_preimage: None });
2731+
self.htlcs_resolved_on_chain.push(IrrevocablyResolvedHTLC {
2732+
commitment_tx_output_idx: idx, resolving_txid: Some(entry.txid),
2733+
payment_preimage: None,
2734+
});
27272735
}
27282736
},
27292737
OnchainEvent::MaturingOutput { descriptor } => {
@@ -2733,7 +2741,10 @@ impl<Signer: Sign> ChannelMonitorImpl<Signer> {
27332741
});
27342742
},
27352743
OnchainEvent::HTLCSpendConfirmation { commitment_tx_output_idx, preimage, .. } => {
2736-
self.htlcs_resolved_on_chain.push(IrrevocablyResolvedHTLC { commitment_tx_output_idx, payment_preimage: preimage });
2744+
self.htlcs_resolved_on_chain.push(IrrevocablyResolvedHTLC {
2745+
commitment_tx_output_idx, resolving_txid: Some(entry.txid),
2746+
payment_preimage: preimage,
2747+
});
27372748
},
27382749
OnchainEvent::FundingSpendConfirmation { commitment_tx_to_counterparty_output, .. } => {
27392750
self.funding_spend_confirmed = Some(entry.txid);

0 commit comments

Comments
 (0)