@@ -133,16 +133,6 @@ arith_uint256 nMinimumChainWork;
133133
134134CFeeRate minRelayTxFee = CFeeRate(DEFAULT_MIN_RELAY_TX_FEE);
135135
136- // Internal stuff from blockstorage ...
137- extern RecursiveMutex cs_LastBlockFile;
138- extern std::vector<CBlockFileInfo> vinfoBlockFile;
139- extern int nLastBlockFile;
140- extern bool fCheckForPruning ;
141- extern std::set<CBlockIndex*> setDirtyBlockIndex;
142- extern std::set<int > setDirtyFileInfo;
143- void FlushBlockFile (bool fFinalize = false , bool finalize_undo = false );
144- // ... TODO move fully to blockstorage
145-
146136CBlockIndex* CChainState::FindForkInGlobalIndex (const CBlockLocator& locator) const
147137{
148138 AssertLockHeld (cs_main);
@@ -1505,7 +1495,7 @@ void CChainState::InvalidBlockFound(CBlockIndex* pindex, const BlockValidationSt
15051495 if (state.GetResult () != BlockValidationResult::BLOCK_MUTATED) {
15061496 pindex->nStatus |= BLOCK_FAILED_VALID;
15071497 m_chainman.m_failed_blocks .insert (pindex);
1508- setDirtyBlockIndex.insert (pindex);
1498+ m_blockman. setDirtyBlockIndex .insert (pindex);
15091499 setBlockIndexCandidates.erase (pindex);
15101500 InvalidChainFound (pindex);
15111501 }
@@ -2141,7 +2131,7 @@ bool CChainState::ConnectBlock(const CBlock& block, BlockValidationState& state,
21412131
21422132 if (!pindex->IsValid (BLOCK_VALID_SCRIPTS)) {
21432133 pindex->RaiseValidity (BLOCK_VALID_SCRIPTS);
2144- setDirtyBlockIndex.insert (pindex);
2134+ m_blockman. setDirtyBlockIndex .insert (pindex);
21452135 }
21462136
21472137 assert (pindex->phashBlock );
@@ -2214,8 +2204,8 @@ bool CChainState::FlushStateToDisk(
22142204 bool fDoFullFlush = false ;
22152205
22162206 CoinsCacheSizeState cache_state = GetCoinsCacheSizeState ();
2217- LOCK (cs_LastBlockFile);
2218- if (fPruneMode && (fCheckForPruning || nManualPruneHeight > 0 ) && !fReindex ) {
2207+ LOCK (m_blockman. cs_LastBlockFile );
2208+ if (fPruneMode && (m_blockman. fCheckForPruning || nManualPruneHeight > 0 ) && !fReindex ) {
22192209 // make sure we don't prune above the blockfilterindexes bestblocks
22202210 // pruning is height-based
22212211 int last_prune = m_chain.Height (); // last height we can prune
@@ -2231,7 +2221,7 @@ bool CChainState::FlushStateToDisk(
22312221 LOG_TIME_MILLIS_WITH_CATEGORY (" find files to prune" , BCLog::BENCH);
22322222
22332223 m_blockman.FindFilesToPrune (setFilesToPrune, m_params.PruneAfterHeight (), m_chain.Height (), last_prune, IsInitialBlockDownload ());
2234- fCheckForPruning = false ;
2224+ m_blockman. fCheckForPruning = false ;
22352225 }
22362226 if (!setFilesToPrune.empty ()) {
22372227 fFlushForPrune = true ;
@@ -2336,7 +2326,7 @@ void CChainState::ForceFlushStateToDisk()
23362326void CChainState::PruneAndFlush ()
23372327{
23382328 BlockValidationState state;
2339- fCheckForPruning = true ;
2329+ m_blockman. fCheckForPruning = true ;
23402330 if (!this ->FlushStateToDisk (state, FlushStateMode::NONE)) {
23412331 LogPrintf (" %s: failed to flush state (%s)\n " , __func__, state.ToString ());
23422332 }
@@ -3006,14 +2996,14 @@ bool CChainState::InvalidateBlock(BlockValidationState& state, CBlockIndex* pind
30062996 // are no blocks that meet the "have data and are not invalid per
30072997 // nStatus" criteria for inclusion in setBlockIndexCandidates).
30082998 invalid_walk_tip->nStatus |= BLOCK_FAILED_VALID;
3009- setDirtyBlockIndex.insert (invalid_walk_tip);
2999+ m_blockman. setDirtyBlockIndex .insert (invalid_walk_tip);
30103000 setBlockIndexCandidates.erase (invalid_walk_tip);
30113001 setBlockIndexCandidates.insert (invalid_walk_tip->pprev );
30123002 if (invalid_walk_tip->pprev == to_mark_failed && (to_mark_failed->nStatus & BLOCK_FAILED_VALID)) {
30133003 // We only want to mark the last disconnected block as BLOCK_FAILED_VALID; its children
30143004 // need to be BLOCK_FAILED_CHILD instead.
30153005 to_mark_failed->nStatus = (to_mark_failed->nStatus ^ BLOCK_FAILED_VALID) | BLOCK_FAILED_CHILD;
3016- setDirtyBlockIndex.insert (to_mark_failed);
3006+ m_blockman. setDirtyBlockIndex .insert (to_mark_failed);
30173007 }
30183008
30193009 // Add any equal or more work headers to setBlockIndexCandidates
@@ -3043,7 +3033,7 @@ bool CChainState::InvalidateBlock(BlockValidationState& state, CBlockIndex* pind
30433033
30443034 // Mark pindex (or the last disconnected block) as invalid, even when it never was in the main chain
30453035 to_mark_failed->nStatus |= BLOCK_FAILED_VALID;
3046- setDirtyBlockIndex.insert (to_mark_failed);
3036+ m_blockman. setDirtyBlockIndex .insert (to_mark_failed);
30473037 setBlockIndexCandidates.erase (to_mark_failed);
30483038 m_chainman.m_failed_blocks .insert (to_mark_failed);
30493039
@@ -3082,7 +3072,7 @@ void CChainState::ResetBlockFailureFlags(CBlockIndex *pindex) {
30823072 while (it != m_blockman.m_block_index .end ()) {
30833073 if (!it->second ->IsValid () && it->second ->GetAncestor (nHeight) == pindex) {
30843074 it->second ->nStatus &= ~BLOCK_FAILED_MASK;
3085- setDirtyBlockIndex.insert (it->second );
3075+ m_blockman. setDirtyBlockIndex .insert (it->second );
30863076 if (it->second ->IsValid (BLOCK_VALID_TRANSACTIONS) && it->second ->HaveTxsDownloaded () && setBlockIndexCandidates.value_comp ()(m_chain.Tip (), it->second )) {
30873077 setBlockIndexCandidates.insert (it->second );
30883078 }
@@ -3099,7 +3089,7 @@ void CChainState::ResetBlockFailureFlags(CBlockIndex *pindex) {
30993089 while (pindex != nullptr ) {
31003090 if (pindex->nStatus & BLOCK_FAILED_MASK) {
31013091 pindex->nStatus &= ~BLOCK_FAILED_MASK;
3102- setDirtyBlockIndex.insert (pindex);
3092+ m_blockman. setDirtyBlockIndex .insert (pindex);
31033093 m_chainman.m_failed_blocks .erase (pindex);
31043094 }
31053095 pindex = pindex->pprev ;
@@ -3119,7 +3109,7 @@ void CChainState::ReceivedBlockTransactions(const CBlock& block, CBlockIndex* pi
31193109 pindexNew->nStatus |= BLOCK_OPT_WITNESS;
31203110 }
31213111 pindexNew->RaiseValidity (BLOCK_VALID_TRANSACTIONS);
3122- setDirtyBlockIndex.insert (pindexNew);
3112+ m_blockman. setDirtyBlockIndex .insert (pindexNew);
31233113
31243114 if (pindexNew->pprev == nullptr || pindexNew->pprev ->HaveTxsDownloaded ()) {
31253115 // If pindexNew is the genesis block or all parents are BLOCK_VALID_TRANSACTIONS.
@@ -3481,7 +3471,7 @@ bool ChainstateManager::AcceptBlockHeader(const CBlockHeader& block, BlockValida
34813471 CBlockIndex* invalid_walk = pindexPrev;
34823472 while (invalid_walk != failedit) {
34833473 invalid_walk->nStatus |= BLOCK_FAILED_CHILD;
3484- setDirtyBlockIndex.insert (invalid_walk);
3474+ m_blockman. setDirtyBlockIndex .insert (invalid_walk);
34853475 invalid_walk = invalid_walk->pprev ;
34863476 }
34873477 LogPrint (BCLog::VALIDATION, " %s: %s prev block invalid\n " , __func__, hash.ToString ());
@@ -3579,7 +3569,7 @@ bool CChainState::AcceptBlock(const std::shared_ptr<const CBlock>& pblock, Block
35793569 !ContextualCheckBlock (block, state, m_params.GetConsensus (), pindex->pprev )) {
35803570 if (state.IsInvalid () && state.GetResult () != BlockValidationResult::BLOCK_MUTATED) {
35813571 pindex->nStatus |= BLOCK_FAILED_VALID;
3582- setDirtyBlockIndex.insert (pindex);
3572+ m_blockman. setDirtyBlockIndex .insert (pindex);
35833573 }
35843574 return error (" %s: %s" , __func__, state.ToString ());
35853575 }
@@ -4914,7 +4904,7 @@ bool ChainstateManager::PopulateAndValidateSnapshot(
49144904 index->nStatus |= BLOCK_OPT_WITNESS;
49154905 }
49164906
4917- setDirtyBlockIndex.insert (index);
4907+ m_blockman. setDirtyBlockIndex .insert (index);
49184908 // Changes to the block index will be flushed to disk after this call
49194909 // returns in `ActivateSnapshot()`, when `MaybeRebalanceCaches()` is
49204910 // called, since we've added a snapshot chainstate and therefore will
0 commit comments