@@ -170,8 +170,6 @@ CBlockIndex* BlockManager::FindForkInGlobalIndex(const CChain& chain, const CBlo
170
170
return chain.Genesis ();
171
171
}
172
172
173
- std::unique_ptr<CBlockTreeDB> pblocktree;
174
-
175
173
bool CheckInputScripts (const CTransaction& tx, TxValidationState& state,
176
174
const CCoinsViewCache& inputs, unsigned int flags, bool cacheSigStore,
177
175
bool cacheFullScriptStore, PrecomputedTransactionData& txdata,
@@ -2075,7 +2073,7 @@ bool CChainState::FlushStateToDisk(
2075
2073
if (!setFilesToPrune.empty ()) {
2076
2074
fFlushForPrune = true ;
2077
2075
if (!fHavePruned ) {
2078
- pblocktree ->WriteFlag (" prunedblockfiles" , true );
2076
+ m_blockman. m_block_tree_db ->WriteFlag (" prunedblockfiles" , true );
2079
2077
fHavePruned = true ;
2080
2078
}
2081
2079
}
@@ -2127,7 +2125,7 @@ bool CChainState::FlushStateToDisk(
2127
2125
vBlocks.push_back (*it);
2128
2126
setDirtyBlockIndex.erase (it++);
2129
2127
}
2130
- if (!pblocktree ->WriteBatchSync (vFiles, nLastBlockFile, vBlocks)) {
2128
+ if (!m_blockman. m_block_tree_db ->WriteBatchSync (vFiles, nLastBlockFile, vBlocks)) {
2131
2129
return AbortNode (state, " Failed to write to block index database" );
2132
2130
}
2133
2131
}
@@ -3700,11 +3698,11 @@ CBlockIndex * BlockManager::InsertBlockIndex(const uint256& hash)
3700
3698
3701
3699
bool BlockManager::LoadBlockIndex (
3702
3700
const Consensus::Params& consensus_params,
3703
- CBlockTreeDB& blocktree,
3704
3701
std::set<CBlockIndex*, CBlockIndexWorkComparator>& block_index_candidates)
3705
3702
{
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); })) {
3707
3704
return false ;
3705
+ }
3708
3706
3709
3707
// Calculate nChainWork
3710
3708
std::vector<std::pair<int , CBlockIndex*> > vSortedByHeight;
@@ -3764,25 +3762,25 @@ void BlockManager::Unload() {
3764
3762
m_block_index.clear ();
3765
3763
}
3766
3764
3767
- bool CChainState ::LoadBlockIndexDB ()
3765
+ bool BlockManager ::LoadBlockIndexDB (std::set<CBlockIndex*, CBlockIndexWorkComparator>& setBlockIndexCandidates )
3768
3766
{
3769
- if (!m_blockman. LoadBlockIndex (
3770
- m_params .GetConsensus (), *pblocktree ,
3767
+ if (!LoadBlockIndex (
3768
+ ::Params () .GetConsensus(),
3771
3769
setBlockIndexCandidates)) {
3772
3770
return false ;
3773
3771
}
3774
3772
3775
3773
// Load block file info
3776
- pblocktree ->ReadLastBlockFile (nLastBlockFile);
3774
+ m_block_tree_db ->ReadLastBlockFile (nLastBlockFile);
3777
3775
vinfoBlockFile.resize (nLastBlockFile + 1 );
3778
3776
LogPrintf (" %s: last block file = %i\n " , __func__, nLastBlockFile);
3779
3777
for (int nFile = 0 ; nFile <= nLastBlockFile; nFile++) {
3780
- pblocktree ->ReadBlockFileInfo (nFile, vinfoBlockFile[nFile]);
3778
+ m_block_tree_db ->ReadBlockFileInfo (nFile, vinfoBlockFile[nFile]);
3781
3779
}
3782
3780
LogPrintf (" %s: last block file info: %s\n " , __func__, vinfoBlockFile[nLastBlockFile].ToString ());
3783
3781
for (int nFile = nLastBlockFile + 1 ; true ; nFile++) {
3784
3782
CBlockFileInfo info;
3785
- if (pblocktree ->ReadBlockFileInfo (nFile, info)) {
3783
+ if (m_block_tree_db ->ReadBlockFileInfo (nFile, info)) {
3786
3784
vinfoBlockFile.push_back (info);
3787
3785
} else {
3788
3786
break ;
@@ -3792,7 +3790,7 @@ bool CChainState::LoadBlockIndexDB()
3792
3790
// Check presence of blk files
3793
3791
LogPrintf (" Checking all blk files are present...\n " );
3794
3792
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) {
3796
3794
CBlockIndex* pindex = item.second ;
3797
3795
if (pindex->nStatus & BLOCK_HAVE_DATA) {
3798
3796
setBlkDataFiles.insert (pindex->nFile );
@@ -3807,13 +3805,13 @@ bool CChainState::LoadBlockIndexDB()
3807
3805
}
3808
3806
3809
3807
// Check whether we have ever pruned block & undo files
3810
- pblocktree ->ReadFlag (" prunedblockfiles" , fHavePruned );
3808
+ m_block_tree_db ->ReadFlag (" prunedblockfiles" , fHavePruned );
3811
3809
if (fHavePruned )
3812
3810
LogPrintf (" LoadBlockIndexDB(): Block files have previously been pruned\n " );
3813
3811
3814
3812
// Check whether we need to continue reindexing
3815
3813
bool fReindexing = false ;
3816
- pblocktree ->ReadReindexing (fReindexing );
3814
+ m_block_tree_db ->ReadReindexing (fReindexing );
3817
3815
if (fReindexing ) fReindex = true ;
3818
3816
3819
3817
return true ;
@@ -4114,7 +4112,7 @@ bool ChainstateManager::LoadBlockIndex()
4114
4112
// Load block index from databases
4115
4113
bool needs_init = fReindex ;
4116
4114
if (!fReindex ) {
4117
- bool ret = ActiveChainstate ().LoadBlockIndexDB ( );
4115
+ bool ret = m_blockman. LoadBlockIndexDB ( ActiveChainstate ().setBlockIndexCandidates );
4118
4116
if (!ret) return false ;
4119
4117
needs_init = m_blockman.m_block_index .empty ();
4120
4118
}
0 commit comments