Skip to content

Commit

Permalink
handle false-positive txid index hit
Browse files Browse the repository at this point in the history
  • Loading branch information
romanz committed Dec 2, 2023
1 parent 5aba2a1 commit 2ff5f00
Showing 1 changed file with 12 additions and 13 deletions.
25 changes: 12 additions & 13 deletions src/tracker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,18 +105,17 @@ impl Tracker {
) -> Result<Option<(BlockHash, Transaction)>> {
// Note: there are two blocks with coinbase transactions having same txid (see BIP-30)
let blockhashes = self.index.filter_by_txid(txid);
let result = daemon
.for_blocks(blockhashes, |blockhash, block| {
let mut visitor = FindTransaction::new(txid);
match bsl::Block::visit(&block, &mut visitor) {
Ok(_) | Err(VisitBreak) => (),
Err(e) => panic!("core returned invalid block: {:?}", e),
}
visitor.tx_found().map(|tx| (blockhash, tx))
})?
.first()
.cloned()
.flatten();
Ok(result)
let results: Vec<Option<_>> = daemon.for_blocks(blockhashes, |blockhash, block| {
let mut visitor = FindTransaction::new(txid);
match bsl::Block::visit(&block, &mut visitor) {
Ok(_) | Err(VisitBreak) => (),
Err(e) => panic!("core returned invalid block: {:?}", e),
}
visitor.tx_found().map(|tx| (blockhash, tx))
})?;
Ok(results
.into_iter()
.flatten() // skip non-matching blocks, in case of a false-positive index hit
.next()) // return first match
}
}

0 comments on commit 2ff5f00

Please sign in to comment.