diff --git a/src/chain.h b/src/chain.h --- a/src/chain.h +++ b/src/chain.h @@ -239,7 +239,7 @@ }; typedef std::unordered_map BlockMap; -extern BlockMap mapBlockIndex; +extern BlockMap &mapBlockIndex; arith_uint256 GetBlockProof(const CBlockIndex &block); diff --git a/src/validation.h b/src/validation.h --- a/src/validation.h +++ b/src/validation.h @@ -439,8 +439,6 @@ */ void UnlinkPrunedFiles(const std::set &setFilesToPrune); -/** Create a new block index entry for a given block hash */ -CBlockIndex *InsertBlockIndex(uint256 hash); /** Flush all state, indexes and buffers to disk. */ void FlushStateToDisk(); /** Prune block files and flush state to disk. */ @@ -666,7 +664,7 @@ bool IsBlockFinalized(const CBlockIndex *pindex); /** The currently-connected chain of blocks (protected by cs_main). */ -extern CChain chainActive; +extern CChain &chainActive; /** * Global variable that points to the coins database (protected by cs_main) diff --git a/src/validation.cpp b/src/validation.cpp --- a/src/validation.cpp +++ b/src/validation.cpp @@ -59,14 +59,120 @@ #define MICRO 0.000001 #define MILLI 0.001 +class ConnectTrace; + +/** + * CChainState stores and provides an API to update our local knowledge of the + * current best chain and header tree. + * + * It generally provides access to the current block tree, as well as functions + * to provide new data, which it will appropriately validate and incorporate in + * its state as necessary. + * + * Eventually, the API here is targeted at being exposed externally as a + * consumable libconsensus library, so any functions added must only call + * other class member functions, pure functions in other parts of the consensus + * library, callbacks via the validation interface, or read/write-to-disk + * functions (eventually this will also be via callbacks). + */ +class CChainState { +private: + /** + * The set of all CBlockIndex entries with BLOCK_VALID_TRANSACTIONS (for + * itself and all ancestors) and + * as good as our current tip or better. Entries may be failed, though, and + * pruning nodes may be + * missing the data for the block. + */ + std::set setBlockIndexCandidates; + +public: + CChain chainActive; + BlockMap mapBlockIndex; + std::multimap mapBlocksUnlinked; + CBlockIndex *pindexBestInvalid = nullptr; + CBlockIndex *pindexBestParked = nullptr; + + bool LoadBlockIndex(const Config &config, CBlockTreeDB &blocktree); + + bool ActivateBestChain( + const Config &config, CValidationState &state, + std::shared_ptr pblock = std::shared_ptr()); + + bool AcceptBlockHeader(const Config &config, const CBlockHeader &block, + CValidationState &state, CBlockIndex **ppindex); + bool AcceptBlock(const Config &config, + const std::shared_ptr &pblock, + CValidationState &state, bool fRequested, + const CDiskBlockPos *dbp, bool *fNewBlock); + + // Block (dis)connection on a given view: + DisconnectResult DisconnectBlock(const CBlock &block, + const CBlockIndex *pindex, + CCoinsViewCache &view); + bool ConnectBlock(const Config &config, const CBlock &block, + CValidationState &state, CBlockIndex *pindex, + CCoinsViewCache &view, bool fJustCheck = false); + + // Block disconnection on our pcoinsTip: + bool DisconnectTip(const Config &config, CValidationState &state, + DisconnectedBlockTransactions *disconnectpool); + + // Manual block validity manipulation: + bool PreciousBlock(const Config &config, CValidationState &state, + CBlockIndex *pindex); + bool UnwindBlock(const Config &config, CValidationState &state, + CBlockIndex *pindex, bool invalidate); + bool ResetBlockFailureFlags(CBlockIndex *pindex); + template + void UpdateFlagsForBlock(CBlockIndex *pindexBase, CBlockIndex *pindex, F f); + template + void UpdateFlags(CBlockIndex *pindex, F f, C fchild); + template void UpdateFlags(CBlockIndex *pindex, F f); + /** Remove parked status from a block and its descendants. */ + bool UnparkBlockImpl(CBlockIndex *pindex, bool fClearChildren); + + bool ReplayBlocks(const Config &config, CCoinsView *view); + bool RewindBlockIndex(const Config &config); + bool LoadGenesisBlock(const CChainParams &chainparams); + + void PruneBlockIndexCandidates(); + + void UnloadBlockIndex(); + +private: + bool ActivateBestChainStep(const Config &config, CValidationState &state, + CBlockIndex *pindexMostWork, + const std::shared_ptr &pblock, + bool &fInvalidFound, ConnectTrace &connectTrace); + bool ConnectTip(const Config &config, CValidationState &state, + CBlockIndex *pindexNew, + const std::shared_ptr &pblock, + ConnectTrace &connectTrace, + DisconnectedBlockTransactions &disconnectpool); + + CBlockIndex *AddToBlockIndex(const CBlockHeader &block); + /** Create a new block index entry for a given block hash */ + CBlockIndex *InsertBlockIndex(const uint256 &hash); + void CheckBlockIndex(const Consensus::Params &consensusParams); + + void InvalidBlockFound(CBlockIndex *pindex, const CValidationState &state); + CBlockIndex *FindMostWorkChain(); + bool ReceivedBlockTransactions(const CBlock &block, CValidationState &state, + CBlockIndex *pindexNew, + const CDiskBlockPos &pos); + + bool RollforwardBlock(const CBlockIndex *pindex, CCoinsViewCache &inputs, + const Config &config); +} g_chainstate; /** * Global state */ CCriticalSection cs_main; -BlockMap mapBlockIndex; -CChain chainActive; +BlockMap &mapBlockIndex = g_chainstate.mapBlockIndex; +CChain &chainActive = g_chainstate.chainActive; CBlockIndex *pindexBestHeader = nullptr; CWaitableCriticalSection g_best_block_mutex; CConditionVariable g_best_block_cv; @@ -92,8 +198,6 @@ CTxMemPool g_mempool; -static void CheckBlockIndex(const Consensus::Params &consensusParams); - /** Constant stuff for coinbase transactions we create: */ CScript COINBASE_FLAGS; @@ -101,9 +205,8 @@ // Internal stuff namespace { - -CBlockIndex *pindexBestInvalid; -CBlockIndex *pindexBestParked; +CBlockIndex *&pindexBestInvalid = g_chainstate.pindexBestInvalid; +CBlockIndex *&pindexBestParked = g_chainstate.pindexBestParked; /** * The best finalized block. @@ -111,17 +214,12 @@ */ CBlockIndex const *pindexFinalized; -/** - * The set of all CBlockIndex entries with BLOCK_VALID_TRANSACTIONS (for itself - * and all ancestors) and as good as our current tip or better. Entries may be - * failed, though, and pruning nodes may be missing the data for the block. - */ -std::set setBlockIndexCandidates; /** * All pairs A->B, where A (or one of its ancestors) misses transactions, but B * has transactions. Pruned nodes may have entries where B is missing data. */ -std::multimap mapBlocksUnlinked; +std::multimap &mapBlocksUnlinked = + g_chainstate.mapBlocksUnlinked; CCriticalSection cs_LastBlockFile; std::vector vinfoBlockFile; @@ -1058,8 +1156,8 @@ FormatISO8601DateTime(tip->GetBlockTime())); } -static void InvalidBlockFound(CBlockIndex *pindex, - const CValidationState &state) { +void CChainState::InvalidBlockFound(CBlockIndex *pindex, + const CValidationState &state) { if (!state.CorruptionPossible()) { pindex->nStatus = pindex->nStatus.withFailed(); setDirtyBlockIndex.insert(pindex); @@ -1365,9 +1463,9 @@ * Undo the effects of this block (with given index) on the UTXO set represented * by coins. When FAILED is returned, view is left in an indeterminate state. */ -static DisconnectResult DisconnectBlock(const CBlock &block, - const CBlockIndex *pindex, - CCoinsViewCache &view) { +DisconnectResult CChainState::DisconnectBlock(const CBlock &block, + const CBlockIndex *pindex, + CCoinsViewCache &view) { CBlockUndo blockUndo; if (!UndoReadFromDisk(blockUndo, pindex)) { error("DisconnectBlock(): failure reading undo data"); @@ -1615,9 +1713,9 @@ * done; ConnectBlock() can fail if those validity checks fail (among other * reasons). */ -static bool ConnectBlock(const Config &config, const CBlock &block, - CValidationState &state, CBlockIndex *pindex, - CCoinsViewCache &view, bool fJustCheck = false) { +bool CChainState::ConnectBlock(const Config &config, const CBlock &block, + CValidationState &state, CBlockIndex *pindex, + CCoinsViewCache &view, bool fJustCheck) { AssertLockHeld(cs_main); assert(pindex); // pindex->phashBlock can be null if called by @@ -2183,8 +2281,8 @@ * disconnectpool (note that the caller is responsible for mempool consistency * in any case). */ -static bool DisconnectTip(const Config &config, CValidationState &state, - DisconnectedBlockTransactions *disconnectpool) { +bool CChainState::DisconnectTip(const Config &config, CValidationState &state, + DisconnectedBlockTransactions *disconnectpool) { CBlockIndex *pindexDelete = chainActive.Tip(); assert(pindexDelete); @@ -2413,11 +2511,11 @@ * by copying pblock) - if that is not intended, care must be taken to remove * the last entry in blocksConnected in case of failure. */ -static bool ConnectTip(const Config &config, CValidationState &state, - CBlockIndex *pindexNew, - const std::shared_ptr &pblock, - ConnectTrace &connectTrace, - DisconnectedBlockTransactions &disconnectpool) { +bool CChainState::ConnectTip(const Config &config, CValidationState &state, + CBlockIndex *pindexNew, + const std::shared_ptr &pblock, + ConnectTrace &connectTrace, + DisconnectedBlockTransactions &disconnectpool) { AssertLockHeld(cs_main); assert(pindexNew->pprev == chainActive.Tip()); @@ -2533,7 +2631,7 @@ * Return the tip of the chain with the most work in it, that isn't known to be * invalid (it's however far from certain to be valid). */ -static CBlockIndex *FindMostWorkChain() { +CBlockIndex *CChainState::FindMostWorkChain() { AssertLockHeld(cs_main); do { CBlockIndex *pindexNew = nullptr; @@ -2682,7 +2780,7 @@ * Delete all entries in setBlockIndexCandidates that are worse than the current * tip. */ -static void PruneBlockIndexCandidates() { +void CChainState::PruneBlockIndexCandidates() { // Note that we can't delete the current block itself, as we may need to // return to it later in case a reorganization to a better block fails. auto it = setBlockIndexCandidates.begin(); @@ -2701,11 +2799,10 @@ * pblock is either nullptr or a pointer to a CBlock corresponding to * pindexMostWork. */ -static bool ActivateBestChainStep(const Config &config, CValidationState &state, - CBlockIndex *pindexMostWork, - const std::shared_ptr &pblock, - bool &fInvalidFound, - ConnectTrace &connectTrace) { +bool CChainState::ActivateBestChainStep( + const Config &config, CValidationState &state, CBlockIndex *pindexMostWork, + const std::shared_ptr &pblock, bool &fInvalidFound, + ConnectTrace &connectTrace) { AssertLockHeld(cs_main); const CBlockIndex *pindexOldTip = chainActive.Tip(); const CBlockIndex *pindexFork = chainActive.FindFork(pindexMostWork); @@ -2823,8 +2920,9 @@ } } -bool ActivateBestChain(const Config &config, CValidationState &state, - std::shared_ptr pblock) { +bool CChainState::ActivateBestChain(const Config &config, + CValidationState &state, + std::shared_ptr pblock) { // Note that while we're often called here from ProcessNewBlock, this is // far from a guarantee. Things in the P2P/RPC will often end up calling // us in the middle of ProcessNewBlock - do not assume pblock is set @@ -2927,8 +3025,13 @@ return true; } -bool PreciousBlock(const Config &config, CValidationState &state, - CBlockIndex *pindex) { +bool ActivateBestChain(const Config &config, CValidationState &state, + std::shared_ptr pblock) { + return g_chainstate.ActivateBestChain(config, state, std::move(pblock)); +} + +bool CChainState::PreciousBlock(const Config &config, CValidationState &state, + CBlockIndex *pindex) { { LOCK(cs_main); if (pindex->nChainWork < chainActive.Tip()->nChainWork) { @@ -2964,8 +3067,13 @@ return ActivateBestChain(config, state); } -static bool UnwindBlock(const Config &config, CValidationState &state, - CBlockIndex *pindex, bool invalidate) { +bool PreciousBlock(const Config &config, CValidationState &state, + CBlockIndex *pindex) { + return g_chainstate.PreciousBlock(config, state, pindex); +} + +bool CChainState::UnwindBlock(const Config &config, CValidationState &state, + CBlockIndex *pindex, bool invalidate) { AssertLockHeld(cs_main); // Mark the block as either invalid or parked. @@ -3040,16 +3148,17 @@ bool InvalidateBlock(const Config &config, CValidationState &state, CBlockIndex *pindex) { - return UnwindBlock(config, state, pindex, true); + return g_chainstate.UnwindBlock(config, state, pindex, true); } bool ParkBlock(const Config &config, CValidationState &state, CBlockIndex *pindex) { - return UnwindBlock(config, state, pindex, false); + return g_chainstate.UnwindBlock(config, state, pindex, false); } template -void UpdateFlagsForBlock(CBlockIndex *pindexBase, CBlockIndex *pindex, F f) { +void CChainState::UpdateFlagsForBlock(CBlockIndex *pindexBase, + CBlockIndex *pindex, F f) { BlockStatus newStatus = f(pindex->nStatus); if (pindex->nStatus != newStatus && pindex->GetAncestor(pindexBase->nHeight) == pindexBase) { @@ -3064,7 +3173,7 @@ } template -void UpdateFlags(CBlockIndex *pindex, F f, C fchild) { +void CChainState::UpdateFlags(CBlockIndex *pindex, F f, C fchild) { AssertLockHeld(cs_main); // Update the current block. @@ -3088,12 +3197,12 @@ } } -template void UpdateFlags(CBlockIndex *pindex, F f) { +template void CChainState::UpdateFlags(CBlockIndex *pindex, F f) { // Handy shorthand. UpdateFlags(pindex, f, f); } -bool ResetBlockFailureFlags(CBlockIndex *pindex) { +bool CChainState::ResetBlockFailureFlags(CBlockIndex *pindex) { AssertLockHeld(cs_main); if (pindexBestInvalid && @@ -3117,7 +3226,11 @@ return true; } -static bool UnparkBlockImpl(CBlockIndex *pindex, bool fClearChildren) { +bool ResetBlockFailureFlags(CBlockIndex *pindex) { + return g_chainstate.ResetBlockFailureFlags(pindex); +} + +bool CChainState::UnparkBlockImpl(CBlockIndex *pindex, bool fClearChildren) { AssertLockHeld(cs_main); if (pindexBestParked && @@ -3140,11 +3253,11 @@ } bool UnparkBlockAndChildren(CBlockIndex *pindex) { - return UnparkBlockImpl(pindex, true); + return g_chainstate.UnparkBlockImpl(pindex, true); } bool UnparkBlock(CBlockIndex *pindex) { - return UnparkBlockImpl(pindex, false); + return g_chainstate.UnparkBlockImpl(pindex, false); } const CBlockIndex *GetFinalizedBlock() { @@ -3158,7 +3271,7 @@ pindexFinalized->GetAncestor(pindex->nHeight) == pindex; } -static CBlockIndex *AddToBlockIndex(const CBlockHeader &block) { +CBlockIndex *CChainState::AddToBlockIndex(const CBlockHeader &block) { // Check for duplicate uint256 hash = block.GetHash(); BlockMap::iterator it = mapBlockIndex.find(hash); @@ -3203,9 +3316,10 @@ * Mark a block as having its data received and checked (up to * BLOCK_VALID_TRANSACTIONS). */ -bool ReceivedBlockTransactions(const CBlock &block, CValidationState &state, - CBlockIndex *pindexNew, - const CDiskBlockPos &pos) { +bool CChainState::ReceivedBlockTransactions(const CBlock &block, + CValidationState &state, + CBlockIndex *pindexNew, + const CDiskBlockPos &pos) { pindexNew->nTx = block.vtx.size(); pindexNew->nChainTx = 0; pindexNew->nFile = pos.nFile; @@ -3690,8 +3804,10 @@ * * Returns true if the block is succesfully added to the block index. */ -static bool AcceptBlockHeader(const Config &config, const CBlockHeader &block, - CValidationState &state, CBlockIndex **ppindex) { +bool CChainState::AcceptBlockHeader(const Config &config, + const CBlockHeader &block, + CValidationState &state, + CBlockIndex **ppindex) { AssertLockHeld(cs_main); const CChainParams &chainparams = config.GetChainParams(); @@ -3769,7 +3885,8 @@ for (const CBlockHeader &header : headers) { // Use a temp pindex instead of ppindex to avoid a const_cast CBlockIndex *pindex = nullptr; - if (!AcceptBlockHeader(config, header, state, &pindex)) { + if (!g_chainstate.AcceptBlockHeader(config, header, state, + &pindex)) { if (first_invalid) { *first_invalid = header; } @@ -3824,10 +3941,10 @@ * @param[in-out] fNewBlock True if block was first received via this call. * @return True if the block is accepted as a valid block and written to disk. */ -static bool AcceptBlock(const Config &config, - const std::shared_ptr &pblock, - CValidationState &state, bool fRequested, - const CDiskBlockPos *dbp, bool *fNewBlock) { +bool CChainState::AcceptBlock(const Config &config, + const std::shared_ptr &pblock, + CValidationState &state, bool fRequested, + const CDiskBlockPos *dbp, bool *fNewBlock) { AssertLockHeld(cs_main); const CBlock &block = *pblock; @@ -3975,6 +4092,8 @@ FlushStateToDisk(config.GetChainParams(), state, FlushStateMode::NONE); } + CheckBlockIndex(chainparams.GetConsensus()); + return true; } @@ -3988,8 +4107,6 @@ *fNewBlock = false; } - const CChainParams &chainparams = config.GetChainParams(); - CValidationState state; // Ensure that CheckBlock() passes before calling AcceptBlock, as // belt-and-suspenders. @@ -3999,11 +4116,10 @@ if (ret) { // Store to disk - ret = AcceptBlock(config, pblock, state, fForceProcessing, nullptr, - fNewBlock); + ret = g_chainstate.AcceptBlock( + config, pblock, state, fForceProcessing, nullptr, fNewBlock); } - CheckBlockIndex(chainparams.GetConsensus()); if (!ret) { GetMainSignals().BlockChecked(*pblock, state); return error("%s: AcceptBlock FAILED", __func__); @@ -4014,7 +4130,7 @@ // Only used to report errors, not invalidity - ignore it CValidationState state; - if (!ActivateBestChain(config, state, pblock)) { + if (!g_chainstate.ActivateBestChain(config, state, pblock)) { return error("%s: ActivateBestChain failed", __func__); } @@ -4048,7 +4164,8 @@ FormatStateMessage(state)); } - if (!ConnectBlock(config, block, state, &indexDummy, viewNew, true)) { + if (!g_chainstate.ConnectBlock(config, block, state, &indexDummy, viewNew, + true)) { return false; } @@ -4291,7 +4408,7 @@ return GetDataDir() / "blocks" / strprintf("%s%05u.dat", prefix, pos.nFile); } -CBlockIndex *InsertBlockIndex(uint256 hash) { +CBlockIndex *CChainState::InsertBlockIndex(const uint256 &hash) { if (hash.IsNull()) { return nullptr; } @@ -4310,8 +4427,11 @@ return pindexNew; } -static bool LoadBlockIndexDB(const Config &config) { - if (!pblocktree->LoadBlockIndexGuts(config, InsertBlockIndex)) { +bool CChainState::LoadBlockIndex(const Config &config, + CBlockTreeDB &blocktree) { + if (!blocktree.LoadBlockIndexGuts(config, [this](const uint256 &hash) { + return this->InsertBlockIndex(hash); + })) { return false; } @@ -4377,6 +4497,14 @@ } } + return true; +} + +bool static LoadBlockIndexDB(const Config &config) { + if (!g_chainstate.LoadBlockIndex(config, *pblocktree)) { + return false; + } + // Load block file info pblocktree->ReadLastBlockFile(nLastBlockFile); vinfoBlockFile.resize(nLastBlockFile + 1); @@ -4461,7 +4589,7 @@ chainActive.SetTip(it->second); - PruneBlockIndexCandidates(); + g_chainstate.PruneBlockIndexCandidates(); LogPrintf( "Loaded best chain: hashBestChain=%s height=%d date=%s progress=%f\n", @@ -4567,7 +4695,8 @@ (coins.DynamicMemoryUsage() + pcoinsTip->DynamicMemoryUsage()) <= nCoinCacheUsage) { assert(coins.GetBestBlock() == pindex->GetBlockHash()); - DisconnectResult res = DisconnectBlock(block, pindex, coins); + DisconnectResult res = + g_chainstate.DisconnectBlock(block, pindex, coins); if (res == DISCONNECT_FAILED) { return error("VerifyDB(): *** irrecoverable inconsistency in " "block data at %d, hash=%s", @@ -4615,7 +4744,8 @@ "VerifyDB(): *** ReadBlockFromDisk failed at %d, hash=%s", pindex->nHeight, pindex->GetBlockHash().ToString()); } - if (!ConnectBlock(config, block, state, pindex, coins)) { + if (!g_chainstate.ConnectBlock(config, block, state, pindex, + coins)) { return error( "VerifyDB(): *** found unconnectable block at %d, hash=%s", pindex->nHeight, pindex->GetBlockHash().ToString()); @@ -4635,8 +4765,9 @@ * Apply the effects of a block on the utxo cache, ignoring that it may already * have been applied. */ -static bool RollforwardBlock(const CBlockIndex *pindex, CCoinsViewCache &view, - const Config &config) { +bool CChainState::RollforwardBlock(const CBlockIndex *pindex, + CCoinsViewCache &view, + const Config &config) { // TODO: merge with ConnectBlock CBlock block; if (!ReadBlockFromDisk(block, pindex, config)) { @@ -4662,7 +4793,7 @@ return true; } -bool ReplayBlocks(const Config &config, CCoinsView *view) { +bool CChainState::ReplayBlocks(const Config &config, CCoinsView *view) { LOCK(cs_main); CCoinsViewCache cache(view); @@ -4756,7 +4887,11 @@ return true; } -bool RewindBlockIndex(const Config &config) { +bool ReplayBlocks(const Config &config, CCoinsView *view) { + return g_chainstate.ReplayBlocks(config, view); +} + +bool CChainState::RewindBlockIndex(const Config &config) { LOCK(cs_main); const CChainParams ¶ms = config.GetChainParams(); @@ -4805,11 +4940,23 @@ PruneBlockIndexCandidates(); CheckBlockIndex(params.GetConsensus()); + } + + return true; +} + +bool RewindBlockIndex(const Config &config) { + if (!g_chainstate.RewindBlockIndex(config)) { + return false; + } + if (chainActive.Tip() != nullptr) { // FlushStateToDisk can possibly read chainActive. Be conservative // and skip it here, we're about to -reindex-chainstate anyway, so // it'll get called a bunch real soon. - if (!FlushStateToDisk(params, state, FlushStateMode::ALWAYS)) { + CValidationState state; + if (!FlushStateToDisk(config.GetChainParams(), state, + FlushStateMode::ALWAYS)) { return false; } } @@ -4819,9 +4966,15 @@ // May NOT be used after any connections are up as much of the peer-processing // logic assumes a consistent block index state +void CChainState::UnloadBlockIndex() { + setBlockIndexCandidates.clear(); +} + +// May NOT be used after any connections are up as much +// of the peer-processing logic assumes a consistent +// block index state void UnloadBlockIndex() { LOCK(cs_main); - setBlockIndexCandidates.clear(); chainActive.SetTip(nullptr); pindexFinalized = nullptr; pindexBestInvalid = nullptr; @@ -4842,6 +4995,8 @@ mapBlockIndex.clear(); fHavePruned = false; + + g_chainstate.UnloadBlockIndex(); } bool LoadBlockIndex(const Config &config) { @@ -4871,7 +5026,7 @@ return true; } -bool LoadGenesisBlock(const CChainParams &chainparams) { +bool CChainState::LoadGenesisBlock(const CChainParams &chainparams) { LOCK(cs_main); // Check whether we're already initialized by checking for genesis in @@ -4904,6 +5059,10 @@ return true; } +bool LoadGenesisBlock(const CChainParams &chainparams) { + return g_chainstate.LoadGenesisBlock(chainparams); +} + bool LoadExternalBlockFile(const Config &config, FILE *fileIn, CDiskBlockPos *dbp) { // Map of disk positions for blocks with unknown parent (only used for @@ -4985,8 +5144,8 @@ !mapBlockIndex[hash]->nStatus.hasData()) { LOCK(cs_main); CValidationState state; - if (AcceptBlock(config, pblock, state, true, dbp, - nullptr)) { + if (g_chainstate.AcceptBlock(config, pblock, state, true, + dbp, nullptr)) { nLoaded++; } @@ -5037,8 +5196,9 @@ head.ToString()); LOCK(cs_main); CValidationState dummy; - if (AcceptBlock(config, pblockrecursive, dummy, - true, &it->second, nullptr)) { + if (g_chainstate.AcceptBlock( + config, pblockrecursive, dummy, true, + &it->second, nullptr)) { nLoaded++; queue.push_back(pblockrecursive->GetHash()); } @@ -5065,7 +5225,7 @@ return nLoaded > 0; } -static void CheckBlockIndex(const Consensus::Params &consensusParams) { +void CChainState::CheckBlockIndex(const Consensus::Params &consensusParams) { if (!fCheckBlockIndex) { return; }