MCPcopy Create free account
hub / github.com/bitcoinxt/bitcoinxt / LastCommonAncestor

Function LastCommonAncestor

src/main.cpp:356–371  ·  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

354/** Find the last common ancestor two blocks have.
355 * Both pa and pb must be non-NULL. */
356CBlockIndex* LastCommonAncestor(CBlockIndex* pa, CBlockIndex* pb) {
357 if (pa->nHeight > pb->nHeight) {
358 pa = pa->GetAncestor(pb->nHeight);
359 } else if (pb->nHeight > pa->nHeight) {
360 pb = pb->GetAncestor(pa->nHeight);
361 }
362
363 while (pa != pb && pa && pb) {
364 pa = pa->pprev;
365 pb = pb->pprev;
366 }
367
368 // Eventually all chain branches meet at the genesis block.
369 assert(pa == pb);
370 return pa;
371}
372
373/** Update pindexLastCommonBlock and add not-in-flight missing successors to vBlocks, until it has
374 * at most count entries. */

Callers 1

FindNextBlocksToDownloadFunction · 0.85

Calls 1

GetAncestorMethod · 0.80

Tested by

no test coverage detected