Skip to content

Commit

Permalink
align maximum body size between Websock and HTTP transports (#211)
Browse files Browse the repository at this point in the history
HTTP has a 128 MB limit, while websock uses the library default (20 MB).
Align both to 128 MB. This should be enough for an Ethereum `getPayload`
with 6 blobs, all hex encoded binary + JSON overhead.
  • Loading branch information
etan-status authored Feb 20, 2024
1 parent 9c65df3 commit 8682bb6
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 6 deletions.
2 changes: 2 additions & 0 deletions json_rpc/client.nim
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ export
ResponseBatchRx,
results

const MaxMessageBodyBytes* = 128 * 1024 * 1024 # 128 MB (JSON encoded)

type
RpcBatchItem* = object
meth*: string
Expand Down
7 changes: 2 additions & 5 deletions json_rpc/clients/httpclient.nim
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,14 @@ type
maxBodySize: int
getHeaders: GetJsonRpcRequestHeaders

const
MaxHttpRequestSize = 128 * 1024 * 1024 # maximum size of HTTP body in octets

{.push gcsafe, raises: [].}

# ------------------------------------------------------------------------------
# Private helpers
# ------------------------------------------------------------------------------

proc new(
T: type RpcHttpClient, maxBodySize = MaxHttpRequestSize, secure = false,
T: type RpcHttpClient, maxBodySize = MaxMessageBodyBytes, secure = false,
getHeaders: GetJsonRpcRequestHeaders = nil, flags: HttpClientFlags = {}): T =

var moreFlags: HttpClientFlags
Expand Down Expand Up @@ -132,7 +129,7 @@ proc callImpl(client: RpcHttpClient, reqBody: string): Future[string] {.async.}
# ------------------------------------------------------------------------------

proc newRpcHttpClient*(
maxBodySize = MaxHttpRequestSize, secure = false,
maxBodySize = MaxMessageBodyBytes, secure = false,
getHeaders: GetJsonRpcRequestHeaders = nil,
flags: HttpClientFlags = {}): RpcHttpClient =
RpcHttpClient.new(maxBodySize, secure, getHeaders, flags)
Expand Down
2 changes: 1 addition & 1 deletion json_rpc/clients/websocketclientimpl.nim
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ proc processData(client: RpcWebSocketClient) {.async.} =
let ws = client.transport
try:
while ws.readyState != ReadyState.Closed:
var value = await ws.recvMsg()
var value = await ws.recvMsg(MaxMessageBodyBytes)

if value.len == 0:
# transmission ends
Expand Down

0 comments on commit 8682bb6

Please sign in to comment.