|
|
@ -20,9 +20,7 @@ std::optional<ChainstateLoadingError> LoadChainstate(bool fReset,
|
|
|
|
bool fReindexChainState,
|
|
|
|
bool fReindexChainState,
|
|
|
|
int64_t nBlockTreeDBCache,
|
|
|
|
int64_t nBlockTreeDBCache,
|
|
|
|
int64_t nCoinDBCache,
|
|
|
|
int64_t nCoinDBCache,
|
|
|
|
int64_t nCoinCacheUsage,
|
|
|
|
int64_t nCoinCacheUsage)
|
|
|
|
unsigned int check_blocks,
|
|
|
|
|
|
|
|
unsigned int check_level)
|
|
|
|
|
|
|
|
{
|
|
|
|
{
|
|
|
|
auto is_coinsview_empty = [&](CChainState* chainstate) EXCLUSIVE_LOCKS_REQUIRED(::cs_main) {
|
|
|
|
auto is_coinsview_empty = [&](CChainState* chainstate) EXCLUSIVE_LOCKS_REQUIRED(::cs_main) {
|
|
|
|
return fReset || fReindexChainState || chainstate->CoinsTip().GetBestBlock().IsNull();
|
|
|
|
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 {
|
|
|
|
try {
|
|
|
|
LOCK(cs_main);
|
|
|
|
LOCK(cs_main);
|
|
|
|
|
|
|
|
|
|
|
@ -145,20 +157,20 @@ std::optional<ChainstateLoadingError> LoadChainstate(bool fReset,
|
|
|
|
const CBlockIndex* tip = chainstate->m_chain.Tip();
|
|
|
|
const CBlockIndex* tip = chainstate->m_chain.Tip();
|
|
|
|
RPCNotifyBlockChange(tip);
|
|
|
|
RPCNotifyBlockChange(tip);
|
|
|
|
if (tip && tip->nTime > GetTime() + MAX_FUTURE_BLOCK_TIME) {
|
|
|
|
if (tip && tip->nTime > GetTime() + MAX_FUTURE_BLOCK_TIME) {
|
|
|
|
return ChainstateLoadingError::ERROR_BLOCK_FROM_FUTURE;
|
|
|
|
return ChainstateLoadVerifyError::ERROR_BLOCK_FROM_FUTURE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (!CVerifyDB().VerifyDB(
|
|
|
|
if (!CVerifyDB().VerifyDB(
|
|
|
|
*chainstate, chainparams, chainstate->CoinsDB(),
|
|
|
|
*chainstate, chainparams, chainstate->CoinsDB(),
|
|
|
|
check_level,
|
|
|
|
check_level,
|
|
|
|
check_blocks)) {
|
|
|
|
check_blocks)) {
|
|
|
|
return ChainstateLoadingError::ERROR_CORRUPTED_BLOCK_DB;
|
|
|
|
return ChainstateLoadVerifyError::ERROR_CORRUPTED_BLOCK_DB;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} catch (const std::exception& e) {
|
|
|
|
} catch (const std::exception& e) {
|
|
|
|
LogPrintf("%s\n", e.what());
|
|
|
|
LogPrintf("%s\n", e.what());
|
|
|
|
return ChainstateLoadingError::ERROR_GENERIC_BLOCKDB_OPEN_FAILED;
|
|
|
|
return ChainstateLoadVerifyError::ERROR_GENERIC_FAILURE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return std::nullopt;
|
|
|
|
return std::nullopt;
|
|
|
|