Find the last common ancestor two blocks have. * Both pa and pb must be non-NULL. */
| 354 | /** Find the last common ancestor two blocks have. |
| 355 | * Both pa and pb must be non-NULL. */ |
| 356 | CBlockIndex* 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. */ |
no test coverage detected