Skip to content

Commit 5923c38

Browse files
committed
account for gas estimation difference during spikes
1 parent 995236f commit 5923c38

File tree

1 file changed

+18
-5
lines changed

1 file changed

+18
-5
lines changed

core/tests/ts-integration/src/helpers.ts

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import * as zksync from 'zksync-ethers';
33
import * as ethers from 'ethers';
44
import * as hre from 'hardhat';
55
import { ZkSyncArtifact } from '@matterlabs/hardhat-zksync-solc/dist/src/types';
6-
import { TimeoutError } from 'ethers/src.ts/utils/errors';
6+
import { TransactionReceipt } from 'ethers';
77

88
export const SYSTEM_CONTEXT_ADDRESS = '0x000000000000000000000000000000000000800b';
99

@@ -75,7 +75,7 @@ export async function waitForNewL1Batch(wallet: zksync.Wallet): Promise<zksync.t
7575
const MAX_ATTEMPTS = 3;
7676

7777
let txResponse = null;
78-
let txReceipt = null;
78+
let txReceipt: TransactionReceipt | null = null;
7979
let nonce = Number(await wallet.getNonce());
8080
for (let i = 0; i < MAX_ATTEMPTS; i++) {
8181
// Send a dummy transaction and wait for it to execute. We override `maxFeePerGas` as the default ethers behavior
@@ -91,12 +91,25 @@ export async function waitForNewL1Batch(wallet: zksync.Wallet): Promise<zksync.t
9191
} else {
9292
console.log('Gas price has not gone up, waiting longer');
9393
}
94-
txReceipt = await wallet.provider.waitForTransaction(txResponse.hash, 1, 3000).catch((_: TimeoutError) => null);
94+
txReceipt = await wallet.provider.waitForTransaction(txResponse.hash, 1, 3000).catch((e) => {
95+
if (ethers.isError(e, 'TIMEOUT')) {
96+
console.log(`Transaction timed out, potentially gas price went up (attempt ${i + 1}/${MAX_ATTEMPTS})`);
97+
return null;
98+
} else if (
99+
ethers.isError(e, 'UNKNOWN_ERROR') &&
100+
e.message.match(/Not enough gas for transaction validation/)
101+
) {
102+
console.log(
103+
`Transaction did not have enough gas, likely gas price went up (attempt ${i + 1}/${MAX_ATTEMPTS})`
104+
);
105+
return null;
106+
} else {
107+
return Promise.reject(e);
108+
}
109+
});
95110
if (txReceipt) {
96111
// Transaction got executed, so we can safely assume it will be sealed in the next batch
97112
break;
98-
} else {
99-
console.log(`Transaction timed out (attempt ${i + 1}/${MAX_ATTEMPTS})`);
100113
}
101114
}
102115
if (!txReceipt) {

0 commit comments

Comments
 (0)