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

Method ChainStateFlushed

src/index/base.cpp:386–428  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

384}
385
386void BaseIndex::ChainStateFlushed(const ChainstateRole& role, const CBlockLocator& locator)
387{
388 // Ignore events from not fully validated chains to avoid out-of-order indexing.
389 if (!role.validated) {
390 return;
391 }
392
393 if (!m_synced) {
394 return;
395 }
396
397 const uint256& locator_tip_hash = locator.vHave.front();
398 const CBlockIndex* locator_tip_index;
399 {
400 LOCK(cs_main);
401 locator_tip_index = m_chainstate->m_blockman.LookupBlockIndex(locator_tip_hash);
402 }
403
404 if (!locator_tip_index) {
405 FatalErrorf("First block (hash=%s) in locator was not found",
406 locator_tip_hash.ToString());
407 return;
408 }
409
410 // This checks that ChainStateFlushed callbacks are received after BlockConnected. The check may fail
411 // immediately after the sync thread catches up and sets m_synced. Consider the case where
412 // there is a reorg and the blocks on the stale branch are in the ValidationInterface queue
413 // backlog even after the sync thread has caught up to the new chain tip. In this unlikely
414 // event, log a warning and let the queue clear.
415 const CBlockIndex* best_block_index = m_best_block_index.load();
416 if (best_block_index->GetAncestor(locator_tip_index->nHeight) != locator_tip_index) {
417 LogWarning("Locator contains block (hash=%s) not on known best "
418 "chain (tip=%s); not writing index locator",
419 locator_tip_hash.ToString(),
420 best_block_index->GetBlockHash().ToString());
421 return;
422 }
423
424 // No need to handle errors in Commit. If it fails, the error will be already be logged. The
425 // best way to recover is to continue, as index cannot be corrupted by a missed commit to disk
426 // for an advanced index state.
427 Commit();
428}
429
430bool BaseIndex::BlockUntilSyncedToCurrentChain() const
431{

Callers 1

FlushStateToDiskMethod · 0.45

Calls 6

LookupBlockIndexMethod · 0.80
frontMethod · 0.45
ToStringMethod · 0.45
loadMethod · 0.45
GetAncestorMethod · 0.45
GetBlockHashMethod · 0.45

Tested by

no test coverage detected