Skip to content

Commit

Permalink
Cleanup: remove unneeded check (time-based) for version 4 header
Browse files Browse the repository at this point in the history
thus remove !CheckBlockHeader and directly use (fCheckPOW &&
!CheckProofOfWork)
  • Loading branch information
random-zebra committed Dec 17, 2020
1 parent c0819f8 commit a4ef257
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 27 deletions.
28 changes: 2 additions & 26 deletions src/validation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand Down
1 change: 0 additions & 1 deletion src/validation.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down

0 comments on commit a4ef257

Please sign in to comment.