MCPcopy Create free account
hub / github.com/WaykiChain/WaykiChain / PruneOrphanBlocks

Function PruneOrphanBlocks

src/main.cpp:373–397  ·  view source on GitHub ↗

Remove a random orphan block (which does not have any dependent orphans).

Source from the content-addressed store, hash-verified

371
372// Remove a random orphan block (which does not have any dependent orphans).
373bool static PruneOrphanBlocks(int32_t height) {
374 if (mapOrphanBlocksByPrev.size() <= MAX_ORPHAN_BLOCKS) {
375 return true;
376 }
377
378 COrphanBlock *pOrphanBlock = *setOrphanBlock.rbegin();
379 if (pOrphanBlock->height <= height) {
380 return false;
381 }
382 uint256 hash = pOrphanBlock->blockHash;
383 uint256 prevHash = pOrphanBlock->prevBlockHash;
384 setOrphanBlock.erase(pOrphanBlock);
385 multimap<uint256, COrphanBlock *>::iterator beg = mapOrphanBlocksByPrev.lower_bound(prevHash);
386 multimap<uint256, COrphanBlock *>::iterator end = mapOrphanBlocksByPrev.upper_bound(prevHash);
387 while (beg != end) {
388 if (beg->second->blockHash == hash) {
389 mapOrphanBlocksByPrev.erase(beg);
390 break;
391 }
392 ++beg;
393 }
394 mapOrphanBlocks.erase(hash);
395 delete pOrphanBlock;
396 return true;
397}
398
399bool fLargeWorkForkFound = false;
400bool fLargeWorkInvalidChainFound = false;

Callers 1

ProcessBlockFunction · 0.85

Calls 2

sizeMethod · 0.45
eraseMethod · 0.45

Tested by

no test coverage detected