From a4e9739a4fdc1905cc1932a6fda8c7b4343459a2 Mon Sep 17 00:00:00 2001 From: Ranadeep Biswas Date: Sun, 28 Apr 2024 14:57:03 +0200 Subject: [PATCH 1/9] impl TryFrom --- ibc-clients/ics07-tendermint/src/consensus_state.rs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/ibc-clients/ics07-tendermint/src/consensus_state.rs b/ibc-clients/ics07-tendermint/src/consensus_state.rs index d923ebb73..7338069d4 100644 --- a/ibc-clients/ics07-tendermint/src/consensus_state.rs +++ b/ibc-clients/ics07-tendermint/src/consensus_state.rs @@ -43,6 +43,13 @@ impl ConsensusState { } } +impl TryFrom for ConsensusStateType { + type Error = ClientError; + fn try_from(value: ConsensusState) -> Result { + Ok(value.0) + } +} + impl Protobuf for ConsensusState {} impl TryFrom for ConsensusState { From 6b33a3806766668f917eae381c29a0f6c75686aa Mon Sep 17 00:00:00 2001 From: Ranadeep Biswas Date: Sun, 28 Apr 2024 14:57:44 +0200 Subject: [PATCH 2/9] simplify Tendermint ClientType impl --- .../cw-contract/src/client_type.rs | 53 +------------------ 1 file changed, 1 insertion(+), 52 deletions(-) diff --git a/ibc-clients/ics07-tendermint/cw-contract/src/client_type.rs b/ibc-clients/ics07-tendermint/cw-contract/src/client_type.rs index dde85427b..001657220 100644 --- a/ibc-clients/ics07-tendermint/cw-contract/src/client_type.rs +++ b/ibc-clients/ics07-tendermint/cw-contract/src/client_type.rs @@ -1,12 +1,6 @@ use ibc_client_cw::api::ClientType; use ibc_client_tendermint::client_state::ClientState; use ibc_client_tendermint::consensus_state::ConsensusState; -use ibc_client_tendermint::types::{ - ConsensusState as ConsensusStateType, TENDERMINT_CONSENSUS_STATE_TYPE_URL, -}; -use ibc_core::client::types::error::ClientError; -use ibc_core::derive::ConsensusState as ConsensusStateDerive; -use ibc_core::primitives::proto::Any; /// A unit struct that represents the Tendermint client type. #[derive(Clone, Debug)] @@ -14,50 +8,5 @@ pub struct TendermintClient; impl<'a> ClientType<'a> for TendermintClient { type ClientState = ClientState; - type ConsensusState = AnyConsensusState; -} - -#[derive(Clone, Debug, ConsensusStateDerive)] -pub enum AnyConsensusState { - Tendermint(ConsensusState), -} - -impl From for AnyConsensusState { - fn from(value: ConsensusStateType) -> Self { - AnyConsensusState::Tendermint(value.into()) - } -} - -impl TryFrom for ConsensusStateType { - type Error = ClientError; - - fn try_from(value: AnyConsensusState) -> Result { - match value { - AnyConsensusState::Tendermint(state) => Ok(state.into_inner()), - } - } -} - -impl From for Any { - fn from(value: AnyConsensusState) -> Self { - match value { - AnyConsensusState::Tendermint(cs) => cs.into(), - } - } -} - -impl TryFrom for AnyConsensusState { - type Error = ClientError; - - fn try_from(raw: Any) -> Result { - match raw.type_url.as_str() { - TENDERMINT_CONSENSUS_STATE_TYPE_URL => { - let cs = ConsensusState::try_from(raw)?; - Ok(AnyConsensusState::Tendermint(cs)) - } - _ => Err(ClientError::UnknownConsensusStateType { - consensus_state_type: raw.type_url, - }), - } - } + type ConsensusState = ConsensusState; } From f52197cb51f9b5423fd6b432d4e78b32b37f3031 Mon Sep 17 00:00:00 2001 From: Ranadeep Biswas Date: Sun, 28 Apr 2024 15:13:51 +0200 Subject: [PATCH 3/9] add comment --- ibc-clients/ics07-tendermint/src/consensus_state.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/ibc-clients/ics07-tendermint/src/consensus_state.rs b/ibc-clients/ics07-tendermint/src/consensus_state.rs index 7338069d4..6518e29b2 100644 --- a/ibc-clients/ics07-tendermint/src/consensus_state.rs +++ b/ibc-clients/ics07-tendermint/src/consensus_state.rs @@ -43,6 +43,8 @@ impl ConsensusState { } } +/// Can't use [`Infallible`](core::convert::Infallible) because TryFrom is required by +/// [`ConsensusStateDecoder`](ibc_core_client::context::consensus_state::ConsensusStateDecoder). impl TryFrom for ConsensusStateType { type Error = ClientError; fn try_from(value: ConsensusState) -> Result { From 4cdb0e9e42d184e1f1fd179429dcaf45c5b23bc6 Mon Sep 17 00:00:00 2001 From: Ranadeep Biswas Date: Sun, 28 Apr 2024 21:25:35 +0200 Subject: [PATCH 4/9] rm Clone bound --- ibc-clients/cw-context/src/api.rs | 2 +- ibc-clients/cw-context/src/context/mod.rs | 2 +- ibc-clients/cw-context/src/handlers.rs | 6 ++++-- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/ibc-clients/cw-context/src/api.rs b/ibc-clients/cw-context/src/api.rs index cdab7a745..5877b190a 100644 --- a/ibc-clients/cw-context/src/api.rs +++ b/ibc-clients/cw-context/src/api.rs @@ -9,6 +9,6 @@ use crate::context::Context; /// their client state and consensus state types into the generic [`Context`] /// object. pub trait ClientType<'a>: Sized { - type ClientState: ClientStateExecution> + Clone; + type ClientState: ClientStateExecution>; type ConsensusState: ConsensusStateTrait + Into + TryFrom; } diff --git a/ibc-clients/cw-context/src/context/mod.rs b/ibc-clients/cw-context/src/context/mod.rs index 1000f837c..9b9b5f589 100644 --- a/ibc-clients/cw-context/src/context/mod.rs +++ b/ibc-clients/cw-context/src/context/mod.rs @@ -290,9 +290,9 @@ impl<'a, C: ClientType<'a>> Context<'a, C> { client_state: C::ClientState, ) -> Result, ClientError> { let wasm_client_state = WasmClientState { - data: C::ClientState::encode_to_any_vec(client_state.clone()), checksum: self.obtain_checksum()?, latest_height: client_state.latest_height(), + data: C::ClientState::encode_to_any_vec(client_state), }; Ok(Any::from(wasm_client_state).encode_to_vec()) diff --git a/ibc-clients/cw-context/src/handlers.rs b/ibc-clients/cw-context/src/handlers.rs index 024d8e08a..50aa1e03a 100644 --- a/ibc-clients/cw-context/src/handlers.rs +++ b/ibc-clients/cw-context/src/handlers.rs @@ -133,13 +133,15 @@ impl<'a, C: ClientType<'a>> Context<'a, C> { substitute_client_state.latest_height().revision_height(), ))?; + let substitute_client_state_any = substitute_client_state.into(); + self.set_subject_prefix(); - client_state.check_substitute(self, substitute_client_state.clone().into())?; + client_state.check_substitute(self, substitute_client_state_any.clone())?; client_state.update_on_recovery( self, &self.client_id(), - substitute_client_state.into(), + substitute_client_state_any, substitute_consensus_state.into(), )?; From 082dc181b343335bc474300a2cfad817c0587c81 Mon Sep 17 00:00:00 2001 From: Sean Chen Date: Tue, 30 Apr 2024 14:13:23 -0500 Subject: [PATCH 5/9] Implement From --- ibc-clients/ics07-tendermint/cw-contract/Cargo.toml | 13 +++++++------ ibc-clients/ics07-tendermint/src/consensus_state.rs | 9 +++------ ibc-core/ics02-client/types/src/error.rs | 8 ++++++++ 3 files changed, 18 insertions(+), 12 deletions(-) diff --git a/ibc-clients/ics07-tendermint/cw-contract/Cargo.toml b/ibc-clients/ics07-tendermint/cw-contract/Cargo.toml index 8c5c35733..dca014186 100644 --- a/ibc-clients/ics07-tendermint/cw-contract/Cargo.toml +++ b/ibc-clients/ics07-tendermint/cw-contract/Cargo.toml @@ -18,9 +18,10 @@ crate-type = [ "cdylib", "rlib" ] [dependencies] # ibc dependencies -ibc-core = { workspace = true } -ibc-client-cw = { workspace = true } -ibc-client-tendermint = { workspace = true } +ibc-core = { workspace = true } +ibc-client-cw = { workspace = true } +ibc-client-tendermint = { workspace = true } +ibc-client-tendermint-types = { workspace = true } # cosmwasm dependencies cosmwasm-std = { workspace = true } @@ -28,7 +29,7 @@ cosmwasm-std = { workspace = true } [features] default = [ "std" ] std = [ - "ibc-core/std", - "ibc-client-cw/std", - "ibc-client-tendermint/std", + "ibc-core/std", + "ibc-client-cw/std", + "ibc-client-tendermint/std", ] diff --git a/ibc-clients/ics07-tendermint/src/consensus_state.rs b/ibc-clients/ics07-tendermint/src/consensus_state.rs index 6518e29b2..e87778f37 100644 --- a/ibc-clients/ics07-tendermint/src/consensus_state.rs +++ b/ibc-clients/ics07-tendermint/src/consensus_state.rs @@ -43,12 +43,9 @@ impl ConsensusState { } } -/// Can't use [`Infallible`](core::convert::Infallible) because TryFrom is required by -/// [`ConsensusStateDecoder`](ibc_core_client::context::consensus_state::ConsensusStateDecoder). -impl TryFrom for ConsensusStateType { - type Error = ClientError; - fn try_from(value: ConsensusState) -> Result { - Ok(value.0) +impl From for ConsensusStateType { + fn from(value: ConsensusState) -> Self { + value.0 } } diff --git a/ibc-core/ics02-client/types/src/error.rs b/ibc-core/ics02-client/types/src/error.rs index 0783c906b..9eb5c51da 100644 --- a/ibc-core/ics02-client/types/src/error.rs +++ b/ibc-core/ics02-client/types/src/error.rs @@ -1,5 +1,7 @@ //! Defines the client error type +use core::convert::Infallible; + use displaydoc::Display; use ibc_core_commitment_types::error::CommitmentError; use ibc_core_host_types::error::IdentifierError; @@ -113,6 +115,12 @@ impl From<&'static str> for ClientError { } } +impl From for ClientError { + fn from(value: Infallible) -> Self { + match value {} + } +} + #[cfg(feature = "std")] impl std::error::Error for ClientError { fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { From c7ce5b7b8dad34f51aad3e12fa6f4d64dda1d563 Mon Sep 17 00:00:00 2001 From: Sean Chen Date: Tue, 30 Apr 2024 14:30:31 -0500 Subject: [PATCH 6/9] Remove unneeded dependency --- ibc-clients/ics07-tendermint/cw-contract/Cargo.toml | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/ibc-clients/ics07-tendermint/cw-contract/Cargo.toml b/ibc-clients/ics07-tendermint/cw-contract/Cargo.toml index dca014186..301945423 100644 --- a/ibc-clients/ics07-tendermint/cw-contract/Cargo.toml +++ b/ibc-clients/ics07-tendermint/cw-contract/Cargo.toml @@ -18,10 +18,9 @@ crate-type = [ "cdylib", "rlib" ] [dependencies] # ibc dependencies -ibc-core = { workspace = true } -ibc-client-cw = { workspace = true } -ibc-client-tendermint = { workspace = true } -ibc-client-tendermint-types = { workspace = true } +ibc-core = { workspace = true } +ibc-client-cw = { workspace = true } +ibc-client-tendermint = { workspace = true } # cosmwasm dependencies cosmwasm-std = { workspace = true } From 4028ac9898b135c6c02550003ae57cf50edcb8d7 Mon Sep 17 00:00:00 2001 From: Sean Chen Date: Wed, 1 May 2024 08:25:10 -0500 Subject: [PATCH 7/9] Format cargo.toml file --- ibc-clients/ics07-tendermint/cw-contract/Cargo.toml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/ibc-clients/ics07-tendermint/cw-contract/Cargo.toml b/ibc-clients/ics07-tendermint/cw-contract/Cargo.toml index 301945423..8c5c35733 100644 --- a/ibc-clients/ics07-tendermint/cw-contract/Cargo.toml +++ b/ibc-clients/ics07-tendermint/cw-contract/Cargo.toml @@ -28,7 +28,7 @@ cosmwasm-std = { workspace = true } [features] default = [ "std" ] std = [ - "ibc-core/std", - "ibc-client-cw/std", - "ibc-client-tendermint/std", + "ibc-core/std", + "ibc-client-cw/std", + "ibc-client-tendermint/std", ] From 05450e97d15a59f16f44129af85bbca07f774475 Mon Sep 17 00:00:00 2001 From: Ranadeep Biswas Date: Fri, 3 May 2024 18:18:09 +0200 Subject: [PATCH 8/9] nit --- .../ics07-tendermint/cw-contract/src/entrypoint.rs | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/ibc-clients/ics07-tendermint/cw-contract/src/entrypoint.rs b/ibc-clients/ics07-tendermint/cw-contract/src/entrypoint.rs index b496c97c1..e01e796b9 100644 --- a/ibc-clients/ics07-tendermint/cw-contract/src/entrypoint.rs +++ b/ibc-clients/ics07-tendermint/cw-contract/src/entrypoint.rs @@ -1,6 +1,4 @@ -use cosmwasm_std::{ - entry_point, Binary, Deps, DepsMut, Env, MessageInfo, Response, StdError, StdResult, -}; +use cosmwasm_std::{entry_point, Binary, Deps, DepsMut, Env, MessageInfo, Response}; use ibc_client_cw::context::Context; use ibc_client_cw::types::{ContractError, InstantiateMsg, QueryMsg, SudoMsg}; @@ -16,25 +14,19 @@ pub fn instantiate( msg: InstantiateMsg, ) -> Result { let mut ctx = TendermintContext::new_mut(deps, env)?; - let data = ctx.instantiate(msg)?; - Ok(Response::default().set_data(data)) } #[entry_point] pub fn sudo(deps: DepsMut<'_>, env: Env, msg: SudoMsg) -> Result { let mut ctx = TendermintContext::new_mut(deps, env)?; - let data = ctx.sudo(msg)?; - Ok(Response::default().set_data(data)) } #[entry_point] -pub fn query(deps: Deps<'_>, env: Env, msg: QueryMsg) -> StdResult { +pub fn query(deps: Deps<'_>, env: Env, msg: QueryMsg) -> Result { let ctx = TendermintContext::new_ref(deps, env)?; - ctx.query(msg) - .map_err(|e| StdError::generic_err(e.to_string())) } From a117a325e85abc6f48787aa91250cc48756c7699 Mon Sep 17 00:00:00 2001 From: Ranadeep Biswas Date: Fri, 3 May 2024 18:24:12 +0200 Subject: [PATCH 9/9] update gh workflow titles --- .github/workflows/upload-cw-clients.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/upload-cw-clients.yaml b/.github/workflows/upload-cw-clients.yaml index 224d54bec..6ee12e7e4 100644 --- a/.github/workflows/upload-cw-clients.yaml +++ b/.github/workflows/upload-cw-clients.yaml @@ -1,4 +1,4 @@ -name: Upload CosmWasm clients as Github workflow artifact +name: Upload precompiled CosmWasm clients on: pull_request: paths: @@ -36,7 +36,7 @@ concurrency: jobs: upload-tendermint-cw-client: - name: Compile and upload Tendermint CosmWasm client + name: Upload precompiled Tendermint CosmWasm client runs-on: ubuntu-latest steps: - uses: actions/checkout@v4