diff --git a/src/init.cpp b/src/init.cpp index 5e48b1f1da..0deffd54f1 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -650,6 +650,7 @@ void SetupServerArgs(ArgsManager& argsman, bool can_listen_ipc) argsman.AddArg("-blockmaxweight=", strprintf("Set maximum BIP141 block weight (default: %d).", MAX_BLOCK_WEIGHT), ArgsManager::ALLOW_ANY, OptionsCategory::BLOCK_CREATION); + argsman.AddArg("-maxcoinbaseweight=", strprintf("Set the block maximum reserved coinbase transaction weight (default: %d).", node::BlockCreateOptions{}.coinbase_max_additional_weight), ArgsManager::ALLOW_ANY, OptionsCategory::BLOCK_CREATION); argsman.AddArg("-blockmintxfee=", strprintf("Set lowest fee rate (in %s/kvB) for transactions to be included in block creation. (default: %s)", CURRENCY_UNIT, FormatMoney(DEFAULT_BLOCK_MIN_TX_FEE)), ArgsManager::ALLOW_ANY, OptionsCategory::BLOCK_CREATION); argsman.AddArg("-blockversion=", "Override block version to test forking scenarios", ArgsManager::ALLOW_ANY | ArgsManager::DEBUG_ONLY, OptionsCategory::BLOCK_CREATION); @@ -1024,6 +1025,13 @@ bool AppInitParameterInteraction(const ArgsManager& args) } } + if (args.IsArgSet("-maxcoinbaseweight")) { + const auto max_coinbase_weight = args.GetIntArg("-maxcoinbaseweight", node::BlockCreateOptions{}.coinbase_max_additional_weight); + if (max_coinbase_weight > MAX_BLOCK_WEIGHT) { + return InitError(strprintf(_("Specified -maxcoinbaseweight (%d) exceeds consensus maximum block weight (%d)"), max_coinbase_weight, MAX_BLOCK_WEIGHT)); + } + } + nBytesPerSigOp = args.GetIntArg("-bytespersigop", nBytesPerSigOp); if (!g_wallet_init_interface.ParameterInteraction()) return false; diff --git a/src/node/miner.cpp b/src/node/miner.cpp index 37dfd07d9a..667d1fd945 100644 --- a/src/node/miner.cpp +++ b/src/node/miner.cpp @@ -90,7 +90,9 @@ void ApplyArgsManOptions(const ArgsManager& args, BlockAssembler::Options& optio if (const auto blockmintxfee{args.GetArg("-blockmintxfee")}) { if (const auto parsed{ParseMoney(*blockmintxfee)}) options.blockMinFeeRate = CFeeRate{*parsed}; } + options.print_modified_fee = args.GetBoolArg("-printpriority", options.print_modified_fee); + options.coinbase_max_additional_weight = args.GetIntArg("-maxcoinbaseweight", options.coinbase_max_additional_weight); } void BlockAssembler::resetBlock() diff --git a/test/functional/mining_basic.py b/test/functional/mining_basic.py index f160b6e180..60c7cd791e 100755 --- a/test/functional/mining_basic.py +++ b/test/functional/mining_basic.py @@ -272,6 +272,21 @@ class MiningTest(BitcoinTestFramework): expected_weight=MAX_BLOCK_WEIGHT - DEFAULT_COINBASE_TX_WEIGHT, ) + self.log.info("Test -maxcoinbaseweight startup option.") + # Lowering the -maxcoinbaseweight by 4000 will allow for two more transactions. + self.restart_node(0, extra_args=[f"-datacarriersize={LARGE_VSIZE}", "-maxcoinbaseweight=4000"]) + self.verify_block_template( + expected_tx_count=12, + expected_weight=MAX_BLOCK_WEIGHT - 4000, + ) + + self.log.info("Test that node will fail to start when user provide consensus invalid -maxcoinbaseweight") + self.stop_node(0) + self.nodes[0].assert_start_raises_init_error( + extra_args=[f"-maxcoinbaseweight={MAX_BLOCK_WEIGHT + 1}"], + expected_msg=f"Error: Specified -maxcoinbaseweight ({MAX_BLOCK_WEIGHT + 1}) exceeds consensus maximum block weight ({MAX_BLOCK_WEIGHT})", + ) + self.log.info("Test that node will fail to start when user provide consensus invalid -blockmaxweight") self.stop_node(0) self.nodes[0].assert_start_raises_init_error(