Skip to content

Commit 32f834c

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 0042c7f commit 32f834c

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
@@ -596,13 +596,20 @@ pub enum Balance {
596596
#[derive(PartialEq)]
597597
struct IrrevocablyResolvedHTLC {
598598
commitment_tx_output_idx: u32,
599+
/// The txid of the transaction which resolved the HTLC, this may be a commitment,
600+
/// HTLC-Success, or HTLC-Timeout transaction.
601+
resolving_txid: Option<Txid>,
602+
/// The amount of the output for this HTLC in `resolving_txid`.
603+
onchain_value_satoshis: Option<u64>,
599604
/// Only set if the HTLC claim was ours using a payment preimage
600605
payment_preimage: Option<PaymentPreimage>,
601606
}
602607

603608
impl_writeable_tlv_based!(IrrevocablyResolvedHTLC, {
604609
(0, commitment_tx_output_idx, required),
610+
(1, resolving_txid, option),
605611
(2, payment_preimage, option),
612+
(3, onchain_value_satoshis, option),
606613
});
607614

608615
/// A ChannelMonitor handles chain events (blocks connected and disconnected) and generates
@@ -2675,7 +2682,7 @@ impl<Signer: Sign> ChannelMonitorImpl<Signer> {
26752682
// Produce actionable events from on-chain events having reached their threshold.
26762683
for entry in onchain_events_reaching_threshold_conf.drain(..) {
26772684
match entry.event {
2678-
OnchainEvent::HTLCUpdate { ref source, payment_hash, htlc_value_satoshis, commitment_tx_output_idx, .. } => {
2685+
OnchainEvent::HTLCUpdate { ref source, payment_hash, htlc_value_satoshis, commitment_tx_output_idx, onchain_value_satoshis } => {
26792686
// Check for duplicate HTLC resolutions.
26802687
#[cfg(debug_assertions)]
26812688
{
@@ -2701,7 +2708,10 @@ impl<Signer: Sign> ChannelMonitorImpl<Signer> {
27012708
htlc_value_satoshis,
27022709
}));
27032710
if let Some(idx) = commitment_tx_output_idx {
2704-
self.htlcs_resolved_on_chain.push(IrrevocablyResolvedHTLC { commitment_tx_output_idx: idx, payment_preimage: None });
2711+
self.htlcs_resolved_on_chain.push(IrrevocablyResolvedHTLC {
2712+
commitment_tx_output_idx: idx, resolving_txid: Some(entry.txid),
2713+
payment_preimage: None, onchain_value_satoshis,
2714+
});
27052715
}
27062716
},
27072717
OnchainEvent::MaturingOutput { descriptor } => {
@@ -2710,8 +2720,10 @@ impl<Signer: Sign> ChannelMonitorImpl<Signer> {
27102720
outputs: vec![descriptor]
27112721
});
27122722
},
2713-
OnchainEvent::HTLCSpendConfirmation { commitment_tx_output_idx, preimage, .. } => {
2714-
self.htlcs_resolved_on_chain.push(IrrevocablyResolvedHTLC { commitment_tx_output_idx, payment_preimage: preimage });
2723+
OnchainEvent::HTLCSpendConfirmation { commitment_tx_output_idx, preimage, onchain_value_satoshis, .. } => {
2724+
self.htlcs_resolved_on_chain.push(IrrevocablyResolvedHTLC {
2725+
commitment_tx_output_idx, resolving_txid: Some(entry.txid),
2726+
payment_preimage: preimage, onchain_value_satoshis });
27152727
},
27162728
OnchainEvent::FundingSpendConfirmation { commitment_tx_to_counterparty_output, .. } => {
27172729
self.funding_spend_confirmed = Some(entry.txid);

0 commit comments

Comments
 (0)