From c8acd4032d5a7617764857b51777c076fd7ef13d Mon Sep 17 00:00:00 2001 From: ismaelsadeeq Date: Thu, 9 Jan 2025 10:50:53 -0500 Subject: [PATCH] init: fail to start when `-blockmaxweight` exceeds `MAX_BLOCK_WEIGHT` --- src/init.cpp | 7 +++++++ test/functional/mining_basic.py | 7 +++++++ 2 files changed, 14 insertions(+) diff --git a/src/init.cpp b/src/init.cpp index 82ad068a1b6..c293ef23acc 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -1016,6 +1016,13 @@ bool AppInitParameterInteraction(const ArgsManager& args) } } + if (args.IsArgSet("-blockmaxweight")) { + const auto max_block_weight = args.GetIntArg("-blockmaxweight", DEFAULT_BLOCK_MAX_WEIGHT); + if (max_block_weight > MAX_BLOCK_WEIGHT) { + return InitError(strprintf(_("Specified -blockmaxweight (%d) exceeds consensus maximum block weight (%d)"), max_block_weight, MAX_BLOCK_WEIGHT)); + } + } + nBytesPerSigOp = args.GetIntArg("-bytespersigop", nBytesPerSigOp); if (!g_wallet_init_interface.ParameterInteraction()) return false; diff --git a/test/functional/mining_basic.py b/test/functional/mining_basic.py index 8e403e0217a..1c3a46e5d19 100755 --- a/test/functional/mining_basic.py +++ b/test/functional/mining_basic.py @@ -276,6 +276,13 @@ class MiningTest(BitcoinTestFramework): expected_weight=MAX_BLOCK_WEIGHT - DEFAULT_BLOCK_RESERVED_WEIGHT, ) + self.log.info("Test that node will fail to start when user provide invalid -blockmaxweight") + self.stop_node(0) + self.nodes[0].assert_start_raises_init_error( + extra_args=[f"-blockmaxweight={MAX_BLOCK_WEIGHT + 1}"], + expected_msg=f"Error: Specified -blockmaxweight ({MAX_BLOCK_WEIGHT + 1}) exceeds consensus maximum block weight ({MAX_BLOCK_WEIGHT})", + ) + def run_test(self): node = self.nodes[0]