diff --git a/src/main.cpp b/src/main.cpp index e1d4d9d8ae..1d5e2a533c 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -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);