diff --git a/src/pow.cpp b/src/pow.cpp --- a/src/pow.cpp +++ b/src/pow.cpp @@ -96,10 +96,8 @@ const CBlockHeader *pblock, const Config &config) { const Consensus::Params ¶ms = config.GetChainParams().GetConsensus(); - // Genesis block - if (pindexPrev == nullptr) { - return UintToArith256(params.powLimit).GetCompact(); - } + // GetNextWorkRequired should never be called on the genesis block + assert(pindexPrev != nullptr); // Special rule for regtest: we never retarget. if (params.fPowNoRetargeting) { diff --git a/src/validation.cpp b/src/validation.cpp --- a/src/validation.cpp +++ b/src/validation.cpp @@ -1642,7 +1642,11 @@ CValidationState &state, CBlockIndex *pindex, CCoinsViewCache &view, bool fJustCheck = false) { AssertLockHeld(cs_main); - + assert(pindex); + // pindex->phashBlock can be null if called by + // CreateNewBlock/TestBlockValidity + assert((pindex->phashBlock == nullptr) || + (*pindex->phashBlock == block.GetHash())); int64_t nTimeStart = GetTimeMicros(); // Check it again in case a previous version let a bad block in @@ -3566,7 +3570,8 @@ const Consensus::Params &consensusParams = config.GetChainParams().GetConsensus(); - const int nHeight = pindexPrev == nullptr ? 0 : pindexPrev->nHeight + 1; + assert(pindexPrev != nullptr); + const int nHeight = pindexPrev->nHeight + 1; // Check proof of work if (block.nBits != GetNextWorkRequired(pindexPrev, &block, config)) {