MCPcopy Create free account
hub / github.com/BTCGPU/BTCGPU / LastCommonAncestor

Function LastCommonAncestor

src/chain.cpp:155–170  ·  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

153/** Find the last common ancestor two blocks have.
154 * Both pa and pb must be non-nullptr. */
155const 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
172bool AreOnTheSameFork(const CBlockIndex *pa, const CBlockIndex *pb) {
173 if (pa->nHeight > pb->nHeight) {

Callers 3

EXCLUSIVE_LOCKS_REQUIREDFunction · 0.85
ReplayBlocksMethod · 0.85

Calls 1

GetAncestorMethod · 0.80

Tested by

no test coverage detected