From 2b949f413e583e62073f4183575b8ed28dd57d97 Mon Sep 17 00:00:00 2001 From: Daniel Savu <23065004+daniel-savu@users.noreply.github.com> Date: Wed, 29 Nov 2023 19:31:15 +0000 Subject: [PATCH] fix: clippy --- rust/agents/relayer/src/relayer.rs | 11 +++---- rust/agents/scraper/src/agent.rs | 8 ++--- rust/agents/validator/src/validator.rs | 8 ++--- .../{metrics_fetcher.rs => agent_metrics.rs} | 2 ++ .../hyperlane-cosmos/src/aggregation_ism.rs | 2 +- .../hyperlane-cosmos/src/interchain_gas.rs | 1 - .../src/interchain_security_module.rs | 2 +- rust/chains/hyperlane-cosmos/src/lib.rs | 10 +++---- rust/chains/hyperlane-cosmos/src/mailbox.rs | 5 +--- .../hyperlane-cosmos/src/merkle_tree_hook.rs | 2 +- .../hyperlane-cosmos/src/providers/mod.rs | 2 ++ .../hyperlane-cosmos/src/providers/rpc.rs | 2 +- .../hyperlane-cosmos/src/routing_ism.rs | 2 +- .../hyperlane-ethereum/src/agent_metrics.rs | 1 + rust/chains/hyperlane-ethereum/src/lib.rs | 4 ++- .../chains/hyperlane-ethereum/src/provider.rs | 2 +- rust/ethers-prometheus/src/lib.rs | 2 -- rust/ethers-prometheus/src/middleware/mod.rs | 2 +- rust/hyperlane-base/src/agent.rs | 7 ++--- .../metrics/{agent.rs => agent_metrics.rs} | 17 ++++++----- rust/hyperlane-base/src/metrics/mod.rs | 8 ++--- rust/hyperlane-base/src/settings/chains.rs | 29 +++++++++---------- rust/hyperlane-core/src/lib.rs | 1 + rust/hyperlane-core/src/metrics/agent.rs | 8 +++-- rust/hyperlane-core/src/metrics/mod.rs | 1 + rust/utils/run-locally/Cargo.toml | 2 +- rust/utils/run-locally/src/cosmos/mod.rs | 6 ++-- rust/utils/run-locally/src/main.rs | 2 +- 28 files changed, 75 insertions(+), 74 deletions(-) rename rust/chains/hyperlane-cosmos/src/{metrics_fetcher.rs => agent_metrics.rs} (90%) rename rust/hyperlane-base/src/metrics/{agent.rs => agent_metrics.rs} (89%) diff --git a/rust/agents/relayer/src/relayer.rs b/rust/agents/relayer/src/relayer.rs index a779afe32b..af7df960ae 100644 --- a/rust/agents/relayer/src/relayer.rs +++ b/rust/agents/relayer/src/relayer.rs @@ -9,10 +9,7 @@ use derive_more::AsRef; use eyre::Result; use hyperlane_base::{ db::{HyperlaneRocksDB, DB}, - metrics::{ - self, - agent::{AgentMetrics, Metrics, MetricsFetcher}, - }, + metrics::{AgentMetrics, InstrumentedFallibleTask, Metrics}, run_all, BaseAgent, ContractSyncMetrics, CoreMetrics, HyperlaneAgentCore, SequencedDataContractSync, WatermarkContractSync, }; @@ -101,7 +98,7 @@ impl BaseAgent for Relayer { settings: Self::Settings, core_metrics: Arc, agent_metrics: Metrics, - ) -> Result<(Self, Vec)> + ) -> Result<(Self, Vec>)> where Self: Sized, { @@ -201,7 +198,7 @@ impl BaseAgent for Relayer { for destination in &settings.destination_chains { let destination_chain_setup = core.settings.chain_setup(destination).unwrap().clone(); let agent_metrics_conf = destination_chain_setup - .agent_metrics_conf("relayer".to_owned()) + .agent_metrics_conf(Self::AGENT_NAME.to_string()) .await?; let agent_metrics_fetcher = destination_chain_setup .build_agent_metrics_fetcher() @@ -280,7 +277,7 @@ impl BaseAgent for Relayer { #[allow(clippy::async_yields_async)] async fn run( self, - metrics_fetchers: Vec, + metrics_fetchers: Vec>, ) -> Instrumented>> { // The tasks vec is initialized with the metrics fetcher tasks, // and is then extended with the rest of the tasks. diff --git a/rust/agents/scraper/src/agent.rs b/rust/agents/scraper/src/agent.rs index 0264177e4c..24549b3765 100644 --- a/rust/agents/scraper/src/agent.rs +++ b/rust/agents/scraper/src/agent.rs @@ -3,7 +3,7 @@ use std::{collections::HashMap, sync::Arc}; use async_trait::async_trait; use derive_more::AsRef; use hyperlane_base::{ - metrics::agent::{Metrics as AgentMetrics, MetricsFetcher}, + metrics::{InstrumentedFallibleTask, Metrics as AgentMetrics}, run_all, settings::IndexSettings, BaseAgent, ContractSyncMetrics, CoreMetrics, HyperlaneAgentCore, @@ -40,8 +40,8 @@ impl BaseAgent for Scraper { async fn from_settings( settings: Self::Settings, metrics: Arc, - agent_metrics: AgentMetrics, - ) -> eyre::Result<(Self, Vec)> + _agent_metrics: AgentMetrics, + ) -> eyre::Result<(Self, Vec>)> where Self: Sized, { @@ -94,7 +94,7 @@ impl BaseAgent for Scraper { #[allow(clippy::async_yields_async)] async fn run( self, - metrics_fetchers: Vec, + metrics_fetchers: Vec>, ) -> Instrumented>> { // The tasks vec is initialized with the metrics fetcher tasks, // and is then extended with the rest of the tasks. diff --git a/rust/agents/validator/src/validator.rs b/rust/agents/validator/src/validator.rs index 46ffb1051c..2fd90b4edb 100644 --- a/rust/agents/validator/src/validator.rs +++ b/rust/agents/validator/src/validator.rs @@ -10,7 +10,7 @@ use tracing::{error, info, info_span, instrument::Instrumented, warn, Instrument use hyperlane_base::{ db::{HyperlaneRocksDB, DB}, - metrics::agent::{Metrics as AgentMetrics, MetricsFetcher}, + metrics::{InstrumentedFallibleTask, Metrics as AgentMetrics}, run_all, BaseAgent, CheckpointSyncer, ContractSyncMetrics, CoreMetrics, HyperlaneAgentCore, SequencedDataContractSync, }; @@ -55,8 +55,8 @@ impl BaseAgent for Validator { async fn from_settings( settings: Self::Settings, metrics: Arc, - agent_metrics: AgentMetrics, - ) -> Result<(Self, Vec)> + _agent_metrics: AgentMetrics, + ) -> Result<(Self, Vec>)> where Self: Sized, { @@ -114,7 +114,7 @@ impl BaseAgent for Validator { #[allow(clippy::async_yields_async)] async fn run( mut self, - metrics_fetchers: Vec, + metrics_fetchers: Vec>, ) -> Instrumented>> { // The tasks vec is initialized with the metrics fetcher tasks, // and is then extended with the rest of the tasks. diff --git a/rust/chains/hyperlane-cosmos/src/metrics_fetcher.rs b/rust/chains/hyperlane-cosmos/src/agent_metrics.rs similarity index 90% rename from rust/chains/hyperlane-cosmos/src/metrics_fetcher.rs rename to rust/chains/hyperlane-cosmos/src/agent_metrics.rs index 3cb20419c0..30c15f98f3 100644 --- a/rust/chains/hyperlane-cosmos/src/metrics_fetcher.rs +++ b/rust/chains/hyperlane-cosmos/src/agent_metrics.rs @@ -6,6 +6,7 @@ use hyperlane_core::{ use crate::{address::CosmosAddress, ConnectionConf, CosmosProvider}; +/// Concrete struct for implementing the AgenMetricsFetcher and HyperlaneChain traits for Cosmos #[derive(Debug)] pub struct CosmosMetricsFetcher { address: CosmosAddress, @@ -14,6 +15,7 @@ pub struct CosmosMetricsFetcher { } impl CosmosMetricsFetcher { + /// Instiante a new CosmosMetricsFetcher pub fn new( conf: ConnectionConf, locator: ContractLocator, diff --git a/rust/chains/hyperlane-cosmos/src/aggregation_ism.rs b/rust/chains/hyperlane-cosmos/src/aggregation_ism.rs index a2439f92a3..49e5d60397 100644 --- a/rust/chains/hyperlane-cosmos/src/aggregation_ism.rs +++ b/rust/chains/hyperlane-cosmos/src/aggregation_ism.rs @@ -2,7 +2,7 @@ use std::str::FromStr; use crate::{ address::CosmosAddress, - grpc::{WasmGrpcProvider, WasmProvider}, + grpc::WasmProvider, payloads::aggregate_ism::{ModulesAndThresholdRequest, ModulesAndThresholdResponse}, ConnectionConf, CosmosProvider, Signer, }; diff --git a/rust/chains/hyperlane-cosmos/src/interchain_gas.rs b/rust/chains/hyperlane-cosmos/src/interchain_gas.rs index 83044913b4..491274c846 100644 --- a/rust/chains/hyperlane-cosmos/src/interchain_gas.rs +++ b/rust/chains/hyperlane-cosmos/src/interchain_gas.rs @@ -10,7 +10,6 @@ use once_cell::sync::Lazy; use std::ops::RangeInclusive; use crate::{ - grpc::WasmGrpcProvider, rpc::{CosmosWasmIndexer, ParsedEvent, WasmIndexer}, signers::Signer, utils::{CONTRACT_ADDRESS_ATTRIBUTE_KEY, CONTRACT_ADDRESS_ATTRIBUTE_KEY_BASE64}, diff --git a/rust/chains/hyperlane-cosmos/src/interchain_security_module.rs b/rust/chains/hyperlane-cosmos/src/interchain_security_module.rs index f4c6932cf5..9e726e5628 100644 --- a/rust/chains/hyperlane-cosmos/src/interchain_security_module.rs +++ b/rust/chains/hyperlane-cosmos/src/interchain_security_module.rs @@ -5,7 +5,7 @@ use hyperlane_core::{ }; use crate::{ - grpc::{WasmGrpcProvider, WasmProvider}, + grpc::WasmProvider, payloads::{ general::EmptyStruct, ism_routes::{QueryIsmGeneralRequest, QueryIsmModuleTypeRequest}, diff --git a/rust/chains/hyperlane-cosmos/src/lib.rs b/rust/chains/hyperlane-cosmos/src/lib.rs index 92b3a56730..c61f1de261 100644 --- a/rust/chains/hyperlane-cosmos/src/lib.rs +++ b/rust/chains/hyperlane-cosmos/src/lib.rs @@ -5,6 +5,7 @@ // TODO: Remove once we start filling things in #![allow(unused_variables)] +mod agent_metrics; mod aggregation_ism; mod error; mod interchain_gas; @@ -12,7 +13,6 @@ mod interchain_security_module; mod libs; mod mailbox; mod merkle_tree_hook; -mod metrics_fetcher; mod multisig_ism; mod payloads; mod providers; @@ -24,8 +24,8 @@ mod utils; mod validator_announce; pub use self::{ - aggregation_ism::*, error::*, interchain_gas::*, interchain_security_module::*, libs::*, - mailbox::*, merkle_tree_hook::*, metrics_fetcher::*, multisig_ism::*, providers::*, - routing_ism::*, signers::*, trait_builder::*, trait_builder::*, validator_announce::*, - validator_announce::*, + agent_metrics::*, aggregation_ism::*, error::*, interchain_gas::*, + interchain_security_module::*, libs::*, mailbox::*, merkle_tree_hook::*, multisig_ism::*, + providers::*, routing_ism::*, signers::*, trait_builder::*, trait_builder::*, + validator_announce::*, validator_announce::*, }; diff --git a/rust/chains/hyperlane-cosmos/src/mailbox.rs b/rust/chains/hyperlane-cosmos/src/mailbox.rs index 51e8529bc3..2249546b77 100644 --- a/rust/chains/hyperlane-cosmos/src/mailbox.rs +++ b/rust/chains/hyperlane-cosmos/src/mailbox.rs @@ -14,10 +14,7 @@ use crate::payloads::{general, mailbox}; use crate::rpc::{CosmosWasmIndexer, ParsedEvent, WasmIndexer}; use crate::CosmosProvider; use crate::{address::CosmosAddress, types::tx_response_to_outcome}; -use crate::{ - grpc::{WasmGrpcProvider, WasmProvider}, - HyperlaneCosmosError, -}; +use crate::{grpc::WasmProvider, HyperlaneCosmosError}; use crate::{signers::Signer, utils::get_block_height_for_lag, ConnectionConf}; use async_trait::async_trait; use cosmrs::proto::cosmos::base::abci::v1beta1::TxResponse; diff --git a/rust/chains/hyperlane-cosmos/src/merkle_tree_hook.rs b/rust/chains/hyperlane-cosmos/src/merkle_tree_hook.rs index f18f5a2a83..40a0a2ab55 100644 --- a/rust/chains/hyperlane-cosmos/src/merkle_tree_hook.rs +++ b/rust/chains/hyperlane-cosmos/src/merkle_tree_hook.rs @@ -12,7 +12,7 @@ use once_cell::sync::Lazy; use tracing::instrument; use crate::{ - grpc::{WasmGrpcProvider, WasmProvider}, + grpc::WasmProvider, payloads::{ general::{self}, merkle_tree_hook, diff --git a/rust/chains/hyperlane-cosmos/src/providers/mod.rs b/rust/chains/hyperlane-cosmos/src/providers/mod.rs index 527f06d2bd..4bb960b536 100644 --- a/rust/chains/hyperlane-cosmos/src/providers/mod.rs +++ b/rust/chains/hyperlane-cosmos/src/providers/mod.rs @@ -50,10 +50,12 @@ impl CosmosProvider { }) } + /// Get a grpc client pub fn grpc(&self) -> WasmGrpcProvider { self.grpc_client.clone() } + /// Get an rpc client pub fn rpc(&self) -> &HttpClient { &self.rpc_client } diff --git a/rust/chains/hyperlane-cosmos/src/providers/rpc.rs b/rust/chains/hyperlane-cosmos/src/providers/rpc.rs index e8fe8ba48a..1f0d2a24a1 100644 --- a/rust/chains/hyperlane-cosmos/src/providers/rpc.rs +++ b/rust/chains/hyperlane-cosmos/src/providers/rpc.rs @@ -1,7 +1,7 @@ use std::ops::RangeInclusive; use async_trait::async_trait; -use cosmrs::rpc::client::{Client, CompatMode, HttpClient}; +use cosmrs::rpc::client::Client; use cosmrs::rpc::endpoint::{tx, tx_search::Response as TxSearchResponse}; use cosmrs::rpc::query::Query; use cosmrs::rpc::Order; diff --git a/rust/chains/hyperlane-cosmos/src/routing_ism.rs b/rust/chains/hyperlane-cosmos/src/routing_ism.rs index 97360546f4..63b759f1b9 100644 --- a/rust/chains/hyperlane-cosmos/src/routing_ism.rs +++ b/rust/chains/hyperlane-cosmos/src/routing_ism.rs @@ -9,7 +9,7 @@ use hyperlane_core::{ use crate::{ address::CosmosAddress, - grpc::{WasmGrpcProvider, WasmProvider}, + grpc::WasmProvider, payloads::ism_routes::{ IsmRouteRequest, IsmRouteRequestInner, IsmRouteRespnose, QueryRoutingIsmGeneralRequest, }, diff --git a/rust/chains/hyperlane-ethereum/src/agent_metrics.rs b/rust/chains/hyperlane-ethereum/src/agent_metrics.rs index a78528ef05..f1bd5065ba 100644 --- a/rust/chains/hyperlane-ethereum/src/agent_metrics.rs +++ b/rust/chains/hyperlane-ethereum/src/agent_metrics.rs @@ -1,6 +1,7 @@ use async_trait::async_trait; use hyperlane_core::{metrics::agent::AgenMetricsFetcher, ChainResult, U256}; +/// Concrete struct for implementing the AgenMetricsFetcher trait for Ethereum pub struct EthereumMetricsFetcher {} #[async_trait] diff --git a/rust/chains/hyperlane-ethereum/src/lib.rs b/rust/chains/hyperlane-ethereum/src/lib.rs index 27d75b3d57..6f3d9b268b 100644 --- a/rust/chains/hyperlane-ethereum/src/lib.rs +++ b/rust/chains/hyperlane-ethereum/src/lib.rs @@ -74,9 +74,11 @@ mod signers; #[cfg(not(doctest))] mod singleton_signer; -pub mod agent_metrics; +mod agent_metrics; mod config; +pub use self::agent_metrics::*; + fn extract_fn_map(abi: &'static Lazy) -> HashMap, &'static str> { abi.functions() .map(|f| (f.selector().to_vec(), f.name.as_str())) diff --git a/rust/chains/hyperlane-ethereum/src/provider.rs b/rust/chains/hyperlane-ethereum/src/provider.rs index 871fc2a464..e23b19a779 100644 --- a/rust/chains/hyperlane-ethereum/src/provider.rs +++ b/rust/chains/hyperlane-ethereum/src/provider.rs @@ -106,7 +106,7 @@ where Ok(!code.is_empty()) } - async fn get_balance(&self, address: String) -> ChainResult { + async fn get_balance(&self, _address: String) -> ChainResult { todo!() } } diff --git a/rust/ethers-prometheus/src/lib.rs b/rust/ethers-prometheus/src/lib.rs index 6268aee6dd..8cf57329f0 100644 --- a/rust/ethers-prometheus/src/lib.rs +++ b/rust/ethers-prometheus/src/lib.rs @@ -3,8 +3,6 @@ #![forbid(unsafe_code)] #![warn(missing_docs)] -use ethers::prelude::U256; - mod contracts; pub mod json_rpc_client; diff --git a/rust/ethers-prometheus/src/middleware/mod.rs b/rust/ethers-prometheus/src/middleware/mod.rs index b536a1b13f..1526f84e72 100644 --- a/rust/ethers-prometheus/src/middleware/mod.rs +++ b/rust/ethers-prometheus/src/middleware/mod.rs @@ -20,9 +20,9 @@ use maplit::hashmap; use prometheus::{CounterVec, GaugeVec, IntCounterVec, IntGaugeVec}; use static_assertions::assert_impl_all; use tokio::sync::RwLock; -use tokio::time::MissedTickBehavior; pub use error::PrometheusMiddlewareError; +use tokio::time::MissedTickBehavior; pub use crate::ChainInfo; diff --git a/rust/hyperlane-base/src/agent.rs b/rust/hyperlane-base/src/agent.rs index 01e3ee6f4f..e638108dcf 100644 --- a/rust/hyperlane-base/src/agent.rs +++ b/rust/hyperlane-base/src/agent.rs @@ -9,8 +9,7 @@ use tracing::{debug_span, instrument::Instrumented, Instrument}; use crate::{ metrics::{ - agent::{create_agent_metrics, Metrics as AgentMetrics, MetricsFetcher}, - CoreMetrics, + create_agent_metrics, CoreMetrics, InstrumentedFallibleTask, Metrics as AgentMetrics, }, settings::Settings, }; @@ -46,7 +45,7 @@ pub trait BaseAgent: Send + Sync + Debug { settings: Self::Settings, metrics: Arc, agent_metrics: AgentMetrics, - ) -> Result<(Self, Vec)> + ) -> Result<(Self, Vec>)> where Self: Sized; @@ -54,7 +53,7 @@ pub trait BaseAgent: Send + Sync + Debug { #[allow(clippy::async_yields_async)] async fn run( self, - metrics_fetchers: Vec, + metrics_fetchers: Vec>, ) -> Instrumented>>; } diff --git a/rust/hyperlane-base/src/metrics/agent.rs b/rust/hyperlane-base/src/metrics/agent_metrics.rs similarity index 89% rename from rust/hyperlane-base/src/metrics/agent.rs rename to rust/hyperlane-base/src/metrics/agent_metrics.rs index 37e21ab3cc..267197e9b4 100644 --- a/rust/hyperlane-base/src/metrics/agent.rs +++ b/rust/hyperlane-base/src/metrics/agent_metrics.rs @@ -1,14 +1,10 @@ -use std::future::Future; -use std::{collections::HashMap, time::Duration}; +use std::time::Duration; -use async_trait::async_trait; use derive_builder::Builder; use derive_new::new; use eyre::Result; use hyperlane_core::metrics::agent::u256_as_scaled_f64; -use hyperlane_core::{ - metrics::agent::AgenMetricsFetcher, ChainResult, HyperlaneDomain, H256, U256, -}; +use hyperlane_core::{metrics::agent::AgenMetricsFetcher, HyperlaneDomain}; use maplit::hashmap; use prometheus::GaugeVec; use tokio::time::MissedTickBehavior; @@ -30,8 +26,10 @@ pub const WALLET_BALANCE_LABELS: &[&str] = &[ pub const WALLET_BALANCE_HELP: &str = "Current native token balance for the wallet addresses in the `wallets` set"; -pub type MetricsFetcher = Instrumented>>; +/// Instrumented fallible task alias +pub type InstrumentedFallibleTask = Instrumented>>; +/// Agent-specific metrics #[derive(Clone, Builder)] pub struct Metrics { /// Current balance of eth and other tokens in the `tokens` map for the @@ -69,9 +67,11 @@ pub struct AgentMetricsConf { /// Information about the chain this metric is for pub domain: HyperlaneDomain, + /// Name of the agent the metrics are about pub name: String, } +/// Utility struct to update agent metrics #[derive(new)] pub struct AgentMetrics { metrics: Metrics, @@ -95,7 +95,7 @@ impl AgentMetrics { // Okay, so the native type is not a token, but whatever, close enough. // Note: This is ETH for many chains, but not all so that is why we use `N` and `Native` // TODO: can we get away with scaling as 18 in all cases here? I am guessing not. - let balance = u256_as_scaled_f64(U256::from(balance), 18); + let balance = u256_as_scaled_f64(balance, 18); trace!("Wallet {wallet_name} ({wallet_addr}) on chain {chain} balance is {balance} of the native currency"); wallet_balance_metric .with(&hashmap! { @@ -111,6 +111,7 @@ impl AgentMetrics { } } + /// Periodically updates the metrics pub async fn start_updating_on_interval(self, period: Duration) { let mut interval = tokio::time::interval(period); interval.set_missed_tick_behavior(MissedTickBehavior::Skip); diff --git a/rust/hyperlane-base/src/metrics/mod.rs b/rust/hyperlane-base/src/metrics/mod.rs index 1b032015e9..b2b1c6acd9 100644 --- a/rust/hyperlane-base/src/metrics/mod.rs +++ b/rust/hyperlane-base/src/metrics/mod.rs @@ -5,12 +5,10 @@ pub use self::core::*; /// The metrics namespace prefix. All metric names will start with `{NAMESPACE}_`. pub const NAMESPACE: &str = "hyperlane"; -// This should be whatever the prometheus scrape interval is -const METRICS_SCRAPE_INTERVAL: Duration = Duration::from_secs(60); - mod core; -use std::time::Duration; -pub mod agent; +mod agent_metrics; mod json_rpc_client; mod provider; + +pub use self::agent_metrics::*; diff --git a/rust/hyperlane-base/src/settings/chains.rs b/rust/hyperlane-base/src/settings/chains.rs index a266658b49..a40abeb531 100644 --- a/rust/hyperlane-base/src/settings/chains.rs +++ b/rust/hyperlane-base/src/settings/chains.rs @@ -1,18 +1,16 @@ use ethers::prelude::Selector; -use h_cosmos::{address::CosmosAddress, CosmosMetricsFetcher, CosmosProvider}; +use h_cosmos::{address::CosmosAddress, CosmosMetricsFetcher}; use std::collections::HashMap; use eyre::{eyre, Context, Result}; -use ethers_prometheus::middleware::{ - ChainInfo, ContractInfo, PrometheusMiddlewareConf, WalletInfo, -}; +use ethers_prometheus::middleware::{ChainInfo, ContractInfo, PrometheusMiddlewareConf}; use hyperlane_core::{ - metrics::agent::AgenMetricsFetcher, AggregationIsm, CcipReadIsm, ChainResult, ContractLocator, - HyperlaneAbi, HyperlaneDomain, HyperlaneDomainProtocol, HyperlaneMessage, HyperlaneProvider, - HyperlaneSigner, IndexMode, InterchainGasPaymaster, InterchainGasPayment, - InterchainSecurityModule, Mailbox, MerkleTreeHook, MerkleTreeInsertion, MultisigIsm, - RoutingIsm, SequenceIndexer, ValidatorAnnounce, H256, + metrics::agent::AgenMetricsFetcher, AggregationIsm, CcipReadIsm, ContractLocator, HyperlaneAbi, + HyperlaneDomain, HyperlaneDomainProtocol, HyperlaneMessage, HyperlaneProvider, IndexMode, + InterchainGasPaymaster, InterchainGasPayment, InterchainSecurityModule, Mailbox, + MerkleTreeHook, MerkleTreeInsertion, MultisigIsm, RoutingIsm, SequenceIndexer, + ValidatorAnnounce, H256, }; use hyperlane_cosmos as h_cosmos; use hyperlane_ethereum::{ @@ -23,7 +21,7 @@ use hyperlane_fuel as h_fuel; use hyperlane_sealevel as h_sealevel; use crate::{ - metrics::agent::AgentMetricsConf, + metrics::AgentMetricsConf, settings::signers::{BuildableWithSignerConf, ChainSigner, SignerConf}, CoreMetrics, }; @@ -596,13 +594,13 @@ impl ChainConf { .context(ctx) } + /// Try to convert the chain setting into a trait object for fetching agent metrics pub async fn build_agent_metrics_fetcher(&self) -> Result> { let ctx = "Building Agent Metrics Fetcher"; match &self.connection { - ChainConnectionConf::Ethereum(conf) => { - Ok(Box::new(h_eth::agent_metrics::EthereumMetricsFetcher {}) - as Box) + ChainConnectionConf::Ethereum(_conf) => { + Ok(Box::new(h_eth::EthereumMetricsFetcher {}) as Box) } ChainConnectionConf::Fuel(_) => todo!(), ChainConnectionConf::Sealevel(_) => todo!(), @@ -670,6 +668,7 @@ impl ChainConf { self.signer().await } + /// Try to build an agent metrics configuration from the chain config pub async fn agent_metrics_conf(&self, agent_name: String) -> Result { let chain_signer_address = self.chain_signer().await?.map(|s| s.address_string()); Ok(AgentMetricsConf { @@ -681,7 +680,7 @@ impl ChainConf { /// Get a clone of the ethereum metrics conf with correctly configured /// contract information. - pub fn metrics_conf(&self, agent_name: &str) -> PrometheusMiddlewareConf { + pub fn metrics_conf(&self) -> PrometheusMiddlewareConf { let mut cfg = self.metrics_conf.clone(); if cfg.chain.is_none() { @@ -746,7 +745,7 @@ impl ChainConf { B: BuildableWithProvider + Sync, { let signer = self.ethereum_signer().await?; - let metrics_conf = self.metrics_conf(metrics.agent_name()); + let metrics_conf = self.metrics_conf(); let rpc_metrics = Some(metrics.json_rpc_client_metrics()); let middleware_metrics = Some((metrics.provider_metrics(), metrics_conf)); let res = builder diff --git a/rust/hyperlane-core/src/lib.rs b/rust/hyperlane-core/src/lib.rs index 3d91f35fcc..6834df3951 100644 --- a/rust/hyperlane-core/src/lib.rs +++ b/rust/hyperlane-core/src/lib.rs @@ -26,6 +26,7 @@ pub mod utils; pub mod test_utils; pub mod config; +/// Prometheus metrics traits / utilities pub mod metrics; /// Core hyperlane system data structures diff --git a/rust/hyperlane-core/src/metrics/agent.rs b/rust/hyperlane-core/src/metrics/agent.rs index 59349eec4b..6134e2b8e5 100644 --- a/rust/hyperlane-core/src/metrics/agent.rs +++ b/rust/hyperlane-core/src/metrics/agent.rs @@ -1,14 +1,18 @@ -use std::{collections::HashMap, time::Duration}; +use std::time::Duration; use async_trait::async_trait; use crate::{ChainResult, U256}; -// This should be whatever the prometheus scrape interval is +/// Interval for querying the prometheus metrics endpoint. +/// This should be whatever the prometheus scrape interval is pub const METRICS_SCRAPE_INTERVAL: Duration = Duration::from_secs(60); +/// Trait to be implemented by all chain-specific agent implementations, +/// to support gathering agent metrics. #[async_trait] pub trait AgenMetricsFetcher: Send + Sync { + /// Fetch the balance of the wallet address associated with the chain provider. async fn get_balance(&self) -> ChainResult; } diff --git a/rust/hyperlane-core/src/metrics/mod.rs b/rust/hyperlane-core/src/metrics/mod.rs index f17bc55db8..4c82be31d7 100644 --- a/rust/hyperlane-core/src/metrics/mod.rs +++ b/rust/hyperlane-core/src/metrics/mod.rs @@ -1 +1,2 @@ +/// Agent metrics utils pub mod agent; diff --git a/rust/utils/run-locally/Cargo.toml b/rust/utils/run-locally/Cargo.toml index 1f59fb2fb3..66e86a92bc 100644 --- a/rust/utils/run-locally/Cargo.toml +++ b/rust/utils/run-locally/Cargo.toml @@ -10,7 +10,7 @@ publish.workspace = true version.workspace = true [dependencies] -hyperlane-core = { path = "../../hyperlane-core" } +hyperlane-core = { path = "../../hyperlane-core", features = ["float"]} toml_edit.workspace = true k256.workspace = true ripemd.workspace = true diff --git a/rust/utils/run-locally/src/cosmos/mod.rs b/rust/utils/run-locally/src/cosmos/mod.rs index de20beb631..5ff4402527 100644 --- a/rust/utils/run-locally/src/cosmos/mod.rs +++ b/rust/utils/run-locally/src/cosmos/mod.rs @@ -564,9 +564,9 @@ fn relayer_balance_sum(metrics_port: u32) -> eyre::Result { } fn termination_invariants_met( - relayer_metrics_port: u32, - messages_expected: u32, - starting_relayer_balance: f64, + _relayer_metrics_port: u32, + _messages_expected: u32, + _starting_relayer_balance: f64, ) -> eyre::Result { Ok(true) // TODO: uncomment once CI passes consistently on Ubuntu diff --git a/rust/utils/run-locally/src/main.rs b/rust/utils/run-locally/src/main.rs index 0ee63b02d4..0910d14710 100644 --- a/rust/utils/run-locally/src/main.rs +++ b/rust/utils/run-locally/src/main.rs @@ -388,7 +388,7 @@ fn main() -> ExitCode { let loop_start = Instant::now(); // give things a chance to fully start. - sleep(Duration::from_secs(5)); + sleep(Duration::from_secs(10)); let mut failure_occurred = false; while !SHUTDOWN.load(Ordering::Relaxed) { if config.ci_mode {