Skip to content

Commit

Permalink
Merge pull request #224 from pimlicolabs/PIM-1045
Browse files Browse the repository at this point in the history
Include v0.7 paymaster gas limit multiplier
  • Loading branch information
mouseless0x authored May 27, 2024
2 parents 78d12ab + b69f37d commit 5f0fb58
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 25 deletions.
8 changes: 7 additions & 1 deletion src/cli/config/bundler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,10 @@ export const bundlerArgsSchema = z.object({
"mempool-max-parallel-ops": z.number().int().min(0).default(10),
"mempool-max-queued-ops": z.number().int().min(0).default(0),
"enforce-unique-senders-per-bundle": z.boolean().default(true),
"max-gas-per-bundle": z.string().transform((val) => BigInt(val)).default("5000000"),
"max-gas-per-bundle": z
.string()
.transform((val) => BigInt(val))
.default("5000000")
})

export const compatibilityArgsSchema = z.object({
Expand All @@ -93,6 +96,9 @@ export const compatibilityArgsSchema = z.object({
"balance-override": z.boolean(),
"local-gas-limit-calculation": z.boolean(),
"flush-stuck-transactions-during-startup": z.boolean(),
"paymaster-gas-limit-multiplier": z
.string()
.transform((val) => BigInt(val)),
"fixed-gas-limit-for-estimation": z
.string()
.transform((val) => BigInt(val))
Expand Down
26 changes: 18 additions & 8 deletions src/cli/config/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,29 +106,32 @@ export const bundlerOptions: CliCommandOptions<IBundlerArgsInput> = {
default: "105,110,115"
},
"mempool-max-parallel-ops": {
description: "Maximum amount of parallel user ops to keep in the meempool (same sender, different nonce keys)",
description:
"Maximum amount of parallel user ops to keep in the meempool (same sender, different nonce keys)",
type: "number",
require: false,
default: 10,
default: 10
},
"mempool-max-queued-ops": {
description: "Maximum amount of sequential user ops to keep in the mempool (same sender and nonce key, different nonce values)",
description:
"Maximum amount of sequential user ops to keep in the mempool (same sender and nonce key, different nonce values)",
type: "number",
require: false,
default: 0,
default: 0
},
"enforce-unique-senders-per-bundle": {
description: "Include user ops with the same sender in the single bundle",
description:
"Include user ops with the same sender in the single bundle",
type: "boolean",
require: false,
default: true,
default: true
},
"max-gas-per-bundle": {
description: "Maximum amount of gas per bundle",
type: "string",
require: false,
default: "5000000",
},
default: "5000000"
}
}

export const compatibilityOptions: CliCommandOptions<ICompatibilityArgsInput> =
Expand Down Expand Up @@ -186,6 +189,13 @@ export const compatibilityOptions: CliCommandOptions<ICompatibilityArgsInput> =
type: "string",
require: false,
default: "v1"
},
"paymaster-gas-limit-multiplier": {
description:
"Amount to multiply the paymaster gas limits fetched from simulations",
type: "string",
require: true,
default: "110"
}
}

