@@ -50,9 +50,7 @@ std::optional<ChainstateLoadingError> LoadChainstate(bool fReset,
5050 bool fReindexChainState ,
5151 int64_t nBlockTreeDBCache,
5252 int64_t nCoinDBCache,
53- int64_t nCoinCacheUsage,
54- unsigned int check_blocks,
55- unsigned int check_level)
53+ int64_t nCoinCacheUsage)
5654{
5755 auto is_coinsview_empty = [&](CChainState* chainstate) EXCLUSIVE_LOCKS_REQUIRED (::cs_main) {
5856 return fReset || fReindexChainState || chainstate->CoinsTip ().GetBestBlock ().IsNull ();
@@ -232,6 +230,21 @@ std::optional<ChainstateLoadingError> LoadChainstate(bool fReset,
232230 return ChainstateLoadingError::ERROR_GENERIC_BLOCKDB_OPEN_FAILED;
233231 }
234232
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+
235248 try {
236249 LOCK (cs_main);
237250
@@ -246,7 +259,7 @@ std::optional<ChainstateLoadingError> LoadChainstate(bool fReset,
246259 const CBlockIndex* tip = chainstate->m_chain .Tip ();
247260 RPCNotifyBlockChange (tip);
248261 if (tip && tip->nTime > GetTime () + MAX_FUTURE_BLOCK_TIME) {
249- return ChainstateLoadingError ::ERROR_BLOCK_FROM_FUTURE;
262+ return ChainstateLoadVerifyError ::ERROR_BLOCK_FROM_FUTURE;
250263 }
251264 const bool v19active{DeploymentActiveAfter (tip, chainparams.GetConsensus (), Consensus::DEPLOYMENT_V19)};
252265 if (v19active) {
@@ -256,10 +269,10 @@ std::optional<ChainstateLoadingError> LoadChainstate(bool fReset,
256269
257270 if (!CVerifyDB ().VerifyDB (
258271 *chainstate, chainparams, chainstate->CoinsDB (),
259- * evodb,
272+ evodb,
260273 check_level,
261274 check_blocks)) {
262- return ChainstateLoadingError ::ERROR_CORRUPTED_BLOCK_DB;
275+ return ChainstateLoadVerifyError ::ERROR_CORRUPTED_BLOCK_DB;
263276 }
264277
265278 // VerifyDB() disconnects blocks which might result in us switching back to legacy.
@@ -277,15 +290,15 @@ std::optional<ChainstateLoadingError> LoadChainstate(bool fReset,
277290 // TODO: CEvoDB instance should probably be a part of CChainState
278291 // (for multiple chainstates to actually work in parallel)
279292 // and not a global
280- if (&chainman.ActiveChainstate () == chainstate && !evodb-> IsEmpty ()) {
293+ if (&chainman.ActiveChainstate () == chainstate && !evodb. IsEmpty ()) {
281294 // 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;
283296 }
284297 }
285298 }
286299 } catch (const std::exception& e) {
287300 LogPrintf (" %s\n " , e.what ());
288- return ChainstateLoadingError::ERROR_GENERIC_BLOCKDB_OPEN_FAILED ;
301+ return ChainstateLoadVerifyError::ERROR_GENERIC_FAILURE ;
289302 }
290303
291304 return std::nullopt ;
0 commit comments