Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: increase retry count and delay when waiting for transaction receipt #176

Merged
merged 2 commits into from
Feb 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading