Fixes #22964
This is a small part of the work to accomplish what I described in 972c5166ee685447a6d4bf5e501b07a0871fba85:
0Over time, we should probably move these mutable global state variables
1into ChainstateManager or CChainState so it's easier to reason about
2their lifecycles.
::UnloadBlockIndex
manually resets a subset of our mutable globals in addition to unloading the ChainstateManager
and clearing the mempool. The need for this manual reset (AFAICT) arises out of the fact that many of these globals are closely related to the block index (hence ::UnloadBlockIndex
), and need to be reset with it.
I’ve shot this “manual reset” gun at my foot several times while doing the de-globalize chainman work.
Thankfully, now that we have a BlockManager
class that owns the block index, these globals should be moved under that class so that they can live and die with the block index. These moves, along with making the block index non-heap-based, eliminates:
- https://github.com/bitcoin/bitcoin/commit/3585b521392c5b2c855c3ba6dc9b7d2a171b3710 The need to reason about when we need to manually call
::UnloadBlockIndex
(this decision can at times seem almost arbitrary) - https://github.com/bitcoin/bitcoin/commit/f741623c25455c20bff9eb1ddd10a4ac84dc5655 The need to have an
::UnloadBlockIndex
or explicit~ChainstateManager
at all