diff --git a/src/init.cpp b/src/init.cpp index 7dceef7fff4..90bf3c6461f 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -1559,7 +1559,7 @@ bool AppInitMain(const util::Ref& context, NodeContext& node, interfaces::BlockA chainman.m_total_coinstip_cache = nCoinCacheUsage; chainman.m_total_coinsdb_cache = nCoinDBCache; - UnloadBlockIndex(node.mempool.get()); + UnloadBlockIndex(node.mempool.get(), chainman); // new CBlockTreeDB tries to delete the existing file, which // fails if it's still open from the previous loop. Close it first: diff --git a/src/qt/test/apptests.cpp b/src/qt/test/apptests.cpp index 0b5c3415481..8dffd2f59f1 100644 --- a/src/qt/test/apptests.cpp +++ b/src/qt/test/apptests.cpp @@ -84,8 +84,11 @@ void AppTests::appTests() // Reset global state to avoid interfering with later tests. LogInstance().DisconnectTestLogger(); AbortShutdown(); - UnloadBlockIndex(/* mempool */ nullptr); - WITH_LOCK(::cs_main, g_chainman.Reset()); + { + LOCK(cs_main); + UnloadBlockIndex(/* mempool */ nullptr, g_chainman); + g_chainman.Reset(); + } } //! Entry point for BitcoinGUI tests. diff --git a/src/test/util/setup_common.cpp b/src/test/util/setup_common.cpp index 08aff074486..2d3137e1e2a 100644 --- a/src/test/util/setup_common.cpp +++ b/src/test/util/setup_common.cpp @@ -187,7 +187,7 @@ TestingSetup::~TestingSetup() m_node.connman.reset(); m_node.banman.reset(); m_node.args = nullptr; - UnloadBlockIndex(m_node.mempool.get()); + UnloadBlockIndex(m_node.mempool.get(), *m_node.chainman); m_node.mempool.reset(); m_node.scheduler.reset(); m_node.chainman->Reset(); diff --git a/src/validation.cpp b/src/validation.cpp index 5beff88a01a..7478fb55105 100644 --- a/src/validation.cpp +++ b/src/validation.cpp @@ -4605,10 +4605,10 @@ void CChainState::UnloadBlockIndex() { // May NOT be used after any connections are up as much // of the peer-processing logic assumes a consistent // block index state -void UnloadBlockIndex(CTxMemPool* mempool) +void UnloadBlockIndex(CTxMemPool* mempool, ChainstateManager& chainman) { LOCK(cs_main); - g_chainman.Unload(); + chainman.Unload(); pindexBestInvalid = nullptr; pindexBestHeader = nullptr; if (mempool) mempool->clear(); diff --git a/src/validation.h b/src/validation.h index 12d1d4c91f1..2d9d2cb918d 100644 --- a/src/validation.h +++ b/src/validation.h @@ -159,7 +159,7 @@ void LoadExternalBlockFile(const CChainParams& chainparams, FILE* fileIn, FlatFi /** Ensures we have a genesis block in the block tree, possibly writing one to disk. */ bool LoadGenesisBlock(const CChainParams& chainparams); /** Unload database information */ -void UnloadBlockIndex(CTxMemPool* mempool); +void UnloadBlockIndex(CTxMemPool* mempool, ChainstateManager& chainman); /** Run an instance of the script checking thread */ void ThreadScriptCheck(int worker_num); /**