Skip to content

Commit

Permalink
feat: events service per ep version
Browse files Browse the repository at this point in the history
  • Loading branch information
0xSulpiride committed Feb 5, 2024
1 parent 6ba0409 commit 7241895
Show file tree
Hide file tree
Showing 30 changed files with 470 additions and 327 deletions.
32 changes: 16 additions & 16 deletions packages/api/src/dto/EstimateUserOperation.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,47 +37,47 @@ export class EstimateUserOperation {
/**
* EntryPoint v6 Properties
*/
@ValidateIf((o) => o.paymasterData)
@ValidateIf((o) => o.paymasterAndData)
@IsString()
@IsCallData()
initCode!: BytesLike;
initCode?: BytesLike;

@ValidateIf((o) => o.paymasterData)
@ValidateIf((o) => o.paymasterAndData)
@IsString()
@IsCallData()
paymasterAndData!: BytesLike;
paymasterAndData?: BytesLike;

/**
* EntryPoint v7 Properties
*/
/**
* EntryPoint v7 Properties
*/
@ValidateIf((o) => o.paymasterAndData)
@ValidateIf((o) => o.paymasterData)
@IsString()
factory!: string;
factory?: string;

@ValidateIf((o) => o.paymasterAndData)
@ValidateIf((o) => o.paymasterData)
@IsCallData()
@IsString()
factoryData!: BytesLike;
factoryData?: BytesLike;

@ValidateIf((o) => o.paymasterAndData)
@ValidateIf((o) => o.paymasterData)
@IsString()
paymaster!: string;
paymaster?: string;

@ValidateIf((o) => o.paymasterAndData)
@ValidateIf((o) => o.paymasterData)
@IsBigNumber()
paymasterVerificationGasLimit!: BigNumberish;
paymasterVerificationGasLimit?: BigNumberish;

@ValidateIf((o) => o.paymasterAndData)
@ValidateIf((o) => o.paymasterData)
@IsBigNumber()
paymasterPostOpGasLimit!: BigNumberish;
paymasterPostOpGasLimit?: BigNumberish;

@ValidateIf((o) => o.paymasterAndData)
@ValidateIf((o) => o.paymasterData)
@IsCallData()
@IsString()
paymasterData!: BytesLike;
paymasterData?: BytesLike;
}

export class EstimateUserOperationGasArgs {
Expand Down
16 changes: 8 additions & 8 deletions packages/api/src/dto/SendUserOperation.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,40 +37,40 @@ export class SendUserOperation {
/**
* EntryPoint v6 Properties
*/
@ValidateIf((o) => o.paymasterData)
@ValidateIf((o) => o.paymasterAndData)
@IsString()
@IsCallData()
initCode!: BytesLike;

@ValidateIf((o) => o.paymasterData)
@ValidateIf((o) => o.paymasterAndData)
@IsString()
@IsCallData()
paymasterAndData!: BytesLike;

/**
* EntryPoint v7 Properties
*/
@ValidateIf((o) => o.paymasterAndData)
@ValidateIf((o) => o.paymasterData)
@IsString()
factory!: string;

@ValidateIf((o) => o.paymasterAndData)
@ValidateIf((o) => o.paymasterData)
@IsString()
factoryData!: BytesLike;

@ValidateIf((o) => o.paymasterAndData)
@ValidateIf((o) => o.paymasterData)
@IsString()
paymaster!: string;

@ValidateIf((o) => o.paymasterAndData)
@ValidateIf((o) => o.paymasterData)
@IsBigNumber()
paymasterVerificationGasLimit!: BigNumberish;

@ValidateIf((o) => o.paymasterAndData)
@ValidateIf((o) => o.paymasterData)
@IsBigNumber()
paymasterPostOpGasLimit!: BigNumberish;

@ValidateIf((o) => o.paymasterAndData)
@ValidateIf((o) => o.paymasterData)
@IsString()
paymasterData!: BytesLike;
}
Expand Down
4 changes: 2 additions & 2 deletions packages/api/src/dto/SetMempool.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ import {
IsEthereumAddress,
ValidateNested,
} from "class-validator";
import { SendUserOperationStruct } from "./SendUserOperation.dto";
import { SendUserOperation } from "./SendUserOperation.dto";

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

@IsEthereumAddress()
entryPoint!: string;
Expand Down
4 changes: 2 additions & 2 deletions packages/api/src/modules/debug.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { UserOperationStruct } from "types/lib/executor/contracts/EntryPoint";
import { UserOperation6And7 } from "types/lib/contracts/UserOperation";
import { Debug } from "executor/lib/modules";
import { IsEthereumAddress } from "class-validator";
import { BundlingMode } from "types/lib/api/interfaces";
Expand Down Expand Up @@ -49,7 +49,7 @@ export class DebugAPI {
* Dumps the current UserOperations mempool
* array - Array of UserOperations currently in the mempool
*/
async dumpMempool(): Promise<UserOperationStruct[]> {
async dumpMempool(): Promise<UserOperation6And7[]> {
return await this.debugModule.dumpMempool();
}

Expand Down
6 changes: 5 additions & 1 deletion packages/api/src/utils/RpcMethodValidator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,11 @@ export function validationFactory<T>(
arguments: args[0],
},
});
throw new RpcError("Invalid Request", RpcErrorCodes.INVALID_REQUEST);
throw new RpcError("Invalid Request", RpcErrorCodes.INVALID_REQUEST, {
data: {
errors,
},
});
}

