Skip to content

Commit

Permalink
Add parameter and send 1 wei transaction in 'sendBundle' (#218)
Browse files Browse the repository at this point in the history
* Add parameter and send 1 wei transaction in 'sendBundle'

* Upd

* Fix lint
  • Loading branch information
forshtat authored Aug 4, 2024
1 parent b42d8d4 commit 79577d8
Show file tree
Hide file tree
Showing 9 changed files with 25 additions and 8 deletions.
4 changes: 3 additions & 1 deletion packages/bundler/src/BundlerConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export interface BundlerConfig {
autoBundleMempoolSize: number
rip7560: boolean
rip7560Mode: string
gethDevMode: boolean
}

// TODO: implement merging config (args -> config.js -> default) and runtime shape validation
Expand All @@ -50,7 +51,8 @@ export const BundlerConfigShape = {
autoBundleInterval: ow.number,
autoBundleMempoolSize: ow.number,
rip7560: ow.boolean,
rip7560Mode: ow.string.oneOf(['PULL', 'PUSH'])
rip7560Mode: ow.string.oneOf(['PULL', 'PUSH']),
gethDevMode: ow.boolean
}

// TODO: consider if we want any default fields at all
Expand Down
1 change: 1 addition & 0 deletions packages/bundler/src/modules/BundleManagerRIP7560.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ export class BundleManagerRIP7560 extends BundleManager {
transactionHash: bundleHash,
userOpHashes
})

return bundleHash
}

Expand Down
12 changes: 10 additions & 2 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 { IValidationManager } from '@account-abstraction/validation-manager'
import { DepositManager } from './DepositManager'
import { BigNumberish } from 'ethers'
import { BigNumberish, Signer } from 'ethers'

const debug = Debug('aa.exec')

Expand All @@ -28,7 +28,9 @@ export class ExecutionManager {
private readonly mempoolManager: MempoolManager,
private readonly bundleManager: IBundleManager,
private readonly validationManager: IValidationManager,
private readonly depositManager: DepositManager
private readonly depositManager: DepositManager,
private readonly signer: Signer,
private readonly gethDevMode: boolean
) {
}

