From 0e86a9c8c8a4630efd218dcf6e42c6604cd95aa2 Mon Sep 17 00:00:00 2001 From: Jun Kimura Date: Mon, 7 Aug 2023 15:21:01 +0900 Subject: [PATCH 1/3] move relay-tendermint crate into integration test Signed-off-by: Jun Kimura --- Cargo.lock | 19 +- Cargo.toml | 1 - modules/relay/tendermint/Cargo.toml | 16 -- modules/relay/tendermint/src/lib.rs | 4 - modules/relay/tendermint/src/relay.rs | 177 -------------- tests/integration/Cargo.toml | 5 +- tests/integration/src/config.rs | 71 ++++++ tests/integration/src/lib.rs | 9 +- tests/integration/src/relayer.rs | 226 +++++++++++++----- .../integration}/src/types.rs | 0 10 files changed, 249 insertions(+), 279 deletions(-) delete mode 100644 modules/relay/tendermint/Cargo.toml delete mode 100644 modules/relay/tendermint/src/lib.rs delete mode 100644 modules/relay/tendermint/src/relay.rs create mode 100644 tests/integration/src/config.rs rename {modules/relay/tendermint => tests/integration}/src/types.rs (100%) diff --git a/Cargo.lock b/Cargo.lock index 02f58e5d..922dda5f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2457,8 +2457,10 @@ dependencies = [ "host", "host-environment", "ibc", + "ibc-proto 0.24.1", "ibc-proto 0.26.0", "ibc-relayer", + "ibc-relayer-types", "ibc-test-framework", "keymanager", "lcp-types", @@ -2466,7 +2468,6 @@ dependencies = [ "ocall-handler", "once_cell", "prost-types", - "relay-tendermint", "store", "tempfile", "tendermint-light-client-verifier 0.28.0", @@ -3822,22 +3823,6 @@ version = "0.6.27" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a3f87b73ce11b1619a3c6332f45341e0047173771e8b8b73f87bfeefb7b56244" -[[package]] -name = "relay-tendermint" -version = "0.1.0" -dependencies = [ - "anyhow", - "ibc", - "ibc-proto 0.24.1", - "ibc-proto 0.26.0", - "ibc-relayer", - "ibc-relayer-types", - "lcp-types", - "tendermint-light-client-verifier 0.28.0", - "tendermint-rpc", - "tokio", -] - [[package]] name = "reqwest" version = "0.11.14" diff --git a/Cargo.toml b/Cargo.toml index 329d399b..8d6787b4 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -22,7 +22,6 @@ members = [ "modules/tendermint-lc", "modules/mock-lc", "modules/service", - "modules/relay/tendermint", "proto", "tests/integration", "tools/nodes-runner", diff --git a/modules/relay/tendermint/Cargo.toml b/modules/relay/tendermint/Cargo.toml deleted file mode 100644 index 0cc54e03..00000000 --- a/modules/relay/tendermint/Cargo.toml +++ /dev/null @@ -1,16 +0,0 @@ -[package] -name = "relay-tendermint" -version = "0.1.0" -edition = "2021" - -[dependencies] -ibc = { version = "0.29.0", default-features = false, features = ["serde"] } -ibc-proto = { version = "0.26.0", default-features = false, features = ["parity-scale-codec", "borsh"] } -ibc-proto-relayer = { package = "ibc-proto", version = "0.24.1", default-features = false } -ibc-relayer = "0.22.0" -ibc-relayer-types = "0.22.0" -tendermint-rpc = { version = "0.28", default-features = false } -tendermint-light-client-verifier = { version = "0.28", default-features = false } -anyhow = { version = "1.0.56" } -tokio = { version = "1.0" } -lcp-types = { path = "../../types" } diff --git a/modules/relay/tendermint/src/lib.rs b/modules/relay/tendermint/src/lib.rs deleted file mode 100644 index 7930b7eb..00000000 --- a/modules/relay/tendermint/src/lib.rs +++ /dev/null @@ -1,4 +0,0 @@ -pub use relay::Relayer; - -pub mod relay; -pub mod types; diff --git a/modules/relay/tendermint/src/relay.rs b/modules/relay/tendermint/src/relay.rs deleted file mode 100644 index 21e39bdd..00000000 --- a/modules/relay/tendermint/src/relay.rs +++ /dev/null @@ -1,177 +0,0 @@ -use crate::types::{ - relayer_header_to_any, to_ibc_channel, to_ibc_client_state, to_ibc_connection, - to_ibc_consensus_state, to_ibc_height, to_relayer_channel_id, to_relayer_client_state, - to_relayer_connection_id, to_relayer_height, to_relayer_port_id, to_relayer_sequence, -}; -use anyhow::Result; -use ibc::clients::ics07_tendermint::client_state::ClientState; -use ibc::clients::ics07_tendermint::consensus_state::ConsensusState; -use ibc::core::ics03_connection::connection::ConnectionEnd; -use ibc::core::ics04_channel::channel::ChannelEnd; -use ibc::core::ics04_channel::commitment::PacketCommitment; -use ibc::core::ics04_channel::packet::Sequence; -use ibc::core::ics23_commitment::merkle::MerkleProof; -use ibc::core::ics24_host::identifier::{ChannelId, ConnectionId, PortId}; -use ibc::Height; -use ibc_proto::google::protobuf::Any as IBCAny; -use ibc_relayer::chain::requests::QueryConnectionRequest; -use ibc_relayer::chain::{ - client::ClientSettings, - cosmos::{client::Settings, CosmosSdkChain}, - endpoint::ChainEndpoint, - requests::{IncludeProof, QueryChannelRequest, QueryHeight, QueryPacketCommitmentRequest}, -}; -use ibc_relayer::client_state::AnyClientState; -use ibc_relayer::config::ChainConfig; -use ibc_relayer::light_client::tendermint::LightClient as TmLightClient; -use ibc_relayer::light_client::{tendermint::LightClient, LightClient as IBCLightClient}; -use lcp_types::Any; -use std::sync::Arc; -use tendermint_rpc::{Client, HttpClient}; -use tokio::runtime::Runtime as TokioRuntime; - -pub struct Relayer { - tmlc: LightClient, - chain: CosmosSdkChain, - - client_state: Option, -} - -/// Initialize the light client for the given chain using the given HTTP client -/// to fetch the node identifier to be used as peer id in the light client. -async fn init_light_client(rpc_client: &HttpClient, config: &ChainConfig) -> TmLightClient { - use tendermint_light_client_verifier::types::PeerId; - - let peer_id: PeerId = rpc_client.status().await.map(|s| s.node_info.id).unwrap(); - TmLightClient::from_config(config, peer_id).unwrap() -} - -impl Relayer { - pub fn new(cc: ChainConfig, rt: Arc) -> Result { - let chain = CosmosSdkChain::bootstrap(cc.clone(), rt.clone()).unwrap(); - let rpc_client = HttpClient::new(cc.rpc_addr.clone()).unwrap(); - let tmlc = rt.block_on(init_light_client(&rpc_client, &cc)); - Ok(Self { - tmlc, - chain, - client_state: None, - }) - } - - pub fn create_header(&mut self, trusted_height: Height, target_height: Height) -> Result { - let (target, supporting) = self.chain.build_header( - to_relayer_height(trusted_height), - to_relayer_height(target_height), - &AnyClientState::Tendermint(to_relayer_client_state( - self.client_state.clone().unwrap(), - )), - )?; - assert!(supporting.is_empty()); - Ok(relayer_header_to_any(target)) - } - - pub fn fetch_state(&mut self, height: Height) -> Result<(ClientState, ConsensusState)> { - let height = to_relayer_height(height); - let block = self.tmlc.fetch(height)?; - let config = self.chain.config(); - let client_state = to_ibc_client_state(self.chain.build_client_state( - height, - ClientSettings::Tendermint(Settings { - max_clock_drift: config.clock_drift, - trusting_period: config.trusting_period, - trust_threshold: config.trust_threshold.into(), - }), - )?); - let consensus_state = to_ibc_consensus_state(self.chain.build_consensus_state(block)?); - self.client_state = Some(client_state.clone()); - Ok((client_state, consensus_state)) - } - - pub fn fetch_state_as_any(&mut self, height: Height) -> Result<(Any, Any)> { - let (client_state, consensus_state) = self.fetch_state(height)?; - let any_client_state = IBCAny::from(client_state); - let any_consensus_state = IBCAny::from(consensus_state); - Ok((any_client_state.into(), any_consensus_state.into())) - } - - pub fn query_latest_height(&self) -> Result { - Ok(to_ibc_height(self.chain.query_chain_latest_height()?)) - } - - pub fn query_connection_proof( - &self, - connection_id: ConnectionId, - height: Option, // height of consensus state - ) -> Result<(ConnectionEnd, MerkleProof, Height)> { - let height = match height { - Some(height) => height.decrement().unwrap(), - None => self.query_latest_height()?.decrement().unwrap(), - }; - let req = QueryConnectionRequest { - connection_id: to_relayer_connection_id(connection_id), - height: QueryHeight::Specific(to_relayer_height(height)), - }; - let res = self.chain.query_connection(req, IncludeProof::Yes)?; - Ok(( - to_ibc_connection(res.0), - MerkleProof { - proofs: res.1.unwrap().proofs, - }, - height.increment(), - )) - } - - pub fn query_channel_proof( - &self, - port_id: PortId, - channel_id: ChannelId, - height: Option, // height of consensus state - ) -> Result<(ChannelEnd, MerkleProof, Height)> { - let height = match height { - Some(height) => height.decrement().unwrap(), - None => self.query_latest_height()?.decrement().unwrap(), - }; - let req = QueryChannelRequest { - port_id: to_relayer_port_id(port_id), - channel_id: to_relayer_channel_id(channel_id), - height: QueryHeight::Specific(to_relayer_height(height)), - }; - let res = self.chain.query_channel(req, IncludeProof::Yes)?; - Ok(( - to_ibc_channel(res.0), - MerkleProof { - proofs: res.1.unwrap().proofs, - }, - height.increment(), - )) - } - - pub fn query_packet_proof( - &self, - port_id: PortId, - channel_id: ChannelId, - sequence: Sequence, - height: Option, // height of consensus state - ) -> Result<(PacketCommitment, MerkleProof, Height)> { - let height = match height { - Some(height) => height.decrement().unwrap(), - None => self.query_latest_height()?.decrement().unwrap(), - }; - let res = self.chain.query_packet_commitment( - QueryPacketCommitmentRequest { - port_id: to_relayer_port_id(port_id), - channel_id: to_relayer_channel_id(channel_id), - sequence: to_relayer_sequence(sequence), - height: QueryHeight::Specific(to_relayer_height(height)), - }, - IncludeProof::Yes, - )?; - Ok(( - res.0.into(), - MerkleProof { - proofs: res.1.unwrap().proofs, - }, - height.increment(), - )) - } -} diff --git a/tests/integration/Cargo.toml b/tests/integration/Cargo.toml index d99b1601..e415af3c 100644 --- a/tests/integration/Cargo.toml +++ b/tests/integration/Cargo.toml @@ -7,8 +7,10 @@ build = "build.rs" [dev-dependencies] prost-types = { version = "0.11", default-features = false } ibc = { version = "0.29.0", default-features = false, features = ["serde", "std"] } -ibc-proto = { version = "0.26.0", default-features = false, features = ["parity-scale-codec", "borsh"] } +ibc-proto = { version = "0.26.0", default-features = false } +ibc-proto-relayer = { package = "ibc-proto", version = "0.24.1", default-features = false } ibc-relayer = { version = "0.22.0", default-features = false } +ibc-relayer-types = "0.22.0" ibc-test-framework = { version = "0.22.0", default-features = false } tendermint-rpc = { version = "0.28", default-features = false } tendermint-light-client-verifier = { version = "0.28", default-features = false } @@ -31,7 +33,6 @@ enclave-api = { path = "../../modules/enclave-api" } ecall-commands = { path = "../../modules/ecall-commands" } attestation-report = { path = "../../modules/attestation-report" } keymanager = { path = "../../modules/keymanager" } -relay-tendermint = { path = "../../modules/relay/tendermint" } [features] default = [] diff --git a/tests/integration/src/config.rs b/tests/integration/src/config.rs new file mode 100644 index 00000000..1d34894b --- /dev/null +++ b/tests/integration/src/config.rs @@ -0,0 +1,71 @@ +use crate::relayer::Relayer; +use crate::types::to_relayer_chain_id; +use envconfig::Envconfig; +use ibc::core::ics24_host::identifier::ChainId; +use ibc_relayer::chain::ChainType; +use ibc_relayer::config::{self, ChainConfig}; +use ibc_relayer::keyring::Store; +use std::str::FromStr; +use std::{sync::Arc, time::Duration}; +use tendermint_rpc::Url; +use tokio::runtime::Runtime as TokioRuntime; + +type Result = std::result::Result; + +#[derive(Envconfig)] +pub struct TestChainConfig { + #[envconfig(from = "TEST_NODE_CHAIN_ID", default = "ibc0")] + pub id: String, + #[envconfig(from = "TEST_NODE_RPC_ADDR", default = "http://localhost:26657")] + pub rpc_addr: String, + #[envconfig( + from = "TEST_NODE_WEBSOCKET_ADDR", + default = "ws://localhost:26657/websocket" + )] + pub websocket_addr: String, + #[envconfig(from = "TEST_NODE_GRPC_ADDR", default = "http://localhost:9090")] + pub grpc_addr: String, +} + +pub fn create_relayer(rt: Arc) -> Result { + let cfg = TestChainConfig::init_from_env().unwrap(); + Relayer::new(make_tm_config(cfg), rt) +} + +fn make_tm_config(cfg: TestChainConfig) -> ChainConfig { + ChainConfig { + id: to_relayer_chain_id(ChainId::new(cfg.id, 0)), + r#type: ChainType::CosmosSdk, + rpc_addr: Url::from_str(&cfg.rpc_addr).unwrap(), + websocket_addr: Url::from_str(&cfg.websocket_addr).unwrap(), + grpc_addr: Url::from_str(&cfg.grpc_addr).unwrap(), + rpc_timeout: Duration::from_secs(10), + account_prefix: "cosmos".to_string(), + key_name: "testkey".to_string(), + + // By default we use in-memory key store to avoid polluting + // ~/.hermes/keys. See + // https://github.com/informalsystems/ibc-rs/issues/1541 + key_store_type: Store::Memory, + + store_prefix: "ibc".to_string(), + default_gas: None, + max_gas: Some(3000000), + gas_adjustment: Some(0.1), + gas_multiplier: None, + fee_granter: None, + max_msg_num: Default::default(), + max_tx_size: Default::default(), + max_block_time: Default::default(), + clock_drift: Duration::from_secs(5), + trusting_period: Some(Duration::from_secs(14 * 24 * 3600)), + trust_threshold: Default::default(), + gas_price: config::GasPrice::new(0.001, "stake".to_string()), + packet_filter: Default::default(), + address_type: Default::default(), + memo_prefix: Default::default(), + proof_specs: Default::default(), + sequential_batch_tx: Default::default(), + extension_options: Default::default(), + } +} diff --git a/tests/integration/src/lib.rs b/tests/integration/src/lib.rs index ee62d87f..57753c57 100644 --- a/tests/integration/src/lib.rs +++ b/tests/integration/src/lib.rs @@ -1,8 +1,14 @@ #[cfg(test)] +mod config; +#[cfg(test)] mod relayer; +#[cfg(test)] +mod types; + #[cfg(test)] mod tests { use super::*; + use crate::relayer::Relayer; use anyhow::{anyhow, bail}; use commitments::UpdateClientCommitment; use ecall_commands::{ @@ -27,7 +33,6 @@ mod tests { use keymanager::EnclaveKeyManager; use lcp_types::Time; use log::*; - use relay_tendermint::Relayer; use std::str::FromStr; use std::sync::{Arc, RwLock}; use store::{host::HostStore, memory::MemStore}; @@ -84,7 +89,7 @@ mod tests { fn run_test(enclave: &Enclave) -> Result<(), anyhow::Error> { env_logger::init(); let rt = Arc::new(TokioRuntime::new()?); - let rly = relayer::create_relayer(rt).unwrap(); + let rly = config::create_relayer(rt).unwrap(); verify(rly, enclave) } diff --git a/tests/integration/src/relayer.rs b/tests/integration/src/relayer.rs index de97ad55..21e39bdd 100644 --- a/tests/integration/src/relayer.rs +++ b/tests/integration/src/relayer.rs @@ -1,71 +1,177 @@ -use envconfig::Envconfig; -use ibc::core::ics24_host::identifier::ChainId; -use ibc_relayer::chain::ChainType; -use ibc_relayer::config::{self, ChainConfig}; -use ibc_relayer::keyring::Store; -use relay_tendermint::types::to_relayer_chain_id; -use relay_tendermint::Relayer; -use std::str::FromStr; -use std::{sync::Arc, time::Duration}; -use tendermint_rpc::Url; +use crate::types::{ + relayer_header_to_any, to_ibc_channel, to_ibc_client_state, to_ibc_connection, + to_ibc_consensus_state, to_ibc_height, to_relayer_channel_id, to_relayer_client_state, + to_relayer_connection_id, to_relayer_height, to_relayer_port_id, to_relayer_sequence, +}; +use anyhow::Result; +use ibc::clients::ics07_tendermint::client_state::ClientState; +use ibc::clients::ics07_tendermint::consensus_state::ConsensusState; +use ibc::core::ics03_connection::connection::ConnectionEnd; +use ibc::core::ics04_channel::channel::ChannelEnd; +use ibc::core::ics04_channel::commitment::PacketCommitment; +use ibc::core::ics04_channel::packet::Sequence; +use ibc::core::ics23_commitment::merkle::MerkleProof; +use ibc::core::ics24_host::identifier::{ChannelId, ConnectionId, PortId}; +use ibc::Height; +use ibc_proto::google::protobuf::Any as IBCAny; +use ibc_relayer::chain::requests::QueryConnectionRequest; +use ibc_relayer::chain::{ + client::ClientSettings, + cosmos::{client::Settings, CosmosSdkChain}, + endpoint::ChainEndpoint, + requests::{IncludeProof, QueryChannelRequest, QueryHeight, QueryPacketCommitmentRequest}, +}; +use ibc_relayer::client_state::AnyClientState; +use ibc_relayer::config::ChainConfig; +use ibc_relayer::light_client::tendermint::LightClient as TmLightClient; +use ibc_relayer::light_client::{tendermint::LightClient, LightClient as IBCLightClient}; +use lcp_types::Any; +use std::sync::Arc; +use tendermint_rpc::{Client, HttpClient}; use tokio::runtime::Runtime as TokioRuntime; -type Result = std::result::Result; +pub struct Relayer { + tmlc: LightClient, + chain: CosmosSdkChain, -#[derive(Envconfig)] -pub struct TestChainConfig { - #[envconfig(from = "TEST_NODE_CHAIN_ID", default = "ibc0")] - pub id: String, - #[envconfig(from = "TEST_NODE_RPC_ADDR", default = "http://localhost:26657")] - pub rpc_addr: String, - #[envconfig( - from = "TEST_NODE_WEBSOCKET_ADDR", - default = "ws://localhost:26657/websocket" - )] - pub websocket_addr: String, - #[envconfig(from = "TEST_NODE_GRPC_ADDR", default = "http://localhost:9090")] - pub grpc_addr: String, + client_state: Option, } -pub fn create_relayer(rt: Arc) -> Result { - let cfg = TestChainConfig::init_from_env().unwrap(); - Relayer::new(make_tm_config(cfg), rt) +/// Initialize the light client for the given chain using the given HTTP client +/// to fetch the node identifier to be used as peer id in the light client. +async fn init_light_client(rpc_client: &HttpClient, config: &ChainConfig) -> TmLightClient { + use tendermint_light_client_verifier::types::PeerId; + + let peer_id: PeerId = rpc_client.status().await.map(|s| s.node_info.id).unwrap(); + TmLightClient::from_config(config, peer_id).unwrap() } -fn make_tm_config(cfg: TestChainConfig) -> ChainConfig { - ChainConfig { - id: to_relayer_chain_id(ChainId::new(cfg.id, 0)), - r#type: ChainType::CosmosSdk, - rpc_addr: Url::from_str(&cfg.rpc_addr).unwrap(), - websocket_addr: Url::from_str(&cfg.websocket_addr).unwrap(), - grpc_addr: Url::from_str(&cfg.grpc_addr).unwrap(), - rpc_timeout: Duration::from_secs(10), - account_prefix: "cosmos".to_string(), - key_name: "testkey".to_string(), +impl Relayer { + pub fn new(cc: ChainConfig, rt: Arc) -> Result { + let chain = CosmosSdkChain::bootstrap(cc.clone(), rt.clone()).unwrap(); + let rpc_client = HttpClient::new(cc.rpc_addr.clone()).unwrap(); + let tmlc = rt.block_on(init_light_client(&rpc_client, &cc)); + Ok(Self { + tmlc, + chain, + client_state: None, + }) + } + + pub fn create_header(&mut self, trusted_height: Height, target_height: Height) -> Result { + let (target, supporting) = self.chain.build_header( + to_relayer_height(trusted_height), + to_relayer_height(target_height), + &AnyClientState::Tendermint(to_relayer_client_state( + self.client_state.clone().unwrap(), + )), + )?; + assert!(supporting.is_empty()); + Ok(relayer_header_to_any(target)) + } - // By default we use in-memory key store to avoid polluting - // ~/.hermes/keys. See - // https://github.com/informalsystems/ibc-rs/issues/1541 - key_store_type: Store::Memory, + pub fn fetch_state(&mut self, height: Height) -> Result<(ClientState, ConsensusState)> { + let height = to_relayer_height(height); + let block = self.tmlc.fetch(height)?; + let config = self.chain.config(); + let client_state = to_ibc_client_state(self.chain.build_client_state( + height, + ClientSettings::Tendermint(Settings { + max_clock_drift: config.clock_drift, + trusting_period: config.trusting_period, + trust_threshold: config.trust_threshold.into(), + }), + )?); + let consensus_state = to_ibc_consensus_state(self.chain.build_consensus_state(block)?); + self.client_state = Some(client_state.clone()); + Ok((client_state, consensus_state)) + } + + pub fn fetch_state_as_any(&mut self, height: Height) -> Result<(Any, Any)> { + let (client_state, consensus_state) = self.fetch_state(height)?; + let any_client_state = IBCAny::from(client_state); + let any_consensus_state = IBCAny::from(consensus_state); + Ok((any_client_state.into(), any_consensus_state.into())) + } + + pub fn query_latest_height(&self) -> Result { + Ok(to_ibc_height(self.chain.query_chain_latest_height()?)) + } + + pub fn query_connection_proof( + &self, + connection_id: ConnectionId, + height: Option, // height of consensus state + ) -> Result<(ConnectionEnd, MerkleProof, Height)> { + let height = match height { + Some(height) => height.decrement().unwrap(), + None => self.query_latest_height()?.decrement().unwrap(), + }; + let req = QueryConnectionRequest { + connection_id: to_relayer_connection_id(connection_id), + height: QueryHeight::Specific(to_relayer_height(height)), + }; + let res = self.chain.query_connection(req, IncludeProof::Yes)?; + Ok(( + to_ibc_connection(res.0), + MerkleProof { + proofs: res.1.unwrap().proofs, + }, + height.increment(), + )) + } + + pub fn query_channel_proof( + &self, + port_id: PortId, + channel_id: ChannelId, + height: Option, // height of consensus state + ) -> Result<(ChannelEnd, MerkleProof, Height)> { + let height = match height { + Some(height) => height.decrement().unwrap(), + None => self.query_latest_height()?.decrement().unwrap(), + }; + let req = QueryChannelRequest { + port_id: to_relayer_port_id(port_id), + channel_id: to_relayer_channel_id(channel_id), + height: QueryHeight::Specific(to_relayer_height(height)), + }; + let res = self.chain.query_channel(req, IncludeProof::Yes)?; + Ok(( + to_ibc_channel(res.0), + MerkleProof { + proofs: res.1.unwrap().proofs, + }, + height.increment(), + )) + } - store_prefix: "ibc".to_string(), - default_gas: None, - max_gas: Some(3000000), - gas_adjustment: Some(0.1), - gas_multiplier: None, - fee_granter: None, - max_msg_num: Default::default(), - max_tx_size: Default::default(), - max_block_time: Default::default(), - clock_drift: Duration::from_secs(5), - trusting_period: Some(Duration::from_secs(14 * 24 * 3600)), - trust_threshold: Default::default(), - gas_price: config::GasPrice::new(0.001, "stake".to_string()), - packet_filter: Default::default(), - address_type: Default::default(), - memo_prefix: Default::default(), - proof_specs: Default::default(), - sequential_batch_tx: Default::default(), - extension_options: Default::default(), + pub fn query_packet_proof( + &self, + port_id: PortId, + channel_id: ChannelId, + sequence: Sequence, + height: Option, // height of consensus state + ) -> Result<(PacketCommitment, MerkleProof, Height)> { + let height = match height { + Some(height) => height.decrement().unwrap(), + None => self.query_latest_height()?.decrement().unwrap(), + }; + let res = self.chain.query_packet_commitment( + QueryPacketCommitmentRequest { + port_id: to_relayer_port_id(port_id), + channel_id: to_relayer_channel_id(channel_id), + sequence: to_relayer_sequence(sequence), + height: QueryHeight::Specific(to_relayer_height(height)), + }, + IncludeProof::Yes, + )?; + Ok(( + res.0.into(), + MerkleProof { + proofs: res.1.unwrap().proofs, + }, + height.increment(), + )) } } diff --git a/modules/relay/tendermint/src/types.rs b/tests/integration/src/types.rs similarity index 100% rename from modules/relay/tendermint/src/types.rs rename to tests/integration/src/types.rs From b305fcaf48d6d5c654d137cca5d674448c77c39c Mon Sep 17 00:00:00 2001 From: Jun Kimura Date: Mon, 7 Aug 2023 15:56:30 +0900 Subject: [PATCH 2/3] rename ibc-client crate with lcp-client Signed-off-by: Jun Kimura --- Cargo.lock | 2 +- Cargo.toml | 2 +- modules/{ibc-client => lcp-client}/Cargo.toml | 2 +- modules/{ibc-client => lcp-client}/README.md | 2 +- modules/{ibc-client => lcp-client}/src/client_def.rs | 0 modules/{ibc-client => lcp-client}/src/client_state.rs | 0 modules/{ibc-client => lcp-client}/src/consensus_state.rs | 0 modules/{ibc-client => lcp-client}/src/errors.rs | 0 modules/{ibc-client => lcp-client}/src/lib.rs | 0 modules/{ibc-client => lcp-client}/src/message.rs | 0 10 files changed, 4 insertions(+), 4 deletions(-) rename modules/{ibc-client => lcp-client}/Cargo.toml (98%) rename modules/{ibc-client => lcp-client}/README.md (85%) rename modules/{ibc-client => lcp-client}/src/client_def.rs (100%) rename modules/{ibc-client => lcp-client}/src/client_state.rs (100%) rename modules/{ibc-client => lcp-client}/src/consensus_state.rs (100%) rename modules/{ibc-client => lcp-client}/src/errors.rs (100%) rename modules/{ibc-client => lcp-client}/src/lib.rs (100%) rename modules/{ibc-client => lcp-client}/src/message.rs (100%) diff --git a/Cargo.lock b/Cargo.lock index 922dda5f..daeaa32c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2601,7 +2601,7 @@ dependencies = [ ] [[package]] -name = "lcp-ibc-client" +name = "lcp-client" version = "0.1.0" dependencies = [ "attestation-report", diff --git a/Cargo.toml b/Cargo.toml index 8d6787b4..2577f5e0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -15,7 +15,7 @@ members = [ "modules/crypto", "modules/keymanager", "modules/store", - "modules/ibc-client", + "modules/lcp-client", "modules/validation-context", "modules/light-client", "modules/light-client-registry", diff --git a/modules/ibc-client/Cargo.toml b/modules/lcp-client/Cargo.toml similarity index 98% rename from modules/ibc-client/Cargo.toml rename to modules/lcp-client/Cargo.toml index 74947b1e..ffa5ab7d 100644 --- a/modules/ibc-client/Cargo.toml +++ b/modules/lcp-client/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "lcp-ibc-client" +name = "lcp-client" version = "0.1.0" edition = "2021" diff --git a/modules/ibc-client/README.md b/modules/lcp-client/README.md similarity index 85% rename from modules/ibc-client/README.md rename to modules/lcp-client/README.md index c9223c17..5ca793e2 100644 --- a/modules/ibc-client/README.md +++ b/modules/lcp-client/README.md @@ -1,3 +1,3 @@ -# ibc-client +# lcp-client This crate is a PoC implementation of the IBC Client that verifies the LCP. diff --git a/modules/ibc-client/src/client_def.rs b/modules/lcp-client/src/client_def.rs similarity index 100% rename from modules/ibc-client/src/client_def.rs rename to modules/lcp-client/src/client_def.rs diff --git a/modules/ibc-client/src/client_state.rs b/modules/lcp-client/src/client_state.rs similarity index 100% rename from modules/ibc-client/src/client_state.rs rename to modules/lcp-client/src/client_state.rs diff --git a/modules/ibc-client/src/consensus_state.rs b/modules/lcp-client/src/consensus_state.rs similarity index 100% rename from modules/ibc-client/src/consensus_state.rs rename to modules/lcp-client/src/consensus_state.rs diff --git a/modules/ibc-client/src/errors.rs b/modules/lcp-client/src/errors.rs similarity index 100% rename from modules/ibc-client/src/errors.rs rename to modules/lcp-client/src/errors.rs diff --git a/modules/ibc-client/src/lib.rs b/modules/lcp-client/src/lib.rs similarity index 100% rename from modules/ibc-client/src/lib.rs rename to modules/lcp-client/src/lib.rs diff --git a/modules/ibc-client/src/message.rs b/modules/lcp-client/src/message.rs similarity index 100% rename from modules/ibc-client/src/message.rs rename to modules/lcp-client/src/message.rs From 1a0e7857ffcd3f1153c43c6f9801621215ad7ab7 Mon Sep 17 00:00:00 2001 From: Jun Kimura Date: Tue, 8 Aug 2023 11:16:59 +0900 Subject: [PATCH 3/3] tests: fix lint errors Signed-off-by: Jun Kimura --- tests/integration/src/relayer.rs | 66 ++------------------------ tests/integration/src/types.rs | 79 ++++++-------------------------- 2 files changed, 20 insertions(+), 125 deletions(-) diff --git a/tests/integration/src/relayer.rs b/tests/integration/src/relayer.rs index 21e39bdd..4db96eac 100644 --- a/tests/integration/src/relayer.rs +++ b/tests/integration/src/relayer.rs @@ -1,25 +1,21 @@ use crate::types::{ - relayer_header_to_any, to_ibc_channel, to_ibc_client_state, to_ibc_connection, - to_ibc_consensus_state, to_ibc_height, to_relayer_channel_id, to_relayer_client_state, - to_relayer_connection_id, to_relayer_height, to_relayer_port_id, to_relayer_sequence, + relayer_header_to_any, to_ibc_channel, to_ibc_client_state, to_ibc_consensus_state, + to_ibc_height, to_relayer_channel_id, to_relayer_client_state, to_relayer_height, + to_relayer_port_id, }; use anyhow::Result; use ibc::clients::ics07_tendermint::client_state::ClientState; use ibc::clients::ics07_tendermint::consensus_state::ConsensusState; -use ibc::core::ics03_connection::connection::ConnectionEnd; use ibc::core::ics04_channel::channel::ChannelEnd; -use ibc::core::ics04_channel::commitment::PacketCommitment; -use ibc::core::ics04_channel::packet::Sequence; use ibc::core::ics23_commitment::merkle::MerkleProof; -use ibc::core::ics24_host::identifier::{ChannelId, ConnectionId, PortId}; +use ibc::core::ics24_host::identifier::{ChannelId, PortId}; use ibc::Height; use ibc_proto::google::protobuf::Any as IBCAny; -use ibc_relayer::chain::requests::QueryConnectionRequest; use ibc_relayer::chain::{ client::ClientSettings, cosmos::{client::Settings, CosmosSdkChain}, endpoint::ChainEndpoint, - requests::{IncludeProof, QueryChannelRequest, QueryHeight, QueryPacketCommitmentRequest}, + requests::{IncludeProof, QueryChannelRequest, QueryHeight}, }; use ibc_relayer::client_state::AnyClientState; use ibc_relayer::config::ChainConfig; @@ -98,29 +94,6 @@ impl Relayer { Ok(to_ibc_height(self.chain.query_chain_latest_height()?)) } - pub fn query_connection_proof( - &self, - connection_id: ConnectionId, - height: Option, // height of consensus state - ) -> Result<(ConnectionEnd, MerkleProof, Height)> { - let height = match height { - Some(height) => height.decrement().unwrap(), - None => self.query_latest_height()?.decrement().unwrap(), - }; - let req = QueryConnectionRequest { - connection_id: to_relayer_connection_id(connection_id), - height: QueryHeight::Specific(to_relayer_height(height)), - }; - let res = self.chain.query_connection(req, IncludeProof::Yes)?; - Ok(( - to_ibc_connection(res.0), - MerkleProof { - proofs: res.1.unwrap().proofs, - }, - height.increment(), - )) - } - pub fn query_channel_proof( &self, port_id: PortId, @@ -145,33 +118,4 @@ impl Relayer { height.increment(), )) } - - pub fn query_packet_proof( - &self, - port_id: PortId, - channel_id: ChannelId, - sequence: Sequence, - height: Option, // height of consensus state - ) -> Result<(PacketCommitment, MerkleProof, Height)> { - let height = match height { - Some(height) => height.decrement().unwrap(), - None => self.query_latest_height()?.decrement().unwrap(), - }; - let res = self.chain.query_packet_commitment( - QueryPacketCommitmentRequest { - port_id: to_relayer_port_id(port_id), - channel_id: to_relayer_channel_id(channel_id), - sequence: to_relayer_sequence(sequence), - height: QueryHeight::Specific(to_relayer_height(height)), - }, - IncludeProof::Yes, - )?; - Ok(( - res.0.into(), - MerkleProof { - proofs: res.1.unwrap().proofs, - }, - height.increment(), - )) - } } diff --git a/tests/integration/src/types.rs b/tests/integration/src/types.rs index f5ca1a61..b0d42c99 100644 --- a/tests/integration/src/types.rs +++ b/tests/integration/src/types.rs @@ -1,12 +1,11 @@ use ibc::{ clients::ics07_tendermint::{ client_state::ClientState as TendermintClientState, - consensus_state::ConsensusState as TendermintConsensusState, header::Header, + consensus_state::ConsensusState as TendermintConsensusState, }, core::{ - ics03_connection::connection::ConnectionEnd, - ics04_channel::{channel::ChannelEnd, packet::Sequence}, - ics24_host::identifier::{ChainId, ChannelId, ConnectionId, PortId}, + ics04_channel::channel::ChannelEnd, + ics24_host::identifier::{ChainId, ChannelId, PortId}, }, Height, }; @@ -14,19 +13,13 @@ use ibc_proto::{google::protobuf::Any as IBCAny, protobuf::Protobuf}; use ibc_proto_relayer::{ google::protobuf::Any as IBCRelayerAny, protobuf::Protobuf as RelayerProtobuf, }; -use ibc_relayer_types::core::ics04_channel::packet::Sequence as RSequence; -use ibc_relayer_types::core::ics24_host::identifier::{ - ChannelId as RChannelId, ConnectionId as RConnectionId, PortId as RPortId, -}; +use ibc_relayer_types::core::ics24_host::identifier::{ChannelId as RChannelId, PortId as RPortId}; use ibc_relayer_types::{ clients::ics07_tendermint::{ client_state::ClientState as RTendermintClientState, consensus_state::ConsensusState as RTendermintConsensusState, header::Header as RHeader, }, - core::{ - ics03_connection::connection::ConnectionEnd as RConnectionEnd, - ics04_channel::channel::ChannelEnd as RChannelEnd, - }, + core::ics04_channel::channel::ChannelEnd as RChannelEnd, }; use ibc_relayer_types::{core::ics24_host::identifier::ChainId as RChainId, Height as RHeight}; use lcp_types::Any; @@ -37,38 +30,22 @@ use std::str::FromStr; /// relayer-types to lcp types -pub fn relayer_header_to_any(value: RHeader) -> Any { +pub(crate) fn relayer_header_to_any(value: RHeader) -> Any { let any = IBCRelayerAny::from(value); Any::new(any.type_url, any.value) } /// relayer-types to ibc -pub fn to_ibc_connection(value: RConnectionEnd) -> ConnectionEnd { - ConnectionEnd::decode_vec(&value.encode_vec().unwrap()).unwrap() -} - -pub fn to_ibc_connection_id(value: RConnectionId) -> ConnectionId { - ConnectionId::from_str(value.as_str()).unwrap() -} - -pub fn to_ibc_channel(value: RChannelEnd) -> ChannelEnd { +pub(crate) fn to_ibc_channel(value: RChannelEnd) -> ChannelEnd { ChannelEnd::decode_vec(&value.encode_vec().unwrap()).unwrap() } -pub fn to_ibc_channel_id(value: RChannelId) -> ChannelId { - ChannelId::from_str(value.as_str()).unwrap() -} - -pub fn to_ibc_port_id(value: RPortId) -> PortId { - PortId::from_str(value.as_str()).unwrap() -} - -pub fn to_ibc_height(value: RHeight) -> Height { +pub(crate) fn to_ibc_height(value: RHeight) -> Height { Height::new(value.revision_number(), value.revision_height()).unwrap() } -pub fn to_ibc_client_state(value: RTendermintClientState) -> TendermintClientState { +pub(crate) fn to_ibc_client_state(value: RTendermintClientState) -> TendermintClientState { let any = IBCRelayerAny::from(value); TendermintClientState::try_from(IBCAny { type_url: any.type_url, @@ -77,7 +54,7 @@ pub fn to_ibc_client_state(value: RTendermintClientState) -> TendermintClientSta .unwrap() } -pub fn to_ibc_consensus_state(value: RTendermintConsensusState) -> TendermintConsensusState { +pub(crate) fn to_ibc_consensus_state(value: RTendermintConsensusState) -> TendermintConsensusState { let any = IBCRelayerAny::from(value); TendermintConsensusState::try_from(IBCAny { type_url: any.type_url, @@ -86,42 +63,25 @@ pub fn to_ibc_consensus_state(value: RTendermintConsensusState) -> TendermintCon .unwrap() } -pub fn to_ibc_header(value: RHeader) -> Header { - let any = IBCRelayerAny::from(value); - Header::try_from(IBCAny { - type_url: any.type_url, - value: any.value, - }) - .unwrap() -} - /// ibc to relayer-types -pub fn to_relayer_chain_id(value: ChainId) -> RChainId { +pub(crate) fn to_relayer_chain_id(value: ChainId) -> RChainId { RChainId::from_str(value.as_str()).unwrap() } -pub fn to_relayer_height(value: Height) -> RHeight { +pub(crate) fn to_relayer_height(value: Height) -> RHeight { RHeight::new(value.revision_number(), value.revision_height()).unwrap() } -pub fn to_relayer_connection_id(value: ConnectionId) -> RConnectionId { - RConnectionId::from_str(value.as_str()).unwrap() -} - -pub fn to_relayer_channel_id(value: ChannelId) -> RChannelId { +pub(crate) fn to_relayer_channel_id(value: ChannelId) -> RChannelId { RChannelId::from_str(value.as_str()).unwrap() } -pub fn to_relayer_port_id(value: PortId) -> RPortId { +pub(crate) fn to_relayer_port_id(value: PortId) -> RPortId { RPortId::from_str(value.as_str()).unwrap() } -pub fn to_relayer_sequence(value: Sequence) -> RSequence { - RSequence::from_str(value.to_string().as_str()).unwrap() -} - -pub fn to_relayer_client_state(value: TendermintClientState) -> RTendermintClientState { +pub(crate) fn to_relayer_client_state(value: TendermintClientState) -> RTendermintClientState { let any = IBCAny::from(value); RTendermintClientState::try_from(IBCRelayerAny { type_url: any.type_url, @@ -129,12 +89,3 @@ pub fn to_relayer_client_state(value: TendermintClientState) -> RTendermintClien }) .unwrap() } - -pub fn to_relayer_consensus_state(value: TendermintConsensusState) -> RTendermintConsensusState { - let any = IBCAny::from(value); - RTendermintConsensusState::try_from(IBCRelayerAny { - type_url: any.type_url, - value: any.value, - }) - .unwrap() -}