@@ -4101,17 +4101,21 @@ CVerifyDB::~CVerifyDB()
4101
4101
uiInterface.ShowProgress (" " , 100 , false );
4102
4102
}
4103
4103
4104
- bool CVerifyDB::VerifyDB (const CChainParams& chainparams, CChainState& active_chainstate, CCoinsView *coinsview, int nCheckLevel, int nCheckDepth)
4104
+ bool CVerifyDB::VerifyDB (
4105
+ CChainState& chainstate,
4106
+ const CChainParams& chainparams,
4107
+ CCoinsView* coinsview,
4108
+ int nCheckLevel, int nCheckDepth)
4105
4109
{
4106
4110
AssertLockHeld (cs_main);
4107
4111
4108
- assert (std::addressof (::ChainstateActive ()) == std::addressof (active_chainstate ));
4109
- if (active_chainstate .m_chain .Tip () == nullptr || active_chainstate .m_chain .Tip ()->pprev == nullptr )
4112
+ assert (std::addressof (::ChainstateActive ()) == std::addressof (chainstate ));
4113
+ if (chainstate .m_chain .Tip () == nullptr || chainstate .m_chain .Tip ()->pprev == nullptr )
4110
4114
return true ;
4111
4115
4112
4116
// Verify blocks in the best chain
4113
- if (nCheckDepth <= 0 || nCheckDepth > active_chainstate .m_chain .Height ())
4114
- nCheckDepth = active_chainstate .m_chain .Height ();
4117
+ if (nCheckDepth <= 0 || nCheckDepth > chainstate .m_chain .Height ())
4118
+ nCheckDepth = chainstate .m_chain .Height ();
4115
4119
nCheckLevel = std::max (0 , std::min (4 , nCheckLevel));
4116
4120
LogPrintf (" Verifying last %i blocks at level %i\n " , nCheckDepth, nCheckLevel);
4117
4121
CCoinsViewCache coins (coinsview);
@@ -4121,15 +4125,15 @@ bool CVerifyDB::VerifyDB(const CChainParams& chainparams, CChainState& active_ch
4121
4125
BlockValidationState state;
4122
4126
int reportDone = 0 ;
4123
4127
LogPrintf (" [0%%]..." ); /* Continued */
4124
- for (pindex = active_chainstate .m_chain .Tip (); pindex && pindex->pprev ; pindex = pindex->pprev ) {
4125
- const int percentageDone = std::max (1 , std::min (99 , (int )(((double )(active_chainstate .m_chain .Height () - pindex->nHeight )) / (double )nCheckDepth * (nCheckLevel >= 4 ? 50 : 100 ))));
4128
+ for (pindex = chainstate .m_chain .Tip (); pindex && pindex->pprev ; pindex = pindex->pprev ) {
4129
+ const int percentageDone = std::max (1 , std::min (99 , (int )(((double )(chainstate .m_chain .Height () - pindex->nHeight )) / (double )nCheckDepth * (nCheckLevel >= 4 ? 50 : 100 ))));
4126
4130
if (reportDone < percentageDone/10 ) {
4127
4131
// report every 10% step
4128
4132
LogPrintf (" [%d%%]..." , percentageDone); /* Continued */
4129
4133
reportDone = percentageDone/10 ;
4130
4134
}
4131
4135
uiInterface.ShowProgress (_ (" Verifying blocks..." ).translated , percentageDone, false );
4132
- if (pindex->nHeight <= active_chainstate .m_chain .Height ()-nCheckDepth)
4136
+ if (pindex->nHeight <= chainstate .m_chain .Height ()-nCheckDepth)
4133
4137
break ;
4134
4138
if (fPruneMode && !(pindex->nStatus & BLOCK_HAVE_DATA)) {
4135
4139
// If pruning, only go back as far as we have data.
@@ -4154,9 +4158,11 @@ bool CVerifyDB::VerifyDB(const CChainParams& chainparams, CChainState& active_ch
4154
4158
}
4155
4159
}
4156
4160
// check level 3: check for inconsistencies during memory-only disconnect of tip blocks
4157
- if (nCheckLevel >= 3 && (coins.DynamicMemoryUsage () + active_chainstate.CoinsTip ().DynamicMemoryUsage ()) <= active_chainstate.m_coinstip_cache_size_bytes ) {
4161
+ int64_t curr_coins_usage = coins.DynamicMemoryUsage () + chainstate.CoinsTip ().DynamicMemoryUsage ();
4162
+
4163
+ if (nCheckLevel >= 3 && static_cast <unsigned long >(curr_coins_usage) <= chainstate.m_coinstip_cache_size_bytes ) {
4158
4164
assert (coins.GetBestBlock () == pindex->GetBlockHash ());
4159
- DisconnectResult res = active_chainstate .DisconnectBlock (block, pindex, coins);
4165
+ DisconnectResult res = chainstate .DisconnectBlock (block, pindex, coins);
4160
4166
if (res == DISCONNECT_FAILED) {
4161
4167
return error (" VerifyDB(): *** irrecoverable inconsistency in block data at %d, hash=%s" , pindex->nHeight , pindex->GetBlockHash ().ToString ());
4162
4168
}
@@ -4170,26 +4176,26 @@ bool CVerifyDB::VerifyDB(const CChainParams& chainparams, CChainState& active_ch
4170
4176
if (ShutdownRequested ()) return true ;
4171
4177
}
4172
4178
if (pindexFailure)
4173
- return error (" VerifyDB(): *** coin database inconsistencies found (last %i blocks, %i good transactions before that)\n " , active_chainstate .m_chain .Height () - pindexFailure->nHeight + 1 , nGoodTransactions);
4179
+ return error (" VerifyDB(): *** coin database inconsistencies found (last %i blocks, %i good transactions before that)\n " , chainstate .m_chain .Height () - pindexFailure->nHeight + 1 , nGoodTransactions);
4174
4180
4175
4181
// store block count as we move pindex at check level >= 4
4176
- int block_count = active_chainstate .m_chain .Height () - pindex->nHeight ;
4182
+ int block_count = chainstate .m_chain .Height () - pindex->nHeight ;
4177
4183
4178
4184
// check level 4: try reconnecting blocks
4179
4185
if (nCheckLevel >= 4 ) {
4180
- while (pindex != active_chainstate .m_chain .Tip ()) {
4181
- const int percentageDone = std::max (1 , std::min (99 , 100 - (int )(((double )(active_chainstate .m_chain .Height () - pindex->nHeight )) / (double )nCheckDepth * 50 )));
4186
+ while (pindex != chainstate .m_chain .Tip ()) {
4187
+ const int percentageDone = std::max (1 , std::min (99 , 100 - (int )(((double )(chainstate .m_chain .Height () - pindex->nHeight )) / (double )nCheckDepth * 50 )));
4182
4188
if (reportDone < percentageDone/10 ) {
4183
4189
// report every 10% step
4184
4190
LogPrintf (" [%d%%]..." , percentageDone); /* Continued */
4185
4191
reportDone = percentageDone/10 ;
4186
4192
}
4187
4193
uiInterface.ShowProgress (_ (" Verifying blocks..." ).translated , percentageDone, false );
4188
- pindex = active_chainstate .m_chain .Next (pindex);
4194
+ pindex = chainstate .m_chain .Next (pindex);
4189
4195
CBlock block;
4190
4196
if (!ReadBlockFromDisk (block, pindex, chainparams.GetConsensus ()))
4191
4197
return error (" VerifyDB(): *** ReadBlockFromDisk failed at %d, hash=%s" , pindex->nHeight , pindex->GetBlockHash ().ToString ());
4192
- if (!active_chainstate .ConnectBlock (block, state, pindex, coins, chainparams))
4198
+ if (!chainstate .ConnectBlock (block, state, pindex, coins, chainparams))
4193
4199
return error (" VerifyDB(): *** found unconnectable block at %d, hash=%s (%s)" , pindex->nHeight , pindex->GetBlockHash ().ToString (), state.ToString ());
4194
4200
if (ShutdownRequested ()) return true ;
4195
4201
}
0 commit comments