From 276f80fe58696256b664c325ac87db759c2d3947 Mon Sep 17 00:00:00 2001 From: marie-fourier Date: Fri, 2 Feb 2024 17:17:25 +0500 Subject: [PATCH 1/3] feat: some debugging tools --- packages/api/src/app.ts | 22 +++++++++++++++---- packages/api/src/constants.ts | 1 + packages/api/src/modules/debug.ts | 5 +++++ packages/executor/src/modules/debug.ts | 14 +++++++++++- .../src/services/BundlingService/service.ts | 8 +++++++ 5 files changed, 45 insertions(+), 5 deletions(-) diff --git a/packages/api/src/app.ts b/packages/api/src/app.ts index 46426468..14f75a4f 100644 --- a/packages/api/src/app.ts +++ b/packages/api/src/app.ts @@ -84,11 +84,20 @@ export class ApiApp { const redirectApi = new RedirectAPI(executor.networkName, this.config); const skandhaApi = new SkandhaAPI(executor.eth, executor.skandha); - const handleRpc = async (ip: string, request: any): Promise => { + const handleRpc = async ( + ip: string, + request: any, + auth: string | undefined + ): Promise => { let result: any; const { method, params, jsonrpc, id } = request; // ADMIN METHODS - if (this.testingMode || ip === "localhost" || ip === "127.0.0.1") { + if ( + this.testingMode || + ip === "localhost" || + ip === "127.0.0.1" || + (process.env.ADMIN_KEY && auth === process.env.ADMIN_KEY) + ) { switch (method) { case BundlerRPCMethods.debug_bundler_setBundlingMode: result = await debugApi.setBundlingMode(params[0]); @@ -107,6 +116,9 @@ export class ApiApp { case BundlerRPCMethods.debug_bundler_dumpMempool: result = await debugApi.dumpMempool(/* params[0] */); break; + case BundlerRPCMethods.debug_bundler_dumpMempoolRaw: + result = await debugApi.dumpMempoolRaw(/* params[0] */); + break; case BundlerRPCMethods.debug_bundler_setReputation: result = await debugApi.setReputation({ reputations: params[0], @@ -219,10 +231,12 @@ export class ApiApp { if (Array.isArray(req.body)) { response = []; for (const request of req.body) { - response.push(await handleRpc(req.ip, request)); + response.push( + await handleRpc(req.ip, request, req.headers.authorization) + ); } } else { - response = await handleRpc(req.ip, req.body); + response = await handleRpc(req.ip, req.body, req.headers.authorization); } return res.status(HttpStatus.OK).send(response); }; diff --git a/packages/api/src/constants.ts b/packages/api/src/constants.ts index b19674e6..1e51be59 100644 --- a/packages/api/src/constants.ts +++ b/packages/api/src/constants.ts @@ -15,6 +15,7 @@ export const BundlerRPCMethods = { web3_clientVersion: "web3_clientVersion", debug_bundler_clearState: "debug_bundler_clearState", debug_bundler_dumpMempool: "debug_bundler_dumpMempool", + debug_bundler_dumpMempoolRaw: "debug_bundler_dumpMempoolRaw", debug_bundler_setReputation: "debug_bundler_setReputation", debug_bundler_dumpReputation: "debug_bundler_dumpReputation", debug_bundler_setBundlingMode: "debug_bundler_setBundlingMode", diff --git a/packages/api/src/modules/debug.ts b/packages/api/src/modules/debug.ts index 2e7172de..00732347 100644 --- a/packages/api/src/modules/debug.ts +++ b/packages/api/src/modules/debug.ts @@ -3,6 +3,7 @@ import { Debug } from "executor/lib/modules"; import { IsEthereumAddress } from "class-validator"; import { BundlingMode } from "types/lib/api/interfaces"; import { GetStakeStatus } from "executor/lib/interfaces"; +import { MempoolEntrySerialized } from "executor/src/entities/interfaces"; import { RpcMethodValidator } from "../utils/RpcMethodValidator"; import { SetReputationArgs, @@ -53,6 +54,10 @@ export class DebugAPI { return await this.debugModule.dumpMempool(); } + async dumpMempoolRaw(): Promise { + return await this.debugModule.dumpMempoolRaw(); + } + /** * Forces the bundler to build and execute a bundle from the mempool as handleOps() transaction */ diff --git a/packages/executor/src/modules/debug.ts b/packages/executor/src/modules/debug.ts index 8e650832..7b51f36d 100644 --- a/packages/executor/src/modules/debug.ts +++ b/packages/executor/src/modules/debug.ts @@ -13,7 +13,10 @@ import { ReputationService, } from "../services"; import { BundlingMode, GetStakeStatus, NetworkConfig } from "../interfaces"; -import { ReputationEntryDump } from "../entities/interfaces"; +import { + MempoolEntrySerialized, + ReputationEntryDump, +} from "../entities/interfaces"; import { getAddr } from "../utils"; import { SetReputationArgs, SetMempoolArgs } from "./interfaces"; /* @@ -71,6 +74,15 @@ export class Debug { .map((entry) => entry.userOp); } + /** + * Dumps the current UserOperations mempool + * array - Array of UserOperations currently in the mempool + */ + async dumpMempoolRaw(): Promise { + const entries = await this.mempoolService.dump(); + return entries.map((entry) => entry); + } + /** * Forces the bundler to build and execute a bundle from the mempool as handleOps() transaction */ diff --git a/packages/executor/src/services/BundlingService/service.ts b/packages/executor/src/services/BundlingService/service.ts index e9be09a5..c0cffcbe 100644 --- a/packages/executor/src/services/BundlingService/service.ts +++ b/packages/executor/src/services/BundlingService/service.ts @@ -327,6 +327,14 @@ export class BundlingService { async sendNextBundle(): Promise { await this.mutex.runExclusive(async () => { let relayersCount = this.relayer.getAvailableRelayersCount(); + if (relayersCount == 0) { + if ( + (await this.mempoolService.getNewEntriesSorted(this.maxBundleSize)) + .length > 0 + ) { + this.logger.debug("All relayers are busy"); + } + } while (relayersCount-- > 0) { let entries = await this.mempoolService.getNewEntriesSorted( this.maxBundleSize From ed83c31c07e838e05d9dc8bd9b7200181db55c81 Mon Sep 17 00:00:00 2001 From: marie-fourier Date: Fri, 2 Feb 2024 17:19:29 +0500 Subject: [PATCH 2/3] chore(release): 1.0.33-alpha --- lerna.json | 2 +- package.json | 2 +- packages/api/package.json | 8 ++++---- packages/cli/package.json | 14 +++++++------- packages/db/package.json | 4 ++-- packages/executor/package.json | 8 ++++---- packages/monitoring/package.json | 4 ++-- packages/node/package.json | 16 ++++++++-------- packages/params/package.json | 6 +++--- packages/types/package.json | 2 +- packages/utils/package.json | 4 ++-- 11 files changed, 35 insertions(+), 35 deletions(-) diff --git a/lerna.json b/lerna.json index cc64be6b..49b16d10 100644 --- a/lerna.json +++ b/lerna.json @@ -4,7 +4,7 @@ ], "npmClient": "yarn", "useWorkspaces": true, - "version": "1.0.32-alpha", + "version": "1.0.33-alpha", "stream": "true", "command": { "version": { diff --git a/package.json b/package.json index 82f1ccc4..091d82fa 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "root", "private": true, - "version": "1.0.32-alpha", + "version": "1.0.33-alpha", "engines": { "node": ">=18.0.0" }, diff --git a/packages/api/package.json b/packages/api/package.json index 7b4e3df9..d25385b2 100644 --- a/packages/api/package.json +++ b/packages/api/package.json @@ -1,6 +1,6 @@ { "name": "api", - "version": "1.0.32-alpha", + "version": "1.0.33-alpha", "description": "The API module of Etherspot bundler client", "author": "Etherspot", "homepage": "https://https://github.com/etherspot/skandha#readme", @@ -35,13 +35,13 @@ "class-transformer": "0.5.1", "class-validator": "0.14.0", "ethers": "5.7.2", - "executor": "^1.0.32-alpha", + "executor": "^1.0.33-alpha", "fastify": "4.14.1", - "monitoring": "^1.0.32-alpha", + "monitoring": "^1.0.33-alpha", "pino": "8.11.0", "pino-pretty": "10.0.0", "reflect-metadata": "0.1.13", - "types": "^1.0.32-alpha" + "types": "^1.0.33-alpha" }, "devDependencies": { "@types/connect": "3.4.35" diff --git a/packages/cli/package.json b/packages/cli/package.json index f805f9f0..713d2a10 100644 --- a/packages/cli/package.json +++ b/packages/cli/package.json @@ -1,6 +1,6 @@ { "name": "cli", - "version": "1.0.32-alpha", + "version": "1.0.33-alpha", "description": "> TODO: description", "author": "zincoshine ", "homepage": "https://https://github.com/etherspot/skandha#readme", @@ -38,15 +38,15 @@ "@libp2p/peer-id-factory": "2.0.1", "@libp2p/prometheus-metrics": "1.1.3", "@multiformats/multiaddr": "12.1.3", - "api": "^1.0.32-alpha", - "db": "^1.0.32-alpha", - "executor": "^1.0.32-alpha", + "api": "^1.0.33-alpha", + "db": "^1.0.33-alpha", + "executor": "^1.0.33-alpha", "find-up": "5.0.0", "got": "12.5.3", "js-yaml": "4.1.0", - "monitoring": "^1.0.32-alpha", - "node": "^1.0.32-alpha", - "types": "^1.0.32-alpha", + "monitoring": "^1.0.33-alpha", + "node": "^1.0.33-alpha", + "types": "^1.0.33-alpha", "yargs": "17.6.2" }, "devDependencies": { diff --git a/packages/db/package.json b/packages/db/package.json index 89febb23..8272f267 100644 --- a/packages/db/package.json +++ b/packages/db/package.json @@ -1,6 +1,6 @@ { "name": "db", - "version": "1.0.32-alpha", + "version": "1.0.33-alpha", "description": "The DB module of Etherspot bundler client", "author": "Etherspot", "homepage": "https://github.com/etherspot/etherspot-bundler#readme", @@ -33,7 +33,7 @@ "dependencies": { "@chainsafe/ssz": "0.10.1", "@farcaster/rocksdb": "5.5.0", - "types": "^1.0.32-alpha" + "types": "^1.0.33-alpha" }, "devDependencies": { "@types/rocksdb": "3.0.1", diff --git a/packages/executor/package.json b/packages/executor/package.json index a44715d2..e08403cb 100644 --- a/packages/executor/package.json +++ b/packages/executor/package.json @@ -1,6 +1,6 @@ { "name": "executor", - "version": "1.0.32-alpha", + "version": "1.0.33-alpha", "description": "The Relayer module of Etherspot bundler client", "author": "Etherspot", "homepage": "https://https://github.com/etherspot/skandha#readme", @@ -34,8 +34,8 @@ "@flashbots/ethers-provider-bundle": "0.6.2", "async-mutex": "0.4.0", "ethers": "5.7.2", - "monitoring": "^1.0.32-alpha", - "params": "^1.0.32-alpha", - "types": "^1.0.32-alpha" + "monitoring": "^1.0.33-alpha", + "params": "^1.0.33-alpha", + "types": "^1.0.33-alpha" } } diff --git a/packages/monitoring/package.json b/packages/monitoring/package.json index 91f3878e..cb821680 100644 --- a/packages/monitoring/package.json +++ b/packages/monitoring/package.json @@ -1,6 +1,6 @@ { "name": "monitoring", - "version": "1.0.32-alpha", + "version": "1.0.33-alpha", "description": "The Monitoring module of Etherspot bundler client", "author": "Etherspot", "homepage": "https://github.com/etherspot/etherspot-bundler#readme", @@ -32,6 +32,6 @@ }, "dependencies": { "prom-client": "^14.2.0", - "types": "^1.0.32-alpha" + "types": "^1.0.33-alpha" } } diff --git a/packages/node/package.json b/packages/node/package.json index 7c408d6c..a05fa4dd 100644 --- a/packages/node/package.json +++ b/packages/node/package.json @@ -1,6 +1,6 @@ { "name": "node", - "version": "1.0.32-alpha", + "version": "1.0.33-alpha", "description": "The bundler node module of Etherspot bundler client", "author": "Etherspot", "homepage": "https://https://github.com/etherspot/skandha#readme", @@ -56,25 +56,25 @@ "@libp2p/tcp": "6.1.0", "@multiformats/multiaddr": "11.4.0", "abstract-leveldown": "7.2.0", - "api": "^1.0.32-alpha", + "api": "^1.0.33-alpha", "datastore-core": "8.0.1", - "db": "^1.0.32-alpha", + "db": "^1.0.33-alpha", "ethers": "5.7.2", - "executor": "^1.0.32-alpha", + "executor": "^1.0.33-alpha", "it-filter": "1.0.2", "it-map": "1.0.5", "it-sort": "1.0.0", "it-take": "1.0.1", "libp2p": "0.42.2", - "monitoring": "^1.0.32-alpha", - "params": "^1.0.32-alpha", + "monitoring": "^1.0.33-alpha", + "params": "^1.0.33-alpha", "prettier": "2.8.4", "snappy": "7.2.2", "snappyjs": "0.7.0", "stream-to-it": "0.2.4", "strict-event-emitter-types": "2.0.0", - "types": "^1.0.32-alpha", - "utils": "^1.0.32-alpha", + "types": "^1.0.33-alpha", + "utils": "^1.0.33-alpha", "varint": "6.0.0", "xxhash-wasm": "1.0.2" }, diff --git a/packages/params/package.json b/packages/params/package.json index e118abeb..bf09a80c 100644 --- a/packages/params/package.json +++ b/packages/params/package.json @@ -1,6 +1,6 @@ { "name": "params", - "version": "1.0.32-alpha", + "version": "1.0.33-alpha", "description": "Various bundler parameters", "author": "Etherspot", "homepage": "https://github.com/etherspot/skandha#readme", @@ -26,8 +26,8 @@ "@eth-optimism/sdk": "3.0.0", "@mantleio/sdk": "0.2.1", "ethers": "5.7.2", - "types": "^1.0.32-alpha", - "utils": "^1.0.32-alpha" + "types": "^1.0.33-alpha", + "utils": "^1.0.33-alpha" }, "scripts": { "clean": "rm -rf lib && rm -f *.tsbuildinfo", diff --git a/packages/types/package.json b/packages/types/package.json index 17a33971..05bde326 100644 --- a/packages/types/package.json +++ b/packages/types/package.json @@ -1,6 +1,6 @@ { "name": "types", - "version": "1.0.32-alpha", + "version": "1.0.33-alpha", "description": "The types of Etherspot bundler client", "author": "Etherspot", "homepage": "https://https://github.com/etherspot/skandha#readme", diff --git a/packages/utils/package.json b/packages/utils/package.json index 6eb603a0..1c571200 100644 --- a/packages/utils/package.json +++ b/packages/utils/package.json @@ -1,6 +1,6 @@ { "name": "utils", - "version": "1.0.32-alpha", + "version": "1.0.33-alpha", "description": "utils of Etherspot bundler client", "author": "Etherspot", "homepage": "https://https://github.com/etherspot/skandha#readme", @@ -37,6 +37,6 @@ "case": "^1.6.3", "pino": "8.11.0", "pino-pretty": "10.0.0", - "types": "^1.0.32-alpha" + "types": "^1.0.33-alpha" } } From 240e5e642fd1f631343951276a174e6563fff07a Mon Sep 17 00:00:00 2001 From: marie-fourier Date: Fri, 2 Feb 2024 17:20:45 +0500 Subject: [PATCH 3/3] rename env var --- packages/api/src/app.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/api/src/app.ts b/packages/api/src/app.ts index 14f75a4f..2bdfcc8a 100644 --- a/packages/api/src/app.ts +++ b/packages/api/src/app.ts @@ -96,7 +96,7 @@ export class ApiApp { this.testingMode || ip === "localhost" || ip === "127.0.0.1" || - (process.env.ADMIN_KEY && auth === process.env.ADMIN_KEY) + (process.env.ADMIN_KEY && auth === process.env.SKANDHA_ADMIN_KEY) ) { switch (method) { case BundlerRPCMethods.debug_bundler_setBundlingMode: