Skip to content

Commit 37b6092

Browse files
authored
fix: align JSON-RPC client batch body limit with server default (#24953)
## Problem The JSON-RPC client (`SafeJsonRpcClient`, used by PXE to talk to the node via `createAztecNodeClient`) and the JSON-RPC server enforce two batch limits: a max request count and a max body size. The request-count limits already agree (both default to **100**), but the body-size limits do not: - Client: `DEFAULT_MAX_REQUESTY_BODY_SIZE = 10 * 1024 * 1024` (**10 MB**) — `foundation/src/json-rpc/client/safe_json_rpc_client.ts` - Server: `maxBodySizeBytes: '1mb'` (**1 MB**, Koa `bodyParser` `jsonLimit`) — `foundation/src/json-rpc/server/safe_json_rpc_server.ts` Because the client only stops accreting a batch once the cumulative encoded size reaches its own 10 MB cap, it can assemble a sub-100-request batch between 1 MB and 10 MB that the node rejects at the 1 MB body limit. That rejection is an HTTP 4xx, which the client's fetch treats as a `NoRetryError`, so the **entire batch fails without retry** and every request in it rejects. Large-payload paths (e.g. `sendTx` with a Chonk proof, or a burst of witness queries coalesced into one batch) are the realistic triggers. ## Change Lower the client's default max batch body size to **1 MB** so it matches the server's default `maxBodySizeBytes`. The client now flushes and starts a new batch before crossing the limit the server enforces, instead of building an over-limit batch that gets rejected. - Request-count caps were already aligned (100 = 100); no change needed there. - `1mb` in the server config resolves to `1 * 1024 * 1024` bytes via the `bytes` library, so the constants now match exactly. ## Notes - The server's body limit remains configurable via `RPC_MAX_BODY_SIZE` / `--rpcMaxBodySize`; this only changes the client-side *default*, which is not env-configurable. Callers who talk to a node started with a raised `RPC_MAX_BODY_SIZE` and who need larger client batches can still pass an explicit `maxRequestBodySize` to `createSafeJsonRpcClient`. - No test pins the old 10 MB default — the body-size unit test in `safe_json_rpc_client.test.ts` passes an explicit `maxRequestBodySize` override, so it is unaffected. Context: raised from a research thread on PXE↔node RPC batching/limits. --- *Created by [claudebox](https://claudebox.work/v2/sessions/55ac241ae08220e9/jobs/2) · group: `slackbot` · requested by Nicolás Venturo · [Slack thread](https://aztecprotocol.slack.com/archives/C0BLBBGT3S4/p1784862842936309?thread_ts=1784862842.936309&cid=C0BLBBGT3S4)*
1 parent 76a1caf commit 37b6092

1 file changed

Lines changed: 3 additions & 2 deletions

File tree

yarn-project/foundation/src/json-rpc/client/safe_json_rpc_client.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,9 @@ const DEFAULT_BATCH_WINDOW_MS = 0;
1414
// the maximum size of a batched request
1515
const DEFAULT_MAX_BATCH_SIZE = 100;
1616

17-
// 10 mb
18-
const DEFAULT_MAX_REQUESTY_BODY_SIZE = 10 * 1024 * 1024;
17+
// 1 mb, matching the JSON-RPC server's default maxBodySizeBytes so the client never assembles a batch the
18+
// server rejects for exceeding the body limit
19+
const DEFAULT_MAX_REQUESTY_BODY_SIZE = 1 * 1024 * 1024;
1920

2021
export type SafeJsonRpcClientOptions = {
2122
namespaceMethods?: string | false;

0 commit comments

Comments
 (0)