@@ -133,16 +133,6 @@ arith_uint256 nMinimumChainWork;
133
133
134
134
CFeeRate minRelayTxFee = CFeeRate(DEFAULT_MIN_RELAY_TX_FEE);
135
135
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
-
146
136
CBlockIndex* CChainState::FindForkInGlobalIndex (const CBlockLocator& locator) const
147
137
{
148
138
AssertLockHeld (cs_main);
@@ -1505,7 +1495,7 @@ void CChainState::InvalidBlockFound(CBlockIndex* pindex, const BlockValidationSt
1505
1495
if (state.GetResult () != BlockValidationResult::BLOCK_MUTATED) {
1506
1496
pindex->nStatus |= BLOCK_FAILED_VALID;
1507
1497
m_chainman.m_failed_blocks .insert (pindex);
1508
- setDirtyBlockIndex.insert (pindex);
1498
+ m_blockman. setDirtyBlockIndex .insert (pindex);
1509
1499
setBlockIndexCandidates.erase (pindex);
1510
1500
InvalidChainFound (pindex);
1511
1501
}
@@ -2141,7 +2131,7 @@ bool CChainState::ConnectBlock(const CBlock& block, BlockValidationState& state,
2141
2131
2142
2132
if (!pindex->IsValid (BLOCK_VALID_SCRIPTS)) {
2143
2133
pindex->RaiseValidity (BLOCK_VALID_SCRIPTS);
2144
- setDirtyBlockIndex.insert (pindex);
2134
+ m_blockman. setDirtyBlockIndex .insert (pindex);
2145
2135
}
2146
2136
2147
2137
assert (pindex->phashBlock );
@@ -2214,8 +2204,8 @@ bool CChainState::FlushStateToDisk(
2214
2204
bool fDoFullFlush = false ;
2215
2205
2216
2206
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 ) {
2219
2209
// make sure we don't prune above the blockfilterindexes bestblocks
2220
2210
// pruning is height-based
2221
2211
int last_prune = m_chain.Height (); // last height we can prune
@@ -2231,7 +2221,7 @@ bool CChainState::FlushStateToDisk(
2231
2221
LOG_TIME_MILLIS_WITH_CATEGORY (" find files to prune" , BCLog::BENCH);
2232
2222
2233
2223
m_blockman.FindFilesToPrune (setFilesToPrune, m_params.PruneAfterHeight (), m_chain.Height (), last_prune, IsInitialBlockDownload ());
2234
- fCheckForPruning = false ;
2224
+ m_blockman. fCheckForPruning = false ;
2235
2225
}
2236
2226
if (!setFilesToPrune.empty ()) {
2237
2227
fFlushForPrune = true ;
@@ -2336,7 +2326,7 @@ void CChainState::ForceFlushStateToDisk()
2336
2326
void CChainState::PruneAndFlush ()
2337
2327
{
2338
2328
BlockValidationState state;
2339
- fCheckForPruning = true ;
2329
+ m_blockman. fCheckForPruning = true ;
2340
2330
if (!this ->FlushStateToDisk (state, FlushStateMode::NONE)) {
2341
2331
LogPrintf (" %s: failed to flush state (%s)\n " , __func__, state.ToString ());
2342
2332
}
@@ -3006,14 +2996,14 @@ bool CChainState::InvalidateBlock(BlockValidationState& state, CBlockIndex* pind
3006
2996
// are no blocks that meet the "have data and are not invalid per
3007
2997
// nStatus" criteria for inclusion in setBlockIndexCandidates).
3008
2998
invalid_walk_tip->nStatus |= BLOCK_FAILED_VALID;
3009
- setDirtyBlockIndex.insert (invalid_walk_tip);
2999
+ m_blockman. setDirtyBlockIndex .insert (invalid_walk_tip);
3010
3000
setBlockIndexCandidates.erase (invalid_walk_tip);
3011
3001
setBlockIndexCandidates.insert (invalid_walk_tip->pprev );
3012
3002
if (invalid_walk_tip->pprev == to_mark_failed && (to_mark_failed->nStatus & BLOCK_FAILED_VALID)) {
3013
3003
// We only want to mark the last disconnected block as BLOCK_FAILED_VALID; its children
3014
3004
// need to be BLOCK_FAILED_CHILD instead.
3015
3005
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);
3017
3007
}
3018
3008
3019
3009
// Add any equal or more work headers to setBlockIndexCandidates
@@ -3043,7 +3033,7 @@ bool CChainState::InvalidateBlock(BlockValidationState& state, CBlockIndex* pind
3043
3033
3044
3034
// Mark pindex (or the last disconnected block) as invalid, even when it never was in the main chain
3045
3035
to_mark_failed->nStatus |= BLOCK_FAILED_VALID;
3046
- setDirtyBlockIndex.insert (to_mark_failed);
3036
+ m_blockman. setDirtyBlockIndex .insert (to_mark_failed);
3047
3037
setBlockIndexCandidates.erase (to_mark_failed);
3048
3038
m_chainman.m_failed_blocks .insert (to_mark_failed);
3049
3039
@@ -3082,7 +3072,7 @@ void CChainState::ResetBlockFailureFlags(CBlockIndex *pindex) {
3082
3072
while (it != m_blockman.m_block_index .end ()) {
3083
3073
if (!it->second ->IsValid () && it->second ->GetAncestor (nHeight) == pindex) {
3084
3074
it->second ->nStatus &= ~BLOCK_FAILED_MASK;
3085
- setDirtyBlockIndex.insert (it->second );
3075
+ m_blockman. setDirtyBlockIndex .insert (it->second );
3086
3076
if (it->second ->IsValid (BLOCK_VALID_TRANSACTIONS) && it->second ->HaveTxsDownloaded () && setBlockIndexCandidates.value_comp ()(m_chain.Tip (), it->second )) {
3087
3077
setBlockIndexCandidates.insert (it->second );
3088
3078
}
@@ -3099,7 +3089,7 @@ void CChainState::ResetBlockFailureFlags(CBlockIndex *pindex) {
3099
3089
while (pindex != nullptr ) {
3100
3090
if (pindex->nStatus & BLOCK_FAILED_MASK) {
3101
3091
pindex->nStatus &= ~BLOCK_FAILED_MASK;
3102
- setDirtyBlockIndex.insert (pindex);
3092
+ m_blockman. setDirtyBlockIndex .insert (pindex);
3103
3093
m_chainman.m_failed_blocks .erase (pindex);
3104
3094
}
3105
3095
pindex = pindex->pprev ;
@@ -3119,7 +3109,7 @@ void CChainState::ReceivedBlockTransactions(const CBlock& block, CBlockIndex* pi
3119
3109
pindexNew->nStatus |= BLOCK_OPT_WITNESS;
3120
3110
}
3121
3111
pindexNew->RaiseValidity (BLOCK_VALID_TRANSACTIONS);
3122
- setDirtyBlockIndex.insert (pindexNew);
3112
+ m_blockman. setDirtyBlockIndex .insert (pindexNew);
3123
3113
3124
3114
if (pindexNew->pprev == nullptr || pindexNew->pprev ->HaveTxsDownloaded ()) {
3125
3115
// If pindexNew is the genesis block or all parents are BLOCK_VALID_TRANSACTIONS.
@@ -3481,7 +3471,7 @@ bool ChainstateManager::AcceptBlockHeader(const CBlockHeader& block, BlockValida
3481
3471
CBlockIndex* invalid_walk = pindexPrev;
3482
3472
while (invalid_walk != failedit) {
3483
3473
invalid_walk->nStatus |= BLOCK_FAILED_CHILD;
3484
- setDirtyBlockIndex.insert (invalid_walk);
3474
+ m_blockman. setDirtyBlockIndex .insert (invalid_walk);
3485
3475
invalid_walk = invalid_walk->pprev ;
3486
3476
}
3487
3477
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
3579
3569
!ContextualCheckBlock (block, state, m_params.GetConsensus (), pindex->pprev )) {
3580
3570
if (state.IsInvalid () && state.GetResult () != BlockValidationResult::BLOCK_MUTATED) {
3581
3571
pindex->nStatus |= BLOCK_FAILED_VALID;
3582
- setDirtyBlockIndex.insert (pindex);
3572
+ m_blockman. setDirtyBlockIndex .insert (pindex);
3583
3573
}
3584
3574
return error (" %s: %s" , __func__, state.ToString ());
3585
3575
}
@@ -4914,7 +4904,7 @@ bool ChainstateManager::PopulateAndValidateSnapshot(
4914
4904
index->nStatus |= BLOCK_OPT_WITNESS;
4915
4905
}
4916
4906
4917
- setDirtyBlockIndex.insert (index);
4907
+ m_blockman. setDirtyBlockIndex .insert (index);
4918
4908
// Changes to the block index will be flushed to disk after this call
4919
4909
// returns in `ActivateSnapshot()`, when `MaybeRebalanceCaches()` is
4920
4910
// called, since we've added a snapshot chainstate and therefore will
0 commit comments