return method.apply(this, args);
Expand Down
31 changes: 13 additions & 18 deletions packages/executor/src/executor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import {
BundlingService,
ReputationService,
P2PService,
EventsService,
EntryPointService,
} from "./services";
import { Config } from "./config";
Expand Down Expand Up @@ -49,7 +48,6 @@ export class Executor {
public userOpValidationService: UserOpValidationService;
public reputationService: ReputationService;
public p2pService: P2PService;
public eventsService: EventsService;

private db: IDbController;

Expand All @@ -68,12 +66,6 @@ export class Executor {

this.provider = this.config.getNetworkProvider();

this.entryPointService = new EntryPointService(
this.config,
this.networkConfig,
this.provider,
this.logger
);
this.reputationService = new ReputationService(
this.db,
this.chainId,
Expand All @@ -83,6 +75,14 @@ export class Executor {
BigNumber.from(this.networkConfig.minStake),
this.networkConfig.minUnstakeDelay
);
this.entryPointService = new EntryPointService(
this.chainId,
this.networkConfig,
this.provider,
this.reputationService,
this.db,
this.logger
);
this.userOpValidationService = new UserOpValidationService(
this.provider,
this.entryPointService,
Expand All @@ -94,6 +94,7 @@ export class Executor {
this.mempoolService = new MempoolService(
this.db,
this.chainId,
this.entryPointService,
this.reputationService,
this.networkConfig
);
Expand All @@ -109,15 +110,6 @@ export class Executor {
this.metrics,
this.networkConfig.relayingMode
);
this.eventsService = new EventsService(
this.chainId,
this.provider,
this.logger,
this.reputationService,
this.networkConfig.entryPointsV6!,
this.db
);
this.eventsService.initEventListener();

this.web3 = new Web3(this.config, this.version);
this.debug = new Debug(
Expand Down Expand Up @@ -147,7 +139,10 @@ export class Executor {
this.metrics,
this.getNodeApi
);
this.p2pService = new P2PService(this.mempoolService);
this.p2pService = new P2PService(
this.entryPointService,
this.mempoolService
);

if (this.config.testingMode || options.bundlingMode == "manual") {
this.bundlingService.setBundlingMode("manual");
Expand Down
20 changes: 12 additions & 8 deletions packages/executor/src/modules/debug.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import {
} from "../services";
import { BundlingMode, GetStakeStatus, NetworkConfig } from "../interfaces";
import { ReputationEntryDump } from "../entities/interfaces";
import { getAddr } from "../utils";
import { SetReputationArgs, SetMempoolArgs } from "./interfaces";
/*
SPEC: https://eips.ethereum.org/EIPS/eip-4337#rpc-methods-debug-namespace
Expand Down Expand Up @@ -115,32 +114,37 @@ export class Debug {
}

async setMempool(mempool: SetMempoolArgs): Promise<string> {
const { entryPoint, userOps } = mempool;
await this.mempoolService.clearState();
// Loop through the array and persist to the local mempool without simulation.
for (const userOp of mempool.userOps) {
for (const userOp of userOps) {
const [factory, paymaster] = [
this.entryPointService.getFactory(entryPoint, userOp),
this.entryPointService.getPaymaster(entryPoint, userOp),
];
const userOpHash = await this.entryPointService.getUserOpHash(
mempool.entryPoint,
entryPoint,
userOp
);
await this.mempoolService.addUserOp(
userOp,
mempool.entryPoint,
entryPoint,
0x0,
{
addr: userOp.sender,
stake: 0,
unstakeDelaySec: 0,
},
getAddr(userOp.initCode)
factory
? {
addr: getAddr(userOp.initCode)!,
addr: factory,
stake: 0,
unstakeDelaySec: 0,
}
: undefined,
getAddr(userOp.paymasterAndData)
paymaster
? {
addr: getAddr(userOp.paymasterAndData)!,
addr: paymaster,
stake: 0,
unstakeDelaySec: 0,
}
Expand Down
33 changes: 26 additions & 7 deletions packages/executor/src/modules/eth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
estimateArbitrumPVG,
ECDSA_DUMMY_SIGNATURE,
estimateMantlePVG,
AddressZero,
} from "params/lib";
import { Logger } from "types/lib";
import { PerChainMetrics } from "monitoring/lib";
Expand Down Expand Up @@ -68,7 +69,7 @@ export class Eth {
*/
async sendUserOperation(args: SendUserOperationGasArgs): Promise<string> {
const userOp = args.userOp as unknown as UserOperation6And7;
const entryPoint = args.entryPoint;
const entryPoint = args.entryPoint.toLowerCase();
if (!this.validateEntryPoint(entryPoint)) {
throw new RpcError("Invalid Entrypoint", RpcErrorCodes.INVALID_REQUEST);
}
Expand Down Expand Up @@ -139,7 +140,8 @@ export class Eth {
async estimateUserOperationGas(
args: EstimateUserOperationGasArgs
): Promise<EstimatedUserOperationGas> {
const { userOp, entryPoint } = args;
const userOp = args.userOp;
const entryPoint = args.entryPoint.toLowerCase();
if (!this.validateEntryPoint(entryPoint)) {
throw new RpcError("Invalid Entrypoint", RpcErrorCodes.INVALID_REQUEST);
}
Expand Down Expand Up @@ -172,7 +174,10 @@ export class Eth {
.toNumber();

let preVerificationGas: BigNumberish =
this.entryPointService.calcPreverificationGas(entryPoint, userOp);
this.entryPointService.calcPreverificationGas(
entryPoint,
userOpComplemented
);
userOpComplemented.preVerificationGas = preVerificationGas;
let callGasLimit: BigNumber = BigNumber.from(0);

Expand Down Expand Up @@ -212,10 +217,22 @@ export class Eth {
if (this.pvgEstimator) {
userOpComplemented.maxFeePerGas = gasFee.maxFeePerGas;
userOpComplemented.maxPriorityFeePerGas = gasFee.maxPriorityFeePerGas;
const data = this.entryPointService.encodeHandleOps(
entryPoint,
[userOpComplemented],
AddressZero
);
preVerificationGas = await this.pvgEstimator(
entryPoint,
userOpComplemented,
preVerificationGas
data,
preVerificationGas,
{
contractCreation: Boolean(
userOp.factory ||
(userOp.initCode != null && userOp.initCode.length >= 42)
),
userOp: userOpComplemented,
}
);
}

Expand All @@ -240,7 +257,8 @@ export class Eth {
async estimateUserOperationGasWithSignature(
args: SendUserOperationGasArgs
): Promise<EstimatedUserOperationGas> {
const { userOp, entryPoint } = args;
const userOp = args.userOp;
const entryPoint = args.entryPoint.toLowerCase();
if (!this.validateEntryPoint(entryPoint)) {
throw new RpcError("Invalid Entrypoint", RpcErrorCodes.INVALID_REQUEST);
}
Expand Down Expand Up @@ -287,7 +305,8 @@ export class Eth {
* @returns
*/
async validateUserOp(args: SendUserOperationGasArgs): Promise<boolean> {
const { userOp, entryPoint } = args;
const userOp = args.userOp;
const entryPoint = args.entryPoint.toLowerCase();
if (!this.validateEntryPoint(entryPoint)) {
throw new RpcError("Invalid Entrypoint", RpcErrorCodes.INVALID_REQUEST);
}
Expand Down
9 changes: 8 additions & 1 deletion packages/executor/src/modules/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,14 @@ import { UserOperation6And7 } from "types/lib/contracts/UserOperation";
import { ReputationStatus } from "types/lib/executor";

export class EstimateUserOperationGasArgs {
userOp!: UserOperation6And7;
userOp!: Omit<
UserOperation6And7,
| "callGasLimit"
| "verificationGasLimit"
| "preVerificationGas"
| "maxFeePerGas"
| "maxPriorityFeePerGas"
>;
entryPoint!: string;
}

Expand Down
Loading

0 comments on commit 7241895

Please sign in to comment.