Find the last common ancestor two blocks have. * Both pa and pb must be non-nullptr. */
| 188 | /** Find the last common ancestor two blocks have. |
| 189 | * Both pa and pb must be non-nullptr. */ |
| 190 | const CBlockIndex* LastCommonAncestor(const CBlockIndex* pa, const CBlockIndex* pb) { |
| 191 | if (pa->nHeight > pb->nHeight) { |
| 192 | pa = pa->GetAncestor(pb->nHeight); |
| 193 | } else if (pb->nHeight > pa->nHeight) { |
| 194 | pb = pb->GetAncestor(pa->nHeight); |
| 195 | } |
| 196 | |
| 197 | while (pa != pb && pa && pb) { |
| 198 | pa = pa->pprev; |
| 199 | pb = pb->pprev; |
| 200 | } |
| 201 | |
| 202 | // Eventually all chain branches meet at the genesis block. |
| 203 | assert(pa == pb); |
| 204 | return pa; |
| 205 | } |
no test coverage detected