From 05fe877ef3988f8653970f80b835737b5933e65c Mon Sep 17 00:00:00 2001 From: random-zebra Date: Thu, 17 Dec 2020 16:54:51 +0100 Subject: [PATCH] Cleanup: remove unneeded check (time-based) for version 4 header thus remove !CheckBlockHeader and directly use (fCheckPOW && !CheckProofOfWork) Github-Pull: #2067 Rebased-From: a4ef257afa9fee744c32d7a4b3ccadd291ffc159 --- src/validation.cpp | 28 ++-------------------------- src/validation.h | 1 - 2 files changed, 2 insertions(+), 27 deletions(-) diff --git a/src/validation.cpp b/src/validation.cpp index 225e90ebc0d53..bdbac4e384450 100644 --- a/src/validation.cpp +++ b/src/validation.cpp @@ -2617,26 +2617,6 @@ bool FindUndoPos(CValidationState& state, int nFile, CDiskBlockPos& pos, unsigne return true; } -bool CheckBlockHeader(const CBlockHeader& block, CValidationState& state, bool fCheckPOW) -{ - // Check proof of work matches claimed amount - if (fCheckPOW && !CheckProofOfWork(block.GetHash(), block.nBits)) - return state.DoS(50, false, REJECT_INVALID, "high-hash", false, "proof of work failed"); - - if (Params().IsRegTestNet()) return true; - - // Version 4 header must be used after consensus.ZC_TimeStart. And never before. - if (block.GetBlockTime() > Params().GetConsensus().ZC_TimeStart) { - if(block.nVersion < 4) - return state.DoS(50,false, REJECT_INVALID, "block-version", "must be above 4 after ZC_TimeStart"); - } else { - if (block.nVersion >= 4) - return state.DoS(50,false, REJECT_INVALID, "block-version", "must be below 4 before ZC_TimeStart"); - } - - return true; -} - bool CheckColdStakeFreeOutput(const CTransaction& tx, const int nHeight) { if (!tx.HasP2CSOutputs()) @@ -2703,8 +2683,8 @@ bool CheckBlock(const CBlock& block, CValidationState& state, bool fCheckPOW, bo // Check that the header is valid (particularly PoW). This is mostly // redundant with the call in AcceptBlockHeader. - if (!CheckBlockHeader(block, state, !IsPoS && fCheckPOW)) - return false; + if (!IsPoS && fCheckPOW && !CheckProofOfWork(block.GetHash(), block.nBits)) + return state.DoS(50, false, REJECT_INVALID, "high-hash", false, "proof of work failed"); // All potential-corruption validation must be done before we do any // transaction validation, as otherwise we may mark the header as invalid @@ -3070,10 +3050,6 @@ bool AcceptBlockHeader(const CBlock& block, CValidationState& state, CBlockIndex return true; } - if (!CheckBlockHeader(block, state, false)) { - return error("%s: CheckBlockHeader failed for block %s: %s", __func__, hash.ToString(), FormatStateMessage(state)); - } - // Get prev block index if (pindexPrev == nullptr && !GetPrevIndex(block, &pindexPrev, state)) { return false; diff --git a/src/validation.h b/src/validation.h index 9715c02a087f3..06713a60f3b6e 100644 --- a/src/validation.h +++ b/src/validation.h @@ -323,7 +323,6 @@ bool ReadBlockFromDisk(CBlock& block, const CBlockIndex* pindex); bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pindex, CCoinsViewCache& coins, bool fJustCheck, bool fAlreadyChecked = false); /** Context-independent validity checks */ -bool CheckBlockHeader(const CBlockHeader& block, CValidationState& state, bool fCheckPOW = true); bool CheckBlock(const CBlock& block, CValidationState& state, bool fCheckPOW = true, bool fCheckMerkleRoot = true, bool fCheckSig = true); bool CheckWork(const CBlock block, CBlockIndex* const pindexPrev);