Repository navigation
Conversation
A node answers a batch it rejects as a whole (size or rate limit) with a single JSON-RPC error object, as JSON-RPC 2.0 requires. BatchClient called .find() on it and every caller got 'results.find is not a function' instead of the node's error. The batch promises of a failed batch were also never deleted. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
PhilippeR26
left a comment
There was a problem hiding this comment.
Thanks for this fix: the bug is real, and the change is small and clear.
One request about the tests. We keep one test file per module, named after it: the tests of src/utils/batch/ live in __tests__/utils/batch.test.ts. That file already contains a test with a mocked transport (sends the batch through an injected transport instead of baseFetch). Could you move your three tests into batch.test.ts, in their own describe block, and delete batchClient.test.ts? They will then run with the devnet suite, like the existing mocked test.
There is also a small change to request on a code comment: see the inline comment.
| // JSON-RPC 2.0: a batch rejected as a whole (size limit, rate limit...) gets a single | ||
| // response object. Every caller of that batch gets its error. |
There was a problem hiding this comment.
The JSON-RPC 2.0 spec does not say this. Section 6 (Batch) asks for a single response object only when the batch itself is invalid:
If the batch rpc call itself fails to be recognized as an valid JSON or as an Array with at least one value, the response from the Server MUST be a single Response object.
BatchClient never sends such a batch. A size or rate limit is a choice of the node, not a rule of the spec. Could you reword the comment, for example:
| // JSON-RPC 2.0: a batch rejected as a whole (size limit, rate limit...) gets a single | |
| // response object. Every caller of that batch gets its error. | |
| // A node can reject the whole batch, for example when it is too large. | |
| // It then answers with a single error object instead of an array. | |
| // Every caller of the batch gets this error. |
|
Unrelated to this PR, but it may interest the OneKey team. We had a look at how the OneKey app uses starknet.js (app-monorepo at 1. No memory or size gain
2. Following the changes of Starknet The RPC spec keeps changing: starknet.js 10.8.0 has channels for 0.9 and 0.10.2 to 0.10.4, and 11.x adds 0.10.5. Fair point: starknet 10.8.0 has no channel for spec 0.8, and 3. Reliability Our CI runs the test suite on devnet for every PR, and on Pathfinder and Juno (spec 0.9 and 0.10) before each release to A hand-written client must find its own edge cases. One example, from reading the code (we did not run it):
If RpcProvider lacks something you need, feel free to tell us. |
Motivation and Resolution
When batching is enabled (
new RpcProvider({ batch: 0 })), a node that rejects the batch as a whole answers with a single JSON-RPC response object instead of an array, as JSON-RPC 2.0 §6 requires (and as public RPC providers do for batch-size or rate limits), e.g.:{ "jsonrpc": "2.0", "id": null, "error": { "code": -32005, "message": "Rate limit exceeded" } }BatchClient.fetch()calledresults.find(...)on that object, so every request in the batch failed withError: results.find is not a function, and the node's actual error was lost.Also,
delete this.batchPromises[requestId]only ran when the batch succeeded, so every request of a failed batch (network error, transport rejection) left an entry inbatchPromisesfor the lifetime of the provider.Changes in
src/utils/batch/index.ts:try/finally, so its entry is always deleted;erroris handed to every caller of the batch, sofetchEndpointraises the usualRpcErrorwith the node's message; any other non-array reply raises an explicit error instead of aTypeError.Successful batches behave exactly as before.
Usage related changes
batchenabled, a batch rejected by the node now rejects with anRpcErrorcarrying the node's code and message (e.g.-32005: Rate limit exceeded) instead ofresults.find is not a function.Development related changes
__tests__/utils/batchClient.test.ts, which needs no node (mocked transport) and so runs innpm run test:unit: a batch-level error reaches every caller, the channel turns it into anRpcError, and a failed batch leaves no entry inbatchPromises. The three tests fail ondevelopand pass with this change.I could not run the devnet-backed integration suite (
npm test) locally; the change does not touch the success path that__tests__/utils/batch.test.tscovers.Checklist:
This PR was prepared with the help of an AI assistant (Claude) and reviewed for correctness.
🤖 Generated with Claude Code