@@ -197,8 +197,6 @@ CBlockIndex* BlockManager::FindForkInGlobalIndex(const CChain& chain, const CBlo
197197 return chain.Genesis ();
198198}
199199
200- std::unique_ptr<CBlockTreeDB> pblocktree;
201-
202200bool CheckInputScripts (const CTransaction& tx, TxValidationState &state, const CCoinsViewCache &inputs, unsigned int flags, bool cacheSigStore, bool cacheFullScriptStore, PrecomputedTransactionData& txdata, std::vector<CScriptCheck> *pvChecks = nullptr );
203201static FILE* OpenUndoFile (const FlatFilePos &pos, bool fReadOnly = false );
204202static FlatFileSeq BlockFileSeq ();
@@ -2525,7 +2523,7 @@ bool CChainState::FlushStateToDisk(
25252523 if (!setFilesToPrune.empty ()) {
25262524 fFlushForPrune = true ;
25272525 if (!fHavePruned ) {
2528- pblocktree ->WriteFlag (" prunedblockfiles" , true );
2526+ m_blockman. m_block_tree_db ->WriteFlag (" prunedblockfiles" , true );
25292527 fHavePruned = true ;
25302528 }
25312529 }
@@ -2580,7 +2578,7 @@ bool CChainState::FlushStateToDisk(
25802578 vBlocks.push_back (*it);
25812579 setDirtyBlockIndex.erase (it++);
25822580 }
2583- if (!pblocktree ->WriteBatchSync (vFiles, nLastBlockFile, vBlocks)) {
2581+ if (!m_blockman. m_block_tree_db ->WriteBatchSync (vFiles, nLastBlockFile, vBlocks)) {
25842582 return AbortNode (state, " Failed to write to block index database" );
25852583 }
25862584 }
@@ -4477,11 +4475,11 @@ CBlockIndex * BlockManager::InsertBlockIndex(const uint256& hash)
44774475
44784476bool BlockManager::LoadBlockIndex (
44794477 const Consensus::Params& consensus_params,
4480- CBlockTreeDB& blocktree,
44814478 std::set<CBlockIndex*, CBlockIndexWorkComparator>& block_index_candidates)
44824479{
4483- if (!blocktree. LoadBlockIndexGuts (consensus_params, [this ](const uint256& hash) EXCLUSIVE_LOCKS_REQUIRED (cs_main) { return this ->InsertBlockIndex (hash); }))
4480+ if (!m_block_tree_db-> LoadBlockIndexGuts (consensus_params, [this ](const uint256& hash) EXCLUSIVE_LOCKS_REQUIRED (cs_main) { return this ->InsertBlockIndex (hash); })) {
44844481 return false ;
4482+ }
44854483
44864484 // Calculate nChainWork
44874485 std::vector<std::pair<int , CBlockIndex*> > vSortedByHeight;
@@ -4547,25 +4545,20 @@ void BlockManager::Unload() {
45474545 m_prev_block_index.clear ();
45484546}
45494547
4550- bool CChainState ::LoadBlockIndexDB ()
4548+ bool BlockManager ::LoadBlockIndexDB (std::set<CBlockIndex*, CBlockIndexWorkComparator>& setBlockIndexCandidates )
45514549{
4552- if (!m_blockman. LoadBlockIndex (
4553- m_params .GetConsensus (), *pblocktree ,
4550+ if (!LoadBlockIndex (
4551+ ::Params () .GetConsensus(),
45544552 setBlockIndexCandidates)) {
45554553 return false ;
4556- }
45574554
45584555 // Load block file info
4559- pblocktree->ReadLastBlockFile (nLastBlockFile);
4560- vinfoBlockFile.resize (nLastBlockFile + 1 );
4561- LogPrintf (" %s: last block file = %i\n " , __func__, nLastBlockFile);
4562- for (int nFile = 0 ; nFile <= nLastBlockFile; nFile++) {
4563- pblocktree->ReadBlockFileInfo (nFile, vinfoBlockFile[nFile]);
4556+ m_block_tree_db->ReadLastBlockFile (nLastBlockFile);
45644557 }
45654558 LogPrintf (" %s: last block file info: %s\n " , __func__, vinfoBlockFile[nLastBlockFile].ToString ());
45664559 for (int nFile = nLastBlockFile + 1 ; true ; nFile++) {
45674560 CBlockFileInfo info;
4568- if (pblocktree ->ReadBlockFileInfo (nFile, info)) {
4561+ if (m_block_tree_db ->ReadBlockFileInfo (nFile, info)) {
45694562 vinfoBlockFile.push_back (info);
45704563 } else {
45714564 break ;
@@ -4575,7 +4568,7 @@ bool CChainState::LoadBlockIndexDB()
45754568 // Check presence of blk files
45764569 LogPrintf (" Checking all blk files are present...\n " );
45774570 std::set<int > setBlkDataFiles;
4578- for (const std::pair<const uint256, CBlockIndex*>& item : m_blockman. m_block_index ) {
4571+ for (const std::pair<const uint256, CBlockIndex*>& item : m_block_index) {
45794572 CBlockIndex* pindex = item.second ;
45804573 if (pindex->nStatus & BLOCK_HAVE_DATA) {
45814574 setBlkDataFiles.insert (pindex->nFile );
@@ -4590,13 +4583,13 @@ bool CChainState::LoadBlockIndexDB()
45904583 }
45914584
45924585 // Check whether we have ever pruned block & undo files
4593- pblocktree ->ReadFlag (" prunedblockfiles" , fHavePruned );
4586+ m_block_tree_db ->ReadFlag (" prunedblockfiles" , fHavePruned );
45944587 if (fHavePruned )
45954588 LogPrintf (" LoadBlockIndexDB(): Block files have previously been pruned\n " );
45964589
45974590 // Check whether we need to continue reindexing
45984591 bool fReindexing = false ;
4599- pblocktree ->ReadReindexing (fReindexing );
4592+ m_block_tree_db ->ReadReindexing (fReindexing );
46004593 if (fReindexing ) fReindex = true ;
46014594
46024595 // Check whether we have an address index
@@ -4988,7 +4981,7 @@ bool ChainstateManager::LoadBlockIndex()
49884981 // Load block index from databases
49894982 bool needs_init = fReindex ;
49904983 if (!fReindex ) {
4991- bool ret = ActiveChainstate ().LoadBlockIndexDB ( );
4984+ bool ret = m_blockman. LoadBlockIndexDB ( ActiveChainstate ().setBlockIndexCandidates );
49924985 if (!ret) return false ;
49934986 needs_init = m_blockman.m_block_index .empty ();
49944987 }
0 commit comments