Skip to content

Commit

Permalink
Move 'userOpMaxGas' calculation into the MempoolEntry class
Browse files Browse the repository at this point in the history
  • Loading branch information
forshtat committed Aug 4, 2024
1 parent 68eb2a9 commit 7f2c4f3
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 24 deletions.
15 changes: 4 additions & 11 deletions packages/bundler/src/modules/BundleManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ import {
import { EventsManager } from './EventsManager'
import { GetUserOpHashes__factory } from '../types'
import { IBundleManager } from './IBundleManager'
import { MempoolEntry, MempoolManager } from './MempoolManager'
import { MempoolEntry } from './MempoolEntry'
import { MempoolManager } from './MempoolManager'
import { ReputationManager, ReputationStatus } from './ReputationManager'

const debug = Debug('aa.exec.cron')
Expand Down Expand Up @@ -313,20 +314,12 @@ export class BundleManager implements IBundleManager {
}
mergeStorageMap(storageMap, validationResult.storageMap)

const userOpGas =
BigNumber
.from((entry.userOp as UserOperation).preVerificationGas ?? 0)
.add(entry.userOp.callGasLimit)
.add(entry.userOp.verificationGasLimit)
.add(entry.userOp.paymasterVerificationGasLimit ?? 0)
.add(entry.userOp.paymasterPostOpGasLimit ?? 0)

const newBundleGas = userOpGas.add(bundleGas)
const newBundleGas = entry.userOpMaxGas.add(bundleGas)
if (
maxBundleGas != null &&
!BigNumber.from(maxBundleGas).eq(0) &&
newBundleGas.gte(maxBundleGas)) {
debug('exiting after maxBundleGas is reached', maxBundleGas, bundleGas, userOpGas)
debug('exiting after maxBundleGas is reached', maxBundleGas, bundleGas, entry.userOpMaxGas)
break
}
bundleGas = newBundleGas
Expand Down
21 changes: 21 additions & 0 deletions packages/bundler/src/modules/MempoolEntry.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { BigNumber, BigNumberish } from 'ethers'
import { OperationBase, ReferencedCodeHashes, UserOperation } from '@account-abstraction/utils'

export class MempoolEntry {
userOpMaxGas: BigNumber

constructor (
readonly userOp: OperationBase,
readonly userOpHash: string,
readonly prefund: BigNumberish,
readonly referencedContracts: ReferencedCodeHashes,
readonly aggregator?: string
) {
this.userOpMaxGas = BigNumber
.from((this.userOp as UserOperation).preVerificationGas ?? 0)
.add(this.userOp.callGasLimit)
.add(this.userOp.verificationGasLimit)
.add(this.userOp.paymasterVerificationGasLimit ?? 0)
.add(this.userOp.paymasterPostOpGasLimit ?? 0)
}
}
19 changes: 6 additions & 13 deletions packages/bundler/src/modules/MempoolManager.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,18 @@
import { BigNumber, BigNumberish } from 'ethers'
import Debug from 'debug'

import {
ReferencedCodeHashes,
RpcError,
StakeInfo,
ValidationErrors,
requireCond, OperationBase
} from '@account-abstraction/utils'
import { MempoolEntry } from './MempoolEntry'
import { ReputationManager } from './ReputationManager'
import Debug from 'debug'

const debug = Debug('aa.mempool')

export interface MempoolEntry {
userOp: OperationBase
userOpHash: string
prefund: BigNumberish
referencedContracts: ReferencedCodeHashes
// aggregator, if one was found during simulation
aggregator?: string
}

type MempoolDump = OperationBase[]

const THROTTLED_ENTITY_MEMPOOL_COUNT = 4
Expand Down Expand Up @@ -75,13 +68,13 @@ export class MempoolManager {
factoryInfo?: StakeInfo,
aggregatorInfo?: StakeInfo
): void {
const entry: MempoolEntry = {
const entry = new MempoolEntry(
userOp,
userOpHash,
prefund,
referencedContracts,
aggregator: aggregatorInfo?.addr
}
aggregatorInfo?.addr
)
const index = this._findBySenderNonce(userOp.sender, userOp.nonce)
if (index !== -1) {
const oldEntry = this.mempool[index]
Expand Down

0 comments on commit 7f2c4f3

Please sign in to comment.