From 69b6b0d19d1fb808225e994e3da8174b6d4ab5b0 Mon Sep 17 00:00:00 2001 From: dancoombs Date: Mon, 18 Sep 2023 19:29:19 -0400 Subject: [PATCH] fix(sim): add fallback for polygon gasstaion failures --- crates/sim/src/gas/gas.rs | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/crates/sim/src/gas/gas.rs b/crates/sim/src/gas/gas.rs index 1789e3615..18a65f9b0 100644 --- a/crates/sim/src/gas/gas.rs +++ b/crates/sim/src/gas/gas.rs @@ -1,6 +1,5 @@ use std::sync::Arc; -use anyhow::Context; use ethers::{ prelude::gas_oracle::{GasCategory, GasOracle}, types::{Address, Chain, U256}, @@ -274,11 +273,17 @@ impl FeeEstimator

{ if POLYGON_CHAIN_IDS.contains(&self.chain_id) { let gas_oracle = Polygon::new(Chain::try_from(self.chain_id)?)?.category(GasCategory::Fast); - let fees = gas_oracle - .estimate_eip1559_fees() - .await - .context("failed to query polygon gasstation")?; - Ok(fees.1) + match gas_oracle.estimate_eip1559_fees().await { + Ok(fees) => Ok(fees.1), + // Polygon gas station is very unreliable, fallback to max priority fee if it fails + // Fast can be 10% faster than what is returned by `eth_maxPriorityFeePerGas` + // so we increase the max priority fee by 10% to ensure that multiple + // calls to this endpoint give reasonably similar results. + Err(_) => Ok(math::increase_by_percent( + self.provider.get_max_priority_fee().await?, + 10, + )), + } } else if self.use_bundle_priority_fee { self.provider.get_max_priority_fee().await } else {