diff --git a/src/init.cpp b/src/init.cpp --- a/src/init.cpp +++ b/src/init.cpp @@ -2277,25 +2277,6 @@ GetRand(std::numeric_limits::max()), *node.addrman, args.GetBoolArg("-networkactive", true)); - assert(!node.mempool); - int check_ratio = std::min( - std::max( - args.GetIntArg("-checkmempool", - chainparams.DefaultConsistencyChecks() ? 1 : 0), - 0), - 1000000); - node.mempool = std::make_unique(check_ratio); - - assert(!node.chainman); - node.chainman = std::make_unique(); - ChainstateManager &chainman = *node.chainman; - - assert(!node.peerman); - node.peerman = PeerManager::make( - chainparams, *node.connman, *node.addrman, node.banman.get(), chainman, - *node.mempool, args.GetBoolArg("-blocksonly", DEFAULT_BLOCKSONLY)); - RegisterValidationInterface(node.peerman.get()); - // sanitize comments per BIP-0014, format user agent and check total size std::vector uacomments; for (const std::string &cmt : args.GetArgs("-uacomment")) { @@ -2451,8 +2432,22 @@ cache_sizes.coins * (1.0 / 1024 / 1024), nMempoolSizeMax * (1.0 / 1024 / 1024)); + assert(!node.mempool); + assert(!node.chainman); + int check_ratio = std::min( + std::max( + args.GetIntArg("-checkmempool", + chainparams.DefaultConsistencyChecks() ? 1 : 0), + 0), + 1000000); + bool fLoaded = false; while (!fLoaded && !ShutdownRequested()) { + node.mempool = std::make_unique(check_ratio); + + node.chainman = std::make_unique(); + ChainstateManager &chainman = *node.chainman; + const bool fReset = fReindex; bilingual_str strLoadError; @@ -2598,6 +2593,14 @@ return false; } + ChainstateManager &chainman = *Assert(node.chainman); + + assert(!node.peerman); + node.peerman = PeerManager::make( + chainparams, *node.connman, *node.addrman, node.banman.get(), chainman, + *node.mempool, args.GetBoolArg("-blocksonly", DEFAULT_BLOCKSONLY)); + RegisterValidationInterface(node.peerman.get()); + // Encoded addresses using cashaddr instead of base58. // We do this by default to avoid confusion with BTC addresses. config.SetCashAddrEncoding(args.GetBoolArg("-usecashaddr", true)); diff --git a/src/node/chainstate.cpp b/src/node/chainstate.cpp --- a/src/node/chainstate.cpp +++ b/src/node/chainstate.cpp @@ -29,8 +29,6 @@ chainman.m_total_coinstip_cache = nCoinCacheUsage; chainman.m_total_coinsdb_cache = nCoinDBCache; - UnloadBlockIndex(mempool, chainman); - auto &pblocktree{chainman.m_blockman.m_block_tree_db}; // new CBlockTreeDB tries to delete the existing file, which // fails if it's still open from the previous loop. Close it first: