[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.
This commit is contained in:
glozow 2022-12-13 15:49:38 +00:00
parent c058852308
commit cba5934eb6
No known key found for this signature in database
GPG Key ID: BA03F4DBE0C63FB4
2 changed files with 9 additions and 2 deletions

View File

@ -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<CBlockTemplate> 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()};

View File

@ -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);