| 4944 | } |
| 4945 | |
| 4946 | bool 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 | |
| 4976 | void ChainstateManager::LoadExternalBlockFile( |
| 4977 | AutoFile& file_in, |