@@ -4101,38 +4101,46 @@ 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
- CCoinsViewCache coins (coinsview);
4121
+ CCoinsViewCache coins (& coinsview);
4118
4122
CBlockIndex* pindex;
4119
4123
CBlockIndex* pindexFailure = nullptr ;
4120
4124
int nGoodTransactions = 0 ;
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
+
4129
+ bool is_snapshot_cs = !chainstate.m_from_snapshot_blockhash .IsNull ();
4130
+
4131
+ for (pindex = chainstate.m_chain .Tip (); pindex && pindex->pprev ; pindex = pindex->pprev ) {
4132
+ const int percentageDone = std::max (1 , std::min (99 , (int )(((double )(chainstate.m_chain .Height () - pindex->nHeight )) / (double )nCheckDepth * (nCheckLevel >= 4 ? 50 : 100 ))));
4126
4133
if (reportDone < percentageDone/10 ) {
4127
4134
// report every 10% step
4128
4135
LogPrintf (" [%d%%]..." , percentageDone); /* Continued */
4129
4136
reportDone = percentageDone/10 ;
4130
4137
}
4131
4138
uiInterface.ShowProgress (_ (" Verifying blocks..." ).translated , percentageDone, false );
4132
- if (pindex->nHeight <= active_chainstate .m_chain .Height ()-nCheckDepth)
4139
+ if (pindex->nHeight <= chainstate .m_chain .Height ()-nCheckDepth)
4133
4140
break ;
4134
- if (fPruneMode && !(pindex->nStatus & BLOCK_HAVE_DATA)) {
4135
- // If pruning, only go back as far as we have data.
4141
+ if ((fPruneMode || is_snapshot_cs) && !(pindex->nStatus & BLOCK_HAVE_DATA)) {
4142
+ // If pruning or running under an assumeutxo snapshot, only go
4143
+ // back as far as we have data.
4136
4144
LogPrintf (" VerifyDB(): block verification stopping at height %d (pruning, no data)\n " , pindex->nHeight );
4137
4145
break ;
4138
4146
}
@@ -4154,9 +4162,11 @@ bool CVerifyDB::VerifyDB(const CChainParams& chainparams, CChainState& active_ch
4154
4162
}
4155
4163
}
4156
4164
// 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 ) {
4165
+ size_t curr_coins_usage = coins.DynamicMemoryUsage () + chainstate.CoinsTip ().DynamicMemoryUsage ();
4166
+
4167
+ if (nCheckLevel >= 3 && curr_coins_usage <= chainstate.m_coinstip_cache_size_bytes ) {
4158
4168
assert (coins.GetBestBlock () == pindex->GetBlockHash ());
4159
- DisconnectResult res = active_chainstate .DisconnectBlock (block, pindex, coins);
4169
+ DisconnectResult res = chainstate .DisconnectBlock (block, pindex, coins);
4160
4170
if (res == DISCONNECT_FAILED) {
4161
4171
return error (" VerifyDB(): *** irrecoverable inconsistency in block data at %d, hash=%s" , pindex->nHeight , pindex->GetBlockHash ().ToString ());
4162
4172
}
@@ -4170,26 +4180,26 @@ bool CVerifyDB::VerifyDB(const CChainParams& chainparams, CChainState& active_ch
4170
4180
if (ShutdownRequested ()) return true ;
4171
4181
}
4172
4182
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);
4183
+ 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
4184
4175
4185
// store block count as we move pindex at check level >= 4
4176
- int block_count = active_chainstate .m_chain .Height () - pindex->nHeight ;
4186
+ int block_count = chainstate .m_chain .Height () - pindex->nHeight ;
4177
4187
4178
4188
// check level 4: try reconnecting blocks
4179
4189
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 )));
4190
+ while (pindex != chainstate .m_chain .Tip ()) {
4191
+ const int percentageDone = std::max (1 , std::min (99 , 100 - (int )(((double )(chainstate .m_chain .Height () - pindex->nHeight )) / (double )nCheckDepth * 50 )));
4182
4192
if (reportDone < percentageDone/10 ) {
4183
4193
// report every 10% step
4184
4194
LogPrintf (" [%d%%]..." , percentageDone); /* Continued */
4185
4195
reportDone = percentageDone/10 ;
4186
4196
}
4187
4197
uiInterface.ShowProgress (_ (" Verifying blocks..." ).translated , percentageDone, false );
4188
- pindex = active_chainstate .m_chain .Next (pindex);
4198
+ pindex = chainstate .m_chain .Next (pindex);
4189
4199
CBlock block;
4190
4200
if (!ReadBlockFromDisk (block, pindex, chainparams.GetConsensus ()))
4191
4201
return error (" VerifyDB(): *** ReadBlockFromDisk failed at %d, hash=%s" , pindex->nHeight , pindex->GetBlockHash ().ToString ());
4192
- if (!active_chainstate .ConnectBlock (block, state, pindex, coins, chainparams))
4202
+ if (!chainstate .ConnectBlock (block, state, pindex, coins, chainparams))
4193
4203
return error (" VerifyDB(): *** found unconnectable block at %d, hash=%s (%s)" , pindex->nHeight , pindex->GetBlockHash ().ToString (), state.ToString ());
4194
4204
if (ShutdownRequested ()) return true ;
4195
4205
}
0 commit comments