Skip to content

Commit

Permalink
feat: config rpc (#88)
Browse files Browse the repository at this point in the history
* feat: config rpc

* disable binary search

* http codes

* chore(release): v0.0.44
  • Loading branch information
0xSulpiride authored Sep 12, 2023
1 parent b96cc1f commit 1d6f494
Show file tree
Hide file tree
Showing 19 changed files with 147 additions and 44 deletions.
2 changes: 1 addition & 1 deletion lerna.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
],
"npmClient": "yarn",
"useWorkspaces": true,
"version": "0.0.43",
"version": "0.0.44",
"stream": "true",
"command": {
"version": {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "root",
"private": true,
"version": "0.0.43",
"version": "0.0.44",
"engines": {
"node": ">=18.0.0"
},
Expand Down
6 changes: 3 additions & 3 deletions packages/api/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "api",
"version": "0.0.43",
"version": "0.0.44",
"description": "The API module of Etherspot bundler client",
"author": "Etherspot",
"homepage": "https://https://github.com/etherspot/skandha#readme",
Expand Down Expand Up @@ -35,12 +35,12 @@
"class-transformer": "0.5.1",
"class-validator": "0.14.0",
"ethers": "5.7.2",
"executor": "^0.0.43",
"executor": "^0.0.44",
"fastify": "4.14.1",
"pino": "8.11.0",
"pino-pretty": "10.0.0",
"reflect-metadata": "0.1.13",
"types": "^0.0.43"
"types": "^0.0.44"
},
"devDependencies": {
"@types/connect": "3.4.35"
Expand Down
15 changes: 12 additions & 3 deletions packages/api/src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import logger from "./logger";
import {
BundlerRPCMethods,
CustomRPCMethods,
HttpStatus,
RedirectedRPCMethods,
} from "./constants";
import { EthAPI, DebugAPI, Web3API, RedirectAPI } from "./modules";
Expand Down Expand Up @@ -139,9 +140,9 @@ export class ApiApp {
if (this.redirectRpc && method in RedirectedRPCMethods) {
const body = await redirectApi.redirect(method, params);
if (body.error) {
return res.status(200).send({ ...body, id });
return res.status(HttpStatus.OK).send({ ...body, id });
}
return res.status(200).send({ jsonrpc, id, ...body });
return res.status(HttpStatus.OK).send({ jsonrpc, id, ...body });
}

if (result === undefined) {
Expand Down Expand Up @@ -197,6 +198,14 @@ export class ApiApp {
newestBlock: params[2],
});
break;
case CustomRPCMethods.skandha_config:
result = await skandhaApi.getConfig();
// skip hexlify for this particular rpc
return res.status(HttpStatus.OK).send({
jsonrpc,
id,
result,
});
default:
throw new RpcError(
`Method ${method} is not supported`,
Expand All @@ -206,7 +215,7 @@ export class ApiApp {
}

result = deepHexlify(result);
return res.status(200).send({
return res.status(HttpStatus.OK).send({
jsonrpc,
id,
result,
Expand Down
6 changes: 6 additions & 0 deletions packages/api/src/constants.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
export const CustomRPCMethods = {
skandha_validateUserOperation: "skandha_validateUserOperation",
skandha_getGasPrice: "skandha_getGasPrice",
skandha_config: "skandha_config",
skandha_feeHistory: "skandha_feeHistory",
};

Expand Down Expand Up @@ -60,3 +61,8 @@ export const RedirectedRPCMethods = {
eth_maxPriorityFeePerGas: "eth_maxPriorityFeePerGas",
eth_sendRawTransaction: "eth_sendRawTransaction",
};

export enum HttpStatus {
OK = 200,
INTERNAL_SERVER_ERROR = 500,
}
5 changes: 5 additions & 0 deletions packages/api/src/modules/skandha.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Eth } from "executor/lib/modules/eth";
import {
GetConfigResponse,
GetFeeHistoryResponse,
GetGasPriceResponse,
} from "types/lib/api/interfaces";
Expand Down Expand Up @@ -46,4 +47,8 @@ export class SkandhaAPI {
async getGasPrice(): Promise<GetGasPriceResponse> {
return await this.skandhaModule.getGasPrice();
}

async getConfig(): Promise<GetConfigResponse> {
return await this.skandhaModule.getConfig();
}
}
11 changes: 7 additions & 4 deletions packages/api/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import cors from "@fastify/cors";
import RpcError from "types/lib/api/errors/rpc-error";
import { ServerConfig } from "types/lib/api/interfaces";
import logger from "./logger";
import { HttpStatus } from "./constants";

export class Server {
constructor(private app: FastifyInstance, private config: ServerConfig) {
Expand Down Expand Up @@ -70,16 +71,18 @@ export class Server {
data: err.data,
code: err.code,
};
return res.status(200).send({
return res.status(HttpStatus.OK).send({
jsonrpc: body.jsonrpc,
id: body.id,
error,
});
}

return res.status(err.statusCode ?? 500).send({
error: "Unexpected behaviour",
});
return res
.status(err.statusCode ?? HttpStatus.INTERNAL_SERVER_ERROR)
.send({
error: "Unexpected behaviour",
});
});

await this.app.listen({
Expand Down
10 changes: 5 additions & 5 deletions packages/cli/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "cli",
"version": "0.0.43",
"version": "0.0.44",
"description": "> TODO: description",
"author": "zincoshine <[email protected]>",
"homepage": "https://https://github.com/etherspot/skandha#readme",
Expand Down Expand Up @@ -31,13 +31,13 @@
"url": "https://https://github.com/etherspot/skandha/issues"
},
"dependencies": {
"api": "^0.0.43",
"db": "^0.0.43",
"executor": "^0.0.43",
"api": "^0.0.44",
"db": "^0.0.44",
"executor": "^0.0.44",
"find-up": "5.0.0",
"got": "12.5.3",
"js-yaml": "4.1.0",
"types": "^0.0.43",
"types": "^0.0.44",
"yargs": "17.6.2"
},
"devDependencies": {
Expand Down
2 changes: 2 additions & 0 deletions packages/cli/src/cmds/start/handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,15 @@ export async function bundlerHandler(
networks: configOptions.networks,
testingMode,
unsafeMode,
redirectRpc,
});
} catch (err) {
logger.debug("Config file not found. Proceeding with env vars...");
config = new Config({
networks: {},
testingMode,
unsafeMode,
redirectRpc,
});
}

Expand Down
4 changes: 2 additions & 2 deletions packages/db/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "db",
"version": "0.0.43",
"version": "0.0.44",
"description": "The DB module of Etherspot bundler client",
"author": "Etherspot",
"homepage": "https://github.com/etherspot/etherspot-bundler#readme",
Expand Down Expand Up @@ -37,6 +37,6 @@
"devDependencies": {
"@types/rocksdb": "3.0.1",
"prettier": "^2.8.4",
"types": "^0.0.43"
"types": "^0.0.44"
}
}
6 changes: 3 additions & 3 deletions packages/executor/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "executor",
"version": "0.0.43",
"version": "0.0.44",
"description": "The Relayer module of Etherspot bundler client",
"author": "Etherspot",
"homepage": "https://https://github.com/etherspot/skandha#readme",
Expand Down Expand Up @@ -33,7 +33,7 @@
"dependencies": {
"async-mutex": "0.4.0",
"ethers": "5.7.2",
"params": "^0.0.43",
"types": "^0.0.43"
"params": "^0.0.44",
"types": "^0.0.44"
}
}
9 changes: 7 additions & 2 deletions packages/executor/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,14 @@ export class Config {
networks: Networks;
testingMode: boolean;
unsafeMode: boolean;
redirectRpc: boolean;

constructor(private config: ConfigOptions) {
this.supportedNetworks = this.parseSupportedNetworks();
this.networks = this.parseNetworkConfigs();
this.testingMode = config.testingMode ?? false;
this.unsafeMode = config.unsafeMode ?? false;
this.redirectRpc = config.redirectRpc ?? false;
this.supportedNetworks = this.parseSupportedNetworks();
this.networks = this.parseNetworkConfigs();
}

getNetworkProvider(network: NetworkName): providers.JsonRpcProvider | null {
Expand Down Expand Up @@ -64,6 +66,9 @@ export class Config {
}

private parseSupportedNetworks(): NetworkName[] {
if (this.testingMode) {
return ["dev"];
}
const envNetworks = NETWORKS_ENV();
if (envNetworks) {
return envNetworks.map((key) => key as NetworkName);
Expand Down
2 changes: 1 addition & 1 deletion packages/executor/src/executor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ export class Executor {
this.skandha = new Skandha(
this.network,
this.provider,
this.networkConfig,
this.config,
this.logger
);

Expand Down
1 change: 1 addition & 0 deletions packages/executor/src/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ export interface ConfigOptions {
networks: Networks;
testingMode?: boolean;
unsafeMode: boolean;
redirectRpc: boolean;
}

export interface SlotMap {
Expand Down
15 changes: 3 additions & 12 deletions packages/executor/src/modules/eth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,22 +160,13 @@ export class Eth {
//>

// Binary search gas limits
let userOpToEstimate: UserOperationStruct = {
const userOpToEstimate: UserOperationStruct = {
...userOpComplemented,
preVerificationGas,
verificationGasLimit,
callGasLimit,
};

// binary search vgl and cgl
try {
userOpToEstimate = await this.userOpValidationService.binarySearchVGL(
userOpToEstimate,
entryPoint
);
// eslint-disable-next-line no-empty
} catch (err) {}

const gasFee = await getGasFee(
this.networkName,
this.provider,
Expand All @@ -190,8 +181,8 @@ export class Eth {
preVerificationGas,
verificationGasLimit: userOpToEstimate.verificationGasLimit,
verificationGas: userOpToEstimate.verificationGasLimit,
validAfter: BigNumber.from(validAfter),
validUntil: BigNumber.from(validUntil),
validAfter: validAfter ? BigNumber.from(validAfter) : undefined,
validUntil: validUntil ? BigNumber.from(validUntil) : undefined,
callGasLimit: userOpToEstimate.callGasLimit,
maxFeePerGas: gasFee.maxFeePerGas,
maxPriorityFeePerGas: gasFee.maxPriorityFeePerGas,
Expand Down
Loading

0 comments on commit 1d6f494

Please sign in to comment.