Skip to content

Commit

Permalink
Prometheus (#116)
Browse files Browse the repository at this point in the history
  • Loading branch information
0xSulpiride authored Nov 13, 2023
1 parent 996712a commit 79376dc
Show file tree
Hide file tree
Showing 52 changed files with 594 additions and 88 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": "1.0.20-alpha",
"version": "1.0.21-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.20-alpha",
"version": "1.0.21-alpha",
"engines": {
"node": ">=18.0.0"
},
Expand Down
7 changes: 4 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.20-alpha",
"version": "1.0.21-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,13 @@
"class-transformer": "0.5.1",
"class-validator": "0.14.0",
"ethers": "5.7.2",
"executor": "^1.0.20-alpha",
"executor": "^1.0.21-alpha",
"fastify": "4.14.1",
"monitoring": "^1.0.21-alpha",
"pino": "8.11.0",
"pino-pretty": "10.0.0",
"reflect-metadata": "0.1.13",
"types": "^1.0.20-alpha"
"types": "^1.0.21-alpha"
},
"devDependencies": {
"@types/connect": "3.4.35"
Expand Down
13 changes: 7 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.20-alpha",
"version": "1.0.21-alpha",
"description": "> TODO: description",
"author": "zincoshine <[email protected]>",
"homepage": "https://https://github.com/etherspot/skandha#readme",
Expand Down Expand Up @@ -38,14 +38,15 @@
"@libp2p/peer-id-factory": "2.0.1",
"@libp2p/prometheus-metrics": "1.1.3",
"@multiformats/multiaddr": "12.1.3",
"api": "^1.0.20-alpha",
"db": "^1.0.20-alpha",
"executor": "^1.0.20-alpha",
"api": "^1.0.21-alpha",
"db": "^1.0.21-alpha",
"executor": "^1.0.21-alpha",
"find-up": "5.0.0",
"got": "12.5.3",
"js-yaml": "4.1.0",
"node": "^1.0.20-alpha",
"types": "^1.0.20-alpha",
"monitoring": "^1.0.21-alpha",
"node": "^1.0.21-alpha",
"types": "^1.0.21-alpha",
"yargs": "17.6.2"
},
"devDependencies": {
Expand Down
9 changes: 9 additions & 0 deletions packages/cli/src/cmds/node/handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { BundlerNode, IBundlerNodeOptions, defaultOptions } from "node/lib";
import { initNetworkOptions } from "node/lib";
import logger from "api/lib/logger";
import { ExecutorOptions, ApiOptions, P2POptions } from "types/lib/options";
import { MetricsOptions } from "types/lib/options/metrics";
import { IGlobalArgs } from "../../options";
import { mkdir, readFile } from "../../util";
import { initPeerIdAndEnr } from "./initPeerIdAndEnr";
Expand Down Expand Up @@ -75,6 +76,7 @@ export async function nodeHandler(args: IGlobalArgs): Promise<void> {
redirectRpc: params.redirectRpc,
bundlingMode: params.executor.bundlingMode,
peerId,
metricsOptions: params.metrics,
});

