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

Method LoadBlockIndexGuts

src/txdb.cpp:378–442  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

376}
377
378bool CBlockTreeDB::LoadBlockIndexGuts(const Consensus::Params& consensusParams, std::function<CBlockIndex*(const uint256&)> insertBlockIndex, int trimBelowHeight)
379{
380 AssertLockHeld(::cs_main);
381 std::unique_ptr<CDBIterator> pcursor(NewIterator());
382 pcursor->Seek(std::make_pair(DB_BLOCK_INDEX, uint256()));
383
384 int n_untrimmed = 0;
385 int n_total = 0;
386
387 // Load m_block_index
388 while (pcursor->Valid()) {
389 if (ShutdownRequested()) return false;
390 std::pair<uint8_t, uint256> key;
391 if (pcursor->GetKey(key) && key.first == DB_BLOCK_INDEX) {
392 CDiskBlockIndex diskindex;
393 if (pcursor->GetValue(diskindex)) {
394 // Construct block index object
395 CBlockIndex* pindexNew = insertBlockIndex(diskindex.GetBlockHash());
396 pindexNew->pprev = insertBlockIndex(diskindex.hashPrev);
397 pindexNew->nHeight = diskindex.nHeight;
398 pindexNew->nFile = diskindex.nFile;
399 pindexNew->nDataPos = diskindex.nDataPos;
400 pindexNew->nUndoPos = diskindex.nUndoPos;
401 pindexNew->nVersion = diskindex.nVersion;
402 pindexNew->hashMerkleRoot = diskindex.hashMerkleRoot;
403 pindexNew->nTime = diskindex.nTime;
404 pindexNew->nBits = diskindex.nBits;
405 pindexNew->nNonce = diskindex.nNonce;
406 pindexNew->nStatus = diskindex.nStatus;
407 pindexNew->nTx = diskindex.nTx;
408
409 pindexNew->proof = diskindex.proof;
410 pindexNew->m_dynafed_params = diskindex.m_dynafed_params;
411 pindexNew->m_signblock_witness = diskindex.m_signblock_witness;
412
413 assert(!(g_signed_blocks && diskindex.m_dynafed_params.value().IsNull() && diskindex.proof.value().IsNull()));
414
415 pindexNew->set_stored();
416 n_total++;
417
418 const uint256 block_hash = pindexNew->GetBlockHash();
419 // Only validate one of every 1000 block header for sanity check
420 if (pindexNew->nHeight % 1000 == 0 &&
421 block_hash != consensusParams.hashGenesisBlock &&
422 !CheckProof(pindexNew->GetBlockHeader(), consensusParams)) {
423 return error("%s: CheckProof: %s, %s", __func__, block_hash.ToString(), pindexNew->ToString());
424 }
425 if (diskindex.nHeight >= trimBelowHeight) {
426 n_untrimmed++;
427 } else {
428 pindexNew->trim();
429 }
430
431 pcursor->Next();
432 } else {
433 return error("%s: failed to read value", __func__);
434 }
435 } else {

Callers 1

LoadBlockIndexMethod · 0.80

Calls 15

ShutdownRequestedFunction · 0.85
CheckProofFunction · 0.85
errorFunction · 0.85
set_storedMethod · 0.80
trimMethod · 0.80
uint256Class · 0.70
SeekMethod · 0.45
ValidMethod · 0.45
GetKeyMethod · 0.45
GetValueMethod · 0.45
GetBlockHashMethod · 0.45
IsNullMethod · 0.45

Tested by

no test coverage detected