Skip to content

Commit

Permalink
Add nHeight to CheckBlock
Browse files Browse the repository at this point in the history
  • Loading branch information
alamshafil committed Jul 14, 2022
1 parent 8296aeb commit 0d0f758
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/bench/checkblock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ static void DeserializeAndCheckBlockTest(benchmark::State& state)
assert(stream.Rewind(sizeof(block_bench::block566553)));

CValidationState validationState;
assert(CheckBlock(block, validationState, chainParams->GetConsensus()));
assert(CheckBlock(block, validationState, chainParams->GetConsensus(), 0));
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/blockencodings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ ReadStatus PartiallyDownloadedBlock::FillBlock(CBlock& block, const std::vector<

CValidationState state;

if (!CheckBlock(block, state, Params().GetConsensus())) {
if (!CheckBlock(block, state, Params().GetConsensus(), 0)) {
// TODO: We really want to just check merkle tree manually here,
// but that is expensive, and CheckBlock caches a block's
// "checked-status" (in the CBlock?). CBlock should be able to
Expand Down
10 changes: 5 additions & 5 deletions src/validation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2451,7 +2451,7 @@ static bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockInd
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)) // Force the check of asset duplicates when connecting the block
if (!CheckBlock(block, state, chainparams.GetConsensus(), 0, !fJustCheck, !fJustCheck)) // Force the check of asset duplicates when connecting the block
return error("%s: Consensus::CheckBlock: %s", __func__, FormatStateMessage(state));

// verify that the view's current state corresponds to the previous block
Expand Down Expand Up @@ -4010,7 +4010,7 @@ static bool CheckBlockHeader(const CBlockHeader& block, CValidationState& state,
return true;
}

bool CheckBlock(const CBlock& block, CValidationState& state, const Consensus::ConsensusParams& consensusParams, bool fCheckPOW, bool fCheckMerkleRoot, bool fCheckAssetDuplicate, bool fForceDuplicateCheck)
bool CheckBlock(const CBlock& block, CValidationState& state, const Consensus::ConsensusParams& consensusParams, int nHeight, bool fCheckPOW, bool fCheckMerkleRoot, bool fCheckAssetDuplicate, bool fForceDuplicateCheck)
{
// These are checks that are independent of context.

Expand Down Expand Up @@ -4052,11 +4052,11 @@ bool CheckBlock(const CBlock& block, CValidationState& state, const Consensus::C
for (unsigned int i = 1; i < block.vtx.size(); i++)
if (block.vtx[i]->IsCoinBase())
return state.DoS(100, false, REJECT_INVALID, "bad-cb-multiple", false, "more than one coinbase");

// Check transactions
bool fCheckBlock = CHECK_BLOCK_TRANSACTION_TRUE;
bool fCheckDuplicates = CHECK_DUPLICATE_TRANSACTION_TRUE;
bool fCheckMempool = CHECK_MEMPOOL_TRANSACTION_FALSE;
CAmount blockReward = GetBlockSubsidy(nHeight - 1, Params().GetConsensus());
for (const auto& tx : block.vtx) {
// We only want to check the blocks when they are added to our chain
// We want to make sure when nodes shutdown and restart that they still
Expand Down Expand Up @@ -4523,7 +4523,7 @@ bool ProcessNewBlock(const CChainParams& chainparams, const std::shared_ptr<cons

// Ensure that CheckBlock() passes before calling AcceptBlock, as
// belt-and-suspenders.
bool ret = CheckBlock(*pblock, state, chainparams.GetConsensus(), true, true);
bool ret = CheckBlock(*pblock, state, chainparams.GetConsensus(), 0, true, true);

LOCK(cs_main);

Expand Down Expand Up @@ -4563,7 +4563,7 @@ bool TestBlockValidity(CValidationState& state, const CChainParams& chainparams,
// NOTE: CheckBlockHeader is called by CheckBlock
if (!ContextualCheckBlockHeader(block, state, chainparams, pindexPrev, GetAdjustedTime()))
return error("%s: Consensus::ContextualCheckBlockHeader: %s", __func__, FormatStateMessage(state));
if (!CheckBlock(block, state, chainparams.GetConsensus(), fCheckPOW, fCheckMerkleRoot))
if (!CheckBlock(block, state, chainparams.GetConsensus(), 0, fCheckPOW, fCheckMerkleRoot))
return error("%s: Consensus::CheckBlock: %s", __func__, FormatStateMessage(state));
if (!ContextualCheckBlock(block, state, chainparams.GetConsensus(), pindexPrev, &assetCache))
return error("%s: Consensus::ContextualCheckBlock: %s", __func__, FormatStateMessage(state));
Expand Down
2 changes: 1 addition & 1 deletion src/validation.h
Original file line number Diff line number Diff line change
Expand Up @@ -464,7 +464,7 @@ bool ReadBlockFromDisk(CBlock& block, const CBlockIndex* pindex, const Consensus
/** Functions for validating blocks and updating the block tree */

/** Context-independent validity checks */
bool CheckBlock(const CBlock& block, CValidationState& state, const Consensus::ConsensusParams& consensusParams, bool fCheckPOW = true, bool fCheckMerkleRoot = true, bool fCheckAssetDuplicate = true, bool fForceDuplicateCheck = true);
bool CheckBlock(const CBlock& block, CValidationState& state, const Consensus::ConsensusParams& consensusParams, int nHeight, bool fCheckPOW = true, bool fCheckMerkleRoot = true, bool fCheckAssetDuplicate = true, bool fForceDuplicateCheck = true);

/** Check a block is completely valid from start to finish (only works on top of our current best block, with cs_main held) */
bool TestBlockValidity(CValidationState& state, const CChainParams& chainparams, const CBlock& block, CBlockIndex* pindexPrev, bool fCheckPOW = true, bool fCheckMerkleRoot = true);
Expand Down

0 comments on commit 0d0f758

Please sign in to comment.