@@ -56,22 +56,19 @@ void RegenerateCommitments(CBlock& block, ChainstateManager& chainman)
56
56
block.hashMerkleRoot = BlockMerkleRoot (block);
57
57
}
58
58
59
- BlockAssembler::Options::Options ( )
59
+ static BlockAssembler::Options ClampOptions (BlockAssembler ::Options options )
60
60
{
61
- blockMinFeeRate = CFeeRate (DEFAULT_BLOCK_MIN_TX_FEE);
62
- nBlockMaxWeight = DEFAULT_BLOCK_MAX_WEIGHT;
63
- test_block_validity = true ;
61
+ // Limit weight to between 4K and DEFAULT_BLOCK_MAX_WEIGHT for sanity:
62
+ options. nBlockMaxWeight = std::clamp< size_t >(options. nBlockMaxWeight , 4000 , DEFAULT_BLOCK_MAX_WEIGHT) ;
63
+ return options ;
64
64
}
65
65
66
66
BlockAssembler::BlockAssembler (Chainstate& chainstate, const CTxMemPool* mempool, const Options& options)
67
- : test_block_validity{options. test_block_validity },
68
- chainparams{chainstate. m_chainman . GetParams () },
69
- m_mempool (mempool) ,
70
- m_chainstate (chainstate)
67
+ : chainparams{chainstate. m_chainman . GetParams () },
68
+ m_mempool{mempool },
69
+ m_chainstate{chainstate} ,
70
+ m_options{ ClampOptions (options)}
71
71
{
72
- blockMinFeeRate = options.blockMinFeeRate ;
73
- // Limit weight to between 4K and MAX_BLOCK_WEIGHT-4K for sanity:
74
- nBlockMaxWeight = std::max<size_t >(4000 , std::min<size_t >(MAX_BLOCK_WEIGHT - 4000 , options.nBlockMaxWeight ));
75
72
}
76
73
77
74
void ApplyArgsManOptions (const ArgsManager& args, BlockAssembler::Options& options)
@@ -176,7 +173,7 @@ std::unique_ptr<CBlockTemplate> BlockAssembler::CreateNewBlock(const CScript& sc
176
173
pblocktemplate->vTxSigOpsCost [0 ] = WITNESS_SCALE_FACTOR * GetLegacySigOpCount (*pblock->vtx [0 ]);
177
174
178
175
BlockValidationState state;
179
- if (test_block_validity && !TestBlockValidity (state, chainparams, m_chainstate, *pblock, pindexPrev,
176
+ if (m_options. test_block_validity && !TestBlockValidity (state, chainparams, m_chainstate, *pblock, pindexPrev,
180
177
GetAdjustedTime, /* fCheckPOW=*/ false , /* fCheckMerkleRoot=*/ false )) {
181
178
throw std::runtime_error (strprintf (" %s: TestBlockValidity failed: %s" , __func__, state.ToString ()));
182
179
}
@@ -205,7 +202,7 @@ void BlockAssembler::onlyUnconfirmed(CTxMemPool::setEntries& testSet)
205
202
bool BlockAssembler::TestPackage (uint64_t packageSize, int64_t packageSigOpsCost) const
206
203
{
207
204
// TODO: switch to weight-based accounting for packages instead of vsize-based accounting.
208
- if (nBlockWeight + WITNESS_SCALE_FACTOR * packageSize >= nBlockMaxWeight) {
205
+ if (nBlockWeight + WITNESS_SCALE_FACTOR * packageSize >= m_options. nBlockMaxWeight ) {
209
206
return false ;
210
207
}
211
208
if (nBlockSigOpsCost + packageSigOpsCost >= MAX_BLOCK_SIGOPS_COST) {
@@ -377,7 +374,7 @@ void BlockAssembler::addPackageTxs(const CTxMemPool& mempool, int& nPackagesSele
377
374
packageSigOpsCost = modit->nSigOpCostWithAncestors ;
378
375
}
379
376
380
- if (packageFees < blockMinFeeRate.GetFee (packageSize)) {
377
+ if (packageFees < m_options. blockMinFeeRate .GetFee (packageSize)) {
381
378
// Everything else we might consider has a lower fee rate
382
379
return ;
383
380
}
@@ -394,7 +391,7 @@ void BlockAssembler::addPackageTxs(const CTxMemPool& mempool, int& nPackagesSele
394
391
++nConsecutiveFailed;
395
392
396
393
if (nConsecutiveFailed > MAX_CONSECUTIVE_FAILURES && nBlockWeight >
397
- nBlockMaxWeight - 4000 ) {
394
+ m_options. nBlockMaxWeight - 4000 ) {
398
395
// Give up if we're close to full and haven't succeeded in a while
399
396
break ;
400
397
}
0 commit comments