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

Method LoadBlockIndex

src/validation.cpp:4920–4944  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

4918}
4919
4920bool ChainstateManager::LoadBlockIndex()
4921{
4922 AssertLockHeld(cs_main);
4923 // Load block index from databases
4924 if (m_blockman.m_blockfiles_indexed) {
4925 bool ret{m_blockman.LoadBlockIndexDB(CurrentChainstate().m_from_snapshot_blockhash)};
4926 if (!ret) return false;
4927
4928 m_blockman.ScanAndUnlinkAlreadyPrunedFiles();
4929
4930 std::vector<CBlockIndex*> vSortedByHeight{m_blockman.GetAllBlockIndices()};
4931 std::sort(vSortedByHeight.begin(), vSortedByHeight.end(),
4932 CBlockIndexHeightOnlyComparator());
4933
4934 for (CBlockIndex* pindex : vSortedByHeight) {
4935 if (m_interrupt) return false;
4936 if (pindex->nStatus & BLOCK_FAILED_VALID && (!m_best_invalid || pindex->nChainWork > m_best_invalid->nChainWork)) {
4937 m_best_invalid = pindex;
4938 }
4939 if (pindex->IsValid(BLOCK_VALID_TREE) && (m_best_header == nullptr || CBlockIndexWorkComparator()(m_best_header, pindex)))
4940 m_best_header = pindex;
4941 }
4942 }
4943 return true;
4944}
4945
4946bool Chainstate::LoadGenesisBlock()
4947{

Callers

nothing calls this directly

Calls 8

LoadBlockIndexDBMethod · 0.80
GetAllBlockIndicesMethod · 0.80
beginMethod · 0.45
endMethod · 0.45
IsValidMethod · 0.45

Tested by

no test coverage detected