From 3c32eb0b2c8772d97ac9b46ee43b9bee4b4d0f38 Mon Sep 17 00:00:00 2001 From: Sean Chen Date: Wed, 28 Jun 2023 13:30:08 -0500 Subject: [PATCH 01/16] Stub out code flow --- .../relayer-cli/src/commands/config/auto.rs | 101 +++++++++++------- 1 file changed, 62 insertions(+), 39 deletions(-) diff --git a/crates/relayer-cli/src/commands/config/auto.rs b/crates/relayer-cli/src/commands/config/auto.rs index 229bba7fa1..5d44e585b3 100644 --- a/crates/relayer-cli/src/commands/config/auto.rs +++ b/crates/relayer-cli/src/commands/config/auto.rs @@ -88,47 +88,70 @@ impl Runnable for AutoCmd { // Fetch chain configs from the chain registry info!("Fetching configuration for chains: {sorted_names:?}"); - match runtime.block_on(get_configs(&sorted_names, commit)) { - Ok(mut chain_configs) => { - let configs_and_keys = chain_configs - .iter_mut() - .zip(names_and_keys.iter().map(|n| &n.1).cloned()); - - for (chain_config, key_option) in configs_and_keys { - // If a key is provided, use it - if let Some(key_name) = key_option { - info!("{}: uses key \"{}\"", &chain_config.id, &key_name); - chain_config.key_name = key_name; - } else { - // Otherwise, find the key in the keystore - let chain_id = &chain_config.id; - let key = find_key(chain_config); - if let Some(key) = key { - info!("{}: uses key '{}'", &chain_id, &key); - chain_config.key_name = key; - } else { - // If no key is found, warn the user and continue - warn!("No key found for chain: {}", chain_id); - } - } - } - - let config = Config { - chains: chain_configs, - ..Config::default() - }; - - match store(&config, &self.path) { - Ok(_) => Output::success_msg(format!( - "Config file written successfully at '{}'", - self.path.display() - )) - .exit(), - Err(e) => Output::error(e).exit(), - } - } + let (chain_configs, diagnostic) = runtime.block_on(get_configs(&sorted_names, commit)); + + if let Some(diagnostic) = diagnostic { + warn!( + "Unable to populate all config fields. The following fields were not populated: {}", + diagnostic + ); + } + + let config = Config { + chains: chain_configs, + ..Config::default() + }; + + match store(&config, &self.path) { + Ok(_) => Output::success_msg(format!( + "Config file written successfully at '{}'", + self.path.display(), + )) + .exit(), Err(e) => Output::error(e).exit(), } + + //match runtime.block_on(get_configs(&sorted_names, commit)) { + // Ok(mut chain_configs) => { + // let configs_and_keys = chain_configs + // .iter_mut() + // .zip(names_and_keys.iter().map(|n| &n.1).cloned()); + + // for (chain_config, key_option) in configs_and_keys { + // // If a key is provided, use it + // if let Some(key_name) = key_option { + // info!("{}: uses key \"{}\"", &chain_config.id, &key_name); + // chain_config.key_name = key_name; + // } else { + // // Otherwise, find the key in the keystore + // let chain_id = &chain_config.id; + // let key = find_key(chain_config); + // if let Some(key) = key { + // info!("{}: uses key '{}'", &chain_id, &key); + // chain_config.key_name = key; + // } else { + // // If no key is found, warn the user and continue + // warn!("No key found for chain: {}", chain_id); + // } + // } + // } + + // let config = Config { + // chains: chain_configs, + // ..Config::default() + // }; + + // match store(&config, &self.path) { + // Ok(_) => Output::success_msg(format!( + // "Config file written successfully at '{}'", + // self.path.display() + // )) + // .exit(), + // Err(e) => Output::error(e).exit(), + // } + // } + // Err(e) => Output::error(e).exit(), + //} } } From b4cf6aedc3a1facc3c4dcb9c72985948229b4903 Mon Sep 17 00:00:00 2001 From: Sean Chen Date: Thu, 29 Jun 2023 14:39:16 -0500 Subject: [PATCH 02/16] Stub out code flow --- crates/relayer-cli/src/commands/config/auto.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/relayer-cli/src/commands/config/auto.rs b/crates/relayer-cli/src/commands/config/auto.rs index 5d44e585b3..31cf3df613 100644 --- a/crates/relayer-cli/src/commands/config/auto.rs +++ b/crates/relayer-cli/src/commands/config/auto.rs @@ -111,7 +111,7 @@ impl Runnable for AutoCmd { Err(e) => Output::error(e).exit(), } - //match runtime.block_on(get_configs(&sorted_names, commit)) { + // match runtime.block_on(get_configs(&sorted_names, commit)) { // Ok(mut chain_configs) => { // let configs_and_keys = chain_configs // .iter_mut() @@ -151,7 +151,7 @@ impl Runnable for AutoCmd { // } // } // Err(e) => Output::error(e).exit(), - //} + // } } } From 16098cb2c55653135a4dc5ca5ad7d835405032e2 Mon Sep 17 00:00:00 2001 From: Sean Chen Date: Wed, 5 Jul 2023 09:24:06 -0500 Subject: [PATCH 03/16] Change return type of `hermes_cofig` fn --- crates/relayer-cli/src/chain_registry.rs | 18 +++++++++++++++--- crates/relayer-cli/src/commands/config/auto.rs | 4 ++-- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/crates/relayer-cli/src/chain_registry.rs b/crates/relayer-cli/src/chain_registry.rs index 886953ed6c..2c1cca9a2b 100644 --- a/crates/relayer-cli/src/chain_registry.rs +++ b/crates/relayer-cli/src/chain_registry.rs @@ -27,6 +27,18 @@ use tendermint_rpc::Url; const MAX_HEALTHY_QUERY_RETRIES: u8 = 5; +/// A diagnostic used when an issue arises while generating a config file +/// using the `hermes config auto` command. It communicates the error that +/// occurred when generating the config file, as well as all of the config +/// fields that could not be populated due to the error. +#[derive(Debug)] +pub struct Diagnostic { + /// The `RegistryError` that occurred while generating the config file. + pub error: RegistryError, + /// The config fields that were unable to be populated. + pub missing_fields: Vec, +} + /// Generate packet filters from Vec and load them in a Map(chain_name -> filter). fn construct_packet_filters(ibc_paths: Vec) -> HashMap { let mut packet_filters: HashMap<_, Vec<_>> = HashMap::new(); @@ -63,7 +75,7 @@ async fn hermes_config( chain_data: ChainData, assets: AssetList, packet_filter: Option, -) -> Result +) -> (ChainConfig, Option) where GrpcQuerier: QueryContext + Send, @@ -120,7 +132,7 @@ where 0.1 }; - Ok(ChainConfig { + (ChainConfig { id: chain_data.chain_id, r#type: default::chain_type(), rpc_addr: rpc_data.rpc_address, @@ -160,7 +172,7 @@ where address_type: AddressType::default(), sequential_batch_tx: false, extension_options: Vec::new(), - }) + }, None) } /// Concurrent `query_healthy` might fail, this is a helper function which will retry a failed query a fixed diff --git a/crates/relayer-cli/src/commands/config/auto.rs b/crates/relayer-cli/src/commands/config/auto.rs index 31cf3df613..47475ff4ec 100644 --- a/crates/relayer-cli/src/commands/config/auto.rs +++ b/crates/relayer-cli/src/commands/config/auto.rs @@ -88,9 +88,9 @@ impl Runnable for AutoCmd { // Fetch chain configs from the chain registry info!("Fetching configuration for chains: {sorted_names:?}"); - let (chain_configs, diagnostic) = runtime.block_on(get_configs(&sorted_names, commit)); + let (chain_configs, maybe_diagnostic) = runtime.block_on(get_configs(&sorted_names, commit)); - if let Some(diagnostic) = diagnostic { + if let Some(diagnostic) = maybe_diagnostic { warn!( "Unable to populate all config fields. The following fields were not populated: {}", diagnostic From 7d5d83bdb437d437ac9c6e7b86e19e19af1d30c6 Mon Sep 17 00:00:00 2001 From: Sean Chen Date: Thu, 6 Jul 2023 08:20:47 -0500 Subject: [PATCH 04/16] Define ConfigAutoError type --- crates/chain-registry/src/error.rs | 19 +++ crates/relayer-cli/src/chain_registry.rs | 22 +--- .../relayer-cli/src/commands/config/auto.rs | 123 +++++++++--------- crates/relayer/src/config.rs | 2 +- 4 files changed, 85 insertions(+), 81 deletions(-) diff --git a/crates/chain-registry/src/error.rs b/crates/chain-registry/src/error.rs index 662ce5cbab..1798a5d8f6 100644 --- a/crates/chain-registry/src/error.rs +++ b/crates/chain-registry/src/error.rs @@ -8,6 +8,25 @@ use tendermint_rpc; use tokio::task::JoinError; use tokio::time::error::Elapsed; +define_error! { + /// A diagnostic used when an issue arises while generating a config file + /// using the `hermes config auto` command. It communicates the error that + /// occurred when generating the config file, as well as all of the config + /// fields that could not be populated due to the error. + ConfigAutoError { + Diagnostic + { missing_fields: Vec, chain_name: String } + [ RegistryError ] + |e| { + let missing_fields = e.missing_fields + .iter() + .join("\n\t"); + + format!("Chain {} missing config fields: {}", e.chain_name, missing_fields) + }, + } +} + define_error! { RegistryError { diff --git a/crates/relayer-cli/src/chain_registry.rs b/crates/relayer-cli/src/chain_registry.rs index 2c1cca9a2b..df68dd1346 100644 --- a/crates/relayer-cli/src/chain_registry.rs +++ b/crates/relayer-cli/src/chain_registry.rs @@ -11,7 +11,7 @@ use tracing::trace; use ibc_chain_registry::asset_list::AssetList; use ibc_chain_registry::chain::ChainData; -use ibc_chain_registry::error::RegistryError; +use ibc_chain_registry::error::{RegistryError, ConfigAutoError}; use ibc_chain_registry::fetchable::Fetchable; use ibc_chain_registry::formatter::{SimpleGrpcFormatter, UriFormatter}; use ibc_chain_registry::paths::IBCPath; @@ -27,18 +27,6 @@ use tendermint_rpc::Url; const MAX_HEALTHY_QUERY_RETRIES: u8 = 5; -/// A diagnostic used when an issue arises while generating a config file -/// using the `hermes config auto` command. It communicates the error that -/// occurred when generating the config file, as well as all of the config -/// fields that could not be populated due to the error. -#[derive(Debug)] -pub struct Diagnostic { - /// The `RegistryError` that occurred while generating the config file. - pub error: RegistryError, - /// The config fields that were unable to be populated. - pub missing_fields: Vec, -} - /// Generate packet filters from Vec and load them in a Map(chain_name -> filter). fn construct_packet_filters(ibc_paths: Vec) -> HashMap { let mut packet_filters: HashMap<_, Vec<_>> = HashMap::new(); @@ -75,7 +63,7 @@ async fn hermes_config( chain_data: ChainData, assets: AssetList, packet_filter: Option, -) -> (ChainConfig, Option) +) -> Result where GrpcQuerier: QueryContext + Send, @@ -132,7 +120,7 @@ where 0.1 }; - (ChainConfig { + Ok(ChainConfig { id: chain_data.chain_id, r#type: default::chain_type(), rpc_addr: rpc_data.rpc_address, @@ -144,7 +132,7 @@ where rpc_timeout: default::rpc_timeout(), trusted_node: default::trusted_node(), genesis_restart: None, - account_prefix: chain_data.bech32_prefix, + account_prefix: Some(chain_data.bech32_prefix), key_name: String::new(), key_store_type: Store::default(), key_store_folder: None, @@ -172,7 +160,7 @@ where address_type: AddressType::default(), sequential_batch_tx: false, extension_options: Vec::new(), - }, None) + }) } /// Concurrent `query_healthy` might fail, this is a helper function which will retry a failed query a fixed diff --git a/crates/relayer-cli/src/commands/config/auto.rs b/crates/relayer-cli/src/commands/config/auto.rs index 47475ff4ec..4f8aeb6395 100644 --- a/crates/relayer-cli/src/commands/config/auto.rs +++ b/crates/relayer-cli/src/commands/config/auto.rs @@ -88,70 +88,67 @@ impl Runnable for AutoCmd { // Fetch chain configs from the chain registry info!("Fetching configuration for chains: {sorted_names:?}"); - let (chain_configs, maybe_diagnostic) = runtime.block_on(get_configs(&sorted_names, commit)); - - if let Some(diagnostic) = maybe_diagnostic { - warn!( - "Unable to populate all config fields. The following fields were not populated: {}", - diagnostic - ); - } - - let config = Config { - chains: chain_configs, - ..Config::default() - }; - - match store(&config, &self.path) { - Ok(_) => Output::success_msg(format!( - "Config file written successfully at '{}'", - self.path.display(), - )) - .exit(), - Err(e) => Output::error(e).exit(), + match runtime.block_on(get_configs(&sorted_names, commit)) { + Ok(mut chain_configs) => { + let configs_and_keys = chain_configs + .iter_mut() + .zip(names_and_keys.iter().map(|n| &n.1).cloned()); + + for (chain_config, key_option) in configs_and_keys { + // If a key is provided, use it + if let Some(key_name) = key_option { + info!("{}: uses key \"{}\"", &chain_config.id, &key_name); + chain_config.key_name = key_name; + } else { + // Otherwise, find the key in the keystore + let chain_id = &chain_config.id; + let key = find_key(chain_config); + if let Some(key) = key { + info!("{}: uses key '{}'", &chain_id, &key); + chain_config.key_name = key; + } else { + // If no key is found, warn the user and continue + warn!("No key found for chain: {}", chain_id); + } + } + } + + let config = Config { + chains: chain_configs, + ..Config::default() + }; + + match store(&config, &self.path) { + Ok(_) => Output::success_msg(format!( + "Config file written successfully at '{}'", + self.path.display() + )) + .exit(), + Err(e) => Output::error(e).exit(), + } + } + Err(e) => { + // In the case that we get a RegistryError, construct a Config with + // the chain configs that were successfully generated. Print out the names + // of the chains whose configs were not successfully generated. + + let missing_chain_configs: Vec = Vec::new(); + let config = Config::default(); + + match store(&config, &self.path) { + Ok(_) => Output::success_msg(format!( + "An error occurred while generating the chain config file: {:?}\n + A default config file has been written at '{}'\n + Configurations for the following chains were unable to be generated: {:?}", + e, + self.path.display(), + missing_chain_configs, + )) + .exit(), + Err(e) => Output::error(e).exit(), + } + } } - - // match runtime.block_on(get_configs(&sorted_names, commit)) { - // Ok(mut chain_configs) => { - // let configs_and_keys = chain_configs - // .iter_mut() - // .zip(names_and_keys.iter().map(|n| &n.1).cloned()); - - // for (chain_config, key_option) in configs_and_keys { - // // If a key is provided, use it - // if let Some(key_name) = key_option { - // info!("{}: uses key \"{}\"", &chain_config.id, &key_name); - // chain_config.key_name = key_name; - // } else { - // // Otherwise, find the key in the keystore - // let chain_id = &chain_config.id; - // let key = find_key(chain_config); - // if let Some(key) = key { - // info!("{}: uses key '{}'", &chain_id, &key); - // chain_config.key_name = key; - // } else { - // // If no key is found, warn the user and continue - // warn!("No key found for chain: {}", chain_id); - // } - // } - // } - - // let config = Config { - // chains: chain_configs, - // ..Config::default() - // }; - - // match store(&config, &self.path) { - // Ok(_) => Output::success_msg(format!( - // "Config file written successfully at '{}'", - // self.path.display() - // )) - // .exit(), - // Err(e) => Output::error(e).exit(), - // } - // } - // Err(e) => Output::error(e).exit(), - // } } } diff --git a/crates/relayer/src/config.rs b/crates/relayer/src/config.rs index 92fe601cbf..49b7e79921 100644 --- a/crates/relayer/src/config.rs +++ b/crates/relayer/src/config.rs @@ -579,7 +579,7 @@ pub struct ChainConfig { #[serde(default = "default::trusted_node")] pub trusted_node: bool, - pub account_prefix: String, + pub account_prefix: Option, pub key_name: String, #[serde(default)] pub key_store_type: Store, From 675bd38587f9c39a95e3a258cd168565bfbccba6 Mon Sep 17 00:00:00 2001 From: Sean Chen Date: Fri, 7 Jul 2023 08:20:00 -0500 Subject: [PATCH 05/16] Add some printlns --- crates/chain-registry/src/error.rs | 21 ++++--------------- crates/relayer-cli/src/chain_registry.rs | 8 ++++--- .../relayer-cli/src/commands/config/auto.rs | 12 +++++++---- crates/relayer/src/config.rs | 2 +- 4 files changed, 18 insertions(+), 25 deletions(-) diff --git a/crates/chain-registry/src/error.rs b/crates/chain-registry/src/error.rs index 1798a5d8f6..c2ac9630bd 100644 --- a/crates/chain-registry/src/error.rs +++ b/crates/chain-registry/src/error.rs @@ -8,23 +8,10 @@ use tendermint_rpc; use tokio::task::JoinError; use tokio::time::error::Elapsed; -define_error! { - /// A diagnostic used when an issue arises while generating a config file - /// using the `hermes config auto` command. It communicates the error that - /// occurred when generating the config file, as well as all of the config - /// fields that could not be populated due to the error. - ConfigAutoError { - Diagnostic - { missing_fields: Vec, chain_name: String } - [ RegistryError ] - |e| { - let missing_fields = e.missing_fields - .iter() - .join("\n\t"); - - format!("Chain {} missing config fields: {}", e.chain_name, missing_fields) - }, - } +pub struct ConfigAutoDiagnostic { + pub chain_name: String, + pub missing_fields: Vec, + pub error: RegistryError, } define_error! { diff --git a/crates/relayer-cli/src/chain_registry.rs b/crates/relayer-cli/src/chain_registry.rs index df68dd1346..ed2c005574 100644 --- a/crates/relayer-cli/src/chain_registry.rs +++ b/crates/relayer-cli/src/chain_registry.rs @@ -11,7 +11,7 @@ use tracing::trace; use ibc_chain_registry::asset_list::AssetList; use ibc_chain_registry::chain::ChainData; -use ibc_chain_registry::error::{RegistryError, ConfigAutoError}; +use ibc_chain_registry::error::RegistryError; use ibc_chain_registry::fetchable::Fetchable; use ibc_chain_registry::formatter::{SimpleGrpcFormatter, UriFormatter}; use ibc_chain_registry::paths::IBCPath; @@ -63,7 +63,7 @@ async fn hermes_config( chain_data: ChainData, assets: AssetList, packet_filter: Option, -) -> Result +) -> Result where GrpcQuerier: QueryContext + Send, @@ -132,7 +132,7 @@ where rpc_timeout: default::rpc_timeout(), trusted_node: default::trusted_node(), genesis_restart: None, - account_prefix: Some(chain_data.bech32_prefix), + account_prefix: chain_data.bech32_prefix, key_name: String::new(), key_store_type: Store::default(), key_store_folder: None, @@ -299,6 +299,8 @@ pub async fn get_configs( }) .collect(); + println!("config_handles: {:?}", config_handles); + get_data_from_handles::(config_handles, "config_handle_join").await } diff --git a/crates/relayer-cli/src/commands/config/auto.rs b/crates/relayer-cli/src/commands/config/auto.rs index 4f8aeb6395..523a2ac4cb 100644 --- a/crates/relayer-cli/src/commands/config/auto.rs +++ b/crates/relayer-cli/src/commands/config/auto.rs @@ -88,7 +88,11 @@ impl Runnable for AutoCmd { // Fetch chain configs from the chain registry info!("Fetching configuration for chains: {sorted_names:?}"); - match runtime.block_on(get_configs(&sorted_names, commit)) { + let fetched_configs = runtime.block_on(get_configs(&sorted_names, commit)); + + println!("fetched_configs: {:?}", fetched_configs); + + match fetched_configs { Ok(mut chain_configs) => { let configs_and_keys = chain_configs .iter_mut() @@ -136,9 +140,9 @@ impl Runnable for AutoCmd { let config = Config::default(); match store(&config, &self.path) { - Ok(_) => Output::success_msg(format!( - "An error occurred while generating the chain config file: {:?}\n - A default config file has been written at '{}'\n + Ok(_) => Output::error(format!( + "An error occurred while generating the chain config file: {:?} + A default config file has been written at '{}' Configurations for the following chains were unable to be generated: {:?}", e, self.path.display(), diff --git a/crates/relayer/src/config.rs b/crates/relayer/src/config.rs index 49b7e79921..92fe601cbf 100644 --- a/crates/relayer/src/config.rs +++ b/crates/relayer/src/config.rs @@ -579,7 +579,7 @@ pub struct ChainConfig { #[serde(default = "default::trusted_node")] pub trusted_node: bool, - pub account_prefix: Option, + pub account_prefix: String, pub key_name: String, #[serde(default)] pub key_store_type: Store, From edaaca5c7cc6a519f9ab2913413293a4e3676744 Mon Sep 17 00:00:00 2001 From: Sean Chen Date: Fri, 7 Jul 2023 11:11:23 -0500 Subject: [PATCH 06/16] Change `get_configs` return type --- crates/chain-registry/src/error.rs | 6 - crates/relayer-cli/src/chain_registry.rs | 154 ++++++++++++----------- 2 files changed, 83 insertions(+), 77 deletions(-) diff --git a/crates/chain-registry/src/error.rs b/crates/chain-registry/src/error.rs index c2ac9630bd..662ce5cbab 100644 --- a/crates/chain-registry/src/error.rs +++ b/crates/chain-registry/src/error.rs @@ -8,12 +8,6 @@ use tendermint_rpc; use tokio::task::JoinError; use tokio::time::error::Elapsed; -pub struct ConfigAutoDiagnostic { - pub chain_name: String, - pub missing_fields: Vec, - pub error: RegistryError, -} - define_error! { RegistryError { diff --git a/crates/relayer-cli/src/chain_registry.rs b/crates/relayer-cli/src/chain_registry.rs index ed2c005574..26c0532211 100644 --- a/crates/relayer-cli/src/chain_registry.rs +++ b/crates/relayer-cli/src/chain_registry.rs @@ -242,7 +242,7 @@ async fn get_data_from_handles( pub async fn get_configs( chains: &[String], commit: Option, -) -> Result, RegistryError> { +) -> Result>, RegistryError> { let n = chains.len(); if n == 0 { @@ -299,9 +299,13 @@ pub async fn get_configs( }) .collect(); - println!("config_handles: {:?}", config_handles); + let config_results = join_all(config_handles) + .await + .into_iter() + .collect::, JoinError>>() + .map_err(|e| RegistryError::join_error("config_handle_join".to_string(), e))?; - get_data_from_handles::(config_handles, "config_handle_join").await + Ok(config_results) } /// Concurrent RPC and GRPC queries are likely to fail. @@ -324,10 +328,13 @@ mod tests { // chain-registry repository: https://github.com/cosmos/chain-registry/tree/master/_IBC async fn should_have_no_filter(test_chains: &[String]) -> Result<(), RegistryError> { let configs = get_configs(test_chains, Some(TEST_COMMIT.to_owned())).await?; + for config in configs { - match config.packet_filter.channel_policy { - ChannelPolicy::AllowAll => {} - _ => panic!("PacketFilter not allowed"), + match config { + Ok(config) => { + assert_eq!(config.packet_filter.channel_policy, ChannelPolicy::AllowAll); + }, + Err(e) => panic!("Encountered an unexpected error in chain registry test: {}", e) } } @@ -347,73 +354,78 @@ mod tests { let configs = get_configs(test_chains, Some(TEST_COMMIT.to_owned())).await?; for config in configs { - match config.packet_filter.channel_policy { - ChannelPolicy::Allow(channel_filter) => { - if config.id.as_str().contains("cosmoshub") { - assert!(channel_filter.is_exact()); - - let cosmoshub_juno = ( - &PortId::from_str("transfer").unwrap(), - &ChannelId::from_str("channel-207").unwrap(), - ); - - let cosmoshub_osmosis = ( - &PortId::from_str("transfer").unwrap(), - &ChannelId::from_str("channel-141").unwrap(), - ); - - assert!(channel_filter.matches(cosmoshub_juno)); - assert!(channel_filter.matches(cosmoshub_osmosis)); - assert!(channel_filter.len() == 2); - } else if config.id.as_str().contains("juno") { - assert!(channel_filter.is_exact()); - - let juno_cosmoshub = ( - &PortId::from_str("transfer").unwrap(), - &ChannelId::from_str("channel-1").unwrap(), - ); - - let juno_osmosis_1 = ( - &PortId::from_str("transfer").unwrap(), - &ChannelId::from_str("channel-0").unwrap(), - ); - - let juno_osmosis_2 = ( - &PortId::from_str("wasm.juno1v4887y83d6g28puzvt8cl0f3cdhd3y6y9mpysnsp3k8krdm7l6jqgm0rkn").unwrap(), - &ChannelId::from_str("channel-47").unwrap() - ); - - assert!(channel_filter.matches(juno_cosmoshub)); - assert!(channel_filter.matches(juno_osmosis_1)); - assert!(channel_filter.matches(juno_osmosis_2)); - assert!(channel_filter.len() == 3); - } else if config.id.as_str().contains("osmosis") { - assert!(channel_filter.is_exact()); - - let osmosis_cosmoshub = ( - &PortId::from_str("transfer").unwrap(), - &ChannelId::from_str("channel-0").unwrap(), - ); - - let osmosis_juno_1 = ( - &PortId::from_str("transfer").unwrap(), - &ChannelId::from_str("channel-42").unwrap(), - ); - - let osmosis_juno_2 = ( - &PortId::from_str("transfer").unwrap(), - &ChannelId::from_str("channel-169").unwrap(), - ); - - assert!(channel_filter.matches(osmosis_cosmoshub)); - assert!(channel_filter.matches(osmosis_juno_1)); - assert!(channel_filter.matches(osmosis_juno_2)); - assert!(channel_filter.len() == 3); - } else { - panic!("Unknown chain"); + match config { + Ok(config) => { + match config.packet_filter.channel_policy { + ChannelPolicy::Allow(channel_filter) => { + if config.id.as_str().contains("cosmoshub") { + assert!(channel_filter.is_exact()); + + let cosmoshub_juno = ( + &PortId::from_str("transfer").unwrap(), + &ChannelId::from_str("channel-207").unwrap(), + ); + + let cosmoshub_osmosis = ( + &PortId::from_str("transfer").unwrap(), + &ChannelId::from_str("channel-141").unwrap(), + ); + + assert!(channel_filter.matches(cosmoshub_juno)); + assert!(channel_filter.matches(cosmoshub_osmosis)); + assert!(channel_filter.len() == 2); + } else if config.id.as_str().contains("juno") { + assert!(channel_filter.is_exact()); + + let juno_cosmoshub = ( + &PortId::from_str("transfer").unwrap(), + &ChannelId::from_str("channel-1").unwrap(), + ); + + let juno_osmosis_1 = ( + &PortId::from_str("transfer").unwrap(), + &ChannelId::from_str("channel-0").unwrap(), + ); + + let juno_osmosis_2 = ( + &PortId::from_str("wasm.juno1v4887y83d6g28puzvt8cl0f3cdhd3y6y9mpysnsp3k8krdm7l6jqgm0rkn").unwrap(), + &ChannelId::from_str("channel-47").unwrap() + ); + + assert!(channel_filter.matches(juno_cosmoshub)); + assert!(channel_filter.matches(juno_osmosis_1)); + assert!(channel_filter.matches(juno_osmosis_2)); + assert!(channel_filter.len() == 3); + } else if config.id.as_str().contains("osmosis") { + assert!(channel_filter.is_exact()); + + let osmosis_cosmoshub = ( + &PortId::from_str("transfer").unwrap(), + &ChannelId::from_str("channel-0").unwrap(), + ); + + let osmosis_juno_1 = ( + &PortId::from_str("transfer").unwrap(), + &ChannelId::from_str("channel-42").unwrap(), + ); + + let osmosis_juno_2 = ( + &PortId::from_str("transfer").unwrap(), + &ChannelId::from_str("channel-169").unwrap(), + ); + + assert!(channel_filter.matches(osmosis_cosmoshub)); + assert!(channel_filter.matches(osmosis_juno_1)); + assert!(channel_filter.matches(osmosis_juno_2)); + assert!(channel_filter.len() == 3); + } else { + panic!("Unknown chain"); + } + } + _ => panic!("PacketFilter not allowed"), } } - _ => panic!("PacketFilter not allowed"), + Err(e) => panic!("Encountered an unexpected error in chain registry test: {}", e) } } From 308e747ab0988864e901dfc30f67245b7b30086d Mon Sep 17 00:00:00 2001 From: Sean Chen Date: Fri, 7 Jul 2023 14:03:04 -0500 Subject: [PATCH 07/16] Change AutoCmd::run --- .../relayer-cli/src/commands/config/auto.rs | 27 +++++++++++++++---- .../src/core/ics24_host/identifier.rs | 2 +- 2 files changed, 23 insertions(+), 6 deletions(-) diff --git a/crates/relayer-cli/src/commands/config/auto.rs b/crates/relayer-cli/src/commands/config/auto.rs index 523a2ac4cb..9a907c57bc 100644 --- a/crates/relayer-cli/src/commands/config/auto.rs +++ b/crates/relayer-cli/src/commands/config/auto.rs @@ -7,6 +7,7 @@ use crate::conclude::Output; use ibc_relayer::config::{store, ChainConfig, Config}; use ibc_relayer::keyring::list_keys; +use std::collections::HashSet; use std::path::PathBuf; use tracing::{info, warn}; @@ -81,6 +82,8 @@ impl Runnable for AutoCmd { .map(|n| &n.0) .cloned() .collect::>(); + + let sorted_names_set = HashSet::from_iter(sorted_names.iter().cloned()); let commit = self.commit.clone(); @@ -88,9 +91,24 @@ impl Runnable for AutoCmd { // Fetch chain configs from the chain registry info!("Fetching configuration for chains: {sorted_names:?}"); - let fetched_configs = runtime.block_on(get_configs(&sorted_names, commit)); + let Ok(config_results) = runtime.block_on(get_configs(&sorted_names, commit)) else { + let config = Config::default(); + + match store(&config, &self.path) { + Ok(_) => Output::error(format!( + "An error occurred while generating the chain config file. + A default config file has been written at '{}'", + self.path.display(), + )) + .exit(), + Err(e) => Output::error(e).exit(), + } + }; - println!("fetched_configs: {:?}", fetched_configs); + let fetched_configs: Vec = config_results + .into_iter() + .filter_map(|r| r.ok()) + .collect(); match fetched_configs { Ok(mut chain_configs) => { @@ -135,16 +153,15 @@ impl Runnable for AutoCmd { // In the case that we get a RegistryError, construct a Config with // the chain configs that were successfully generated. Print out the names // of the chains whose configs were not successfully generated. - + let sorted_names_set = HashSet::from_iter(sorted_names); let missing_chain_configs: Vec = Vec::new(); let config = Config::default(); match store(&config, &self.path) { Ok(_) => Output::error(format!( - "An error occurred while generating the chain config file: {:?} + "An error occurred while generating the chain config file. A default config file has been written at '{}' Configurations for the following chains were unable to be generated: {:?}", - e, self.path.display(), missing_chain_configs, )) diff --git a/crates/relayer-types/src/core/ics24_host/identifier.rs b/crates/relayer-types/src/core/ics24_host/identifier.rs index a98696a982..a7e3726cd1 100644 --- a/crates/relayer-types/src/core/ics24_host/identifier.rs +++ b/crates/relayer-types/src/core/ics24_host/identifier.rs @@ -18,7 +18,7 @@ use crate::core::ics24_host::error::ValidationError; #[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize)] #[serde(from = "tendermint::chain::Id", into = "tendermint::chain::Id")] pub struct ChainId { - id: String, + pub id: String, version: u64, } From ae696d1d297056d52f8a47efd1ffbc701bf343c8 Mon Sep 17 00:00:00 2001 From: Sean Chen Date: Fri, 7 Jul 2023 14:40:22 -0500 Subject: [PATCH 08/16] Get it to compile --- .../relayer-cli/src/commands/config/auto.rs | 118 +++++++++--------- 1 file changed, 57 insertions(+), 61 deletions(-) diff --git a/crates/relayer-cli/src/commands/config/auto.rs b/crates/relayer-cli/src/commands/config/auto.rs index 9a907c57bc..497a813c37 100644 --- a/crates/relayer-cli/src/commands/config/auto.rs +++ b/crates/relayer-cli/src/commands/config/auto.rs @@ -83,7 +83,7 @@ impl Runnable for AutoCmd { .cloned() .collect::>(); - let sorted_names_set = HashSet::from_iter(sorted_names.iter().cloned()); + let sorted_names_set: HashSet = HashSet::from_iter(sorted_names.iter().cloned()); let commit = self.commit.clone(); @@ -91,84 +91,80 @@ impl Runnable for AutoCmd { // Fetch chain configs from the chain registry info!("Fetching configuration for chains: {sorted_names:?}"); - let Ok(config_results) = runtime.block_on(get_configs(&sorted_names, commit)) else { + let config_results = runtime.block_on(get_configs(&sorted_names, commit)); + + if let Err(e) = config_results { let config = Config::default(); match store(&config, &self.path) { Ok(_) => Output::error(format!( - "An error occurred while generating the chain config file. + "An error occurred while generating the chain config file: {} A default config file has been written at '{}'", + e, self.path.display(), )) .exit(), - Err(e) => Output::error(e).exit(), + Err(e) => Output::error(format!("An error occurred while attempting to write the config file: {}", e)).exit(), } }; - let fetched_configs: Vec = config_results + let mut chain_configs: Vec = config_results + .unwrap() .into_iter() .filter_map(|r| r.ok()) .collect(); - match fetched_configs { - Ok(mut chain_configs) => { - let configs_and_keys = chain_configs - .iter_mut() - .zip(names_and_keys.iter().map(|n| &n.1).cloned()); - - for (chain_config, key_option) in configs_and_keys { - // If a key is provided, use it - if let Some(key_name) = key_option { - info!("{}: uses key \"{}\"", &chain_config.id, &key_name); - chain_config.key_name = key_name; - } else { - // Otherwise, find the key in the keystore - let chain_id = &chain_config.id; - let key = find_key(chain_config); - if let Some(key) = key { - info!("{}: uses key '{}'", &chain_id, &key); - chain_config.key_name = key; - } else { - // If no key is found, warn the user and continue - warn!("No key found for chain: {}", chain_id); - } - } - } - - let config = Config { - chains: chain_configs, - ..Config::default() - }; - - match store(&config, &self.path) { - Ok(_) => Output::success_msg(format!( - "Config file written successfully at '{}'", - self.path.display() - )) - .exit(), - Err(e) => Output::error(e).exit(), - } - } - Err(e) => { - // In the case that we get a RegistryError, construct a Config with - // the chain configs that were successfully generated. Print out the names - // of the chains whose configs were not successfully generated. - let sorted_names_set = HashSet::from_iter(sorted_names); - let missing_chain_configs: Vec = Vec::new(); - let config = Config::default(); - - match store(&config, &self.path) { - Ok(_) => Output::error(format!( - "An error occurred while generating the chain config file. - A default config file has been written at '{}' - Configurations for the following chains were unable to be generated: {:?}", + // Determine which chains were not fetched + let fetched_chains_set = HashSet::from_iter(chain_configs.iter().map(|c| c.id.id.clone())); + let missing_chains_set: HashSet<_> = sorted_names_set.difference(&fetched_chains_set).collect(); + + let configs_and_keys = chain_configs + .iter_mut() + .zip(names_and_keys.iter().map(|n| &n.1).cloned()); + + for (chain_config, key_option) in configs_and_keys { + // If a key is provided, use it + if let Some(key_name) = key_option { + info!("{}: uses key \"{}\"", &chain_config.id, &key_name); + chain_config.key_name = key_name; + } else { + // Otherwise, find the key in the keystore + let chain_id = &chain_config.id; + let key = find_key(chain_config); + if let Some(key) = key { + info!("{}: uses key '{}'", &chain_id, &key); + chain_config.key_name = key; + } else { + // If no key is found, warn the user and continue + warn!("No key found for chain: {}", chain_id); + } + } + } + + let config = Config { + chains: chain_configs, + ..Config::default() + }; + + match store(&config, &self.path) { + Ok(_) => { + if missing_chains_set.is_empty() { + Output::success_msg(format!( + "Config file written successfully at '{}'", + self.path.display() + )) + .exit() + } else { + Output::success_msg(format!( + "Config file written successfully at '{}'. + However, configurations for the following chains were not able to be generated: {:?}", self.path.display(), - missing_chain_configs, + missing_chains_set, )) - .exit(), - Err(e) => Output::error(e).exit(), + .exit() } - } + } + Err(e) => Output::error(format!("An error occurred while attempting to write the config file: {}", e)).exit(), } } } From 9f63875e205e2bddf241cb8c97c90955163bc733 Mon Sep 17 00:00:00 2001 From: Sean Chen Date: Mon, 10 Jul 2023 09:39:17 -0500 Subject: [PATCH 09/16] Fix false reporting of missing chain configs --- crates/relayer-cli/src/commands/config/auto.rs | 7 ++++++- .../relayer-types/src/core/ics24_host/identifier.rs | 12 +++++++++++- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/crates/relayer-cli/src/commands/config/auto.rs b/crates/relayer-cli/src/commands/config/auto.rs index 497a813c37..b042891537 100644 --- a/crates/relayer-cli/src/commands/config/auto.rs +++ b/crates/relayer-cli/src/commands/config/auto.rs @@ -82,6 +82,8 @@ impl Runnable for AutoCmd { .map(|n| &n.0) .cloned() .collect::>(); + + println!("sorted_names: {:?}", sorted_names); let sorted_names_set: HashSet = HashSet::from_iter(sorted_names.iter().cloned()); @@ -115,7 +117,10 @@ impl Runnable for AutoCmd { .collect(); // Determine which chains were not fetched - let fetched_chains_set = HashSet::from_iter(chain_configs.iter().map(|c| c.id.id.clone())); + let fetched_chains_set = HashSet::from_iter(chain_configs.iter().map(|c| c.id.name())); + + println!("fetched_chains_set: {:?}", fetched_chains_set); + let missing_chains_set: HashSet<_> = sorted_names_set.difference(&fetched_chains_set).collect(); let configs_and_keys = chain_configs diff --git a/crates/relayer-types/src/core/ics24_host/identifier.rs b/crates/relayer-types/src/core/ics24_host/identifier.rs index a7e3726cd1..ae503dc587 100644 --- a/crates/relayer-types/src/core/ics24_host/identifier.rs +++ b/crates/relayer-types/src/core/ics24_host/identifier.rs @@ -18,7 +18,7 @@ use crate::core::ics24_host::error::ValidationError; #[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize)] #[serde(from = "tendermint::chain::Id", into = "tendermint::chain::Id")] pub struct ChainId { - pub id: String, + id: String, version: u64, } @@ -64,6 +64,16 @@ impl ChainId { self.version } + /// Extract the chain name from this chain identifier. The chain name + /// consists of the first part of the identifier, before the dash. + pub fn name(&self) -> String { + self.id + .split('-') + .take(1) + .collect::>() + .join("") + } + /// Extract the version from the given chain identifier. /// ``` /// use ibc_relayer_types::core::ics24_host::identifier::ChainId; From 7b7b6286af3b559bf37a58aefb86ceadd84165ca Mon Sep 17 00:00:00 2001 From: Sean Chen Date: Mon, 10 Jul 2023 09:52:42 -0500 Subject: [PATCH 10/16] Change get_data_from_handles --- crates/relayer-cli/src/chain_registry.rs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/crates/relayer-cli/src/chain_registry.rs b/crates/relayer-cli/src/chain_registry.rs index 26c0532211..c0be084070 100644 --- a/crates/relayer-cli/src/chain_registry.rs +++ b/crates/relayer-cli/src/chain_registry.rs @@ -214,14 +214,12 @@ async fn get_handles( async fn get_data_from_handles( handles: Vec>>, error_task: &str, -) -> Result, RegistryError> { - let data_array: Result, JoinError> = join_all(handles).await.into_iter().collect(); - let data_array: Result, RegistryError> = data_array - .map_err(|e| RegistryError::join_error(error_task.to_string(), e))? +) -> Result>, RegistryError> { + join_all(handles) + .await .into_iter() - .collect(); - - data_array + .collect::, JoinError>>() + .map_err(|e| RegistryError::join_error(error_task.to_string(), e)) } /// Generates a `Vec` for a slice of chain names by fetching data from @@ -299,6 +297,8 @@ pub async fn get_configs( }) .collect(); + // get_data_from_handles::(config_handles, "config_handle_join").await + let config_results = join_all(config_handles) .await .into_iter() From 825880b11200f1cf991c5ae1fe5b5c057b0b920a Mon Sep 17 00:00:00 2001 From: Sean Chen Date: Mon, 10 Jul 2023 10:54:59 -0500 Subject: [PATCH 11/16] Get it working --- crates/relayer-cli/src/chain_registry.rs | 33 ++++++++++++------- .../relayer-cli/src/commands/config/auto.rs | 9 +---- 2 files changed, 23 insertions(+), 19 deletions(-) diff --git a/crates/relayer-cli/src/chain_registry.rs b/crates/relayer-cli/src/chain_registry.rs index c0be084070..0c23f9f2ed 100644 --- a/crates/relayer-cli/src/chain_registry.rs +++ b/crates/relayer-cli/src/chain_registry.rs @@ -76,6 +76,10 @@ where { let chain_name = chain_data.chain_name; + if chain_name == "cosmoshub" { + return Err(RegistryError::no_asset_found(chain_name.to_string())); + } + let asset = assets .assets .first() @@ -196,6 +200,10 @@ where )) } +/// Fetches the specified resources from the Cosmos chain registry, using the specified commit hash +/// if it is provided. Fetching is done in a concurrent fashion by spawning a task for each resource. +/// Returns a vector of handles that need to be awaited in order to access the fetched data, or the +/// error that occurred while fetching. async fn get_handles( resources: &[String], commit: &Option, @@ -211,6 +219,8 @@ async fn get_handles( handles } +/// Given a vector of handles, awaits them and returns a vector of results. Any errors +/// that occurred are mapped to a `RegistryError`. async fn get_data_from_handles( handles: Vec>>, error_task: &str, @@ -265,11 +275,20 @@ pub async fn get_configs( } // Collect data from the spawned tasks - let chain_data_array = + let chain_data_results = get_data_from_handles::(chain_data_handle, "chain_data_join").await?; - let asset_lists = + let asset_list_results = get_data_from_handles::(asset_lists_handle, "asset_handle_join").await?; + let chain_data_array: Vec = chain_data_results + .into_iter() + .filter_map(|chain_data| chain_data.ok()) + .collect(); + let asset_lists: Vec = asset_list_results + .into_iter() + .filter_map(|asset_list| asset_list.ok()) + .collect(); + let path_data: Result, JoinError> = join_all(path_handles).await.into_iter().collect(); let path_data: Vec = path_data .map_err(|e| RegistryError::join_error("path_handle_join".to_string(), e))? @@ -297,15 +316,7 @@ pub async fn get_configs( }) .collect(); - // get_data_from_handles::(config_handles, "config_handle_join").await - - let config_results = join_all(config_handles) - .await - .into_iter() - .collect::, JoinError>>() - .map_err(|e| RegistryError::join_error("config_handle_join".to_string(), e))?; - - Ok(config_results) + get_data_from_handles::(config_handles, "config_handle_join").await } /// Concurrent RPC and GRPC queries are likely to fail. diff --git a/crates/relayer-cli/src/commands/config/auto.rs b/crates/relayer-cli/src/commands/config/auto.rs index b042891537..9fde87c9b3 100644 --- a/crates/relayer-cli/src/commands/config/auto.rs +++ b/crates/relayer-cli/src/commands/config/auto.rs @@ -76,23 +76,19 @@ impl Runnable for AutoCmd { // Assert that for every chain, a key name is provided let runtime = tokio::runtime::Runtime::new().unwrap(); + // Extract keys and sort chains by name let names_and_keys = extract_chains_and_keys(&self.chain_names); let sorted_names = names_and_keys .iter() .map(|n| &n.0) .cloned() .collect::>(); - - println!("sorted_names: {:?}", sorted_names); let sorted_names_set: HashSet = HashSet::from_iter(sorted_names.iter().cloned()); let commit = self.commit.clone(); - // Extract keys and sort chains by name // Fetch chain configs from the chain registry - info!("Fetching configuration for chains: {sorted_names:?}"); - let config_results = runtime.block_on(get_configs(&sorted_names, commit)); if let Err(e) = config_results { @@ -118,9 +114,6 @@ impl Runnable for AutoCmd { // Determine which chains were not fetched let fetched_chains_set = HashSet::from_iter(chain_configs.iter().map(|c| c.id.name())); - - println!("fetched_chains_set: {:?}", fetched_chains_set); - let missing_chains_set: HashSet<_> = sorted_names_set.difference(&fetched_chains_set).collect(); let configs_and_keys = chain_configs From 6e6f0f3a9781b22f1bd29bd58493827b1ed9af3b Mon Sep 17 00:00:00 2001 From: Sean Chen Date: Mon, 10 Jul 2023 12:18:33 -0500 Subject: [PATCH 12/16] Remove some debugging code --- crates/relayer-cli/src/chain_registry.rs | 4 ---- 1 file changed, 4 deletions(-) diff --git a/crates/relayer-cli/src/chain_registry.rs b/crates/relayer-cli/src/chain_registry.rs index 0c23f9f2ed..3f5c817f18 100644 --- a/crates/relayer-cli/src/chain_registry.rs +++ b/crates/relayer-cli/src/chain_registry.rs @@ -76,10 +76,6 @@ where { let chain_name = chain_data.chain_name; - if chain_name == "cosmoshub" { - return Err(RegistryError::no_asset_found(chain_name.to_string())); - } - let asset = assets .assets .first() From 06cfbb5965a4514dd98ac7eb236adf4408e072c7 Mon Sep 17 00:00:00 2001 From: Sean Chen Date: Mon, 10 Jul 2023 12:25:58 -0500 Subject: [PATCH 13/16] Cargo fmt --- crates/relayer-cli/src/chain_registry.rs | 144 +++++++++--------- .../relayer-cli/src/commands/config/auto.rs | 21 ++- .../src/core/ics24_host/identifier.rs | 6 +- 3 files changed, 90 insertions(+), 81 deletions(-) diff --git a/crates/relayer-cli/src/chain_registry.rs b/crates/relayer-cli/src/chain_registry.rs index 3f5c817f18..612469f598 100644 --- a/crates/relayer-cli/src/chain_registry.rs +++ b/crates/relayer-cli/src/chain_registry.rs @@ -198,8 +198,8 @@ where /// Fetches the specified resources from the Cosmos chain registry, using the specified commit hash /// if it is provided. Fetching is done in a concurrent fashion by spawning a task for each resource. -/// Returns a vector of handles that need to be awaited in order to access the fetched data, or the -/// error that occurred while fetching. +/// Returns a vector of handles that need to be awaited in order to access the fetched data, or the +/// error that occurred while fetching. async fn get_handles( resources: &[String], commit: &Option, @@ -340,8 +340,11 @@ mod tests { match config { Ok(config) => { assert_eq!(config.packet_filter.channel_policy, ChannelPolicy::AllowAll); - }, - Err(e) => panic!("Encountered an unexpected error in chain registry test: {}", e) + } + Err(e) => panic!( + "Encountered an unexpected error in chain registry test: {}", + e + ), } } @@ -362,77 +365,78 @@ mod tests { for config in configs { match config { - Ok(config) => { - match config.packet_filter.channel_policy { - ChannelPolicy::Allow(channel_filter) => { - if config.id.as_str().contains("cosmoshub") { - assert!(channel_filter.is_exact()); - - let cosmoshub_juno = ( - &PortId::from_str("transfer").unwrap(), - &ChannelId::from_str("channel-207").unwrap(), - ); - - let cosmoshub_osmosis = ( - &PortId::from_str("transfer").unwrap(), - &ChannelId::from_str("channel-141").unwrap(), - ); - - assert!(channel_filter.matches(cosmoshub_juno)); - assert!(channel_filter.matches(cosmoshub_osmosis)); - assert!(channel_filter.len() == 2); - } else if config.id.as_str().contains("juno") { - assert!(channel_filter.is_exact()); - - let juno_cosmoshub = ( - &PortId::from_str("transfer").unwrap(), - &ChannelId::from_str("channel-1").unwrap(), - ); - - let juno_osmosis_1 = ( - &PortId::from_str("transfer").unwrap(), - &ChannelId::from_str("channel-0").unwrap(), - ); - - let juno_osmosis_2 = ( + Ok(config) => match config.packet_filter.channel_policy { + ChannelPolicy::Allow(channel_filter) => { + if config.id.as_str().contains("cosmoshub") { + assert!(channel_filter.is_exact()); + + let cosmoshub_juno = ( + &PortId::from_str("transfer").unwrap(), + &ChannelId::from_str("channel-207").unwrap(), + ); + + let cosmoshub_osmosis = ( + &PortId::from_str("transfer").unwrap(), + &ChannelId::from_str("channel-141").unwrap(), + ); + + assert!(channel_filter.matches(cosmoshub_juno)); + assert!(channel_filter.matches(cosmoshub_osmosis)); + assert!(channel_filter.len() == 2); + } else if config.id.as_str().contains("juno") { + assert!(channel_filter.is_exact()); + + let juno_cosmoshub = ( + &PortId::from_str("transfer").unwrap(), + &ChannelId::from_str("channel-1").unwrap(), + ); + + let juno_osmosis_1 = ( + &PortId::from_str("transfer").unwrap(), + &ChannelId::from_str("channel-0").unwrap(), + ); + + let juno_osmosis_2 = ( &PortId::from_str("wasm.juno1v4887y83d6g28puzvt8cl0f3cdhd3y6y9mpysnsp3k8krdm7l6jqgm0rkn").unwrap(), &ChannelId::from_str("channel-47").unwrap() ); - - assert!(channel_filter.matches(juno_cosmoshub)); - assert!(channel_filter.matches(juno_osmosis_1)); - assert!(channel_filter.matches(juno_osmosis_2)); - assert!(channel_filter.len() == 3); - } else if config.id.as_str().contains("osmosis") { - assert!(channel_filter.is_exact()); - - let osmosis_cosmoshub = ( - &PortId::from_str("transfer").unwrap(), - &ChannelId::from_str("channel-0").unwrap(), - ); - - let osmosis_juno_1 = ( - &PortId::from_str("transfer").unwrap(), - &ChannelId::from_str("channel-42").unwrap(), - ); - - let osmosis_juno_2 = ( - &PortId::from_str("transfer").unwrap(), - &ChannelId::from_str("channel-169").unwrap(), - ); - - assert!(channel_filter.matches(osmosis_cosmoshub)); - assert!(channel_filter.matches(osmosis_juno_1)); - assert!(channel_filter.matches(osmosis_juno_2)); - assert!(channel_filter.len() == 3); - } else { - panic!("Unknown chain"); - } + + assert!(channel_filter.matches(juno_cosmoshub)); + assert!(channel_filter.matches(juno_osmosis_1)); + assert!(channel_filter.matches(juno_osmosis_2)); + assert!(channel_filter.len() == 3); + } else if config.id.as_str().contains("osmosis") { + assert!(channel_filter.is_exact()); + + let osmosis_cosmoshub = ( + &PortId::from_str("transfer").unwrap(), + &ChannelId::from_str("channel-0").unwrap(), + ); + + let osmosis_juno_1 = ( + &PortId::from_str("transfer").unwrap(), + &ChannelId::from_str("channel-42").unwrap(), + ); + + let osmosis_juno_2 = ( + &PortId::from_str("transfer").unwrap(), + &ChannelId::from_str("channel-169").unwrap(), + ); + + assert!(channel_filter.matches(osmosis_cosmoshub)); + assert!(channel_filter.matches(osmosis_juno_1)); + assert!(channel_filter.matches(osmosis_juno_2)); + assert!(channel_filter.len() == 3); + } else { + panic!("Unknown chain"); } - _ => panic!("PacketFilter not allowed"), } - } - Err(e) => panic!("Encountered an unexpected error in chain registry test: {}", e) + _ => panic!("PacketFilter not allowed"), + }, + Err(e) => panic!( + "Encountered an unexpected error in chain registry test: {}", + e + ), } } diff --git a/crates/relayer-cli/src/commands/config/auto.rs b/crates/relayer-cli/src/commands/config/auto.rs index 9fde87c9b3..6736f0dd76 100644 --- a/crates/relayer-cli/src/commands/config/auto.rs +++ b/crates/relayer-cli/src/commands/config/auto.rs @@ -83,7 +83,7 @@ impl Runnable for AutoCmd { .map(|n| &n.0) .cloned() .collect::>(); - + let sorted_names_set: HashSet = HashSet::from_iter(sorted_names.iter().cloned()); let commit = self.commit.clone(); @@ -102,7 +102,11 @@ impl Runnable for AutoCmd { self.path.display(), )) .exit(), - Err(e) => Output::error(format!("An error occurred while attempting to write the config file: {}", e)).exit(), + Err(e) => Output::error(format!( + "An error occurred while attempting to write the config file: {}", + e + )) + .exit(), } }; @@ -114,7 +118,8 @@ impl Runnable for AutoCmd { // Determine which chains were not fetched let fetched_chains_set = HashSet::from_iter(chain_configs.iter().map(|c| c.id.name())); - let missing_chains_set: HashSet<_> = sorted_names_set.difference(&fetched_chains_set).collect(); + let missing_chains_set: HashSet<_> = + sorted_names_set.difference(&fetched_chains_set).collect(); let configs_and_keys = chain_configs .iter_mut() @@ -145,7 +150,7 @@ impl Runnable for AutoCmd { }; match store(&config, &self.path) { - Ok(_) => { + Ok(_) => { if missing_chains_set.is_empty() { Output::success_msg(format!( "Config file written successfully at '{}'", @@ -161,8 +166,12 @@ impl Runnable for AutoCmd { )) .exit() } - } - Err(e) => Output::error(format!("An error occurred while attempting to write the config file: {}", e)).exit(), + } + Err(e) => Output::error(format!( + "An error occurred while attempting to write the config file: {}", + e + )) + .exit(), } } } diff --git a/crates/relayer-types/src/core/ics24_host/identifier.rs b/crates/relayer-types/src/core/ics24_host/identifier.rs index ae503dc587..15713ec044 100644 --- a/crates/relayer-types/src/core/ics24_host/identifier.rs +++ b/crates/relayer-types/src/core/ics24_host/identifier.rs @@ -67,11 +67,7 @@ impl ChainId { /// Extract the chain name from this chain identifier. The chain name /// consists of the first part of the identifier, before the dash. pub fn name(&self) -> String { - self.id - .split('-') - .take(1) - .collect::>() - .join("") + self.id.split('-').take(1).collect::>().join("") } /// Extract the version from the given chain identifier. From 313396b7e30a97d09221949506c05a18a3559ce4 Mon Sep 17 00:00:00 2001 From: Sean Chen Date: Mon, 10 Jul 2023 12:38:12 -0500 Subject: [PATCH 14/16] Update `get_configs` doc comment --- crates/relayer-cli/src/chain_registry.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/crates/relayer-cli/src/chain_registry.rs b/crates/relayer-cli/src/chain_registry.rs index 612469f598..dcf2f7af6d 100644 --- a/crates/relayer-cli/src/chain_registry.rs +++ b/crates/relayer-cli/src/chain_registry.rs @@ -228,8 +228,10 @@ async fn get_data_from_handles( .map_err(|e| RegistryError::join_error(error_task.to_string(), e)) } -/// Generates a `Vec` for a slice of chain names by fetching data from -/// . Gas settings are set to default values. +/// Fetches a list of ChainConfigs specified by the given slice of chain names. These +/// configs are fetched from . The `default_gas` +/// and `max_gas` parameters set to default values. The `gas_price` parameter is set to +/// the average gas price for the chain listed in the chain registry. /// /// # Arguments /// From fc02956fe7af4cd5f6c79b447ab3255e760ab010 Mon Sep 17 00:00:00 2001 From: Sean Chen Date: Mon, 10 Jul 2023 12:40:46 -0500 Subject: [PATCH 15/16] Update gas price warning in guide --- guide/src/documentation/commands/config.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/guide/src/documentation/commands/config.md b/guide/src/documentation/commands/config.md index 2f0fed8204..793a1a523c 100644 --- a/guide/src/documentation/commands/config.md +++ b/guide/src/documentation/commands/config.md @@ -17,7 +17,7 @@ The available sub-commands are the following: ### Automatically generate configuration files for specified chains Use `config auto` to automatically generate a configuration file from the [chain-registry](https://github.com/cosmos/chain-registry). -> __WARNING__: Currently, gas parameters are set to default value and require to be set manually. +> __WARNING__: Currently, `default_gas` and `max_gas` parameters are set to default values; these should be manually reset. The `gas_price` parameter is set as the average gas price listed for the chain in the chain registry. ``` {{#include ../../templates/help_templates/config/auto.md}} From d6ea5d1cd28c67f9e79d13967c7b337b0e78412f Mon Sep 17 00:00:00 2001 From: Sean Chen Date: Mon, 10 Jul 2023 12:41:06 -0500 Subject: [PATCH 16/16] Cargo fmt --- crates/relayer-cli/src/chain_registry.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/relayer-cli/src/chain_registry.rs b/crates/relayer-cli/src/chain_registry.rs index dcf2f7af6d..305a8d615a 100644 --- a/crates/relayer-cli/src/chain_registry.rs +++ b/crates/relayer-cli/src/chain_registry.rs @@ -231,7 +231,7 @@ async fn get_data_from_handles( /// Fetches a list of ChainConfigs specified by the given slice of chain names. These /// configs are fetched from . The `default_gas` /// and `max_gas` parameters set to default values. The `gas_price` parameter is set to -/// the average gas price for the chain listed in the chain registry. +/// the average gas price for the chain listed in the chain registry. /// /// # Arguments ///