Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Standardize CLI logging and errors #190

Open
wants to merge 23 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
1ef5795
Clean up start command
seanchen1991 Feb 20, 2024
ead66a2
Clean up keys add command
seanchen1991 Feb 20, 2024
c6d5247
Clean up create channel command
seanchen1991 Feb 20, 2024
56fe7bf
Clean up packet clear command
seanchen1991 Feb 20, 2024
311a79b
Clean up client create command
seanchen1991 Feb 20, 2024
6ada78e
Clean up client update command
seanchen1991 Feb 20, 2024
96faff4
Clean up create connection command
seanchen1991 Feb 20, 2024
db60058
Clean up query client state command
seanchen1991 Feb 20, 2024
2ffa85d
Clean up query client status command
seanchen1991 Feb 20, 2024
42f53d2
Clean up query client consensus command
seanchen1991 Feb 20, 2024
b73fe0c
Clean up query connection end command
seanchen1991 Feb 20, 2024
c2de3c0
Clean up query clients command
seanchen1991 Feb 20, 2024
d26bce5
Clean up query connections command
seanchen1991 Feb 20, 2024
3d46d4d
Clean up query channel client command
seanchen1991 Feb 21, 2024
f034aa4
Clean up query channel end command
seanchen1991 Feb 21, 2024
9059811
Clean up query channel ends command
seanchen1991 Feb 21, 2024
eb25401
Clean up query channels command
seanchen1991 Feb 21, 2024
020678c
Clean up query pending packets command
seanchen1991 Feb 21, 2024
b05800d
Clean up query packet commitments command
seanchen1991 Feb 21, 2024
c2df2f0
Clean up query packet pending acks command
seanchen1991 Feb 21, 2024
d242c80
Fix channel_id:port_id formatting
seanchen1991 Feb 21, 2024
6d1f945
Tweak an error message
seanchen1991 Feb 21, 2024
98ce52d
Better organize some dependencies
seanchen1991 Feb 21, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions crates/cli/cli/src/commands/channel/create.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
use oneline_eyre::eyre::Context;
use tracing::info;

use hermes_cli_framework::command::CommandRunner;
use hermes_cli_framework::output::Output;
use hermes_cosmos_client_components::types::channel::CosmosInitChannelOptions;
use hermes_cosmos_relayer::contexts::builder::CosmosBuilder;
use hermes_relayer_components::build::traits::components::relay_builder::CanBuildRelay;
use hermes_relayer_components::build::traits::target::relay::RelayAToBTarget;
use hermes_relayer_components::relay::impls::channel::bootstrap::CanBootstrapChannel;

use ibc_relayer::channel::version::Version;
use ibc_relayer_types::core::ics04_channel::channel::Ordering;
use ibc_relayer_types::core::ics24_host::identifier::{ChainId, ClientId, ConnectionId, PortId};
use oneline_eyre::eyre::eyre;
use tracing::info;

use crate::Result;

Expand Down Expand Up @@ -104,7 +106,7 @@ impl CommandRunner<CosmosBuilder> for ChannelCreate {
&self.client_id_b,
)
.await
.map_err(|e| eyre!("Failed to build relay: {e}"))?;
.wrap_err("relayer failed to start")?;

