Skip to content

Commit 537e91c

Browse files
committed
Explicitly track the set of spendable transactions which confirm
In `ChannelMonitor`s, when a transaction containing a spend of a revoked remote output reaches 6 confs, we may have no other tracking of that txid remaining. Thus, if we see that transaction again (because a user duplicatively confirms it), we'll generate a redundant spendable output event for it. Here we simply explicitly track all txids of transactions which confirm with a spendable output, allowing us to check this condition in the next commit.
1 parent 4883eba commit 537e91c

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

lightning/src/chain/channelmonitor.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -826,6 +826,13 @@ pub(crate) struct ChannelMonitorImpl<Signer: Sign> {
826826
/// spending CSV for revocable outputs).
827827
htlcs_resolved_on_chain: Vec<IrrevocablyResolvedHTLC>,
828828

829+
/// The set of `SpendableOutput` events which we have already passed upstream to be claimed.
830+
/// These are tracked explicitly to ensure that we don't generate the same events redundantly
831+
/// if users duplicatively confirm old transactions. Specifically for transactions claiming a
832+
/// revoked remote outpoint we otherwise have no tracking at all once they've reached
833+
/// [`ANTI_REORG_DELAY`], so we have to track them here.
834+
spendable_txids_confirmed: Vec<Txid>,
835+
829836
// We simply modify best_block in Channel's block_connected so that serialization is
830837
// consistent but hopefully the users' copy handles block_connected in a consistent way.
831838
// (we do *not*, however, update them in update_monitor to ensure any local user copies keep
@@ -1071,6 +1078,7 @@ impl<Signer: Sign> Writeable for ChannelMonitorImpl<Signer> {
10711078
(7, self.funding_spend_seen, required),
10721079
(9, self.counterparty_node_id, option),
10731080
(11, self.confirmed_commitment_tx_counterparty_output, option),
1081+
(13, self.spendable_txids_confirmed, vec_type),
10741082
});
10751083

10761084
Ok(())
@@ -1179,6 +1187,7 @@ impl<Signer: Sign> ChannelMonitor<Signer> {
11791187
funding_spend_confirmed: None,
11801188
confirmed_commitment_tx_counterparty_output: None,
11811189
htlcs_resolved_on_chain: Vec::new(),
1190+
spendable_txids_confirmed: Vec::new(),
11821191

11831192
best_block,
11841193
counterparty_node_id: Some(counterparty_node_id),
@@ -3042,6 +3051,7 @@ impl<Signer: Sign> ChannelMonitorImpl<Signer> {
30423051
self.pending_events.push(Event::SpendableOutputs {
30433052
outputs: vec![descriptor]
30443053
});
3054+
self.spendable_txids_confirmed.push(entry.txid);
30453055
},
30463056
OnchainEvent::HTLCSpendConfirmation { commitment_tx_output_idx, preimage, .. } => {
30473057
self.htlcs_resolved_on_chain.push(IrrevocablyResolvedHTLC {
@@ -3763,13 +3773,15 @@ impl<'a, K: KeysInterface> ReadableArgs<&'a K>
37633773
let mut funding_spend_seen = Some(false);
37643774
let mut counterparty_node_id = None;
37653775
let mut confirmed_commitment_tx_counterparty_output = None;
3776+
let mut spendable_txids_confirmed = Some(Vec::new());
37663777
read_tlv_fields!(reader, {
37673778
(1, funding_spend_confirmed, option),
37683779
(3, htlcs_resolved_on_chain, vec_type),
37693780
(5, pending_monitor_events, vec_type),
37703781
(7, funding_spend_seen, option),
37713782
(9, counterparty_node_id, option),
37723783
(11, confirmed_commitment_tx_counterparty_output, option),
3784+
(13, spendable_txids_confirmed, vec_type),
37733785
});
37743786

37753787
let mut secp_ctx = Secp256k1::new();
@@ -3822,6 +3834,7 @@ impl<'a, K: KeysInterface> ReadableArgs<&'a K>
38223834
funding_spend_confirmed,
38233835
confirmed_commitment_tx_counterparty_output,
38243836
htlcs_resolved_on_chain: htlcs_resolved_on_chain.unwrap(),
3837+
spendable_txids_confirmed: spendable_txids_confirmed.unwrap(),
38253838

38263839
best_block,
38273840
counterparty_node_id,

0 commit comments

Comments
 (0)