diff --git a/rust/chains/hyperlane-ethereum/src/mailbox.rs b/rust/chains/hyperlane-ethereum/src/mailbox.rs index 42fad5d843..60bf35c9d8 100644 --- a/rust/chains/hyperlane-ethereum/src/mailbox.rs +++ b/rust/chains/hyperlane-ethereum/src/mailbox.rs @@ -264,7 +264,7 @@ where metadata.to_vec().into(), RawHyperlaneMessage::from(message).to_vec().into(), ); - fill_tx_gas_params(tx, tx_gas_limit, self.provider.clone(), message.destination).await + fill_tx_gas_params(tx, tx_gas_limit, self.provider.clone()).await } } diff --git a/rust/chains/hyperlane-ethereum/src/trait_builder.rs b/rust/chains/hyperlane-ethereum/src/trait_builder.rs index f2242cb162..03a33c2fdc 100644 --- a/rust/chains/hyperlane-ethereum/src/trait_builder.rs +++ b/rust/chains/hyperlane-ethereum/src/trait_builder.rs @@ -3,6 +3,9 @@ use std::sync::Arc; use std::time::Duration; use async_trait::async_trait; +use ethers::middleware::gas_oracle::{ + GasCategory, GasOracle, GasOracleMiddleware, Polygon, ProviderOracle, +}; use ethers::prelude::{ Http, JsonRpcClient, Middleware, NonceManagerMiddleware, Provider, Quorum, QuorumProvider, SignerMiddleware, WeightedProvider, Ws, WsClientError, @@ -17,7 +20,9 @@ use ethers_prometheus::json_rpc_client::{ use ethers_prometheus::middleware::{ MiddlewareMetrics, PrometheusMiddleware, PrometheusMiddlewareConf, }; -use hyperlane_core::{ChainCommunicationError, ChainResult, ContractLocator}; +use hyperlane_core::{ + ChainCommunicationError, ChainResult, ContractLocator, HyperlaneDomain, KnownHyperlaneDomain, +}; use crate::{signers::Signers, ConnectionConf, FallbackProvider, RetryingProvider}; @@ -89,7 +94,7 @@ pub trait BuildableWithProvider { builder = builder.add_provider(weighted_provider); } let quorum_provider = builder.build(); - self.wrap_with_metrics(quorum_provider, locator, signer, middleware_metrics) + self.build(quorum_provider, locator, signer, middleware_metrics) .await? } ConnectionConf::HttpFallback { urls } => { @@ -109,7 +114,7 @@ pub trait BuildableWithProvider { builder = builder.add_provider(metrics_provider); } let fallback_provider = builder.build(); - self.wrap_with_metrics(fallback_provider, locator, signer, middleware_metrics) + self.build(fallback_provider, locator, signer, middleware_metrics) .await? } ConnectionConf::Http { url } => { @@ -125,15 +130,14 @@ pub trait BuildableWithProvider { &middleware_metrics, ); let retrying_http_provider = RetryingProvider::new(metrics_provider, None, None); - self.wrap_with_metrics(retrying_http_provider, locator, signer, middleware_metrics) + self.build(retrying_http_provider, locator, signer, middleware_metrics) .await? } ConnectionConf::Ws { url } => { let ws = Ws::connect(url) .await .map_err(EthereumProviderConnectionError::from)?; - self.wrap_with_metrics(ws, locator, signer, middleware_metrics) - .await? + self.build(ws, locator, signer, middleware_metrics).await? } }) } @@ -174,9 +178,9 @@ pub trait BuildableWithProvider { ) } - /// Wrap the provider creation with metrics if provided; this is the second - /// step - async fn wrap_with_metrics
( + /// Create the provider, applying any middlewares (e.g. gas oracle, signer, metrics) as needed, + /// and then create the associated trait. + async fn build
(
&self,
client: P,
locator: &ContractLocator,
@@ -186,19 +190,20 @@ pub trait BuildableWithProvider {
where
P: JsonRpcClient + 'static,
{
- let provider = Provider::new(client);
+ let provider = wrap_with_gas_oracle(Provider::new(client), locator.domain)?;
+
Ok(if let Some(metrics) = metrics {
let provider = Arc::new(PrometheusMiddleware::new(provider, metrics.0, metrics.1));
tokio::spawn(provider.start_updating_on_interval(METRICS_SCRAPE_INTERVAL));
- self.wrap_with_signer(provider, locator, signer).await?
+ self.build_with_signer(provider, locator, signer).await?
} else {
- self.wrap_with_signer(provider, locator, signer).await?
+ self.build_with_signer(provider, locator, signer).await?
})
}
/// Wrap the provider creation with a signing provider if signers were
- /// provided; this is the third step.
- async fn wrap_with_signer