| 4570 | } |
| 4571 | |
| 4572 | bool CChainState::LoadGenesisBlock() |
| 4573 | { |
| 4574 | LOCK(cs_main); |
| 4575 | |
| 4576 | // Check whether we're already initialized by checking for genesis in |
| 4577 | // m_blockman.m_block_index. Note that we can't use m_chain here, since it is |
| 4578 | // set based on the coins db, not the block index db, which is the only |
| 4579 | // thing loaded at this point. |
| 4580 | if (m_blockman.m_block_index.count(m_params.GenesisBlock().GetHash())) |
| 4581 | return true; |
| 4582 | |
| 4583 | try { |
| 4584 | const CBlock& block = m_params.GenesisBlock(); |
| 4585 | FlatFilePos blockPos{m_blockman.SaveBlockToDisk(block, 0, m_chain, m_params, nullptr)}; |
| 4586 | if (blockPos.IsNull()) { |
| 4587 | return error("%s: writing genesis block to disk failed", __func__); |
| 4588 | } |
| 4589 | CBlockIndex *pindex = m_blockman.AddToBlockIndex(block); |
| 4590 | ReceivedBlockTransactions(block, pindex, blockPos); |
| 4591 | } catch (const std::runtime_error& e) { |
| 4592 | return error("%s: failed to write genesis block: %s", __func__, e.what()); |
| 4593 | } |
| 4594 | |
| 4595 | return true; |
| 4596 | } |
| 4597 | |
| 4598 | void CChainState::LoadExternalBlockFile(FILE* fileIn, FlatFilePos* dbp) |
| 4599 | { |