This PR paves the way for de-globalizing g_chainman entirely by removing the usage of g_chainman in the following functions/methods:
- ~CMainCleanup
- CChainState::FlushStateToDisk
- UnloadBlockIndex
The remaining direct uses of g_chainman are as follows:
- In initialization codepaths:
- AppTests
- AppInitMain
- TestingSetup::TestingSetup
 
- ::ChainstateActive
- LookupBlockIndex- Note: LookupBlockIndexis used extensively throughout the codebase and require a much larger set of changes, therefore I’ve left it out of this initial PR
 
- Note: