Changeset View
Changeset View
Standalone View
Standalone View
src/chain.cpp
Show First 20 Lines • Show All 171 Lines • ▼ Show 20 Lines | const CBlockIndex *LastCommonAncestor(const CBlockIndex *pa, | ||||
const CBlockIndex *pb) { | const CBlockIndex *pb) { | ||||
if (pa->nHeight > pb->nHeight) { | if (pa->nHeight > pb->nHeight) { | ||||
pa = pa->GetAncestor(pb->nHeight); | pa = pa->GetAncestor(pb->nHeight); | ||||
} else if (pb->nHeight > pa->nHeight) { | } else if (pb->nHeight > pa->nHeight) { | ||||
pb = pb->GetAncestor(pa->nHeight); | pb = pb->GetAncestor(pa->nHeight); | ||||
} | } | ||||
while (pa != pb && pa && pb) { | while (pa != pb && pa && pb) { | ||||
if (pa->pskip && pb->pskip && pa->pskip != pb->pskip) { | |||||
pa = pa->pskip; | |||||
pb = pb->pskip; | |||||
assert(pa->nHeight == pb->nHeight); | |||||
} else { | |||||
markblundeberg: I just realized this else doesn't actually need to be here (the next two lines can be run… | |||||
pa = pa->pprev; | pa = pa->pprev; | ||||
pb = pb->pprev; | pb = pb->pprev; | ||||
} | } | ||||
} | |||||
// Eventually all chain branches meet at the genesis block. | // Eventually all chain branches meet at the genesis block. | ||||
assert(pa == pb); | assert(pa == pb); | ||||
return pa; | return pa; | ||||
} | } | ||||
bool AreOnTheSameFork(const CBlockIndex *pa, const CBlockIndex *pb) { | bool AreOnTheSameFork(const CBlockIndex *pa, const CBlockIndex *pb) { | ||||
if (pa->nHeight > pb->nHeight) { | if (pa->nHeight > pb->nHeight) { | ||||
pa = pa->GetAncestor(pb->nHeight); | pa = pa->GetAncestor(pb->nHeight); | ||||
} else if (pb->nHeight > pa->nHeight) { | } else if (pb->nHeight > pa->nHeight) { | ||||
pb = pb->GetAncestor(pa->nHeight); | pb = pb->GetAncestor(pa->nHeight); | ||||
} | } | ||||
return pa == pb; | return pa == pb; | ||||
} | } |
I just realized this else doesn't actually need to be here (the next two lines can be run immediately even if skip was used, since they satisfy the while condition. Anyway...