Skip hashBlockCommitments check when testing block templates
Both hashMerkleRoot and hashAuthDataRoot are not set by the block template, and hashAuthDataRoot is an input to hashBlockCommitments.
This commit is contained in:
parent
2d0a8f1f3a
commit
d7a517465b
27
src/main.cpp
27
src/main.cpp
|
@ -2732,7 +2732,8 @@ static bool ShouldCheckTransactions(const CChainParams& chainparams, const CBloc
|
|||
}
|
||||
|
||||
bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pindex,
|
||||
CCoinsViewCache& view, const CChainParams& chainparams, bool fJustCheck)
|
||||
CCoinsViewCache& view, const CChainParams& chainparams,
|
||||
bool fJustCheck, bool fCheckAuthDataRoot)
|
||||
{
|
||||
AssertLockHeld(cs_main);
|
||||
|
||||
|
@ -3035,16 +3036,18 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin
|
|||
blockundo.old_sprout_tree_root = old_sprout_tree_root;
|
||||
|
||||
if (chainparams.GetConsensus().NetworkUpgradeActive(pindex->nHeight, Consensus::UPGRADE_NU5)) {
|
||||
// If NU5 is active, block.hashBlockCommitments must be the top digest
|
||||
// of the ZIP 244 block commitments linked list.
|
||||
// https://zips.z.cash/zip-0244#block-header-changes
|
||||
uint256 hashBlockCommitments = DeriveBlockCommitmentsHash(
|
||||
hashChainHistoryRoot,
|
||||
hashAuthDataRoot);
|
||||
if (block.hashBlockCommitments != hashBlockCommitments) {
|
||||
return state.DoS(100,
|
||||
error("ConnectBlock(): block's hashBlockCommitments is incorrect (should be ZIP 244 block commitment)"),
|
||||
REJECT_INVALID, "bad-block-commitments-hash");
|
||||
if (fCheckAuthDataRoot) {
|
||||
// If NU5 is active, block.hashBlockCommitments must be the top digest
|
||||
// of the ZIP 244 block commitments linked list.
|
||||
// https://zips.z.cash/zip-0244#block-header-changes
|
||||
uint256 hashBlockCommitments = DeriveBlockCommitmentsHash(
|
||||
hashChainHistoryRoot,
|
||||
hashAuthDataRoot);
|
||||
if (block.hashBlockCommitments != hashBlockCommitments) {
|
||||
return state.DoS(100,
|
||||
error("ConnectBlock(): block's hashBlockCommitments is incorrect (should be ZIP 244 block commitment)"),
|
||||
REJECT_INVALID, "bad-block-commitments-hash");
|
||||
}
|
||||
}
|
||||
} else if (IsActivationHeight(pindex->nHeight, chainparams.GetConsensus(), Consensus::UPGRADE_HEARTWOOD)) {
|
||||
// In the block that activates ZIP 221, block.hashBlockCommitments MUST
|
||||
|
@ -4604,7 +4607,7 @@ bool TestBlockValidity(CValidationState& state, const CChainParams& chainparams,
|
|||
return false;
|
||||
if (!ContextualCheckBlock(block, state, chainparams, pindexPrev, true))
|
||||
return false;
|
||||
if (!ConnectBlock(block, state, &indexDummy, viewNew, chainparams, true))
|
||||
if (!ConnectBlock(block, state, &indexDummy, viewNew, chainparams, true, fCheckMerkleRoot))
|
||||
return false;
|
||||
assert(state.IsValid());
|
||||
|
||||
|
|
|
@ -486,7 +486,8 @@ bool ContextualCheckBlock(const CBlock& block, CValidationState& state,
|
|||
* Validity checks that depend on the UTXO set are also done; ConnectBlock()
|
||||
* can fail if those validity checks fail (among other reasons). */
|
||||
bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pindex, CCoinsViewCache& coins,
|
||||
const CChainParams& chainparams, bool fJustCheck = false);
|
||||
const CChainParams& chainparams,
|
||||
bool fJustCheck = false, bool fCheckAuthDataRoot = true);
|
||||
|
||||
/**
|
||||
* Check a block is completely valid from start to finish (only works on top
|
||||
|
|
Loading…
Reference in New Issue