From ea4c665dafcab68e89e09af7c8954d1747412db7 Mon Sep 17 00:00:00 2001 From: Alfredo Garcia Date: Mon, 12 Oct 2020 14:25:44 -0300 Subject: [PATCH 1/2] simplify TestBlockValidity --- src/main.cpp | 4 ++-- src/main.h | 2 +- src/miner.cpp | 2 +- src/rpc/mining.cpp | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index d097d8b07..73de799c2 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -4400,7 +4400,7 @@ bool ProcessNewBlock(CValidationState& state, const CChainParams& chainparams, c /** * This is only invoked by the miner. fCheckPOW is always false. */ -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 +4416,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; diff --git a/src/main.h b/src/main.h index 1595a955e..d3b9afea1 100644 --- a/src/main.h +++ b/src/main.h @@ -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); /** diff --git a/src/miner.cpp b/src/miner.cpp index 9721649d3..7c599ed88 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -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()); } diff --git a/src/rpc/mining.cpp b/src/rpc/mining.cpp index 7db227298..5c0801bc6 100644 --- a/src/rpc/mining.cpp +++ b/src/rpc/mining.cpp @@ -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); } } From 52270f60ee6c5c95f7973bc54ad62593956b39c6 Mon Sep 17 00:00:00 2001 From: Alfredo Garcia Date: Wed, 14 Oct 2020 11:08:21 -0300 Subject: [PATCH 2/2] update function comment Co-authored-by: str4d --- src/main.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index 73de799c2..911f34e14 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -4398,7 +4398,8 @@ 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 fCheckMerkleRoot) {