From a2de971ba1c588488dde653a76853666429d4911 Mon Sep 17 00:00:00 2001 From: glozow Date: Thu, 15 Dec 2022 15:07:41 +0000 Subject: [PATCH] [refactor] add helper to apply ArgsManager to BlockAssembler::Options This allows us to both manually manipulate options and grab values from ArgsManager (i.e. -blockmaxweight and -blockmintxfee config options) when constructing BlockAssembler::Options. Prior to this change, the only way to apply the config options is by ctoring BlockAssembler with no options, which calls DefaultOptions(). --- src/node/miner.cpp | 10 +++++++--- src/node/miner.h | 4 ++++ 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/node/miner.cpp b/src/node/miner.cpp index e11ec5b0f1f..6098197cfce 100644 --- a/src/node/miner.cpp +++ b/src/node/miner.cpp @@ -72,11 +72,10 @@ BlockAssembler::BlockAssembler(Chainstate& chainstate, const CTxMemPool* mempool nBlockMaxWeight = std::max(4000, std::min(MAX_BLOCK_WEIGHT - 4000, options.nBlockMaxWeight)); } -static BlockAssembler::Options DefaultOptions() +void ApplyArgsManOptions(const ArgsManager& gArgs, BlockAssembler::Options& options) { // Block resource limits // If -blockmaxweight is not given, limit to DEFAULT_BLOCK_MAX_WEIGHT - BlockAssembler::Options options; options.nBlockMaxWeight = gArgs.GetIntArg("-blockmaxweight", DEFAULT_BLOCK_MAX_WEIGHT); if (gArgs.IsArgSet("-blockmintxfee")) { std::optional parsed = ParseMoney(gArgs.GetArg("-blockmintxfee", "")); @@ -84,11 +83,16 @@ static BlockAssembler::Options DefaultOptions() } else { options.blockMinFeeRate = CFeeRate{DEFAULT_BLOCK_MIN_TX_FEE}; } +} +static BlockAssembler::Options ConfiguredOptions() +{ + BlockAssembler::Options options; + ApplyArgsManOptions(gArgs, options); return options; } BlockAssembler::BlockAssembler(Chainstate& chainstate, const CTxMemPool* mempool) - : BlockAssembler(chainstate, mempool, DefaultOptions()) {} + : BlockAssembler(chainstate, mempool, ConfiguredOptions()) {} void BlockAssembler::resetBlock() { diff --git a/src/node/miner.h b/src/node/miner.h index 7269ce11867..0ee3b5c828b 100644 --- a/src/node/miner.h +++ b/src/node/miner.h @@ -16,6 +16,7 @@ #include #include +class ArgsManager; class ChainstateManager; class CBlockIndex; class CChainParams; @@ -197,6 +198,9 @@ int64_t UpdateTime(CBlockHeader* pblock, const Consensus::Params& consensusParam /** Update an old GenerateCoinbaseCommitment from CreateNewBlock after the block txs have changed */ void RegenerateCommitments(CBlock& block, ChainstateManager& chainman); + +/** Apply -blockmintxfee and -blockmaxweight options from ArgsManager to BlockAssembler options. */ +void ApplyArgsManOptions(const ArgsManager& gArgs, BlockAssembler::Options& options); } // namespace node #endif // BITCOIN_NODE_MINER_H