await node.start();
Expand All @@ -89,6 +91,7 @@ export async function getNodeConfigFromArgs(args: IGlobalArgs): Promise<{
p2p: P2POptions;
api: ApiOptions;
executor: ExecutorOptions;
metrics: MetricsOptions;
}> {
const entries = new Map(Object.entries(args));

Expand All @@ -98,6 +101,7 @@ export async function getNodeConfigFromArgs(args: IGlobalArgs): Promise<{
unsafeMode: entries.get("unsafeMode"),
testingMode: entries.get("testingMode"),
redirectRpc: entries.get("redirectRpc"),
enableMetrics: entries.get("enableMetrics"),
p2p: {
host: entries.get("p2p.host"),
port: entries.get("p2p.port"),
Expand All @@ -115,6 +119,11 @@ export async function getNodeConfigFromArgs(args: IGlobalArgs): Promise<{
executor: {
bundlingMode: entries.get("executor.bundlingMode"),
},
metrics: {
enable: entries.get("metrics.enable"),
port: entries.get("metrics.port"),
host: entries.get("metrics.host"),
},
};

return ret;
Expand Down
18 changes: 18 additions & 0 deletions packages/cli/src/cmds/standalone/handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { IDbController } from "types/lib";
import { Executors } from "executor/lib/interfaces";
import { Executor } from "executor/lib/executor";
import logger from "api/lib/logger";
import { createMetrics, getHttpMetricsServer } from "monitoring/lib";
import { mkdir, readFile } from "../../util";
import { IStandaloneGlobalArgs } from "../../options";

Expand Down Expand Up @@ -83,31 +84,48 @@ export async function bundlerHandler(
cors: args["api.cors"],
});

const metrics = args["metrics.enable"]
? createMetrics({ p2p: false }, logger)
: null;

const executors: Executors = new Map<number, Executor>();
if (config.testingMode) {
metrics?.addChain(1337);
const executor = new Executor({
network: "dev",
chainId: 1337,
db: db,
config: config,
logger: logger,
bundlingMode: args["executor.bundlingMode"],
metrics: metrics?.chains[1337] || null,
});
executors.set(1337, executor);
} else {
for (const [network, chainId] of Object.entries(config.supportedNetworks)) {
metrics?.addChain(chainId);
const executor = new Executor({
network,
chainId,
db: db,
config: config,
logger: logger,
bundlingMode: args["executor.bundlingMode"],
metrics: metrics?.chains[chainId] || null,
});
executors.set(chainId, executor);
}
}

args["metrics.enable"]
? await getHttpMetricsServer(
args["metrics.port"],
args["metrics.host"],
metrics!.registry,
logger
)
: null;

new ApiApp({
server: server.application,
config: config,
Expand Down
41 changes: 41 additions & 0 deletions packages/cli/src/options/bundlerOptions/metrics.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import { defaultMetricsOptions } from "types/lib/options/metrics";
import { ICliCommandOptions } from "../../util";
import { IBundlerOptions } from "./options";

export interface IMetricsArgs {
"metrics.enable": boolean;
"metrics.host": string;
"metrics.port": number;
}

export function parseArgs(args: IMetricsArgs): IBundlerOptions["metrics"] {
return {
enable: args["metrics.enable"],
host: args["metrics.host"],
port: args["metrics.port"],
};
}

export const options: ICliCommandOptions<IMetricsArgs> = {
"metrics.enable": {
type: "boolean",
description: "Enable monitoring",
default: defaultMetricsOptions.enable,
group: "metrics",
demandOption: false,
},
"metrics.host": {
type: "string",
description: "Metrics host",
default: defaultMetricsOptions.host,
group: "metrics",
demandOption: false,
},
"metrics.port": {
type: "number",
description: "Metrics port",
default: defaultMetricsOptions.port,
group: "metrics",
demandOption: false,
},
};
2 changes: 2 additions & 0 deletions packages/cli/src/options/bundlerOptions/options.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import { ApiOptions } from "types/lib/options/api";
import { ExecutorOptions } from "types/lib/options/executor";
import { MetricsOptions } from "types/lib/options/metrics";
import { P2POptions } from "types/lib/options/network";

export interface IBundlerOptions {
api: ApiOptions;
p2p: P2POptions;
executor: ExecutorOptions;
metrics: MetricsOptions;
}
9 changes: 8 additions & 1 deletion packages/cli/src/options/globalOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ import {
IExecutorArgs,
options as executorOptions,
} from "./bundlerOptions/executor";
import {
IMetricsArgs,
options as metricsOptions,
} from "./bundlerOptions/metrics";

const __dirname = process.cwd();

Expand Down Expand Up @@ -61,14 +65,17 @@ export const globalOptions = {
...apiOptions,
...networkOptions,
...executorOptions,
...metricsOptions,
};

export type IStandaloneGlobalArgs = IGlobalSingleArgs &
IApiArgs &
IExecutorArgs;
IExecutorArgs &
IMetricsArgs;

export const standaloneGlobalOptions = {
...globalSingleOptions,
...apiOptions,
...executorOptions,
...metricsOptions,
};
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.20-alpha",
"version": "1.0.21-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.20-alpha"
"types": "^1.0.21-alpha"
},
"devDependencies": {
"@types/rocksdb": "3.0.1",
Expand Down
7 changes: 4 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.20-alpha",
"version": "1.0.21-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,8 @@
"dependencies": {
"async-mutex": "0.4.0",
"ethers": "5.7.2",
"params": "^1.0.20-alpha",
"types": "^1.0.20-alpha"
"monitoring": "^1.0.21-alpha",
"params": "^1.0.21-alpha",
"types": "^1.0.21-alpha"
}
}
13 changes: 9 additions & 4 deletions packages/executor/src/executor.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
/* eslint-disable @typescript-eslint/explicit-member-accessibility */
import { BigNumber, providers } from "ethers";
import { IDbController } from "types/lib";
import { NetworkName } from "types/lib";
import { IDbController, NetworkName, Logger } from "types/lib";
import { INodeAPI } from "types/lib/node";
import { chainsWithoutEIP1559 } from "params/lib";
import { PerChainMetrics } from "monitoring/lib";
import { Web3, Debug, Eth, Skandha } from "./modules";
import {
MempoolService,
Expand All @@ -13,7 +13,7 @@ import {
P2PService,
} from "./services";
import { Config } from "./config";
import { BundlingMode, Logger, NetworkConfig } from "./interfaces";
import { BundlingMode, NetworkConfig } from "./interfaces";

export interface ExecutorOptions {
network: NetworkName;
Expand All @@ -23,11 +23,13 @@ export interface ExecutorOptions {
logger: Logger;
nodeApi?: INodeAPI;
bundlingMode: BundlingMode;
metrics: PerChainMetrics | null;
}

export class Executor {
private networkConfig: NetworkConfig;
private logger: Logger;
private metrics: PerChainMetrics | null;

public chainId: number;
public networkName: NetworkName;
Expand Down Expand Up @@ -56,6 +58,7 @@ export class Executor {
this.logger = options.logger;
this.chainId = options.chainId;
this.nodeApi = options.nodeApi;
this.metrics = options.metrics;

this.networkConfig = options.config.networks[
options.network
Expand Down Expand Up @@ -96,7 +99,8 @@ export class Executor {
this.userOpValidationService,
this.reputationService,
this.config,
this.logger
this.logger,
this.metrics
);
this.web3 = new Web3(this.config);
this.debug = new Debug(
Expand All @@ -120,6 +124,7 @@ export class Executor {
this.skandha,
this.networkConfig,
this.logger,
this.metrics,
this.nodeApi
);
this.p2pService = new P2PService(
Expand Down
17 changes: 0 additions & 17 deletions packages/executor/src/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,23 +71,6 @@ export type EthChainIdResponse = { chainId: number };

export type BundlingMode = "auto" | "manual";

export interface LogFn {
/* tslint:disable:no-unnecessary-generics */
<T extends object>(obj: T, msg?: string, ...args: any[]): void;
(obj: unknown, msg?: string, ...args: any[]): void;
(msg: string, ...args: any[]): void;
}

export interface Logger {
fatal: LogFn;
error: LogFn;
warn: LogFn;
info: LogFn;
debug: LogFn;
trace: LogFn;
silent: LogFn;
}

export type Executors = Map<number, Executor>;
export interface NetworkConfig {
entryPoints: string[];
Expand Down
3 changes: 1 addition & 2 deletions packages/executor/src/modules/debug.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ 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,
Expand All @@ -11,7 +10,7 @@ import {
} from "../services";
import { BundlingMode } from "../interfaces";
import { ReputationEntryDump } from "../entities/interfaces";
import { SetReputationArgs } from "./interfaces";
import { SetReputationArgs, SetMempoolArgs } from "./interfaces";
/*
SPEC: https://eips.ethereum.org/EIPS/eip-4337#rpc-methods-debug-namespace
*/
Expand Down
Loading

0 comments on commit 79376dc

Please sign in to comment.