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

Method LoadGenesisBlock

src/validation.cpp:4946–4974  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

4944}
4945
4946bool Chainstate::LoadGenesisBlock()
4947{
4948 LOCK(cs_main);
4949
4950 const CChainParams& params{m_chainman.GetParams()};
4951
4952 // Check whether we're already initialized by checking for genesis in
4953 // m_blockman.m_block_index. Note that we can't use m_chain here, since it is
4954 // set based on the coins db, not the block index db, which is the only
4955 // thing loaded at this point.
4956 if (m_blockman.m_block_index.contains(params.GenesisBlock().GetHash()))
4957 return true;
4958
4959 try {
4960 const CBlock& block = params.GenesisBlock();
4961 FlatFilePos blockPos{m_blockman.WriteBlock(block, 0)};
4962 if (blockPos.IsNull()) {
4963 LogError("%s: writing genesis block to disk failed\n", __func__);
4964 return false;
4965 }
4966 CBlockIndex* pindex = m_blockman.AddToBlockIndex(block, m_chainman.m_best_header);
4967 m_chainman.ReceivedBlockTransactions(block, pindex, blockPos);
4968 } catch (const std::runtime_error& e) {
4969 LogError("%s: failed to write genesis block: %s\n", __func__, e.what());
4970 return false;
4971 }
4972
4973 return true;
4974}
4975
4976void ChainstateManager::LoadExternalBlockFile(
4977 AutoFile& file_in,

Callers 4

BOOST_AUTO_TEST_CASEFunction · 0.80
EXCLUSIVE_LOCKS_REQUIREDFunction · 0.80
ImportBlocksFunction · 0.80

Calls 7

AddToBlockIndexMethod · 0.80
containsMethod · 0.45
GetHashMethod · 0.45
WriteBlockMethod · 0.45
IsNullMethod · 0.45
whatMethod · 0.45

Tested by 2

BOOST_AUTO_TEST_CASEFunction · 0.64