Skip to content

Commit

Permalink
fix: clippy
Browse files Browse the repository at this point in the history
  • Loading branch information
daniel-savu committed Nov 29, 2023
1 parent a696f69 commit 2b949f4
Show file tree
Hide file tree
Showing 28 changed files with 75 additions and 74 deletions.
11 changes: 4 additions & 7 deletions rust/agents/relayer/src/relayer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
Expand Down Expand Up @@ -101,7 +98,7 @@ impl BaseAgent for Relayer {
settings: Self::Settings,
core_metrics: Arc<CoreMetrics>,
agent_metrics: Metrics,
) -> Result<(Self, Vec<MetricsFetcher>)>
) -> Result<(Self, Vec<InstrumentedFallibleTask<()>>)>
where
Self: Sized,
{
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -280,7 +277,7 @@ impl BaseAgent for Relayer {
#[allow(clippy::async_yields_async)]
async fn run(
self,
metrics_fetchers: Vec<MetricsFetcher>,
metrics_fetchers: Vec<InstrumentedFallibleTask<()>>,
) -> Instrumented<JoinHandle<Result<()>>> {
// The tasks vec is initialized with the metrics fetcher tasks,
// and is then extended with the rest of the tasks.
Expand Down
8 changes: 4 additions & 4 deletions rust/agents/scraper/src/agent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -40,8 +40,8 @@ impl BaseAgent for Scraper {
async fn from_settings(
settings: Self::Settings,
metrics: Arc<CoreMetrics>,
agent_metrics: AgentMetrics,
) -> eyre::Result<(Self, Vec<MetricsFetcher>)>
_agent_metrics: AgentMetrics,
) -> eyre::Result<(Self, Vec<InstrumentedFallibleTask<()>>)>
where
Self: Sized,
{
Expand Down Expand Up @@ -94,7 +94,7 @@ impl BaseAgent for Scraper {
#[allow(clippy::async_yields_async)]
async fn run(
self,
metrics_fetchers: Vec<MetricsFetcher>,
metrics_fetchers: Vec<InstrumentedFallibleTask<()>>,
) -> Instrumented<JoinHandle<eyre::Result<()>>> {
// The tasks vec is initialized with the metrics fetcher tasks,
// and is then extended with the rest of the tasks.
Expand Down
8 changes: 4 additions & 4 deletions rust/agents/validator/src/validator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
Expand Down Expand Up @@ -55,8 +55,8 @@ impl BaseAgent for Validator {
async fn from_settings(
settings: Self::Settings,
metrics: Arc<CoreMetrics>,
agent_metrics: AgentMetrics,
) -> Result<(Self, Vec<MetricsFetcher>)>
_agent_metrics: AgentMetrics,
) -> Result<(Self, Vec<InstrumentedFallibleTask<()>>)>
where
Self: Sized,
{
Expand Down Expand Up @@ -114,7 +114,7 @@ impl BaseAgent for Validator {
#[allow(clippy::async_yields_async)]
async fn run(
mut self,
metrics_fetchers: Vec<MetricsFetcher>,
metrics_fetchers: Vec<InstrumentedFallibleTask<()>>,
) -> Instrumented<JoinHandle<Result<()>>> {
// The tasks vec is initialized with the metrics fetcher tasks,
// and is then extended with the rest of the tasks.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -14,6 +15,7 @@ pub struct CosmosMetricsFetcher {
}

impl CosmosMetricsFetcher {
/// Instiante a new CosmosMetricsFetcher
pub fn new(
conf: ConnectionConf,
locator: ContractLocator,
Expand Down
2 changes: 1 addition & 1 deletion rust/chains/hyperlane-cosmos/src/aggregation_ism.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
Expand Down
1 change: 0 additions & 1 deletion rust/chains/hyperlane-cosmos/src/interchain_gas.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use hyperlane_core::{
};

use crate::{
grpc::{WasmGrpcProvider, WasmProvider},
grpc::WasmProvider,
payloads::{
general::EmptyStruct,
ism_routes::{QueryIsmGeneralRequest, QueryIsmModuleTypeRequest},
Expand Down
10 changes: 5 additions & 5 deletions rust/chains/hyperlane-cosmos/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@
// TODO: Remove once we start filling things in
#![allow(unused_variables)]

mod agent_metrics;
mod aggregation_ism;
mod error;
mod interchain_gas;
mod interchain_security_module;
mod libs;
mod mailbox;
mod merkle_tree_hook;
mod metrics_fetcher;
mod multisig_ism;
mod payloads;
mod providers;
Expand All @@ -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::*,
};
5 changes: 1 addition & 4 deletions rust/chains/hyperlane-cosmos/src/mailbox.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion rust/chains/hyperlane-cosmos/src/merkle_tree_hook.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 2 additions & 0 deletions rust/chains/hyperlane-cosmos/src/providers/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion rust/chains/hyperlane-cosmos/src/providers/rpc.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
2 changes: 1 addition & 1 deletion rust/chains/hyperlane-cosmos/src/routing_ism.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use hyperlane_core::{

use crate::{
address::CosmosAddress,
grpc::{WasmGrpcProvider, WasmProvider},
grpc::WasmProvider,
payloads::ism_routes::{
IsmRouteRequest, IsmRouteRequestInner, IsmRouteRespnose, QueryRoutingIsmGeneralRequest,
},
Expand Down
1 change: 1 addition & 0 deletions rust/chains/hyperlane-ethereum/src/agent_metrics.rs
Original file line number Diff line number Diff line change
@@ -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]
Expand Down
4 changes: 3 additions & 1 deletion rust/chains/hyperlane-ethereum/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<abi::Abi>) -> HashMap<Vec<u8>, &'static str> {
abi.functions()
.map(|f| (f.selector().to_vec(), f.name.as_str()))
Expand Down
2 changes: 1 addition & 1 deletion rust/chains/hyperlane-ethereum/src/provider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ where
Ok(!code.is_empty())
}

async fn get_balance(&self, address: String) -> ChainResult<U256> {
async fn get_balance(&self, _address: String) -> ChainResult<U256> {
todo!()
}
}
Expand Down
2 changes: 0 additions & 2 deletions rust/ethers-prometheus/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
#![forbid(unsafe_code)]
#![warn(missing_docs)]

use ethers::prelude::U256;

mod contracts;

pub mod json_rpc_client;
Expand Down
2 changes: 1 addition & 1 deletion rust/ethers-prometheus/src/middleware/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
7 changes: 3 additions & 4 deletions rust/hyperlane-base/src/agent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
Expand Down Expand Up @@ -46,15 +45,15 @@ pub trait BaseAgent: Send + Sync + Debug {
settings: Self::Settings,
metrics: Arc<CoreMetrics>,
agent_metrics: AgentMetrics,
) -> Result<(Self, Vec<MetricsFetcher>)>
) -> Result<(Self, Vec<InstrumentedFallibleTask<()>>)>
where
Self: Sized;

/// Start running this agent.
#[allow(clippy::async_yields_async)]
async fn run(
self,
metrics_fetchers: Vec<MetricsFetcher>,
metrics_fetchers: Vec<InstrumentedFallibleTask<()>>,
) -> Instrumented<JoinHandle<Result<()>>>;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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<tokio::task::JoinHandle<Result<()>>>;
/// Instrumented fallible task alias
pub type InstrumentedFallibleTask<T> = Instrumented<tokio::task::JoinHandle<Result<T>>>;

/// Agent-specific metrics
#[derive(Clone, Builder)]
pub struct Metrics {
/// Current balance of eth and other tokens in the `tokens` map for the
Expand Down Expand Up @@ -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,
Expand All @@ -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! {
Expand All @@ -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);
Expand Down
8 changes: 3 additions & 5 deletions rust/hyperlane-base/src/metrics/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::*;
Loading

0 comments on commit 2b949f4

Please sign in to comment.