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

Method RegenerateFullIndex

src/txdb.cpp:334–376  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

332}
333
334const CBlockIndex *CBlockTreeDB::RegenerateFullIndex(const CBlockIndex *pindexTrimmed, CBlockIndex *pindexNew) const
335{
336 LOCK(cs_main);
337
338 if(!pindexTrimmed->trimmed()) {
339 return pindexTrimmed;
340 }
341 CBlockHeader tmp;
342 bool BlockRead = false;
343 {
344 // In unpruned nodes, same data could be read from blocks using ReadBlockFromDisk, but that turned out to
345 // be about 6x slower than reading from the index
346 std::pair<uint8_t, uint256> key(DB_BLOCK_INDEX, pindexTrimmed->GetBlockHash());
347 CDiskBlockIndex diskindex;
348 BlockRead = this->Read(key, diskindex);
349 tmp = diskindex.GetBlockHeader();
350 }
351 assert(BlockRead);
352 // Clone the needed data from the original trimmed block
353 pindexNew->pprev = pindexTrimmed->pprev;
354 pindexNew->phashBlock = pindexTrimmed->phashBlock;
355 // Construct block index object
356 pindexNew->nHeight = pindexTrimmed->nHeight;
357 pindexNew->nFile = pindexTrimmed->nFile;
358 pindexNew->nDataPos = pindexTrimmed->nDataPos;
359 pindexNew->nUndoPos = pindexTrimmed->nUndoPos;
360 pindexNew->nVersion = pindexTrimmed->nVersion;
361 pindexNew->hashMerkleRoot = pindexTrimmed->hashMerkleRoot;
362 pindexNew->nTime = pindexTrimmed->nTime;
363 pindexNew->nBits = pindexTrimmed->nBits;
364 pindexNew->nNonce = pindexTrimmed->nNonce;
365 pindexNew->nStatus = pindexTrimmed->nStatus;
366 pindexNew->nTx = pindexTrimmed->nTx;
367
368 pindexNew->proof = tmp.proof;
369 pindexNew->m_dynafed_params = tmp.m_dynafed_params;
370 pindexNew->m_signblock_witness = tmp.m_signblock_witness;
371
372 if (pindexTrimmed->nHeight && pindexTrimmed->nHeight % 1000 == 0) {
373 assert(CheckProof(pindexNew->GetBlockHeader(), Params().GetConsensus()));
374 }
375 return pindexNew;
376}
377
378bool CBlockTreeDB::LoadBlockIndexGuts(const Consensus::Params& consensusParams, std::function<CBlockIndex*(const uint256&)> insertBlockIndex, int trimBelowHeight)
379{

Callers 1

EXCLUSIVE_LOCKS_REQUIREDFunction · 0.80

Calls 6

CheckProofFunction · 0.85
trimmedMethod · 0.80
ParamsClass · 0.70
GetBlockHashMethod · 0.45
ReadMethod · 0.45
GetBlockHeaderMethod · 0.45

Tested by

no test coverage detected