Skip to content

Commit 9d0883b

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 90de1be commit 9d0883b

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

lightning/src/chain/channelmonitor.rs

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -586,13 +586,20 @@ pub enum Balance {
586586
#[derive(PartialEq)]
587587
struct IrrevocablyResolvedHTLC {
588588
commitment_tx_output_idx: u32,
589+
/// The txid of the transaction which resolved the HTLC, this may be a commitment,
590+
/// HTLC-Success, or HTLC-Timeout transaction.
591+
resolving_txid: Option<Txid>,
592+
/// The amount of the output for this HTLC in `resolving_txid`.
593+
onchain_value_satoshis: Option<u64>,
589594
/// Only set if the HTLC claim was ours using a payment preimage
590595
payment_preimage: Option<PaymentPreimage>,
591596
}
592597

593598
impl_writeable_tlv_based!(IrrevocablyResolvedHTLC, {
594599
(0, commitment_tx_output_idx, required),
600+
(1, resolving_txid, option),
595601
(2, payment_preimage, option),
602+
(3, onchain_value_satoshis, option),
596603
});
597604

598605
/// A ChannelMonitor handles chain events (blocks connected and disconnected) and generates
@@ -2695,7 +2702,10 @@ impl<Signer: Sign> ChannelMonitorImpl<Signer> {
26952702
htlc_value_satoshis,
26962703
}));
26972704
if let Some(idx) = commitment_tx_output_idx {
2698-
self.htlcs_resolved_on_chain.push(IrrevocablyResolvedHTLC { commitment_tx_output_idx: idx, payment_preimage: None });
2705+
self.htlcs_resolved_on_chain.push(IrrevocablyResolvedHTLC {
2706+
commitment_tx_output_idx: idx, resolving_txid: Some(entry.txid),
2707+
payment_preimage: None, onchain_value_satoshis,
2708+
});
26992709
}
27002710
},
27012711
OnchainEvent::MaturingOutput { descriptor } => {
@@ -2704,8 +2714,10 @@ impl<Signer: Sign> ChannelMonitorImpl<Signer> {
27042714
outputs: vec![descriptor]
27052715
});
27062716
},
2707-
OnchainEvent::HTLCSpendConfirmation { commitment_tx_output_idx, preimage, .. } => {
2708-
self.htlcs_resolved_on_chain.push(IrrevocablyResolvedHTLC { commitment_tx_output_idx, payment_preimage: preimage });
2717+
OnchainEvent::HTLCSpendConfirmation { commitment_tx_output_idx, preimage, onchain_value_satoshis, .. } => {
2718+
self.htlcs_resolved_on_chain.push(IrrevocablyResolvedHTLC {
2719+
commitment_tx_output_idx, resolving_txid: Some(entry.txid),
2720+
payment_preimage: preimage, onchain_value_satoshis });
27092721
},
27102722
OnchainEvent::FundingSpendConfirmation { commitment_tx_to_counterparty_output, .. } => {
27112723
self.funding_spend_confirmed = Some(entry.txid);

0 commit comments

Comments
 (0)