HomePhabricator

qa: Wait for txindex to avoid race condition

Description

qa: Wait for txindex to avoid race condition

Summary:
If the Transaction Index happens to be slow, we get rare test failures when querying it for transactions.

Can be verified to be necessary through adding std::this_thread::sleep_for(0.5s) at the beginning of TxIndex::WriteBlock.

diff --git a/src/index/txindex.cpp b/src/index/txindex.cpp
index 2453d8eccf..7ee246bce5 100644
--- a/src/index/txindex.cpp
+++ b/src/index/txindex.cpp
@@ -54,6 +54,7 @@ TxIndex::TxIndex(std::unique_ptr<interfaces::Chain> chain, size_t n_cache_size,
 TxIndex::~TxIndex() {}

 bool TxIndex::WriteBlock(const CBlock &block, const CBlockIndex *pindex) {
+    std::this_thread::sleep_for(0.5s);
     // Exclude genesis block transaction because outputs are not spendable.
     if (pindex->nHeight == 0) {
         return true;

This concludes backport of core#32010
https://github.com/bitcoin/bitcoin/pull/32010/commits/3301d2cbe8c3b76c97285d75fa59637cb6952d0b
Depends on D18623

Test Plan: ninja check-functional

Reviewers: #bitcoin_abc, Fabien

Reviewed By: #bitcoin_abc, Fabien

Differential Revision: https://reviews.bitcoinabc.org/D18624

Details

Provenance
Hodlinator <172445034+hodlinator@users.noreply.github.com>Authored on Mar 10 2025, 14:24
PiRKCommitted on Sep 16 2025, 06:22
PiRKPushed on Sep 16 2025, 06:22
Reviewer
Restricted Project
Differential Revision
D18624: qa: Wait for txindex to avoid race condition
Parents
rABCeb275a50b28c: qa: Add missing coverage of corrupt indexes
Branches
Unknown
Tags
Unknown

Event Timeline