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.
0diff --git a/test/functional/interface_ipc.py b/test/functional/interface_ipc.py
1index 02f3e0dd35d..677244e1a44 100755
2--- a/test/functional/interface_ipc.py
3+++ b/test/functional/interface_ipc.py
4@@ -126,11 +126,6 @@ class IPCInterfaceTest(BitcoinTestFramework):
5
6 def setup_nodes(self):
7 self.extra_init = [{"ipcbind": True}, {}]
8- # Set an absurd reserved weight. `-blockreservedweight` is RPC-only, so
9- # with this setting RPC templates would be empty. IPC clients set
10- # blockReservedWeight per template request and are unaffected; later in
11- # the test the IPC template includes a mempool transaction.
12- self.extra_args =[{f"-blockreservedweight={MAX_BLOCK_WEIGHT}"}, {}]
13 super().setup_nodes()
14 # Use this function to also load the capnp modules (we cannot use set_test_params for this,
15 # as it is being called before knowing whether capnp is available).
16@@ -250,7 +245,6 @@ class IPCInterfaceTest(BitcoinTestFramework):
17 block_hash_size = 32
18 block_header_size = 80
19 timeout = 1000.0 # 1000 milliseconds
20- miniwallet = MiniWallet(self.nodes[0])
21
22 async def async_routine():
23 ctx, init = await self.make_capnp_init_ctx()
24@@ -318,7 +312,7 @@ class IPCInterfaceTest(BitcoinTestFramework):
25 self.log.debug("Wait for another, get one after increase in fees in the mempool")
26 template4 = await wait_and_do(
27 wait_next_template(template2, stack, ctx, waitoptions),
28- lambda: miniwallet.send_self_transfer(fee_rate=10, from_node=self.nodes[0]))
29+ lambda: self.miniwallet.send_self_transfer(fee_rate=10, from_node=self.nodes[0]))
30 assert template4 is not None
31 block3 = await self.parse_and_deserialize_block(template4, ctx)
32 assert_equal(len(block3.vtx), 2)
33@@ -334,7 +328,7 @@ class IPCInterfaceTest(BitcoinTestFramework):
34 self.log.debug("Wait for another, get one after increase in fees in the mempool")
35 template6 = await wait_and_do(
36 wait_next_template(template5, stack, ctx, waitoptions),
37- lambda: miniwallet.send_self_transfer(fee_rate=10, from_node=self.nodes[0]))
38+ lambda: self.miniwallet.send_self_transfer(fee_rate=10, from_node=self.nodes[0]))
39 assert template6 is not None
40 block4 = await self.parse_and_deserialize_block(template6, ctx)
41 assert_equal(len(block4.vtx), 3)
42@@ -352,21 +346,12 @@ class IPCInterfaceTest(BitcoinTestFramework):
43 assert template7 is None
44 await wait_and_do(wait_for_block(), template6.interruptWait())
45
46- self.log.debug("Use absurdly large reserved weight to force an empty template")
47- opts.blockReservedWeight = MAX_BLOCK_WEIGHT
48- empty_template = await create_block_template(mining, stack, ctx, opts)
49- assert empty_template is not None
50- block = await self.parse_and_deserialize_block(empty_template, ctx)
51- assert_equal(len(block.vtx), 1)
52- # Restore opts
53- opts.blockReservedWeight = 4000
54-
55 current_block_height = self.nodes[0].getchaintips()[0]["height"]
56 check_opts = self.capnp_modules['mining'].BlockCheckOptions()
57 async with destroying((await mining.createNewBlock(opts)).result, ctx) as template:
58 block = await self.parse_and_deserialize_block(template, ctx)
59- balance = miniwallet.get_balance()
60- coinbase = await self.build_coinbase_test(template, ctx, miniwallet)
61+ balance = self.miniwallet.get_balance()
62+ coinbase = await self.build_coinbase_test(template, ctx, self.miniwallet)
63 # Reduce payout for balance comparison simplicity
64 coinbase.vout[0].nValue = COIN
65 block.vtx[0] = coinbase
66@@ -414,8 +399,8 @@ class IPCInterfaceTest(BitcoinTestFramework):
67 # Check that the other node accepts the block
68 assert_equal(self.nodes[0].getchaintips()[0], self.nodes[1].getchaintips()[0])
69
70- miniwallet.rescan_utxos()
71- assert_equal(miniwallet.get_balance(), balance + 1)
72+ self.miniwallet.rescan_utxos()
73+ assert_equal(self.miniwallet.get_balance(), balance + 1)
74 self.log.debug("Check block should fail now, since it is a duplicate")
75 check = await mining.checkBlock(block.serialize(), check_opts)
76 assert_equal(check.result, False)
77@@ -423,9 +408,40 @@ class IPCInterfaceTest(BitcoinTestFramework):
78
79 asyncio.run(capnp.run(async_routine()))
80
81+ def run_ipc_option_test(self):
82+ self.log.debug("Test that IPC blockReservedReight runtime value will override startup -blockreservedweight")
83+ # The absurd blockreservedweight startup option should not force us to have empty blocks when
84+ # a lower value is added is passed via the IPC.
85+ self.restart_node(0, extra_args=[f"-blockreservedweight={MAX_BLOCK_WEIGHT}"])
86+ async def async_routine():
87+ ctx, init = await self.make_capnp_init_ctx()
88+ mining = init.makeMining(ctx).result
89+ async with AsyncExitStack() as stack:
90+ opts = self.capnp_modules['mining'].BlockCreateOptions()
91+ opts.useMempool = True
92+ opts.blockReservedWeight = 4000
93+ opts.coinbaseOutputMaxAdditionalSigops = 0
94+ self.miniwallet.send_self_transfer(fee_rate=10, from_node=self.nodes[0])
95+ template = await create_block_template(mining, stack, ctx, opts)
96+ assert template is not None
97+ block = await self.parse_and_deserialize_block(template, ctx)
98+ assert_equal(len(block.vtx), 2)
99+ self.log.debug("Use absurdly large reserved weight to force an empty template")
100+ opts.blockReservedWeight = MAX_BLOCK_WEIGHT
101+ empty_template = await create_block_template(mining, stack, ctx, opts)
102+ assert empty_template is not None
103+ block = await self.parse_and_deserialize_block(empty_template, ctx)
104+ assert_equal(len(block.vtx), 1)
105+
106+ asyncio.run(capnp.run(async_routine()))
107+
108+
109 def run_test(self):
110+ self.miniwallet = MiniWallet(self.nodes[0])
111 self.run_echo_test()
112 self.run_mining_test()
113+ self.run_ipc_option_test()
114+
115
116 if __name__ == '__main__':
117 IPCInterfaceTest(__file__).main()