diff options
author | Carl Dong <contact@carldong.me> | 2021-11-10 15:57:14 -0500 |
---|---|---|
committer | Carl Dong <contact@carldong.me> | 2021-12-06 15:58:10 -0500 |
commit | ca7c0b934db68acdc410e3a82f1ed898382da2e5 (patch) | |
tree | f270e09b1d92fd1e3ac37e85e68a7f3918add8f0 /src/node/chainstate.cpp | |
parent | adf4912d77496b9a243476c5944528f95641f14d (diff) |
Split off VerifyLoadedChainstate
Diffstat (limited to 'src/node/chainstate.cpp')
-rw-r--r-- | src/node/chainstate.cpp | 24 |
1 files changed, 18 insertions, 6 deletions
diff --git a/src/node/chainstate.cpp b/src/node/chainstate.cpp index 8cc523fdd5..7dbaedb483 100644 --- a/src/node/chainstate.cpp +++ b/src/node/chainstate.cpp @@ -20,9 +20,7 @@ std::optional<ChainstateLoadingError> LoadChainstate(bool fReset, bool fReindexChainState, int64_t nBlockTreeDBCache, int64_t nCoinDBCache, - int64_t nCoinCacheUsage, - unsigned int check_blocks, - unsigned int check_level) + int64_t nCoinCacheUsage) { auto is_coinsview_empty = [&](CChainState* chainstate) EXCLUSIVE_LOCKS_REQUIRED(::cs_main) { return fReset || fReindexChainState || chainstate->CoinsTip().GetBestBlock().IsNull(); @@ -131,6 +129,20 @@ std::optional<ChainstateLoadingError> LoadChainstate(bool fReset, } } + return std::nullopt; +} + +std::optional<ChainstateLoadVerifyError> VerifyLoadedChainstate(ChainstateManager& chainman, + bool fReset, + bool fReindexChainState, + const CChainParams& chainparams, + unsigned int check_blocks, + unsigned int check_level) +{ + auto is_coinsview_empty = [&](CChainState* chainstate) EXCLUSIVE_LOCKS_REQUIRED(::cs_main) { + return fReset || fReindexChainState || chainstate->CoinsTip().GetBestBlock().IsNull(); + }; + try { LOCK(cs_main); @@ -145,20 +157,20 @@ std::optional<ChainstateLoadingError> LoadChainstate(bool fReset, const CBlockIndex* tip = chainstate->m_chain.Tip(); RPCNotifyBlockChange(tip); if (tip && tip->nTime > GetTime() + MAX_FUTURE_BLOCK_TIME) { - return ChainstateLoadingError::ERROR_BLOCK_FROM_FUTURE; + return ChainstateLoadVerifyError::ERROR_BLOCK_FROM_FUTURE; } if (!CVerifyDB().VerifyDB( *chainstate, chainparams, chainstate->CoinsDB(), check_level, check_blocks)) { - return ChainstateLoadingError::ERROR_CORRUPTED_BLOCK_DB; + return ChainstateLoadVerifyError::ERROR_CORRUPTED_BLOCK_DB; } } } } catch (const std::exception& e) { LogPrintf("%s\n", e.what()); - return ChainstateLoadingError::ERROR_GENERIC_BLOCKDB_OPEN_FAILED; + return ChainstateLoadVerifyError::ERROR_GENERIC_FAILURE; } return std::nullopt; |