From 59feee41753cf621a341ee74f59c4a042e73e537 Mon Sep 17 00:00:00 2001 From: Nikita Melnikov Date: Thu, 10 Oct 2024 18:33:45 +0100 Subject: [PATCH 1/5] log execution reverted errors as info messages --- src/cli/customTransport.ts | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/cli/customTransport.ts b/src/cli/customTransport.ts index 0f8f475d..9ee920b1 100644 --- a/src/cli/customTransport.ts +++ b/src/cli/customTransport.ts @@ -54,13 +54,20 @@ export function customTransport( const [{ error, result }] = await fn(body) if (error) { - logger.error( + let loggerFn = logger.error + + if (error.message === "execution reverted") { + loggerFn = logger.info + } + + loggerFn( { error, body }, - "Received error response" + "received error response" ) + throw new RpcRequestError({ body, error: { @@ -75,7 +82,7 @@ export function customTransport( url: url }) } - logger.info({ body, result }, "Received response") + logger.info({ body, result }, "received response") return result }, retryCount, From 4d3f7f81f3a6757747ea625c54910172a1693c4e Mon Sep 17 00:00:00 2001 From: mouseless <97399882+mouseless-eth@users.noreply.github.com> Date: Thu, 10 Oct 2024 20:02:42 +0100 Subject: [PATCH 2/5] skip sending log if revert comes from simulations --- src/cli/customTransport.ts | 69 +++++++++++++++++++++++++++++++++----- 1 file changed, 60 insertions(+), 9 deletions(-) diff --git a/src/cli/customTransport.ts b/src/cli/customTransport.ts index 9ee920b1..8278cc54 100644 --- a/src/cli/customTransport.ts +++ b/src/cli/customTransport.ts @@ -4,9 +4,15 @@ import { type HttpTransportConfig, RpcRequestError, UrlRequiredError, - createTransport + createTransport, + toFunctionSelector, + getAbiItem, + isHex, + slice, + Hex } from "viem" -import { rpc } from "viem/utils" +import { formatAbiItem, rpc } from "viem/utils" +import { EntryPointV06Abi } from "../types/contracts" export type RpcRequest = { jsonrpc?: "2.0" | undefined @@ -15,6 +21,33 @@ export type RpcRequest = { id?: number | undefined } +const EXECUTION_RESULT_SELECTOR = toFunctionSelector( + formatAbiItem( + getAbiItem({ + abi: EntryPointV06Abi, + name: "ExecutionResult" + }) + ) +) + +const VALIDATION_RESULT_SELECTOR = toFunctionSelector( + formatAbiItem( + getAbiItem({ + abi: EntryPointV06Abi, + name: "ValidationResult" + }) + ) +) + +const FAILED_OP_SELECTOR = toFunctionSelector( + formatAbiItem( + getAbiItem({ + abi: EntryPointV06Abi, + name: "FailedOp" + }) + ) +) + export function customTransport( /** URL of the JSON-RPC API. Defaults to the chain's public RPC URL. */ url_: string, @@ -60,13 +93,31 @@ export function customTransport( loggerFn = logger.info } - loggerFn( - { - error, - body - }, - "received error response" - ) + let shouldSkipLog = false + + if (error?.data && isHex(error?.data)) { + const errorSelector = slice(error?.data, 0, 4) + + if ( + [ + EXECUTION_RESULT_SELECTOR, + VALIDATION_RESULT_SELECTOR, + FAILED_OP_SELECTOR + ].includes(errorSelector as Hex) + ) { + shouldSkipLog = true + } + } + + if (!shouldSkipLog) { + loggerFn( + { + error, + body + }, + "received error response" + ) + } throw new RpcRequestError({ body, From 8cf3ea7815081f32e0a4ca80bfda9c54ff2d35f5 Mon Sep 17 00:00:00 2001 From: mouseless <97399882+mouseless-eth@users.noreply.github.com> Date: Thu, 10 Oct 2024 20:05:35 +0100 Subject: [PATCH 3/5] check length before slicing --- src/cli/customTransport.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cli/customTransport.ts b/src/cli/customTransport.ts index 8278cc54..d41162d8 100644 --- a/src/cli/customTransport.ts +++ b/src/cli/customTransport.ts @@ -95,7 +95,7 @@ export function customTransport( let shouldSkipLog = false - if (error?.data && isHex(error?.data)) { + if (isHex(error?.data) && error?.data?.length > 10) { const errorSelector = slice(error?.data, 0, 4) if ( From 84d20ff6d25eb1e98d37a1173c3c6e9abeaa7707 Mon Sep 17 00:00:00 2001 From: Nikita Melnikov Date: Thu, 10 Oct 2024 20:15:06 +0100 Subject: [PATCH 4/5] fix --- src/cli/customTransport.ts | 24 ++++++++---------------- 1 file changed, 8 insertions(+), 16 deletions(-) diff --git a/src/cli/customTransport.ts b/src/cli/customTransport.ts index d41162d8..82d31aa7 100644 --- a/src/cli/customTransport.ts +++ b/src/cli/customTransport.ts @@ -89,12 +89,6 @@ export function customTransport( if (error) { let loggerFn = logger.error - if (error.message === "execution reverted") { - loggerFn = logger.info - } - - let shouldSkipLog = false - if (isHex(error?.data) && error?.data?.length > 10) { const errorSelector = slice(error?.data, 0, 4) @@ -105,19 +99,17 @@ export function customTransport( FAILED_OP_SELECTOR ].includes(errorSelector as Hex) ) { - shouldSkipLog = true + loggerFn = logger.info } } - if (!shouldSkipLog) { - loggerFn( - { - error, - body - }, - "received error response" - ) - } + loggerFn( + { + error, + body + }, + "received error response" + ) throw new RpcRequestError({ body, From 2b1ade9f6fcc956a33acf687834c4f56d0c0fc6f Mon Sep 17 00:00:00 2001 From: Nikita Melnikov Date: Thu, 10 Oct 2024 20:27:37 +0100 Subject: [PATCH 5/5] try with bind --- src/cli/customTransport.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/cli/customTransport.ts b/src/cli/customTransport.ts index 82d31aa7..7a30b201 100644 --- a/src/cli/customTransport.ts +++ b/src/cli/customTransport.ts @@ -87,7 +87,7 @@ export function customTransport( const [{ error, result }] = await fn(body) if (error) { - let loggerFn = logger.error + let loggerFn = logger.error.bind(logger) if (isHex(error?.data) && error?.data?.length > 10) { const errorSelector = slice(error?.data, 0, 4) @@ -99,13 +99,13 @@ export function customTransport( FAILED_OP_SELECTOR ].includes(errorSelector as Hex) ) { - loggerFn = logger.info + loggerFn = logger.info.bind(logger) } } loggerFn( { - error, + err: error, body }, "received error response"