diff --git a/src/init.cpp b/src/init.cpp --- a/src/init.cpp +++ b/src/init.cpp @@ -2360,12 +2360,14 @@ break; } + const Consensus::Params ¶ms = chainparams.GetConsensus(); + // LoadBlockIndex will load fHavePruned if we've ever removed a // block file from disk. // Note that it also sets fReindex based on the disk flag! // From here on out fReindex and fReset mean something // different! - if (!LoadBlockIndex(config)) { + if (!LoadBlockIndex(params)) { strLoadError = _("Error loading block database").translated; break; } @@ -2374,8 +2376,7 @@ // (we're likely using a testnet datadir, or the other way // around). if (!mapBlockIndex.empty() && - !LookupBlockIndex( - chainparams.GetConsensus().hashGenesisBlock)) { + !LookupBlockIndex(params.hashGenesisBlock)) { return InitError(_("Incorrect or no genesis block found. " "Wrong datadir for network?") .translated); @@ -2424,8 +2425,7 @@ // ReplayBlocks is a no-op if we cleared the coinsviewdb with // -reindex or -reindex-chainstate - if (!ReplayBlocks(chainparams.GetConsensus(), - pcoinsdbview.get())) { + if (!ReplayBlocks(params, pcoinsdbview.get())) { strLoadError = _("Unable to replay blocks. You will need to rebuild " "the database using -reindex-chainstate.") diff --git a/src/validation.h b/src/validation.h --- a/src/validation.h +++ b/src/validation.h @@ -346,7 +346,8 @@ * Load the block tree and coins database from disk, initializing state if we're * running with -reindex. */ -bool LoadBlockIndex(const Config &config) EXCLUSIVE_LOCKS_REQUIRED(cs_main); +bool LoadBlockIndex(const Consensus::Params ¶ms) + EXCLUSIVE_LOCKS_REQUIRED(cs_main); /** * Update the chain tip based on database information. @@ -763,7 +764,8 @@ CBlockIndex *pindexBestParked = nullptr; CBlockIndex const *pindexFinalized = nullptr; - bool LoadBlockIndex(const Config &config, CBlockTreeDB &blocktree) + bool LoadBlockIndex(const Consensus::Params ¶ms, + CBlockTreeDB &blocktree) EXCLUSIVE_LOCKS_REQUIRED(cs_main); /** diff --git a/src/validation.cpp b/src/validation.cpp --- a/src/validation.cpp +++ b/src/validation.cpp @@ -4356,14 +4356,12 @@ return pindexNew; } -bool CChainState::LoadBlockIndex(const Config &config, +bool CChainState::LoadBlockIndex(const Consensus::Params ¶ms, CBlockTreeDB &blocktree) { AssertLockHeld(cs_main); if (!blocktree.LoadBlockIndexGuts( - config.GetChainParams().GetConsensus(), - [this](const BlockHash &hash) EXCLUSIVE_LOCKS_REQUIRED(cs_main) { - return this->InsertBlockIndex(hash); - })) { + params, [this](const BlockHash &hash) EXCLUSIVE_LOCKS_REQUIRED( + cs_main) { return this->InsertBlockIndex(hash); })) { return false; } @@ -4436,9 +4434,9 @@ return true; } -static bool LoadBlockIndexDB(const Config &config) +static bool LoadBlockIndexDB(const Consensus::Params ¶ms) EXCLUSIVE_LOCKS_REQUIRED(cs_main) { - if (!::ChainstateActive().LoadBlockIndex(config, *pblocktree)) { + if (!::ChainstateActive().LoadBlockIndex(params, *pblocktree)) { return false; } @@ -4876,11 +4874,11 @@ ::ChainstateActive().UnloadBlockIndex(); } -bool LoadBlockIndex(const Config &config) { +bool LoadBlockIndex(const Consensus::Params ¶ms) { // Load block index from databases bool needs_init = fReindex; if (!fReindex) { - bool ret = LoadBlockIndexDB(config); + bool ret = LoadBlockIndexDB(params); if (!ret) { return false; }