From 1aa21becc9115e77efdefe7d25e2d26e5b791fb7 Mon Sep 17 00:00:00 2001 From: marie-fourier Date: Wed, 1 Nov 2023 16:27:28 +0500 Subject: [PATCH] feat: batch rpc & increase min CGL --- packages/api/src/app.ts | 44 ++++++++++++++++----------------- packages/executor/src/config.ts | 10 +++++++- 2 files changed, 31 insertions(+), 23 deletions(-) diff --git a/packages/api/src/app.ts b/packages/api/src/app.ts index 3357f050..fa4ec6dd 100644 --- a/packages/api/src/app.ts +++ b/packages/api/src/app.ts @@ -84,16 +84,11 @@ export class ApiApp { const redirectApi = new RedirectAPI(executor.networkName, this.config); const skandhaApi = new SkandhaAPI(executor.eth, executor.skandha); - return async (req, res): Promise => { - let result: any = undefined; - const { method, params, jsonrpc, id } = req.body as any; - + const handleRpc = async (ip: string, request: any): Promise => { + let result: any; + const { method, params, jsonrpc, id } = request; // ADMIN METHODS - if ( - this.testingMode || - req.ip === "localhost" || - req.ip === "127.0.0.1" - ) { + if (this.testingMode || ip === "localhost" || ip === "127.0.0.1") { switch (method) { case BundlerRPCMethods.debug_bundler_setBundlingMode: result = await debugApi.setBundlingMode(params[0]); @@ -136,12 +131,12 @@ export class ApiApp { if (this.redirectRpc && method in RedirectedRPCMethods) { const body = await redirectApi.redirect(method, params); if (body.error) { - return res.status(HttpStatus.OK).send({ ...body, id }); + return { ...body, id }; } - return res.status(HttpStatus.OK).send({ jsonrpc, id, ...body }); + return { jsonrpc, id, ...body }; } - if (result === undefined) { + if (!result) { switch (method) { case BundlerRPCMethods.eth_supportedEntryPoints: result = await ethApi.getSupportedEntryPoints(); @@ -197,11 +192,7 @@ export class ApiApp { case CustomRPCMethods.skandha_config: result = await skandhaApi.getConfig(); // skip hexlify for this particular rpc - return res.status(HttpStatus.OK).send({ - jsonrpc, - id, - result, - }); + return { jsonrpc, id, result }; default: throw new RpcError( `Method ${method} is not supported`, @@ -211,11 +202,20 @@ export class ApiApp { } result = deepHexlify(result); - return res.status(HttpStatus.OK).send({ - jsonrpc, - id, - result, - }); + return { jsonrpc, id, result }; + }; + + return async (req, res): Promise => { + let response: any = null; + if (Array.isArray(req.body)) { + response = []; + for (const request of req.body) { + response.push(await handleRpc(req.ip, request)); + } + } else { + response = await handleRpc(req.ip, req.body); + } + return res.status(HttpStatus.OK).send(response); }; } } diff --git a/packages/executor/src/config.ts b/packages/executor/src/config.ts index 05302976..cbf05c93 100644 --- a/packages/executor/src/config.ts +++ b/packages/executor/src/config.ts @@ -221,6 +221,14 @@ export class Config { conf.useropsTTL || bundlerDefaultConfigs.useropsTTL ) ); + conf.estimationStaticBuffer = Number( + fromEnvVar( + network, + "ESTIMATION_STATIC_BUFFER", + conf.estimationStaticBuffer || + bundlerDefaultConfigs.estimationStaticBuffer + ) + ); return Object.assign({}, bundlerDefaultConfigs, conf); } @@ -232,7 +240,7 @@ const bundlerDefaultConfigs: BundlerConfig = { banSlack: 10, minSignerBalance: utils.parseEther("0.1"), multicall: "0xcA11bde05977b3631167028862bE2a173976CA11", // default multicall address - estimationStaticBuffer: 21000, + estimationStaticBuffer: 35000, validationGasLimit: 10e6, receiptLookupRange: 1024, etherscanApiKey: "",