From 79577d84534205c7cd4514b46b7622235dc03f00 Mon Sep 17 00:00:00 2001 From: Alex Forshtat Date: Sun, 4 Aug 2024 21:07:46 +0300 Subject: [PATCH] Add parameter and send 1 wei transaction in 'sendBundle' (#218) * Add parameter and send 1 wei transaction in 'sendBundle' * Upd * Fix lint --- packages/bundler/src/BundlerConfig.ts | 4 +++- packages/bundler/src/modules/BundleManagerRIP7560.ts | 1 + packages/bundler/src/modules/ExecutionManager.ts | 12 ++++++++++-- packages/bundler/src/modules/initServer.ts | 2 +- packages/bundler/src/runBundler.ts | 1 + packages/bundler/test/BundlerManager.test.ts | 4 +++- packages/bundler/test/BundlerServer.test.ts | 3 ++- packages/bundler/test/DebugMethodHandler.test.ts | 3 ++- packages/bundler/test/UserOpMethodHandler.test.ts | 3 ++- 9 files changed, 25 insertions(+), 8 deletions(-) diff --git a/packages/bundler/src/BundlerConfig.ts b/packages/bundler/src/BundlerConfig.ts index a296b056..131632d4 100644 --- a/packages/bundler/src/BundlerConfig.ts +++ b/packages/bundler/src/BundlerConfig.ts @@ -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 @@ -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 diff --git a/packages/bundler/src/modules/BundleManagerRIP7560.ts b/packages/bundler/src/modules/BundleManagerRIP7560.ts index 883240ed..4f727645 100644 --- a/packages/bundler/src/modules/BundleManagerRIP7560.ts +++ b/packages/bundler/src/modules/BundleManagerRIP7560.ts @@ -119,6 +119,7 @@ export class BundleManagerRIP7560 extends BundleManager { transactionHash: bundleHash, userOpHashes }) + return bundleHash } diff --git a/packages/bundler/src/modules/ExecutionManager.ts b/packages/bundler/src/modules/ExecutionManager.ts index dd085da1..08d8a3c0 100644 --- a/packages/bundler/src/modules/ExecutionManager.ts +++ b/packages/bundler/src/modules/ExecutionManager.ts @@ -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') @@ -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 ) { } @@ -90,6 +92,12 @@ export class ExecutionManager { */ async attemptBundle (force = true): Promise { 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) { diff --git a/packages/bundler/src/modules/initServer.ts b/packages/bundler/src/modules/initServer.ts index bde064c7..01fd8dc7 100644 --- a/packages/bundler/src/modules/initServer.ts +++ b/packages/bundler/src/modules/initServer.ts @@ -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 ?? []) diff --git a/packages/bundler/src/runBundler.ts b/packages/bundler/src/runBundler.ts index 69003eb7..c34f531c 100644 --- a/packages/bundler/src/runBundler.ts +++ b/packages/bundler/src/runBundler.ts @@ -85,6 +85,7 @@ export async function runBundler (argv: string[], overrideExit = true): Promise< .option('--createMnemonic ', 'create the mnemonic file') .option('--rip7560', 'Use this bundler as an RIP-7560 node', false) .option('--rip7560Mode ', '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 diff --git a/packages/bundler/test/BundlerManager.test.ts b/packages/bundler/test/BundlerManager.test.ts index e6802f30..8b403d93 100644 --- a/packages/bundler/test/BundlerManager.test.ts +++ b/packages/bundler/test/BundlerManager.test.ts @@ -53,6 +53,7 @@ describe('#BundlerManager', () => { minUnstakeDelay: 0, rip7560: false, rip7560Mode: 'PULL', + gethDevMode: false, conditionalRpc: false } @@ -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) @@ -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( diff --git a/packages/bundler/test/BundlerServer.test.ts b/packages/bundler/test/BundlerServer.test.ts index e8de390a..5ce8f688 100644 --- a/packages/bundler/test/BundlerServer.test.ts +++ b/packages/bundler/test/BundlerServer.test.ts @@ -49,6 +49,7 @@ describe('BundleServer', function () { minStake: '0', rip7560: false, rip7560Mode: 'PULL', + gethDevMode: false, minUnstakeDelay: 0 } @@ -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, diff --git a/packages/bundler/test/DebugMethodHandler.test.ts b/packages/bundler/test/DebugMethodHandler.test.ts index bb33ce1f..aef75889 100644 --- a/packages/bundler/test/DebugMethodHandler.test.ts +++ b/packages/bundler/test/DebugMethodHandler.test.ts @@ -60,6 +60,7 @@ describe('#DebugMethodHandler', () => { minStake: '0', rip7560: false, rip7560Mode: 'PULL', + gethDevMode: false, minUnstakeDelay: 0 } @@ -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, diff --git a/packages/bundler/test/UserOpMethodHandler.test.ts b/packages/bundler/test/UserOpMethodHandler.test.ts index cd7f29cd..696cc750 100644 --- a/packages/bundler/test/UserOpMethodHandler.test.ts +++ b/packages/bundler/test/UserOpMethodHandler.test.ts @@ -78,6 +78,7 @@ describe('UserOpMethodHandler', function () { minStake: '0', rip7560: false, rip7560Mode: 'PULL', + gethDevMode: false, minUnstakeDelay: 0 } @@ -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,