Skip to content
Open
11 changes: 9 additions & 2 deletions lightning/src/chain/channelmonitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5818,10 +5818,17 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitorImpl<Signer> {

/// Filters a block's `txdata` for transactions spending watched outputs or for any child
/// transactions thereof.
/// While iterating, this also tracks whether we observed the funding transaction.
#[rustfmt::skip]
fn filter_block<'a>(&self, txdata: &TransactionData<'a>) -> Vec<&'a Transaction> {
fn filter_block<'a>(&mut self, txdata: &TransactionData<'a>) -> Vec<&'a Transaction> {
let mut matched_txn = new_hash_set();
txdata.iter().filter(|&&(_, tx)| {
let txid = tx.compute_txid();
if !self.funding_seen_onchain && (txid == self.funding.funding_txid() ||
self.pending_funding.iter().any(|f| f.funding_txid() == txid))
{
self.funding_seen_onchain = true;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any reason we're not doing this in transactions_confirmed instead?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to reset this in case of a reorg, i.e., in transactions_unconfirmed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

see #3838 (comment)

Ah, right, I knew I saw a related comment somewhere. Mind adding a comment (or two) in the code explaining that and why we're fine with it never being unset? FWIW, the current behavior might be okay for the current use case, but if someone would ever reuse the flag for some other application they might be surprised to find it's not unset if there's a reorg.

}
let mut matches = self.spends_watched_output(tx);
for input in tx.input.iter() {
if matches { break; }
Expand All @@ -5830,7 +5837,7 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitorImpl<Signer> {
}
}
if matches {
matched_txn.insert(tx.compute_txid());
matched_txn.insert(txid);
}
matches
}).map(|(_, tx)| *tx).collect()
Expand Down