@@ -170,8 +170,6 @@ CBlockIndex* BlockManager::FindForkInGlobalIndex(const CChain& chain, const CBlo
170170 return chain.Genesis ();
171171}
172172
173- std::unique_ptr<CBlockTreeDB> pblocktree;
174-
175173bool CheckInputScripts (const CTransaction& tx, TxValidationState& state,
176174 const CCoinsViewCache& inputs, unsigned int flags, bool cacheSigStore,
177175 bool cacheFullScriptStore, PrecomputedTransactionData& txdata,
@@ -2075,7 +2073,7 @@ bool CChainState::FlushStateToDisk(
20752073 if (!setFilesToPrune.empty ()) {
20762074 fFlushForPrune = true ;
20772075 if (!fHavePruned ) {
2078- pblocktree ->WriteFlag (" prunedblockfiles" , true );
2076+ m_blockman. m_block_tree_db ->WriteFlag (" prunedblockfiles" , true );
20792077 fHavePruned = true ;
20802078 }
20812079 }
@@ -2127,7 +2125,7 @@ bool CChainState::FlushStateToDisk(
21272125 vBlocks.push_back (*it);
21282126 setDirtyBlockIndex.erase (it++);
21292127 }
2130- if (!pblocktree ->WriteBatchSync (vFiles, nLastBlockFile, vBlocks)) {
2128+ if (!m_blockman. m_block_tree_db ->WriteBatchSync (vFiles, nLastBlockFile, vBlocks)) {
21312129 return AbortNode (state, " Failed to write to block index database" );
21322130 }
21332131 }
@@ -3700,11 +3698,11 @@ CBlockIndex * BlockManager::InsertBlockIndex(const uint256& hash)
37003698
37013699bool BlockManager::LoadBlockIndex (
37023700 const Consensus::Params& consensus_params,
3703- CBlockTreeDB& blocktree,
37043701 std::set<CBlockIndex*, CBlockIndexWorkComparator>& block_index_candidates)
37053702{
3706- if (!blocktree. LoadBlockIndexGuts (consensus_params, [this ](const uint256& hash) EXCLUSIVE_LOCKS_REQUIRED (cs_main) { return this ->InsertBlockIndex (hash); }))
3703+ if (!m_block_tree_db-> LoadBlockIndexGuts (consensus_params, [this ](const uint256& hash) EXCLUSIVE_LOCKS_REQUIRED (cs_main) { return this ->InsertBlockIndex (hash); })) {
37073704 return false ;
3705+ }
37083706
37093707 // Calculate nChainWork
37103708 std::vector<std::pair<int , CBlockIndex*> > vSortedByHeight;
@@ -3764,25 +3762,25 @@ void BlockManager::Unload() {
37643762 m_block_index.clear ();
37653763}
37663764
3767- bool CChainState ::LoadBlockIndexDB ()
3765+ bool BlockManager ::LoadBlockIndexDB (std::set<CBlockIndex*, CBlockIndexWorkComparator>& setBlockIndexCandidates )
37683766{
3769- if (!m_blockman. LoadBlockIndex (
3770- m_params .GetConsensus (), *pblocktree ,
3767+ if (!LoadBlockIndex (
3768+ ::Params () .GetConsensus(),
37713769 setBlockIndexCandidates)) {
37723770 return false ;
37733771 }
37743772
37753773 // Load block file info
3776- pblocktree ->ReadLastBlockFile (nLastBlockFile);
3774+ m_block_tree_db ->ReadLastBlockFile (nLastBlockFile);
37773775 vinfoBlockFile.resize (nLastBlockFile + 1 );
37783776 LogPrintf (" %s: last block file = %i\n " , __func__, nLastBlockFile);
37793777 for (int nFile = 0 ; nFile <= nLastBlockFile; nFile++) {
3780- pblocktree ->ReadBlockFileInfo (nFile, vinfoBlockFile[nFile]);
3778+ m_block_tree_db ->ReadBlockFileInfo (nFile, vinfoBlockFile[nFile]);
37813779 }
37823780 LogPrintf (" %s: last block file info: %s\n " , __func__, vinfoBlockFile[nLastBlockFile].ToString ());
37833781 for (int nFile = nLastBlockFile + 1 ; true ; nFile++) {
37843782 CBlockFileInfo info;
3785- if (pblocktree ->ReadBlockFileInfo (nFile, info)) {
3783+ if (m_block_tree_db ->ReadBlockFileInfo (nFile, info)) {
37863784 vinfoBlockFile.push_back (info);
37873785 } else {
37883786 break ;
@@ -3792,7 +3790,7 @@ bool CChainState::LoadBlockIndexDB()
37923790 // Check presence of blk files
37933791 LogPrintf (" Checking all blk files are present...\n " );
37943792 std::set<int > setBlkDataFiles;
3795- for (const std::pair<const uint256, CBlockIndex*>& item : m_blockman. m_block_index ) {
3793+ for (const std::pair<const uint256, CBlockIndex*>& item : m_block_index) {
37963794 CBlockIndex* pindex = item.second ;
37973795 if (pindex->nStatus & BLOCK_HAVE_DATA) {
37983796 setBlkDataFiles.insert (pindex->nFile );
@@ -3807,13 +3805,13 @@ bool CChainState::LoadBlockIndexDB()
38073805 }
38083806
38093807 // Check whether we have ever pruned block & undo files
3810- pblocktree ->ReadFlag (" prunedblockfiles" , fHavePruned );
3808+ m_block_tree_db ->ReadFlag (" prunedblockfiles" , fHavePruned );
38113809 if (fHavePruned )
38123810 LogPrintf (" LoadBlockIndexDB(): Block files have previously been pruned\n " );
38133811
38143812 // Check whether we need to continue reindexing
38153813 bool fReindexing = false ;
3816- pblocktree ->ReadReindexing (fReindexing );
3814+ m_block_tree_db ->ReadReindexing (fReindexing );
38173815 if (fReindexing ) fReindex = true ;
38183816
38193817 return true ;
@@ -4114,7 +4112,7 @@ bool ChainstateManager::LoadBlockIndex()
41144112 // Load block index from databases
41154113 bool needs_init = fReindex ;
41164114 if (!fReindex ) {
4117- bool ret = ActiveChainstate ().LoadBlockIndexDB ( );
4115+ bool ret = m_blockman. LoadBlockIndexDB ( ActiveChainstate ().setBlockIndexCandidates );
41184116 if (!ret) return false ;
41194117 needs_init = m_blockman.m_block_index .empty ();
41204118 }
0 commit comments