Merge bitcoin/bitcoin#27348: test: fix intermittent failure in ChainStateManager tests

f8abcb3e3b test: Fix intermittent failure in ChainStateManager tests (Martin Zumsande)

Pull request description:

  Before wiping a `ChainStateManager` and creating a new one, the `validationinterface` queue should be emptied to avoid the possibility of accessing deleted memory.
  This could lead to very rare CI failures reported in #26613 and #27320 (see [here](https://github.com/bitcoin/bitcoin/issues/27320#issuecomment-1485694691) for a more detailed explanation).

  Fixes #27320

ACKs for top commit:
  jamesob:
    crACK f8abcb3e3b
  MarcoFalke:
    lgtm ACK f8abcb3e3b

Tree-SHA512: 953fcca46ffee039ae1c8c98eed5464ba7ee0007f54e18989caab3f645f5f45e64407a21f614984fd2843a3d56219f44603086b0c305a9a5cec64a8bf76c110a
This commit is contained in:
fanquake 2023-03-28 10:42:12 +01:00
commit 86e7410b22
No known key found for this signature in database
GPG key ID: 2EEB9F5CC09526C1

View file

@ -367,10 +367,13 @@ struct SnapshotTestSetup : TestChain100Setup {
BOOST_TEST_MESSAGE("Simulating node restart");
{
LOCK(::cs_main);
for (Chainstate* cs : chainman.GetAll()) {
LOCK(::cs_main);
cs->ForceFlushStateToDisk();
}
// Process all callbacks referring to the old manager before wiping it.
SyncWithValidationInterfaceQueue();
LOCK(::cs_main);
chainman.ResetChainstates();
BOOST_CHECK_EQUAL(chainman.GetAll().size(), 0);
const ChainstateManager::Options chainman_opts{