Skip to content

Commit cba5934

Browse files
committed
[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.
1 parent c058852 commit cba5934

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

src/node/miner.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,12 @@ BlockAssembler::Options::Options()
6060
{
6161
blockMinFeeRate = CFeeRate(DEFAULT_BLOCK_MIN_TX_FEE);
6262
nBlockMaxWeight = DEFAULT_BLOCK_MAX_WEIGHT;
63+
test_block_validity = true;
6364
}
6465

6566
BlockAssembler::BlockAssembler(Chainstate& chainstate, const CTxMemPool* mempool, const Options& options)
66-
: chainparams{chainstate.m_chainman.GetParams()},
67+
: test_block_validity{options.test_block_validity},
68+
chainparams{chainstate.m_chainman.GetParams()},
6769
m_mempool(mempool),
6870
m_chainstate(chainstate)
6971
{
@@ -174,7 +176,8 @@ std::unique_ptr<CBlockTemplate> BlockAssembler::CreateNewBlock(const CScript& sc
174176
pblocktemplate->vTxSigOpsCost[0] = WITNESS_SCALE_FACTOR * GetLegacySigOpCount(*pblock->vtx[0]);
175177

176178
BlockValidationState state;
177-
if (!TestBlockValidity(state, chainparams, m_chainstate, *pblock, pindexPrev, GetAdjustedTime, false, false)) {
179+
if (test_block_validity && !TestBlockValidity(state, chainparams, m_chainstate, *pblock, pindexPrev,
180+
GetAdjustedTime, /*fCheckPOW=*/false, /*fCheckMerkleRoot=*/false)) {
178181
throw std::runtime_error(strprintf("%s: TestBlockValidity failed: %s", __func__, state.ToString()));
179182
}
180183
const auto time_2{SteadyClock::now()};

src/node/miner.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,9 @@ class BlockAssembler
136136
unsigned int nBlockMaxWeight;
137137
CFeeRate blockMinFeeRate;
138138

139+
// Whether to call TestBlockValidity() at the end of CreateNewBlock().
140+
const bool test_block_validity;
141+
139142
// Information on the current status of the block
140143
uint64_t nBlockWeight;
141144
uint64_t nBlockTx;
@@ -156,6 +159,7 @@ class BlockAssembler
156159
Options();
157160
size_t nBlockMaxWeight;
158161
CFeeRate blockMinFeeRate;
162+
bool test_block_validity;
159163
};
160164

161165
explicit BlockAssembler(Chainstate& chainstate, const CTxMemPool* mempool);

0 commit comments

Comments
 (0)