MCPcopy Create free account
hub / github.com/ElementsProject/elements / LoadBlockIndexDB

Method LoadBlockIndexDB

src/node/blockstorage.cpp:375–426  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

373}
374
375bool BlockManager::LoadBlockIndexDB(ChainstateManager& chainman)
376{
377 if (!LoadBlockIndex(::Params().GetConsensus(), chainman)) {
378 return false;
379 }
380
381 // Load block file info
382 m_block_tree_db->ReadLastBlockFile(m_last_blockfile);
383 m_blockfile_info.resize(m_last_blockfile + 1);
384 LogPrintf("%s: last block file = %i\n", __func__, m_last_blockfile);
385 for (int nFile = 0; nFile <= m_last_blockfile; nFile++) {
386 m_block_tree_db->ReadBlockFileInfo(nFile, m_blockfile_info[nFile]);
387 }
388 LogPrintf("%s: last block file info: %s\n", __func__, m_blockfile_info[m_last_blockfile].ToString());
389 for (int nFile = m_last_blockfile + 1; true; nFile++) {
390 CBlockFileInfo info;
391 if (m_block_tree_db->ReadBlockFileInfo(nFile, info)) {
392 m_blockfile_info.push_back(info);
393 } else {
394 break;
395 }
396 }
397
398 // Check presence of blk files
399 LogPrintf("Checking all blk files are present...\n");
400 std::set<int> setBlkDataFiles;
401 for (const std::pair<const uint256, CBlockIndex*>& item : m_block_index) {
402 CBlockIndex* pindex = item.second;
403 if (pindex->nStatus & BLOCK_HAVE_DATA) {
404 setBlkDataFiles.insert(pindex->nFile);
405 }
406 }
407 for (std::set<int>::iterator it = setBlkDataFiles.begin(); it != setBlkDataFiles.end(); it++) {
408 FlatFilePos pos(*it, 0);
409 if (CAutoFile(OpenBlockFile(pos, true), SER_DISK, CLIENT_VERSION).IsNull()) {
410 return false;
411 }
412 }
413
414 // Check whether we have ever pruned block & undo files
415 m_block_tree_db->ReadFlag("prunedblockfiles", fHavePruned);
416 if (fHavePruned) {
417 LogPrintf("LoadBlockIndexDB(): Block files have previously been pruned\n");
418 }
419
420 // Check whether we need to continue reindexing
421 bool fReindexing = false;
422 m_block_tree_db->ReadReindexing(fReindexing);
423 if (fReindexing) fReindex = true;
424
425 return true;
426}
427
428CBlockIndex* BlockManager::GetLastCheckpoint(const CCheckpointData& data)
429{

Callers 1

LoadBlockIndexMethod · 0.80

Calls 14

OpenBlockFileFunction · 0.85
ReadLastBlockFileMethod · 0.80
ReadBlockFileInfoMethod · 0.80
ReadFlagMethod · 0.80
ReadReindexingMethod · 0.80
ParamsClass · 0.70
CAutoFileClass · 0.50
resizeMethod · 0.45
ToStringMethod · 0.45
push_backMethod · 0.45
insertMethod · 0.45
beginMethod · 0.45

Tested by

no test coverage detected