Adding some logging shows that this generate call is the slowest part of the added test. Questions:
Why 300 blocks? On my laptop the test passes reliably with 239 blocks and fails reliably with 238. Fewer blocks = faster test runs.
Can you explain how the number of blocks used was arrived at, and document that calculation along with the other magic numbers?
<details><summary>Ideas, feel free to pick and choose (maybe some of the suggested logging should be debug instead of info)</summary><p>
@@ -29,7 +29,7 @@ class ReindexTest(BitcoinTestFramework):
def reindex(self, justchainstate=False):
self.generatetoaddress(self.nodes[0], 3, self.nodes[0].get_deterministic_priv_key().address)
blockcount = self.nodes[0].getblockcount()
- self.restart_node(0, ["-reindex-chainstate" if justchainstate else "-reindex"])
+ self.restart_node(0, extra_args=["-reindex-chainstate" if justchainstate else "-reindex"])
self.connect_nodes(0, 1)
assert_equal(self.nodes[0].getblockcount(), blockcount) # start_node is blocking on reindex
self.log.info("Success")
@@ -72,34 +72,36 @@ class ReindexTest(BitcoinTestFramework):
'LoadExternalBlockFile: Out of order block',
'LoadExternalBlockFile: Processing out of order child',
]):
- self.start_node(0, ["-reindex"])
+ self.start_node(0, extra_args=["-reindex"])
# All blocks should be accepted and processed.
assert_equal(self.nodes[0].getblockcount(), 12)
def reindex_readonly(self):
self.connect_nodes(0, 1)
- # generate enough blocks to ensure that the -fastprune node fills up the
- # first blk00000.dat file and starts another block file
- self.generatetoaddress(self.nodes[1], 300, self.nodes[1].get_deterministic_priv_key().address)
+ block_count = self.nodes[1].getblockcount()
+
+ num_blocks_to_add = 239 # document how this is calculated...
+ self.log.info(f"Generate {num_blocks_to_add} blocks to ensure the -fastprune node fills up the first blk00000.dat file and starts another block file")
+ self.generatetoaddress(self.nodes[1], num_blocks_to_add, self.nodes[1].get_deterministic_priv_key().address)
self.stop_node(1)
assert os.path.exists(self.nodes[1].chain_path / 'blocks' / 'blk00000.dat')
assert os.path.exists(self.nodes[1].chain_path / 'blocks' / 'blk00001.dat')
- # make the first block file read-only
- path = self.nodes[1].chain_path / 'blocks' / 'blk00000.dat'
- os.chmod(path, 0o444)
+ self.log.info("Make the first block file read-only")
+ filename = self.nodes[1].chain_path / 'blocks' / 'blk00000.dat'
+ os.chmod(filename, 0o444)
- # restart and reindex the node with the read-only block file
+ self.log.info("Restart the node and reindex with the read-only block file")
self.start_node(1, ["-reindex", "-fastprune"])
- assert_equal(self.nodes[1].getblockcount(), 312)
+ assert_equal(self.nodes[1].getblockcount(), block_count + num_blocks_to_add)
- # shut down this node, triggering disk flushes, but not to the read-only file
+ self.log.info("Shut down this node, triggering disk flushes, but not to the read-only file")
with self.nodes[1].assert_debug_log(expected_msgs=['FlushStateToDisk'], unexpected_msgs=['failed to open file']):
self.stop_node(1)
- self.log.info("Reindex read-only Success")
+ self.log.info("Success of reindex read-only test")
def run_test(self):
self.reindex(False)
</p></details>