MCPcopy Create free account
hub / github.com/ElementsProject/elements / LastCommonAncestor

Function LastCommonAncestor

src/chain.cpp:190–205  ·  view source on GitHub ↗

Find the last common ancestor two blocks have. * Both pa and pb must be non-nullptr. */

Source from the content-addressed store, hash-verified

188/** Find the last common ancestor two blocks have.
189 * Both pa and pb must be non-nullptr. */
190const 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}

Callers 3

ReplayBlocksMethod · 0.85
findCommonAncestorMethod · 0.85

Calls 1

GetAncestorMethod · 0.80

Tested by

no test coverage detected