MCPcopy Create free account
hub / github.com/LUX-Core/lux / LoadBlockIndexGuts

Method LoadBlockIndexGuts

src/txdb.cpp:484–590  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

482}
483
484bool CBlockTreeDB::LoadBlockIndexGuts()
485{
486 boost::scoped_ptr<leveldb::Iterator> pcursor(NewIterator());
487
488 CDataStream ssKeySet(SER_DISK, CLIENT_VERSION);
489 ssKeySet << make_pair(DB_BLOCK_INDEX, uint256(0));
490 pcursor->Seek(ssKeySet.str());
491
492 CBlockIndex* pindexPrev = nullptr;
493
494 int nDiscarded = 0;
495 int nFirstDiscarded = INT_MAX;
496 CLevelDBBatch batch;
497
498 // Load mapBlockIndex
499 while (pcursor->Valid()) {
500 if (fRequestShutdown) return false;
501 boost::this_thread::interruption_point();
502 try {
503 leveldb::Slice slKey = pcursor->key();
504 CDataStream ssKey(slKey.data(), slKey.data() + slKey.size(), SER_DISK, CLIENT_VERSION);
505 char chType;
506 ssKey >> chType;
507 if (chType == DB_BLOCK_INDEX) {
508 leveldb::Slice slValue = pcursor->value();
509 CDataStream ssValue(slValue.data(), slValue.data() + slValue.size(), SER_DISK, CLIENT_VERSION);
510 CDiskBlockIndex diskindex;
511 ssValue >> diskindex;
512
513 // Construct block index object
514 CBlockIndex* pindexNew = InsertBlockIndex(diskindex.GetBlockHash());
515 pindexNew->pprev = InsertBlockIndex(diskindex.hashPrev);
516 pindexNew->pnext = InsertBlockIndex(diskindex.hashNext);
517 pindexNew->nHeight = diskindex.nHeight;
518 pindexNew->nFile = diskindex.nFile;
519 pindexNew->nDataPos = diskindex.nDataPos;
520 pindexNew->nUndoPos = diskindex.nUndoPos;
521 pindexNew->nVersion = diskindex.nVersion;
522 pindexNew->hashMerkleRoot = diskindex.hashMerkleRoot;
523 pindexNew->nTime = diskindex.nTime;
524 pindexNew->nBits = diskindex.nBits;
525 pindexNew->nNonce = diskindex.nNonce;
526 pindexNew->nStatus = diskindex.nStatus;
527 pindexNew->nTx = diskindex.nTx;
528 pindexNew->hashStateRoot = diskindex.hashStateRoot; // lux
529 pindexNew->hashUTXORoot = diskindex.hashUTXORoot; // lux
530
531 // Proof Of Stake
532 pindexNew->nMint = diskindex.nMint;
533 pindexNew->nMoneySupply = diskindex.nMoneySupply;
534 pindexNew->nFlags = diskindex.nFlags;
535 pindexNew->nStakeModifier = diskindex.nStakeModifier;
536 pindexNew->prevoutStake = diskindex.prevoutStake;
537 pindexNew->nStakeTime = diskindex.nStakeTime;
538 pindexNew->hashProofOfStake = diskindex.hashProofOfStake;
539
540 bool isPoW = (diskindex.nNonce != 0) && pindexNew->nHeight <= Params().LAST_POW_BLOCK();
541 if (isPoW) {

Callers 1

LoadBlockIndexDBFunction · 0.80

Calls 15

InsertBlockIndexFunction · 0.85
LogPrintFunction · 0.85
errorFunction · 0.85
strMethod · 0.80
LAST_POW_BLOCKMethod · 0.80
MarkStakeMethod · 0.80
GetProofMethod · 0.80
SetProofMethod · 0.80
uint256Class · 0.70
ParamsClass · 0.70
WriteBatchClass · 0.50
SeekMethod · 0.45

Tested by

no test coverage detected