Skip to content

Commit 22cf7f9

Browse files
committed
Fix data race in lookup_confirmations()
Hold the `HeaderList` read lock during lookups to ensure results are computed against a stable chain tip. Previously, another thread could update the `HeaderList` between reading the height and querying the DB, resulting in inconsistent results. Also adds a missing timer. (to be squashed)
1 parent 416cb4c commit 22cf7f9

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

src/new_index/schema.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1069,7 +1069,9 @@ impl ChainQuery {
10691069
}
10701070

10711071
pub fn lookup_confirmations(&self, txids: BTreeSet<Txid>) -> HashMap<Txid, u32> {
1072-
lookup_confirmations(&self.store.history_db, self.best_height() as u32, txids)
1072+
let _timer = self.start_timer("lookup_confirmations");
1073+
let headers = self.store.indexed_headers.read().unwrap();
1074+
lookup_confirmations(&self.store.history_db, headers.best_height() as u32, txids)
10731075
}
10741076

10751077
pub fn get_block_status(&self, hash: &BlockHash) -> BlockStatus {

0 commit comments

Comments
 (0)