Auto merge of #4782 - oxarbitrage:issue4769, r=str4d

simplify `TestBlockValidity()`

Closes https://github.com/zcash/zcash/issues/4769
This commit is contained in:
Homu 2020-10-14 15:33:42 +00:00
commit 03e68a3ed8
4 changed files with 7 additions and 6 deletions

View File

@ -4398,9 +4398,10 @@ bool ProcessNewBlock(CValidationState& state, const CChainParams& chainparams, c
}
/**
* This is only invoked by the miner. fCheckPOW is always false.
* This is only invoked by the miner.
* The block's proof-of-work is assumed invalid and not checked.
*/
bool TestBlockValidity(CValidationState& state, const CChainParams& chainparams, const CBlock& block, CBlockIndex* pindexPrev, bool fCheckPOW, bool fCheckMerkleRoot)
bool TestBlockValidity(CValidationState& state, const CChainParams& chainparams, const CBlock& block, CBlockIndex* pindexPrev, bool fCheckMerkleRoot)
{
AssertLockHeld(cs_main);
assert(pindexPrev == chainActive.Tip());
@ -4416,7 +4417,7 @@ bool TestBlockValidity(CValidationState& state, const CChainParams& chainparams,
if (!ContextualCheckBlockHeader(block, state, chainparams, pindexPrev))
return false;
// The following may be duplicative of the `CheckBlock` call within `ConnectBlock`
if (!CheckBlock(block, state, chainparams, verifier, fCheckPOW, fCheckMerkleRoot, true))
if (!CheckBlock(block, state, chainparams, verifier, false, fCheckMerkleRoot, true))
return false;
if (!ContextualCheckBlock(block, state, chainparams, pindexPrev, true))
return false;

View File

@ -481,7 +481,7 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin
* 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);
bool TestBlockValidity(CValidationState& state, const CChainParams& chainparams, const CBlock& block, CBlockIndex* pindexPrev, bool fCheckMerkleRoot);
/**

View File

@ -619,7 +619,7 @@ CBlockTemplate* CreateNewBlock(const CChainParams& chainparams, const MinerAddre
pblocktemplate->vTxSigOps[0] = GetLegacySigOpCount(pblock->vtx[0]);
CValidationState state;
if (!TestBlockValidity(state, chainparams, *pblock, pindexPrev, false, false))
if (!TestBlockValidity(state, chainparams, *pblock, pindexPrev, false))
throw std::runtime_error(std::string("CreateNewBlock(): TestBlockValidity failed: ") + state.GetRejectReason());
}

View File

@ -529,7 +529,7 @@ UniValue getblocktemplate(const UniValue& params, bool fHelp)
return "inconclusive-not-best-prevblk";
CValidationState state;
TestBlockValidity(state, Params(), block, pindexPrev, false, true);
TestBlockValidity(state, Params(), block, pindexPrev, true);
return BIP22ValidationResult(state);
}
}