Skip to content

Commit c48e806

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 e55c7e2 commit c48e806

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
@@ -2631,7 +2638,7 @@ impl<Signer: Sign> ChannelMonitorImpl<Signer> {
26312638
// Produce actionable events from on-chain events having reached their threshold.
26322639
for entry in onchain_events_reaching_threshold_conf.drain(..) {
26332640
match entry.event {
2634-
OnchainEvent::HTLCUpdate { ref source, payment_hash, htlc_value_satoshis, commitment_tx_output_idx, .. } => {
2641+
OnchainEvent::HTLCUpdate { ref source, payment_hash, htlc_value_satoshis, commitment_tx_output_idx, onchain_value_satoshis } => {
26352642
// Check for duplicate HTLC resolutions.
26362643
#[cfg(debug_assertions)]
26372644
{
@@ -2657,7 +2664,10 @@ impl<Signer: Sign> ChannelMonitorImpl<Signer> {
26572664
htlc_value_satoshis,
26582665
}));
26592666
if let Some(idx) = commitment_tx_output_idx {
2660-
self.htlcs_resolved_on_chain.push(IrrevocablyResolvedHTLC { commitment_tx_output_idx: idx, payment_preimage: None });
2667+
self.htlcs_resolved_on_chain.push(IrrevocablyResolvedHTLC {
2668+
commitment_tx_output_idx: idx, resolving_txid: Some(entry.txid),
2669+
payment_preimage: None, onchain_value_satoshis,
2670+
});
26612671
}
26622672
},
26632673
OnchainEvent::MaturingOutput { descriptor } => {
@@ -2666,8 +2676,10 @@ impl<Signer: Sign> ChannelMonitorImpl<Signer> {
26662676
outputs: vec![descriptor]
26672677
});
26682678
},
2669-
OnchainEvent::HTLCSpendConfirmation { commitment_tx_output_idx, preimage, .. } => {
2670-
self.htlcs_resolved_on_chain.push(IrrevocablyResolvedHTLC { commitment_tx_output_idx, payment_preimage: preimage });
2679+
OnchainEvent::HTLCSpendConfirmation { commitment_tx_output_idx, preimage, onchain_value_satoshis, .. } => {
2680+
self.htlcs_resolved_on_chain.push(IrrevocablyResolvedHTLC {
2681+
commitment_tx_output_idx, resolving_txid: Some(entry.txid),
2682+
payment_preimage: preimage, onchain_value_satoshis });
26712683
},
26722684
OnchainEvent::FundingSpendConfirmation { commitment_tx_to_counterparty_output, .. } => {
26732685
self.funding_spend_confirmed = Some(entry.txid);

0 commit comments

Comments
 (0)