Skip to content

Commit

Permalink
fix(apps/price_pusher): address issues with alpha version (#1864)
Browse files Browse the repository at this point in the history
This PR addresses the issues in the new alpha version that were reported by the users. It now handles more errors and also supports networks with legacy transactions.

* fix(apps/price_pusher): handle more errors in evm
* fix: use getGasPrice instead of estimateFee for compatibility
* chore: bump version
  • Loading branch information
ali-bahjati authored Sep 4, 2024
1 parent c252a1c commit c253beb
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
2 changes: 1 addition & 1 deletion apps/price_pusher/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@pythnetwork/price-pusher",
"version": "8.0.0-alpha",
"version": "8.0.0",
"description": "Pyth Price Pusher",
"homepage": "https://pyth.network",
"main": "lib/index.js",
Expand Down
22 changes: 16 additions & 6 deletions apps/price_pusher/src/evm/evm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import {
FeeCapTooLowError,
InternalRpcError,
InsufficientFundsError,
ContractFunctionExecutionError,
} from "viem";

import { PythContract } from "./pyth-contract";
Expand Down Expand Up @@ -179,14 +180,13 @@ export class EvmPricePusher implements IPricePusher {
throw e;
}

const fees = await this.client.estimateFeesPerGas();

this.logger.debug({ fees }, "Estimated fees");

// Gas price in networks with transaction type eip1559 represents the
// addition of baseFee and priorityFee required to land the transaction. We
// are using this to remain compatible with the networks that doesn't
// support this transaction type.
let gasPrice =
Number(await this.customGasStation?.getCustomGasPrice()) ||
Number(fees.gasPrice) ||
Number(fees.maxFeePerGas);
Number(await this.client.getGasPrice());

// Try to re-use the same nonce and increase the gas if the last tx is not landed yet.
if (this.pusherAddress === undefined) {
Expand Down Expand Up @@ -306,6 +306,16 @@ export class EvmPricePusher implements IPricePusher {
return;
}

// Sometimes the contract function execution fails in simulation and this error is thrown.
if (err.walk((e) => e instanceof ContractFunctionExecutionError)) {
this.logger.warn(
{ err },
"The contract function execution failed in simulation. This is an expected behaviour in high frequency or multi-instance setup. " +
"Please review this error and file an issue if it is a bug. Skipping this push."
);
return;
}

// We normally crash on unknown failures but we believe that this type of error is safe to skip. The other reason is that
// wometimes we see a TransactionExecutionError because of the nonce without any details and it is not catchable.
if (err.walk((e) => e instanceof TransactionExecutionError)) {
Expand Down

0 comments on commit c253beb

Please sign in to comment.