consensus: Fix a rare crash bug

Fix a rare crash bug where no best chain can be activated, and therefore when trying
to find the height of the best chain via the last block triggers a null pointer dereference.
This commit is contained in:
Ross Nicoll 2021-07-26 22:40:39 +01:00
parent 1d2380df56
commit 14a2e1ba96
No known key found for this signature in database
GPG key ID: E679E30C312B94E0

View file

@ -2573,7 +2573,11 @@ bool ActivateBestChain(CValidationState &state, const CChainParams& chainparams,
}
} while (pindexNewTip != pindexMostWork);
CheckBlockIndex(chainparams.GetConsensus(pindexNewTip->nHeight));
if (pindexNewTip != NULL) {
CheckBlockIndex(chainparams.GetConsensus(pindexNewTip->nHeight));
} else {
CheckBlockIndex(chainparams.GetConsensus(0));
}
// Write changes periodically to disk, after relay.
if (!FlushStateToDisk(state, FLUSH_STATE_PERIODIC)) {