Skip to content

Commit

Permalink
SREP-010 add RPC debug API
Browse files Browse the repository at this point in the history
  • Loading branch information
forshtat committed Oct 2, 2023
1 parent 083936f commit 0a7c3c5
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 1 deletion.
3 changes: 3 additions & 0 deletions packages/bundler/src/BundlerServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,9 @@ export class BundlerServer {
result = 'ok'
}
break
case 'debug_bundler_getAddressStakeStatus':
result = await this.debugHandler.getAddressStakeStatus(params[0], params[1])
break
default:
throw new RpcError(`Method ${method} is not supported`, -32601)
}
Expand Down
11 changes: 11 additions & 0 deletions packages/bundler/src/DebugMethodHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +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'

export class DebugMethodHandler {
constructor (
Expand Down Expand Up @@ -65,4 +66,14 @@ export class DebugMethodHandler {
clearReputation (): void {
this.repManager.clearState()
}

async getAddressStakeStatus (
address: string,
entryPoint: string
): Promise<{
stakeInfo: StakeInfo
isStaked: boolean
}> {
return await this.repManager.getStakeStatus(address, entryPoint)
}
}
23 changes: 23 additions & 0 deletions packages/bundler/src/modules/ReputationManager.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import Debug from 'debug'
import { requireCond, tostr } from '../utils'
import { BigNumber } from 'ethers'
import { Provider } from '@ethersproject/providers'

import { StakeInfo, ValidationErrors } from './Types'
import { IStakeManager__factory } from '../types'

const debug = Debug('aa.rep')

Expand Down Expand Up @@ -42,6 +45,7 @@ export type ReputationDump = ReputationEntry[]

export class ReputationManager {
constructor (
readonly provider: Provider,
readonly params: ReputationParams,
readonly minStake: BigNumber,
readonly minUnstakeDelay: number) {
Expand Down Expand Up @@ -149,6 +153,25 @@ export class ReputationManager {
}
}

async getStakeStatus (address: string, entryPointAddress: string): Promise<{
stakeInfo: StakeInfo
isStaked: boolean
}> {
const sm = IStakeManager__factory.connect(entryPointAddress, this.provider)
const info = await sm.getDepositInfo(address)
const isStaked =
BigNumber.from(info.stake).gte(this.minStake) &&
BigNumber.from(info.unstakeDelaySec).gte(this.minUnstakeDelay)
return {
stakeInfo: {
addr: address,
stake: info.stake.toString(),
unstakeDelaySec: info.unstakeDelaySec.toString()
},
isStaked
}
}

/**
* an entity that caused handleOps to revert, which requires re-building the bundle from scratch.
* should be banned immediately, by increasing its opSeen counter
Expand Down
3 changes: 2 additions & 1 deletion packages/bundler/src/modules/initServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { parseEther } from 'ethers/lib/utils'
import { Signer } from 'ethers'
import { BundlerConfig } from '../BundlerConfig'
import { EventsManager } from './EventsManager'
import { getNetworkProvider } from '../Config'

/**
* initialize server modules.
Expand All @@ -17,7 +18,7 @@ import { EventsManager } from './EventsManager'
*/
export function initServer (config: BundlerConfig, signer: Signer): [ExecutionManager, EventsManager, ReputationManager, MempoolManager] {
const entryPoint = EntryPoint__factory.connect(config.entryPoint, signer)
const reputationManager = new ReputationManager(BundlerReputationParams, parseEther(config.minStake), config.minUnstakeDelay)
const reputationManager = new ReputationManager(getNetworkProvider(config.network), BundlerReputationParams, parseEther(config.minStake), config.minUnstakeDelay)
const mempoolManager = new MempoolManager(reputationManager)
const validationManager = new ValidationManager(entryPoint, reputationManager, config.unsafe)
const eventsManager = new EventsManager(entryPoint, mempoolManager, reputationManager)
Expand Down

0 comments on commit 0a7c3c5

Please sign in to comment.