Skip to content

Commit

Permalink
Make GetAncestor more robust
Browse files Browse the repository at this point in the history
This check for pskip != NULL was introduced in bitcoin#5927 for 0.12.
It is in general safer and allows GetAncestor to be used in more places, specifically in the mining tests for the backport of BIP 68 to 0.11.
  • Loading branch information
morcos committed Mar 16, 2016
1 parent 741a06a commit 148e3ba
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/chain.cpp
Expand Up @@ -82,9 +82,10 @@ CBlockIndex* CBlockIndex::GetAncestor(int height)
while (heightWalk > height) {
int heightSkip = GetSkipHeight(heightWalk);
int heightSkipPrev = GetSkipHeight(heightWalk - 1);
if (heightSkip == height ||
(heightSkip > height && !(heightSkipPrev < heightSkip - 2 &&
heightSkipPrev >= height))) {
if (pindexWalk->pskip != NULL &&
(heightSkip == height ||
(heightSkip > height && !(heightSkipPrev < heightSkip - 2 &&
heightSkipPrev >= height)))) {
// Only follow pskip if pprev->pskip isn't better than pskip->pprev.
pindexWalk = pindexWalk->pskip;
heightWalk = heightSkip;
Expand Down

0 comments on commit 148e3ba

Please sign in to comment.