@@ -50,9 +50,7 @@ std::optional<ChainstateLoadingError> LoadChainstate(bool fReset,
50
50
bool fReindexChainState ,
51
51
int64_t nBlockTreeDBCache,
52
52
int64_t nCoinDBCache,
53
- int64_t nCoinCacheUsage,
54
- unsigned int check_blocks,
55
- unsigned int check_level)
53
+ int64_t nCoinCacheUsage)
56
54
{
57
55
auto is_coinsview_empty = [&](CChainState* chainstate) EXCLUSIVE_LOCKS_REQUIRED (::cs_main) {
58
56
return fReset || fReindexChainState || chainstate->CoinsTip ().GetBestBlock ().IsNull ();
@@ -232,6 +230,21 @@ std::optional<ChainstateLoadingError> LoadChainstate(bool fReset,
232
230
return ChainstateLoadingError::ERROR_GENERIC_BLOCKDB_OPEN_FAILED;
233
231
}
234
232
233
+ return std::nullopt;
234
+ }
235
+
236
+ std::optional<ChainstateLoadVerifyError> VerifyLoadedChainstate (ChainstateManager& chainman,
237
+ CEvoDB& evodb,
238
+ bool fReset ,
239
+ bool fReindexChainState ,
240
+ const CChainParams& chainparams,
241
+ unsigned int check_blocks,
242
+ unsigned int check_level)
243
+ {
244
+ auto is_coinsview_empty = [&](CChainState* chainstate) EXCLUSIVE_LOCKS_REQUIRED (::cs_main) {
245
+ return fReset || fReindexChainState || chainstate->CoinsTip ().GetBestBlock ().IsNull ();
246
+ };
247
+
235
248
try {
236
249
LOCK (cs_main);
237
250
@@ -246,7 +259,7 @@ std::optional<ChainstateLoadingError> LoadChainstate(bool fReset,
246
259
const CBlockIndex* tip = chainstate->m_chain .Tip ();
247
260
RPCNotifyBlockChange (tip);
248
261
if (tip && tip->nTime > GetTime () + MAX_FUTURE_BLOCK_TIME) {
249
- return ChainstateLoadingError ::ERROR_BLOCK_FROM_FUTURE;
262
+ return ChainstateLoadVerifyError ::ERROR_BLOCK_FROM_FUTURE;
250
263
}
251
264
const bool v19active{DeploymentActiveAfter (tip, chainparams.GetConsensus (), Consensus::DEPLOYMENT_V19)};
252
265
if (v19active) {
@@ -256,10 +269,10 @@ std::optional<ChainstateLoadingError> LoadChainstate(bool fReset,
256
269
257
270
if (!CVerifyDB ().VerifyDB (
258
271
*chainstate, chainparams, chainstate->CoinsDB (),
259
- * evodb,
272
+ evodb,
260
273
check_level,
261
274
check_blocks)) {
262
- return ChainstateLoadingError ::ERROR_CORRUPTED_BLOCK_DB;
275
+ return ChainstateLoadVerifyError ::ERROR_CORRUPTED_BLOCK_DB;
263
276
}
264
277
265
278
// VerifyDB() disconnects blocks which might result in us switching back to legacy.
@@ -277,15 +290,15 @@ std::optional<ChainstateLoadingError> LoadChainstate(bool fReset,
277
290
// TODO: CEvoDB instance should probably be a part of CChainState
278
291
// (for multiple chainstates to actually work in parallel)
279
292
// and not a global
280
- if (&chainman.ActiveChainstate () == chainstate && !evodb-> IsEmpty ()) {
293
+ if (&chainman.ActiveChainstate () == chainstate && !evodb. IsEmpty ()) {
281
294
// EvoDB processed some blocks earlier but we have no blocks anymore, something is wrong
282
- return ChainstateLoadingError ::ERROR_EVO_DB_SANITY_FAILED;
295
+ return ChainstateLoadVerifyError ::ERROR_EVO_DB_SANITY_FAILED;
283
296
}
284
297
}
285
298
}
286
299
} catch (const std::exception & e) {
287
300
LogPrintf (" %s\n " , e.what ());
288
- return ChainstateLoadingError::ERROR_GENERIC_BLOCKDB_OPEN_FAILED ;
301
+ return ChainstateLoadVerifyError::ERROR_GENERIC_FAILURE ;
289
302
}
290
303
291
304
return std::nullopt;
0 commit comments