Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AA-522: Support alt-mempool configurations (WIP) #240

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions packages/bundler/src/BundlerServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -334,9 +334,13 @@ export class BundlerServer {
case 'debug_bundler_setConfiguration': {
const pvgc = await this.debugHandler._setConfiguration(params[0])
this.methodHandler.preVerificationGasCalculator = pvgc
break
}
case 'debug_bundler_setAltMempoolConfig': {
await this.debugHandler._setAltMempoolConfig(params[0])
result = {}
break
}
default:
throw new RpcError(`Method ${method} is not supported`, -32601)
}
Expand Down
15 changes: 15 additions & 0 deletions packages/bundler/src/Config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import fs from 'fs'
import { BundlerConfig, bundlerConfigDefault, BundlerConfigShape } from './BundlerConfig'
import { Wallet, Signer } from 'ethers'
import { JsonRpcProvider } from '@ethersproject/providers'
import { AltMempoolConfig, validateAltMempoolConfigShape } from '@account-abstraction/validation-manager'

function getCommandLineParams (programOpts: any): Partial<BundlerConfig> {
const params: any = {}
Expand Down Expand Up @@ -60,3 +61,17 @@ export async function resolveConfiguration (programOpts: any): Promise<{ config:
}
return { config, provider, wallet }
}

export async function resolveAltMempoolConfig (programOpts: any): Promise<AltMempoolConfig> {
const configFileName: string = programOpts.altMempoolConfig
if (!fs.existsSync(configFileName)) {
return {}
}
try {
const fileConfig = JSON.parse(fs.readFileSync(configFileName, 'ascii'))
validateAltMempoolConfigShape(fileConfig)
return fileConfig
} catch (e: any) {
throw new Error(`Unable to read --altMempoolConfig ${configFileName}: ${e.message as string}`)
}
}
20 changes: 14 additions & 6 deletions packages/bundler/src/DebugMethodHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ import { BundlerConfig, DebugBundlerConfigShape } from './BundlerConfig'
import { EventsManager } from './modules/EventsManager'
import { ExecutionManager } from './modules/ExecutionManager'
import { MempoolManager } from './modules/MempoolManager'
import { ReputationDump, ReputationManager } from './modules/ReputationManager'
import { ReputationEntry, ReputationManager } from './modules/ReputationManager'
import { SendBundleReturn } from './modules/BundleManager'
import { AltMempoolConfig, validateAltMempoolConfigShape } from '@account-abstraction/validation-manager'

export class DebugMethodHandler {
constructor (
Expand Down Expand Up @@ -53,19 +54,19 @@ export class DebugMethodHandler {
}

async dumpMempool (): Promise<any> {
return this.mempoolMgr.dump()
return this.mempoolMgr.debugDumpMempool()
}

clearMempool (): void {
this.mempoolMgr.clearState()
}

setReputation (param: any): ReputationDump {
return this.repManager.setReputation(param)
setReputation (param: any): ReputationEntry[] {
return this.repManager._debugSetReputation(param)
}

dumpReputation (): ReputationDump {
return this.repManager.dump()
dumpReputation (): ReputationEntry[] {
return this.repManager._debugDumpReputation()
}

clearReputation (): void {
Expand All @@ -86,4 +87,11 @@ export class DebugMethodHandler {
ow.object.exactShape(DebugBundlerConfigShape)
return await this.execManager._setConfiguration(config)
}

async _setAltMempoolConfig (altMempoolConfig: AltMempoolConfig): Promise<void> {
const configCleanedUp = JSON.parse(JSON.stringify(altMempoolConfig))
validateAltMempoolConfigShape(configCleanedUp)
await this.mempoolMgr._setAltMempoolConfig(configCleanedUp)
await this._setConfiguration({})
}
}
1 change: 1 addition & 0 deletions packages/bundler/src/modules/EventsManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ export class EventsManager {

handleUserOperationEvent (ev: UserOperationEventEvent): void {
const hash = ev.args.userOpHash
this.mempoolManager.includedUserOp(hash)
this.mempoolManager.removeUserOp(hash)
this._includedAddress(ev.args.sender)
this._includedAddress(ev.args.paymaster)
Expand Down
7 changes: 4 additions & 3 deletions packages/bundler/src/modules/ExecutionManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { ReputationManager } from './ReputationManager'
import { IBundleManager } from './IBundleManager'
import {
EmptyValidateUserOpResult,
IValidationManager, ValidationManager
IValidationManager, ValidateUserOpResult, ValidationManager
} from '@account-abstraction/validation-manager'
import { DepositManager } from './DepositManager'
import { BigNumberish, Signer } from 'ethers'
Expand Down Expand Up @@ -56,7 +56,7 @@ export class ExecutionManager {
await this.mutex.runExclusive(async () => {
debug('sendUserOperation')
this.validationManager.validateInputParameters(userOp, entryPointInput)
let validationResult = EmptyValidateUserOpResult
let validationResult: ValidateUserOpResult = EmptyValidateUserOpResult
if (!skipValidation) {
validationResult = await this.validationManager.validateUserOp(userOp)
}
Expand Down Expand Up @@ -150,7 +150,8 @@ export class ExecutionManager {
const { configuration, entryPoint, unsafe } = this.validationManager._getDebugConfiguration()
const mergedConfiguration = Object.assign({}, configuration, configOverrides)
const pvgc = new PreVerificationGasCalculator(mergedConfiguration)
const erc7562Parser = new ERC7562Parser(entryPoint.address, mergedConfiguration.senderCreator ?? '')
const bailOnViolation = this.mempoolManager.hasAltMempools()
const erc7562Parser = new ERC7562Parser(bailOnViolation, entryPoint.address, mergedConfiguration.senderCreator ?? '')
this.validationManager = new ValidationManager(
entryPoint,
unsafe,
Expand Down
4 changes: 4 additions & 0 deletions packages/bundler/src/modules/MempoolEntry.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
import { BigNumber, BigNumberish } from 'ethers'
import { OperationBase, ReferencedCodeHashes, UserOperation } from '@account-abstraction/utils'
import { ERC7562Violation } from '@account-abstraction/validation-manager/dist/src/ERC7562Violation'
import { ValidateUserOpResult } from '@account-abstraction/validation-manager'

export class MempoolEntry {
userOpMaxGas: BigNumber

constructor (
readonly userOp: OperationBase,
readonly userOpHash: string,
readonly validateUserOpResult: ValidateUserOpResult,
readonly prefund: BigNumberish,
readonly referencedContracts: ReferencedCodeHashes,
readonly ruleViolations: ERC7562Violation[],
readonly skipValidation: boolean,
readonly aggregator?: string
) {
Expand Down
Loading
Loading