Inside Bitcoin
Opening the selected file…
Inside Bitcoin
Opening the selected file…
The code behind the network, with room to understand it.
Release published 2026-10-28 · Snapshot fetched 2026-11-01. Latest stable release at fetch time; development branches and Git history are excluded. Only the selected code window and visible folders load here.
1#!/usr/bin/env python32# Copyright (c) The Bitcoin Core developers3# Distributed under the MIT software license, see the accompanying4# file COPYING or https://opensource.org/license/mit/.5"""Ensure RPCs with a (possibly large) payload will either be rejected or handled, but will never time out."""7from concurrent.futures import ThreadPoolExecutor8from test_framework.test_framework import BitcoinTestFramework9from test_framework.util import assert_equal, JSONRPCException10import random13class RpcEchoPayloadTest(BitcoinTestFramework):14def set_test_params(self):15self.num_nodes = 116self.setup_clean_chain = True17self.extra_args = [["-rpcworkqueue=2", "-rpcthreads=2"]]18# enough to possibly fill the running threads as well as the queue:19self.num_threads = 621def run_test(self):22node = self.nodes[0]23# Use json-serializable, but non-hex data24data = "z" + random.randbytes(1_999_000).hex()26def check_results(rpc):27self.log.info("Starting thread ...")28for i in range(200):29payload = data[: random.randrange(0, len(data))]30try:31if random.getrandbits(1):32assert_equal(payload, rpc.echo(payload)[0])33else:34rpc.sendrawtransaction(payload)35except JSONRPCException as e:36msg = e.error["message"]37if msg not in [38"TX decode failed. Make sure the tx has at least one input.",39"non-JSON HTTP response with '503 Service Unavailable' from server: Work queue depth exceeded",40]:41raise AssertionError(f"Unexpected msg: {msg}")43rpcs = [node.create_new_rpc_connection() for _ in range(self.num_threads)]44self.log.info("Starting threadpool ...")45with ThreadPoolExecutor(max_workers=len(rpcs)) as threads:46list(threads.map(check_results, rpcs))49if __name__ == "__main__":50RpcEchoPayloadTest(__file__).main()
Independent explanations by MyBitcoinExplorer. Not affiliated with or endorsed by Bitcoin Core. Guides are educational and do not replace the source or its tests.
Bitcoin Core source © its contributors, distributed under the MIT license. Original notices and bundled third-party licenses are retained in the source tree.