Skip to content

validation: In case of a continued reindex, only activate chain in the end

If a user interrupts a reindex while it is iterating over the block files, it will continue to reindex with the next node start (if the -reindex arg is dropped, otherwise it will start reindexing from scratch). However, due to an early call to ActivateBestChainState() that only exists to connect the genesis block during the original -reindex, it wil start connecting blocks immediately before having iterated through all block files. Because later headers above the minchainwork threshold won't be loaded in this case, -assumevalid will not be applied and the process is much slower due to script validation being done.

Fix this by only calling ActivateBestChainState() here if Genesis is not connected yet (equivalent to ActiveHeight() == -1). Also simplify this spot by only doing this for the active chainstate instead of looping over all chainstates (first commit).

This issue was discussed in the thread below https://github.com/bitcoin/bitcoin/pull/31346#discussion_r1856824817, the impact on assumevalid was found by l0rinc.

The fix can be tested by manually aborting a -reindex e.g. on signet and observing in the debug log the order in which blockfiles are indexed / blocks are connected with this branch vs master.

Merge request reports

Loading