Skip to content

Commit

Permalink
Merge pull request #14 from Farhad-Shabani/farhad/fix-cons-state-conv…
Browse files Browse the repository at this point in the history
…ersions

fix: use `ibc::types::ConsensusState` and `ConsensusStateDerive` for conversions to satisfy bounds
  • Loading branch information
Carlos Rodriguez authored Mar 18, 2024
2 parents 6c3305d + e8652e7 commit 1bc9a77
Show file tree
Hide file tree
Showing 10 changed files with 29 additions and 32 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ cosmwasm-std = { version = "1.5.0", features = [
cw-storage-plus = "1.1.0"
cw2 = "1.1.1"
derive_more = "0.99.17"
ibc = { git = "https://github.com/cosmos/ibc-rs", rev = "3b11b12cc7963f8391a547bd2d60744708e91cbd", default-features = false } # "0.50.0"
ibc = { git = "https://github.com/cosmos/ibc-rs", rev = "3b11b12cc7963f8391a547bd2d60744708e91cbd", default-features = false, features = ["schema"] } # "0.50.0"
ibc-proto = { git = "https://github.com/cosmos/ibc-proto-rs.git", rev = "3adf964d795bf4d53150f3b2ce47feed93121759", default-features = false } # "0.42.0"
prost = "0.12.3"
schemars = "0.8.15"
Expand Down
4 changes: 2 additions & 2 deletions src/context/ctx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ use ibc::core::client::context::ClientExecutionContext;
use ibc::core::client::types::error::ClientError;

use ibc::core::client::context::ClientValidationContext;
use ibc::core::host::types::identifiers::ClientId;
use ibc::core::primitives::Timestamp;
use ibc::core::client::types::Height;
use ibc::core::handler::types::error::ContextError;
use ibc::core::host::types::identifiers::ClientId;
use ibc::core::primitives::Timestamp;

/// Enables conversion (`TryInto` and `From`) between the consensus state type
/// used by the host and the one specific to the Rollkit light client, which
Expand Down
4 changes: 2 additions & 2 deletions src/context/custom_ctx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ use ibc::core::host::types::path::{
};
use ibc::core::primitives::proto::{Any, Protobuf};

use prost::Message;

use crate::types::AnyCodec;
use crate::types::ClientType;
use crate::{parse_height, ContractError, GenesisMetadata, HeightTravel};
use prost::Message;

type Checksum = Vec<u8>;

Expand Down
1 change: 1 addition & 0 deletions src/context/execution_ctx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use ibc::core::host::types::path::{iteration_key, ClientConsensusStatePath, Clie
use ibc::core::primitives::Timestamp;

use super::Context;
use crate::types::AnyCodec;
use crate::types::ClientType;

impl<'a, C: ClientType<'a>> ClientExecutionContext for Context<'a, C> {
Expand Down
2 changes: 1 addition & 1 deletion src/context/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
mod ctx;
// mod ctx;
mod custom_ctx;
mod execution_ctx;
mod validation_ctx;
Expand Down
23 changes: 10 additions & 13 deletions src/context/validation_ctx.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use ibc::clients::tendermint::consensus_state::ConsensusState as TendermintConsensusState;
use ibc::clients::tendermint::context::{ConsensusStateConverter, ValidationContext};
use ibc::clients::wasm_types::client_state::ClientState as WasmClientState;
use ibc::clients::wasm_types::consensus_state::ConsensusState as WasmConsensusState;
use ibc::core::client::context::ClientValidationContext;
Expand All @@ -9,10 +9,10 @@ use ibc::core::host::types::path::{ClientConsensusStatePath, ClientStatePath};
use ibc::core::primitives::proto::{Any, Protobuf};
use ibc::core::primitives::Timestamp;

use super::{ctx::ValidationContext, ctx::ConsensusStateConverter, Context};
use super::Context;
use crate::helpers::HeightTravel;
use crate::types::ClientType;
use crate::types::AnyCodec;
use crate::types::ClientType;

impl<'a, C: ClientType<'a>> ClientValidationContext for Context<'a, C> {
type ClientStateRef = C::ClientState;
Expand All @@ -21,9 +21,11 @@ impl<'a, C: ClientType<'a>> ClientValidationContext for Context<'a, C> {
fn client_state(&self, _client_id: &ClientId) -> Result<Self::ClientStateRef, ContextError> {
let client_state_value = self.retrieve(ClientStatePath::leaf())?;

let wasm_client_state: WasmClientState = Protobuf::<Any>::decode(client_state_value.as_slice())
.map_err(|e| ClientError::Other {
description: e.to_string(),
let wasm_client_state: WasmClientState =
Protobuf::<Any>::decode(client_state_value.as_slice()).map_err(|e| {
ClientError::Other {
description: e.to_string(),
}
})?;

let tm_client_state = C::ClientState::decode_thru_any(wasm_client_state.data)?;
Expand All @@ -44,14 +46,9 @@ impl<'a, C: ClientType<'a>> ClientValidationContext for Context<'a, C> {
}
})?;

let tm_consensus_state: TendermintConsensusState =
Protobuf::<Any>::decode(&mut any_wasm.data.as_slice()).map_err(|e| {
ClientError::Other {
description: e.to_string(),
}
})?;
let tm_consensus_state = C::ConsensusState::decode_thru_any(any_wasm.data)?;

Ok(tm_consensus_state.into())
Ok(tm_consensus_state)
}

fn client_update_meta(
Expand Down
8 changes: 4 additions & 4 deletions src/handlers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ use prost::Message;

use crate::context::Context;
use crate::types::{
CheckForMisbehaviourMsg, ContractError, ContractResult, ExportMetadataMsg, InstantiateMsg,
QueryMsg, QueryResponse, StatusMsg, SudoMsg, UpdateStateMsg, UpdateStateOnMisbehaviourMsg,
VerifyClientMessageMsg, VerifyMembershipMsg, VerifyNonMembershipMsg,
VerifyUpgradeAndUpdateStateMsg, ClientMessage,
CheckForMisbehaviourMsg, ClientMessage, ContractError, ContractResult, ExportMetadataMsg,
InstantiateMsg, QueryMsg, QueryResponse, StatusMsg, SudoMsg, UpdateStateMsg,
UpdateStateOnMisbehaviourMsg, VerifyClientMessageMsg, VerifyMembershipMsg,
VerifyNonMembershipMsg, VerifyUpgradeAndUpdateStateMsg,
};

impl<'a, C: ClientType<'a>> Context<'a, C> {
Expand Down
2 changes: 1 addition & 1 deletion src/types/client_type.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use ibc::clients::tendermint::types::ClientState as TendermintClientState;
use ibc::clients::tendermint::client_state::ClientState as TendermintClientState;
use ibc::core::client::context::client_state::ClientStateExecution;
use ibc::core::client::context::consensus_state::ConsensusState as ConsensusStateTrait;
use ibc::core::client::types::error::ClientError;
Expand Down
3 changes: 1 addition & 2 deletions src/types/codec.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use ibc::core::client::types::error::ClientError;
use ibc_proto::google::protobuf::Any;
use ibc::{core::client::types::error::ClientError, primitives::proto::Any};
use prost::Message;

pub trait AnyCodec {
Expand Down
12 changes: 6 additions & 6 deletions src/types/consensus_state.rs
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
use ibc::clients::tendermint::consensus_state::ConsensusState as TendermintConsensusState;
use ibc::clients::tendermint::types::TENDERMINT_CONSENSUS_STATE_TYPE_URL;
use ibc::clients::tendermint::types::{ConsensusState, 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;
use ibc::derive::ConsensusState as ConsensusStateDerive;

#[derive(Clone, Debug)]
#[derive(Clone, Debug, ConsensusStateDerive)]
pub enum AnyConsensusState {
Rollkit(TendermintConsensusState),
}

impl From<TendermintConsensusState> for AnyConsensusState {
fn from(value: TendermintConsensusState) -> Self {
impl From<ConsensusState> for AnyConsensusState {
fn from(value: ConsensusState) -> Self {
AnyConsensusState::Rollkit(value.into())
}
}

impl TryFrom<AnyConsensusState> for TendermintConsensusState {
impl TryFrom<AnyConsensusState> for ConsensusState {
type Error = ClientError;

fn try_from(value: AnyConsensusState) -> Result<Self, Self::Error> {
Expand Down

0 comments on commit 1bc9a77

Please sign in to comment.