In "mining: fix -blockreservedweight shadows IPC option" f69320d3279e2abe1e5d47f496ad54deb4c20fcf
This seems like a weird way to test this.
It would be better if we didn't generalise here and had a separate subtest for this.
diff --git a/test/functional/interface_ipc.py b/test/functional/interface_ipc.py
index 02f3e0dd35d..677244e1a44 100755
--- a/test/functional/interface_ipc.py
+++ b/test/functional/interface_ipc.py
@@ -126,11 +126,6 @@ class IPCInterfaceTest(BitcoinTestFramework):
def setup_nodes(self):
self.extra_init = [{"ipcbind": True}, {}]
- # Set an absurd reserved weight. `-blockreservedweight` is RPC-only, so
- # with this setting RPC templates would be empty. IPC clients set
- # blockReservedWeight per template request and are unaffected; later in
- # the test the IPC template includes a mempool transaction.
- self.extra_args =[{f"-blockreservedweight={MAX_BLOCK_WEIGHT}"}, {}]
super().setup_nodes()
# Use this function to also load the capnp modules (we cannot use set_test_params for this,
# as it is being called before knowing whether capnp is available).
@@ -250,7 +245,6 @@ class IPCInterfaceTest(BitcoinTestFramework):
block_hash_size = 32
block_header_size = 80
timeout = 1000.0 # 1000 milliseconds
- miniwallet = MiniWallet(self.nodes[0])
async def async_routine():
ctx, init = await self.make_capnp_init_ctx()
@@ -318,7 +312,7 @@ class IPCInterfaceTest(BitcoinTestFramework):
self.log.debug("Wait for another, get one after increase in fees in the mempool")
template4 = await wait_and_do(
wait_next_template(template2, stack, ctx, waitoptions),
- lambda: miniwallet.send_self_transfer(fee_rate=10, from_node=self.nodes[0]))
+ lambda: self.miniwallet.send_self_transfer(fee_rate=10, from_node=self.nodes[0]))
assert template4 is not None
block3 = await self.parse_and_deserialize_block(template4, ctx)
assert_equal(len(block3.vtx), 2)
@@ -334,7 +328,7 @@ class IPCInterfaceTest(BitcoinTestFramework):
self.log.debug("Wait for another, get one after increase in fees in the mempool")
template6 = await wait_and_do(
wait_next_template(template5, stack, ctx, waitoptions),
- lambda: miniwallet.send_self_transfer(fee_rate=10, from_node=self.nodes[0]))
+ lambda: self.miniwallet.send_self_transfer(fee_rate=10, from_node=self.nodes[0]))
assert template6 is not None
block4 = await self.parse_and_deserialize_block(template6, ctx)
assert_equal(len(block4.vtx), 3)
@@ -352,21 +346,12 @@ class IPCInterfaceTest(BitcoinTestFramework):
assert template7 is None
await wait_and_do(wait_for_block(), template6.interruptWait())
- self.log.debug("Use absurdly large reserved weight to force an empty template")
- opts.blockReservedWeight = MAX_BLOCK_WEIGHT
- empty_template = await create_block_template(mining, stack, ctx, opts)
- assert empty_template is not None
- block = await self.parse_and_deserialize_block(empty_template, ctx)
- assert_equal(len(block.vtx), 1)
- # Restore opts
- opts.blockReservedWeight = 4000
-
current_block_height = self.nodes[0].getchaintips()[0]["height"]
check_opts = self.capnp_modules['mining'].BlockCheckOptions()
async with destroying((await mining.createNewBlock(opts)).result, ctx) as template:
block = await self.parse_and_deserialize_block(template, ctx)
- balance = miniwallet.get_balance()
- coinbase = await self.build_coinbase_test(template, ctx, miniwallet)
+ balance = self.miniwallet.get_balance()
+ coinbase = await self.build_coinbase_test(template, ctx, self.miniwallet)
# Reduce payout for balance comparison simplicity
coinbase.vout[0].nValue = COIN
block.vtx[0] = coinbase
@@ -414,8 +399,8 @@ class IPCInterfaceTest(BitcoinTestFramework):
# Check that the other node accepts the block
assert_equal(self.nodes[0].getchaintips()[0], self.nodes[1].getchaintips()[0])
- miniwallet.rescan_utxos()
- assert_equal(miniwallet.get_balance(), balance + 1)
+ self.miniwallet.rescan_utxos()
+ assert_equal(self.miniwallet.get_balance(), balance + 1)
self.log.debug("Check block should fail now, since it is a duplicate")
check = await mining.checkBlock(block.serialize(), check_opts)
assert_equal(check.result, False)
@@ -423,9 +408,40 @@ class IPCInterfaceTest(BitcoinTestFramework):
asyncio.run(capnp.run(async_routine()))
+ def run_ipc_option_test(self):
+ self.log.debug("Test that IPC blockReservedReight runtime value will override startup -blockreservedweight")
+ # The absurd blockreservedweight startup option should not force us to have empty blocks when
+ # a lower value is added is passed via the IPC.
+ self.restart_node(0, extra_args=[f"-blockreservedweight={MAX_BLOCK_WEIGHT}"])
+ async def async_routine():
+ ctx, init = await self.make_capnp_init_ctx()
+ mining = init.makeMining(ctx).result
+ async with AsyncExitStack() as stack:
+ opts = self.capnp_modules['mining'].BlockCreateOptions()
+ opts.useMempool = True
+ opts.blockReservedWeight = 4000
+ opts.coinbaseOutputMaxAdditionalSigops = 0
+ self.miniwallet.send_self_transfer(fee_rate=10, from_node=self.nodes[0])
+ template = await create_block_template(mining, stack, ctx, opts)
+ assert template is not None
+ block = await self.parse_and_deserialize_block(template, ctx)
+ assert_equal(len(block.vtx), 2)
+ self.log.debug("Use absurdly large reserved weight to force an empty template")
+ opts.blockReservedWeight = MAX_BLOCK_WEIGHT
+ empty_template = await create_block_template(mining, stack, ctx, opts)
+ assert empty_template is not None
+ block = await self.parse_and_deserialize_block(empty_template, ctx)
+ assert_equal(len(block.vtx), 1)
+
+ asyncio.run(capnp.run(async_routine()))
+
+
def run_test(self):
+ self.miniwallet = MiniWallet(self.nodes[0])
self.run_echo_test()
self.run_mining_test()
+ self.run_ipc_option_test()
+
if __name__ == '__main__':
IPCInterfaceTest(__file__).main()