CBlockIndex contains, in addition to the pprev pointer to it parent block, a pskip pointer that points further back added in #4420. This allows GetAncestor(), and since #33515 also LastCommonAncestor() to locate ancestors and fork points in faster than linear time.
Contrary to what I believed when #4420 was written, the scheme is not $\mathcal{O}(\log n)$ but $\mathcal{O}(\log^2 n)$ (see #33661 (review)). However, true $\mathcal{O}(\log n)$ schemes exist: Fable 5.2 found the paper "An applicative random-access stack" by Eugene W. Myers (1983)... and then improved it by a factor 1.5. That is what is implemented here.
The idea is to lay out all the heights in a binary tree (not the block tree, this is just to arrange what heights point to which other ones):
<img width="950" height="510" alt="skiplist_tree" src="https://github.com/user-attachments/assets/24fb6622-86ec-439c-bc86-d70de2e78501" />
For inner nodes, pskip points to the left child (blue) and pprev to the right child (orange). For leaf nodes, pprev points to one below (light blue), and pskip points to the leftmost leaf descendant of it (light orange). Going from one height to another is simply following pskip when it doesn't overshoot the target, and pprev otherwise.
The scheme guarantees that any jump from a height $H$ takes at most $2 \, \lfloor\log_2(H+1)\rfloor - 1$ steps. The proof is explained in the comments, and (a tighter version of) the formula tested in the unit tests.
The number of pointers followed to go $d$ blocks back, over all heights from 500000 to 1499999 (before / after):
| $d$ | avg | p50 | p95 | p99 | max |
|---|---|---|---|---|---|
| 10 | 4.44 / 4.37 | 5 / 4 | 6 / 7 | 6 / 9 | 6 / 10 |
| 144 | 13.52 / 10.37 | 14 / 10 | 20 / 14 | 22 / 17 | 23 / 26 |
| 2016 | 26.20 / 16.19 | 26 / 16 | 38 / 20 | 41 / 23 | 43 / 29 |
| 50000 | 45.91 / 23.03 | 46 / 23 | 63 / 27 | 70 / 29 | 82 / 34 |
| 210000 | 56.78 / 25.99 | 57 / 26 | 77 / 30 | 84 / 32 | 101 / 36 |