Skip to content

Commit

Permalink
Merge branch 'main' into get-configuration-rpc
Browse files Browse the repository at this point in the history
  • Loading branch information
drortirosh authored Nov 22, 2023
2 parents 0cceb95 + 436f122 commit 8300830
Show file tree
Hide file tree
Showing 39 changed files with 614 additions and 344 deletions.
18 changes: 0 additions & 18 deletions packages/bundler/contracts/BundlerHelper.sol
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,3 @@ contract GetUserOpHashes {
}
}
}

contract GetCodeHashes {

error CodeHashesResult(bytes32 hash);
constructor(address[] memory addresses) {
revert CodeHashesResult(getCodeHashes(addresses));
}

function getCodeHashes(address[] memory addresses) public view returns (bytes32) {
bytes32[] memory hashes = new bytes32[](addresses.length);
for (uint i = 0; i < addresses.length; i++) {
hashes[i] = addresses[i].codehash;
}
bytes memory data = abi.encode(hashes);
return (keccak256(data));
}

}
1 change: 1 addition & 0 deletions packages/bundler/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
"@account-abstraction/contracts": "^0.6.0",
"@account-abstraction/sdk": "^0.6.0",
"@account-abstraction/utils": "^0.6.0",
"@account-abstraction/validation-manager": "^0.6.0",
"@ethersproject/abi": "^5.7.0",
"@ethersproject/properties": "^5.7.0",
"@ethersproject/providers": "^5.7.0",
Expand Down
2 changes: 2 additions & 0 deletions packages/bundler/src/BundlerConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ export interface BundlerConfig {
network: string
port: string
unsafe: boolean
debugRpc?: boolean
conditionalRpc: boolean

whitelist?: string[]
Expand All @@ -72,6 +73,7 @@ export const BundlerConfigShape = {
network: ow.string,
port: ow.string,
unsafe: ow.boolean,
debugRpc: ow.optional.boolean,
conditionalRpc: ow.boolean,

whitelist: ow.optional.array.ofType(ow.string),
Expand Down
3 changes: 1 addition & 2 deletions packages/bundler/src/BundlerServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,11 @@ import { Provider } from '@ethersproject/providers'
import { Signer, utils } from 'ethers'
import { parseEther } from 'ethers/lib/utils'

import { AddressZero, deepHexlify, erc4337RuntimeVersion } from '@account-abstraction/utils'
import { AddressZero, deepHexlify, erc4337RuntimeVersion, RpcError } from '@account-abstraction/utils'

import { BundlerConfig } from './BundlerConfig'
import { UserOpMethodHandler } from './UserOpMethodHandler'
import { Server } from 'http'
import { RpcError } from './utils'
import { EntryPoint__factory, UserOperationStruct } from '@account-abstraction/contracts'
import { DebugMethodHandler } from './DebugMethodHandler'

Expand Down
2 changes: 1 addition & 1 deletion packages/bundler/src/DebugMethodHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { ReputationDump, ReputationManager } from './modules/ReputationManager'
import { MempoolManager } from './modules/MempoolManager'
import { SendBundleReturn } from './modules/BundleManager'
import { EventsManager } from './modules/EventsManager'
import { StakeInfo } from './modules/Types'
import { StakeInfo } from '@account-abstraction/utils'

export class DebugMethodHandler {
constructor (
Expand Down
2 changes: 1 addition & 1 deletion packages/bundler/src/RpcTypes.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { BigNumberish } from 'ethers'
import { TransactionReceipt } from '@ethersproject/providers'
import { UserOperation } from './modules/Types'
import { UserOperation } from '@account-abstraction/utils'

/**
* RPC calls return types
Expand Down
7 changes: 2 additions & 5 deletions packages/bundler/src/UserOpMethodHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,12 @@ import { Log, Provider } from '@ethersproject/providers'

import { BundlerConfig } from './BundlerConfig'
import { resolveProperties } from 'ethers/lib/utils'
import { deepHexlify, erc4337RuntimeVersion } from '@account-abstraction/utils'
import { UserOperation, deepHexlify, erc4337RuntimeVersion, requireCond, RpcError, tostr, getAddr, ValidationErrors } from '@account-abstraction/utils'
import { UserOperationStruct, EntryPoint } from '@account-abstraction/contracts'
import { UserOperationEventEvent } from '@account-abstraction/contracts/dist/types/EntryPoint'
import { calcPreVerificationGas } from '@account-abstraction/sdk'
import { requireCond, RpcError, tostr } from './utils'
import { ExecutionManager } from './modules/ExecutionManager'
import { getAddr } from './modules/moduleUtils'
import { UserOperationByHashResponse, UserOperationReceipt } from './RpcTypes'
import { ExecutionErrors, UserOperation, ValidationErrors } from './modules/Types'

const HEX_REGEX = /^0x[a-fA-F\d]*$/i

Expand Down Expand Up @@ -133,7 +130,7 @@ export class UserOpMethodHandler {
data: userOp.callData
}).then(b => b.toNumber()).catch(err => {
const message = err.message.match(/reason="(.*?)"/)?.at(1) ?? 'execution reverted'
throw new RpcError(message, ExecutionErrors.UserOperationReverted)
throw new RpcError(message, ValidationErrors.UserOperationReverted)
})
validAfter = BigNumber.from(validAfter)
validUntil = BigNumber.from(validUntil)
Expand Down
13 changes: 8 additions & 5 deletions packages/bundler/src/modules/BundleManager.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
import { EntryPoint } from '@account-abstraction/contracts'
import { MempoolManager } from './MempoolManager'
import { ValidateUserOpResult, ValidationManager } from './ValidationManager'
import { ValidateUserOpResult, ValidationManager } from '@account-abstraction/validation-manager'
import { BigNumber, BigNumberish } from 'ethers'
import { JsonRpcProvider, JsonRpcSigner } from '@ethersproject/providers'
import Debug from 'debug'
import { ReputationManager, ReputationStatus } from './ReputationManager'
import { Mutex } from 'async-mutex'
import { GetUserOpHashes__factory } from '../types'
import { StorageMap, UserOperation } from './Types'
import { getAddr, mergeStorageMap, runContractScript } from './moduleUtils'
import { UserOperation, StorageMap, getAddr, mergeStorageMap, runContractScript } from '@account-abstraction/utils'
import { EventsManager } from './EventsManager'
import { ErrorDescription } from '@ethersproject/abi/lib/interface'

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

const THROTTLED_ENTITY_BUNDLE_COUNT = 4

export interface SendBundleReturn {
transactionHash: string
userOpHashes: string[]
Expand Down Expand Up @@ -172,11 +173,13 @@ export class BundleManager {
this.mempoolManager.removeUserOp(entry.userOp)
continue
}
if (paymaster != null && (paymasterStatus === ReputationStatus.THROTTLED ?? (stakedEntityCount[paymaster] ?? 0) > 1)) {
// [SREP-030]
if (paymaster != null && (paymasterStatus === ReputationStatus.THROTTLED ?? (stakedEntityCount[paymaster] ?? 0) > THROTTLED_ENTITY_BUNDLE_COUNT)) {
debug('skipping throttled paymaster', entry.userOp.sender, entry.userOp.nonce)
continue
}
if (factory != null && (deployerStatus === ReputationStatus.THROTTLED ?? (stakedEntityCount[factory] ?? 0) > 1)) {
// [SREP-030]
if (factory != null && (deployerStatus === ReputationStatus.THROTTLED ?? (stakedEntityCount[factory] ?? 0) > THROTTLED_ENTITY_BUNDLE_COUNT)) {
debug('skipping throttled factory', entry.userOp.sender, entry.userOp.nonce)
continue
}
Expand Down
13 changes: 7 additions & 6 deletions packages/bundler/src/modules/ExecutionManager.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { ReputationManager } from './ReputationManager'
import { clearInterval } from 'timers'
import { MempoolManager } from './MempoolManager'
import { BundleManager, SendBundleReturn } from './BundleManager'
import Debug from 'debug'
import { ValidationManager } from './ValidationManager'
import { Mutex } from 'async-mutex'
import { UserOperation } from './Types'
import { ValidationManager } from '@account-abstraction/validation-manager'
import { UserOperation } from '@account-abstraction/utils'
import { clearInterval } from 'timers'

import { BundleManager, SendBundleReturn } from './BundleManager'
import { MempoolManager } from './MempoolManager'
import { ReputationManager } from './ReputationManager'

const debug = Debug('aa.exec')

Expand Down
12 changes: 9 additions & 3 deletions packages/bundler/src/modules/MempoolManager.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
import { BigNumber, BigNumberish } from 'ethers'
import { getAddr } from './moduleUtils'
import { requireCond, RpcError } from '../utils'
import {
ReferencedCodeHashes,
RpcError,
StakeInfo,
UserOperation,
ValidationErrors,
getAddr,
requireCond
} from '@account-abstraction/utils'
import { ReputationManager } from './ReputationManager'
import Debug from 'debug'
import { ReferencedCodeHashes, StakeInfo, UserOperation, ValidationErrors } from './Types'

const debug = Debug('aa.mempool')

Expand Down
6 changes: 3 additions & 3 deletions packages/bundler/src/modules/ReputationManager.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import Debug from 'debug'
import { requireCond, tostr } from '../utils'
import { BigNumber } from 'ethers'
import { Provider } from '@ethersproject/providers'

import { StakeInfo, ValidationErrors } from './Types'
import { StakeInfo, ValidationErrors, requireCond, tostr } from '@account-abstraction/utils'
import { IStakeManager__factory } from '../types'

const debug = Debug('aa.rep')
Expand Down Expand Up @@ -171,7 +170,8 @@ export class ReputationManager {
}
// todo: what value to put? how long do we want this banning to hold?
const entry = this._getOrCreate(addr)
entry.opsSeen = 100
// [SREP-050]
entry.opsSeen += 10000
entry.opsIncluded = 0
debug('crashedHandleOps', addr, entry)
}
Expand Down
47 changes: 0 additions & 47 deletions packages/bundler/src/modules/Types.ts

This file was deleted.

4 changes: 2 additions & 2 deletions packages/bundler/src/modules/initServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { ExecutionManager } from './ExecutionManager'
import { ReputationManager } from './ReputationManager'
import { MempoolManager } from './MempoolManager'
import { BundleManager } from './BundleManager'
import { ValidationManager } from './ValidationManager'
import { ValidationManager } from '@account-abstraction/validation-manager'
import { EntryPoint__factory } from '@account-abstraction/contracts'
import { parseEther } from 'ethers/lib/utils'
import { Signer } from 'ethers'
Expand All @@ -29,7 +29,7 @@ export function initServer (config: BundlerConfig, signer: Signer): [ExecutionMa
parseInt(config.eipParams.MIN_UNSTAKE_DELAY)
)
const mempoolManager = new MempoolManager(reputationManager)
const validationManager = new ValidationManager(entryPoint, reputationManager, config.unsafe)
const validationManager = new ValidationManager(entryPoint, config.unsafe)
const eventsManager = new EventsManager(entryPoint, mempoolManager, reputationManager)
const bundleManager = new BundleManager(entryPoint, eventsManager, mempoolManager, validationManager, reputationManager,
config.beneficiary, parseEther(config.minBalance), config.maxBundleGas, config.conditionalRpc)
Expand Down
71 changes: 0 additions & 71 deletions packages/bundler/src/modules/moduleUtils.ts

This file was deleted.

19 changes: 16 additions & 3 deletions packages/bundler/src/runBundler.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import fs from 'fs'

import { Command } from 'commander'
import { erc4337RuntimeVersion } from '@account-abstraction/utils'
import { erc4337RuntimeVersion, RpcError, supportsRpcMethod } from '@account-abstraction/utils'
import { ethers, Wallet, Signer } from 'ethers'

import { BundlerServer } from './BundlerServer'
Expand All @@ -11,7 +11,7 @@ import { EntryPoint, EntryPoint__factory } from '@account-abstraction/contracts'
import { initServer } from './modules/initServer'
import { DebugMethodHandler } from './DebugMethodHandler'
import { DeterministicDeployer } from '@account-abstraction/sdk'
import { supportsDebugTraceCall, supportsRpcMethod } from './utils'
import { supportsDebugTraceCall } from '@account-abstraction/validation-manager'
import { resolveConfiguration } from './Config'
import { bundlerConfigDefault } from './BundlerConfig'
import { JsonRpcProvider } from '@ethersproject/providers'
Expand Down Expand Up @@ -70,6 +70,7 @@ export async function runBundler (argv: string[], overrideExit = true): Promise<
.option('--config <string>', 'path to config file', CONFIG_FILE_NAME)
.option('--auto', 'automatic bundling (bypass config.autoBundleMempoolSize)', false)
.option('--unsafe', 'UNSAFE mode: no storage or opcode checks (safe mode requires geth)')
.option('--debugRpc', 'enable debug rpc methods (auto-enabled for test node')
.option('--conditionalRpc', 'Use eth_sendRawTransactionConditional RPC)')
.option('--show-stack-traces', 'Show stack traces.')
.option('--createMnemonic <file>', 'create the mnemonic file')
Expand Down Expand Up @@ -98,6 +99,12 @@ export async function runBundler (argv: string[], overrideExit = true): Promise<
} = await provider.getNetwork()

if (chainId === 31337 || chainId === 1337) {
if (config.debugRpc == null) {
console.log('== debugrpc was', config.debugRpc)
config.debugRpc = true
} else {
console.log('== debugrpc already st', config.debugRpc)
}
await new DeterministicDeployer(provider as any).deterministicDeploy(EntryPoint__factory.bytecode)
if ((await wallet.getBalance()).eq(0)) {
console.log('=== testnet: fund signer')
Expand Down Expand Up @@ -138,7 +145,13 @@ export async function runBundler (argv: string[], overrideExit = true): Promise<
entryPoint
)
eventsManager.initEventListener()
const debugHandler = new DebugMethodHandler(execManager, eventsManager, reputationManager, mempoolManager)
const debugHandler = config.debugRpc ?? false
? new DebugMethodHandler(execManager, eventsManager, reputationManager, mempoolManager)
: new Proxy({}, {
get (target: {}, method: string, receiver: any): any {
throw new RpcError(`method debug_bundler_${method} is not supported`, -32601)
}
}) as DebugMethodHandler

const bundlerServer = new BundlerServer(
methodHandler,
Expand Down
Loading

0 comments on commit 8300830

Please sign in to comment.