diff --git a/Cargo.lock b/Cargo.lock index 3cebda4ee..608ca836f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1636,6 +1636,7 @@ dependencies = [ "hermes-relayer-components", "hermes-runtime", "hermes-runtime-components", + "http 1.1.0", "humantime", "ibc", "ibc-relayer", @@ -1660,6 +1661,7 @@ dependencies = [ "hermes-relayer-components", "hermes-runtime-components", "hermes-test-components", + "http 1.1.0", "serde", "toml", ] @@ -1854,6 +1856,7 @@ dependencies = [ "hermes-runtime", "hermes-runtime-components", "hermes-test-components", + "http 1.1.0", "ibc-proto", "ibc-relayer", "ibc-relayer-types", diff --git a/crates/cli/cli-components/Cargo.toml b/crates/cli/cli-components/Cargo.toml index ed3b5b1fc..4d1da2d9c 100644 --- a/crates/cli/cli-components/Cargo.toml +++ b/crates/cli/cli-components/Cargo.toml @@ -20,6 +20,7 @@ hermes-logging-components = { workspace = true } hermes-test-components = { workspace = true } cgp = { workspace = true } +http = { workspace = true } serde = { workspace = true, features = ["derive"] } toml = { workspace = true } clap = { workspace = true, features = ["derive"] } diff --git a/crates/cli/cli/Cargo.toml b/crates/cli/cli/Cargo.toml index 1d9c8f2f4..2360eb19a 100644 --- a/crates/cli/cli/Cargo.toml +++ b/crates/cli/cli/Cargo.toml @@ -42,6 +42,7 @@ eyre = { workspace = true } toml = { workspace = true } oneline-eyre = { workspace = true } hdpath = { workspace = true } +http = { workspace = true } humantime = { workspace = true } tracing = { workspace = true } tonic = { workspace = true } diff --git a/crates/cli/cli/src/commands/keys/add.rs b/crates/cli/cli/src/commands/keys/add.rs index b4eed3010..2769a6fd0 100644 --- a/crates/cli/cli/src/commands/keys/add.rs +++ b/crates/cli/cli/src/commands/keys/add.rs @@ -6,7 +6,7 @@ use hdpath::StandardHDPath; use hermes_cli_components::traits::build::CanLoadBuilder; use hermes_cli_framework::command::CommandRunner; use hermes_cli_framework::output::Output; -use ibc_relayer::chain::cosmos::config::CosmosSdkConfig; +use hermes_cosmos_chain_components::impls::types::config::CosmosChainConfig; use ibc_relayer::keyring::{ AnySigningKeyPair, KeyRing, Secp256k1KeyPair, SigningKeyPair, SigningKeyPairSized, Store, }; @@ -94,7 +94,7 @@ pub struct KeysAddCmd { } impl KeysAddCmd { - fn options(&self, chain_config: &CosmosSdkConfig) -> eyre::Result { + fn options(&self, chain_config: &CosmosChainConfig) -> eyre::Result { let name = self .key_name .clone() @@ -114,12 +114,12 @@ impl KeysAddCmd { #[derive(Clone, Debug)] pub struct KeysAddOptions { pub name: String, - pub config: CosmosSdkConfig, + pub config: CosmosChainConfig, pub hd_path: StandardHDPath, } pub fn add_key( - config: &CosmosSdkConfig, + config: &CosmosChainConfig, key_name: &str, file: &Path, hd_path: &StandardHDPath, @@ -128,7 +128,7 @@ pub fn add_key( let mut keyring = KeyRing::new_secp256k1( Store::Test, &config.account_prefix, - &config.id, + &ChainId::from_string(&config.id), &config.key_store_folder, )?; @@ -146,7 +146,7 @@ pub fn restore_key( mnemonic: &Path, key_name: &str, hdpath: &StandardHDPath, - config: &CosmosSdkConfig, + config: &CosmosChainConfig, overwrite: bool, ) -> eyre::Result { let mnemonic_content = @@ -155,7 +155,7 @@ pub fn restore_key( let mut keyring = KeyRing::new_secp256k1( Store::Test, &config.account_prefix, - &config.id, + &ChainId::from_string(&config.id), &config.key_store_folder, )?; @@ -164,7 +164,7 @@ pub fn restore_key( let key_pair = Secp256k1KeyPair::from_mnemonic( &mnemonic_content, hdpath, - &config.address_type, + &ibc_relayer::config::AddressType::Cosmos, keyring.account_prefix(), )?; diff --git a/crates/cli/cli/src/commands/keys/delete.rs b/crates/cli/cli/src/commands/keys/delete.rs index a3d1c7388..45fe8375f 100644 --- a/crates/cli/cli/src/commands/keys/delete.rs +++ b/crates/cli/cli/src/commands/keys/delete.rs @@ -1,7 +1,7 @@ use hermes_cli_components::traits::build::CanLoadBuilder; use hermes_cli_framework::command::CommandRunner; use hermes_cli_framework::output::Output; -use ibc_relayer::chain::cosmos::config::CosmosSdkConfig; +use hermes_cosmos_chain_components::impls::types::config::CosmosChainConfig; use ibc_relayer::keyring::{KeyRing, Store}; use ibc_relayer_types::core::ics24_host::identifier::ChainId; use oneline_eyre::eyre::{eyre, Context}; @@ -46,7 +46,7 @@ pub struct KeysDeleteCmd { } impl KeysDeleteCmd { - fn options(&self, config: &CosmosSdkConfig) -> eyre::Result> { + fn options(&self, config: &CosmosChainConfig) -> eyre::Result> { let id = match (self.all, &self.key_name) { (true, None) => KeysDeleteId::All, (false, Some(ref key_name)) => KeysDeleteId::Named(key_name), @@ -67,7 +67,7 @@ impl KeysDeleteCmd { #[derive(Clone, Debug)] struct KeysDeleteOptions<'a> { id: KeysDeleteId<'a>, - config: CosmosSdkConfig, + config: CosmosChainConfig, } #[derive(Clone, Debug)] @@ -118,11 +118,11 @@ impl CommandRunner for KeysDeleteCmd { } } -fn delete_key(config: &CosmosSdkConfig, key_name: &str) -> eyre::Result<()> { +fn delete_key(config: &CosmosChainConfig, key_name: &str) -> eyre::Result<()> { let mut keyring = KeyRing::new_secp256k1( Store::Test, &config.account_prefix, - &config.id, + &ChainId::from_string(&config.id), &config.key_store_folder, )?; @@ -131,11 +131,11 @@ fn delete_key(config: &CosmosSdkConfig, key_name: &str) -> eyre::Result<()> { Ok(()) } -fn delete_all_keys(config: &CosmosSdkConfig) -> eyre::Result<()> { +fn delete_all_keys(config: &CosmosChainConfig) -> eyre::Result<()> { let mut keyring = KeyRing::new_secp256k1( Store::Test, &config.account_prefix, - &config.id, + &ChainId::from_string(&config.id), &config.key_store_folder, )?; diff --git a/crates/cli/cli/src/commands/keys/list.rs b/crates/cli/cli/src/commands/keys/list.rs index dae45e11d..1de02011f 100644 --- a/crates/cli/cli/src/commands/keys/list.rs +++ b/crates/cli/cli/src/commands/keys/list.rs @@ -34,7 +34,7 @@ impl CommandRunner for KeysListCmd { let keyring = KeyRing::new_secp256k1( Store::Test, &chain_config.account_prefix, - &chain_config.id, + &ChainId::from_string(&chain_config.id), &chain_config.key_store_folder, )?; diff --git a/crates/cli/cli/src/commands/query/channel/client.rs b/crates/cli/cli/src/commands/query/channel/client.rs index 19671947c..32e02aa7c 100644 --- a/crates/cli/cli/src/commands/query/channel/client.rs +++ b/crates/cli/cli/src/commands/query/channel/client.rs @@ -2,6 +2,7 @@ use hermes_cli_components::traits::build::CanLoadBuilder; use hermes_cli_framework::command::CommandRunner; use hermes_cli_framework::output::Output; use hermes_cosmos_chain_components::traits::grpc_address::HasGrpcAddress; +use http::Uri; use ibc::core::channel::types::proto::v1::query_client::QueryClient; use ibc::core::channel::types::proto::v1::QueryChannelClientStateRequest; use ibc_relayer_types::core::ics24_host::identifier::{ChainId, ChannelId, PortId}; @@ -47,7 +48,8 @@ impl CommandRunner for QueryChannelClient { let channel_id = self.channel_id.clone(); let port_id = self.port_id.clone(); - let mut client = QueryClient::connect(chain.grpc_address().clone()).await?; + let mut client = + QueryClient::connect(Uri::try_from(&chain.grpc_address().to_string())?).await?; let request = tonic::Request::new(QueryChannelClientStateRequest { port_id: port_id.to_string(), diff --git a/crates/cli/cli/src/commands/query/channels.rs b/crates/cli/cli/src/commands/query/channels.rs index ea6c88671..fce350ebf 100644 --- a/crates/cli/cli/src/commands/query/channels.rs +++ b/crates/cli/cli/src/commands/query/channels.rs @@ -8,6 +8,7 @@ use hermes_cli_framework::output::{json, Output}; use hermes_cosmos_chain_components::traits::grpc_address::HasGrpcAddress; use hermes_cosmos_relayer::contexts::chain::CosmosChain; use hermes_relayer_components::chain::traits::queries::chain_status::CanQueryChainHeight; +use http::Uri; use ibc::core::channel::types::proto::v1::query_client::QueryClient; use ibc::core::channel::types::proto::v1::QueryChannelsRequest; use ibc_relayer_types::core::ics04_channel::channel::{IdentifiedChannelEnd, State}; @@ -52,7 +53,8 @@ impl CommandRunner for QueryChannels { let dst_chain_id = self.counterparty_chain_id.clone(); let show_counterparty = self.show_counterparty; - let mut client = QueryClient::connect(chain.grpc_address().clone()).await?; + let mut client = + QueryClient::connect(Uri::try_from(&chain.grpc_address().to_string())?).await?; let request = tonic::Request::new(QueryChannelsRequest { pagination: None }); diff --git a/crates/cli/cli/src/commands/query/connections.rs b/crates/cli/cli/src/commands/query/connections.rs index 68e28e4c8..935382e68 100644 --- a/crates/cli/cli/src/commands/query/connections.rs +++ b/crates/cli/cli/src/commands/query/connections.rs @@ -6,6 +6,7 @@ use hermes_cli_framework::output::{json, Output}; use hermes_cosmos_chain_components::traits::grpc_address::HasGrpcAddress; use hermes_cosmos_relayer::contexts::chain::CosmosChain; use hermes_relayer_components::chain::traits::queries::client_state::CanQueryClientStateWithLatestHeight; +use http::Uri; use ibc::core::connection::types::proto::v1::query_client::QueryClient; use ibc::core::connection::types::proto::v1::QueryConnectionsRequest; use ibc_relayer_types::core::ics02_client::client_state::ClientState; @@ -50,7 +51,8 @@ impl CommandRunner for QueryConnections { let counterparty_chain_id = self.counterparty_chain_id.clone(); let verbose = self.verbose; - let mut client = QueryClient::connect(chain.grpc_address().clone()).await?; + let mut client = + QueryClient::connect(Uri::try_from(&chain.grpc_address().to_string())?).await?; let request = tonic::Request::new(QueryConnectionsRequest { pagination: None }); diff --git a/crates/cli/cli/src/impls/build.rs b/crates/cli/cli/src/impls/build.rs index 99a063bc5..072bf65da 100644 --- a/crates/cli/cli/src/impls/build.rs +++ b/crates/cli/cli/src/impls/build.rs @@ -24,7 +24,7 @@ where .into_iter() .map(|config| { let ChainConfig::CosmosSdk(config) = config; - config + config.into() }) .collect(); diff --git a/crates/cli/cli/src/impls/error.rs b/crates/cli/cli/src/impls/error.rs index 39f8fed7d..38fefd4ed 100644 --- a/crates/cli/cli/src/impls/error.rs +++ b/crates/cli/cli/src/impls/error.rs @@ -19,6 +19,7 @@ use ibc_relayer_types::core::ics02_client::height::HeightError; use ibc_relayer_types::core::ics03_connection::error::Error as Ics03Error; use ibc_relayer_types::core::ics23_commitment::error::Error as Ics23Error; use ibc_relayer_types::core::ics24_host::error::ValidationError as Ics24ValidationError; +use tonic::transport::Error as TransportError; pub struct ProvideCliError; @@ -59,6 +60,7 @@ delegate_components! { Ics03Error, Ics23Error, Ics24ValidationError, + TransportError, ]: ReportError, [ <'a> &'a str, diff --git a/crates/cosmos/cosmos-chain-components/src/impls/queries/consensus_state_height.rs b/crates/cosmos/cosmos-chain-components/src/impls/queries/consensus_state_height.rs index 635b199f8..983820757 100644 --- a/crates/cosmos/cosmos-chain-components/src/impls/queries/consensus_state_height.rs +++ b/crates/cosmos/cosmos-chain-components/src/impls/queries/consensus_state_height.rs @@ -2,6 +2,8 @@ use cgp::core::error::CanRaiseError; use hermes_relayer_components::chain::traits::queries::consensus_state_height::ConsensusStateHeightsQuerier; use hermes_relayer_components::chain::traits::types::height::HasHeightType; use hermes_relayer_components::chain::traits::types::ibc::HasIbcChainTypes; +use http::uri::InvalidUri; +use http::Uri; use ibc_proto::ibc::core::client::v1::query_client::QueryClient; use ibc_relayer::chain::requests::QueryConsensusStateHeightsRequest; use ibc_relayer_types::core::ics24_host::identifier::ClientId; @@ -19,6 +21,7 @@ where Chain: HasIbcChainTypes + HasGrpcAddress + CanRaiseError + + CanRaiseError + CanRaiseError, Counterparty: HasHeightType, { @@ -26,10 +29,12 @@ where chain: &Chain, client_id: &ClientId, ) -> Result, Chain::Error> { - let mut client = QueryClient::connect(chain.grpc_address().clone()) - .await - .map_err(Chain::raise_error)? - .max_decoding_message_size(33554432); + let mut client = QueryClient::connect( + Uri::try_from(&chain.grpc_address().to_string()).map_err(Chain::raise_error)?, + ) + .await + .map_err(Chain::raise_error)? + .max_decoding_message_size(33554432); let request = QueryConsensusStateHeightsRequest { client_id: client_id.clone(), diff --git a/crates/cosmos/cosmos-chain-components/src/impls/queries/packet_acknowledgements.rs b/crates/cosmos/cosmos-chain-components/src/impls/queries/packet_acknowledgements.rs index f4ebb46ed..89835e52a 100644 --- a/crates/cosmos/cosmos-chain-components/src/impls/queries/packet_acknowledgements.rs +++ b/crates/cosmos/cosmos-chain-components/src/impls/queries/packet_acknowledgements.rs @@ -4,12 +4,16 @@ use cgp::core::error::CanRaiseError; use eyre::eyre; use hermes_relayer_components::chain::traits::queries::packet_acknowledgements::PacketAcknowledgementsQuerier; use hermes_relayer_components::chain::traits::types::ibc::HasIbcChainTypes; +use http::uri::InvalidUri; +use http::Uri; use ibc_proto::ibc::core::channel::v1::query_client::QueryClient as ChannelQueryClient; use ibc_relayer::chain::requests::{Paginate, QueryPacketAcknowledgementsRequest}; +use ibc_relayer_types::core::ics02_client::error::Error as Ics02Error; use ibc_relayer_types::core::ics04_channel::packet::Sequence; use ibc_relayer_types::core::ics24_host::identifier::{ChannelId, PortId}; use ibc_relayer_types::Height; -use tonic::Request; +use tonic::transport::Error as TransportError; +use tonic::{Request, Status}; use crate::traits::grpc_address::HasGrpcAddress; @@ -25,6 +29,10 @@ where ChannelId = ChannelId, Sequence = Sequence, > + HasGrpcAddress + + CanRaiseError + + CanRaiseError + + CanRaiseError + + CanRaiseError + CanRaiseError, Counterparty: HasIbcChainTypes, { @@ -34,9 +42,11 @@ where port_id: &Chain::PortId, sequences: &[Counterparty::Sequence], ) -> Result, Chain::Height)>, Chain::Error> { - let mut client = ChannelQueryClient::connect(chain.grpc_address().clone()) - .await - .map_err(|e| Chain::raise_error(e.into()))?; + let mut client = ChannelQueryClient::connect( + Uri::try_from(&chain.grpc_address().to_string()).map_err(Chain::raise_error)?, + ) + .await + .map_err(Chain::raise_error)?; let raw_request = QueryPacketAcknowledgementsRequest { port_id: port_id.clone(), @@ -50,7 +60,7 @@ where let response = client .packet_acknowledgements(request) .await - .map_err(|e| Chain::raise_error(e.into()))? + .map_err(Chain::raise_error)? .into_inner(); let commit_set = sequences.iter().cloned().collect::>(); @@ -68,7 +78,7 @@ where .height .ok_or_else(|| Chain::raise_error(eyre!("missing height in response")))?; - let height = Height::try_from(raw_height).map_err(|e| Chain::raise_error(e.into()))?; + let height = Height::try_from(raw_height).map_err(Chain::raise_error)?; Ok(Some((response_acks, height))) } diff --git a/crates/cosmos/cosmos-chain-components/src/impls/queries/packet_commitments.rs b/crates/cosmos/cosmos-chain-components/src/impls/queries/packet_commitments.rs index b281d6058..e9c60b563 100644 --- a/crates/cosmos/cosmos-chain-components/src/impls/queries/packet_commitments.rs +++ b/crates/cosmos/cosmos-chain-components/src/impls/queries/packet_commitments.rs @@ -2,12 +2,16 @@ use cgp::core::error::CanRaiseError; use eyre::eyre; use hermes_relayer_components::chain::traits::queries::packet_commitments::PacketCommitmentsQuerier; use hermes_relayer_components::chain::traits::types::ibc::HasIbcChainTypes; +use http::uri::InvalidUri; +use http::Uri; use ibc_proto::ibc::core::channel::v1::query_client::QueryClient as ChannelQueryClient; use ibc_relayer::chain::requests::{Paginate, QueryPacketCommitmentsRequest}; +use ibc_relayer_types::core::ics02_client::error::Error as Ics02Error; use ibc_relayer_types::core::ics04_channel::packet::Sequence; use ibc_relayer_types::core::ics24_host::identifier::{ChannelId, PortId}; use ibc_relayer_types::Height; -use tonic::Request; +use tonic::transport::Error as TransportError; +use tonic::{Request, Status}; use crate::traits::grpc_address::HasGrpcAddress; @@ -23,6 +27,10 @@ where ChannelId = ChannelId, Sequence = Sequence, > + HasGrpcAddress + + CanRaiseError + + CanRaiseError + + CanRaiseError + + CanRaiseError + CanRaiseError, { async fn query_packet_commitments( @@ -30,9 +38,11 @@ where channel_id: &Chain::ChannelId, port_id: &Chain::PortId, ) -> Result<(Vec, Chain::Height), Chain::Error> { - let mut client = ChannelQueryClient::connect(chain.grpc_address().clone()) - .await - .map_err(|e| Chain::raise_error(e.into()))?; + let mut client = ChannelQueryClient::connect( + Uri::try_from(&chain.grpc_address().to_string()).map_err(Chain::raise_error)?, + ) + .await + .map_err(Chain::raise_error)?; let raw_request = QueryPacketCommitmentsRequest { port_id: port_id.clone(), @@ -46,7 +56,7 @@ where let response = client .packet_commitments(request) .await - .map_err(|e| Chain::raise_error(e.into()))? + .map_err(Chain::raise_error)? .into_inner(); let commitment_sequences: Vec = response @@ -59,7 +69,7 @@ where .height .ok_or_else(|| Chain::raise_error(eyre!("missing height in response")))?; - let height = Height::try_from(raw_height).map_err(|e| Chain::raise_error(e.into()))?; + let height = Height::try_from(raw_height).map_err(Chain::raise_error)?; Ok((commitment_sequences, height)) } diff --git a/crates/cosmos/cosmos-chain-components/src/impls/queries/unreceived_acks.rs b/crates/cosmos/cosmos-chain-components/src/impls/queries/unreceived_acks.rs index 629f27fb6..c8b46703b 100644 --- a/crates/cosmos/cosmos-chain-components/src/impls/queries/unreceived_acks.rs +++ b/crates/cosmos/cosmos-chain-components/src/impls/queries/unreceived_acks.rs @@ -1,11 +1,14 @@ use cgp::core::error::{CanRaiseError, HasErrorType}; use hermes_relayer_components::chain::traits::queries::unreceived_acks_sequences::UnreceivedAcksSequencesQuerier; use hermes_relayer_components::chain::traits::types::ibc::HasIbcChainTypes; +use http::uri::InvalidUri; +use http::Uri; use ibc_proto::ibc::core::channel::v1::query_client::QueryClient as ChannelQueryClient; use ibc_relayer::chain::requests::QueryUnreceivedAcksRequest; use ibc_relayer_types::core::ics04_channel::packet::Sequence; use ibc_relayer_types::core::ics24_host::identifier::{ChannelId, PortId}; -use tonic::Request; +use tonic::transport::Error as TransportError; +use tonic::{Request, Status}; use crate::traits::grpc_address::HasGrpcAddress; @@ -17,6 +20,9 @@ where Chain: HasIbcChainTypes + HasErrorType + HasGrpcAddress + + CanRaiseError + + CanRaiseError + + CanRaiseError + CanRaiseError, Counterparty: HasIbcChainTypes, { @@ -26,9 +32,11 @@ where port_id: &Chain::PortId, sequences: &[Chain::Sequence], ) -> Result, Chain::Error> { - let mut client = ChannelQueryClient::connect(chain.grpc_address().clone()) - .await - .map_err(|e| Chain::raise_error(e.into()))?; + let mut client = ChannelQueryClient::connect( + Uri::try_from(&chain.grpc_address().to_string()).map_err(Chain::raise_error)?, + ) + .await + .map_err(Chain::raise_error)?; let raw_request = QueryUnreceivedAcksRequest { port_id: port_id.clone(), @@ -41,7 +49,7 @@ where let response = client .unreceived_acks(request) .await - .map_err(|e| Chain::raise_error(e.into()))? + .map_err(Chain::raise_error)? .into_inner(); let response_sequences = response.sequences.into_iter().map(|s| s.into()).collect(); diff --git a/crates/cosmos/cosmos-chain-components/src/impls/queries/unreceived_packet.rs b/crates/cosmos/cosmos-chain-components/src/impls/queries/unreceived_packet.rs index 58cf1ed5e..9df0ad851 100644 --- a/crates/cosmos/cosmos-chain-components/src/impls/queries/unreceived_packet.rs +++ b/crates/cosmos/cosmos-chain-components/src/impls/queries/unreceived_packet.rs @@ -1,11 +1,14 @@ use cgp::core::error::{CanRaiseError, HasErrorType}; use hermes_relayer_components::chain::traits::queries::unreceived_packet_sequences::UnreceivedPacketSequencesQuerier; use hermes_relayer_components::chain::traits::types::ibc::HasIbcChainTypes; +use http::uri::InvalidUri; +use http::Uri; use ibc_proto::ibc::core::channel::v1::query_client::QueryClient as ChannelQueryClient; use ibc_relayer::chain::requests::QueryUnreceivedPacketsRequest; use ibc_relayer_types::core::ics04_channel::packet::Sequence; use ibc_relayer_types::core::ics24_host::identifier::{ChannelId, PortId}; -use tonic::Request; +use tonic::transport::Error as TransportError; +use tonic::{Request, Status}; use crate::traits::grpc_address::HasGrpcAddress; @@ -17,6 +20,9 @@ where Chain: HasIbcChainTypes + HasErrorType + HasGrpcAddress + + CanRaiseError + + CanRaiseError + + CanRaiseError + CanRaiseError, Counterparty: HasIbcChainTypes, { @@ -26,9 +32,11 @@ where port_id: &Chain::PortId, sequences: &[Counterparty::Sequence], ) -> Result, Chain::Error> { - let mut client = ChannelQueryClient::connect(chain.grpc_address().clone()) - .await - .map_err(|e| Chain::raise_error(e.into()))?; + let mut client = ChannelQueryClient::connect( + Uri::try_from(&chain.grpc_address().to_string()).map_err(Chain::raise_error)?, + ) + .await + .map_err(Chain::raise_error)?; let raw_request = QueryUnreceivedPacketsRequest { port_id: port_id.clone(), @@ -41,7 +49,7 @@ where let response = client .unreceived_packets(request) .await - .map_err(|e| Chain::raise_error(e.into()))? + .map_err(Chain::raise_error)? .into_inner(); let response_sequences = response.sequences.into_iter().map(|s| s.into()).collect(); diff --git a/crates/cosmos/cosmos-chain-components/src/impls/transaction/estimate_fee.rs b/crates/cosmos/cosmos-chain-components/src/impls/transaction/estimate_fee.rs index cf7edaad5..37a7d31a2 100644 --- a/crates/cosmos/cosmos-chain-components/src/impls/transaction/estimate_fee.rs +++ b/crates/cosmos/cosmos-chain-components/src/impls/transaction/estimate_fee.rs @@ -3,6 +3,7 @@ use hermes_relayer_components::chain::traits::types::chain_id::HasChainId; use hermes_relayer_components::transaction::traits::estimate_tx_fee::TxFeeEstimator; use hermes_relayer_components::transaction::traits::types::fee::HasFeeType; use hermes_relayer_components::transaction::traits::types::transaction::HasTransactionType; +use http::uri::InvalidUri; use ibc_proto::cosmos::tx::v1beta1::service_client::ServiceClient; use ibc_proto::cosmos::tx::v1beta1::{Fee, SimulateRequest, SimulateResponse, Tx}; use ibc_relayer::chain::cosmos::types::tx::SignedTx; @@ -31,6 +32,7 @@ where + HasChainId + CanRaiseError + CanRaiseError + + CanRaiseError + CanConvertGasToFee + CanRaiseError<&'static str>, { @@ -48,10 +50,12 @@ where ..Default::default() }; - let mut client = ServiceClient::connect(chain.grpc_address().clone()) - .await - .map_err(Chain::raise_error)? - .max_decoding_message_size(max_grpc_decoding_size().get_bytes() as usize); + let mut client = ServiceClient::connect( + Uri::try_from(&chain.grpc_address().to_string()).map_err(Chain::raise_error)?, + ) + .await + .map_err(Chain::raise_error)? + .max_decoding_message_size(max_grpc_decoding_size().get_bytes() as usize); let response = client .simulate(request) diff --git a/crates/cosmos/cosmos-chain-components/src/impls/transaction/query_nonce.rs b/crates/cosmos/cosmos-chain-components/src/impls/transaction/query_nonce.rs index 3d5429eef..8f0c2ccef 100644 --- a/crates/cosmos/cosmos-chain-components/src/impls/transaction/query_nonce.rs +++ b/crates/cosmos/cosmos-chain-components/src/impls/transaction/query_nonce.rs @@ -2,6 +2,8 @@ use cgp::core::error::CanRaiseError; use hermes_relayer_components::transaction::traits::nonce::query_nonce::NonceQuerier; use hermes_relayer_components::transaction::traits::types::nonce::HasNonceType; use hermes_relayer_components::transaction::traits::types::signer::HasSignerType; +use http::uri::InvalidUri; +use http::Uri; use ibc_relayer::chain::cosmos::query::account::query_account; use ibc_relayer::chain::cosmos::types::account::Account; use ibc_relayer::error::Error as RelayerError; @@ -16,6 +18,7 @@ where Chain: HasSignerType + HasNonceType + HasGrpcAddress + + CanRaiseError + CanRaiseError, { async fn query_nonce( @@ -24,9 +27,12 @@ where ) -> Result { let address = key_pair.account(); - let account = query_account(chain.grpc_address(), &address) - .await - .map_err(Chain::raise_error)?; + let account = query_account( + &Uri::try_from(&chain.grpc_address().to_string()).map_err(Chain::raise_error)?, + &address, + ) + .await + .map_err(Chain::raise_error)?; Ok(account.into()) } diff --git a/crates/cosmos/cosmos-chain-components/src/impls/types/config.rs b/crates/cosmos/cosmos-chain-components/src/impls/types/config.rs new file mode 100644 index 000000000..54686638c --- /dev/null +++ b/crates/cosmos/cosmos-chain-components/src/impls/types/config.rs @@ -0,0 +1,123 @@ +use core::time::Duration; +use std::path::PathBuf; + +use ibc_proto::cosmos::base::v1beta1::Coin; +use ibc_proto::cosmos::tx::v1beta1::Fee; +use ibc_proto::google::protobuf::Any; +use ibc_relayer::chain::cosmos::config::CosmosSdkConfig; +use serde::{Deserialize, Serialize}; +use tendermint_rpc::Url; + +use crate::types::config::gas::dynamic_gas_config::DynamicGasConfig; +use crate::types::config::gas::gas_config::GasConfig; + +#[derive(Clone, Debug, Serialize, Deserialize)] +pub struct CosmosChainConfig { + pub id: String, + pub grpc_addr: Url, + pub account_prefix: String, + pub key_store_folder: Option, + pub key_name: String, + pub store_prefix: String, + pub event_source: EventSourceMode, + + pub clock_drift: Duration, + pub max_block_time: Duration, + + pub rpc_addr: Url, + pub rpc_timeout: Duration, + pub address_type: String, + pub max_msg_num: usize, + pub max_tx_size: usize, + + pub gas_config: GasConfig, + + pub compat_mode: Option, + pub extension_options: Vec, +} + +#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)] +#[serde(tag = "mode", rename_all = "lowercase")] +pub enum EventSourceMode { + Push { + url: String, + }, + + #[serde(alias = "poll")] + Pull, +} + +impl From for CosmosChainConfig { + fn from(value: CosmosSdkConfig) -> Self { + let event_source = match value.event_source { + ibc_relayer::config::EventSourceMode::Push { + url, + batch_delay: _, + } => EventSourceMode::Push { + url: url.to_string(), + }, + ibc_relayer::config::EventSourceMode::Pull { + interval: _, + max_retries: _, + } => EventSourceMode::Pull, + }; + let gas_multiplier = value.gas_multiplier.unwrap_or_default().to_f64(); + let fee_granter = value.fee_granter.unwrap_or("".to_owned()); + let max_gas = value.max_gas.unwrap_or(400_000); + let max_amount = (max_gas as f64 * gas_multiplier) * value.gas_price.price; + let max_gas_fee_in_coin = Coin { + denom: value.gas_price.denom.clone(), + amount: max_amount.to_string(), + }; + + let max_fee = Fee { + amount: vec![max_gas_fee_in_coin], + gas_limit: max_gas, + payer: "".to_string(), + granter: fee_granter.clone(), + }; + + let dynamic_gas = if value.dynamic_gas_price.enabled { + Some(DynamicGasConfig { + multiplier: value.dynamic_gas_price.multiplier, + max: value.dynamic_gas_price.max, + eip_query_type: Default::default(), + denom: value.gas_price.denom.clone(), + }) + } else { + None + }; + let gas_config = GasConfig { + default_gas: value.default_gas.unwrap_or(400_000), + max_gas, + gas_multiplier: value.gas_multiplier.unwrap_or_default().to_f64(), + gas_price: value.gas_price, + max_fee, + fee_granter, + dynamic_gas_config: dynamic_gas, + }; + let mut extension_options = vec![]; + for extension_option in value.extension_options.into_iter() { + extension_options.push(extension_option.to_any().unwrap()); + } + Self { + id: value.id.to_string(), + grpc_addr: value.grpc_addr, + account_prefix: value.account_prefix, + key_store_folder: value.key_store_folder, + key_name: value.key_name, + store_prefix: value.store_prefix, + event_source, + rpc_addr: value.rpc_addr, + rpc_timeout: value.rpc_timeout, + address_type: value.address_type.to_string(), + max_msg_num: value.max_msg_num.to_usize(), + max_tx_size: value.max_tx_size.to_usize(), + gas_config, + compat_mode: value.compat_mode.map(|compat_mode| compat_mode.to_string()), + extension_options, + clock_drift: value.clock_drift, + max_block_time: value.max_block_time, + } + } +} diff --git a/crates/cosmos/cosmos-chain-components/src/impls/types/mod.rs b/crates/cosmos/cosmos-chain-components/src/impls/types/mod.rs index 2ce4bcdeb..4be9389d8 100644 --- a/crates/cosmos/cosmos-chain-components/src/impls/types/mod.rs +++ b/crates/cosmos/cosmos-chain-components/src/impls/types/mod.rs @@ -1,5 +1,6 @@ pub mod chain; pub mod client_state; +pub mod config; pub mod consensus_state; pub mod create_client_options; pub mod payload; diff --git a/crates/cosmos/cosmos-chain-components/src/traits/grpc_address.rs b/crates/cosmos/cosmos-chain-components/src/traits/grpc_address.rs index 1ea26bb99..af3d05fcf 100644 --- a/crates/cosmos/cosmos-chain-components/src/traits/grpc_address.rs +++ b/crates/cosmos/cosmos-chain-components/src/traits/grpc_address.rs @@ -1,7 +1,7 @@ use cgp::prelude::*; -use http::Uri; +use tendermint_rpc::Url; #[derive_component(GrpcAddressGetterComponent, GrpcAddressGetter)] pub trait HasGrpcAddress: Async { - fn grpc_address(&self) -> &Uri; + fn grpc_address(&self) -> &Url; } diff --git a/crates/cosmos/cosmos-chain-components/src/types/config/gas/dynamic_gas_config.rs b/crates/cosmos/cosmos-chain-components/src/types/config/gas/dynamic_gas_config.rs index f46b8d319..858971764 100644 --- a/crates/cosmos/cosmos-chain-components/src/types/config/gas/dynamic_gas_config.rs +++ b/crates/cosmos/cosmos-chain-components/src/types/config/gas/dynamic_gas_config.rs @@ -1,6 +1,8 @@ +use serde::{Deserialize, Serialize}; + use crate::types::config::gas::eip_type::EipQueryType; -#[derive(Debug, Clone, PartialEq, PartialOrd)] +#[derive(Debug, Clone, PartialEq, PartialOrd, Serialize, Deserialize)] pub struct DynamicGasConfig { pub multiplier: f64, pub max: f64, diff --git a/crates/cosmos/cosmos-chain-components/src/types/config/gas/eip_type.rs b/crates/cosmos/cosmos-chain-components/src/types/config/gas/eip_type.rs index 776729a88..24eccf155 100644 --- a/crates/cosmos/cosmos-chain-components/src/types/config/gas/eip_type.rs +++ b/crates/cosmos/cosmos-chain-components/src/types/config/gas/eip_type.rs @@ -1,8 +1,9 @@ use core::str::FromStr; use eyre::Report; +use serde::{Deserialize, Serialize}; -#[derive(Clone, Debug, Default, PartialEq, PartialOrd)] +#[derive(Clone, Debug, Default, PartialEq, PartialOrd, Serialize, Deserialize)] pub enum EipQueryType { #[default] FeeMarket, diff --git a/crates/cosmos/cosmos-chain-components/src/types/config/gas/gas_config.rs b/crates/cosmos/cosmos-chain-components/src/types/config/gas/gas_config.rs index b56e2e5d3..d543658c3 100644 --- a/crates/cosmos/cosmos-chain-components/src/types/config/gas/gas_config.rs +++ b/crates/cosmos/cosmos-chain-components/src/types/config/gas/gas_config.rs @@ -1,14 +1,10 @@ use ibc_proto::cosmos::tx::v1beta1::Fee; -use ibc_relayer::chain::cosmos::config::CosmosSdkConfig; -use ibc_relayer::chain::cosmos::gas::calculate_fee; -use ibc_relayer::chain::cosmos::types::gas::{ - default_gas_from_config, gas_multiplier_from_config, max_gas_from_config, -}; use ibc_relayer::config::GasPrice; +use serde::{Deserialize, Serialize}; use crate::types::config::gas::dynamic_gas_config::DynamicGasConfig; -use crate::types::config::gas::eip_type::EipQueryType; +#[derive(Clone, Debug, Serialize, Deserialize)] pub struct GasConfig { pub default_gas: u64, pub max_gas: u64, @@ -18,53 +14,3 @@ pub struct GasConfig { pub fee_granter: String, pub dynamic_gas_config: Option, } - -impl<'a> From<&'a CosmosSdkConfig> for GasConfig { - fn from(config: &'a CosmosSdkConfig) -> Self { - let eip_query_type = if config.id.as_str().starts_with("osmo") { - EipQueryType::Osmosis - } else { - EipQueryType::FeeMarket - }; - let dynamic_gas_config = if config.dynamic_gas_price.enabled { - Some(DynamicGasConfig { - multiplier: config.dynamic_gas_price.multiplier, - max: config.dynamic_gas_price.max, - denom: config.gas_price.denom.clone(), - eip_query_type, - }) - } else { - None - }; - Self { - default_gas: default_gas_from_config(config), - max_gas: max_gas_from_config(config), - gas_multiplier: gas_multiplier_from_config(config), - gas_price: config.gas_price.clone(), - max_fee: max_fee_from_config(config), - fee_granter: fee_granter_from_config(config), - dynamic_gas_config, - } - } -} - -/// Get the fee granter address -fn fee_granter_from_config(config: &CosmosSdkConfig) -> String { - config.fee_granter.as_deref().unwrap_or("").to_string() -} - -fn max_fee_from_config(config: &CosmosSdkConfig) -> Fee { - let max_gas = max_gas_from_config(config); - - // The maximum fee the relayer pays for a transaction - let max_fee_in_coins = calculate_fee(max_gas, &config.gas_price); - - let fee_granter = fee_granter_from_config(config); - - Fee { - amount: vec![max_fee_in_coins], - gas_limit: max_gas, - payer: "".to_string(), - granter: fee_granter, - } -} diff --git a/crates/cosmos/cosmos-chain-components/src/types/config/mod.rs b/crates/cosmos/cosmos-chain-components/src/types/config/mod.rs index 06b2635f4..8826db296 100644 --- a/crates/cosmos/cosmos-chain-components/src/types/config/mod.rs +++ b/crates/cosmos/cosmos-chain-components/src/types/config/mod.rs @@ -1,2 +1 @@ pub mod gas; -pub mod tx_config; diff --git a/crates/cosmos/cosmos-chain-components/src/types/config/tx_config.rs b/crates/cosmos/cosmos-chain-components/src/types/config/tx_config.rs deleted file mode 100644 index 6f28ec036..000000000 --- a/crates/cosmos/cosmos-chain-components/src/types/config/tx_config.rs +++ /dev/null @@ -1,58 +0,0 @@ -use core::str::FromStr; -use core::time::Duration; - -use eyre::Report; -use http::Uri; -use ibc::primitives::proto::Any; -use ibc_relayer::chain::cosmos::config::CosmosSdkConfig; -use ibc_relayer::config::types::{MaxMsgNum, MaxTxSize}; -use ibc_relayer::config::AddressType; -use ibc_relayer_types::core::ics24_host::identifier::ChainId; -use tendermint_rpc::Url; - -use crate::types::config::gas::gas_config::GasConfig; - -pub struct TxConfig { - pub chain_id: ChainId, - pub gas_config: GasConfig, - pub rpc_address: Url, - pub grpc_address: Uri, - pub rpc_timeout: Duration, - pub address_type: AddressType, - pub max_msg_num: MaxMsgNum, - pub max_tx_size: MaxTxSize, - pub extension_options: Vec, -} - -impl<'a> TryFrom<&'a CosmosSdkConfig> for TxConfig { - type Error = Report; - - fn try_from(config: &'a CosmosSdkConfig) -> Result { - let grpc_address = Uri::from_str(&config.grpc_addr.to_string()).map_err(|e| { - Report::msg(format!( - "failed to create Uri from gRPC address string `{}`: {e}", - config.grpc_addr - )) - })?; - - let gas_config = GasConfig::from(config); - - let extension_options = config - .extension_options - .iter() - .map(|opt| opt.to_any()) - .collect::>()?; - - Ok(Self { - chain_id: config.id.clone(), - gas_config, - rpc_address: config.rpc_addr.clone(), - grpc_address, - rpc_timeout: config.rpc_timeout, - address_type: config.address_type.clone(), - max_msg_num: config.max_msg_num, - max_tx_size: config.max_tx_size, - extension_options, - }) - } -} diff --git a/crates/cosmos/cosmos-integration-tests/src/contexts/chain_driver.rs b/crates/cosmos/cosmos-integration-tests/src/contexts/chain_driver.rs index 0901055a6..fd521d8dc 100644 --- a/crates/cosmos/cosmos-integration-tests/src/contexts/chain_driver.rs +++ b/crates/cosmos/cosmos-integration-tests/src/contexts/chain_driver.rs @@ -33,7 +33,7 @@ use hermes_test_components::chain_driver::traits::fields::wallet::{ RelayerWallet, UserWallet, ValidatorWallet, WalletGetterAt, WalletsGetter, }; use hermes_test_components::chain_driver::traits::types::chain::{ChainGetter, ProvideChainType}; -use ibc_relayer::config::{ChainConfig, Config}; +use ibc_relayer::config::Config; use tokio::process::Child; use toml::to_string_pretty; @@ -189,13 +189,13 @@ impl ChainProcessTaker for CosmosChainDriverComponents { impl ConfigUpdater for CosmosChainDriverComponents { fn update_config( chain_driver: &CosmosChainDriver, - config: &mut Config, + _config: &mut Config, ) -> Result { let chain_config_str = to_string_pretty(&chain_driver.chain.chain_config)?; - let chain_config = chain_driver.chain.chain_config.clone(); + let _chain_config = chain_driver.chain.chain_config.clone(); - config.chains.push(ChainConfig::CosmosSdk(chain_config)); + //config.chains.push(ChainConfig::CosmosSdk(chain_config)); Ok(chain_config_str) } diff --git a/crates/cosmos/cosmos-integration-tests/src/impls/bootstrap/relayer_chain_config.rs b/crates/cosmos/cosmos-integration-tests/src/impls/bootstrap/relayer_chain_config.rs index fbe9f3e02..c9c03a62c 100644 --- a/crates/cosmos/cosmos-integration-tests/src/impls/bootstrap/relayer_chain_config.rs +++ b/crates/cosmos/cosmos-integration-tests/src/impls/bootstrap/relayer_chain_config.rs @@ -2,6 +2,7 @@ use core::str::FromStr; use core::time::Duration; use cgp::core::error::CanRaiseError; +use hermes_cosmos_chain_components::impls::types::config::CosmosChainConfig; use hermes_cosmos_test_components::bootstrap::traits::fields::account_prefix::HasAccountPrefix; use hermes_cosmos_test_components::bootstrap::traits::fields::dynamic_gas_fee::HasDynamicGas; use hermes_cosmos_test_components::bootstrap::traits::types::chain_node_config::HasChainNodeConfigType; @@ -39,7 +40,7 @@ where chain_node_config: &CosmosChainNodeConfig, chain_genesis_config: &CosmosGenesisConfig, relayer_wallet: &CosmosTestWallet, - ) -> Result { + ) -> Result { let dynamic_gas_price = if let Some(dynamic_gas_config) = bootstrap.dynamic_gas() { DynamicGasPrice::unsafe_new(true, dynamic_gas_config.multiplier, dynamic_gas_config.max) } else { @@ -97,6 +98,6 @@ where allow_ccq: false, }; - Ok(relayer_chain_config) + Ok(relayer_chain_config.into()) } } diff --git a/crates/cosmos/cosmos-integration-tests/src/traits/bootstrap/relayer_chain_config.rs b/crates/cosmos/cosmos-integration-tests/src/traits/bootstrap/relayer_chain_config.rs index 9096d9da8..131e4ab35 100644 --- a/crates/cosmos/cosmos-integration-tests/src/traits/bootstrap/relayer_chain_config.rs +++ b/crates/cosmos/cosmos-integration-tests/src/traits/bootstrap/relayer_chain_config.rs @@ -1,9 +1,9 @@ use cgp::prelude::*; +use hermes_cosmos_chain_components::impls::types::config::CosmosChainConfig; use hermes_cosmos_test_components::bootstrap::traits::types::chain_node_config::HasChainNodeConfigType; use hermes_cosmos_test_components::bootstrap::traits::types::genesis_config::HasChainGenesisConfigType; use hermes_test_components::chain::traits::types::wallet::{HasWalletType, WalletOf}; use hermes_test_components::chain_driver::traits::types::chain::HasChainType; -use ibc_relayer::chain::cosmos::config::CosmosSdkConfig; /** Capability for the bootstrap context to build a Hermes v1 relayer chain config. @@ -19,5 +19,5 @@ where chain_node_config: &Self::ChainNodeConfig, chain_genesis_config: &Self::ChainGenesisConfig, relayer_wallet: &WalletOf, - ) -> Result; + ) -> Result; } diff --git a/crates/cosmos/cosmos-relayer/src/contexts/build.rs b/crates/cosmos/cosmos-relayer/src/contexts/build.rs index 432d9a2ba..eb10aabbf 100644 --- a/crates/cosmos/cosmos-relayer/src/contexts/build.rs +++ b/crates/cosmos/cosmos-relayer/src/contexts/build.rs @@ -4,12 +4,13 @@ use core::marker::PhantomData; use core::ops::Deref; use std::collections::HashMap; use std::fs::{self, File}; +use std::str::FromStr; use cgp::core::error::{ErrorRaiserComponent, ErrorTypeComponent}; use cgp::prelude::*; use eyre::eyre; use futures::lock::Mutex; -use hermes_cosmos_chain_components::types::config::tx_config::TxConfig; +use hermes_cosmos_chain_components::impls::types::config::CosmosChainConfig; use hermes_error::types::Error; use hermes_relayer_components::build::traits::builders::birelay_from_relay_builder::BiRelayFromRelayBuilder; use hermes_relayer_components::build::traits::builders::chain_builder::ChainBuilder; @@ -27,7 +28,6 @@ use hermes_runtime::types::runtime::HermesRuntime; use hermes_runtime_components::traits::runtime::{ ProvideDefaultRuntimeField, RuntimeGetterComponent, RuntimeTypeComponent, }; -use ibc_relayer::chain::cosmos::config::CosmosSdkConfig; use ibc_relayer::config::filter::PacketFilter; use ibc_relayer::keyring::{ AnySigningKeyPair, Secp256k1KeyPair, KEYSTORE_DEFAULT_FOLDER, KEYSTORE_FILE_EXTENSION, @@ -59,7 +59,7 @@ impl Deref for CosmosBuilder { #[derive(HasField)] pub struct CosmosBuilderFields { - pub config_map: HashMap, + pub config_map: HashMap, pub packet_filter: PacketFilter, pub telemetry: CosmosTelemetry, pub runtime: HermesRuntime, @@ -141,7 +141,7 @@ impl CosmosBuilder { } pub fn new( - chain_configs: Vec, + chain_configs: Vec, runtime: HermesRuntime, telemetry: CosmosTelemetry, packet_filter: PacketFilter, @@ -151,7 +151,7 @@ impl CosmosBuilder { let config_map = HashMap::from_iter( chain_configs .into_iter() - .map(|config| (config.id.clone(), config)), + .map(|config| (ChainId::from_string(&config.id), config)), ); Self { @@ -182,19 +182,19 @@ impl CosmosBuilder { pub async fn build_chain_with_config( &self, - chain_config: CosmosSdkConfig, + chain_config: CosmosChainConfig, m_keypair: Option<&Secp256k1KeyPair>, ) -> Result { let key = get_keypair(&chain_config, m_keypair)?; let event_source_mode = chain_config.event_source.clone(); - let tx_config = TxConfig::try_from(&chain_config)?; + //let tx_config = TxConfig::try_from(&chain_config)?; - let mut rpc_client = HttpClient::new(tx_config.rpc_address.clone())?; + let mut rpc_client = HttpClient::new(chain_config.rpc_addr.clone())?; let compat_mode = if let Some(compat_mode) = &chain_config.compat_mode { - *compat_mode + CompatMode::from_str(compat_mode.as_str()).unwrap() } else { let status = rpc_client.status().await?; @@ -205,7 +205,6 @@ impl CosmosBuilder { let context = CosmosChain::new( chain_config, - tx_config, rpc_client, compat_mode, key, @@ -242,7 +241,7 @@ impl CosmosBuilder { } pub fn get_keypair( - chain_config: &CosmosSdkConfig, + chain_config: &CosmosChainConfig, m_keypair: Option<&Secp256k1KeyPair>, ) -> Result { let ks_folder = &chain_config.key_store_folder; diff --git a/crates/cosmos/cosmos-relayer/src/contexts/chain.rs b/crates/cosmos/cosmos-relayer/src/contexts/chain.rs index 00be10d42..468082e1f 100644 --- a/crates/cosmos/cosmos-relayer/src/contexts/chain.rs +++ b/crates/cosmos/cosmos-relayer/src/contexts/chain.rs @@ -1,5 +1,6 @@ use alloc::sync::Arc; use core::ops::Deref; +use std::str::FromStr; use cgp::core::error::{ErrorRaiserComponent, ErrorTypeComponent}; use cgp::prelude::*; @@ -14,6 +15,7 @@ use hermes_cosmos_chain_components::components::client::*; use hermes_cosmos_chain_components::components::cosmos_to_cosmos::CosmosToCosmosComponents; use hermes_cosmos_chain_components::components::delegate::DelegateCosmosChainComponents; use hermes_cosmos_chain_components::components::transaction::*; +use hermes_cosmos_chain_components::impls::types::config::{CosmosChainConfig, EventSourceMode}; use hermes_cosmos_chain_components::traits::convert_gas_to_fee::CanConvertGasToFee; use hermes_cosmos_chain_components::traits::eip::eip_query::CanQueryEipBaseFee; use hermes_cosmos_chain_components::traits::gas_config::GasConfigGetter; @@ -23,7 +25,6 @@ use hermes_cosmos_chain_components::traits::tx_extension_options::TxExtensionOpt use hermes_cosmos_chain_components::traits::unbonding_period::CanQueryUnbondingPeriod; use hermes_cosmos_chain_components::types::commitment_proof::CosmosCommitmentProof; use hermes_cosmos_chain_components::types::config::gas::gas_config::GasConfig; -use hermes_cosmos_chain_components::types::config::tx_config::TxConfig; use hermes_cosmos_chain_components::types::nonce_guard::NonceGuard; use hermes_cosmos_chain_components::types::payloads::client::{ CosmosCreateClientOptions, CosmosCreateClientPayload, CosmosUpdateClientPayload, @@ -97,12 +98,9 @@ use hermes_wasm_test_components::traits::chain::messages::store_code::StoreCodeM use hermes_wasm_test_components::traits::chain::upload_client_code::{ CanUploadWasmClientCode, WasmClientCodeUploaderComponent, }; -use http::Uri; use ibc::core::channel::types::channel::ChannelEnd; use ibc_proto::cosmos::tx::v1beta1::Fee; -use ibc_relayer::chain::cosmos::config::CosmosSdkConfig; use ibc_relayer::chain::cosmos::types::account::Account; -use ibc_relayer::config::EventSourceMode; use ibc_relayer::event::source::queries::all as all_queries; use ibc_relayer::keyring::Secp256k1KeyPair; use ibc_relayer_types::core::ics02_client::height::Height; @@ -110,7 +108,7 @@ use ibc_relayer_types::core::ics24_host::identifier::ChainId; use prost_types::Any; use tendermint::abci::Event as AbciEvent; use tendermint_rpc::client::CompatMode; -use tendermint_rpc::{HttpClient, Url}; +use tendermint_rpc::{HttpClient, Url, WebSocketClientUrl}; use crate::contexts::encoding::ProvideCosmosEncoding; use crate::impls::error::HandleCosmosError; @@ -124,13 +122,12 @@ pub struct CosmosChain { #[derive(HasField)] pub struct BaseCosmosChain { - pub chain_config: CosmosSdkConfig, + pub chain_config: CosmosChainConfig, pub chain_id: ChainId, pub compat_mode: CompatMode, pub runtime: HermesRuntime, pub telemetry: CosmosTelemetry, pub subscription: Arc)>>, - pub tx_config: TxConfig, pub ibc_commitment_prefix: Vec, pub rpc_client: HttpClient, pub key_entry: Secp256k1KeyPair, @@ -216,13 +213,13 @@ delegate_components! { impl TxExtensionOptionsGetter for CosmosChainContextComponents { fn tx_extension_options(chain: &CosmosChain) -> &Vec { - &chain.tx_config.extension_options + &chain.chain_config.extension_options } } impl GasConfigGetter for CosmosChainContextComponents { fn gas_config(chain: &CosmosChain) -> &GasConfig { - &chain.tx_config.gas_config + &chain.chain_config.gas_config } } @@ -234,7 +231,7 @@ impl DefaultSignerGetter for CosmosChainContextComponents { impl FeeForSimulationGetter for CosmosChainContextComponents { fn fee_for_simulation(chain: &CosmosChain) -> &Fee { - &chain.tx_config.gas_config.max_fee + &chain.chain_config.gas_config.max_fee } } @@ -265,8 +262,7 @@ impl IbcCommitmentPrefixGetter for CosmosChainContextComponents { impl CosmosChain { pub fn new( - chain_config: CosmosSdkConfig, - tx_config: TxConfig, + chain_config: CosmosChainConfig, rpc_client: HttpClient, compat_mode: CompatMode, key_entry: Secp256k1KeyPair, @@ -274,22 +270,22 @@ impl CosmosChain { runtime: HermesRuntime, telemetry: CosmosTelemetry, ) -> Self { - let chain_version = tx_config.chain_id.version(); + let chain_id = ChainId::from_string(&chain_config.id); + let chain_version = chain_id.version(); let subscription = match event_source_mode { - EventSourceMode::Push { - url, - batch_delay: _, - } => { - runtime.new_abci_event_subscription(chain_version, url, compat_mode, all_queries()) - } + EventSourceMode::Push { url } => runtime.new_abci_event_subscription( + chain_version, + WebSocketClientUrl::from_str(&url).unwrap(), + compat_mode, + all_queries(), + ), EventSourceMode::Pull { .. } => { // TODO: implement pull-based event source Arc::new(EmptySubscription::new()) } }; - let chain_id = tx_config.chain_id.clone(); let ibc_commitment_prefix = chain_config.store_prefix.clone().into(); let chain = Self { @@ -300,7 +296,6 @@ impl CosmosChain { runtime, telemetry, subscription, - tx_config, ibc_commitment_prefix, rpc_client, key_entry, @@ -321,8 +316,8 @@ impl HasTelemetry for CosmosChain { } impl GrpcAddressGetter for CosmosChainContextComponents { - fn grpc_address(chain: &CosmosChain) -> &Uri { - &chain.tx_config.grpc_address + fn grpc_address(chain: &CosmosChain) -> &Url { + &chain.chain_config.grpc_addr } } @@ -332,7 +327,7 @@ impl RpcClientGetter for CosmosChainContextComponents { } fn rpc_address(chain: &CosmosChain) -> &Url { - &chain.tx_config.rpc_address + &chain.chain_config.rpc_addr } } diff --git a/crates/cosmos/cosmos-relayer/src/impls/error.rs b/crates/cosmos/cosmos-relayer/src/impls/error.rs index 71b8342dc..e9162aafb 100644 --- a/crates/cosmos/cosmos-relayer/src/impls/error.rs +++ b/crates/cosmos/cosmos-relayer/src/impls/error.rs @@ -52,6 +52,7 @@ use hermes_test_components::chain::impls::ibc_transfer::MissingSendPacketEventEr use hermes_test_components::chain::traits::types::address::HasAddressType; use hermes_test_components::chain::traits::types::amount::HasAmountType; use hermes_wasm_test_components::impls::chain::upload_client_code::ProposalIdNotFound; +use http::uri::InvalidUri; use ibc::core::client::types::error::ClientError; use ibc::core::commitment_types::error::CommitmentError; use ibc::core::host::types::error::DecodingError; @@ -145,6 +146,7 @@ delegate_components! { TryFromSliceError, subtle_encoding::Error, reqwest::Error, + InvalidUri, // TODO: make it retryable? TransportError, diff --git a/crates/cosmos/cosmos-test-components/Cargo.toml b/crates/cosmos/cosmos-test-components/Cargo.toml index feee46ff8..697d5490d 100644 --- a/crates/cosmos/cosmos-test-components/Cargo.toml +++ b/crates/cosmos/cosmos-test-components/Cargo.toml @@ -23,6 +23,7 @@ ibc-relayer = { workspace = true } ibc-relayer-types = { workspace = true } ibc-proto = { workspace = true } +http = { workspace = true } itertools = { workspace = true } serde = { workspace = true } serde_json = { workspace = true } diff --git a/crates/cosmos/cosmos-test-components/src/chain/impls/proposal/query_status.rs b/crates/cosmos/cosmos-test-components/src/chain/impls/proposal/query_status.rs index 5a0785f2c..771943398 100644 --- a/crates/cosmos/cosmos-test-components/src/chain/impls/proposal/query_status.rs +++ b/crates/cosmos/cosmos-test-components/src/chain/impls/proposal/query_status.rs @@ -5,6 +5,8 @@ use hermes_cosmos_chain_components::traits::grpc_address::HasGrpcAddress; use hermes_test_components::chain::traits::proposal::query_status::ProposalStatusQuerier; use hermes_test_components::chain::traits::proposal::types::proposal_id::HasProposalIdType; use hermes_test_components::chain::traits::proposal::types::proposal_status::HasProposalStatusType; +use http::uri::InvalidUri; +use http::Uri; use ibc_proto::cosmos::gov::v1::query_client::QueryClient; use ibc_proto::cosmos::gov::v1::{Proposal, QueryProposalRequest}; use tonic::transport::Error as TransportError; @@ -24,6 +26,7 @@ where Chain: HasProposalIdType + HasProposalStatusType + HasGrpcAddress + + CanRaiseError + CanRaiseError + CanRaiseError + CanRaiseError @@ -33,11 +36,11 @@ where chain: &Chain, proposal_id: &u64, ) -> Result { - let grpc_address = chain.grpc_address(); - - let mut client = QueryClient::connect(grpc_address.clone()) - .await - .map_err(Chain::raise_error)?; + let mut client = QueryClient::connect( + Uri::try_from(&chain.grpc_address().to_string()).map_err(Chain::raise_error)?, + ) + .await + .map_err(Chain::raise_error)?; let request = tonic::Request::new(QueryProposalRequest { proposal_id: *proposal_id, diff --git a/crates/cosmos/cosmos-test-components/src/chain/impls/queries/balance.rs b/crates/cosmos/cosmos-test-components/src/chain/impls/queries/balance.rs index 9569b01db..59085a1d2 100644 --- a/crates/cosmos/cosmos-test-components/src/chain/impls/queries/balance.rs +++ b/crates/cosmos/cosmos-test-components/src/chain/impls/queries/balance.rs @@ -5,6 +5,8 @@ use hermes_cosmos_chain_components::traits::grpc_address::HasGrpcAddress; use hermes_test_components::chain::traits::queries::balance::BalanceQuerier; use hermes_test_components::chain::traits::types::address::HasAddressType; use hermes_test_components::chain::traits::types::amount::HasAmountType; +use http::uri::InvalidUri; +use http::Uri; use ibc_relayer::chain::cosmos::query::balance::query_balance; use ibc_relayer::error::Error as RelayerError; @@ -19,6 +21,7 @@ where + HasAmountType + HasGrpcAddress + CanRaiseError + + CanRaiseError + CanRaiseError, { async fn query_balance( @@ -26,12 +29,15 @@ where address: &Chain::Address, denom: &Denom, ) -> Result { - let grpc_address = chain.grpc_address(); let denom_str = denom.to_string(); - let balance = query_balance(grpc_address, &address.to_string(), &denom_str) - .await - .map_err(Chain::raise_error)?; + let balance = query_balance( + &Uri::try_from(&chain.grpc_address().to_string()).map_err(Chain::raise_error)?, + &address.to_string(), + &denom_str, + ) + .await + .map_err(Chain::raise_error)?; let quantity = balance.amount.parse().map_err(Chain::raise_error)?; diff --git a/crates/cosmos/cosmos-wasm-relayer/src/context/chain.rs b/crates/cosmos/cosmos-wasm-relayer/src/context/chain.rs index 49930a0e5..8d159b6a6 100644 --- a/crates/cosmos/cosmos-wasm-relayer/src/context/chain.rs +++ b/crates/cosmos/cosmos-wasm-relayer/src/context/chain.rs @@ -227,7 +227,6 @@ use hermes_wasm_test_components::traits::chain::messages::store_code::StoreCodeM use hermes_wasm_test_components::traits::chain::upload_client_code::{ CanUploadWasmClientCode, WasmClientCodeUploaderComponent, }; -use http::Uri; use ibc::core::channel::types::channel::ChannelEnd; use ibc_proto::cosmos::tx::v1beta1::Fee; use ibc_relayer::chain::cosmos::types::account::Account; @@ -475,13 +474,13 @@ delegate_components! { impl TxExtensionOptionsGetter for WasmCosmosChainComponents { fn tx_extension_options(chain: &WasmCosmosChain) -> &Vec { - &chain.tx_config.extension_options + &chain.chain_config.extension_options } } impl GasConfigGetter for WasmCosmosChainComponents { fn gas_config(chain: &WasmCosmosChain) -> &GasConfig { - &chain.tx_config.gas_config + &chain.chain_config.gas_config } } @@ -493,7 +492,7 @@ impl DefaultSignerGetter for WasmCosmosChainComponents { impl FeeForSimulationGetter for WasmCosmosChainComponents { fn fee_for_simulation(chain: &WasmCosmosChain) -> &Fee { - &chain.tx_config.gas_config.max_fee + &chain.chain_config.gas_config.max_fee } } @@ -523,8 +522,8 @@ impl IbcCommitmentPrefixGetter for WasmCosmosChainComponents { } impl GrpcAddressGetter for WasmCosmosChainComponents { - fn grpc_address(chain: &WasmCosmosChain) -> &Uri { - &chain.tx_config.grpc_address + fn grpc_address(chain: &WasmCosmosChain) -> &Url { + &chain.chain_config.grpc_addr } } @@ -534,7 +533,7 @@ impl RpcClientGetter for WasmCosmosChainComponents { } fn rpc_address(chain: &WasmCosmosChain) -> &Url { - &chain.tx_config.rpc_address + &chain.chain_config.rpc_addr } } diff --git a/tools/integration-test/src/tests/context.rs b/tools/integration-test/src/tests/context.rs index a8709c97f..0f0c0c83c 100644 --- a/tools/integration-test/src/tests/context.rs +++ b/tools/integration-test/src/tests/context.rs @@ -1,5 +1,6 @@ use std::collections::HashMap; +use hermes_cosmos_chain_components::impls::types::config::CosmosChainConfig; use hermes_cosmos_relayer::contexts::birelay::CosmosBiRelay; use hermes_cosmos_relayer::contexts::build::CosmosBuilder; use hermes_relayer_components::build::traits::builders::birelay_builder::CanBuildBiRelay; @@ -36,7 +37,7 @@ where .iter() .map(|config| { let ChainConfig::CosmosSdk(config) = config; - config.clone() + CosmosChainConfig::from(config.clone()) }) .collect();