let options = CosmosInitChannelOptions {
ordering: self.ordering,
Expand All @@ -114,7 +116,7 @@ impl CommandRunner<CosmosBuilder> for ChannelCreate {

info!(
?options,
"Creating channel between {}:{} and {}:{} on connection {}...",
"Creating channel between `{}`:`{}` and `{}`:`{}` on connection `{}`...",
self.chain_id_a,
self.client_id_a,
self.chain_id_b,
Expand All @@ -125,11 +127,11 @@ impl CommandRunner<CosmosBuilder> for ChannelCreate {
let (channel_id_a, channel_id_b) = relay
.bootstrap_channel(&self.port_id_a, &self.port_id_b, &options)
.await
.map_err(|e| eyre!("Failed to create channel: channel handshake failed: {e}"))?;
.wrap_err("failed to create channel; channel handshake failed")?;

info!(
%channel_id_a, %channel_id_b,
"Channel successfully created between {} and {}",
"Channel successfully created between `{}` and `{}`",
self.chain_id_a, self.chain_id_b,
);

Expand Down
9 changes: 6 additions & 3 deletions crates/cli/cli/src/commands/clear/packets.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
use futures::stream::{self, StreamExt};
use oneline_eyre::eyre::Context;

use hermes_cli_framework::command::CommandRunner;
use hermes_cli_framework::output::Output;
use hermes_cosmos_relayer::contexts::builder::CosmosBuilder;

use futures::stream::{self, StreamExt};
use hermes_relayer_components::build::traits::components::birelay_builder::CanBuildBiRelay;
use hermes_relayer_components::relay::traits::packet_clearer::CanClearPackets;

use ibc_relayer_types::core::ics24_host::identifier::ChainId;
use ibc_relayer_types::core::ics24_host::identifier::ChannelId;
use ibc_relayer_types::core::ics24_host::identifier::ClientId;
Expand Down Expand Up @@ -97,7 +99,8 @@ impl CommandRunner<CosmosBuilder> for PacketsClear {
&self.client_id,
&self.counterparty_client_id, // nothing to pass here
)
.await?;
.await
.wrap_err("relayer failed to start")?;

stream::iter(vec![
relayer.relay_a_to_b.clear_packets(
Expand Down
28 changes: 18 additions & 10 deletions crates/cli/cli/src/commands/client/create.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
use oneline_eyre::eyre::{eyre, Context};
use tracing::info;

use hermes_cli_framework::command::CommandRunner;
use hermes_cli_framework::output::Output;
use hermes_cosmos_relayer::contexts::builder::CosmosBuilder;
use hermes_cosmos_relayer::contexts::relay::CosmosRelay;
use hermes_relayer_components::relay::traits::client_creator::CanCreateClient;
use hermes_relayer_components::relay::traits::target::DestinationTarget;

use ibc_relayer::chain::client::ClientSettings;
use ibc_relayer::foreign_client::CreateOptions;
use ibc_relayer_types::core::ics02_client::trust_threshold::TrustThreshold;
use ibc_relayer_types::core::ics24_host::identifier::ChainId;
use oneline_eyre::eyre::eyre;
use tracing::info;

use crate::Result;

Expand Down Expand Up @@ -72,7 +74,7 @@ impl CommandRunner<CosmosBuilder> for ClientCreate {
.find_chain(&self.host_chain_id)
.ok_or_else(|| {
eyre!(
"No chain configuration found for chain `{}`",
"no chain configuration found for chain `{}`",
self.host_chain_id
)
})?;
Expand All @@ -82,13 +84,19 @@ impl CommandRunner<CosmosBuilder> for ClientCreate {
.find_chain(&self.reference_chain_id)
.ok_or_else(|| {
eyre!(
"No chain configuration found for chain `{}`",
"no chain configuration found for chain `{}`",
self.reference_chain_id
)
})?;

let host_chain = builder.build_chain(&self.host_chain_id).await?;
let reference_chain = builder.build_chain(&self.reference_chain_id).await?;
let host_chain = builder
.build_chain(&self.host_chain_id)
.await
.wrap_err_with(|| format!("failed to build chain `{}`", self.host_chain_id))?;
let reference_chain = builder
.build_chain(&self.reference_chain_id)
.await
.wrap_err_with(|| format!("failed to build chain `{}`", self.reference_chain_id))?;

let options = CreateOptions {
max_clock_drift: self.clock_drift.map(|d| d.into()),
Expand All @@ -109,7 +117,7 @@ impl CommandRunner<CosmosBuilder> for ClientCreate {
let client_id_on_host =
CosmosRelay::create_client(DestinationTarget, &host_chain, &reference_chain, &settings)
.await
.map_err(|e| eyre!("Failed to create client on host chain: {e}"))?;
.wrap_err("failed to create client on host chain")?;

info!(
%client_id_on_host,
Expand All @@ -129,12 +137,12 @@ fn parse_trust_threshold(input: &str) -> Result<TrustThreshold> {
let numerator = num_part
.trim()
.parse()
.map_err(|_| eyre!("invalid trust threshold numerator"))?;
.wrap_err("invalid trust threshold numerator")?;

let denominator = denom_part
.trim()
.parse()
.map_err(|_| eyre!("invalid trust threshold denominator"))?;
.wrap_err("invalid trust threshold denominator")?;

TrustThreshold::new(numerator, denominator).map_err(|e| eyre!("invalid trust threshold: {e}"))
TrustThreshold::new(numerator, denominator).wrap_err("invalid trust threshold")
}
28 changes: 19 additions & 9 deletions crates/cli/cli/src/commands/client/update.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
use oneline_eyre::eyre::Context;
use tracing::info;

use hermes_cli_framework::command::CommandRunner;
use hermes_cli_framework::output::Output;
use hermes_cosmos_relayer::contexts::builder::CosmosBuilder;
Expand All @@ -8,10 +11,9 @@ use hermes_relayer_components::chain::traits::queries::chain_status::CanQueryCha
use hermes_relayer_components::chain::traits::queries::client_state::CanQueryClientStateWithLatestHeight;
use hermes_relayer_components::relay::traits::target::SourceTarget;
use hermes_relayer_components::relay::traits::update_client_message_builder::CanSendUpdateClientMessage;

use ibc_relayer_types::core::ics02_client::height::Height;
use ibc_relayer_types::core::ics24_host::identifier::{ChainId, ClientId};
use oneline_eyre::eyre::Context;
use tracing::info;

use crate::Result;

Expand Down Expand Up @@ -45,15 +47,22 @@ pub struct ClientUpdate {

impl CommandRunner<CosmosBuilder> for ClientUpdate {
async fn run(&self, builder: &CosmosBuilder) -> Result<Output> {
let host_chain = builder.build_chain(&self.host_chain_id).await?;
let host_chain = builder
.build_chain(&self.host_chain_id)
.await
.wrap_err_with(|| format!("failed to build chain `{}`", self.host_chain_id))?;

let client_state =
<CosmosChain as CanQueryClientStateWithLatestHeight<CosmosChain>>::
query_client_state_with_latest_height(&host_chain, &self.client_id)
.await?;
.await
.wrap_err_with(|| format!("failed to query client `{}`", self.client_id))?;

let reference_chain_id = client_state.chain_id;
let reference_chain = builder.build_chain(&reference_chain_id).await?;
let reference_chain = builder
.build_chain(&reference_chain_id)
.await
.wrap_err_with(|| format!("failed to build chain `{}`", reference_chain_id))?;

let relayer = builder
.build_relay(
Expand All @@ -63,28 +72,29 @@ impl CommandRunner<CosmosBuilder> for ClientUpdate {
&self.client_id,
&self.client_id, // nothing to pass here
)
.await?;
.await
.wrap_err("relayer failed to start")?;

let target_height = match self.target_height {
Some(height) => {
let height = Height::new(reference_chain_id.version(), height)
.wrap_err("Invalid value for --target-height")?;
.wrap_err_with(|| format!("invalid value for --target-height `{height}`"))?;

info!("Updating client using specified target height: {height}");
height
}
None => {
let height = reference_chain.query_chain_height().await?;

info!("Updating client using specified target height: {height}");
info!("Updating client using specified target height: `{height}`");
height
}
};

relayer
.send_update_client_messages(SourceTarget, &target_height)
.await
.wrap_err("Failed to send update client message")?;
.wrap_err("failed to send update client message")?;

Ok(Output::success_msg("Client successfully updated!"))
}
Expand Down
12 changes: 7 additions & 5 deletions crates/cli/cli/src/commands/connection/create.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
use std::time::Duration;

use oneline_eyre::eyre::Context;
use tracing::info;

use hermes_cli_framework::command::CommandRunner;
use hermes_cli_framework::output::Output;
use hermes_cosmos_client_components::types::connection::CosmosInitConnectionOptions;
use hermes_cosmos_relayer::contexts::builder::CosmosBuilder;
use hermes_relayer_components::build::traits::components::relay_builder::CanBuildRelay;
use hermes_relayer_components::build::traits::target::relay::RelayAToBTarget;
use hermes_relayer_components::relay::impls::connection::bootstrap::CanBootstrapConnection;

use ibc_relayer_types::core::ics03_connection::version::Version;
use ibc_relayer_types::core::ics24_host::identifier::{ChainId, ClientId};
use oneline_eyre::eyre::eyre;
use tracing::info;

use crate::Result;

Expand Down Expand Up @@ -64,7 +66,7 @@ impl CommandRunner<CosmosBuilder> for ConnectionCreate {
&self.client_id_b,
)
.await
.map_err(|e| eyre!("Failed to build relay: {e}"))?;
.wrap_err("relayer failed to start")?;

let options = CosmosInitConnectionOptions {
delay_period: Duration::from_secs(0),
Expand All @@ -73,7 +75,7 @@ impl CommandRunner<CosmosBuilder> for ConnectionCreate {

info!(
?options,
"Creating connection between {}:{} and {}:{}...",
"Creating connection between `{}`:`{}` and `{}`:`{}`...",
self.chain_id_a,
self.client_id_a,
self.chain_id_b,
Expand All @@ -83,7 +85,7 @@ impl CommandRunner<CosmosBuilder> for ConnectionCreate {
let (connection_id_a, connection_id_b) = relay
.bootstrap_connection(&options)
.await
.map_err(|e| eyre!("Failed to create connection: connection handshake failed: {e}"))?;
.wrap_err("failed to create connection; connection handshake failed")?;

info!(
%connection_id_a, %connection_id_b,
Expand Down
16 changes: 8 additions & 8 deletions crates/cli/cli/src/commands/keys/add.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,18 @@ use std::path::{Path, PathBuf};
use std::str::FromStr;

use hdpath::StandardHDPath;
use oneline_eyre::eyre::{self, eyre, Context};
use tracing::warn;

use hermes_cli_framework::command::CommandRunner;
use hermes_cli_framework::output::Output;
use hermes_cosmos_relayer::contexts::builder::CosmosBuilder;

use ibc_relayer::config::ChainConfig;
use ibc_relayer::keyring::{
AnySigningKeyPair, KeyRing, Secp256k1KeyPair, SigningKeyPair, SigningKeyPairSized, Store,
};
use ibc_relayer_types::core::ics24_host::identifier::ChainId;
use oneline_eyre::eyre;
use oneline_eyre::eyre::eyre;
use oneline_eyre::eyre::WrapErr;
use tracing::warn;

/// The data structure that represents the arguments when invoking the `keys add` CLI command.
///
Expand Down Expand Up @@ -178,9 +178,9 @@ pub fn restore_key(
fn check_key_exists<S: SigningKeyPairSized>(keyring: &KeyRing<S>, key_name: &str, overwrite: bool) {
if keyring.get_key(key_name).is_ok() {
if overwrite {
warn!("key '{key_name}' will be overwritten");
warn!("key `{key_name}` will be overwritten");
} else {
Output::error(format!("key with name '{key_name}' already exists")).exit();
Output::error(format!("key with name `{key_name}` already exists")).exit();
}
}
}
Expand Down Expand Up @@ -209,7 +209,7 @@ impl CommandRunner<CosmosBuilder> for crate::commands::keys::add::KeysAddCmd {
);
match key {
Ok(key) => Output::success_msg(format!(
"added key '{}' ({}) on chain `{}`",
"added key `{}` ({}) on chain `{}`",
opts.name,
key.account(),
opts.config.id,
Expand All @@ -233,7 +233,7 @@ impl CommandRunner<CosmosBuilder> for crate::commands::keys::add::KeysAddCmd {

match key {
Ok(key) => Output::success_msg(format!(
"restored key '{}' ({}) on chain `{}`",
"restored key `{}` ({}) on chain `{}`",
opts.name,
key.account(),
opts.config.id
Expand Down
4 changes: 2 additions & 2 deletions crates/cli/cli/src/commands/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ pub mod channel;
pub mod clear;
pub mod client;
pub mod connection;
pub mod query;

pub mod keys;
pub mod query;
pub mod start;

#[derive(Debug, clap::Parser)]
pub enum HermesCommand {
/// Start the Hermes relayer
Expand Down
Loading