Skip to content

Commit 0f89edb

Browse files
committed
Merge #2104: fix(esplora): deduplicate missing txids in fetch_txs_with_outpoints
3b6b3ba fix(esplora): deduplicate missing txids in fetch_txs_with_outpoints (phrwlk) Pull request description: ### Description Previously `fetch_txs_with_outpoints` collected spend txids into a Vec, so the same txid could be pushed multiple times when one transaction spent several input outpoints. This caused redundant `get_tx_info` calls to Esplora for the same transaction, wasting network and CPU without changing the resulting `TxUpdate`. Use `HashSet<Txid>` for `missing_txs` in both async and blocking `fetch_txs_with_outpoints,` so each txid is only requested once while keeping the observable behaviour of `SyncResponse` / `TxUpdate` unchanged. ### Changelog notice ``` ### Changed - Use `HashSet` instead of `Vec` to track `missing_txs` in bdk_esplora, it deduplicates txids. ``` ### Checklists #### All Submissions: * [x] I followed the [contribution guidelines](https://github.com/bitcoindevkit/bdk/blob/master/CONTRIBUTING.md) #### New Features: * [ ] I've added tests for the new feature * [ ] I've added docs for the new feature #### Bugfixes: * [ ] This pull request breaks the existing API * [ ] I've added tests to reproduce the issue which are now passing * [ ] I'm linking the issue being fixed by this PR ACKs for top commit: oleonardolima: ACK 3b6b3ba luisschwab: ACK 3b6b3ba Tree-SHA512: 9f1c48c8576abef5ac7b4cc5a64ae9238617fb06cd726e37021f9052931454f920aaaa1c7b1d81acfbb5a80cc46c9f39153e086941aacc8fc259c2d74b4c66b9
2 parents 37ab670 + 3b6b3ba commit 0f89edb

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

crates/esplora/src/async_ext.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -501,7 +501,7 @@ where
501501

502502
// get outpoint spend-statuses
503503
let mut outpoints = outpoints.into_iter();
504-
let mut missing_txs = Vec::<Txid>::with_capacity(outpoints.len());
504+
let mut missing_txs = HashSet::<Txid>::with_capacity(outpoints.len());
505505
loop {
506506
let handles = outpoints
507507
.by_ref()
@@ -522,7 +522,7 @@ where
522522
None => continue,
523523
};
524524
if !inserted_txs.contains(&spend_txid) {
525-
missing_txs.push(spend_txid);
525+
missing_txs.insert(spend_txid);
526526
}
527527
if let Some(spend_status) = op_status.status {
528528
insert_anchor_or_seen_at_from_status(

crates/esplora/src/blocking_ext.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -457,7 +457,7 @@ fn fetch_txs_with_outpoints<I: IntoIterator<Item = OutPoint>>(
457457

458458
// get outpoint spend-statuses
459459
let mut outpoints = outpoints.into_iter();
460-
let mut missing_txs = Vec::<Txid>::with_capacity(outpoints.len());
460+
let mut missing_txs = HashSet::<Txid>::with_capacity(outpoints.len());
461461
loop {
462462
let handles = outpoints
463463
.by_ref()
@@ -483,7 +483,7 @@ fn fetch_txs_with_outpoints<I: IntoIterator<Item = OutPoint>>(
483483
None => continue,
484484
};
485485
if !inserted_txs.contains(&spend_txid) {
486-
missing_txs.push(spend_txid);
486+
missing_txs.insert(spend_txid);
487487
}
488488
if let Some(spend_status) = op_status.status {
489489
insert_anchor_or_seen_at_from_status(

0 commit comments

Comments
 (0)