Skip to content

Commit 7d5352a

Browse files
mzumsanderyanofsky
andcommitted
test: use -stdin for large rpc commands
Because of the MAX_ARG_STRLEN limit (128kb on most systems) for args, these would usually fail. As a workaround, use -stdin for these large calls. Idea by 0xB10C. Co-authored-by: Ryan Ofsky <[email protected]>
1 parent 6c364e0 commit 7d5352a

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

test/functional/test_framework/test_node.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@
4646
# The size of the blocks xor key
4747
# from InitBlocksdirXorKey::xor_key.size()
4848
NUM_XOR_BYTES = 8
49+
CLI_MAX_ARG_SIZE = 131071 # many systems have a 128kb limit per arg (MAX_ARG_STRLEN)
50+
4951
# The null blocks key (all 0s)
5052
NULL_BLK_XOR_KEY = bytes([0] * NUM_XOR_BYTES)
5153
BITCOIN_PID_FILENAME_DEFAULT = "bitcoind.pid"
@@ -920,12 +922,24 @@ def send_cli(self, clicommand=None, *args, **kwargs):
920922
p_args = self.binaries.rpc_argv() + [f"-datadir={self.datadir}"] + self.options
921923
if named_args:
922924
p_args += ["-named"]
925+
base_arg_pos = len(p_args)
923926
if clicommand is not None:
924927
p_args += [clicommand]
925928
p_args += pos_args + named_args
929+
max_arg_size = max(len(arg) for arg in p_args)
930+
stdin_data = self.input
931+
if max_arg_size > CLI_MAX_ARG_SIZE:
932+
self.log.debug(f"Cli: Command size {max_arg_size} too large, using stdin")
933+
rpc_args = "\n".join([arg for arg in p_args[base_arg_pos:]])
934+
if stdin_data is not None:
935+
stdin_data += "\n" + rpc_args
936+
else:
937+
stdin_data = rpc_args
938+
p_args = p_args[:base_arg_pos] + ['-stdin']
939+
926940
self.log.debug("Running bitcoin-cli {}".format(p_args[2:]))
927941
process = subprocess.Popen(p_args, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True)
928-
cli_stdout, cli_stderr = process.communicate(input=self.input)
942+
cli_stdout, cli_stderr = process.communicate(input=stdin_data)
929943
returncode = process.poll()
930944
if returncode:
931945
match = re.match(r'error code: ([-0-9]+)\nerror message:\n(.*)', cli_stderr)

0 commit comments

Comments
 (0)