From cba5934eb697aedbe1966ebc2817ab87232a1b59 Mon Sep 17 00:00:00 2001 From: glozow Date: Tue, 13 Dec 2022 15:49:38 +0000 Subject: [PATCH] [miner] allow bypassing TestBlockValidity Allows us to test BlockAssembler on transactions without signatures or mature coinbases (which is what PopulateMempool creates). Also means that `TestBlockValidity()` is not included in the bench timing. --- src/node/miner.cpp | 7 +++++-- src/node/miner.h | 4 ++++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/node/miner.cpp b/src/node/miner.cpp index 6098197cfce..3274fe826a4 100644 --- a/src/node/miner.cpp +++ b/src/node/miner.cpp @@ -60,10 +60,12 @@ BlockAssembler::Options::Options() { blockMinFeeRate = CFeeRate(DEFAULT_BLOCK_MIN_TX_FEE); nBlockMaxWeight = DEFAULT_BLOCK_MAX_WEIGHT; + test_block_validity = true; } BlockAssembler::BlockAssembler(Chainstate& chainstate, const CTxMemPool* mempool, const Options& options) - : chainparams{chainstate.m_chainman.GetParams()}, + : test_block_validity{options.test_block_validity}, + chainparams{chainstate.m_chainman.GetParams()}, m_mempool(mempool), m_chainstate(chainstate) { @@ -174,7 +176,8 @@ std::unique_ptr BlockAssembler::CreateNewBlock(const CScript& sc pblocktemplate->vTxSigOpsCost[0] = WITNESS_SCALE_FACTOR * GetLegacySigOpCount(*pblock->vtx[0]); BlockValidationState state; - if (!TestBlockValidity(state, chainparams, m_chainstate, *pblock, pindexPrev, GetAdjustedTime, false, false)) { + if (test_block_validity && !TestBlockValidity(state, chainparams, m_chainstate, *pblock, pindexPrev, + GetAdjustedTime, /*fCheckPOW=*/false, /*fCheckMerkleRoot=*/false)) { throw std::runtime_error(strprintf("%s: TestBlockValidity failed: %s", __func__, state.ToString())); } const auto time_2{SteadyClock::now()}; diff --git a/src/node/miner.h b/src/node/miner.h index 0ee3b5c828b..c9c37c594c4 100644 --- a/src/node/miner.h +++ b/src/node/miner.h @@ -136,6 +136,9 @@ private: unsigned int nBlockMaxWeight; CFeeRate blockMinFeeRate; + // Whether to call TestBlockValidity() at the end of CreateNewBlock(). + const bool test_block_validity; + // Information on the current status of the block uint64_t nBlockWeight; uint64_t nBlockTx; @@ -156,6 +159,7 @@ public: Options(); size_t nBlockMaxWeight; CFeeRate blockMinFeeRate; + bool test_block_validity; }; explicit BlockAssembler(Chainstate& chainstate, const CTxMemPool* mempool);