Skip to content

Commit 0eba2ce

Browse files
committed
Client: make JSON-RPC payload limits configurable for eth and engine servers
1 parent 3f0cd29 commit 0eba2ce

File tree

7 files changed

+46
-4
lines changed

7 files changed

+46
-4
lines changed

packages/client/bin/repl.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ const setupClient = async (
4242
jwtSecret: '',
4343
rpcEngineAuth: false,
4444
rpcCors: '',
45+
rpcEthMaxPayload: args.rpcEthMaxPayload ?? '5mb',
46+
rpcEngineMaxPayload: args.rpcEngineMaxPayload ?? '15mb',
4547
})
4648

4749
return { client, executionRPC: servers[0], engineRPC: servers[1] }

packages/client/bin/startRPC.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ export type RPCArgs = {
3737
jwtSecret?: string
3838
rpcEngineAuth: boolean
3939
rpcCors: string
40+
rpcEthMaxPayload: string
41+
rpcEngineMaxPayload: string
4042
}
4143

4244
/**
@@ -97,7 +99,10 @@ export function startRPCServers(client: EthereumClient, args: RPCArgs) {
9799
rpcCors,
98100
rpcDebug,
99101
rpcDebugVerbose,
102+
rpcEthMaxPayload,
103+
rpcEngineMaxPayload,
100104
} = args
105+
101106
const manager = new RPCManager(client, config)
102107
const { logger } = config
103108
const jwtSecret =
@@ -136,6 +141,7 @@ export function startRPCServers(client: EthereumClient, args: RPCArgs) {
136141
: req.body.method.includes('engine_') === false,
137142
}
138143
: undefined,
144+
maxPayload: rpcEthMaxPayload,
139145
})
140146
rpcHttpServer.listen(rpcPort, rpcAddr)
141147
logger.info(
@@ -191,6 +197,7 @@ export function startRPCServers(client: EthereumClient, args: RPCArgs) {
191197
jwtSecret,
192198
}
193199
: undefined,
200+
maxPayload: rpcEngineMaxPayload,
194201
})
195202
rpcHttpServer.listen(rpcEnginePort, rpcEngineAddr)
196203
logger.info(

packages/client/bin/utils.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,16 @@ export function getArgs(): ClientOpts {
196196
boolean: true,
197197
default: true,
198198
})
199+
.option('rpcEthMaxPayload', {
200+
describe: 'Define max JSON payload size for eth/debug RPC requests',
201+
string: true,
202+
default: '5mb',
203+
})
204+
.option('rpcEngineMaxPayload', {
205+
describe: 'Define max JSON payload size for engine RPC requests',
206+
string: true,
207+
default: '15mb',
208+
})
199209
.option('jwtSecret', {
200210
describe: 'Provide a file containing a hex encoded jwt secret for Engine RPC server',
201211
coerce: (arg: string) => (arg ? path.resolve(arg) : undefined),

packages/client/src/config.ts

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,16 @@ export interface ConfigOptions {
346346
* Enables Prometheus Metrics that can be collected for monitoring client health
347347
*/
348348
prometheusMetrics?: PrometheusMetrics
349+
350+
/**
351+
* Max JSON payload size for eth/eth RPC requests (untrusted)
352+
*/
353+
rpcEthMaxPayload?: string
354+
355+
/*
356+
* Max JSON payload size for engine RPC requests (trusted)
357+
*/
358+
rpcEngineMaxPayload?: string
349359
}
350360

