Skip to content

Commit

Permalink
feat: added a new debug endpoint debug_setMempool (#94)
Browse files Browse the repository at this point in the history
* Added a new debug endpoint debug_bundler_setMempool which will be used to seed local mempool

* fix typo

* chore(release): 1.0.9-alpha

---------

Co-authored-by: ch4r10t33r <[email protected]>
Co-authored-by: 0xSulpiride <[email protected]>
  • Loading branch information
3 people authored Oct 12, 2023
1 parent 4502750 commit 50a1d30
Show file tree
Hide file tree
Showing 28 changed files with 103 additions and 42 deletions.
6 changes: 3 additions & 3 deletions P2P.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,12 @@ Example:

### Run the bootnode

`./skandha node --testingMode --redirectRpc --executor.bundlingMode manual`
`./skandha node --redirectRpc --executor.bundlingMode manual`

### Run a regular node

`./skandha node --testingMode --redirectRpc --executor.bundlingMode manual --dataDir ./db --api.port 14338 --p2p.port 4338 --p2p.enrPort 4338 --p2p.bootEnrs [enr]`
`./skandha node --redirectRpc --executor.bundlingMode manual --dataDir ./db --api.port 14338 --p2p.port 4338 --p2p.enrPort 4338 --p2p.bootEnrs [enr]`

### Run the second regular node

`./skandha node --testingMode --redirectRpc --executor.bundlingMode manual --dataDir ./db2 --api.port 14339 --p2p.port 4339 --p2p.enrPort 4339 --p2p.bootEnrs [enr]`
`./skandha node --redirectRpc --executor.bundlingMode manual --dataDir ./db2 --api.port 14339 --p2p.port 4339 --p2p.enrPort 4339 --p2p.bootEnrs [enr]`
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": "1.0.8-alpha",
"version": "1.0.9-alpha",
"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": "1.0.8-alpha",
"version": "1.0.9-alpha",
"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": "1.0.8-alpha",
"version": "1.0.9-alpha",
"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": "^1.0.8-alpha",
"executor": "^1.0.9-alpha",
"fastify": "4.14.1",
"pino": "8.11.0",
"pino-pretty": "10.0.0",
"reflect-metadata": "0.1.13",
"types": "^1.0.8-alpha"
"types": "^1.0.9-alpha"
},
"devDependencies": {
"@types/connect": "3.4.35"
Expand Down
7 changes: 7 additions & 0 deletions packages/api/src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,13 @@ export class ApiApp {
case BundlerRPCMethods.debug_bundler_sendBundleNow:
result = await debugApi.sendBundleNow();
break;

case BundlerRPCMethods.debug_bundler_setMempool:
result = await debugApi.setMempool({
userOps: params[0],
entryPoint: params[1],
});
break;
}
}

Expand Down
1 change: 1 addition & 0 deletions packages/api/src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export const BundlerRPCMethods = {
debug_bundler_setBundlingMode: "debug_bundler_setBundlingMode",
debug_bundler_setBundleInterval: "debug_bundler_setBundleInterval",
debug_bundler_sendBundleNow: "debug_bundler_sendBundleNow",
debug_bundler_setMempool: "debug_bundler_setMempool",
};

export const RedirectedRPCMethods = {
Expand Down
17 changes: 17 additions & 0 deletions packages/api/src/dto/SetMempool.dto.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import {
IsArray,
IsDefined,
IsEthereumAddress,
ValidateNested,
} from "class-validator";
import { SendUserOperationStruct } from "./SendUserOperation.dto";

export class SetMempoolArgs {
@IsDefined()
@IsArray()
@ValidateNested()
userOps!: SendUserOperationStruct[];

@IsEthereumAddress()
entryPoint!: string;
}
11 changes: 11 additions & 0 deletions packages/api/src/modules/debug.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
SetReputationResponse,
} from "../dto/SetReputation.dto";
import { SetBundlingIntervalArgs } from "../dto/SetBundlingInterval.dto";
import { SetMempoolArgs } from "../dto/SetMempool.dto";

