[diagnostic] perform more aggressive checking of the index during ActivateBestChain
Summary:
This Diff moves the CheckBlockIndex call to just outside of the inner
loop, instead of having it run only after the outer loop is done (and even
then, only if the function was not returned from).
This ensures the block index is in perfect condition every time cs_main
is unlocked, since it gets unlocked during every iteration of the
outer loop. This helps catch bad block index states as soon as they happen,
rather than having them only show up as race conditions (like we
were seeing in rare validation_block_tests failures).
Note that CheckBlockIndex only performs checks on regtest by default,
so this change will cause no impact to mainnet/testnet nodes. For regular
chain behaviour, there is no performance impact here since typically
ActivateBestChain will just do one iteration anyway.
Test Plan:
make check test_runner.py
Reviewers: #bitcoin_abc, deadalnix
Reviewed By: #bitcoin_abc, deadalnix
Differential Revision: https://reviews.bitcoinabc.org/D4717