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

Function InitBlockIndex

src/main.cpp:4112–4153  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

4110
4111
4112bool InitBlockIndex() {
4113 const CChainParams& chainparams = Params();
4114 LOCK(cs_main);
4115
4116 // Initialize global variables that cannot be constructed at startup.
4117 recentRejects.reset(new CRollingBloomFilter(120000, 0.000001));
4118
4119 // Check whether we're already initialized
4120 if (chainActive.Genesis() != NULL)
4121 return true;
4122
4123 // Use the provided setting for -txindex in the new database
4124 fTxIndex = GetBoolArg("-txindex", false);
4125 pblocktree->WriteFlag("txindex", fTxIndex);
4126 LogPrintf("Initializing databases...\n");
4127
4128 // Only add the genesis block if not reindexing (in which case we reuse the one already on disk)
4129 if (!fReindex) {
4130 try {
4131 CBlock &block = const_cast<CBlock&>(Params().GenesisBlock());
4132 // Start new block file
4133 unsigned int nBlockSize = ::GetSerializeSize(block, SER_DISK, CLIENT_VERSION);
4134 CDiskBlockPos blockPos;
4135 CValidationState state;
4136 if (!FindBlockPos(state, blockPos, nBlockSize+8, 0, block.GetBlockTime()))
4137 return error("LoadBlockIndex(): FindBlockPos failed");
4138 if (!WriteBlockToDisk(block, blockPos, chainparams.MessageStart()))
4139 return error("LoadBlockIndex(): writing genesis block to disk failed");
4140 CBlockIndex *pindex = AddToBlockIndex(block);
4141 if (!ReceivedBlockTransactions(block, state, pindex, blockPos))
4142 return error("LoadBlockIndex(): genesis block not accepted");
4143 if (!ActivateBestChain(state, &block))
4144 return error("LoadBlockIndex(): genesis block cannot be activated");
4145 // Force a chainstate write so that when we VerifyDB in a moment, it doesn't check stale data
4146 return FlushStateToDisk(state, FLUSH_STATE_ALWAYS);
4147 } catch (const std::runtime_error& e) {
4148 return error("LoadBlockIndex(): failed to initialize block database: %s", e.what());
4149 }
4150 }
4151
4152 return true;
4153}
4154
4155
4156

Callers 3

ThreadImportFunction · 0.85
AppInit2Function · 0.85
TestingSetupMethod · 0.85

Calls 14

GetBoolArgFunction · 0.85
GetSerializeSizeFunction · 0.85
FindBlockPosFunction · 0.85
errorFunction · 0.85
WriteBlockToDiskFunction · 0.85
AddToBlockIndexFunction · 0.85
ActivateBestChainFunction · 0.85
FlushStateToDiskFunction · 0.85
resetMethod · 0.80
GenesisMethod · 0.80
WriteFlagMethod · 0.80

Tested by 1

TestingSetupMethod · 0.68