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

Function LastCommonAncestor

src/main.cpp:462–478  ·  view source on GitHub ↗

Find the last common ancestor two blocks have. * Both pa and pb must be non-NULL. */

Source from the content-addressed store, hash-verified

460/** Find the last common ancestor two blocks have.
461 * Both pa and pb must be non-NULL. */
462CBlockIndex* LastCommonAncestor(CBlockIndex* pa, CBlockIndex* pb)
463{
464 if (pa->nHeight > pb->nHeight) {
465 pa = pa->GetAncestor(pb->nHeight);
466 } else if (pb->nHeight > pa->nHeight) {
467 pb = pb->GetAncestor(pa->nHeight);
468 }
469
470 while (pa != pb && pa && pb) {
471 pa = pa->pprev;
472 pb = pb->pprev;
473 }
474
475 // Eventually all chain branches meet at the genesis block.
476 assert(pa == pb);
477 return pa;
478}
479
480/** Update pindexLastCommonBlock and add not-in-flight missing successors to vBlocks, until it has
481 * at most count entries. */

Callers 1

FindNextBlocksToDownloadFunction · 0.85

Calls 1

GetAncestorMethod · 0.80

Tested by

no test coverage detected