From 6f59e2592ad4b49d0b5f6d659386e51f4daf0687 Mon Sep 17 00:00:00 2001 From: Romain Ruetschi <106849+romac@users.noreply.github.com> Date: Wed, 13 Sep 2023 17:41:25 +0200 Subject: [PATCH 1/8] Add support for localhost.v1 client state --- .../src/clients/ics09_localhost/mod.rs | 11 ++ .../ics09_localhost/v1/client_state.rs | 130 ++++++++++++++++++ .../src/clients/ics09_localhost/v1/error.rs | 51 +++++++ .../src/clients/ics09_localhost/v1/mod.rs | 2 + .../ics09_localhost/v2/client_state.rs | 2 + .../src/clients/ics09_localhost/v2/mod.rs | 1 + crates/relayer-types/src/clients/mod.rs | 1 + .../src/core/ics02_client/client_type.rs | 23 ++++ .../src/core/ics02_client/error.rs | 4 + .../src/core/ics24_host/identifier.rs | 1 + crates/relayer/src/client_state.rs | 74 ++++++++-- 11 files changed, 285 insertions(+), 15 deletions(-) create mode 100644 crates/relayer-types/src/clients/ics09_localhost/mod.rs create mode 100644 crates/relayer-types/src/clients/ics09_localhost/v1/client_state.rs create mode 100644 crates/relayer-types/src/clients/ics09_localhost/v1/error.rs create mode 100644 crates/relayer-types/src/clients/ics09_localhost/v1/mod.rs create mode 100644 crates/relayer-types/src/clients/ics09_localhost/v2/client_state.rs create mode 100644 crates/relayer-types/src/clients/ics09_localhost/v2/mod.rs diff --git a/crates/relayer-types/src/clients/ics09_localhost/mod.rs b/crates/relayer-types/src/clients/ics09_localhost/mod.rs new file mode 100644 index 0000000000..60f026e2f0 --- /dev/null +++ b/crates/relayer-types/src/clients/ics09_localhost/mod.rs @@ -0,0 +1,11 @@ +//! ICS 09: Loopback Client +//! Loopback client, designed to be used for interaction over the +//! IBC interface with modules present on the same ledger. +//! +//! Loopback clients may be useful in cases where the calling module +//! does not have prior knowledge of where precisely the destination +//! module lives and would like to use the uniform IBC message-passing +//! interface (similar to 127.0.0.1 in TCP/IP). + +pub mod v1; +pub mod v2; diff --git a/crates/relayer-types/src/clients/ics09_localhost/v1/client_state.rs b/crates/relayer-types/src/clients/ics09_localhost/v1/client_state.rs new file mode 100644 index 0000000000..d548e13280 --- /dev/null +++ b/crates/relayer-types/src/clients/ics09_localhost/v1/client_state.rs @@ -0,0 +1,130 @@ +use std::convert::{TryFrom, TryInto}; +use std::time::Duration; + +use prost::Message; +use serde::{Deserialize, Serialize}; + +use ibc_proto::google::protobuf::Any; +use ibc_proto::ibc::lightclients::localhost::v1::ClientState as RawClientState; +use ibc_proto::protobuf::Protobuf; + +use crate::core::ics02_client::client_state::ClientState as Ics02ClientState; +use crate::core::ics02_client::client_state::UpgradeOptions; +use crate::core::ics02_client::client_type::ClientType; +use crate::core::ics02_client::error::Error as Ics02Error; +use crate::core::ics24_host::identifier::ChainId; +use crate::Height; + +use super::error::Error; + +pub const LOCALHOST_CLIENT_STATE_TYPE_URL: &str = "/ibc.lightclients.localhost.v1.ClientState"; + +#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] +pub struct ClientState { + pub chain_id: ChainId, + pub height: Height, +} + +impl ClientState { + pub fn new(chain_id: ChainId, height: Height) -> ClientState { + Self { chain_id, height } + } + + pub fn height(&self) -> Height { + self.height + } +} + +impl Ics02ClientState for ClientState { + fn chain_id(&self) -> ChainId { + self.chain_id.clone() + } + + fn client_type(&self) -> ClientType { + ClientType::Localhost + } + + fn latest_height(&self) -> Height { + self.height + } + + fn frozen_height(&self) -> Option { + None + } + + fn upgrade( + &mut self, + upgrade_height: Height, + _upgrade_options: &dyn UpgradeOptions, + chain_id: ChainId, + ) { + self.height = upgrade_height; + self.chain_id = chain_id; + } + + fn expired(&self, _elapsed: Duration) -> bool { + false + } +} + +impl Protobuf for ClientState {} + +impl TryFrom for ClientState { + type Error = Error; + + fn try_from(raw: RawClientState) -> Result { + Ok(Self { + chain_id: ChainId::from_string(raw.chain_id.as_str()), + height: raw + .height + .ok_or_else(Error::missing_height)? + .try_into() + .map_err(|_| Error::missing_height())?, + }) + } +} + +impl From for RawClientState { + fn from(value: ClientState) -> Self { + Self { + chain_id: value.chain_id.to_string(), + height: Some(value.height.into()), + } + } +} + +impl Protobuf for ClientState {} + +impl TryFrom for ClientState { + type Error = Ics02Error; + + fn try_from(raw: Any) -> Result { + use bytes::Buf; + use core::ops::Deref; + + fn decode_client_state(buf: B) -> Result { + RawClientState::decode(buf) + .map_err(Error::decode)? + .try_into() + } + + match raw.type_url.as_str() { + LOCALHOST_CLIENT_STATE_TYPE_URL => { + decode_client_state(raw.value.deref()).map_err(Into::into) + } + _ => Err(Ics02Error::unexpected_client_state_type( + LOCALHOST_CLIENT_STATE_TYPE_URL.to_string(), + raw.type_url, + )), + } + } +} + +impl From for Any { + fn from(client_state: ClientState) -> Self { + Any { + type_url: LOCALHOST_CLIENT_STATE_TYPE_URL.to_string(), + value: Protobuf::::encode_vec(&client_state), + } + } +} diff --git a/crates/relayer-types/src/clients/ics09_localhost/v1/error.rs b/crates/relayer-types/src/clients/ics09_localhost/v1/error.rs new file mode 100644 index 0000000000..738b5f2f22 --- /dev/null +++ b/crates/relayer-types/src/clients/ics09_localhost/v1/error.rs @@ -0,0 +1,51 @@ +use flex_error::{define_error, TraceError}; + +use crate::core::ics02_client::error::Error as Ics02Error; +use crate::core::ics24_host::error::ValidationError; + +use crate::Height; + +define_error! { + #[derive(Debug, PartialEq, Eq)] + Error { + InvalidRawClientState + { reason: String } + |e| { format_args!("invalid raw client state: {}", e.reason) }, + + InvalidChainIdentifier + [ ValidationError ] + |_| { "invalid chain identifier" }, + + MissingHeight + |_| { "missing height" }, + + InvalidChainId + { raw_value: String } + [ ValidationError ] + |e| { format_args!("invalid chain identifier: {}", e.raw_value) }, + + InvalidRawHeight + { raw_height: u64 } + |e| { format_args!("invalid raw height: {}", e.raw_height) }, + + Decode + [ TraceError ] + |_| { "decode error" }, + + InsufficientHeight + { + latest_height: Height, + target_height: Height, + } + |e| { + format_args!("the height is insufficient: latest_height={0} target_height={1}", + e.latest_height, e.target_height) + }, + } +} + +impl From for Ics02Error { + fn from(e: Error) -> Self { + Self::client_specific(e.to_string()) + } +} diff --git a/crates/relayer-types/src/clients/ics09_localhost/v1/mod.rs b/crates/relayer-types/src/clients/ics09_localhost/v1/mod.rs new file mode 100644 index 0000000000..6e8e2e71ae --- /dev/null +++ b/crates/relayer-types/src/clients/ics09_localhost/v1/mod.rs @@ -0,0 +1,2 @@ +pub mod client_state; +pub mod error; diff --git a/crates/relayer-types/src/clients/ics09_localhost/v2/client_state.rs b/crates/relayer-types/src/clients/ics09_localhost/v2/client_state.rs new file mode 100644 index 0000000000..139597f9cb --- /dev/null +++ b/crates/relayer-types/src/clients/ics09_localhost/v2/client_state.rs @@ -0,0 +1,2 @@ + + diff --git a/crates/relayer-types/src/clients/ics09_localhost/v2/mod.rs b/crates/relayer-types/src/clients/ics09_localhost/v2/mod.rs new file mode 100644 index 0000000000..1afebe67a2 --- /dev/null +++ b/crates/relayer-types/src/clients/ics09_localhost/v2/mod.rs @@ -0,0 +1 @@ +pub mod client_state; diff --git a/crates/relayer-types/src/clients/mod.rs b/crates/relayer-types/src/clients/mod.rs index 65ea910b18..413c78777f 100644 --- a/crates/relayer-types/src/clients/mod.rs +++ b/crates/relayer-types/src/clients/mod.rs @@ -1,3 +1,4 @@ //! Implementations of client verification algorithms for specific types of chains. pub mod ics07_tendermint; +pub mod ics09_localhost; diff --git a/crates/relayer-types/src/core/ics02_client/client_type.rs b/crates/relayer-types/src/core/ics02_client/client_type.rs index a35e44604d..8e903a83db 100644 --- a/crates/relayer-types/src/core/ics02_client/client_type.rs +++ b/crates/relayer-types/src/core/ics02_client/client_type.rs @@ -8,12 +8,15 @@ use super::error::Error; pub enum ClientType { Tendermint = 1, + Localhost = 9, + #[cfg(any(test, feature = "mocks"))] Mock = 9999, } impl ClientType { const TENDERMINT_STR: &'static str = "07-tendermint"; + const LOCALHOST_STR: &'static str = "09-tendermint"; #[cfg_attr(not(test), allow(dead_code))] const MOCK_STR: &'static str = "9999-mock"; @@ -22,6 +25,7 @@ impl ClientType { pub fn as_str(&self) -> &'static str { match self { Self::Tendermint => Self::TENDERMINT_STR, + Self::Localhost => Self::LOCALHOST_STR, #[cfg(any(test, feature = "mocks"))] Self::Mock => Self::MOCK_STR, @@ -41,6 +45,7 @@ impl core::str::FromStr for ClientType { fn from_str(s: &str) -> Result { match s { Self::TENDERMINT_STR => Ok(Self::Tendermint), + Self::LOCALHOST_STR => Ok(Self::Localhost), #[cfg(any(test, feature = "mocks"))] Self::MOCK_STR => Ok(Self::Mock), @@ -68,6 +73,16 @@ mod tests { } } + #[test] + fn parse_localhost_client_type() { + let client_type = ClientType::from_str("09-localhost"); + + match client_type { + Ok(ClientType::Localhost) => (), + _ => panic!("parse failed"), + } + } + #[test] fn parse_mock_client_type() { let client_type = ClientType::from_str("9999-mock"); @@ -108,4 +123,12 @@ mod tests { let client_type_from_str = ClientType::from_str(type_string).unwrap(); assert_eq!(client_type_from_str, client_type); } + + #[test] + fn parse_localhost_as_string_result() { + let client_type = ClientType::Localhost; + let type_string = client_type.as_str(); + let client_type_from_str = ClientType::from_str(type_string).unwrap(); + assert_eq!(client_type_from_str, client_type); + } } diff --git a/crates/relayer-types/src/core/ics02_client/error.rs b/crates/relayer-types/src/core/ics02_client/error.rs index c01dd19714..1df0befe8b 100644 --- a/crates/relayer-types/src/core/ics02_client/error.rs +++ b/crates/relayer-types/src/core/ics02_client/error.rs @@ -63,6 +63,10 @@ define_error! { { client_state_type: String } | e | { format_args!("unknown client state type: {0}", e.client_state_type) }, + UnexpectedClientStateType + { expected: String, got: String } + | e | { format_args!("unexpected client state type: expected `{0}`, got {1}", e.expected, e.got) }, + EmptyClientStateResponse | _ | { "the client state was not found" }, diff --git a/crates/relayer-types/src/core/ics24_host/identifier.rs b/crates/relayer-types/src/core/ics24_host/identifier.rs index 0405c50b2d..d392c020d6 100644 --- a/crates/relayer-types/src/core/ics24_host/identifier.rs +++ b/crates/relayer-types/src/core/ics24_host/identifier.rs @@ -178,6 +178,7 @@ impl ClientId { pub fn prefix(client_type: ClientType) -> &'static str { match client_type { ClientType::Tendermint => ClientType::Tendermint.as_str(), + ClientType::Localhost => ClientType::Localhost.as_str(), #[cfg(any(test, feature = "mocks"))] ClientType::Mock => ClientType::Mock.as_str(), diff --git a/crates/relayer/src/client_state.rs b/crates/relayer/src/client_state.rs index 8c5eff288b..eb43de0bab 100644 --- a/crates/relayer/src/client_state.rs +++ b/crates/relayer/src/client_state.rs @@ -1,17 +1,21 @@ use core::time::Duration; +use serde::{Deserialize, Serialize}; + +use ibc_proto::google::protobuf::Any; use ibc_proto::ibc::core::client::v1::IdentifiedClientState; -use ibc_proto::ibc::lightclients::tendermint::v1::ClientState as RawClientState; +use ibc_proto::ibc::lightclients::localhost::v1::ClientState as RawLocalhostClientState; +use ibc_proto::ibc::lightclients::tendermint::v1::ClientState as RawTmClientState; #[cfg(test)] use ibc_proto::ibc::mock::ClientState as RawMockClientState; use ibc_proto::protobuf::Protobuf; -use serde::{Deserialize, Serialize}; - -use ibc_proto::google::protobuf::Any; use ibc_relayer_types::clients::ics07_tendermint::client_state::{ ClientState as TmClientState, UpgradeOptions as TmUpgradeOptions, TENDERMINT_CLIENT_STATE_TYPE_URL, }; +use ibc_relayer_types::clients::ics09_localhost::v1::client_state::{ + ClientState as LocalhostClientState, LOCALHOST_CLIENT_STATE_TYPE_URL, +}; use ibc_relayer_types::core::ics02_client::client_state::{ downcast_client_state, ClientState, UpgradeOptions, }; @@ -31,6 +35,7 @@ use ibc_relayer_types::Height; #[serde(tag = "type")] pub enum AnyUpgradeOptions { Tendermint(TmUpgradeOptions), + Localhost(()), #[cfg(test)] Mock(()), @@ -40,8 +45,7 @@ impl AnyUpgradeOptions { fn as_tm_upgrade_options(&self) -> Option<&TmUpgradeOptions> { match self { AnyUpgradeOptions::Tendermint(tm) => Some(tm), - #[cfg(test)] - AnyUpgradeOptions::Mock(_) => None, + _ => None, } } } @@ -52,15 +56,27 @@ impl UpgradeOptions for AnyUpgradeOptions {} #[serde(tag = "type")] pub enum AnyClientState { Tendermint(TmClientState), + Localhost(LocalhostClientState), #[cfg(test)] Mock(MockClientState), } impl AnyClientState { + pub fn chain_id(&self) -> ChainId { + match self { + Self::Tendermint(tm_state) => tm_state.chain_id(), + Self::Localhost(local_state) => local_state.chain_id(), + + #[cfg(test)] + Self::Mock(mock_state) => mock_state.chain_id(), + } + } + pub fn latest_height(&self) -> Height { match self { Self::Tendermint(tm_state) => tm_state.latest_height(), + Self::Localhost(local_state) => local_state.latest_height(), #[cfg(test)] Self::Mock(mock_state) => mock_state.latest_height(), @@ -70,6 +86,7 @@ impl AnyClientState { pub fn frozen_height(&self) -> Option { match self { Self::Tendermint(tm_state) => tm_state.frozen_height(), + Self::Localhost(local_state) => local_state.frozen_height(), #[cfg(test)] Self::Mock(mock_state) => mock_state.frozen_height(), @@ -78,25 +95,28 @@ impl AnyClientState { pub fn trust_threshold(&self) -> Option { match self { - AnyClientState::Tendermint(state) => Some(state.trust_threshold), + Self::Tendermint(state) => Some(state.trust_threshold), + Self::Localhost(_) => None, #[cfg(test)] - AnyClientState::Mock(_) => None, + Self::Mock(_) => None, } } pub fn max_clock_drift(&self) -> Duration { match self { - AnyClientState::Tendermint(state) => state.max_clock_drift, + Self::Tendermint(state) => state.max_clock_drift, + Self::Localhost(_) => Duration::new(0, 0), #[cfg(test)] - AnyClientState::Mock(_) => Duration::new(0, 0), + Self::Mock(_) => Duration::new(0, 0), } } pub fn client_type(&self) -> ClientType { match self { Self::Tendermint(state) => state.client_type(), + Self::Localhost(state) => state.client_type(), #[cfg(test)] Self::Mock(state) => state.client_type(), @@ -106,6 +126,7 @@ impl AnyClientState { pub fn refresh_period(&self) -> Option { match self { AnyClientState::Tendermint(tm_state) => tm_state.refresh_time(), + AnyClientState::Localhost(_) => None, #[cfg(test)] AnyClientState::Mock(mock_state) => mock_state.refresh_time(), @@ -123,7 +144,12 @@ impl TryFrom for AnyClientState { "" => Err(Error::empty_client_state_response()), TENDERMINT_CLIENT_STATE_TYPE_URL => Ok(AnyClientState::Tendermint( - Protobuf::::decode_vec(&raw.value) + Protobuf::::decode_vec(&raw.value) + .map_err(Error::decode_raw_client_state)?, + )), + + LOCALHOST_CLIENT_STATE_TYPE_URL => Ok(AnyClientState::Localhost( + Protobuf::::decode_vec(&raw.value) .map_err(Error::decode_raw_client_state)?, )), @@ -143,8 +169,14 @@ impl From for Any { match value { AnyClientState::Tendermint(value) => Any { type_url: TENDERMINT_CLIENT_STATE_TYPE_URL.to_string(), - value: Protobuf::::encode_vec(&value), + value: Protobuf::::encode_vec(&value), + }, + + AnyClientState::Localhost(value) => Any { + type_url: LOCALHOST_CLIENT_STATE_TYPE_URL.to_string(), + value: Protobuf::::encode_vec(&value), }, + #[cfg(test)] AnyClientState::Mock(value) => Any { type_url: MOCK_CLIENT_STATE_TYPE_URL.to_string(), @@ -157,10 +189,11 @@ impl From for Any { impl ClientState for AnyClientState { fn chain_id(&self) -> ChainId { match self { - AnyClientState::Tendermint(tm_state) => tm_state.chain_id(), + AnyClientState::Tendermint(state) => state.chain_id(), + AnyClientState::Localhost(state) => state.chain_id(), #[cfg(test)] - AnyClientState::Mock(mock_state) => mock_state.chain_id(), + AnyClientState::Mock(state) => state.chain_id(), } } @@ -190,10 +223,14 @@ impl ClientState for AnyClientState { match self { AnyClientState::Tendermint(tm_state) => tm_state.upgrade( upgrade_height, - upgrade_options.as_tm_upgrade_options().unwrap(), + upgrade_options.as_tm_upgrade_options().unwrap(), // FIXME: This is very brittle chain_id, ), + AnyClientState::Localhost(local_state) => { + local_state.upgrade(upgrade_height, upgrade_options, chain_id) + } + #[cfg(test)] AnyClientState::Mock(mock_state) => { mock_state.upgrade(upgrade_height, upgrade_options, chain_id) @@ -204,6 +241,7 @@ impl ClientState for AnyClientState { fn expired(&self, elapsed_since_latest: Duration) -> bool { match self { AnyClientState::Tendermint(tm_state) => tm_state.expired(elapsed_since_latest), + AnyClientState::Localhost(local_state) => local_state.expired(elapsed_since_latest), #[cfg(test)] AnyClientState::Mock(mock_state) => mock_state.expired(elapsed_since_latest), @@ -217,6 +255,12 @@ impl From for AnyClientState { } } +impl From for AnyClientState { + fn from(cs: LocalhostClientState) -> Self { + Self::Localhost(cs) + } +} + #[cfg(test)] impl From for AnyClientState { fn from(cs: MockClientState) -> Self { From 1ad530d55306793af9a1e46d8c8ff7390038e04b Mon Sep 17 00:00:00 2001 From: Romain Ruetschi <106849+romac@users.noreply.github.com> Date: Wed, 13 Sep 2023 20:11:48 +0200 Subject: [PATCH 2/8] Remove unused ics18_relayer module --- crates/relayer-types/src/lib.rs | 1 - .../src/relayer/ics18_relayer/context.rs | 34 ----------------- .../src/relayer/ics18_relayer/error.rs | 38 ------------------- .../src/relayer/ics18_relayer/mod.rs | 4 -- crates/relayer-types/src/relayer/mod.rs | 5 --- crates/relayer/src/error.rs | 5 --- 6 files changed, 87 deletions(-) delete mode 100644 crates/relayer-types/src/relayer/ics18_relayer/context.rs delete mode 100644 crates/relayer-types/src/relayer/ics18_relayer/error.rs delete mode 100644 crates/relayer-types/src/relayer/ics18_relayer/mod.rs delete mode 100644 crates/relayer-types/src/relayer/mod.rs diff --git a/crates/relayer-types/src/lib.rs b/crates/relayer-types/src/lib.rs index 33ef64cdf3..c89d047d63 100644 --- a/crates/relayer-types/src/lib.rs +++ b/crates/relayer-types/src/lib.rs @@ -53,7 +53,6 @@ pub mod handler; pub mod keys; pub mod macros; pub mod proofs; -pub mod relayer; pub mod signer; pub mod timestamp; pub mod tx_msg; diff --git a/crates/relayer-types/src/relayer/ics18_relayer/context.rs b/crates/relayer-types/src/relayer/ics18_relayer/context.rs deleted file mode 100644 index c7a505914d..0000000000 --- a/crates/relayer-types/src/relayer/ics18_relayer/context.rs +++ /dev/null @@ -1,34 +0,0 @@ -use ibc_proto::google::protobuf::Any; - -use crate::core::ics02_client::client_state::ClientState; -use crate::core::ics02_client::header::Header; -use crate::events::IbcEvent; - -use crate::core::ics24_host::identifier::ClientId; -use crate::relayer::ics18_relayer::error::Error; -use crate::signer::Signer; -use crate::Height; - -/// Trait capturing all dependencies (i.e., the context) which algorithms in ICS18 require to -/// relay packets between chains. This trait comprises the dependencies towards a single chain. -/// Most of the functions in this represent wrappers over the ABCI interface. -/// This trait mimics the `Chain` trait, but at a lower level of abstraction (no networking, header -/// types, light client, RPC client, etc.) -pub trait Ics18Context { - /// Returns the latest height of the chain. - fn query_latest_height(&self) -> Height; - - /// Returns this client state for the given `client_id` on this chain. - /// Wrapper over the `/abci_query?path=..` endpoint. - fn query_client_full_state(&self, client_id: &ClientId) -> Option>; - - /// Returns the most advanced header of this chain. - fn query_latest_header(&self) -> Option>; - - /// Interface that the relayer uses to submit a datagram to this chain. - /// One can think of this as wrapping around the `/broadcast_tx_commit` ABCI endpoint. - fn send(&mut self, msgs: Vec) -> Result, Error>; - - /// Temporary solution. Similar to `CosmosSDKChain::key_and_signer()` but simpler. - fn signer(&self) -> Signer; -} diff --git a/crates/relayer-types/src/relayer/ics18_relayer/error.rs b/crates/relayer-types/src/relayer/ics18_relayer/error.rs deleted file mode 100644 index e975de5a3a..0000000000 --- a/crates/relayer-types/src/relayer/ics18_relayer/error.rs +++ /dev/null @@ -1,38 +0,0 @@ -use crate::core::ics24_host::identifier::ClientId; -use crate::core::ics26_routing::error::Error as RoutingError; -use crate::Height; -use flex_error::define_error; - -define_error! { - Error { - ClientStateNotFound - { client_id: ClientId } - | e | { format_args!("client state on destination chain not found, (client id: {0})", e.client_id) }, - - ClientAlreadyUpToDate - { - client_id: ClientId, - source_height: Height, - destination_height: Height, - } - | e | { - format_args!("the client on destination chain is already up-to-date (client id: {0}, source height: {1}, dest height: {2})", - e.client_id, e.source_height, e.destination_height) - }, - - ClientAtHigherHeight - { - client_id: ClientId, - source_height: Height, - destination_height: Height, - } - | e | { - format_args!("the client on destination chain is at a higher height (client id: {0}, source height: {1}, dest height: {2})", - e.client_id, e.source_height, e.destination_height) - }, - - TransactionFailed - [ RoutingError ] - | _ | { "transaction processing by modules failed" }, - } -} diff --git a/crates/relayer-types/src/relayer/ics18_relayer/mod.rs b/crates/relayer-types/src/relayer/ics18_relayer/mod.rs deleted file mode 100644 index 8a7f14e5b6..0000000000 --- a/crates/relayer-types/src/relayer/ics18_relayer/mod.rs +++ /dev/null @@ -1,4 +0,0 @@ -//! ICS 18: Relayer contains utilities for testing `ibc` against the Hermes relayer. - -pub mod context; -pub mod error; diff --git a/crates/relayer-types/src/relayer/mod.rs b/crates/relayer-types/src/relayer/mod.rs deleted file mode 100644 index 3749606559..0000000000 --- a/crates/relayer-types/src/relayer/mod.rs +++ /dev/null @@ -1,5 +0,0 @@ -//! Utilities for testing the `ibc` crate against the [Hermes IBC relayer][relayer-repo]. -//! -//! [relayer-repo]: https://github.com/informalsystems/hermes/tree/master/crates/relayer - -pub mod ics18_relayer; diff --git a/crates/relayer/src/error.rs b/crates/relayer/src/error.rs index 10e97c08b7..780ac5be63 100644 --- a/crates/relayer/src/error.rs +++ b/crates/relayer/src/error.rs @@ -35,7 +35,6 @@ use ibc_relayer_types::{ ics24_host::identifier::{ChainId, ChannelId, ConnectionId}, }, proofs::ProofError, - relayer::ics18_relayer::error as relayer_error, }; use crate::chain::cosmos::version; @@ -281,10 +280,6 @@ define_error! { [ tendermint_error::Error ] |_| { "ICS 07 error" }, - Ics18 - [ relayer_error::Error ] - |_| { "ICS 18 error" }, - Ics23 [ commitment_error::Error ] |_| { "ICS 23 error" }, From 30c80af2cb9dc7d1242c33a65f625e90585ddf17 Mon Sep 17 00:00:00 2001 From: Romain Ruetschi <106849+romac@users.noreply.github.com> Date: Wed, 13 Sep 2023 20:22:00 +0200 Subject: [PATCH 3/8] Remove dynamically typed hacks formerly used to construct client upgrades --- .../clients/ics07_tendermint/client_state.rs | 47 +++++----- .../ics09_localhost/v1/client_state.rs | 11 --- .../src/core/ics02_client/client_state.rs | 85 ++----------------- crates/relayer-types/src/mock/client_state.rs | 27 +----- crates/relayer/src/client_state.rs | 72 +--------------- crates/relayer/src/upgrade_chain.rs | 4 +- 6 files changed, 34 insertions(+), 212 deletions(-) diff --git a/crates/relayer-types/src/clients/ics07_tendermint/client_state.rs b/crates/relayer-types/src/clients/ics07_tendermint/client_state.rs index 0e0f800653..1c3d976cdc 100644 --- a/crates/relayer-types/src/clients/ics07_tendermint/client_state.rs +++ b/crates/relayer-types/src/clients/ics07_tendermint/client_state.rs @@ -14,7 +14,7 @@ use tendermint_light_client_verifier::options::Options; use crate::clients::ics07_tendermint::error::Error; use crate::clients::ics07_tendermint::header::Header as TmHeader; use crate::core::ics02_client::client_state::{ - ClientState as Ics2ClientState, UpgradeOptions as CoreUpgradeOptions, + ClientState as Ics2ClientState, UpgradableClientState, }; use crate::core::ics02_client::client_type::ClientType; use crate::core::ics02_client::error::Error as Ics02Error; @@ -199,36 +199,15 @@ pub struct UpgradeOptions { pub unbonding_period: Duration, } -impl CoreUpgradeOptions for UpgradeOptions {} - -impl Ics2ClientState for ClientState { - fn chain_id(&self) -> ChainId { - self.chain_id.clone() - } - - fn client_type(&self) -> ClientType { - ClientType::Tendermint - } - - fn latest_height(&self) -> Height { - self.latest_height - } - - fn frozen_height(&self) -> Option { - self.frozen_height - } +impl UpgradableClientState for ClientState { + type UpgradeOptions = UpgradeOptions; fn upgrade( &mut self, upgrade_height: Height, - upgrade_options: &dyn CoreUpgradeOptions, + upgrade_options: UpgradeOptions, chain_id: ChainId, ) { - let upgrade_options = upgrade_options - .as_any() - .downcast_ref::() - .expect("UpgradeOptions not of type Tendermint"); - // Reset custom fields to zero values self.trusting_period = ZERO_DURATION; self.trust_threshold = TrustThreshold::CLIENT_STATE_RESET; @@ -242,6 +221,24 @@ impl Ics2ClientState for ClientState { self.unbonding_period = upgrade_options.unbonding_period; self.chain_id = chain_id; } +} + +impl Ics2ClientState for ClientState { + fn chain_id(&self) -> ChainId { + self.chain_id.clone() + } + + fn client_type(&self) -> ClientType { + ClientType::Tendermint + } + + fn latest_height(&self) -> Height { + self.latest_height + } + + fn frozen_height(&self) -> Option { + self.frozen_height + } fn expired(&self, elapsed: Duration) -> bool { elapsed > self.trusting_period diff --git a/crates/relayer-types/src/clients/ics09_localhost/v1/client_state.rs b/crates/relayer-types/src/clients/ics09_localhost/v1/client_state.rs index d548e13280..80f724ed48 100644 --- a/crates/relayer-types/src/clients/ics09_localhost/v1/client_state.rs +++ b/crates/relayer-types/src/clients/ics09_localhost/v1/client_state.rs @@ -9,7 +9,6 @@ use ibc_proto::ibc::lightclients::localhost::v1::ClientState as RawClientState; use ibc_proto::protobuf::Protobuf; use crate::core::ics02_client::client_state::ClientState as Ics02ClientState; -use crate::core::ics02_client::client_state::UpgradeOptions; use crate::core::ics02_client::client_type::ClientType; use crate::core::ics02_client::error::Error as Ics02Error; use crate::core::ics24_host::identifier::ChainId; @@ -52,16 +51,6 @@ impl Ics02ClientState for ClientState { None } - fn upgrade( - &mut self, - upgrade_height: Height, - _upgrade_options: &dyn UpgradeOptions, - chain_id: ChainId, - ) { - self.height = upgrade_height; - self.chain_id = chain_id; - } - fn expired(&self, _elapsed: Duration) -> bool { false } diff --git a/crates/relayer-types/src/core/ics02_client/client_state.rs b/crates/relayer-types/src/core/ics02_client/client_state.rs index 08c6e5677c..2cdcba9783 100644 --- a/crates/relayer-types/src/core/ics02_client/client_state.rs +++ b/crates/relayer-types/src/core/ics02_client/client_state.rs @@ -1,30 +1,13 @@ +use core::fmt::Debug; use std::marker::{Send, Sync}; use std::time::Duration; -use dyn_clone::DynClone; -use erased_serde::Serialize as ErasedSerialize; -use ibc_proto::google::protobuf::Any; -use ibc_proto::protobuf::Protobuf as ErasedProtobuf; - use crate::core::ics02_client::client_type::ClientType; -use crate::core::ics02_client::error::Error; use crate::core::ics24_host::identifier::ChainId; -use crate::dynamic_typing::AsAny; use crate::Height; -use super::consensus_state::ConsensusState; - -pub trait ClientState: - AsAny - + sealed::ErasedPartialEqClientState - + DynClone - + ErasedSerialize - + ErasedProtobuf - + core::fmt::Debug - + Send - + Sync -{ +pub trait ClientState: Clone + PartialEq + Debug + Send + Sync { /// Return the chain identifier which this client is serving (i.e., the client is verifying /// consensus states from this chain). fn chain_id(&self) -> ChainId; @@ -46,6 +29,10 @@ pub trait ClientState: /// Check if the state is expired when `elapsed` time has passed since the latest consensus /// state timestamp fn expired(&self, elapsed: Duration) -> bool; +} + +pub trait UpgradableClientState: ClientState { + type UpgradeOptions; /// Helper function to verify the upgrade client procedure. /// Resets all fields except the blockchain-specific ones, @@ -53,65 +40,7 @@ pub trait ClientState: fn upgrade( &mut self, upgrade_height: Height, - upgrade_options: &dyn UpgradeOptions, + upgrade_options: Self::UpgradeOptions, chain_id: ChainId, ); - - /// Convert into a boxed trait object - fn into_box(self) -> Box - where - Self: Sized, - { - Box::new(self) - } -} - -// Implements `Clone` for `Box` -dyn_clone::clone_trait_object!(ClientState); - -// Implements `serde::Serialize` for all types that have ClientState as supertrait -erased_serde::serialize_trait_object!(ClientState); - -impl PartialEq for dyn ClientState { - fn eq(&self, other: &Self) -> bool { - self.eq_client_state(other) - } -} - -// see https://github.com/rust-lang/rust/issues/31740 -impl PartialEq<&Self> for Box { - fn eq(&self, other: &&Self) -> bool { - self.eq_client_state(other.as_ref()) - } -} - -pub fn downcast_client_state(h: &dyn ClientState) -> Option<&CS> { - h.as_any().downcast_ref::() -} - -pub trait UpgradeOptions: AsAny {} - -pub struct UpdatedState { - pub client_state: Box, - pub consensus_state: Box, -} - -mod sealed { - use super::*; - - pub trait ErasedPartialEqClientState { - fn eq_client_state(&self, other: &dyn ClientState) -> bool; - } - - impl ErasedPartialEqClientState for CS - where - CS: ClientState + PartialEq, - { - fn eq_client_state(&self, other: &dyn ClientState) -> bool { - other - .as_any() - .downcast_ref::() - .map_or(false, |h| self == h) - } - } } diff --git a/crates/relayer-types/src/mock/client_state.rs b/crates/relayer-types/src/mock/client_state.rs index 320d15aafb..64a4c1c19d 100644 --- a/crates/relayer-types/src/mock/client_state.rs +++ b/crates/relayer-types/src/mock/client_state.rs @@ -1,4 +1,3 @@ -use std::collections::HashMap; use std::time::Duration; use serde::{Deserialize, Serialize}; @@ -7,9 +6,8 @@ use ibc_proto::google::protobuf::Any; use ibc_proto::ibc::mock::ClientState as RawMockClientState; use ibc_proto::protobuf::Protobuf; -use crate::core::ics02_client::client_state::{ClientState, UpgradeOptions}; +use crate::core::ics02_client::client_state::ClientState; use crate::core::ics02_client::client_type::ClientType; -use crate::core::ics02_client::consensus_state::ConsensusState; use crate::core::ics02_client::error::Error; use crate::core::ics24_host::identifier::ChainId; @@ -21,20 +19,6 @@ use crate::Height; pub const MOCK_CLIENT_STATE_TYPE_URL: &str = "/ibc.mock.ClientState"; -/// A mock of an IBC client record as it is stored in a mock context. -/// For testing ICS02 handlers mostly, cf. `MockClientContext`. -#[derive(Clone, Debug)] -pub struct MockClientRecord { - /// The type of this client. - pub client_type: ClientType, - - /// The client state (representing only the latest height at the moment). - pub client_state: Option>, - - /// Mapping of heights to consensus states for this client. - pub consensus_states: HashMap>, -} - /// A mock of a client state. For an example of a real structure that this mocks, you can see /// `ClientState` of ics07_tendermint/client_state.rs. #[derive(Copy, Clone, Debug, PartialEq, Eq, Serialize, Deserialize)] @@ -132,15 +116,6 @@ impl ClientState for MockClientState { self.frozen_height } - fn upgrade( - &mut self, - _upgrade_height: Height, - _upgrade_options: &dyn UpgradeOptions, - _chain_id: ChainId, - ) { - unimplemented!() - } - fn expired(&self, _elapsed: Duration) -> bool { false } diff --git a/crates/relayer/src/client_state.rs b/crates/relayer/src/client_state.rs index eb43de0bab..d72753279f 100644 --- a/crates/relayer/src/client_state.rs +++ b/crates/relayer/src/client_state.rs @@ -10,15 +10,12 @@ use ibc_proto::ibc::lightclients::tendermint::v1::ClientState as RawTmClientStat use ibc_proto::ibc::mock::ClientState as RawMockClientState; use ibc_proto::protobuf::Protobuf; use ibc_relayer_types::clients::ics07_tendermint::client_state::{ - ClientState as TmClientState, UpgradeOptions as TmUpgradeOptions, - TENDERMINT_CLIENT_STATE_TYPE_URL, + ClientState as TmClientState, TENDERMINT_CLIENT_STATE_TYPE_URL, }; use ibc_relayer_types::clients::ics09_localhost::v1::client_state::{ ClientState as LocalhostClientState, LOCALHOST_CLIENT_STATE_TYPE_URL, }; -use ibc_relayer_types::core::ics02_client::client_state::{ - downcast_client_state, ClientState, UpgradeOptions, -}; +use ibc_relayer_types::core::ics02_client::client_state::ClientState; use ibc_relayer_types::core::ics02_client::client_type::ClientType; use ibc_relayer_types::core::ics02_client::error::Error; use ibc_relayer_types::core::ics02_client::trust_threshold::TrustThreshold; @@ -31,27 +28,6 @@ use ibc_relayer_types::mock::client_state::MockClientState; use ibc_relayer_types::mock::client_state::MOCK_CLIENT_STATE_TYPE_URL; use ibc_relayer_types::Height; -#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)] -#[serde(tag = "type")] -pub enum AnyUpgradeOptions { - Tendermint(TmUpgradeOptions), - Localhost(()), - - #[cfg(test)] - Mock(()), -} - -impl AnyUpgradeOptions { - fn as_tm_upgrade_options(&self) -> Option<&TmUpgradeOptions> { - match self { - AnyUpgradeOptions::Tendermint(tm) => Some(tm), - _ => None, - } - } -} - -impl UpgradeOptions for AnyUpgradeOptions {} - #[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] #[serde(tag = "type")] pub enum AnyClientState { @@ -209,35 +185,6 @@ impl ClientState for AnyClientState { self.frozen_height() } - fn upgrade( - &mut self, - upgrade_height: Height, - upgrade_options: &dyn UpgradeOptions, - chain_id: ChainId, - ) { - let upgrade_options = upgrade_options - .as_any() - .downcast_ref::() - .expect("UpgradeOptions not of type AnyUpgradeOptions"); - - match self { - AnyClientState::Tendermint(tm_state) => tm_state.upgrade( - upgrade_height, - upgrade_options.as_tm_upgrade_options().unwrap(), // FIXME: This is very brittle - chain_id, - ), - - AnyClientState::Localhost(local_state) => { - local_state.upgrade(upgrade_height, upgrade_options, chain_id) - } - - #[cfg(test)] - AnyClientState::Mock(mock_state) => { - mock_state.upgrade(upgrade_height, upgrade_options, chain_id) - } - } - } - fn expired(&self, elapsed_since_latest: Duration) -> bool { match self { AnyClientState::Tendermint(tm_state) => tm_state.expired(elapsed_since_latest), @@ -268,21 +215,6 @@ impl From for AnyClientState { } } -impl From<&dyn ClientState> for AnyClientState { - fn from(client_state: &dyn ClientState) -> Self { - #[cfg(test)] - if let Some(cs) = downcast_client_state::(client_state) { - return AnyClientState::from(*cs); - } - - if let Some(cs) = downcast_client_state::(client_state) { - AnyClientState::from(cs.clone()) - } else { - unreachable!() - } - } -} - #[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] #[serde(tag = "type")] pub struct IdentifiedAnyClientState { diff --git a/crates/relayer/src/upgrade_chain.rs b/crates/relayer/src/upgrade_chain.rs index d885fa5a0e..99b1d11c33 100644 --- a/crates/relayer/src/upgrade_chain.rs +++ b/crates/relayer/src/upgrade_chain.rs @@ -13,7 +13,7 @@ use ibc_proto::cosmos::upgrade::v1beta1::Plan; use ibc_proto::google::protobuf::Any; use ibc_proto::ibc::core::client::v1::UpgradeProposal; use ibc_relayer_types::clients::ics07_tendermint::client_state::UpgradeOptions; -use ibc_relayer_types::core::ics02_client::client_state::ClientState; +use ibc_relayer_types::core::ics02_client::client_state::UpgradableClientState; use ibc_relayer_types::core::ics24_host::identifier::{ChainId, ClientId}; use ibc_relayer_types::{downcast, Height}; @@ -109,7 +109,7 @@ pub fn build_and_send_ibc_upgrade_proposal( client_state.upgrade( upgraded_client_latest_height, - &upgrade_options, + upgrade_options, opts.upgraded_chain_id.clone(), ); From 4f6d59cfafdfb4fb38a72c4e06b80b00d9a46033 Mon Sep 17 00:00:00 2001 From: Romain Ruetschi <106849+romac@users.noreply.github.com> Date: Wed, 13 Sep 2023 20:22:14 +0200 Subject: [PATCH 4/8] Add support for localhost.v2 client state --- .../ics09_localhost/v1/client_state.rs | 8 +- .../src/clients/ics09_localhost/v1/error.rs | 12 -- .../ics09_localhost/v2/client_state.rs | 126 ++++++++++++++++++ .../src/clients/ics09_localhost/v2/error.rs | 39 ++++++ .../src/clients/ics09_localhost/v2/mod.rs | 1 + crates/relayer/src/client_state.rs | 71 +++++++--- 6 files changed, 221 insertions(+), 36 deletions(-) create mode 100644 crates/relayer-types/src/clients/ics09_localhost/v2/error.rs diff --git a/crates/relayer-types/src/clients/ics09_localhost/v1/client_state.rs b/crates/relayer-types/src/clients/ics09_localhost/v1/client_state.rs index 80f724ed48..87961bd550 100644 --- a/crates/relayer-types/src/clients/ics09_localhost/v1/client_state.rs +++ b/crates/relayer-types/src/clients/ics09_localhost/v1/client_state.rs @@ -16,7 +16,7 @@ use crate::Height; use super::error::Error; -pub const LOCALHOST_CLIENT_STATE_TYPE_URL: &str = "/ibc.lightclients.localhost.v1.ClientState"; +pub const LOCALHOST_V1_CLIENT_STATE_TYPE_URL: &str = "/ibc.lightclients.localhost.v1.ClientState"; #[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] pub struct ClientState { @@ -98,11 +98,11 @@ impl TryFrom for ClientState { } match raw.type_url.as_str() { - LOCALHOST_CLIENT_STATE_TYPE_URL => { + LOCALHOST_V1_CLIENT_STATE_TYPE_URL => { decode_client_state(raw.value.deref()).map_err(Into::into) } _ => Err(Ics02Error::unexpected_client_state_type( - LOCALHOST_CLIENT_STATE_TYPE_URL.to_string(), + LOCALHOST_V1_CLIENT_STATE_TYPE_URL.to_string(), raw.type_url, )), } @@ -112,7 +112,7 @@ impl TryFrom for ClientState { impl From for Any { fn from(client_state: ClientState) -> Self { Any { - type_url: LOCALHOST_CLIENT_STATE_TYPE_URL.to_string(), + type_url: LOCALHOST_V1_CLIENT_STATE_TYPE_URL.to_string(), value: Protobuf::::encode_vec(&client_state), } } diff --git a/crates/relayer-types/src/clients/ics09_localhost/v1/error.rs b/crates/relayer-types/src/clients/ics09_localhost/v1/error.rs index 738b5f2f22..ae6c9e2744 100644 --- a/crates/relayer-types/src/clients/ics09_localhost/v1/error.rs +++ b/crates/relayer-types/src/clients/ics09_localhost/v1/error.rs @@ -3,8 +3,6 @@ use flex_error::{define_error, TraceError}; use crate::core::ics02_client::error::Error as Ics02Error; use crate::core::ics24_host::error::ValidationError; -use crate::Height; - define_error! { #[derive(Debug, PartialEq, Eq)] Error { @@ -31,16 +29,6 @@ define_error! { Decode [ TraceError ] |_| { "decode error" }, - - InsufficientHeight - { - latest_height: Height, - target_height: Height, - } - |e| { - format_args!("the height is insufficient: latest_height={0} target_height={1}", - e.latest_height, e.target_height) - }, } } diff --git a/crates/relayer-types/src/clients/ics09_localhost/v2/client_state.rs b/crates/relayer-types/src/clients/ics09_localhost/v2/client_state.rs index 139597f9cb..756f7682b4 100644 --- a/crates/relayer-types/src/clients/ics09_localhost/v2/client_state.rs +++ b/crates/relayer-types/src/clients/ics09_localhost/v2/client_state.rs @@ -1,2 +1,128 @@ +use std::convert::{TryFrom, TryInto}; +use std::time::Duration; +use prost::Message; +use serde::{Deserialize, Serialize}; +use ibc_proto::google::protobuf::Any; +use ibc_proto::ibc::core::client::v1::Height as RawHeight; +use ibc_proto::protobuf::Protobuf; + +use crate::core::ics02_client::client_state::ClientState as Ics02ClientState; +use crate::core::ics02_client::client_type::ClientType; +use crate::core::ics02_client::error::Error as Ics02Error; +use crate::core::ics24_host::identifier::ChainId; +use crate::Height; + +use super::error::Error; + +// use ibc_proto::ibc::lightclients::localhost::v2::ClientState as RawClientState; + +/// ClientState defines the 09-localhost client state +#[derive(Serialize, Deserialize)] +#[allow(clippy::derive_partial_eq_without_eq)] +#[derive(Clone, PartialEq, ::prost::Message)] +pub struct RawClientState { + /// the latest block height + #[prost(message, optional, tag = "1")] + pub latest_height: ::core::option::Option, +} + +pub const LOCALHOST_V2_CLIENT_STATE_TYPE_URL: &str = "/ibc.lightclients.localhost.v2.ClientState"; + +#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] +pub struct ClientState { + pub latest_height: Height, +} + +impl ClientState { + pub fn new(latest_height: Height) -> ClientState { + Self { latest_height } + } + + pub fn height(&self) -> Height { + self.latest_height + } +} + +impl Ics02ClientState for ClientState { + fn chain_id(&self) -> ChainId { + unimplemented!() + } + + fn client_type(&self) -> ClientType { + ClientType::Localhost + } + + fn latest_height(&self) -> Height { + self.latest_height + } + + fn frozen_height(&self) -> Option { + None + } + + fn expired(&self, _elapsed: Duration) -> bool { + false + } +} + +impl Protobuf for ClientState {} + +impl TryFrom for ClientState { + type Error = Error; + + fn try_from(raw: RawClientState) -> Result { + Ok(Self { + latest_height: raw + .latest_height + .ok_or_else(Error::missing_latest_height)? + .try_into() + .map_err(|_| Error::missing_latest_height())?, + }) + } +} + +impl From for RawClientState { + fn from(value: ClientState) -> Self { + Self { + latest_height: Some(value.latest_height.into()), + } + } +} + +impl Protobuf for ClientState {} + +impl TryFrom for ClientState { + type Error = Ics02Error; + + fn try_from(raw: Any) -> Result { + use bytes::Buf; + use core::ops::Deref; + + fn decode_client_state(buf: B) -> Result { + RawClientState::decode(buf) + .map_err(Error::decode)? + .try_into() + } + + match raw.type_url.as_str() { + LOCALHOST_V2_CLIENT_STATE_TYPE_URL => { + decode_client_state(raw.value.deref()).map_err(Into::into) + } + _ => Err(Ics02Error::unexpected_client_state_type( + LOCALHOST_V2_CLIENT_STATE_TYPE_URL.to_string(), + raw.type_url, + )), + } + } +} + +impl From for Any { + fn from(client_state: ClientState) -> Self { + Any { + type_url: LOCALHOST_V2_CLIENT_STATE_TYPE_URL.to_string(), + value: Protobuf::::encode_vec(&client_state), + } + } +} diff --git a/crates/relayer-types/src/clients/ics09_localhost/v2/error.rs b/crates/relayer-types/src/clients/ics09_localhost/v2/error.rs new file mode 100644 index 0000000000..bec9685532 --- /dev/null +++ b/crates/relayer-types/src/clients/ics09_localhost/v2/error.rs @@ -0,0 +1,39 @@ +use flex_error::{define_error, TraceError}; + +use crate::core::ics02_client::error::Error as Ics02Error; +use crate::core::ics24_host::error::ValidationError; + +define_error! { + #[derive(Debug, PartialEq, Eq)] + Error { + InvalidRawClientState + { reason: String } + |e| { format_args!("invalid raw client state: {}", e.reason) }, + + InvalidChainIdentifier + [ ValidationError ] + |_| { "invalid chain identifier" }, + + MissingLatestHeight + |_| { "missing latest height" }, + + InvalidChainId + { raw_value: String } + [ ValidationError ] + |e| { format_args!("invalid chain identifier: {}", e.raw_value) }, + + InvalidRawHeight + { raw_height: u64 } + |e| { format_args!("invalid raw height: {}", e.raw_height) }, + + Decode + [ TraceError ] + |_| { "decode error" }, + } +} + +impl From for Ics02Error { + fn from(e: Error) -> Self { + Self::client_specific(e.to_string()) + } +} diff --git a/crates/relayer-types/src/clients/ics09_localhost/v2/mod.rs b/crates/relayer-types/src/clients/ics09_localhost/v2/mod.rs index 1afebe67a2..6e8e2e71ae 100644 --- a/crates/relayer-types/src/clients/ics09_localhost/v2/mod.rs +++ b/crates/relayer-types/src/clients/ics09_localhost/v2/mod.rs @@ -1 +1,2 @@ pub mod client_state; +pub mod error; diff --git a/crates/relayer/src/client_state.rs b/crates/relayer/src/client_state.rs index d72753279f..a431dedce9 100644 --- a/crates/relayer/src/client_state.rs +++ b/crates/relayer/src/client_state.rs @@ -4,7 +4,8 @@ use serde::{Deserialize, Serialize}; use ibc_proto::google::protobuf::Any; use ibc_proto::ibc::core::client::v1::IdentifiedClientState; -use ibc_proto::ibc::lightclients::localhost::v1::ClientState as RawLocalhostClientState; +use ibc_proto::ibc::lightclients::localhost::v1::ClientState as RawLocalhostV1ClientState; +// use ibc_proto::ibc::lightclients::localhost::v2::ClientState as RawLocalhostV2ClientState; use ibc_proto::ibc::lightclients::tendermint::v1::ClientState as RawTmClientState; #[cfg(test)] use ibc_proto::ibc::mock::ClientState as RawMockClientState; @@ -13,7 +14,11 @@ use ibc_relayer_types::clients::ics07_tendermint::client_state::{ ClientState as TmClientState, TENDERMINT_CLIENT_STATE_TYPE_URL, }; use ibc_relayer_types::clients::ics09_localhost::v1::client_state::{ - ClientState as LocalhostClientState, LOCALHOST_CLIENT_STATE_TYPE_URL, + ClientState as LocalhostV1ClientState, LOCALHOST_V1_CLIENT_STATE_TYPE_URL, +}; +use ibc_relayer_types::clients::ics09_localhost::v2::client_state::{ + ClientState as LocalhostV2ClientState, RawClientState as RawLocalhostV2ClientState, + LOCALHOST_V2_CLIENT_STATE_TYPE_URL, }; use ibc_relayer_types::core::ics02_client::client_state::ClientState; use ibc_relayer_types::core::ics02_client::client_type::ClientType; @@ -32,7 +37,8 @@ use ibc_relayer_types::Height; #[serde(tag = "type")] pub enum AnyClientState { Tendermint(TmClientState), - Localhost(LocalhostClientState), + LocalhostV1(LocalhostV1ClientState), + LocalhostV2(LocalhostV2ClientState), #[cfg(test)] Mock(MockClientState), @@ -42,7 +48,8 @@ impl AnyClientState { pub fn chain_id(&self) -> ChainId { match self { Self::Tendermint(tm_state) => tm_state.chain_id(), - Self::Localhost(local_state) => local_state.chain_id(), + Self::LocalhostV1(local_state) => local_state.chain_id(), + Self::LocalhostV2(local_state) => local_state.chain_id(), #[cfg(test)] Self::Mock(mock_state) => mock_state.chain_id(), @@ -52,7 +59,8 @@ impl AnyClientState { pub fn latest_height(&self) -> Height { match self { Self::Tendermint(tm_state) => tm_state.latest_height(), - Self::Localhost(local_state) => local_state.latest_height(), + Self::LocalhostV1(local_state) => local_state.latest_height(), + Self::LocalhostV2(local_state) => local_state.latest_height(), #[cfg(test)] Self::Mock(mock_state) => mock_state.latest_height(), @@ -62,7 +70,8 @@ impl AnyClientState { pub fn frozen_height(&self) -> Option { match self { Self::Tendermint(tm_state) => tm_state.frozen_height(), - Self::Localhost(local_state) => local_state.frozen_height(), + Self::LocalhostV1(local_state) => local_state.frozen_height(), + Self::LocalhostV2(local_state) => local_state.frozen_height(), #[cfg(test)] Self::Mock(mock_state) => mock_state.frozen_height(), @@ -72,7 +81,8 @@ impl AnyClientState { pub fn trust_threshold(&self) -> Option { match self { Self::Tendermint(state) => Some(state.trust_threshold), - Self::Localhost(_) => None, + Self::LocalhostV1(_) => None, + Self::LocalhostV2(_) => None, #[cfg(test)] Self::Mock(_) => None, @@ -82,7 +92,8 @@ impl AnyClientState { pub fn max_clock_drift(&self) -> Duration { match self { Self::Tendermint(state) => state.max_clock_drift, - Self::Localhost(_) => Duration::new(0, 0), + Self::LocalhostV1(_) => Duration::new(0, 0), + Self::LocalhostV2(_) => Duration::new(0, 0), #[cfg(test)] Self::Mock(_) => Duration::new(0, 0), @@ -92,7 +103,8 @@ impl AnyClientState { pub fn client_type(&self) -> ClientType { match self { Self::Tendermint(state) => state.client_type(), - Self::Localhost(state) => state.client_type(), + Self::LocalhostV1(state) => state.client_type(), + Self::LocalhostV2(state) => state.client_type(), #[cfg(test)] Self::Mock(state) => state.client_type(), @@ -102,7 +114,8 @@ impl AnyClientState { pub fn refresh_period(&self) -> Option { match self { AnyClientState::Tendermint(tm_state) => tm_state.refresh_time(), - AnyClientState::Localhost(_) => None, + AnyClientState::LocalhostV1(_) => None, + AnyClientState::LocalhostV2(_) => None, #[cfg(test)] AnyClientState::Mock(mock_state) => mock_state.refresh_time(), @@ -124,8 +137,13 @@ impl TryFrom for AnyClientState { .map_err(Error::decode_raw_client_state)?, )), - LOCALHOST_CLIENT_STATE_TYPE_URL => Ok(AnyClientState::Localhost( - Protobuf::::decode_vec(&raw.value) + LOCALHOST_V1_CLIENT_STATE_TYPE_URL => Ok(AnyClientState::LocalhostV1( + Protobuf::::decode_vec(&raw.value) + .map_err(Error::decode_raw_client_state)?, + )), + + LOCALHOST_V2_CLIENT_STATE_TYPE_URL => Ok(AnyClientState::LocalhostV2( + Protobuf::::decode_vec(&raw.value) .map_err(Error::decode_raw_client_state)?, )), @@ -148,9 +166,14 @@ impl From for Any { value: Protobuf::::encode_vec(&value), }, - AnyClientState::Localhost(value) => Any { - type_url: LOCALHOST_CLIENT_STATE_TYPE_URL.to_string(), - value: Protobuf::::encode_vec(&value), + AnyClientState::LocalhostV1(value) => Any { + type_url: LOCALHOST_V1_CLIENT_STATE_TYPE_URL.to_string(), + value: Protobuf::::encode_vec(&value), + }, + + AnyClientState::LocalhostV2(value) => Any { + type_url: LOCALHOST_V2_CLIENT_STATE_TYPE_URL.to_string(), + value: Protobuf::::encode_vec(&value), }, #[cfg(test)] @@ -166,7 +189,8 @@ impl ClientState for AnyClientState { fn chain_id(&self) -> ChainId { match self { AnyClientState::Tendermint(state) => state.chain_id(), - AnyClientState::Localhost(state) => state.chain_id(), + AnyClientState::LocalhostV1(state) => state.chain_id(), + AnyClientState::LocalhostV2(state) => state.chain_id(), #[cfg(test)] AnyClientState::Mock(state) => state.chain_id(), @@ -188,7 +212,8 @@ impl ClientState for AnyClientState { fn expired(&self, elapsed_since_latest: Duration) -> bool { match self { AnyClientState::Tendermint(tm_state) => tm_state.expired(elapsed_since_latest), - AnyClientState::Localhost(local_state) => local_state.expired(elapsed_since_latest), + AnyClientState::LocalhostV1(local_state) => local_state.expired(elapsed_since_latest), + AnyClientState::LocalhostV2(local_state) => local_state.expired(elapsed_since_latest), #[cfg(test)] AnyClientState::Mock(mock_state) => mock_state.expired(elapsed_since_latest), @@ -202,9 +227,15 @@ impl From for AnyClientState { } } -impl From for AnyClientState { - fn from(cs: LocalhostClientState) -> Self { - Self::Localhost(cs) +impl From for AnyClientState { + fn from(cs: LocalhostV1ClientState) -> Self { + Self::LocalhostV1(cs) + } +} + +impl From for AnyClientState { + fn from(cs: LocalhostV2ClientState) -> Self { + Self::LocalhostV2(cs) } } From 021795190b31d7fcbe09d78aed9786ac4c44430e Mon Sep 17 00:00:00 2001 From: Romain Ruetschi <106849+romac@users.noreply.github.com> Date: Wed, 13 Sep 2023 20:36:30 +0200 Subject: [PATCH 5/8] Cleanup --- crates/relayer-cli/src/cli_utils.rs | 1 - .../src/commands/create/channel.rs | 1 - .../src/commands/create/connection.rs | 1 - .../src/commands/query/channel_ends.rs | 1 - .../src/commands/query/channels.rs | 1 - .../relayer-cli/src/commands/query/clients.rs | 1 - .../src/commands/query/connections.rs | 1 - crates/relayer-cli/src/commands/tx/client.rs | 1 - crates/relayer/src/chain/counterparty.rs | 1 - crates/relayer/src/client_state.rs | 29 +++++++++---------- crates/relayer/src/object.rs | 2 +- .../src/supervisor/client_state_filter.rs | 1 - crates/relayer/src/supervisor/scan.rs | 1 - crates/relayer/src/supervisor/spawn.rs | 2 +- 14 files changed, 15 insertions(+), 29 deletions(-) diff --git a/crates/relayer-cli/src/cli_utils.rs b/crates/relayer-cli/src/cli_utils.rs index 5a2aae7fc0..cb08656c84 100644 --- a/crates/relayer-cli/src/cli_utils.rs +++ b/crates/relayer-cli/src/cli_utils.rs @@ -16,7 +16,6 @@ use ibc_relayer::{ config::Config, spawn, }; -use ibc_relayer_types::core::ics02_client::client_state::ClientState; use ibc_relayer_types::core::ics24_host::identifier::{ChainId, ChannelId, PortId}; use crate::error::Error; diff --git a/crates/relayer-cli/src/commands/create/channel.rs b/crates/relayer-cli/src/commands/create/channel.rs index 3de03a257a..b949adff72 100644 --- a/crates/relayer-cli/src/commands/create/channel.rs +++ b/crates/relayer-cli/src/commands/create/channel.rs @@ -11,7 +11,6 @@ use ibc_relayer::chain::requests::{ use ibc_relayer::channel::Channel; use ibc_relayer::connection::Connection; use ibc_relayer::foreign_client::ForeignClient; -use ibc_relayer_types::core::ics02_client::client_state::ClientState; use ibc_relayer_types::core::ics03_connection::connection::IdentifiedConnectionEnd; use ibc_relayer_types::core::ics04_channel::channel::Ordering; use ibc_relayer_types::core::ics04_channel::version::Version; diff --git a/crates/relayer-cli/src/commands/create/connection.rs b/crates/relayer-cli/src/commands/create/connection.rs index 16c0fa1e6e..052411d069 100644 --- a/crates/relayer-cli/src/commands/create/connection.rs +++ b/crates/relayer-cli/src/commands/create/connection.rs @@ -7,7 +7,6 @@ use ibc_relayer::chain::handle::ChainHandle; use ibc_relayer::chain::requests::{IncludeProof, QueryClientStateRequest, QueryHeight}; use ibc_relayer::connection::Connection; use ibc_relayer::foreign_client::ForeignClient; -use ibc_relayer_types::core::ics02_client::client_state::ClientState; use ibc_relayer_types::core::ics24_host::identifier::{ChainId, ClientId}; use crate::cli_utils::{spawn_chain_runtime, ChainHandlePair}; diff --git a/crates/relayer-cli/src/commands/query/channel_ends.rs b/crates/relayer-cli/src/commands/query/channel_ends.rs index 83a94fdf76..aaa668beb1 100644 --- a/crates/relayer-cli/src/commands/query/channel_ends.rs +++ b/crates/relayer-cli/src/commands/query/channel_ends.rs @@ -9,7 +9,6 @@ use ibc_relayer::chain::requests::{ }; use ibc_relayer::client_state::AnyClientState; use ibc_relayer::registry::Registry; -use ibc_relayer_types::core::ics02_client::client_state::ClientState; use ibc_relayer_types::core::ics03_connection::connection::ConnectionEnd; use ibc_relayer_types::core::ics04_channel::channel::{ChannelEnd, State}; use ibc_relayer_types::core::ics24_host::identifier::ChainId; diff --git a/crates/relayer-cli/src/commands/query/channels.rs b/crates/relayer-cli/src/commands/query/channels.rs index fce0441b1d..a516854416 100644 --- a/crates/relayer-cli/src/commands/query/channels.rs +++ b/crates/relayer-cli/src/commands/query/channels.rs @@ -11,7 +11,6 @@ use ibc_relayer::chain::requests::{ QueryConnectionRequest, QueryHeight, }; use ibc_relayer::registry::Registry; -use ibc_relayer_types::core::ics02_client::client_state::ClientState; use ibc_relayer_types::core::ics04_channel::channel::{ChannelEnd, State}; use ibc_relayer_types::core::ics24_host::identifier::{ ChainId, ChannelId, ConnectionId, PortChannelId, PortId, diff --git a/crates/relayer-cli/src/commands/query/clients.rs b/crates/relayer-cli/src/commands/query/clients.rs index 2290b5661c..0ced719b2b 100644 --- a/crates/relayer-cli/src/commands/query/clients.rs +++ b/crates/relayer-cli/src/commands/query/clients.rs @@ -4,7 +4,6 @@ use ibc_relayer::chain::handle::ChainHandle; use serde::Serialize; use ibc_relayer::chain::requests::{PageRequest, QueryClientStatesRequest}; -use ibc_relayer_types::core::ics02_client::client_state::ClientState; use ibc_relayer_types::core::ics24_host::identifier::{ChainId, ClientId}; use crate::cli_utils::spawn_chain_runtime; diff --git a/crates/relayer-cli/src/commands/query/connections.rs b/crates/relayer-cli/src/commands/query/connections.rs index f3a19e3585..b3bbdc8a11 100644 --- a/crates/relayer-cli/src/commands/query/connections.rs +++ b/crates/relayer-cli/src/commands/query/connections.rs @@ -5,7 +5,6 @@ use ibc_relayer::chain::handle::ChainHandle; use ibc_relayer::chain::requests::{ IncludeProof, PageRequest, QueryClientStateRequest, QueryConnectionsRequest, QueryHeight, }; -use ibc_relayer_types::core::ics02_client::client_state::ClientState; use ibc_relayer_types::core::ics24_host::identifier::{ChainId, ConnectionId}; use crate::cli_utils::spawn_chain_runtime; diff --git a/crates/relayer-cli/src/commands/tx/client.rs b/crates/relayer-cli/src/commands/tx/client.rs index 5729595b47..fd4270479e 100644 --- a/crates/relayer-cli/src/commands/tx/client.rs +++ b/crates/relayer-cli/src/commands/tx/client.rs @@ -14,7 +14,6 @@ use ibc_relayer::config::Config; use ibc_relayer::event::IbcEventWithHeight; use ibc_relayer::foreign_client::{CreateOptions, ForeignClient}; use ibc_relayer::{chain::handle::ChainHandle, config::GenesisRestart}; -use ibc_relayer_types::core::ics02_client::client_state::ClientState; use ibc_relayer_types::core::ics24_host::identifier::{ChainId, ClientId}; use ibc_relayer_types::events::IbcEvent; use ibc_relayer_types::Height; diff --git a/crates/relayer/src/chain/counterparty.rs b/crates/relayer/src/chain/counterparty.rs index ac34d84f40..be9425aae2 100644 --- a/crates/relayer/src/chain/counterparty.rs +++ b/crates/relayer/src/chain/counterparty.rs @@ -2,7 +2,6 @@ use std::collections::HashSet; use ibc_relayer_types::{ core::{ - ics02_client::client_state::ClientState, ics03_connection::connection::{ ConnectionEnd, IdentifiedConnectionEnd, State as ConnectionState, }, diff --git a/crates/relayer/src/client_state.rs b/crates/relayer/src/client_state.rs index a431dedce9..e148eb5f2a 100644 --- a/crates/relayer/src/client_state.rs +++ b/crates/relayer/src/client_state.rs @@ -121,6 +121,17 @@ impl AnyClientState { AnyClientState::Mock(mock_state) => mock_state.refresh_time(), } } + + pub fn expired(&self, elapsed_since_latest: Duration) -> bool { + match self { + AnyClientState::Tendermint(tm_state) => tm_state.expired(elapsed_since_latest), + AnyClientState::LocalhostV1(local_state) => local_state.expired(elapsed_since_latest), + AnyClientState::LocalhostV2(local_state) => local_state.expired(elapsed_since_latest), + + #[cfg(test)] + AnyClientState::Mock(mock_state) => mock_state.expired(elapsed_since_latest), + } + } } impl Protobuf for AnyClientState {} @@ -187,14 +198,7 @@ impl From for Any { impl ClientState for AnyClientState { fn chain_id(&self) -> ChainId { - match self { - AnyClientState::Tendermint(state) => state.chain_id(), - AnyClientState::LocalhostV1(state) => state.chain_id(), - AnyClientState::LocalhostV2(state) => state.chain_id(), - - #[cfg(test)] - AnyClientState::Mock(state) => state.chain_id(), - } + self.chain_id() } fn client_type(&self) -> ClientType { @@ -210,14 +214,7 @@ impl ClientState for AnyClientState { } fn expired(&self, elapsed_since_latest: Duration) -> bool { - match self { - AnyClientState::Tendermint(tm_state) => tm_state.expired(elapsed_since_latest), - AnyClientState::LocalhostV1(local_state) => local_state.expired(elapsed_since_latest), - AnyClientState::LocalhostV2(local_state) => local_state.expired(elapsed_since_latest), - - #[cfg(test)] - AnyClientState::Mock(mock_state) => mock_state.expired(elapsed_since_latest), - } + self.expired(elapsed_since_latest) } } diff --git a/crates/relayer/src/object.rs b/crates/relayer/src/object.rs index 9f7349734d..285856d041 100644 --- a/crates/relayer/src/object.rs +++ b/crates/relayer/src/object.rs @@ -5,7 +5,7 @@ use serde::{Deserialize, Serialize}; use ibc_relayer_types::applications::ics29_fee::events::IncentivizedPacket; use ibc_relayer_types::core::{ - ics02_client::{client_state::ClientState, events::UpdateClient}, + ics02_client::events::UpdateClient, ics03_connection::events::Attributes as ConnectionAttributes, ics04_channel::events::{ Attributes, CloseInit, SendPacket, TimeoutPacket, WriteAcknowledgement, diff --git a/crates/relayer/src/supervisor/client_state_filter.rs b/crates/relayer/src/supervisor/client_state_filter.rs index 0203b563f4..87133e89b7 100644 --- a/crates/relayer/src/supervisor/client_state_filter.rs +++ b/crates/relayer/src/supervisor/client_state_filter.rs @@ -4,7 +4,6 @@ use flex_error::define_error; use ibc_relayer_types::core::ics02_client::trust_threshold::TrustThreshold; use tracing::{debug, trace}; -use ibc_relayer_types::core::ics02_client::client_state::ClientState; use ibc_relayer_types::core::ics03_connection::connection::ConnectionEnd; use ibc_relayer_types::core::ics04_channel::error::Error as ChannelError; use ibc_relayer_types::core::ics24_host::identifier::{ diff --git a/crates/relayer/src/supervisor/scan.rs b/crates/relayer/src/supervisor/scan.rs index 1b4cf705e2..b4ff88cc0b 100644 --- a/crates/relayer/src/supervisor/scan.rs +++ b/crates/relayer/src/supervisor/scan.rs @@ -5,7 +5,6 @@ use itertools::Itertools; use tracing::{debug, error, error_span, info, warn}; use ibc_relayer_types::core::{ - ics02_client::client_state::ClientState, ics03_connection::connection::{IdentifiedConnectionEnd, State as ConnectionState}, ics04_channel::{ channel::{IdentifiedChannelEnd, State as ChannelState}, diff --git a/crates/relayer/src/supervisor/spawn.rs b/crates/relayer/src/supervisor/spawn.rs index c7ffd2a240..b1b608875c 100644 --- a/crates/relayer/src/supervisor/spawn.rs +++ b/crates/relayer/src/supervisor/spawn.rs @@ -1,7 +1,7 @@ use tracing::{error, info}; use ibc_relayer_types::core::{ - ics02_client::client_state::ClientState, ics03_connection::connection::IdentifiedConnectionEnd, + ics03_connection::connection::IdentifiedConnectionEnd, ics04_channel::channel::State as ChannelState, }; From a996db1bb22105d2164e6e27f11852ae5a86779e Mon Sep 17 00:00:00 2001 From: Romain Ruetschi <106849+romac@users.noreply.github.com> Date: Wed, 13 Sep 2023 22:05:15 +0200 Subject: [PATCH 6/8] Fix typo --- crates/relayer-types/src/core/ics02_client/client_type.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/relayer-types/src/core/ics02_client/client_type.rs b/crates/relayer-types/src/core/ics02_client/client_type.rs index 8e903a83db..690c9e3c99 100644 --- a/crates/relayer-types/src/core/ics02_client/client_type.rs +++ b/crates/relayer-types/src/core/ics02_client/client_type.rs @@ -16,7 +16,7 @@ pub enum ClientType { impl ClientType { const TENDERMINT_STR: &'static str = "07-tendermint"; - const LOCALHOST_STR: &'static str = "09-tendermint"; + const LOCALHOST_STR: &'static str = "09-localhost"; #[cfg_attr(not(test), allow(dead_code))] const MOCK_STR: &'static str = "9999-mock"; @@ -35,7 +35,7 @@ impl ClientType { impl Display for ClientType { fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), FmtError> { - write!(f, "ClientType({})", self.as_str()) + write!(f, "{}", self.as_str()) } } From 3283034c15da1d6c03a870d0243e9b1c8f6336ae Mon Sep 17 00:00:00 2001 From: Romain Ruetschi <106849+romac@users.noreply.github.com> Date: Wed, 27 Sep 2023 14:57:37 +0200 Subject: [PATCH 7/8] Update ibc-proto to v0.35.0 --- Cargo.lock | 4 ++-- crates/chain-registry/Cargo.toml | 2 +- crates/relayer-types/Cargo.toml | 2 +- crates/relayer/Cargo.toml | 2 +- crates/relayer/src/chain/cosmos.rs | 4 ++-- tools/test-framework/Cargo.toml | 2 +- 6 files changed, 8 insertions(+), 8 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index b4b72cf6f8..0df8b2a4dd 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1441,9 +1441,9 @@ dependencies = [ [[package]] name = "ibc-proto" -version = "0.34.0" +version = "0.35.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f6e8625e1aa28e4da4a33505c6469747a9201f14ccd9012e2481313dfbbf9e2f" +checksum = "459ccbab879b749bf500ae13244593fa16fc64c1b3159f6b0753c169625a1e23" dependencies = [ "base64 0.21.2", "bytes", diff --git a/crates/chain-registry/Cargo.toml b/crates/chain-registry/Cargo.toml index a8c2809788..4ec23ef7a9 100644 --- a/crates/chain-registry/Cargo.toml +++ b/crates/chain-registry/Cargo.toml @@ -12,7 +12,7 @@ description = """ """ [dependencies] -ibc-proto = { version = "0.34.0", features = ["serde"] } +ibc-proto = { version = "0.35.0", features = ["serde"] } ibc-relayer-types = { version = "0.25.0", path = "../relayer-types" } tendermint-rpc = { version = "0.33.0", features = [ "http-client", diff --git a/crates/relayer-types/Cargo.toml b/crates/relayer-types/Cargo.toml index 9b96c6496d..18423556ef 100644 --- a/crates/relayer-types/Cargo.toml +++ b/crates/relayer-types/Cargo.toml @@ -24,7 +24,7 @@ mocks = ["tendermint-testgen", "clock"] [dependencies] # Proto definitions for all IBC-related interfaces, e.g., connections or channels. -ibc-proto = { version = "0.34.0" } +ibc-proto = { version = "0.35.0" } ics23 = { version = "0.10.2", features = ["std", "host-functions"] } time = { version = "0.3" } serde_derive = { version = "1.0.104" } diff --git a/crates/relayer/Cargo.toml b/crates/relayer/Cargo.toml index 07eb956974..a5be41dff4 100644 --- a/crates/relayer/Cargo.toml +++ b/crates/relayer/Cargo.toml @@ -20,7 +20,7 @@ default = ["flex-error/std", "flex-error/eyre_tracer"] telemetry = ["ibc-telemetry"] [dependencies] -ibc-proto = { version = "0.34.0", features = ["serde"] } +ibc-proto = { version = "0.35.0", features = ["serde"] } ibc-telemetry = { version = "0.25.0", path = "../telemetry", optional = true } ibc-relayer-types = { version = "0.25.0", path = "../relayer-types", features = ["mocks"] } diff --git a/crates/relayer/src/chain/cosmos.rs b/crates/relayer/src/chain/cosmos.rs index b2f71a1c37..4d1c18c22a 100644 --- a/crates/relayer/src/chain/cosmos.rs +++ b/crates/relayer/src/chain/cosmos.rs @@ -19,7 +19,7 @@ use ibc_proto::cosmos::{ base::node::v1beta1::ConfigResponse, staking::v1beta1::Params as StakingParams, }; -use ibc_proto::interchain_security::ccv::consumer::v1::Params as CcvConsumerParams; +use ibc_proto::interchain_security::ccv::v1::Params as CcvParams; use ibc_proto::ibc::apps::fee::v1::{ QueryIncentivizedPacketRequest, QueryIncentivizedPacketResponse, @@ -343,7 +343,7 @@ impl CosmosSdkChain { } /// Performs a gRPC query to fetch CCV Consumer chain staking parameters. - pub fn query_ccv_consumer_chain_params(&self) -> Result { + pub fn query_ccv_consumer_chain_params(&self) -> Result { crate::time!( "query_ccv_consumer_chain_params", { diff --git a/tools/test-framework/Cargo.toml b/tools/test-framework/Cargo.toml index e8cdf503dc..b0dd8f9942 100644 --- a/tools/test-framework/Cargo.toml +++ b/tools/test-framework/Cargo.toml @@ -17,7 +17,7 @@ description = """ ibc-relayer-types = { version = "=0.25.0", path = "../../crates/relayer-types" } ibc-relayer = { version = "=0.25.0", path = "../../crates/relayer" } ibc-relayer-cli = { version = "=1.6.0", path = "../../crates/relayer-cli" } -ibc-proto = { version = "0.34.0", features = ["serde"] } +ibc-proto = { version = "0.35.0", features = ["serde"] } tendermint-rpc = { version = "0.33.0", features = ["http-client", "websocket-client"] } http = "0.2.9" From d48a2822cb3fd7e8ca3c7b71ad058ffc78c6c280 Mon Sep 17 00:00:00 2001 From: Romain Ruetschi <106849+romac@users.noreply.github.com> Date: Wed, 27 Sep 2023 15:00:43 +0200 Subject: [PATCH 8/8] Use `RawClientState` from ibc-proto --- .../src/clients/ics09_localhost/v2/client_state.rs | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-) diff --git a/crates/relayer-types/src/clients/ics09_localhost/v2/client_state.rs b/crates/relayer-types/src/clients/ics09_localhost/v2/client_state.rs index 756f7682b4..6209637362 100644 --- a/crates/relayer-types/src/clients/ics09_localhost/v2/client_state.rs +++ b/crates/relayer-types/src/clients/ics09_localhost/v2/client_state.rs @@ -5,7 +5,6 @@ use prost::Message; use serde::{Deserialize, Serialize}; use ibc_proto::google::protobuf::Any; -use ibc_proto::ibc::core::client::v1::Height as RawHeight; use ibc_proto::protobuf::Protobuf; use crate::core::ics02_client::client_state::ClientState as Ics02ClientState; @@ -16,17 +15,7 @@ use crate::Height; use super::error::Error; -// use ibc_proto::ibc::lightclients::localhost::v2::ClientState as RawClientState; - -/// ClientState defines the 09-localhost client state -#[derive(Serialize, Deserialize)] -#[allow(clippy::derive_partial_eq_without_eq)] -#[derive(Clone, PartialEq, ::prost::Message)] -pub struct RawClientState { - /// the latest block height - #[prost(message, optional, tag = "1")] - pub latest_height: ::core::option::Option, -} +pub use ibc_proto::ibc::lightclients::localhost::v2::ClientState as RawClientState; pub const LOCALHOST_V2_CLIENT_STATE_TYPE_URL: &str = "/ibc.lightclients.localhost.v2.ClientState";