Skip to content

Commit 076890c

Browse files
committed
refactor: simplify watched-output post-processing in parallel sync
Address review nit: use a phase_a_txids HashSet and let-else to flatten the B2 consistency-check loop. Behavior unchanged.
1 parent 9489f3f commit 076890c

1 file changed

Lines changed: 24 additions & 19 deletions

File tree

lightning-transaction-sync/src/esplora.rs

Lines changed: 24 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -369,29 +369,34 @@ where
369369

370370
// B2: post-process sequentially, preserving every consistency check
371371
// the sequential version performed, and build the to-fetch list.
372+
let phase_a_txids: HashSet<Txid> =
373+
confirmed_txs.iter().map(|ctx| ctx.txid).collect();
372374
let mut to_fetch: Vec<(Txid, Option<BlockHash>, Option<u32>)> = Vec::new();
373-
for status_res in status_results {
374-
let output_status = match status_res? {
375-
Some(s) => s,
376-
None => continue,
375+
// `transpose` drops outputs with no status while still surfacing any
376+
// lookup error through the `?` below.
377+
for status_res in status_results.into_iter().filter_map(Result::transpose) {
378+
let output_status = status_res?;
379+
let (Some(spending_txid), Some(spending_tx_status)) =
380+
(output_status.txid, output_status.status)
381+
else {
382+
continue;
377383
};
378-
if let Some(spending_txid) = output_status.txid {
379-
if let Some(spending_tx_status) = output_status.status {
380-
if confirmed_txs.iter().any(|ctx| ctx.txid == spending_txid) {
381-
if spending_tx_status.confirmed {
382-
continue;
383-
} else {
384-
log_trace!(self.logger, "Inconsistency: Detected previously-confirmed Tx {} as unconfirmed", spending_txid);
385-
return Err(InternalError::Inconsistency);
386-
}
387-
}
388-
to_fetch.push((
389-
spending_txid,
390-
spending_tx_status.block_hash,
391-
spending_tx_status.block_height,
392-
));
384+
385+
if phase_a_txids.contains(&spending_txid) {
386+
// Phase A already resolved this spend as confirmed; the server
387+
// flipping it back to unconfirmed is an inconsistency.
388+
if !spending_tx_status.confirmed {
389+
log_trace!(self.logger, "Inconsistency: Detected previously-confirmed Tx {} as unconfirmed", spending_txid);
390+
return Err(InternalError::Inconsistency);
393391
}
392+
continue;
394393
}
394+
395+
to_fetch.push((
396+
spending_txid,
397+
spending_tx_status.block_hash,
398+
spending_tx_status.block_height,
399+
));
395400
}
396401

397402
// B3: fan out the dependent confirmed-tx lookups.

0 commit comments

Comments
 (0)