From c4ab9732d4b5909afe3f44c38b6360e1a08c03b9 Mon Sep 17 00:00:00 2001 From: Garvit Khatri Date: Sat, 21 Sep 2024 16:37:05 +0100 Subject: [PATCH] remove getNonce call to entryPoint --- src/rpc/rpcHandler.ts | 55 ++++++++++++++----------------------------- 1 file changed, 18 insertions(+), 37 deletions(-) diff --git a/src/rpc/rpcHandler.ts b/src/rpc/rpcHandler.ts index 9ece96c0..807f9296 100644 --- a/src/rpc/rpcHandler.ts +++ b/src/rpc/rpcHandler.ts @@ -378,46 +378,27 @@ export class RpcHandler implements IRpcEndpoint { // 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 [userOperationNonceKey, userOperationNonceValue] = + getNonceKeyAndValue(userOperation.nonce) - let queuedUserOperations: UserOperation[] = [] - if (userOperationNonceValue < currentNonceValue) { - throw new RpcError( - "UserOperation reverted during simulation with reason: AA25 invalid account nonce", - ValidationErrors.InvalidFields - ) - } - if (userOperationNonceValue > currentNonceValue) { - // Nonce queues are supported only for v7 user operations - if (isVersion06(userOperation)) { - throw new RpcError( - "UserOperation reverted during simulation with reason: AA25 invalid account nonce", - ValidationErrors.InvalidFields - ) - } - - queuedUserOperations = await this.mempool.getQueuedUserOperations( - userOperation, - entryPoint, - currentNonceValue + const queuedUserOperations: UserOperation[] = this.mempool + .dumpOutstanding() + .map((userOpInfo) => + deriveUserOperation(userOpInfo.mempoolUserOperation) ) - - if ( - userOperationNonceValue > - currentNonceValue + BigInt(queuedUserOperations.length) - ) { - throw new RpcError( - "UserOperation reverted during simulation with reason: AA25 invalid account nonce", - ValidationErrors.InvalidFields + .filter((uo) => { + const [opNonceKey, opNonceValue] = getNonceKeyAndValue(uo.nonce) + + return ( + uo.sender === userOperation.sender && + opNonceKey === userOperationNonceKey && + // on chain nonce - 12 + // in mempool nonce - 11, 13, 15, 18 + // current user operation nonce - 16 + // need to pick 11, 13, 14, 15 + opNonceValue < userOperationNonceValue ) - } - } + }) const executionResult = await this.validator.getExecutionResult( userOperation,