Skip to content

Commit d190f0f

Browse files
committedMar 18, 2025
test, contrib: Fix signer/miner command line escaping
Pass bitcoin binary command lines from test framework to signet/miner utility using shell escaping so they are unambigous and don't get mangled if they contain spaces. This change is not needed for tests to pass currently, but is a useful change to avoid CI failures in followup PR bitcoin#31375 and to avoid other bugs.
1 parent 0d2eefc commit d190f0f

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed
 

‎contrib/signet/miner

+4-4
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import logging
99
import math
1010
import os
1111
import re
12-
import struct
12+
import shlex
1313
import sys
1414
import time
1515
import subprocess
@@ -86,7 +86,7 @@ def finish_block(block, signet_solution, grind_cmd):
8686
block.solve()
8787
else:
8888
headhex = CBlockHeader.serialize(block).hex()
89-
cmd = grind_cmd.split(" ") + [headhex]
89+
cmd = shlex.split(grind_cmd) + [headhex]
9090
newheadhex = subprocess.run(cmd, stdout=subprocess.PIPE, input=b"", check=True).stdout.strip()
9191
newhead = from_hex(CBlockHeader(), newheadhex.decode('utf8'))
9292
block.nNonce = newhead.nNonce
@@ -479,7 +479,7 @@ def do_calibrate(args):
479479
header.nTime = i
480480
header.nNonce = 0
481481
headhex = header.serialize().hex()
482-
cmd = args.grind_cmd.split(" ") + [headhex]
482+
cmd = shlex.split(args.grind_cmd) + [headhex]
483483
newheadhex = subprocess.run(cmd, stdout=subprocess.PIPE, input=b"", check=True).stdout.strip()
484484

485485
avg = (time.time() - start) * 1.0 / TRIALS
@@ -549,7 +549,7 @@ def main():
549549

550550
args = parser.parse_args(sys.argv[1:])
551551

552-
args.bcli = lambda *a, input=b"", **kwargs: bitcoin_cli(args.cli.split(" "), list(a), input=input, **kwargs)
552+
args.bcli = lambda *a, input=b"", **kwargs: bitcoin_cli(shlex.split(args.cli), list(a), input=input, **kwargs)
553553

554554
if hasattr(args, "address") and hasattr(args, "descriptor"):
555555
args.derived_addresses = {}

‎test/functional/tool_signet_miner.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
"""Test signet miner tool"""
66

77
import os.path
8+
import shlex
89
import subprocess
910
import sys
1011
import time
@@ -54,10 +55,10 @@ def run_test(self):
5455
subprocess.run([
5556
sys.executable,
5657
signet_miner_path,
57-
f'--cli={" ".join(rpc_argv)}',
58+
f'--cli={shlex.join(rpc_argv)}',
5859
'generate',
5960
f'--address={node.getnewaddress()}',
60-
f'--grind-cmd={" ".join(util_argv)}',
61+
f'--grind-cmd={shlex.join(util_argv)}',
6162
f'--nbits={DIFF_1_N_BITS:08x}',
6263
f'--set-block-time={int(time.time())}',
6364
'--poolnum=99',

0 commit comments

Comments
 (0)
Please sign in to comment.