Skip to content

Commit

Permalink
Account for "minBaseFee", "maxBundleGas", "maxBundleSize" in "createB…
Browse files Browse the repository at this point in the history
…undle"
  • Loading branch information
forshtat committed Jul 29, 2024
1 parent 9215666 commit d6c58bc
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 11 deletions.
44 changes: 36 additions & 8 deletions packages/bundler/src/modules/BundleManager.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { MempoolEntry, MempoolManager } from './MempoolManager'
import { IValidationManager, ValidateUserOpResult } from '@account-abstraction/validation-manager'
import Debug from 'debug'
import { BigNumber, BigNumberish, Signer } from 'ethers'
import { isAddress } from 'ethers/lib/utils'
import { ErrorDescription } from '@ethersproject/abi/lib/interface'
import { JsonRpcProvider } from '@ethersproject/providers'
import Debug from 'debug'
import { ReputationManager, ReputationStatus } from './ReputationManager'
import { Mutex } from 'async-mutex'
import { GetUserOpHashes__factory } from '../types'
import { isAddress } from 'ethers/lib/utils'

import { IValidationManager, ValidateUserOpResult } from '@account-abstraction/validation-manager'

import {
AddressZero,
IEntryPoint,
Expand All @@ -19,8 +19,12 @@ import {
packUserOp,
runContractScript
} from '@account-abstraction/utils'

import { EventsManager } from './EventsManager'
import { ErrorDescription } from '@ethersproject/abi/lib/interface'
import { GetUserOpHashes__factory } from '../types'
import { IBundleManager } from './IBundleManager'
import { MempoolEntry, MempoolManager } from './MempoolManager'
import { ReputationManager, ReputationStatus } from './ReputationManager'

const debug = Debug('aa.exec.cron')

Expand All @@ -31,7 +35,7 @@ export interface SendBundleReturn {
userOpHashes: string[]
}

export class BundleManager {
export class BundleManager implements IBundleManager {
readonly entryPoint: IEntryPoint
mutex = new Mutex()

Expand Down Expand Up @@ -215,9 +219,19 @@ export class BundleManager {
const storageMap: StorageMap = {}
let totalGas = BigNumber.from(0)
debug('got mempool of ', entries.length)
let bundleGas = BigNumber.from(0)
// eslint-disable-next-line no-labels
mainLoop:
for (const entry of entries) {
const maxBundleSizeNum = BigNumber.from(maxBundleSize).toNumber()
if (maxBundleSizeNum !== 0 && entries.length >= maxBundleSizeNum) {
debug('exiting after maxBundleSize is reached', maxBundleSize, entries.length)
break
}
if (BigNumber.from(entry.userOp.maxFeePerGas).lt(minBaseFee)) {
debug('skipping transaction not paying minBaseFee', minBaseFee, entry.userOp.maxFeePerGas)
continue
}
const paymaster = entry.userOp.paymaster
const factory = entry.userOp.factory
const paymasterStatus = this.reputationManager.getStatus(paymaster)
Expand Down Expand Up @@ -295,6 +309,20 @@ export class BundleManager {
}
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)
if (newBundleGas.gte(maxBundleGas)) {
debug('exiting after maxBundleGas is reached', maxBundleGas, bundleGas, userOpGas)
break
}
bundleGas = newBundleGas
senders.add(entry.userOp.sender)
bundle.push(entry.userOp)
totalGas = newTotalGas
Expand Down
5 changes: 2 additions & 3 deletions packages/bundler/src/modules/BundleManagerRIP7560.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import Debug from 'debug'
import { BigNumber, BigNumberish, ethers, Signer } from 'ethers'
import { JsonRpcProvider } from '@ethersproject/providers'
import { RLP } from '@ethereumjs/rlp'
import { hexlify } from 'ethers/lib/utils'

import {
OperationBase,
Expand All @@ -13,14 +14,12 @@ import { IValidationManager } from '@account-abstraction/validation-manager'

import { BundleManager, SendBundleReturn } from './BundleManager'
import { EventsManager } from './EventsManager'
import { IBundleManager } from './IBundleManager'
import { MempoolManager } from './MempoolManager'
import { ReputationManager } from './ReputationManager'
import { hexlify } from 'ethers/lib/utils'

const debug = Debug('aa.exec.cron')

export class BundleManagerRIP7560 extends BundleManager implements IBundleManager {
export class BundleManagerRIP7560 extends BundleManager {
sentBundles: SendBundleReturn[] = []
lastScannedBlock: number = 0

Expand Down

0 comments on commit d6c58bc

Please sign in to comment.