Skip to content

Commit a2de971

Browse files
committed
[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().
1 parent 8ccab65 commit a2de971

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

src/node/miner.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,23 +72,27 @@ BlockAssembler::BlockAssembler(Chainstate& chainstate, const CTxMemPool* mempool
7272
nBlockMaxWeight = std::max<size_t>(4000, std::min<size_t>(MAX_BLOCK_WEIGHT - 4000, options.nBlockMaxWeight));
7373
}
7474

75-
static BlockAssembler::Options DefaultOptions()
75+
void ApplyArgsManOptions(const ArgsManager& gArgs, BlockAssembler::Options& options)
7676
{
7777
// Block resource limits
7878
// If -blockmaxweight is not given, limit to DEFAULT_BLOCK_MAX_WEIGHT
79-
BlockAssembler::Options options;
8079
options.nBlockMaxWeight = gArgs.GetIntArg("-blockmaxweight", DEFAULT_BLOCK_MAX_WEIGHT);
8180
if (gArgs.IsArgSet("-blockmintxfee")) {
8281
std::optional<CAmount> parsed = ParseMoney(gArgs.GetArg("-blockmintxfee", ""));
8382
options.blockMinFeeRate = CFeeRate{parsed.value_or(DEFAULT_BLOCK_MIN_TX_FEE)};
8483
} else {
8584
options.blockMinFeeRate = CFeeRate{DEFAULT_BLOCK_MIN_TX_FEE};
8685
}
86+
}
87+
static BlockAssembler::Options ConfiguredOptions()
88+
{
89+
BlockAssembler::Options options;
90+
ApplyArgsManOptions(gArgs, options);
8791
return options;
8892
}
8993

9094
BlockAssembler::BlockAssembler(Chainstate& chainstate, const CTxMemPool* mempool)
91-
: BlockAssembler(chainstate, mempool, DefaultOptions()) {}
95+
: BlockAssembler(chainstate, mempool, ConfiguredOptions()) {}
9296

9397
void BlockAssembler::resetBlock()
9498
{

src/node/miner.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include <boost/multi_index/ordered_index.hpp>
1717
#include <boost/multi_index_container.hpp>
1818

19+
class ArgsManager;
1920
class ChainstateManager;
2021
class CBlockIndex;
2122
class CChainParams;
@@ -197,6 +198,9 @@ int64_t UpdateTime(CBlockHeader* pblock, const Consensus::Params& consensusParam
197198

198199
/** Update an old GenerateCoinbaseCommitment from CreateNewBlock after the block txs have changed */
199200
void RegenerateCommitments(CBlock& block, ChainstateManager& chainman);
201+
202+
/** Apply -blockmintxfee and -blockmaxweight options from ArgsManager to BlockAssembler options. */
203+
void ApplyArgsManOptions(const ArgsManager& gArgs, BlockAssembler::Options& options);
200204
} // namespace node
201205

202206
#endif // BITCOIN_NODE_MINER_H

0 commit comments

Comments
 (0)