From 978e7216e62cd1493c1d3fc6e290546a8bb99ebd Mon Sep 17 00:00:00 2001 From: Sjors Provoost Date: Thu, 28 May 2026 11:37:13 +0200 Subject: [PATCH 1/5] test: use shared default_ipc_timeout This commit does not change behavior. Suggested in https://github.com/bitcoin/bitcoin/pull/33966#discussion_r3303357712 --- test/functional/interface_ipc_mining.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/test/functional/interface_ipc_mining.py b/test/functional/interface_ipc_mining.py index 4cd9c17c99f..5d081a8dbc8 100755 --- a/test/functional/interface_ipc_mining.py +++ b/test/functional/interface_ipc_mining.py @@ -131,7 +131,6 @@ class IPCMiningTest(BitcoinTestFramework): """Test Mining interface methods.""" self.log.info("Running Mining interface test") block_hash_size = 32 - timeout = 1000.0 * self.options.timeout_factor # 1000 milliseconds async def async_routine(): ctx, mining = await make_mining_ctx(self) @@ -141,19 +140,19 @@ class IPCMiningTest(BitcoinTestFramework): self.log.debug("Mine a block") newblockref = (await wait_and_do( - mining.waitTipChanged(ctx, blockref.result.hash, timeout), + mining.waitTipChanged(ctx, blockref.result.hash, self.default_ipc_timeout), lambda: self.generate(self.nodes[0], 1))).result assert_equal(len(newblockref.hash), block_hash_size) assert_equal(newblockref.height, current_block_height + 1) self.log.debug("Wait for timeout") - oldblockref = (await mining.waitTipChanged(ctx, newblockref.hash, timeout)).result + oldblockref = (await mining.waitTipChanged(ctx, newblockref.hash, self.default_ipc_timeout)).result assert_equal(len(newblockref.hash), block_hash_size) assert_equal(oldblockref.hash, newblockref.hash) assert_equal(oldblockref.height, newblockref.height) self.log.debug("interrupt() should abort waitTipChanged()") async def wait_for_tip(): - long_timeout = max(timeout, 60000.0) # at least 1 minute + long_timeout = max(self.default_ipc_timeout, 60000.0) # at least 1 minute result = (await mining.waitTipChanged(ctx, newblockref.hash, long_timeout)).result # Unlike a timeout, interrupt() returns an empty BlockRef. assert_equal(len(result.hash), 0) @@ -197,7 +196,6 @@ class IPCMiningTest(BitcoinTestFramework): """Test BlockTemplate interface methods.""" self.log.info("Running BlockTemplate interface test") block_header_size = 80 - timeout = 1000.0 * self.options.timeout_factor async def async_routine(): ctx, mining = await make_mining_ctx(self) @@ -266,7 +264,7 @@ class IPCMiningTest(BitcoinTestFramework): self.log.debug("Wait for a new template") waitoptions = self.capnp_modules['mining'].BlockWaitOptions() - waitoptions.timeout = timeout + waitoptions.timeout = self.default_ipc_timeout waitoptions.feeThreshold = 1 template2 = await wait_and_do( mining_wait_next_template(template, stack, ctx, waitoptions), @@ -310,7 +308,7 @@ class IPCMiningTest(BitcoinTestFramework): self.log.debug("interruptWait should abort the current wait") async def wait_for_block(): new_waitoptions = self.capnp_modules['mining'].BlockWaitOptions() - new_waitoptions.timeout = max(timeout, 60000.0) # at least 1 minute + new_waitoptions.timeout = max(self.default_ipc_timeout, 60000.0) # at least 1 minute new_waitoptions.feeThreshold = 1 template7 = await mining_wait_next_template(template6, stack, ctx, new_waitoptions) assert template7 is None @@ -702,9 +700,11 @@ class IPCMiningTest(BitcoinTestFramework): def run_test(self): self.miniwallet = MiniWallet(self.nodes[0]) + # Amount of time in milliseconds the test is allowed to wait or be idle before it should fail. + self.default_ipc_timeout = 1000.0 * self.options.timeout_factor self.default_block_create_options = self.capnp_modules['mining'].BlockCreateOptions() self.default_block_wait_options = self.capnp_modules['mining'].BlockWaitOptions() - self.default_block_wait_options.timeout = 1000.0 * self.options.timeout_factor + self.default_block_wait_options.timeout = self.default_ipc_timeout self.default_block_wait_options.feeThreshold = 1 self.run_mining_interface_test() self.run_early_startup_test() From 65bd3164fbb00afd7759626b8c2bf4df9643ee25 Mon Sep 17 00:00:00 2001 From: Sjors Provoost Date: Thu, 28 May 2026 11:37:19 +0200 Subject: [PATCH 2/5] mining: clarify test_block_validity comment The option defaults to true, so describe the intended exceptional use case as disabling validation for tests and benchmarks. Suggested in https://github.com/bitcoin/bitcoin/pull/33966#discussion_r3303387586 --- src/node/mining_types.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/node/mining_types.h b/src/node/mining_types.h index 9c4fbcbbafe..6e4eb82aa93 100644 --- a/src/node/mining_types.h +++ b/src/node/mining_types.h @@ -86,7 +86,7 @@ struct BlockCreateOptions { CScript coinbase_output_script{CScript() << OP_TRUE}; /** * Whether to call TestBlockValidity() at the end of CreateNewBlock(). - * Should only be used for tests / benchmarks. + * Should only be disabled for tests / benchmarks. */ bool test_block_validity{true}; }; From 280ce6a0aed469c920aa4faa3baf10fd6572a106 Mon Sep 17 00:00:00 2001 From: Sjors Provoost Date: Thu, 28 May 2026 11:37:27 +0200 Subject: [PATCH 3/5] miner: ensure block_max_weight is flattened before limit checks Suggested in https://github.com/bitcoin/bitcoin/pull/33966#discussion_r3303462087 --- src/node/miner.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/node/miner.cpp b/src/node/miner.cpp index ccd9cc7c57a..32a21440c4e 100644 --- a/src/node/miner.cpp +++ b/src/node/miner.cpp @@ -245,7 +245,9 @@ std::unique_ptr BlockAssembler::CreateNewBlock() bool BlockAssembler::TestChunkBlockLimits(FeePerWeight chunk_feerate, int64_t chunk_sigops_cost) const { - if (nBlockWeight + chunk_feerate.size >= m_options.block_max_weight) { + // block_max_weight has been flattened before block assembly limit checks. + Assert(m_options.block_max_weight); + if (nBlockWeight + chunk_feerate.size >= *m_options.block_max_weight) { return false; } if (nBlockSigOpsCost + chunk_sigops_cost >= MAX_BLOCK_SIGOPS_COST) { @@ -318,8 +320,10 @@ void BlockAssembler::addChunks() m_mempool->SkipBuilderChunk(); ++nConsecutiveFailed; + // block_max_weight has been flattened before block assembly limit checks. + Assert(m_options.block_max_weight); if (nConsecutiveFailed > MAX_CONSECUTIVE_FAILURES && nBlockWeight + - BLOCK_FULL_ENOUGH_WEIGHT_DELTA > m_options.block_max_weight) { + BLOCK_FULL_ENOUGH_WEIGHT_DELTA > *m_options.block_max_weight) { // Give up if we're close to full and haven't succeeded in a while return; } From f4e643cb152c4ace9659de553f80d6a4f79dd62d Mon Sep 17 00:00:00 2001 From: Sjors Provoost Date: Thu, 28 May 2026 13:27:57 +0200 Subject: [PATCH 4/5] test: merge mining options in package feerate check See https://github.com/bitcoin/bitcoin/pull/33966#discussion_r3317409504 --- src/test/miner_tests.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/test/miner_tests.cpp b/src/test/miner_tests.cpp index fd9559b543c..1b8fd62c6b8 100644 --- a/src/test/miner_tests.cpp +++ b/src/test/miner_tests.cpp @@ -13,6 +13,7 @@ #include #include #include +#include #include #include #include @@ -197,7 +198,7 @@ void MinerTestingSetup::TestPackageSelection(const CScript& scriptPubKey, const const auto block_package_feerates = BlockAssembler{ m_node.chainman->ActiveChainstate(), &tx_mempool, - m_node.mining_args, + MergeMiningOptions(options, m_node.mining_args), }.CreateNewBlock()->m_package_feerates; BOOST_CHECK(block_package_feerates.size() == 2); From b847626562e79083865c59df9dbcf0f1e91e2bb8 Mon Sep 17 00:00:00 2001 From: Sjors Provoost Date: Thu, 28 May 2026 19:51:42 +0200 Subject: [PATCH 5/5] test: refresh MiniWallet after node restart --- test/functional/interface_ipc_mining.py | 1 + 1 file changed, 1 insertion(+) diff --git a/test/functional/interface_ipc_mining.py b/test/functional/interface_ipc_mining.py index 5d081a8dbc8..1288a454bad 100755 --- a/test/functional/interface_ipc_mining.py +++ b/test/functional/interface_ipc_mining.py @@ -324,6 +324,7 @@ class IPCMiningTest(BitcoinTestFramework): # blockReservedWeight per template request and are unaffected; later in # the test the IPC template includes a mempool transaction. self.restart_node(0, extra_args=[f"-blockreservedweight={MAX_BLOCK_WEIGHT}"]) + self.miniwallet.rescan_utxos() async def async_routine(): ctx, mining = await make_mining_ctx(self)