Skip to content

Commit

Permalink
fix(GasService): error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
re1ro committed Mar 29, 2024
1 parent 34efbc0 commit 6e75de2
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 25 deletions.
36 changes: 32 additions & 4 deletions axelar-chains-config/info/testnet.json
Original file line number Diff line number Diff line change
Expand Up @@ -104,11 +104,12 @@
"gasOptions": {
"gasLimit": 8000000
},
"finality": "finalized",
"approxFinalityWaitTime": 40,
"onchainGasEstimate": {
"chainName": "ethereum",
"blobBaseFee": 50187563959
}
},
"finality": "finalized",
"approxFinalityWaitTime": 40
},
"avalanche": {
"name": "Avalanche",
Expand Down Expand Up @@ -1010,6 +1011,9 @@
"gasOptions": {
"gasLimit": 300000000
},
"onchainGasEstimate": {
"chainName": "filecoin"
},
"confirmations": 3,
"eip1559": true,
"finality": "120",
Expand Down Expand Up @@ -1125,6 +1129,9 @@
"gasOptions": {
"gasPrice": 3000000000
},
"onchainGasEstimate": {
"l1ChainName": "ethereum"
},
"confirmations": 4,
"finality": "400",
"approxFinalityWaitTime": 30
Expand Down Expand Up @@ -1238,6 +1245,9 @@
"gasLimit": 7000000,
"gasPriceAdjustment": 0.25
},
"onchainGasEstimate": {
"l1ChainName": "ethereum"
},
"finality": "finalized",
"approxFinalityWaitTime": 60
},
Expand Down Expand Up @@ -1438,7 +1448,11 @@
"api": "https://api-sepolia.arbiscan.io/api"
},
"finality": "finalized",
"approxFinalityWaitTime": 25
"approxFinalityWaitTime": 25,
"onchainGasEstimate": {
"chainName": "arbitrum",
"l1ChainName": "ethereum"
}
},
"centrifuge": {
"name": "Centrifuge",
Expand Down Expand Up @@ -1541,6 +1555,10 @@
"gasOptions": {
"gasLimit": 8000000
},
"onchainGasEstimate": {
"l1ChainName": "ethereum",
"gasEstimationType": 1
},
"contracts": {
"InterchainGovernance": {
"minimumTimeDelay": 300,
Expand Down Expand Up @@ -1874,6 +1892,11 @@
"gasOptions": {
"gasLimit": 8000000
},
"onchainGasEstimate": {
"chainName": "blast",
"l1ChainName": "ethereum",
"gasEstimationType": 1
},
"confirmations": 2,
"explorer": {
"name": "Blastscan",
Expand Down Expand Up @@ -1983,6 +2006,11 @@
"gasOptions": {
"gasLimit": 50000000000
},
"onchainGasEstimate": {
"chainName": "mantle",
"l1ChainName": "ethereum",
"gasEstimationType": 1
},
"explorer": {
"name": "Mantle Explorer",
"url": "https://explorer.sepolia.mantle.xyz",
Expand Down
56 changes: 37 additions & 19 deletions evm/gas-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,26 @@ const { getWallet } = require('./sign-utils');

let failedChainUpdates = [];

function addFailedChainUpdate(chain, destinationChain) {
failedChainUpdates.push({ chain, destinationChain });
}

function printFailedChainUpdates() {
if (failedChainUpdates.length > 0) {
printError('Failed to update gas info for following chain combinations');

failedChainUpdates.forEach(({ chain, destinationChain }) => {
printError(`${chain} -> ${destinationChain}`);
});

failedChainUpdates = [];

throw new Error('Failed to update gas info for the chain combinations above');
}

failedChainUpdates = [];
}

async function getGasUpdates(config, env, chain, destinationChains) {
const api = config.axelar.axelarscanApi;

Expand Down Expand Up @@ -62,7 +82,7 @@ async function getGasUpdates(config, env, chain, destinationChains) {
} catch (e) {
printError(`Error getting gas info for ${chain.axelarId} -> ${axelarId}`);
printError(e);
failedChainUpdates.push({ chain: chain.axelarId, destinationChain: axelarId });
addFailedChainUpdate(chain.axelarId, axelarId);
return null;
}

Expand Down Expand Up @@ -134,18 +154,6 @@ async function getGasUpdates(config, env, chain, destinationChains) {
};
}

function printFailedChainUpdates() {
if (failedChainUpdates.length > 0) {
printError('Failed to update gas info for following chain combinations');

failedChainUpdates.forEach(({ chain, destinationChain }) => {
printError(`${chain} -> ${destinationChain}`);
});
}

failedChainUpdates = [];
}

async function processCommand(config, chain, options) {
const { env, contractName, address, action, privateKey, chains, destinationChain, destinationAddress, isExpress, yes } = options;
const executionGasLimit = parseInt(options.executionGasLimit);
Expand Down Expand Up @@ -235,16 +243,25 @@ async function processCommand(config, chain, options) {
return;
}

const tx = await gasService.updateGasInfo(chainsToUpdate, gasInfoUpdates, gasOptions);
try {
const tx = await gasService.updateGasInfo(chainsToUpdate, gasInfoUpdates, gasOptions);

printInfo('TX', tx.hash);

printInfo('TX', tx.hash);
const receipt = await tx.wait(chain.confirmations);

const receipt = await tx.wait(chain.confirmations);
const eventEmitted = wasEventEmitted(receipt, gasService, 'GasInfoUpdated');

const eventEmitted = wasEventEmitted(receipt, gasService, 'GasInfoUpdated');
if (!eventEmitted) {
printWarn('Event not emitted in receipt.');
}
}
catch (error) {
for (let i = 0; i < chainsToUpdate.length; i++) {
addFailedChainUpdate(chain.name, chainsToUpdate[i]);
}

if (!eventEmitted) {
printWarn('Event not emitted in receipt.');
printError(error);
}

break;
Expand Down Expand Up @@ -293,4 +310,5 @@ if (require.main === module) {
}

exports.getGasUpdates = getGasUpdates;
exports.addFailedChainUpdate = addFailedChainUpdate;
exports.printFailedChainUpdates = printFailedChainUpdates;
9 changes: 7 additions & 2 deletions evm/operators.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const {
getContractJSON,
} = require('./utils');
const { addBaseOptions } = require('./cli-utils');
const { getGasUpdates, printFailedChainUpdates } = require('./gas-service');
const { getGasUpdates, printFailedChainUpdates, addFailedChainUpdate } = require('./gas-service');

async function processCommand(config, chain, options) {
const {
Expand Down Expand Up @@ -264,7 +264,12 @@ async function processCommand(config, chain, options) {
const tx = await operatorsContract.executeContract(target, updateGasInfoCalldata, 0, gasOptions);
printInfo('TX', tx.hash);
await tx.wait(chain.confirmations);
} catch (error) {
}
catch (error) {
for (let i = 0; i < chainsToUpdate.length; i++) {
addFailedChainUpdate(chain.name, chainsToUpdate[i]);
}

printError(error);
}

Expand Down

0 comments on commit 6e75de2

Please sign in to comment.