Skip to content

Commit

Permalink
Staked account rep (#150)
Browse files Browse the repository at this point in the history
* Tracking staked account reputation

* Adding clearMempool, clearReputation debug rpc calls
  • Loading branch information
shahafn authored Oct 2, 2023
1 parent 6b916f1 commit a2cd779
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 8 deletions.
2 changes: 1 addition & 1 deletion packages/bundler/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@account-abstraction/bundler",
"version": "0.6.1",
"version": "0.6.2",
"license": "MIT",
"private": true,
"files": [
Expand Down
6 changes: 5 additions & 1 deletion packages/bundler/src/BundlerConfig.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// TODO: consider adopting config-loading approach from hardhat to allow code in config file
import ow from 'ow'

const MIN_UNSTAKE_DELAY = 86400
const MIN_STAKE_VALUE = 1e18.toString()
export interface BundlerConfig {
beneficiary: string
entryPoint: string
Expand Down Expand Up @@ -48,5 +50,7 @@ export const bundlerConfigDefault: Partial<BundlerConfig> = {
port: '3000',
entryPoint: '0x5FF137D4b0FDCD49DcA30c7CF57E578a026d2789',
unsafe: false,
conditionalRpc: false
conditionalRpc: false,
minStake: MIN_STAKE_VALUE,
minUnstakeDelay: MIN_UNSTAKE_DELAY
}
8 changes: 8 additions & 0 deletions packages/bundler/src/BundlerServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -185,13 +185,21 @@ export class BundlerServer {
case 'debug_bundler_dumpMempool':
result = await this.debugHandler.dumpMempool()
break
case 'debug_bundler_clearMempool':
this.debugHandler.clearMempool()
result = 'ok'
break
case 'debug_bundler_setReputation':
await this.debugHandler.setReputation(params[0])
result = 'ok'
break
case 'debug_bundler_dumpReputation':
result = await this.debugHandler.dumpReputation()
break
case 'debug_bundler_clearReputation':
this.debugHandler.clearReputation()
result = 'ok'
break
case 'debug_bundler_setBundlingMode':
await this.debugHandler.setBundlingMode(params[0])
result = 'ok'
Expand Down
8 changes: 8 additions & 0 deletions packages/bundler/src/DebugMethodHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,19 @@ export class DebugMethodHandler {
return this.mempoolMgr.dump()
}

clearMempool (): void {
this.mempoolMgr.clearState()
}

setReputation (param: any): ReputationDump {
return this.repManager.setReputation(param)
}

dumpReputation (): ReputationDump {
return this.repManager.dump()
}

clearReputation (): void {
this.repManager.clearState()
}
}
2 changes: 1 addition & 1 deletion packages/bundler/src/modules/EventsManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ export class EventsManager {
}

_includedAddress (data: string | null): void {
if (data != null && data.length > 42) {
if (data != null && data.length >= 42) {
const addr = data.slice(0, 42)
this.reputationManager.updateIncludedStatus(addr)
}
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,6 +1,6 @@
import { BigNumber, BigNumberish } from 'ethers'
import { getAddr } from './moduleUtils'
import { requireCond } from '../utils'
import { requireCond, RpcError } from '../utils'
import { ReputationManager } from './ReputationManager'
import Debug from 'debug'
import { ReferencedCodeHashes, StakeInfo, UserOperation, ValidationErrors } from './Types'
Expand Down Expand Up @@ -100,10 +100,16 @@ export class MempoolManager {
this.checkReputation(senderInfo, paymasterInfo, factoryInfo, aggregatorInfo)
this.mempool.push(entry)
}
this.updateSeenStatus(aggregatorInfo?.addr, userOp)
this.updateSeenStatus(aggregatorInfo?.addr, userOp, senderInfo)
}

private updateSeenStatus (aggregator: string | undefined, userOp: UserOperation): void {
private updateSeenStatus (aggregator: string | undefined, userOp: UserOperation, senderInfo: StakeInfo): void {
try {
this.reputationManager.checkStake('account', senderInfo)
this.reputationManager.updateSeenStatus(userOp.sender)
} catch (e: any) {
if (!(e instanceof RpcError)) throw e
}
this.reputationManager.updateSeenStatus(aggregator)
this.reputationManager.updateSeenStatus(getAddr(userOp.paymasterAndData))
this.reputationManager.updateSeenStatus(getAddr(userOp.initCode))
Expand Down
5 changes: 3 additions & 2 deletions packages/bundler/src/modules/ReputationManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ export interface ReputationParams {

export const BundlerReputationParams: ReputationParams = {
minInclusionDenominator: 10,
throttlingSlack: 5,
banSlack: 10
throttlingSlack: 10,
banSlack: 50
}

export const NonBundlerReputationParams: ReputationParams = {
Expand Down Expand Up @@ -58,6 +58,7 @@ export class ReputationManager {
* debug: dump reputation map (with updated "status" for each entry)
*/
dump (): ReputationDump {
Object.values(this.entries).forEach(entry => { entry.status = this.getStatus(entry.address) })
return Object.values(this.entries)
}

Expand Down

0 comments on commit a2cd779

Please sign in to comment.