Skip to content

Commit

Permalink
handle errors better
Browse files Browse the repository at this point in the history
  • Loading branch information
mouseless0x committed Oct 30, 2024
1 parent e614196 commit a21c351
Showing 1 changed file with 21 additions and 3 deletions.
24 changes: 21 additions & 3 deletions src/executor/executor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ import {
getContract,
type Account,
type Hex,
BaseError
BaseError,
NonceTooHighError
} from "viem"
import {
type CompressedFilterOpsAndEstimateGasParams,
Expand Down Expand Up @@ -572,9 +573,16 @@ export class Executor {
if (error instanceof TransactionExecutionError) {
const cause = error.cause

if (cause instanceof NonceTooLowError) {
if (
cause instanceof NonceTooLowError ||
cause instanceof NonceTooHighError
) {
this.logger.warn("Nonce too low, retrying")
request.nonce += 1
request.nonce =
await this.config.publicClient.getTransactionCount({
address: request.account.address,
blockTag: "pending"
})
isErrorHandled = true
}

Expand All @@ -583,6 +591,16 @@ export class Executor {
request.gas = scaleBigIntByPercent(request.gas, 150)
isErrorHandled = true
}

// This is thrown by OP-Stack chains that use proxyd.
// ref: https://github.com/ethereum-optimism/optimism/issues/2618#issuecomment-1630272888
if (cause.details?.includes("no backends available")) {
this.logger.warn(
"no backends avaiable error, retrying after 500ms"
)
await new Promise((resolve) => setTimeout(resolve, 500))
isErrorHandled = true
}
}

if (attempts === maxAttempts || !isErrorHandled) {
Expand Down

0 comments on commit a21c351

Please sign in to comment.