Skip to content

Commit

Permalink
Remove rejection of large JSON-RPC requests (#1115)
Browse files Browse the repository at this point in the history
* Remove rejection of large JSON-RPC requests

* CHANGELOG
  • Loading branch information
tomaka authored Sep 6, 2023
1 parent 3c1c5b6 commit 5119e32
Show file tree
Hide file tree
Showing 4 changed files with 2 additions and 28 deletions.
1 change: 1 addition & 0 deletions wasm-node/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
### Changed

- Transactions submitted through the JSON-RPC server before the warp syncing process is finished will now immediately be dropped. ([#1110](https://github.com/smol-dot/smoldot/pull/1110))
- JSON-RPC requests that are too large are no longer rejected. In case where the JSON-RPC client is trusted, then there is nothing to do, and the potential lack of memory space will become a non-issue once the `Memory64` WebAssembly proposal becomes widely available. In case where the JSON-RPC client is not trusted, the API user is encouraged to manually implement a limit to the size of JSON-RPC requests. ([#1115](https://github.com/smol-dot/smoldot/pull/1115))

### Fixed

Expand Down
3 changes: 0 additions & 3 deletions wasm-node/javascript/src/internals/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -534,9 +534,6 @@ export function start(options: ClientOptions, wasmModule: SmoldotBytecode | Prom
throw new AlreadyDestroyedError();
if (options.disableJsonRpc)
throw new JsonRpcDisabledError();
if (request.length >= 64 * 1024 * 1024) {
throw new MalformedJsonRpcError();
};

const retVal = state.instance.instance.request(request, chainId);
switch (retVal) {
Expand Down
3 changes: 1 addition & 2 deletions wasm-node/javascript/src/public-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,7 @@ export interface Chain {
* as the responses.
*
* A {@link MalformedJsonRpcError} is thrown if the request isn't a valid JSON-RPC request
* (for example if it is not valid JSON) or if the request is unreasonably large (64 MiB at the
* time of writing of this comment).
* (for example if it is not valid JSON).
* If, however, the request is a valid JSON-RPC request but that concerns an unknown method, or
* if for example some parameters are missing, an error response is properly generated and
* yielded through the JSON-RPC callback.
Expand Down
23 changes: 0 additions & 23 deletions wasm-node/javascript/test/misc.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -36,29 +36,6 @@ test('malformed json-rpc requests rejected', async t => {
.then(() => client.terminate());
});

test('too large json-rpc requests rejected', async t => {
// Generate a very long string. We start with a length of 1 and double for every iteration.
// Thus the final length of the string is `2^i` where `i` is the number of iterations.
let veryLongString = 'a';
for (let i = 0; i < 27; ++i) {
veryLongString += veryLongString;
}

const client = start({ logCallback: () => { } });
await client
.addChain({ chainSpec: westendSpec })
.then((chain) => {
try {
// We use `JSON.stringify` in order to be certain that the request is valid JSON.
chain.sendJsonRpc(JSON.stringify({ "jsonrpc": "2.0", "id": 1, "method": "foo", "params": [veryLongString] }));
} catch(error) {
t.assert(error instanceof MalformedJsonRpcError);
t.pass();
}
})
.then(() => client.terminate());
});

test('disableJsonRpc option forbids sendJsonRpc', async t => {
const client = start({ logCallback: () => { } });
await client
Expand Down

0 comments on commit 5119e32

Please sign in to comment.