Page MenuHomePhabricator

test: Add new ChainTestingSetup and use it
ClosedPublic

Authored by PiRK on Mar 15 2022, 13:40.

Details

Reviewers
Fabien
Group Reviewers
Restricted Project
Commits
rABC25f5ae14198f: test: Add new ChainTestingSetup and use it
Summary

Previously, the validation_chainstatemanager_tests test suite
instantiated its own duplicate ChainstateManager on which tests were
performed.

This wasn't a problem for the specific actions performed in
that suite. However, the existence of this duplicate ChainstateManager
and the fact that many of our validation static functions reach for
g_chainman, ::Chain(state|)Active means we may end up acting on two
different CChainStates should we write more extensive tests in the
future.

This change adds a new ChainTestingSetup which performs all
initialization previously done by TestingSetup except:

  1. RPC command registration
  2. ChainState initialization
  3. Genesis Activation
  4. {Ban,Conn,Peer}Man initialization

Means that we will no longer need to initialize a duplicate
ChainstateManger in order to test the initialization codepaths of
CChainState and ChainstateManager.

Lastly, this change has the additional benefit of allowing for
review-only assertions meant to show correctness to work in future work
de-globalizing g_chainman.

In the test chainstatemanager_rebalance_caches, an additional
LoadGenesisBlock call is added as MaybeReblanaceCaches eventually calls
FlushBlockFile, which tries to access vinfoBlockFile[nLastBlockFile],
which is out of bounds when LoadGenesisBlock hasn't been called yet.


Note for the future:

The class con/destructor inheritance structure we have for these
TestingSetup classes is probably not the most suitable abstraction. In
particular, for both TestingSetup and ChainTestingSetup, we need to stop
the scheduler first before anything else. Otherwise classes depending on
the scheduler may be referenced by the scheduler after said classes are
freed. This means that there's no clear parallel between our teardown
code and C++'s destructuring order for class hierarchies.

Future work should strive to coalesce (as much as possible) test and
non-test init codepaths and perhaps structure it in a more fail-proof
way.

This concludes backport of core#20323
https://github.com/bitcoin/bitcoin/pull/20323/commits/81137c60fe6234569e1c5e6760f3a6f016956944

Depends on D11170

Test Plan

ninja check

Event Timeline

PiRK requested review of this revision.Mar 15 2022, 13:40
Fabien requested changes to this revision.Mar 15 2022, 17:15
Fabien added a subscriber: Fabien.
Fabien added inline comments.
src/test/util/setup_common.cpp
164

This needs to move with the RPC initialization

This revision now requires changes to proceed.Mar 15 2022, 17:15

move SetRPCWarmupFinished() to TestingSetup together with RegisterAllRPCCommands

This revision is now accepted and ready to land.Mar 16 2022, 08:15