From adf37fd19cdb6fa4f4e8df2c021d530638268f6b Mon Sep 17 00:00:00 2001 From: Ali Behjati Date: Thu, 2 Mar 2023 14:24:28 +0100 Subject: [PATCH] [price-pusher] Bug fix on revert and crash --- package-lock.json | 2 +- price_pusher/package.json | 2 +- price_pusher/src/controller.ts | 5 +++++ price_pusher/src/evm/evm.ts | 24 +++++++++++++++--------- 4 files changed, 22 insertions(+), 11 deletions(-) diff --git a/package-lock.json b/package-lock.json index f41b33e294..94f0e32154 100644 --- a/package-lock.json +++ b/package-lock.json @@ -47854,7 +47854,7 @@ }, "price_pusher": { "name": "@pythnetwork/pyth-evm-price-pusher", - "version": "2.0.1", + "version": "2.0.2", "license": "Apache-2.0", "dependencies": { "@injectivelabs/sdk-ts": "^1.0.457", diff --git a/price_pusher/package.json b/price_pusher/package.json index d3664bdd61..584687bc8e 100644 --- a/price_pusher/package.json +++ b/price_pusher/package.json @@ -1,6 +1,6 @@ { "name": "@pythnetwork/pyth-evm-price-pusher", - "version": "2.0.1", + "version": "2.0.2", "description": "Pyth EVM Price Pusher", "homepage": "https://pyth.network", "main": "lib/index.js", diff --git a/price_pusher/src/controller.ts b/price_pusher/src/controller.ts index 915127785d..27cb7d3be2 100644 --- a/price_pusher/src/controller.ts +++ b/price_pusher/src/controller.ts @@ -22,6 +22,11 @@ export class Controller { await this.sourcePriceListener.start(); await this.targetPriceListener.start(); + // wait for the listeners to get updated. There could be a restart + // before this run and we need to respect the cooldown duration as + // their might be a message sent before. + await sleep(this.cooldownDuration * 1000); + for (;;) { const pricesToPush: PriceConfig[] = []; const pubTimesToPush: UnixTimestamp[] = []; diff --git a/price_pusher/src/evm/evm.ts b/price_pusher/src/evm/evm.ts index 8e2ca4e72c..fa42714d76 100644 --- a/price_pusher/src/evm/evm.ts +++ b/price_pusher/src/evm/evm.ts @@ -150,10 +150,20 @@ export class EvmPricePusher implements ChainPricePusher { "Pushing ", priceIdsWith0x.map((priceIdWith0x) => `${priceIdWith0x}`) ); - const updateFee = await this.pythContract.methods - .getUpdateFee(priceFeedUpdateData) - .call(); - console.log(`Update fee: ${updateFee}`); + + let updateFee; + + try { + updateFee = await this.pythContract.methods + .getUpdateFee(priceFeedUpdateData) + .call(); + console.log(`Update fee: ${updateFee}`); + } catch (e: any) { + console.error( + "An unidentified error has occured when getting the update fee:" + ); + throw e; + } const gasPrice = await this.customGasStation?.getCustomGasPrice(); @@ -168,11 +178,7 @@ export class EvmPricePusher implements ChainPricePusher { console.log(`Successful. Tx hash: ${hash}`); }) .on("error", (err: Error, receipt?: TransactionReceipt) => { - if ( - err.message.includes( - "VM Exception while processing transaction: revert" - ) - ) { + if (err.message.includes("revert")) { // Since we are using custom error structs on solidity the rejection // doesn't return any information why the call has reverted. Assuming that // the update data is valid there is no possible rejection cause other than