351361
export class Config {
@@ -356,7 +366,7 @@ export class Config {
356366
public readonly events: EventEmitter<EventParams>
357367

358368
public static readonly CHAIN_DEFAULT = Mainnet
359-
public static readonly SYNCMODE_DEFAULT = SyncMode.Full
369+
public static readonly SYNCMODE_DEFAULT = SyncMode.None
360370
public static readonly DATADIR_DEFAULT = `./datadir`
361371
public static readonly PORT_DEFAULT = 30303
362372
public static readonly MAXPERREQUEST_DEFAULT = 100
@@ -365,6 +375,8 @@ export class Config {
365375
public static readonly MINPEERS_DEFAULT = 1
366376
public static readonly MAXPEERS_DEFAULT = 25
367377
public static readonly DNSADDR_DEFAULT = '8.8.8.8'
378+
public static readonly RPC_ETH_MAXPAYLOAD_DEFAULT = '5mb'
379+
public static readonly RPC_ENGINE_MAXPAYLOAD_DEFAULT = '15mb'
368380
public static readonly EXECUTION = true
369381
public static readonly NUM_BLOCKS_PER_ITERATION = 100
370382
public static readonly ACCOUNT_CACHE = 400000
@@ -458,6 +470,9 @@ export class Config {
458470

459471
public readonly blobsAndProofsCacheBlocks: number
460472

473+
public readonly rpcEthMaxPayload: string
474+
public readonly rpcEngineMaxPayload: string
475+
461476
public synchronized: boolean
462477
public lastSynchronized?: boolean
463478
/** lastSyncDate in ms */
@@ -563,6 +578,9 @@ export class Config {
563578
this.blobsAndProofsCacheBlocks =
564579
options.blobsAndProofsCacheBlocks ?? Config.BLOBS_AND_PROOFS_CACHE_BLOCKS
565580

581+
this.rpcEthMaxPayload = options.rpcEthMaxPayload ?? Config.RPC_ETH_MAXPAYLOAD_DEFAULT
582+
this.rpcEngineMaxPayload = options.rpcEngineMaxPayload ?? Config.RPC_ENGINE_MAXPAYLOAD_DEFAULT
583+
566584
this.discDns = this.getDnsDiscovery(options.discDns)
567585
this.discV4 = options.discV4 ?? true
568586

packages/client/src/types.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,8 @@ export interface ClientOpts {
148148
skipEngineExec?: boolean
149149
ignoreStatelessInvalidExecs?: boolean
150150
useJsCrypto?: boolean
151+
rpcEthMaxPayload?: string
152+
rpcEngineMaxPayload?: string
151153
}
152154

153155
export type PrometheusMetrics = {

packages/client/src/util/rpc.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ type CreateRPCServerListenerOpts = {
3333
withEngineMiddleware?: WithEngineMiddleware
3434
}
3535
type CreateWSServerOpts = CreateRPCServerListenerOpts & { httpServer?: jayson.HttpServer }
36+
type CreateHTTPServerOpts = CreateRPCServerListenerOpts & { maxPayload: string }
3637
type WithEngineMiddleware = { jwtSecret: Uint8Array; unlessFn?: (req: IncomingMessage) => boolean }
3738

3839
export type MethodConfig = (typeof MethodConfig)[keyof typeof MethodConfig]
@@ -182,13 +183,13 @@ function checkHeaderAuth(req: any, jwtSecret: Uint8Array): void {
182183
}
183184
}
184185

185-
export function createRPCServerListener(opts: CreateRPCServerListenerOpts): jayson.HttpServer {
186-
const { server, withEngineMiddleware, RPCCors } = opts
186+
export function createRPCServerListener(opts: CreateHTTPServerOpts): jayson.HttpServer {
187+
const { server, withEngineMiddleware, RPCCors, maxPayload } = opts
187188

188189
const app = Connect()
189190
if (typeof RPCCors === 'string') app.use(cors({ origin: RPCCors }))
190191
// GOSSIP_MAX_SIZE_BELLATRIX is proposed to be 10MiB
191-
app.use(JSONParser({ limit: '11mb' }))
192+
app.use(JSONParser({ limit: maxPayload }))
192193

193194
if (withEngineMiddleware) {
194195
const { jwtSecret, unlessFn } = withEngineMiddleware

packages/client/test/util/rpc.spec.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ describe('[Util/RPC]', () => {
3232
const httpServer = createRPCServerListener({
3333
server,
3434
withEngineMiddleware: { jwtSecret: new Uint8Array(32) },
35+
maxPayload: '15mb',
3536
})
3637
const wsServer = createWsRPCServerListener({
3738
server,
@@ -74,6 +75,7 @@ describe('[Util/RPC]', () => {
7475
const httpServer = createRPCServerListener({
7576
server,
7677
withEngineMiddleware: { jwtSecret: new Uint8Array(32) },
78+
maxPayload: '15mb',
7779
})
7880
const wsServer = createWsRPCServerListener({
7981
server,

0 commit comments

Comments
 (0)