99 | @@ -99,8 +100,12 @@ CBlockIndex* CBlockIndex::GetAncestor(int height)
100 | // Only follow pskip if pprev->pskip isn't better than pskip->pprev.
101 | pindexWalk = pindexWalk->pskip;
102 | heightWalk = heightSkip;
103 | + } else if (pindexWalk->pprev == NULL) {
104 | + // pindexWalk should always have a parent (since pindexWalk is not the genesis block)
105 | + LogPrintf("%s: Block index is missing a block. Block %s, height %d has no parent.\n", __func__, pindexWalk->GetBlockHash().ToString(), heightWalk);
106 | + LogPrintf("%s: Run bitcoin with -reindex to rebuild the block index. This will redownload the entire blockchain if running a pruned node.\n", __func__);
This sounds like logic that belongs in LoadBlockIndex, not in the basic data structure logic.