diff --git a/src/test/blockencodings_tests.cpp b/src/test/blockencodings_tests.cpp index 27e4fced40..24eaf1477f 100644 --- a/src/test/blockencodings_tests.cpp +++ b/src/test/blockencodings_tests.cpp @@ -102,7 +102,6 @@ BOOST_AUTO_TEST_CASE(SimpleRoundTripTest) CBlock block(BuildBlockTestCase()); LOCK2(cs_main, pool.cs); - block.hashPrevBlock = ::ChainActive().Tip()->GetBlockHash(); pool.addUnchecked(entry.FromTx(block.vtx[2])); BOOST_CHECK_EQUAL(pool.mapTx.find(block.vtx[2]->GetHash())->GetSharedTx().use_count(), SHARED_TX_OFFSET + 0); @@ -145,7 +144,6 @@ BOOST_AUTO_TEST_CASE(SimpleRoundTripTest) BOOST_CHECK(block.hashMerkleRoot != BlockMerkleRoot(block2, &mutated)); CBlock block3; - block3.hashPrevBlock = ::ChainActive().Tip()->GetBlockHash(); BOOST_CHECK(partialBlock.FillBlock(block3, {block.vtx[1]}) == READ_STATUS_OK); BOOST_CHECK_EQUAL(block.GetHash().ToString(), block3.GetHash().ToString()); BOOST_CHECK_EQUAL(block.hashMerkleRoot.ToString(), BlockMerkleRoot(block3, &mutated).ToString()); @@ -274,7 +272,6 @@ BOOST_AUTO_TEST_CASE(SufficientPreforwardRTTest) CBlock block(BuildBlockTestCase()); LOCK2(cs_main, pool.cs); - block.hashPrevBlock = ::ChainActive().Tip()->GetBlockHash(); pool.addUnchecked(entry.FromTx(block.vtx[1])); BOOST_CHECK_EQUAL(pool.mapTx.find(block.vtx[1]->GetHash())->GetSharedTx().use_count(), SHARED_TX_OFFSET + 0); @@ -304,7 +301,6 @@ BOOST_AUTO_TEST_CASE(SufficientPreforwardRTTest) BOOST_CHECK_EQUAL(pool.mapTx.find(block.vtx[1]->GetHash())->GetSharedTx().use_count(), SHARED_TX_OFFSET + 1); CBlock block2; - block2.hashPrevBlock = ::ChainActive().Tip()->GetBlockHash(); PartiallyDownloadedBlock partialBlockCopy = partialBlock; BOOST_CHECK(partialBlock.FillBlock(block2, {}) == READ_STATUS_OK); BOOST_CHECK_EQUAL(block.GetHash().ToString(), block2.GetHash().ToString()); diff --git a/src/validation.cpp b/src/validation.cpp index 2649cc2acd..e04428aedf 100644 --- a/src/validation.cpp +++ b/src/validation.cpp @@ -4526,24 +4526,15 @@ bool CheckBlock(const CBlock& block, CValidationState& state, const Consensus::P if (block.fChecked) return true; - // Create block copy with height based on hashPrevBlock - auto newBlock = block; - const auto pindexPrev = LookupBlockIndex(block.hashPrevBlock); - if (!pindexPrev && block.GetHash() != consensusParams.hashGenesisBlock) { - return state.Invalid(ValidationInvalidReason::BLOCK_MISSING_PREV, error("%s: prev block not found", __func__), 0, "prev-blk-not-found"); - } - const int height = pindexPrev ? pindexPrev->nHeight + 1 : 0; - newBlock.height = height; - // Check that the header is valid (particularly PoW). This is mostly // redundant with the call in AcceptBlockHeader. - if (!fIsFakeNet && fCheckPOS && !pos::ContextualCheckProofOfStake(newBlock, consensusParams, pcustomcsview.get(), ctxState)) + if (!fIsFakeNet && fCheckPOS && !pos::ContextualCheckProofOfStake(block, consensusParams, pcustomcsview.get(), ctxState)) return state.Invalid(ValidationInvalidReason::BLOCK_INVALID_HEADER, false, REJECT_INVALID, "high-hash", "proof of stake failed"); // Check the merkle root. // block merkle root is delayed to ConnectBlock to ensure account changes - if (fCheckMerkleRoot && (height < consensusParams.EunosHeight - || height >= consensusParams.EunosKampungHeight)) { + if (fCheckMerkleRoot && (block.height < consensusParams.EunosHeight + || block.height >= consensusParams.EunosKampungHeight)) { bool mutated; uint256 hashMerkleRoot2 = BlockMerkleRoot(block, &mutated); if (block.hashMerkleRoot != hashMerkleRoot2) @@ -4575,8 +4566,8 @@ bool CheckBlock(const CBlock& block, CValidationState& state, const Consensus::P TBytes dummy; for (unsigned int i = 1; i < block.vtx.size(); i++) { if (block.vtx[i]->IsCoinBase() && - !IsAnchorRewardTx(*block.vtx[i], dummy, height >= consensusParams.FortCanningHeight) && - !IsAnchorRewardTxPlus(*block.vtx[i], dummy, height >= consensusParams.FortCanningHeight)) + !IsAnchorRewardTx(*block.vtx[i], dummy, block.height >= consensusParams.FortCanningHeight) && + !IsAnchorRewardTxPlus(*block.vtx[i], dummy, block.height >= consensusParams.FortCanningHeight)) return state.Invalid(ValidationInvalidReason::CONSENSUS, false, REJECT_INVALID, "bad-cb-multiple", "more than one coinbase"); } } @@ -4590,7 +4581,7 @@ bool CheckBlock(const CBlock& block, CValidationState& state, const Consensus::P strprintf("Transaction check failed (tx hash %s) %s", tx->GetHash().ToString(), state.GetDebugMessage())); } - if (!fIsFakeNet && fCheckPOS && height >= consensusParams.FortCanningHeight) { + if (!fIsFakeNet && fCheckPOS && block.height >= consensusParams.FortCanningHeight) { CKeyID minter; // this is safe cause pos::ContextualCheckProofOfStake checked block.ExtractMinterKey(minter); @@ -4715,7 +4706,7 @@ static bool ContextualCheckBlockHeader(const CBlockHeader& block, CValidationSta return state.Invalid(ValidationInvalidReason::BLOCK_INVALID_HEADER, false, REJECT_INVALID, "time-too-old", strprintf("block's timestamp is too early. Block time: %d Min time: %d", block.GetBlockTime(), pindexPrev->GetMedianTimePast())); // Check timestamp - if (Params().NetworkIDString() != CBaseChainParams::REGTEST && nHeight >= static_cast(consensusParams.EunosPayaHeight)) { + if (Params().NetworkIDString() != CBaseChainParams::REGTEST && block.height >= static_cast(consensusParams.EunosPayaHeight)) { if (block.GetBlockTime() > GetTime() + MAX_FUTURE_BLOCK_TIME_EUNOSPAYA) return state.Invalid(ValidationInvalidReason::BLOCK_TIME_FUTURE, false, REJECT_INVALID, "time-too-new", strprintf("block timestamp too far in the future. Block time: %d Max time: %d", block.GetBlockTime(), GetTime() + MAX_FUTURE_BLOCK_TIME_EUNOSPAYA)); } @@ -4723,7 +4714,7 @@ static bool ContextualCheckBlockHeader(const CBlockHeader& block, CValidationSta if (block.GetBlockTime() > nAdjustedTime + MAX_FUTURE_BLOCK_TIME) return state.Invalid(ValidationInvalidReason::BLOCK_TIME_FUTURE, false, REJECT_INVALID, "time-too-new", "block timestamp too far in the future"); - if (nHeight >= static_cast(consensusParams.DakotaCrescentHeight)) { + if (block.height >= static_cast(consensusParams.DakotaCrescentHeight)) { if (block.GetBlockTime() > GetTime() + MAX_FUTURE_BLOCK_TIME_DAKOTACRESCENT) return state.Invalid(ValidationInvalidReason::BLOCK_TIME_FUTURE, false, REJECT_INVALID, "time-too-new", strprintf("block timestamp too far in the future. Block time: %d Max time: %d", block.GetBlockTime(), GetTime() + MAX_FUTURE_BLOCK_TIME_DAKOTACRESCENT)); }