@@ -179,8 +179,6 @@ CBlockIndex* BlockManager::FindForkInGlobalIndex(const CChain& chain, const CBlo
179
179
return chain.Genesis ();
180
180
}
181
181
182
- std::unique_ptr<CBlockTreeDB> pblocktree;
183
-
184
182
bool CheckInputScripts (const CTransaction& tx, TxValidationState &state, const CCoinsViewCache &inputs, unsigned int flags, bool cacheSigStore, bool cacheFullScriptStore, PrecomputedTransactionData& txdata, std::vector<CScriptCheck> *pvChecks = nullptr );
185
183
186
184
bool CheckFinalTx (const CBlockIndex* active_chain_tip, const CTransaction &tx, int flags)
@@ -1700,25 +1698,25 @@ DisconnectResult CChainState::DisconnectBlock(const CBlock& block, const CBlockI
1700
1698
1701
1699
1702
1700
if (fSpentIndex ) {
1703
- if (!pblocktree ->UpdateSpentIndex (spentIndex)) {
1701
+ if (!m_blockman. m_block_tree_db ->UpdateSpentIndex (spentIndex)) {
1704
1702
AbortNode (" Failed to delete spent index" );
1705
1703
return DISCONNECT_FAILED;
1706
1704
}
1707
1705
}
1708
1706
1709
1707
if (fAddressIndex ) {
1710
- if (!pblocktree ->EraseAddressIndex (addressIndex)) {
1708
+ if (!m_blockman. m_block_tree_db ->EraseAddressIndex (addressIndex)) {
1711
1709
AbortNode (" Failed to delete address index" );
1712
1710
return DISCONNECT_FAILED;
1713
1711
}
1714
- if (!pblocktree ->UpdateAddressUnspentIndex (addressUnspentIndex)) {
1712
+ if (!m_blockman. m_block_tree_db ->UpdateAddressUnspentIndex (addressUnspentIndex)) {
1715
1713
AbortNode (" Failed to write address unspent index" );
1716
1714
return DISCONNECT_FAILED;
1717
1715
}
1718
1716
}
1719
1717
1720
1718
if (fTimestampIndex ) {
1721
- if (!pblocktree ->EraseTimestampIndex (CTimestampIndexKey (pindex->nTime , pindex->GetBlockHash ()))) {
1719
+ if (!m_blockman. m_block_tree_db ->EraseTimestampIndex (CTimestampIndexKey (pindex->nTime , pindex->GetBlockHash ()))) {
1722
1720
AbortNode (" Failed to delete timestamp index" );
1723
1721
return DISCONNECT_FAILED;
1724
1722
}
@@ -2270,21 +2268,21 @@ bool CChainState::ConnectBlock(const CBlock& block, BlockValidationState& state,
2270
2268
int64_t nTime6 = GetTimeMicros ();
2271
2269
2272
2270
if (fAddressIndex ) {
2273
- if (!pblocktree ->WriteAddressIndex (addressIndex)) {
2271
+ if (!m_blockman. m_block_tree_db ->WriteAddressIndex (addressIndex)) {
2274
2272
return AbortNode (state, " Failed to write address index" );
2275
2273
}
2276
2274
2277
- if (!pblocktree ->UpdateAddressUnspentIndex (addressUnspentIndex)) {
2275
+ if (!m_blockman. m_block_tree_db ->UpdateAddressUnspentIndex (addressUnspentIndex)) {
2278
2276
return AbortNode (state, " Failed to write address unspent index" );
2279
2277
}
2280
2278
}
2281
2279
2282
2280
if (fSpentIndex )
2283
- if (!pblocktree ->UpdateSpentIndex (spentIndex))
2281
+ if (!m_blockman. m_block_tree_db ->UpdateSpentIndex (spentIndex))
2284
2282
return AbortNode (state, " Failed to write transaction index" );
2285
2283
2286
2284
if (fTimestampIndex )
2287
- if (!pblocktree ->WriteTimestampIndex (CTimestampIndexKey (pindex->nTime , pindex->GetBlockHash ())))
2285
+ if (!m_blockman. m_block_tree_db ->WriteTimestampIndex (CTimestampIndexKey (pindex->nTime , pindex->GetBlockHash ())))
2288
2286
return AbortNode (state, " Failed to write timestamp index" );
2289
2287
2290
2288
int64_t nTime7 = GetTimeMicros (); nTimeIndexWrite += nTime7 - nTime6;
@@ -2387,7 +2385,7 @@ bool CChainState::FlushStateToDisk(
2387
2385
if (!setFilesToPrune.empty ()) {
2388
2386
fFlushForPrune = true ;
2389
2387
if (!fHavePruned ) {
2390
- pblocktree ->WriteFlag (" prunedblockfiles" , true );
2388
+ m_blockman. m_block_tree_db ->WriteFlag (" prunedblockfiles" , true );
2391
2389
fHavePruned = true ;
2392
2390
}
2393
2391
}
@@ -2442,7 +2440,7 @@ bool CChainState::FlushStateToDisk(
2442
2440
vBlocks.push_back (*it);
2443
2441
setDirtyBlockIndex.erase (it++);
2444
2442
}
2445
- if (!pblocktree ->WriteBatchSync (vFiles, nLastBlockFile, vBlocks)) {
2443
+ if (!m_blockman. m_block_tree_db ->WriteBatchSync (vFiles, nLastBlockFile, vBlocks)) {
2446
2444
return AbortNode (state, " Failed to write to block index database" );
2447
2445
}
2448
2446
}
@@ -4215,11 +4213,11 @@ CBlockIndex * BlockManager::InsertBlockIndex(const uint256& hash)
4215
4213
4216
4214
bool BlockManager::LoadBlockIndex (
4217
4215
const Consensus::Params& consensus_params,
4218
- CBlockTreeDB& blocktree,
4219
4216
std::set<CBlockIndex*, CBlockIndexWorkComparator>& block_index_candidates)
4220
4217
{
4221
- if (!blocktree. LoadBlockIndexGuts (consensus_params, [this ](const uint256& hash) EXCLUSIVE_LOCKS_REQUIRED (cs_main) { return this ->InsertBlockIndex (hash); }))
4218
+ if (!m_block_tree_db-> LoadBlockIndexGuts (consensus_params, [this ](const uint256& hash) EXCLUSIVE_LOCKS_REQUIRED (cs_main) { return this ->InsertBlockIndex (hash); })) {
4222
4219
return false ;
4220
+ }
4223
4221
4224
4222
// Calculate nChainWork
4225
4223
std::vector<std::pair<int , CBlockIndex*> > vSortedByHeight;
@@ -4285,25 +4283,25 @@ void BlockManager::Unload() {
4285
4283
m_prev_block_index.clear ();
4286
4284
}
4287
4285
4288
- bool CChainState ::LoadBlockIndexDB ()
4286
+ bool BlockManager ::LoadBlockIndexDB (std::set<CBlockIndex*, CBlockIndexWorkComparator>& setBlockIndexCandidates )
4289
4287
{
4290
- if (!m_blockman. LoadBlockIndex (
4291
- m_params .GetConsensus (), *pblocktree ,
4288
+ if (!LoadBlockIndex (
4289
+ ::Params () .GetConsensus(),
4292
4290
setBlockIndexCandidates)) {
4293
4291
return false ;
4294
4292
}
4295
4293
4296
4294
// Load block file info
4297
- pblocktree ->ReadLastBlockFile (nLastBlockFile);
4295
+ m_block_tree_db ->ReadLastBlockFile (nLastBlockFile);
4298
4296
vinfoBlockFile.resize (nLastBlockFile + 1 );
4299
4297
LogPrintf (" %s: last block file = %i\n " , __func__, nLastBlockFile);
4300
4298
for (int nFile = 0 ; nFile <= nLastBlockFile; nFile++) {
4301
- pblocktree ->ReadBlockFileInfo (nFile, vinfoBlockFile[nFile]);
4299
+ m_block_tree_db ->ReadBlockFileInfo (nFile, vinfoBlockFile[nFile]);
4302
4300
}
4303
4301
LogPrintf (" %s: last block file info: %s\n " , __func__, vinfoBlockFile[nLastBlockFile].ToString ());
4304
4302
for (int nFile = nLastBlockFile + 1 ; true ; nFile++) {
4305
4303
CBlockFileInfo info;
4306
- if (pblocktree ->ReadBlockFileInfo (nFile, info)) {
4304
+ if (m_block_tree_db ->ReadBlockFileInfo (nFile, info)) {
4307
4305
vinfoBlockFile.push_back (info);
4308
4306
} else {
4309
4307
break ;
@@ -4313,7 +4311,7 @@ bool CChainState::LoadBlockIndexDB()
4313
4311
// Check presence of blk files
4314
4312
LogPrintf (" Checking all blk files are present...\n " );
4315
4313
std::set<int > setBlkDataFiles;
4316
- for (const std::pair<const uint256, CBlockIndex*>& item : m_blockman. m_block_index ) {
4314
+ for (const std::pair<const uint256, CBlockIndex*>& item : m_block_index) {
4317
4315
CBlockIndex* pindex = item.second ;
4318
4316
if (pindex->nStatus & BLOCK_HAVE_DATA) {
4319
4317
setBlkDataFiles.insert (pindex->nFile );
@@ -4328,25 +4326,25 @@ bool CChainState::LoadBlockIndexDB()
4328
4326
}
4329
4327
4330
4328
// Check whether we have ever pruned block & undo files
4331
- pblocktree ->ReadFlag (" prunedblockfiles" , fHavePruned );
4329
+ m_block_tree_db ->ReadFlag (" prunedblockfiles" , fHavePruned );
4332
4330
if (fHavePruned )
4333
4331
LogPrintf (" LoadBlockIndexDB(): Block files have previously been pruned\n " );
4334
4332
4335
4333
// Check whether we need to continue reindexing
4336
4334
bool fReindexing = false ;
4337
- pblocktree ->ReadReindexing (fReindexing );
4335
+ m_block_tree_db ->ReadReindexing (fReindexing );
4338
4336
if (fReindexing ) fReindex = true ;
4339
4337
4340
4338
// Check whether we have an address index
4341
- pblocktree ->ReadFlag (" addressindex" , fAddressIndex );
4339
+ m_block_tree_db ->ReadFlag (" addressindex" , fAddressIndex );
4342
4340
LogPrintf (" %s: address index %s\n " , __func__, fAddressIndex ? " enabled" : " disabled" );
4343
4341
4344
4342
// Check whether we have a timestamp index
4345
- pblocktree ->ReadFlag (" timestampindex" , fTimestampIndex );
4343
+ m_block_tree_db ->ReadFlag (" timestampindex" , fTimestampIndex );
4346
4344
LogPrintf (" %s: timestamp index %s\n " , __func__, fTimestampIndex ? " enabled" : " disabled" );
4347
4345
4348
4346
// Check whether we have a spent index
4349
- pblocktree ->ReadFlag (" spentindex" , fSpentIndex );
4347
+ m_block_tree_db ->ReadFlag (" spentindex" , fSpentIndex );
4350
4348
LogPrintf (" %s: spent index %s\n " , __func__, fSpentIndex ? " enabled" : " disabled" );
4351
4349
4352
4350
return true ;
@@ -4596,22 +4594,22 @@ bool CChainState::RollforwardBlock(const CBlockIndex* pindex, CCoinsViewCache& i
4596
4594
}
4597
4595
4598
4596
if (fAddressIndex ) {
4599
- if (!pblocktree ->WriteAddressIndex (addressIndex)) {
4597
+ if (!m_blockman. m_block_tree_db ->WriteAddressIndex (addressIndex)) {
4600
4598
return error (" RollforwardBlock(DASH): Failed to write address index" );
4601
4599
}
4602
4600
4603
- if (!pblocktree ->UpdateAddressUnspentIndex (addressUnspentIndex)) {
4601
+ if (!m_blockman. m_block_tree_db ->UpdateAddressUnspentIndex (addressUnspentIndex)) {
4604
4602
return error (" RollforwardBlock(DASH): Failed to write address unspent index" );
4605
4603
}
4606
4604
}
4607
4605
4608
4606
if (fSpentIndex ) {
4609
- if (!pblocktree ->UpdateSpentIndex (spentIndex))
4607
+ if (!m_blockman. m_block_tree_db ->UpdateSpentIndex (spentIndex))
4610
4608
return error (" RollforwardBlock(DASH): Failed to write transaction index" );
4611
4609
}
4612
4610
4613
4611
if (fTimestampIndex ) {
4614
- if (!pblocktree ->WriteTimestampIndex (CTimestampIndexKey (pindex->nTime , pindex->GetBlockHash ())))
4612
+ if (!m_blockman. m_block_tree_db ->WriteTimestampIndex (CTimestampIndexKey (pindex->nTime , pindex->GetBlockHash ())))
4615
4613
return error (" RollforwardBlock(DASH): Failed to write timestamp index" );
4616
4614
}
4617
4615
@@ -4726,7 +4724,7 @@ bool ChainstateManager::LoadBlockIndex()
4726
4724
// Load block index from databases
4727
4725
bool needs_init = fReindex ;
4728
4726
if (!fReindex ) {
4729
- bool ret = ActiveChainstate ().LoadBlockIndexDB ( );
4727
+ bool ret = m_blockman. LoadBlockIndexDB ( ActiveChainstate ().setBlockIndexCandidates );
4730
4728
if (!ret) return false ;
4731
4729
needs_init = m_blockman.m_block_index .empty ();
4732
4730
}
@@ -4742,15 +4740,15 @@ bool ChainstateManager::LoadBlockIndex()
4742
4740
4743
4741
// Use the provided setting for -addressindex in the new database
4744
4742
fAddressIndex = gArgs .GetBoolArg (" -addressindex" , DEFAULT_ADDRESSINDEX);
4745
- pblocktree ->WriteFlag (" addressindex" , fAddressIndex );
4743
+ m_blockman. m_block_tree_db ->WriteFlag (" addressindex" , fAddressIndex );
4746
4744
4747
4745
// Use the provided setting for -timestampindex in the new database
4748
4746
fTimestampIndex = gArgs .GetBoolArg (" -timestampindex" , DEFAULT_TIMESTAMPINDEX);
4749
- pblocktree ->WriteFlag (" timestampindex" , fTimestampIndex );
4747
+ m_blockman. m_block_tree_db ->WriteFlag (" timestampindex" , fTimestampIndex );
4750
4748
4751
4749
// Use the provided setting for -spentindex in the new database
4752
4750
fSpentIndex = gArgs .GetBoolArg (" -spentindex" , DEFAULT_SPENTINDEX);
4753
- pblocktree ->WriteFlag (" spentindex" , fSpentIndex );
4751
+ m_blockman. m_block_tree_db ->WriteFlag (" spentindex" , fSpentIndex );
4754
4752
}
4755
4753
return true ;
4756
4754
}
0 commit comments