-
Notifications
You must be signed in to change notification settings - Fork 827
Client: make JSON-RPC payload limits configurable for eth and engine servers #3993
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 5 commits
0eba2ce
dd46b41
5e47e75
91a2c93
dcfa7fa
c0af203
c5defc6
95aae7c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,6 +32,7 @@ describe('[Util/RPC]', () => { | |
const httpServer = createRPCServerListener({ | ||
server, | ||
withEngineMiddleware: { jwtSecret: new Uint8Array(32) }, | ||
maxPayload: Config.RPC_ETH_MAXPAYLOAD_DEFAULT, | ||
}) | ||
const wsServer = createWsRPCServerListener({ | ||
server, | ||
|
@@ -74,6 +75,7 @@ describe('[Util/RPC]', () => { | |
const httpServer = createRPCServerListener({ | ||
server, | ||
withEngineMiddleware: { jwtSecret: new Uint8Array(32) }, | ||
maxPayload: Config.RPC_ENGINE_MAXPAYLOAD_DEFAULT, | ||
}) | ||
const wsServer = createWsRPCServerListener({ | ||
server, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you add a test here to verify that for both engine/eth the config is handled correctly? You can likely just set it to some low limit and then try to push more data over the RPC than the limit to verify that it fails. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done ✅ |
||
|
@@ -84,6 +86,96 @@ describe('[Util/RPC]', () => { | |
'should return http and ws servers', | ||
) | ||
}) | ||
it('should reject oversized RPC payloads', async () => { | ||
const config = new Config({ | ||
accountCache: 10000, | ||
storageCache: 1000, | ||
rpcEthMaxPayload: '1kb', | ||
rpcEngineMaxPayload: '10mb', | ||
}) | ||
const client = await EthereumClient.create({ config, metaDB: new MemoryLevel() }) | ||
|
||
const manager = new RPCManager(client, config) | ||
const { logger } = config | ||
const methodConfig = Object.values(MethodConfig)[0] | ||
const { server } = createRPCServer(manager, { | ||
methodConfig, | ||
rpcDebug: 'eth', | ||
logger, | ||
rpcDebugVerbose: undefined as any, | ||
}) | ||
|
||
const ethHttpServer = createRPCServerListener({ | ||
server, | ||
withEngineMiddleware: undefined, | ||
maxPayload: config.rpcEthMaxPayload, | ||
}) | ||
|
||
const engineHttpServer = createRPCServerListener({ | ||
server, | ||
withEngineMiddleware: undefined, | ||
maxPayload: config.rpcEngineMaxPayload, | ||
}) | ||
|
||
const ethPort = 8545 | ||
const enginePort = 8551 | ||
|
||
ethHttpServer.listen(ethPort) | ||
engineHttpServer.listen(enginePort) | ||
|
||
const oversizedEthPayload = JSON.stringify({ | ||
jsonrpc: '2.0', | ||
id: 1, | ||
method: 'eth_getBlockByNumber', | ||
params: ['latest', true], | ||
data: 'eth'.repeat(2500), | ||
}) | ||
|
||
const oversizedEnginePayload = JSON.stringify({ | ||
jsonrpc: '2.0', | ||
id: 1, | ||
method: 'engine_newPayloadV2', | ||
params: [ | ||
{ | ||
baseFeePerGas: '0x', | ||
blockHash: '0x', | ||
blockNumber: '0x', | ||
extraData: '0x'.repeat(2500), | ||
feeRecipient: '0x', | ||
gasLimit: '0x', | ||
gasUsed: '0x', | ||
logsBloom: '0x', | ||
parentHash: '0x', | ||
prevRandao: '0x', | ||
receiptsRoot: '0x', | ||
stateRoot: '0x', | ||
timestamp: '0x', | ||
transactions: [], | ||
}, | ||
], | ||
}) | ||
|
||
const resEth = await fetch(`http://localhost:${ethPort}`, { | ||
method: 'POST', | ||
body: oversizedEthPayload, | ||
headers: { 'Content-Type': 'application/json' }, | ||
}) | ||
|
||
const resEngine = await fetch(`http://localhost:${enginePort}`, { | ||
method: 'POST', | ||
body: oversizedEnginePayload, | ||
headers: { | ||
'Content-Type': 'application/json', | ||
}, | ||
}) | ||
|
||
assert.strictEqual( | ||
resEth.status, | ||
413, | ||
'ETH server should reject oversized payload with 413 status', | ||
) | ||
assert.strictEqual(resEngine.status, 200, 'ENGINE server should accept oversized payload') | ||
}) | ||
}) | ||
|
||
describe('[Util/RPC/Engine eth methods]', async () => { | ||
|
Uh oh!
There was an error while loading. Please reload this page.