Expand Down Expand Up @@ -90,6 +92,12 @@ export class ExecutionManager {
*/
async attemptBundle (force = true): Promise<SendBundleReturn | undefined> {
debug('attemptBundle force=', force, 'count=', this.mempoolManager.count(), 'max=', this.maxMempoolSize)
if (this.gethDevMode && force) {
await this.signer.sendTransaction({
to: this.signer.getAddress(),
value: 1
})
}
if (force || this.mempoolManager.count() >= this.maxMempoolSize) {
const ret = await this.bundleManager.sendNextBundle()
if (this.maxMempoolSize === 0) {
Expand Down
2 changes: 1 addition & 1 deletion packages/bundler/src/modules/initServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export function initServer (config: BundlerConfig, signer: Signer): [ExecutionMa
config.beneficiary, parseEther(config.minBalance), config.maxBundleGas, config.conditionalRpc, false, config.rip7560Mode)
}
const depositManager = new DepositManager(entryPoint, mempoolManager, bundleManager)
const executionManager = new ExecutionManager(reputationManager, mempoolManager, bundleManager, validationManager, depositManager)
const executionManager = new ExecutionManager(reputationManager, mempoolManager, bundleManager, validationManager, depositManager, signer, config.gethDevMode)

reputationManager.addWhitelist(...config.whitelist ?? [])
reputationManager.addBlacklist(...config.blacklist ?? [])
Expand Down
1 change: 1 addition & 0 deletions packages/bundler/src/runBundler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ export async function runBundler (argv: string[], overrideExit = true): Promise<
.option('--createMnemonic <file>', 'create the mnemonic file')
.option('--rip7560', 'Use this bundler as an RIP-7560 node', false)
.option('--rip7560Mode <string>', 'PUSH mode sends bundles to node at an interval, PULL mode waits for node to query bundle', 'PULL')
.option('--gethDevMode', 'In PULL mode send 1 wei transaction to trigger block creation', false)

const programOpts = program.parse(argv).opts()
showStackTraces = programOpts.showStackTraces
Expand Down
4 changes: 3 additions & 1 deletion packages/bundler/test/BundlerManager.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ describe('#BundlerManager', () => {
minUnstakeDelay: 0,
rip7560: false,
rip7560Mode: 'PULL',
gethDevMode: false,
conditionalRpc: false
}

Expand Down Expand Up @@ -106,6 +107,7 @@ describe('#BundlerManager', () => {
minStake: '0',
rip7560: false,
rip7560Mode: 'PULL',
gethDevMode: false,
minUnstakeDelay: 0
}
const repMgr = new ReputationManager(provider, BundlerReputationParams, parseEther(config.minStake), config.minUnstakeDelay)
Expand All @@ -114,7 +116,7 @@ describe('#BundlerManager', () => {
const evMgr = new EventsManager(_entryPoint, mempoolMgr, repMgr)
bundleMgr = new BundleManager(_entryPoint, _entryPoint.provider as JsonRpcProvider, _entryPoint.signer, evMgr, mempoolMgr, validMgr, repMgr, config.beneficiary, parseEther(config.minBalance), config.maxBundleGas, false)
const depositManager = new DepositManager(entryPoint, mempoolMgr, bundleMgr)
const execManager = new ExecutionManager(repMgr, mempoolMgr, bundleMgr, validMgr, depositManager)
const execManager = new ExecutionManager(repMgr, mempoolMgr, bundleMgr, validMgr, depositManager, _entryPoint.signer, false)
execManager.setAutoBundler(0, 1000)

methodHandler = new MethodHandlerERC4337(
Expand Down
3 changes: 2 additions & 1 deletion packages/bundler/test/BundlerServer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ describe('BundleServer', function () {
minStake: '0',
rip7560: false,
rip7560Mode: 'PULL',
gethDevMode: false,
minUnstakeDelay: 0
}

Expand All @@ -58,7 +59,7 @@ describe('BundleServer', function () {
const evMgr = new EventsManager(entryPoint, mempoolMgr, repMgr)
const bundleMgr = new BundleManager(entryPoint, entryPoint.provider as JsonRpcProvider, entryPoint.signer, evMgr, mempoolMgr, validMgr, repMgr, config.beneficiary, parseEther(config.minBalance), config.maxBundleGas, false)
const depositManager = new DepositManager(entryPoint, mempoolMgr, bundleMgr)
const execManager = new ExecutionManager(repMgr, mempoolMgr, bundleMgr, validMgr, depositManager)
const execManager = new ExecutionManager(repMgr, mempoolMgr, bundleMgr, validMgr, depositManager, entryPoint.signer, false)
const methodHandler = new MethodHandlerERC4337(
execManager,
provider,
Expand Down
3 changes: 2 additions & 1 deletion packages/bundler/test/DebugMethodHandler.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ describe('#DebugMethodHandler', () => {
minStake: '0',
rip7560: false,
rip7560Mode: 'PULL',
gethDevMode: false,
minUnstakeDelay: 0
}

Expand All @@ -70,7 +71,7 @@ describe('#DebugMethodHandler', () => {
const bundleMgr = new BundleManager(entryPoint, entryPoint.provider as JsonRpcProvider, entryPoint.signer, eventsManager, mempoolMgr, validMgr, repMgr,
config.beneficiary, parseEther(config.minBalance), config.maxBundleGas, false)
const depositManager = new DepositManager(entryPoint, mempoolMgr, bundleMgr)
const execManager = new ExecutionManager(repMgr, mempoolMgr, bundleMgr, validMgr, depositManager)
const execManager = new ExecutionManager(repMgr, mempoolMgr, bundleMgr, validMgr, depositManager, entryPoint.signer, false)
methodHandler = new MethodHandlerERC4337(
execManager,
provider,
Expand Down
3 changes: 2 additions & 1 deletion packages/bundler/test/UserOpMethodHandler.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ describe('UserOpMethodHandler', function () {
minStake: '0',
rip7560: false,
rip7560Mode: 'PULL',
gethDevMode: false,
minUnstakeDelay: 0
}

Expand All @@ -87,7 +88,7 @@ describe('UserOpMethodHandler', function () {
const evMgr = new EventsManager(entryPoint, mempoolMgr, repMgr)
const bundleMgr = new BundleManager(entryPoint, entryPoint.provider as JsonRpcProvider, entryPoint.signer, evMgr, mempoolMgr, validMgr, repMgr, config.beneficiary, parseEther(config.minBalance), config.maxBundleGas, false)
const depositManager = new DepositManager(entryPoint, mempoolMgr, bundleMgr)
const execManager = new ExecutionManager(repMgr, mempoolMgr, bundleMgr, validMgr, depositManager)
const execManager = new ExecutionManager(repMgr, mempoolMgr, bundleMgr, validMgr, depositManager, entryPoint.signer, false)
methodHandler = new MethodHandlerERC4337(
execManager,
provider,
Expand Down

0 comments on commit 79577d8

Please sign in to comment.