mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-11-11 14:38:29 +01:00
refactor: avoid duplicating BlockAssembler::Options members
Add Options as a member to BlockAssembler to avoid having to assign all the options individually. Additionally brings the struct more in line with how we typically define default and ArgManager values, as e.g. with ChainstateManager::Options and and CTxMemPool::Options
This commit is contained in:
@@ -56,22 +56,19 @@ void RegenerateCommitments(CBlock& block, ChainstateManager& chainman)
|
||||
block.hashMerkleRoot = BlockMerkleRoot(block);
|
||||
}
|
||||
|
||||
BlockAssembler::Options::Options()
|
||||
static BlockAssembler::Options ClampOptions(BlockAssembler::Options options)
|
||||
{
|
||||
blockMinFeeRate = CFeeRate(DEFAULT_BLOCK_MIN_TX_FEE);
|
||||
nBlockMaxWeight = DEFAULT_BLOCK_MAX_WEIGHT;
|
||||
test_block_validity = true;
|
||||
// Limit weight to between 4K and DEFAULT_BLOCK_MAX_WEIGHT for sanity:
|
||||
options.nBlockMaxWeight = std::clamp<size_t>(options.nBlockMaxWeight, 4000, DEFAULT_BLOCK_MAX_WEIGHT);
|
||||
return options;
|
||||
}
|
||||
|
||||
BlockAssembler::BlockAssembler(Chainstate& chainstate, const CTxMemPool* mempool, const Options& options)
|
||||
: test_block_validity{options.test_block_validity},
|
||||
chainparams{chainstate.m_chainman.GetParams()},
|
||||
m_mempool(mempool),
|
||||
m_chainstate(chainstate)
|
||||
: chainparams{chainstate.m_chainman.GetParams()},
|
||||
m_mempool{mempool},
|
||||
m_chainstate{chainstate},
|
||||
m_options{ClampOptions(options)}
|
||||
{
|
||||
blockMinFeeRate = options.blockMinFeeRate;
|
||||
// Limit weight to between 4K and MAX_BLOCK_WEIGHT-4K for sanity:
|
||||
nBlockMaxWeight = std::max<size_t>(4000, std::min<size_t>(MAX_BLOCK_WEIGHT - 4000, options.nBlockMaxWeight));
|
||||
}
|
||||
|
||||
void ApplyArgsManOptions(const ArgsManager& args, BlockAssembler::Options& options)
|
||||
@@ -176,7 +173,7 @@ std::unique_ptr<CBlockTemplate> BlockAssembler::CreateNewBlock(const CScript& sc
|
||||
pblocktemplate->vTxSigOpsCost[0] = WITNESS_SCALE_FACTOR * GetLegacySigOpCount(*pblock->vtx[0]);
|
||||
|
||||
BlockValidationState state;
|
||||
if (test_block_validity && !TestBlockValidity(state, chainparams, m_chainstate, *pblock, pindexPrev,
|
||||
if (m_options.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()));
|
||||
}
|
||||
@@ -205,7 +202,7 @@ void BlockAssembler::onlyUnconfirmed(CTxMemPool::setEntries& testSet)
|
||||
bool BlockAssembler::TestPackage(uint64_t packageSize, int64_t packageSigOpsCost) const
|
||||
{
|
||||
// TODO: switch to weight-based accounting for packages instead of vsize-based accounting.
|
||||
if (nBlockWeight + WITNESS_SCALE_FACTOR * packageSize >= nBlockMaxWeight) {
|
||||
if (nBlockWeight + WITNESS_SCALE_FACTOR * packageSize >= m_options.nBlockMaxWeight) {
|
||||
return false;
|
||||
}
|
||||
if (nBlockSigOpsCost + packageSigOpsCost >= MAX_BLOCK_SIGOPS_COST) {
|
||||
@@ -377,7 +374,7 @@ void BlockAssembler::addPackageTxs(const CTxMemPool& mempool, int& nPackagesSele
|
||||
packageSigOpsCost = modit->nSigOpCostWithAncestors;
|
||||
}
|
||||
|
||||
if (packageFees < blockMinFeeRate.GetFee(packageSize)) {
|
||||
if (packageFees < m_options.blockMinFeeRate.GetFee(packageSize)) {
|
||||
// Everything else we might consider has a lower fee rate
|
||||
return;
|
||||
}
|
||||
@@ -394,7 +391,7 @@ void BlockAssembler::addPackageTxs(const CTxMemPool& mempool, int& nPackagesSele
|
||||
++nConsecutiveFailed;
|
||||
|
||||
if (nConsecutiveFailed > MAX_CONSECUTIVE_FAILURES && nBlockWeight >
|
||||
nBlockMaxWeight - 4000) {
|
||||
m_options.nBlockMaxWeight - 4000) {
|
||||
// Give up if we're close to full and haven't succeeded in a while
|
||||
break;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user