@@ -133,11 +133,6 @@ arith_uint256 nMinimumChainWork;
133
133
134
134
CFeeRate minRelayTxFee = CFeeRate(DEFAULT_MIN_RELAY_TX_FEE);
135
135
136
- // Internal stuff
137
- namespace {
138
- CBlockIndex* pindexBestInvalid = nullptr ;
139
- } // namespace
140
-
141
136
// Internal stuff from blockstorage ...
142
137
extern RecursiveMutex cs_LastBlockFile;
143
138
extern std::vector<CBlockFileInfo> vinfoBlockFile;
@@ -1257,7 +1252,7 @@ void CChainState::CheckForkWarningConditions()
1257
1252
return ;
1258
1253
}
1259
1254
1260
- if (pindexBestInvalid && pindexBestInvalid ->nChainWork > m_chain.Tip ()->nChainWork + (GetBlockProof (*m_chain.Tip ()) * 6 )) {
1255
+ if (m_chainman. m_best_invalid && m_chainman. m_best_invalid ->nChainWork > m_chain.Tip ()->nChainWork + (GetBlockProof (*m_chain.Tip ()) * 6 )) {
1261
1256
LogPrintf (" %s: Warning: Found invalid chain at least ~6 blocks longer than our best chain.\n Chain state database corruption likely.\n " , __func__);
1262
1257
SetfLargeWorkInvalidChainFound (true );
1263
1258
} else {
@@ -1268,8 +1263,9 @@ void CChainState::CheckForkWarningConditions()
1268
1263
// Called both upon regular invalid block discovery *and* InvalidateBlock
1269
1264
void CChainState::InvalidChainFound (CBlockIndex* pindexNew)
1270
1265
{
1271
- if (!pindexBestInvalid || pindexNew->nChainWork > pindexBestInvalid->nChainWork )
1272
- pindexBestInvalid = pindexNew;
1266
+ if (!m_chainman.m_best_invalid || pindexNew->nChainWork > m_chainman.m_best_invalid ->nChainWork ) {
1267
+ m_chainman.m_best_invalid = pindexNew;
1268
+ }
1273
1269
if (pindexBestHeader != nullptr && pindexBestHeader->GetAncestor (pindexNew->nHeight ) == pindexNew) {
1274
1270
pindexBestHeader = m_chain.Tip ();
1275
1271
}
@@ -2432,8 +2428,9 @@ CBlockIndex* CChainState::FindMostWorkChain() {
2432
2428
bool fMissingData = !(pindexTest->nStatus & BLOCK_HAVE_DATA);
2433
2429
if (fFailedChain || fMissingData ) {
2434
2430
// Candidate chain is not usable (either invalid or missing data)
2435
- if (fFailedChain && (pindexBestInvalid == nullptr || pindexNew->nChainWork > pindexBestInvalid->nChainWork ))
2436
- pindexBestInvalid = pindexNew;
2431
+ if (fFailedChain && (m_chainman.m_best_invalid == nullptr || pindexNew->nChainWork > m_chainman.m_best_invalid ->nChainWork )) {
2432
+ m_chainman.m_best_invalid = pindexNew;
2433
+ }
2437
2434
CBlockIndex *pindexFailed = pindexNew;
2438
2435
// Remove the entire chain from the set.
2439
2436
while (pindexTest != pindexFailed) {
@@ -2885,9 +2882,9 @@ void CChainState::ResetBlockFailureFlags(CBlockIndex *pindex) {
2885
2882
if (it->second ->IsValid (BLOCK_VALID_TRANSACTIONS) && it->second ->HaveTxsDownloaded () && setBlockIndexCandidates.value_comp ()(m_chain.Tip (), it->second )) {
2886
2883
setBlockIndexCandidates.insert (it->second );
2887
2884
}
2888
- if (it->second == pindexBestInvalid ) {
2885
+ if (it->second == m_chainman. m_best_invalid ) {
2889
2886
// Reset invalid block marker if it was pointing to one of those.
2890
- pindexBestInvalid = nullptr ;
2887
+ m_chainman. m_best_invalid = nullptr ;
2891
2888
}
2892
2889
m_chainman.m_failed_blocks .erase (it->second );
2893
2890
}
@@ -3792,8 +3789,9 @@ bool BlockManager::LoadBlockIndex(
3792
3789
}
3793
3790
}
3794
3791
}
3795
- if (pindex->nStatus & BLOCK_FAILED_MASK && (!pindexBestInvalid || pindex->nChainWork > pindexBestInvalid->nChainWork ))
3796
- pindexBestInvalid = pindex;
3792
+ if (pindex->nStatus & BLOCK_FAILED_MASK && (!chainman.m_best_invalid || pindex->nChainWork > chainman.m_best_invalid ->nChainWork )) {
3793
+ chainman.m_best_invalid = pindex;
3794
+ }
3797
3795
if (pindex->pprev )
3798
3796
pindex->BuildSkip ();
3799
3797
if (pindex->IsValid (BLOCK_VALID_TREE) && (pindexBestHeader == nullptr || CBlockIndexWorkComparator ()(pindexBestHeader, pindex)))
@@ -4141,7 +4139,6 @@ void UnloadBlockIndex(CTxMemPool* mempool, ChainstateManager& chainman)
4141
4139
{
4142
4140
LOCK (cs_main);
4143
4141
chainman.Unload ();
4144
- pindexBestInvalid = nullptr ;
4145
4142
pindexBestHeader = nullptr ;
4146
4143
if (mempool) mempool->clear ();
4147
4144
vinfoBlockFile.clear ();
@@ -5120,6 +5117,7 @@ void ChainstateManager::Unload()
5120
5117
5121
5118
m_failed_blocks.clear ();
5122
5119
m_blockman.Unload ();
5120
+ m_best_invalid = nullptr ;
5123
5121
}
5124
5122
5125
5123
void ChainstateManager::Reset ()
0 commit comments