Find the last common ancestor two blocks have. * Both pa and pb must be non-nullptr. */
| 153 | /** Find the last common ancestor two blocks have. |
| 154 | * Both pa and pb must be non-nullptr. */ |
| 155 | const CBlockIndex* LastCommonAncestor(const CBlockIndex* pa, const CBlockIndex* pb) { |
| 156 | if (pa->nHeight > pb->nHeight) { |
| 157 | pa = pa->GetAncestor(pb->nHeight); |
| 158 | } else if (pb->nHeight > pa->nHeight) { |
| 159 | pb = pb->GetAncestor(pa->nHeight); |
| 160 | } |
| 161 | |
| 162 | while (pa != pb && pa && pb) { |
| 163 | pa = pa->pprev; |
| 164 | pb = pb->pprev; |
| 165 | } |
| 166 | |
| 167 | // Eventually all chain branches meet at the genesis block. |
| 168 | assert(pa == pb); |
| 169 | return pa; |
| 170 | } |
| 171 | |
| 172 | bool AreOnTheSameFork(const CBlockIndex *pa, const CBlockIndex *pb) { |
| 173 | if (pa->nHeight > pb->nHeight) { |
no test coverage detected