Skip to content

Commit 6893371

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 36d25c4 commit 6893371

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

lightning/src/chain/channelmonitor.rs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -588,12 +588,16 @@ 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,
592+
/// HTLC-Success, or HTLC-Timeout transaction.
593+
resolving_txid: Option<Txid>, // Added as optional, but always filled in, in 0.0.110
591594
/// Only set if the HTLC claim was ours using a payment preimage
592595
payment_preimage: Option<PaymentPreimage>,
593596
}
594597

595598
impl_writeable_tlv_based!(IrrevocablyResolvedHTLC, {
596599
(0, commitment_tx_output_idx, required),
600+
(1, resolving_txid, option),
597601
(2, payment_preimage, option),
598602
});
599603

@@ -2719,7 +2723,10 @@ impl<Signer: Sign> ChannelMonitorImpl<Signer> {
27192723
htlc_value_satoshis,
27202724
}));
27212725
if let Some(idx) = commitment_tx_output_idx {
2722-
self.htlcs_resolved_on_chain.push(IrrevocablyResolvedHTLC { commitment_tx_output_idx: idx, payment_preimage: None });
2726+
self.htlcs_resolved_on_chain.push(IrrevocablyResolvedHTLC {
2727+
commitment_tx_output_idx: idx, resolving_txid: Some(entry.txid),
2728+
payment_preimage: None,
2729+
});
27232730
}
27242731
},
27252732
OnchainEvent::MaturingOutput { descriptor } => {
@@ -2729,7 +2736,10 @@ impl<Signer: Sign> ChannelMonitorImpl<Signer> {
27292736
});
27302737
},
27312738
OnchainEvent::HTLCSpendConfirmation { commitment_tx_output_idx, preimage, .. } => {
2732-
self.htlcs_resolved_on_chain.push(IrrevocablyResolvedHTLC { commitment_tx_output_idx, payment_preimage: preimage });
2739+
self.htlcs_resolved_on_chain.push(IrrevocablyResolvedHTLC {
2740+
commitment_tx_output_idx, resolving_txid: Some(entry.txid),
2741+
payment_preimage: preimage,
2742+
});
27332743
},
27342744
OnchainEvent::FundingSpendConfirmation { commitment_tx_to_counterparty_output, .. } => {
27352745
self.funding_spend_confirmed = Some(entry.txid);

0 commit comments

Comments
 (0)