diff --git a/relayer-cli/src/commands.rs b/relayer-cli/src/commands.rs index 43259bf2bf..ce8cc1623b 100644 --- a/relayer-cli/src/commands.rs +++ b/relayer-cli/src/commands.rs @@ -16,13 +16,14 @@ use crate::DEFAULT_CONFIG_PATH; use ibc_relayer::config::Config; use self::{ - config::ConfigCmd, create::CreateCmds, keys::KeysCmd, listen::ListenCmd, - misbehaviour::MisbehaviourCmd, query::QueryCmd, start::StartCmd, tx::TxCmd, update::UpdateCmds, - upgrade::UpgradeCmds, version::VersionCmd, + config::ConfigCmd, create::CreateCmds, health::HealthCheckCmd, keys::KeysCmd, + listen::ListenCmd, misbehaviour::MisbehaviourCmd, query::QueryCmd, start::StartCmd, tx::TxCmd, + update::UpdateCmds, upgrade::UpgradeCmds, version::VersionCmd, }; mod config; mod create; +mod health; mod keys; mod listen; mod misbehaviour; @@ -89,6 +90,10 @@ pub enum CliCmd { /// The `version` subcommand #[options(help = "Display version information")] Version(VersionCmd), + + /// The `health` subcommand + #[options(help = "Performs a health check of all chains in the the config")] + HealthCheck(HealthCheckCmd), } /// This trait allows you to define how application configuration is loaded. diff --git a/relayer-cli/src/commands/health.rs b/relayer-cli/src/commands/health.rs new file mode 100644 index 0000000000..14b3bb14f8 --- /dev/null +++ b/relayer-cli/src/commands/health.rs @@ -0,0 +1,38 @@ +use std::sync::Arc; + +use abscissa_core::{Command, Options, Runnable}; + +use crate::conclude::Output; +use crate::prelude::*; +use ibc_relayer::chain::{ChainEndpoint, CosmosSdkChain}; +use tokio::runtime::Runtime as TokioRuntime; + +#[derive(Clone, Command, Debug, Options)] +pub struct HealthCheckCmd {} + +impl Runnable for HealthCheckCmd { + fn run(&self) { + let config = (*app_config()).clone(); + + for ch in config.clone().chains { + let rt = Arc::new(TokioRuntime::new().unwrap()); + info!("Performing health check on chain {:?}...", ch.id); + let chain_config = match config.find_chain(&ch.id) { + None => { + return Output::error(format!( + "chain '{}' not found in configuration file", + ch.id + )) + .exit() + } + Some(chain_config) => chain_config, + }; + let chain = CosmosSdkChain::bootstrap(chain_config.clone(), rt).unwrap(); + chain.health_checkup(); + chain.validate_params(); + info!("Performed health check on chain {:?}", ch.id); + } + info!("Hermes executed a health check for all chains in the config"); + Output::success_msg("done").exit() + } +} diff --git a/relayer/src/chain/cosmos.rs b/relayer/src/chain/cosmos.rs index c5488c1df8..5f7a28b87d 100644 --- a/relayer/src/chain/cosmos.rs +++ b/relayer/src/chain/cosmos.rs @@ -127,7 +127,7 @@ impl CosmosSdkChain { /// Emits a log warning in case anything is amiss. /// Exits early if any health check fails, without doing any /// further checks. - fn health_checkup(&self) { + pub fn health_checkup(&self) { async fn do_health_checkup(chain: &CosmosSdkChain) -> Result<(), Error> { let chain_id = chain.id(); let grpc_address = chain.grpc_addr.to_string(); @@ -737,8 +737,8 @@ impl ChainEndpoint for CosmosSdkChain { account: None, }; - chain.health_checkup(); - chain.validate_params(); + //chain.health_checkup(); + //chain.validate_params(); Ok(chain) }