MCPcopy Create free account
hub / github.com/BTCGPU/BTCGPU / LoadBlockIndexGuts

Method LoadBlockIndexGuts

src/txdb.cpp:250–295  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

248}
249
250bool CBlockTreeDB::LoadBlockIndexGuts(const Consensus::Params& consensusParams, std::function<CBlockIndex*(const uint256&)> insertBlockIndex)
251{
252 std::unique_ptr<CDBIterator> pcursor(NewIterator());
253
254 pcursor->Seek(std::make_pair(DB_BLOCK_INDEX, uint256()));
255
256 // Load mapBlockIndex
257 while (pcursor->Valid()) {
258 boost::this_thread::interruption_point();
259 std::pair<char, uint256> key;
260 if (pcursor->GetKey(key) && key.first == DB_BLOCK_INDEX) {
261 CDiskBlockIndex diskindex;
262 if (pcursor->GetValue(diskindex)) {
263 // Construct block index object
264 CBlockIndex* pindexNew = insertBlockIndex(diskindex.GetBlockHash());
265 pindexNew->pprev = insertBlockIndex(diskindex.hashPrev);
266 pindexNew->nHeight = diskindex.nHeight;
267 pindexNew->nFile = diskindex.nFile;
268 pindexNew->nDataPos = diskindex.nDataPos;
269 pindexNew->nUndoPos = diskindex.nUndoPos;
270 pindexNew->nVersion = diskindex.nVersion;
271 pindexNew->hashMerkleRoot = diskindex.hashMerkleRoot;
272 memcpy(pindexNew->nReserved, diskindex.nReserved, sizeof(pindexNew->nReserved));
273 pindexNew->nTime = diskindex.nTime;
274 pindexNew->nBits = diskindex.nBits;
275 pindexNew->nNonce = diskindex.nNonce;
276 pindexNew->nSolution = diskindex.nSolution;
277 pindexNew->nStatus = diskindex.nStatus;
278 pindexNew->nTx = diskindex.nTx;
279
280 // TODO(h4x3rotab): Check Equihash solution? Not sure why Zcash doesn't do it here.
281 bool postfork = pindexNew->nHeight >= consensusParams.BTGHeight;
282 if (!CheckProofOfWork(pindexNew->GetBlockHash(), pindexNew->nBits, postfork, consensusParams))
283 return error("%s: CheckProofOfWork failed: %s", __func__, pindexNew->ToString());
284
285 pcursor->Next();
286 } else {
287 return error("%s: failed to read value", __func__);
288 }
289 } else {
290 break;
291 }
292 }
293
294 return true;
295}
296
297namespace {
298

Callers 1

LoadBlockIndexMethod · 0.80

Calls 11

memcpyFunction · 0.85
CheckProofOfWorkFunction · 0.85
errorFunction · 0.85
uint256Class · 0.70
SeekMethod · 0.45
ValidMethod · 0.45
GetKeyMethod · 0.45
GetValueMethod · 0.45
GetBlockHashMethod · 0.45
ToStringMethod · 0.45
NextMethod · 0.45

Tested by

no test coverage detected