Skip to content

Commit

Permalink
feat: some debugging tools
Browse files Browse the repository at this point in the history
  • Loading branch information
0xSulpiride committed Feb 2, 2024
1 parent a8b3f1f commit 276f80f
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 5 deletions.
22 changes: 18 additions & 4 deletions packages/api/src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<any> => {
const handleRpc = async (
ip: string,
request: any,
auth: string | undefined
): Promise<any> => {
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]);
Expand All @@ -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],
Expand Down Expand Up @@ -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);
};
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 @@ -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",
Expand Down
5 changes: 5 additions & 0 deletions packages/api/src/modules/debug.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -53,6 +54,10 @@ export class DebugAPI {
return await this.debugModule.dumpMempool();
}

async dumpMempoolRaw(): Promise<MempoolEntrySerialized[]> {
return await this.debugModule.dumpMempoolRaw();
}

/**
* Forces the bundler to build and execute a bundle from the mempool as handleOps() transaction
*/
Expand Down
14 changes: 13 additions & 1 deletion packages/executor/src/modules/debug.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
/*
Expand Down Expand Up @@ -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<MempoolEntrySerialized[]> {
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
*/
Expand Down
8 changes: 8 additions & 0 deletions packages/executor/src/services/BundlingService/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,14 @@ export class BundlingService {
async sendNextBundle(): Promise<void> {
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
Expand Down

0 comments on commit 276f80f

Please sign in to comment.