MCPcopy Create free account
hub / github.com/WaykiChain/WaykiChain / InitBlockIndex

Function InitBlockIndex

src/main.cpp:2395–2429  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2393}
2394
2395bool InitBlockIndex() {
2396 LOCK(cs_main);
2397 // Check whether we're already initialized
2398 if (chainActive.Genesis() != nullptr)
2399 return true;
2400
2401 // Use the provided setting for -txindex in the new database
2402 SysCfg().SetTxIndex(SysCfg().GetBoolArg("-txindex", true));
2403 pCdMan->pBlockCache->WriteFlag("txindex", SysCfg().IsTxIndex());
2404 LogPrint(BCLog::INFO, "Initializing databases...\n");
2405
2406 // Only add the genesis block if not reindexing (in which case we reuse the one already on disk)
2407 if (!SysCfg().IsReindex()) {
2408 try {
2409 CBlock &block = const_cast<CBlock &>(SysCfg().GenesisBlock());
2410 // Start new block file
2411 uint32_t nBlockSize = ::GetSerializeSize(block, SER_DISK, CLIENT_VERSION);
2412 CDiskBlockPos blockPos;
2413 CValidationState state;
2414 if (!FindBlockPos(state, blockPos, nBlockSize + 8, 0, block.GetTime()))
2415 return ERRORMSG("FindBlockPos failed");
2416
2417 if (!WriteBlockToDisk(block, blockPos))
2418 return ERRORMSG("writing genesis block to disk failed");
2419
2420 if (!AddToBlockIndex(block, state, blockPos))
2421 return ERRORMSG("genesis block not accepted");
2422
2423 } catch (runtime_error &e) {
2424 return ERRORMSG("failed to initialize block database: %s", e.what());
2425 }
2426 }
2427
2428 return true;
2429}
2430
2431void PrintBlockTree() {
2432 AssertLockHeld(cs_main);

Callers 2

ThreadImportFunction · 0.85
AppInitFunction · 0.85

Calls 12

GetSerializeSizeFunction · 0.85
FindBlockPosFunction · 0.85
WriteBlockToDiskFunction · 0.85
AddToBlockIndexFunction · 0.85
GenesisMethod · 0.80
GetBoolArgMethod · 0.80
WriteFlagMethod · 0.80
IsTxIndexMethod · 0.80
IsReindexMethod · 0.80
SetTxIndexMethod · 0.45
GetTimeMethod · 0.45
whatMethod · 0.45

Tested by

no test coverage detected