export class DumpReputationArgs {
@IsEthereumAddress()
Expand Down Expand Up @@ -86,4 +87,14 @@ export class DebugAPI {
async setBundlingInterval(args: SetBundlingIntervalArgs): Promise<string> {
return await this.debugModule.setBundlingInterval(args.interval);
}

/**
* Seeds the local mempool with the passed array. Parameters:
* userOps - An array of UserOperations.
* returns "ok"
*/
@RpcMethodValidator(SetMempoolArgs)
async setMempool(args: SetMempoolArgs): Promise<string> {
return await this.debugModule.setMempool(args);
}
}
12 changes: 6 additions & 6 deletions packages/cli/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "cli",
"version": "1.0.8-alpha",
"version": "1.0.9-alpha",
"description": "> TODO: description",
"author": "zincoshine <[email protected]>",
"homepage": "https://https://github.com/etherspot/skandha#readme",
Expand Down Expand Up @@ -38,14 +38,14 @@
"@libp2p/peer-id-factory": "2.0.1",
"@libp2p/prometheus-metrics": "1.1.3",
"@multiformats/multiaddr": "12.1.3",
"api": "^1.0.8-alpha",
"db": "^1.0.8-alpha",
"executor": "^1.0.8-alpha",
"api": "^1.0.9-alpha",
"db": "^1.0.9-alpha",
"executor": "^1.0.9-alpha",
"find-up": "5.0.0",
"got": "12.5.3",
"js-yaml": "4.1.0",
"node": "^1.0.8-alpha",
"types": "^1.0.8-alpha",
"node": "^1.0.9-alpha",
"types": "^1.0.9-alpha",
"yargs": "17.6.2"
},
"devDependencies": {
Expand Down
1 change: 0 additions & 1 deletion packages/cli/src/options/logOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ export const LOG_FILE_DISABLE_KEYWORD = "none";
export const LOG_LEVEL_DEFAULT = LogLevel.info;
export const LOG_FILE_LEVEL_DEFAULT = LogLevel.debug;
export const LOG_DAILY_ROTATE_DEFAULT = 5;
const DATE_PATTERN = "YYYY-MM-DD";

export interface ILogArgs {
logLevel?: LogLevel;
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": "1.0.8-alpha",
"version": "1.0.9-alpha",
"description": "The DB module of Etherspot bundler client",
"author": "Etherspot",
"homepage": "https://github.com/etherspot/etherspot-bundler#readme",
Expand Down Expand Up @@ -33,7 +33,7 @@
"dependencies": {
"@chainsafe/ssz": "0.10.1",
"@farcaster/rocksdb": "5.5.0",
"types": "^1.0.8-alpha"
"types": "^1.0.9-alpha"
},
"devDependencies": {
"@types/rocksdb": "3.0.1",
Expand Down
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": "1.0.8-alpha",
"version": "1.0.9-alpha",
"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": "^1.0.8-alpha",
"types": "^1.0.8-alpha"
"params": "^1.0.9-alpha",
"types": "^1.0.9-alpha"
}
}
27 changes: 27 additions & 0 deletions packages/executor/src/modules/debug.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import { providers } from "ethers";
import RpcError from "types/lib/api/errors/rpc-error";
import * as RpcErrorCodes from "types/lib/api/errors/rpc-error-codes";
import { UserOperationStruct } from "types/lib/executor/contracts/EntryPoint";
import { SetMempoolArgs } from "api/src/dto/SetMempool.dto";
import { IEntryPoint__factory } from "types/lib/executor/contracts";
import {
BundlingService,
MempoolService,
Expand Down Expand Up @@ -97,4 +99,29 @@ export class Debug {
async dumpReputation(entryPoint: string): Promise<ReputationEntryDump[]> {
return await this.reputationService.dump();
}

async setMempool(mempool: SetMempoolArgs): Promise<string> {
const entryPointContract = IEntryPoint__factory.connect(
mempool.entryPoint,
this.provider
);
await this.mempoolService.clearState();
// Loop through the array and persist to the local mempool without simulation.
for (const userOp of mempool.userOps) {
const userOpHash = await entryPointContract.getUserOpHash(userOp);
await this.mempoolService.addUserOp(
userOp,
mempool.entryPoint,
0x0,
{
addr: userOp.sender,
stake: 0,
unstakeDelaySec: 0,
},
userOpHash,
undefined
);
}
return "ok";
}
}
1 change: 1 addition & 0 deletions packages/executor/src/modules/eth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,7 @@ export class Eth {

validateEntryPoint(entryPoint: string): boolean {
return (
(this.config.entryPoints as any) &&
this.config.entryPoints.findIndex(
(ep) => ep.toLowerCase() === entryPoint.toLowerCase()
) !== -1
Expand Down
14 changes: 7 additions & 7 deletions packages/node/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "node",
"version": "1.0.8-alpha",
"version": "1.0.9-alpha",
"description": "The bundler node module of Etherspot bundler client",
"author": "Etherspot",
"homepage": "https://https://github.com/etherspot/skandha#readme",
Expand Down Expand Up @@ -56,24 +56,24 @@
"@libp2p/tcp": "6.1.0",
"@multiformats/multiaddr": "11.4.0",
"abstract-leveldown": "7.2.0",
"api": "^1.0.8-alpha",
"api": "^1.0.9-alpha",
"datastore-core": "8.0.1",
"db": "^1.0.8-alpha",
"db": "^1.0.9-alpha",
"ethers": "5.7.2",
"executor": "^1.0.8-alpha",
"executor": "^1.0.9-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",
"params": "^1.0.8-alpha",
"params": "^1.0.9-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.8-alpha",
"utils": "^1.0.8-alpha",
"types": "^1.0.9-alpha",
"utils": "^1.0.9-alpha",
"varint": "6.0.0",
"xxhash-wasm": "1.0.2"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/node/src/network/peers/peerManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Connection } from "@libp2p/interface-connection";
import { PeerId } from "@libp2p/interface-peer-id";
import { IDiscv5DiscoveryInputOptions } from "@chainsafe/discv5";
import Logger from "api/lib/logger";
import { ts, ssz } from "types/lib";
import { ts } from "types/lib";
import { devNetworkConfig } from "params/lib/networks/dev";
import {
GoodByeReasonCode,
Expand Down
1 change: 0 additions & 1 deletion packages/node/src/network/peers/utils/prioritizePeers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { Direction } from "@libp2p/interface-connection";
import { ts, ssz } from "types/lib";
import { shuffle, sortBy, MapDef } from "utils/lib";
import { BitArray } from "@chainsafe/ssz";
import logger from "api/lib/logger";
import { RequestedSubnet } from "./subnetMap";

/** Target number of peers we'd like to have connected to a given long-lived subnet */
Expand Down
1 change: 0 additions & 1 deletion packages/node/src/network/reqresp/ReqRespNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import { IReqRespNode } from "./interface";
import { onOutgoingReqRespError } from "./score";
import { ReqRespMethod, RequestTypedContainer, Version } from "./types";
import { ReqRespHandlers } from "./handlers";
export { IReqRespNode };

// eslint-disable-next-line @typescript-eslint/no-explicit-any
type ProtocolDefinitionAny = ProtocolDefinition<any, any>;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { NetworkName, ts, ssz } from "types/lib";
import { ts, ssz } from "types/lib";
import { Config } from "executor/lib/config";
import { Executors } from "executor/lib/interfaces";
import { networksConfig, deserializeMempoolId } from "params/lib";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export async function* onPooledUserOpsByHash(
logger.debug(`UserOpsByHash, received hashes: ${userOpHashes.join(", ")}`);
const { supportedNetworks } = relayersConfig;
const chainId = Object.values(supportedNetworks).at(0); // OK: any network works
// eslint-disable-next-line @typescript-eslint/strict-boolean-expressions
if (!chainId) {
throw new ResponseError(RespStatus.SERVER_ERROR, "No network found");
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { toHexString } from "@chainsafe/ssz";
import { Config } from "executor/lib/config";
import { NetworkName, ts } from "types/lib";
import { ts } from "types/lib";
import { GossipErrorCode, GossipValidationError } from "../gossip/errors";

export async function validateGossipUserOpsWithEntryPoint(
Expand Down
1 change: 0 additions & 1 deletion packages/node/src/reqresp/encoders/responseDecode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import {
MixedProtocolDefinition,
} from "../types";
import { RespStatus } from "../interface";
import logger from "api/lib/logger";

/**
* Internal helper type to signal stream ended early
Expand Down
2 changes: 1 addition & 1 deletion packages/node/src/reqresp/protocols/PooledUserOpHashes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export const PooledUserOpHashes: DuplexProtocolDefinitionGenerator<
ts.PooledUserOpHashes
> = (modules, handler) => {
return {
method: "pooled_user_op_hashes",
method: "pooled_user_ops_hashes",
version: 1,
encoding: Encoding.SSZ_SNAPPY,
requestType: () => ssz.PooledUserOpHashesRequest,
Expand Down
2 changes: 1 addition & 1 deletion packages/node/src/utils/peerMap.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {PeerId} from "@libp2p/interface-peer-id";
import { PeerId } from "@libp2p/interface-peer-id";

export class PeerSet {
private peerMap = new PeerMap<PeerId>();
Expand Down
6 changes: 3 additions & 3 deletions packages/params/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "params",
"version": "1.0.8-alpha",
"version": "1.0.9-alpha",
"description": "Various bundler parameters",
"author": "Etherspot",
"homepage": "https://github.com/etherspot/skandha#readme",
Expand All @@ -26,8 +26,8 @@
"@eth-optimism/sdk": "3.0.0",
"@mantleio/sdk": "0.2.1",
"ethers": "5.7.2",
"types": "^1.0.8-alpha",
"utils": "^1.0.8-alpha"
"types": "^1.0.9-alpha",
"utils": "^1.0.9-alpha"
},
"scripts": {
"clean": "rm -rf lib && rm -f *.tsbuildinfo",
Expand Down
2 changes: 1 addition & 1 deletion packages/params/src/gas-price-oracles/oracles/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export async function getEtherscanGasFee(
maxFeePerGas: gasPrice,
gasPrice: gasPrice,
};
};
}

export function parseGwei(num: number | string): BigNumber {
if (typeof num !== "number") {
Expand Down
2 changes: 1 addition & 1 deletion packages/types/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "types",
"version": "1.0.8-alpha",
"version": "1.0.9-alpha",
"description": "The types of Etherspot bundler client",
"author": "Etherspot",
"homepage": "https://https://github.com/etherspot/skandha#readme",
Expand Down
Loading

0 comments on commit 50a1d30

Please sign in to comment.