Expand Down
1 change: 1 addition & 0 deletions src/cli/setupServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,7 @@ const getRpcHandler = ({
gasPriceManager,
parsedArgs["gas-price-multipliers"],
parsedArgs["chain-type"],
parsedArgs["paymaster-gas-limit-multiplier"],
parsedArgs["dangerous-skip-user-operation-validation"]
)
}
Expand Down
56 changes: 40 additions & 16 deletions src/rpc/rpcHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ export class RpcHandler implements IRpcEndpoint {
dangerousSkipUserOperationValidation: boolean
gasPriceManager: GasPriceManager
gasPriceMultipliers: GasPriceMultipliers
paymasterGasLimitMultiplier: bigint

constructor(
entryPoints: Address[],
Expand All @@ -152,6 +153,7 @@ export class RpcHandler implements IRpcEndpoint {
gasPriceManager: GasPriceManager,
gasPriceMultipliers: GasPriceMultipliers,
chainType: ChainType,
paymasterGasLimitMultiplier: bigint,
dangerousSkipUserOperationValidation = false
) {
this.entryPoints = entryPoints
Expand All @@ -176,6 +178,7 @@ export class RpcHandler implements IRpcEndpoint {
this.gasPriceMultipliers = gasPriceMultipliers
this.chainType = chainType
this.gasPriceManager = gasPriceManager
this.paymasterGasLimitMultiplier = paymasterGasLimitMultiplier
}

async handleMethod(
Expand Down Expand Up @@ -368,14 +371,18 @@ export class RpcHandler implements IRpcEndpoint {
// maxFeePerGas to maxPriorityFeePerGas
userOperation.maxPriorityFeePerGas = userOperation.maxFeePerGas


// Check if the nonce is valid
// If the nonce is less than the current nonce, the user operation has already been executed
// If the nonce is greater than the current nonce, we may have missing user operations in the mempool
const currentNonceValue = await this.getNonceValue(userOperation, entryPoint)
const [,userOperationNonceValue] = getNonceKeyAndValue(userOperation.nonce)
const currentNonceValue = await this.getNonceValue(
userOperation,
entryPoint
)
const [, userOperationNonceValue] = getNonceKeyAndValue(
userOperation.nonce
)

let queuedUserOperations: UserOperation[] = [];
let queuedUserOperations: UserOperation[] = []
if (userOperationNonceValue < currentNonceValue) {
throw new RpcError(
"UserOperation reverted during simulation with reason: AA25 invalid account nonce",
Expand All @@ -395,9 +402,12 @@ export class RpcHandler implements IRpcEndpoint {
userOperation,
entryPoint,
currentNonceValue
);
)

if (userOperationNonceValue > currentNonceValue + BigInt(queuedUserOperations.length)) {
if (
userOperationNonceValue >
currentNonceValue + BigInt(queuedUserOperations.length)
) {
throw new RpcError(
"UserOperation reverted during simulation with reason: AA25 invalid account nonce",
ValidationErrors.InvalidFields
Expand All @@ -409,7 +419,7 @@ export class RpcHandler implements IRpcEndpoint {
userOperation,
entryPoint,
queuedUserOperations,
stateOverrides,
stateOverrides
)

let { verificationGasLimit, callGasLimit } =
Expand All @@ -436,6 +446,14 @@ export class RpcHandler implements IRpcEndpoint {
paymasterPostOpGasLimit =
executionResult.data.executionResult.paymasterPostOpGasLimit ||
1n

const multiplier = this.paymasterGasLimitMultiplier

paymasterVerificationGasLimit =
(paymasterVerificationGasLimit * multiplier) / 100n

paymasterPostOpGasLimit =
(paymasterPostOpGasLimit * multiplier) / 100n
}

if (
Expand Down Expand Up @@ -980,8 +998,13 @@ export class RpcHandler implements IRpcEndpoint {
)
}

const currentNonceValue = await this.getNonceValue(userOperation, entryPoint)
const [,userOperationNonceValue] = getNonceKeyAndValue(userOperation.nonce)
const currentNonceValue = await this.getNonceValue(
userOperation,
entryPoint
)
const [, userOperationNonceValue] = getNonceKeyAndValue(
userOperation.nonce
)

if (userOperationNonceValue < currentNonceValue) {
throw new RpcError(
Expand All @@ -997,7 +1020,10 @@ export class RpcHandler implements IRpcEndpoint {
}

let queuedUserOperations: UserOperation[] = []
if (userOperationNonceValue > currentNonceValue && isVersion07(userOperation)) {
if (
userOperationNonceValue > currentNonceValue &&
isVersion07(userOperation)
) {
queuedUserOperations = await this.mempool.getQueuedUserOperations(
userOperation,
entryPoint,
Expand All @@ -1006,7 +1032,8 @@ export class RpcHandler implements IRpcEndpoint {
}

if (
userOperationNonceValue === currentNonceValue + BigInt(queuedUserOperations.length)
userOperationNonceValue ===
currentNonceValue + BigInt(queuedUserOperations.length)
) {
if (this.dangerousSkipUserOperationValidation) {
const success = this.mempool.add(op, entryPoint)
Expand Down Expand Up @@ -1165,10 +1192,7 @@ export class RpcHandler implements IRpcEndpoint {
return { inflatedOp, inflatorId }
}

async getNonceValue(
userOperation: UserOperation,
entryPoint: Address
) {
async getNonceValue(userOperation: UserOperation, entryPoint: Address) {
const entryPointContract = getContract({
address: entryPoint,
abi: isVersion06(userOperation)
Expand All @@ -1179,7 +1203,7 @@ export class RpcHandler implements IRpcEndpoint {
}
})

const [nonceKey,] = getNonceKeyAndValue(userOperation.nonce)
const [nonceKey] = getNonceKeyAndValue(userOperation.nonce)

const getNonceResult = await entryPointContract.read.getNonce(
[userOperation.sender, nonceKey],
Expand Down

0 comments on commit 5f0fb58

Please sign in to comment.