MCPcopy Create free account
hub / github.com/bitcoin/bitcoin / VerifyLoadedChainstate

Function VerifyLoadedChainstate

src/node/chainstate.cpp:240–279  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

238}
239
240ChainstateLoadResult VerifyLoadedChainstate(ChainstateManager& chainman, const ChainstateLoadOptions& options)
241{
242 auto is_coinsview_empty = [&](Chainstate& chainstate) EXCLUSIVE_LOCKS_REQUIRED(::cs_main) {
243 return options.wipe_chainstate_db || chainstate.CoinsTip().GetBestBlock().IsNull();
244 };
245
246 LOCK(cs_main);
247
248 for (auto& chainstate : chainman.m_chainstates) {
249 if (!is_coinsview_empty(*chainstate)) {
250 const CBlockIndex* tip = chainstate->m_chain.Tip();
251 if (tip && tip->nTime > GetTime() + MAX_FUTURE_BLOCK_TIME) {
252 return {ChainstateLoadStatus::FAILURE, _("The block database contains a block which appears to be from the future. "
253 "This may be due to your computer's date and time being set incorrectly. "
254 "Only rebuild the block database if you are sure that your computer's date and time are correct")};
255 }
256
257 VerifyDBResult result = CVerifyDB(chainman.GetNotifications()).VerifyDB(
258 *chainstate, chainman.GetConsensus(), chainstate->CoinsDB(),
259 options.check_level,
260 options.check_blocks);
261 switch (result) {
262 case VerifyDBResult::SUCCESS:
263 case VerifyDBResult::SKIPPED_MISSING_BLOCKS:
264 break;
265 case VerifyDBResult::INTERRUPTED:
266 return {ChainstateLoadStatus::INTERRUPTED, _("Block verification was interrupted")};
267 case VerifyDBResult::CORRUPTED_BLOCK_DB:
268 return {ChainstateLoadStatus::FAILURE, _("Corrupted block database detected")};
269 case VerifyDBResult::SKIPPED_L3_CHECKS:
270 if (options.require_full_verification) {
271 return {ChainstateLoadStatus::FAILURE_INSUFFICIENT_DBCACHE, _("Insufficient dbcache for block verification")};
272 }
273 break;
274 } // no default case, so the compiler can warn about missing cases
275 }
276 }
277
278 return {ChainstateLoadStatus::SUCCESS, {}};
279}
280} // namespace node

Callers 3

InitAndLoadChainstateFunction · 0.85

Calls 8

_Function · 0.85
CVerifyDBClass · 0.85
VerifyDBMethod · 0.80
EXCLUSIVE_LOCKS_REQUIREDFunction · 0.70
GetTimeFunction · 0.50
IsNullMethod · 0.45
GetBestBlockMethod · 0.45
TipMethod · 0.45

Tested by 1