|
46 | 46 | # The size of the blocks xor key
|
47 | 47 | # from InitBlocksdirXorKey::xor_key.size()
|
48 | 48 | NUM_XOR_BYTES = 8
|
| 49 | +CLI_MAX_ARG_SIZE = 131071 # many systems have a 128kb limit per arg (MAX_ARG_STRLEN) |
| 50 | + |
49 | 51 | # The null blocks key (all 0s)
|
50 | 52 | NULL_BLK_XOR_KEY = bytes([0] * NUM_XOR_BYTES)
|
51 | 53 | BITCOIN_PID_FILENAME_DEFAULT = "bitcoind.pid"
|
@@ -920,12 +922,24 @@ def send_cli(self, clicommand=None, *args, **kwargs):
|
920 | 922 | p_args = self.binaries.rpc_argv() + [f"-datadir={self.datadir}"] + self.options
|
921 | 923 | if named_args:
|
922 | 924 | p_args += ["-named"]
|
| 925 | + base_arg_pos = len(p_args) |
923 | 926 | if clicommand is not None:
|
924 | 927 | p_args += [clicommand]
|
925 | 928 | 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 | + |
926 | 940 | self.log.debug("Running bitcoin-cli {}".format(p_args[2:]))
|
927 | 941 | 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) |
929 | 943 | returncode = process.poll()
|
930 | 944 | if returncode:
|
931 | 945 | match = re.match(r'error code: ([-0-9]+)\nerror message:\n(.*)', cli_stderr)
|
|
0 commit comments