From ec4fefd90c3ee8f8afdb12c6e9d973d69a829c44 Mon Sep 17 00:00:00 2001 From: Gregory Sanders Date: Mon, 7 Nov 2016 14:03:42 -0500 Subject: [PATCH] [upstream #9102] Really don't validate genesis block --- src/txdb.cpp | 2 +- src/validation.cpp | 16 +++++++++------- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/src/txdb.cpp b/src/txdb.cpp index 1a30bb58ad..4358f7e474 100644 --- a/src/txdb.cpp +++ b/src/txdb.cpp @@ -197,7 +197,7 @@ bool CBlockTreeDB::LoadBlockIndexGuts(boost::functionnStatus = diskindex.nStatus; pindexNew->nTx = diskindex.nTx; - if (!CheckProofOfWork(pindexNew->GetBlockHash(), pindexNew->nBits, Params().GetConsensus())) + if (!CheckProofOfWork(pindexNew->GetBlockHash(), pindexNew->nBits, Params().GetConsensus()) && pindexNew->GetBlockHash() != Params().GetConsensus().hashGenesisBlock) return error("LoadBlockIndex(): CheckProofOfWork failed: %s", pindexNew->ToString()); pcursor->Next(); diff --git a/src/validation.cpp b/src/validation.cpp index c9135c442b..341ea7bc23 100644 --- a/src/validation.cpp +++ b/src/validation.cpp @@ -1147,7 +1147,8 @@ bool ReadBlockFromDisk(CBlock& block, const CDiskBlockPos& pos, const Consensus: } // Check the header - if (!CheckProofOfWork(block.GetHash(), block.nBits, consensusParams)) + if (!CheckProofOfWork(block.GetHash(), block.nBits, consensusParams) && + block.GetHash() != consensusParams.hashGenesisBlock) return error("ReadBlockFromDisk: Errors in block header at %s", pos.ToString()); return true; @@ -1742,10 +1743,6 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin int64_t nTimeStart = GetTimeMicros(); - // Check it again in case a previous version let a bad block in - if (!CheckBlock(block, state, chainparams.GetConsensus(), !fJustCheck, !fJustCheck)) - return error("%s: Consensus::CheckBlock: %s", __func__, FormatStateMessage(state)); - // verify that the view's current state corresponds to the previous block uint256 hashPrevBlock = pindex->pprev == NULL ? uint256() : pindex->pprev->GetBlockHash(); assert(hashPrevBlock == view.GetBestBlock()); @@ -1758,6 +1755,10 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin return true; } + // Check it again in case a previous version let a bad block in + if (!CheckBlock(block, state, chainparams.GetConsensus(), !fJustCheck, !fJustCheck)) + return error("%s: Consensus::CheckBlock: %s", __func__, FormatStateMessage(state)); + bool fScriptChecks = true; if (!hashAssumeValid.IsNull()) { // We've been configured with the hash of a block which has been externally verified to have a valid history. @@ -3190,8 +3191,9 @@ static bool AcceptBlock(const std::shared_ptr& pblock, CValidation } if (fNewBlock) *fNewBlock = true; - if (!CheckBlock(block, state, chainparams.GetConsensus()) || - !ContextualCheckBlock(block, state, chainparams.GetConsensus(), pindex->pprev)) { + if ((block.GetHash() != chainparams.GetConsensus().hashGenesisBlock) && + (!CheckBlock(block, state, chainparams.GetConsensus()) || + !ContextualCheckBlock(block, state, chainparams.GetConsensus(), pindex->pprev))) { if (state.IsInvalid() && !state.CorruptionPossible()) { pindex->nStatus |= BLOCK_FAILED_VALID; setDirtyBlockIndex.insert(pindex);