From 2641528f29b5b870813586e91b4aadf2efb6b181 Mon Sep 17 00:00:00 2001 From: rouzwelt Date: Tue, 10 Dec 2024 03:54:56 +0000 Subject: [PATCH] update --- src/error.ts | 15 ++++++--------- src/tx.ts | 33 +++++++++++++++++++++++---------- 2 files changed, 29 insertions(+), 19 deletions(-) diff --git a/src/error.ts b/src/error.ts index 65c0922b..881fc0f1 100644 --- a/src/error.ts +++ b/src/error.ts @@ -176,15 +176,12 @@ export async function handleRevert( receipt: TransactionReceipt, rawtx: RawTx, signerBalance: BigNumber, -): Promise< - | { - err: any; - nodeError: boolean; - snapshot: string; - rawRevertError?: TxRevertError; - } - | undefined -> { +): Promise<{ + err: any; + nodeError: boolean; + snapshot: string; + rawRevertError?: TxRevertError; +}> { const header = "transaction reverted onchain"; try { const gasErr = checkGasIssue(receipt, rawtx, signerBalance); diff --git a/src/tx.ts b/src/tx.ts index 1f764d3a..64b0b1fb 100644 --- a/src/tx.ts +++ b/src/tx.ts @@ -281,16 +281,29 @@ export async function handleReceipt( } return result; } else { - // wait at least 90s before simulating the revert tx - // in order for rpcs to catch up - await sleep(Math.max(90_000 + time - Date.now(), 0)); - const simulation = await handleRevert( - signer, - txhash as `0x${string}`, - receipt, - rawtx, - signerBalance, - ); + const simulation = await (async () => { + const result = await handleRevert( + signer, + txhash as `0x${string}`, + receipt, + rawtx, + signerBalance, + ); + if (result.snapshot.includes("simulation failed to find the revert reason")) { + // wait at least 90s before simulating the revert tx + // in order for rpcs to catch up + await sleep(Math.max(90_000 + time - Date.now(), 0)); + return await handleRevert( + signer, + txhash as `0x${string}`, + receipt, + rawtx, + signerBalance, + ); + } else { + return result; + } + })(); if (simulation) { result.error = simulation; spanAttributes["txNoneNodeError"] = !simulation.nodeError;