Skip to content

Commit

Permalink
fix: increase retry count and delay when waiting for transaction rece…
Browse files Browse the repository at this point in the history
…ipt (#176)
  • Loading branch information
chybisov authored Feb 1, 2024
1 parent 6f0b16c commit 4a9cad0
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/core/EVM/EVMStepExecutor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import { checkAllowance } from './checkAllowance.js'
import { updateMultisigRouteProcess } from './multisig.js'
import { switchChain } from './switchChain.js'
import type { MultisigConfig, MultisigTransaction } from './types.js'
import { getMaxPriorityFeePerGas } from './utils.js'
import { getMaxPriorityFeePerGas, retryCount, retryDelay } from './utils.js'

export interface EVMStepExecutorOptions extends StepExecutorOptions {
walletClient: WalletClient
Expand Down Expand Up @@ -332,6 +332,8 @@ export class EVMStepExecutor extends BaseStepExecutor {
txLink: `${fromChain.metamask.blockExplorerUrls[0]}tx/${response.transaction.hash}`,
})
},
retryCount,
retryDelay,
})

if (replacementReason === 'cancelled') {
Expand Down
3 changes: 3 additions & 0 deletions src/core/EVM/checkAllowance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import type { StatusManager } from '../StatusManager.js'
import type { ExecutionOptions } from '../types.js'
import { getAllowance } from './getAllowance.js'
import { setAllowance } from './setAllowance.js'
import { retryCount, retryDelay } from './utils.js'

export const checkAllowance = async (
chain: Chain,
Expand Down Expand Up @@ -136,6 +137,8 @@ const waitForApprovalTransaction = async (
txLink: `${chain.metamask.blockExplorerUrls[0]}tx/${response.transaction.hash}`,
})
},
retryCount,
retryDelay,
})

if (replacementReason === 'cancelled') {
Expand Down
5 changes: 5 additions & 0 deletions src/core/EVM/setAllowance.int.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { polygon } from 'viem/chains'
import { beforeAll, describe, expect, it } from 'vitest'
import { setupTestEnvironment } from '../../../tests/setup.js'
import { revokeTokenApproval, setTokenAllowance } from './setAllowance.js'
import { retryCount, retryDelay } from './utils.js'

const defaultSpenderAddress = '0x9b11bc9FAc17c058CAB6286b0c785bE6a65492EF'
const testToken = {
Expand Down Expand Up @@ -49,6 +50,8 @@ describe.skipIf(!MNEMONIC)('Approval integration tests', () => {
if (revokeTxHash) {
const transactionReceipt = await client.waitForTransactionReceipt({
hash: revokeTxHash!,
retryCount,
retryDelay,
})

expect(transactionReceipt.status).toBe('success')
Expand All @@ -70,6 +73,8 @@ describe.skipIf(!MNEMONIC)('Approval integration tests', () => {
if (approvalTxHash) {
const transactionReceipt = await client.waitForTransactionReceipt({
hash: approvalTxHash!,
retryCount,
retryDelay,
})

expect(transactionReceipt.status).toBe('success')
Expand Down
7 changes: 7 additions & 0 deletions src/core/EVM/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,10 @@ export const getMulticallAddress = async (
const chains = await config.getChains()
return chains.find((chain) => chain.id === chainId)?.multicallAddress
}

// Modified viem retryDelay exponential backoff function.
// Together with adjusted retryCount gives us 25 seconds to wait for the block or transaction.
export const retryDelay = ({ count }: { count: number; error: Error }) =>
Math.min(~~(1 << count) * 200, 2000)

export const retryCount = 15

0 comments on commit 4a9cad0

Please sign in to comment.