@@ -3984,14 +3984,13 @@ bool CVerifyDB::VerifyDB(const CChainParams& chainparams, CCoinsView *coinsview,
3984
3984
nCheckLevel = std::max (0 , std::min (4 , nCheckLevel));
3985
3985
LogPrintf (" Verifying last %i blocks at level %i\n " , nCheckDepth, nCheckLevel);
3986
3986
CCoinsViewCache coins (coinsview);
3987
- CBlockIndex* pindexState = chainActive. Tip () ;
3987
+ CBlockIndex* pindex ;
3988
3988
CBlockIndex* pindexFailure = nullptr ;
3989
3989
int nGoodTransactions = 0 ;
3990
3990
CValidationState state;
3991
3991
int reportDone = 0 ;
3992
3992
LogPrintf (" [0%%]..." ); /* Continued */
3993
- for (CBlockIndex* pindex = chainActive.Tip (); pindex && pindex->pprev ; pindex = pindex->pprev )
3994
- {
3993
+ for (pindex = chainActive.Tip (); pindex && pindex->pprev ; pindex = pindex->pprev ) {
3995
3994
boost::this_thread::interruption_point ();
3996
3995
int percentageDone = std::max (1 , std::min (99 , (int )(((double )(chainActive.Height () - pindex->nHeight )) / (double )nCheckDepth * (nCheckLevel >= 4 ? 50 : 100 ))));
3997
3996
if (reportDone < percentageDone/10 ) {
@@ -4025,13 +4024,12 @@ bool CVerifyDB::VerifyDB(const CChainParams& chainparams, CCoinsView *coinsview,
4025
4024
}
4026
4025
}
4027
4026
// check level 3: check for inconsistencies during memory-only disconnect of tip blocks
4028
- if (nCheckLevel >= 3 && pindex == pindexState && (coins.DynamicMemoryUsage () + pcoinsTip->DynamicMemoryUsage ()) <= nCoinCacheUsage) {
4027
+ if (nCheckLevel >= 3 && (coins.DynamicMemoryUsage () + pcoinsTip->DynamicMemoryUsage ()) <= nCoinCacheUsage) {
4029
4028
assert (coins.GetBestBlock () == pindex->GetBlockHash ());
4030
4029
DisconnectResult res = g_chainstate.DisconnectBlock (block, pindex, coins);
4031
4030
if (res == DISCONNECT_FAILED) {
4032
4031
return error (" VerifyDB(): *** irrecoverable inconsistency in block data at %d, hash=%s" , pindex->nHeight , pindex->GetBlockHash ().ToString ());
4033
4032
}
4034
- pindexState = pindex->pprev ;
4035
4033
if (res == DISCONNECT_UNCLEAN) {
4036
4034
nGoodTransactions = 0 ;
4037
4035
pindexFailure = pindex;
@@ -4045,9 +4043,11 @@ bool CVerifyDB::VerifyDB(const CChainParams& chainparams, CCoinsView *coinsview,
4045
4043
if (pindexFailure)
4046
4044
return error (" VerifyDB(): *** coin database inconsistencies found (last %i blocks, %i good transactions before that)\n " , chainActive.Height () - pindexFailure->nHeight + 1 , nGoodTransactions);
4047
4045
4046
+ // store block count as we move pindex at check level >= 4
4047
+ int block_count = chainActive.Height () - pindex->nHeight ;
4048
+
4048
4049
// check level 4: try reconnecting blocks
4049
4050
if (nCheckLevel >= 4 ) {
4050
- CBlockIndex *pindex = pindexState;
4051
4051
while (pindex != chainActive.Tip ()) {
4052
4052
boost::this_thread::interruption_point ();
4053
4053
uiInterface.ShowProgress (_ (" Verifying blocks..." ), std::max (1 , std::min (99 , 100 - (int )(((double )(chainActive.Height () - pindex->nHeight )) / (double )nCheckDepth * 50 ))), false );
@@ -4061,7 +4061,7 @@ bool CVerifyDB::VerifyDB(const CChainParams& chainparams, CCoinsView *coinsview,
4061
4061
}
4062
4062
4063
4063
LogPrintf (" [DONE].\n " );
4064
- LogPrintf (" No coin database inconsistencies in last %i blocks (%i transactions)\n " , chainActive. Height () - pindexState-> nHeight , nGoodTransactions);
4064
+ LogPrintf (" No coin database inconsistencies in last %i blocks (%i transactions)\n " , block_count , nGoodTransactions);
4065
4065
4066
4066
return true ;
4067
4067
}
0 commit comments