Skip to content

Commit

Permalink
improve(TransactionUtils): Permit env-based nonce reset (#1834)
Browse files Browse the repository at this point in the history
Permit operators to trigger a nonce reset in case of a queue of pending
transactions.
  • Loading branch information
pxrl committed Sep 23, 2024
1 parent 41d9d73 commit 9cf491b
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/utils/TransactionUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ export type TransactionSimulationResult = {

const { isError, isEthersError } = typeguards;

const nonceReset: { [chainId: number]: boolean } = {};

const txnRetryErrors = new Set(["INSUFFICIENT_FUNDS", "NONCE_EXPIRED", "REPLACEMENT_UNDERPRICED"]);
const expectedRpcErrorMessages = new Set(["nonce has already been used", "intrinsic gas too low"]);
const txnRetryable = (error?: unknown): boolean => {
Expand Down Expand Up @@ -61,7 +63,13 @@ export async function runTransaction(
nonce: number | null = null,
retriesRemaining = 2
): Promise<TransactionResponse> {
const chainId = (await contract.provider.getNetwork()).chainId;
const { provider } = contract;
const { chainId } = await provider.getNetwork();

if (process.env[`ACROSS_RESET_NONCE_${chainId}`] && !nonceReset[chainId]) {
nonce = await provider.getTransactionCount(await contract.signer.getAddress());
nonceReset[chainId] = true;
}

try {
const priorityFeeScaler =
Expand All @@ -71,7 +79,7 @@ export async function runTransaction(
Number(process.env[`MAX_FEE_PER_GAS_SCALER_${chainId}`] || process.env.MAX_FEE_PER_GAS_SCALER) ||
DEFAULT_GAS_FEE_SCALERS[chainId]?.maxFeePerGasScaler;

const gas = await getGasPrice(contract.provider, priorityFeeScaler, maxFeePerGasScaler);
const gas = await getGasPrice(provider, priorityFeeScaler, maxFeePerGasScaler);

logger.debug({
at: "TxUtil",
Expand Down

0 comments on commit 9cf491b

Please sign in to comment.