Skip to content

Commit 1111aec

Browse files
author
MarcoFalke
committed
qa: Always refresh stale cache to be out of ibd
1 parent fab0d85 commit 1111aec

File tree

3 files changed

+25
-6
lines changed

3 files changed

+25
-6
lines changed

test/functional/feature_proxy.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,11 @@
4141

4242
RANGE_BEGIN = PORT_MIN + 2 * PORT_RANGE # Start after p2p and rpc ports
4343

44+
4445
class ProxyTest(BitcoinTestFramework):
4546
def set_test_params(self):
4647
self.num_nodes = 4
48+
self.setup_clean_chain = True
4749

4850
def setup_nodes(self):
4951
self.have_ipv6 = test_ipv6_local()
@@ -198,4 +200,3 @@ def networks_dict(d):
198200

199201
if __name__ == '__main__':
200202
ProxyTest().main()
201-

test/functional/mempool_accept.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
assert_raises_rpc_error,
3030
bytes_to_hex_str,
3131
hex_str_to_bytes,
32-
wait_until,
3332
)
3433

3534

@@ -38,7 +37,6 @@ def set_test_params(self):
3837
self.num_nodes = 1
3938
self.extra_args = [[
4039
'-txindex',
41-
'-reindex', # Need reindex for txindex
4240
'-acceptnonstdtxn=0', # Try to mimic main-net
4341
]] * self.num_nodes
4442

@@ -56,7 +54,7 @@ def run_test(self):
5654

5755
self.log.info('Start with empty mempool, and 200 blocks')
5856
self.mempool_size = 0
59-
wait_until(lambda: node.getblockcount() == 200)
57+
assert_equal(node.getblockcount(), 200)
6058
assert_equal(node.getmempoolinfo()['size'], self.mempool_size)
6159
coins = node.listunspent()
6260

test/functional/test_framework/test_framework.py

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,17 @@ def setup_nodes(self):
274274
self.add_nodes(self.num_nodes, extra_args)
275275
self.start_nodes()
276276
self.import_deterministic_coinbase_privkeys()
277+
if not self.setup_clean_chain:
278+
for n in self.nodes:
279+
assert_equal(n.getblockchaininfo()["blocks"], 199)
280+
self.log.debug('Generate a block with current time to finalize the cache and assert we are out of IBD')
281+
block_hash = self.nodes[0].generate(1)[0]
282+
block = self.nodes[0].getblock(blockhash=block_hash, verbosity=0)
283+
for n in self.nodes:
284+
n.submitblock(block)
285+
chain_info = n.getblockchaininfo()
286+
assert_equal(chain_info["blocks"], 200)
287+
assert_equal(chain_info["initialblockdownload"], False)
277288

278289
def import_deterministic_coinbase_privkeys(self):
279290
for n in self.nodes:
@@ -433,7 +444,7 @@ def _start_logging(self):
433444
def _initialize_chain(self):
434445
"""Initialize a pre-mined blockchain for use by the test.
435446
436-
Create a cache of a 200-block-long chain (with wallet) for MAX_NODES
447+
Create a cache of a 199-block-long chain (with wallet) for MAX_NODES
437448
Afterward, create num_nodes copies from the cache."""
438449

439450
assert self.num_nodes <= MAX_NODES
@@ -476,15 +487,24 @@ def _initialize_chain(self):
476487
for node in self.nodes:
477488
node.wait_for_rpc_connection()
478489

479-
# Create a 200-block-long chain; each of the 4 first nodes
490+
# Create a 199-block-long chain; each of the 4 first nodes
480491
# gets 25 mature blocks and 25 immature.
492+
# The 4th node gets only 24 immature blocks so that the very last
493+
# block in the cache does not age too much (have an old tip age).
494+
# This is needed so that we are out of IBD when the test starts,
495+
# see the tip age check in IsInitialBlockDownload().
481496
for i in range(2):
482497
for peer in range(4):
483498
for j in range(25):
499+
if i == 1 and peer == 3 and j == 24:
500+
break
484501
self.nodes[peer].generatetoaddress(1, self.nodes[peer].get_deterministic_priv_key().address)
485502
# Must sync before next peer starts generating blocks
486503
sync_blocks(self.nodes)
487504

505+
for n in self.nodes:
506+
assert_equal(n.getblockchaininfo()["blocks"], 199)
507+
488508
# Shut them down, and clean up cache directories:
489509
self.stop_nodes()
490510
self.nodes = []

0 commit comments

Comments
 (0)