Skip to content

Commit 3301d2c

Browse files
committed
qa: Wait for txindex to avoid race condition
Can be verified to be necessary through adding std::this_thread::sleep_for(0.5s) at the beginning of TxIndex::CustomAppend.
1 parent 9bfb0d7 commit 3301d2c

File tree

4 files changed

+13
-0
lines changed

4 files changed

+13
-0
lines changed

test/functional/mempool_accept.py

+2
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
assert_equal,
4646
assert_greater_than,
4747
assert_raises_rpc_error,
48+
sync_txindex,
4849
)
4950
from test_framework.wallet import MiniWallet
5051
from test_framework.wallet_util import generate_keypair
@@ -270,6 +271,7 @@ def run_test(self):
270271

271272
self.log.info('A coinbase transaction')
272273
# Pick the input of the first tx we created, so it has to be a coinbase tx
274+
sync_txindex(self, node)
273275
raw_tx_coinbase_spent = node.getrawtransaction(txid=node.decoderawtransaction(hexstring=raw_tx_in_block)['vin'][0]['txid'])
274276
tx = tx_from_hex(raw_tx_coinbase_spent)
275277
self.check_mempool_result(

test/functional/rpc_rawtransaction.py

+2
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
assert_equal,
3535
assert_greater_than,
3636
assert_raises_rpc_error,
37+
sync_txindex,
3738
)
3839
from test_framework.wallet import (
3940
getnewdestination,
@@ -109,6 +110,7 @@ def getrawtransaction_tests(self):
109110
self.log.info(f"Test getrawtransaction {'with' if n == 0 else 'without'} -txindex")
110111

111112
if n == 0:
113+
sync_txindex(self, self.nodes[n])
112114
# With -txindex.
113115
# 1. valid parameters - only supply txid
114116
assert_equal(self.nodes[n].getrawtransaction(txId), tx['hex'])

test/functional/rpc_txoutproof.py

+2
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
from test_framework.util import (
1313
assert_equal,
1414
assert_raises_rpc_error,
15+
sync_txindex,
1516
)
1617
from test_framework.wallet import MiniWallet
1718

@@ -77,6 +78,7 @@ def run_test(self):
7778
assert_equal(sorted(self.nodes[0].verifytxoutproof(self.nodes[0].gettxoutproof([txid1, txid2]))), sorted(txlist))
7879
assert_equal(sorted(self.nodes[0].verifytxoutproof(self.nodes[0].gettxoutproof([txid2, txid1]))), sorted(txlist))
7980
# We can always get a proof if we have a -txindex
81+
sync_txindex(self, self.nodes[1])
8082
assert_equal(self.nodes[0].verifytxoutproof(self.nodes[1].gettxoutproof([txid_spent])), [txid_spent])
8183
# We can't get a proof if we specify transactions from different blocks
8284
assert_raises_rpc_error(-5, "Not all transactions found in specified or retrieved block", self.nodes[0].gettxoutproof, [txid1, txid3])

test/functional/test_framework/util.py

+7
Original file line numberDiff line numberDiff line change
@@ -592,3 +592,10 @@ def find_vout_for_address(node, txid, addr):
592592
if addr == tx["vout"][i]["scriptPubKey"]["address"]:
593593
return i
594594
raise RuntimeError("Vout not found for address: txid=%s, addr=%s" % (txid, addr))
595+
596+
597+
def sync_txindex(test_framework, node):
598+
test_framework.log.debug("Waiting for node txindex to sync")
599+
sync_start = int(time.time())
600+
test_framework.wait_until(lambda: node.getindexinfo("txindex")["txindex"]["synced"])
601+
test_framework.log.debug(f"Synced in {time.time() - sync_start} seconds")

0 commit comments

Comments
 (0)