Skip to content

Commit a5cc59e

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 12d668c commit a5cc59e

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

lightning/src/chain/channelmonitor.rs

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -594,13 +594,20 @@ pub enum Balance {
594594
#[derive(PartialEq)]
595595
struct IrrevocablyResolvedHTLC {
596596
commitment_tx_output_idx: u32,
597+
/// The txid of the transaction which resolved the HTLC, this may be a commitment,
598+
/// HTLC-Success, or HTLC-Timeout transaction.
599+
resolving_txid: Option<Txid>,
600+
/// The amount of the output for this HTLC in `resolving_txid`.
601+
onchain_value_satoshis: Option<u64>,
597602
/// Only set if the HTLC claim was ours using a payment preimage
598603
payment_preimage: Option<PaymentPreimage>,
599604
}
600605

601606
impl_writeable_tlv_based!(IrrevocablyResolvedHTLC, {
602607
(0, commitment_tx_output_idx, required),
608+
(1, resolving_txid, option),
603609
(2, payment_preimage, option),
610+
(3, onchain_value_satoshis, option),
604611
});
605612

606613
/// A ChannelMonitor handles chain events (blocks connected and disconnected) and generates
@@ -2673,7 +2680,7 @@ impl<Signer: Sign> ChannelMonitorImpl<Signer> {
26732680
// Produce actionable events from on-chain events having reached their threshold.
26742681
for entry in onchain_events_reaching_threshold_conf.drain(..) {
26752682
match entry.event {
2676-
OnchainEvent::HTLCUpdate { ref source, payment_hash, htlc_value_satoshis, commitment_tx_output_idx, .. } => {
2683+
OnchainEvent::HTLCUpdate { ref source, payment_hash, htlc_value_satoshis, commitment_tx_output_idx, onchain_value_satoshis } => {
26772684
// Check for duplicate HTLC resolutions.
26782685
#[cfg(debug_assertions)]
26792686
{
@@ -2699,7 +2706,10 @@ impl<Signer: Sign> ChannelMonitorImpl<Signer> {
26992706
htlc_value_satoshis,
27002707
}));
27012708
if let Some(idx) = commitment_tx_output_idx {
2702-
self.htlcs_resolved_on_chain.push(IrrevocablyResolvedHTLC { commitment_tx_output_idx: idx, payment_preimage: None });
2709+
self.htlcs_resolved_on_chain.push(IrrevocablyResolvedHTLC {
2710+
commitment_tx_output_idx: idx, resolving_txid: Some(entry.txid),
2711+
payment_preimage: None, onchain_value_satoshis,
2712+
});
27032713
}
27042714
},
27052715
OnchainEvent::MaturingOutput { descriptor } => {
@@ -2708,8 +2718,10 @@ impl<Signer: Sign> ChannelMonitorImpl<Signer> {
27082718
outputs: vec![descriptor]
27092719
});
27102720
},
2711-
OnchainEvent::HTLCSpendConfirmation { commitment_tx_output_idx, preimage, .. } => {
2712-
self.htlcs_resolved_on_chain.push(IrrevocablyResolvedHTLC { commitment_tx_output_idx, payment_preimage: preimage });
2721+
OnchainEvent::HTLCSpendConfirmation { commitment_tx_output_idx, preimage, onchain_value_satoshis, .. } => {
2722+
self.htlcs_resolved_on_chain.push(IrrevocablyResolvedHTLC {
2723+
commitment_tx_output_idx, resolving_txid: Some(entry.txid),
2724+
payment_preimage: preimage, onchain_value_satoshis });
27132725
},
27142726
OnchainEvent::FundingSpendConfirmation { commitment_tx_to_counterparty_output, .. } => {
27152727
self.funding_spend_confirmed = Some(entry.txid);

0 commit comments

Comments
 (0)