Assets?: Make sure there's a chainActive.Tip() before calling some functions

This commit is contained in:
Jorge Timón 2015-06-01 23:20:04 +02:00
parent aee6723f72
commit 6d72a1e403

View file

@ -1453,7 +1453,8 @@ void CheckForkWarningConditionsOnNewFork(CBlockIndex* pindexNewForkTip)
pindexBestForkBase = pfork;
}
CheckForkWarningConditions();
if (chainActive.Tip())
CheckForkWarningConditions();
}
// Requires cs_main.
@ -1488,7 +1489,8 @@ void static InvalidChainFound(CBlockIndex* pindexNew)
LogPrintf("InvalidChainFound: current best=%s height=%d log2_work=%.8g date=%s\n",
chainActive.Tip()->GetBlockHash().ToString(), chainActive.Height(), log(chainActive.Tip()->nChainWork.getdouble())/log(2.0),
DateTimeStrFormat("%Y-%m-%d %H:%M:%S", chainActive.Tip()->GetBlockTime()));
CheckForkWarningConditions();
if (chainActive.Tip())
CheckForkWarningConditions();
}
void static InvalidBlockFound(CBlockIndex *pindex, const CValidationState &state) {
@ -3029,7 +3031,7 @@ bool ProcessNewBlock(CValidationState &state, CNode* pfrom, CBlock* pblock, CDis
return error("%s : AcceptBlock FAILED", __func__);
}
if (!ActivateBestChain(state, pblock))
if (chainActive.Tip() && !ActivateBestChain(state, pblock))
return error("%s : ActivateBestChain failed", __func__);
return true;
@ -3376,7 +3378,7 @@ bool InitBlockIndex() {
CBlockIndex *pindex = AddToBlockIndex(block);
if (!ReceivedBlockTransactions(block, state, pindex, blockPos))
return error("LoadBlockIndex() : genesis block not accepted");
if (!ActivateBestChain(state, &block))
if (chainActive.Tip() && !ActivateBestChain(state, &block))
return error("LoadBlockIndex() : genesis block cannot be activated");
// Force a chainstate write so that when we VerifyDB in a moment, it doesnt check stale data
return FlushStateToDisk(state, FLUSH_STATE_ALWAYS);