Skip to content

Commit

Permalink
ci(gas-info): handling timeout for Scroll (#224)
Browse files Browse the repository at this point in the history
* ci(gas-info): handling timeout for Scroll

* style(JS): prettier

* docs(timeout): comments
  • Loading branch information
re1ro authored May 2, 2024
1 parent 48acddd commit 2117c43
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 6 deletions.
3 changes: 2 additions & 1 deletion axelar-chains-config/info/testnet.json
Original file line number Diff line number Diff line change
Expand Up @@ -1125,7 +1125,8 @@
},
"confirmations": 2,
"gasOptions": {
"gasLimit": 7000000
"gasLimit": 7000000,
"gasPriceAdjustment": 1.5
},
"onchainGasEstimate": {
"l1ChainName": "ethereum",
Expand Down
6 changes: 5 additions & 1 deletion evm/gas-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,11 @@ async function processCommand(config, chain, options) {

printInfo('TX', tx.hash);

const receipt = await tx.wait(chain.confirmations);
const receipt = await timeout(
tx.wait(chain.confirmations),
chain.timeout || 60000,
new Error(`Timeout updating gas info for ${chain.name}`),
);

const eventEmitted = wasEventEmitted(receipt, gasService, 'GasInfoUpdated');

Expand Down
7 changes: 6 additions & 1 deletion evm/operators.js
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,12 @@ async function processCommand(config, chain, options) {
new Error(`Timeout updating gas info for ${chain.name}`),
);
printInfo('TX', tx.hash);
await tx.wait(chain.confirmations);

await timeout(
tx.wait(chain.confirmations),
chain.timeout || 60000,
new Error(`Timeout updating gas info for ${chain.name}`),
);
} catch (error) {
for (let i = 0; i < chainsToUpdate.length; i++) {
addFailedChainUpdate(chain.name, chainsToUpdate[i]);
Expand Down
11 changes: 8 additions & 3 deletions evm/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -1179,9 +1179,14 @@ function toBigNumberString(number) {

function timeout(prom, time, exception) {
let timer;
return Promise.race([prom, new Promise((resolve, reject) => (timer = setTimeout(reject, time, exception)))]).finally(() =>
clearTimeout(timer),
);

// Racing the promise with a timer
// If the timer resolves first, the promise is rejected with the exception
const race = Promise.race([prom, new Promise((resolve, reject) => (timer = setTimeout(reject, time, exception)))]);

race.finally(() => clearTimeout(timer));

return race;
}

module.exports = {
Expand Down

0 comments on commit 2117c43

Please sign in to comment.