Jelajahi Sumber

fix(apps/price_pusher): address issues with alpha version (#1864)

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
Ali Behjati 1 tahun lalu
induk
melakukan
c253beb602
2 mengubah file dengan 17 tambahan dan 7 penghapusan
  1. 1 1
      apps/price_pusher/package.json
  2. 16 6
      apps/price_pusher/src/evm/evm.ts

+ 1 - 1
apps/price_pusher/package.json

@@ -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",

+ 16 - 6
apps/price_pusher/src/evm/evm.ts

@@ -27,6 +27,7 @@ import {
   FeeCapTooLowError,
   InternalRpcError,
   InsufficientFundsError,
+  ContractFunctionExecutionError,
 } from "viem";
 
 import { PythContract } from "./pyth-contract";
@@ -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) {
@@ -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)) {