From dc116daa5e9df73b2f39b063463adc551020314e Mon Sep 17 00:00:00 2001 From: Rano | Ranadeep Date: Tue, 30 Apr 2024 17:40:58 +0200 Subject: [PATCH] imp(ibc-client): rm `TryFrom` restriction (#1204) * rm concrete Error type * update ibc-core * update tm client * update cw-context * Convertible in reverse direction * update code * use Convertible * rm redundant bound --------- Co-authored-by: Sean Chen --- ibc-clients/cw-context/src/api.rs | 8 +++++-- .../cw-context/src/context/client_ctx.rs | 12 ++++++++-- .../cw-context/src/context/custom_ctx.rs | 7 +++++- ibc-clients/cw-context/src/context/mod.rs | 24 +++++++++++++++---- ibc-clients/cw-context/src/handlers.rs | 9 +++++-- ibc-clients/cw-context/src/utils/codec.rs | 7 +++--- .../src/client_state/execution.rs | 24 +++++++++++-------- .../src/client_state/misbehaviour.rs | 11 +++++---- .../src/client_state/update_client.rs | 18 ++++++++------ .../src/client_state/validation.rs | 18 ++++++++------ .../ics02-client/context/src/client_state.rs | 11 +++------ .../context/src/consensus_state.rs | 9 ++----- ibc-core/ics02-client/context/src/context.rs | 6 ++--- .../ics02-client/src/handler/create_client.rs | 7 ++++-- .../src/handler/conn_open_ack.rs | 7 ++++-- .../src/handler/conn_open_try.rs | 7 ++++-- ibc-core/ics25-handler/src/entrypoint.rs | 9 +++++++ 17 files changed, 127 insertions(+), 67 deletions(-) diff --git a/ibc-clients/cw-context/src/api.rs b/ibc-clients/cw-context/src/api.rs index cdab7a745..dfcbe7ce9 100644 --- a/ibc-clients/cw-context/src/api.rs +++ b/ibc-clients/cw-context/src/api.rs @@ -8,7 +8,11 @@ use crate::context::Context; /// Enables users to integrate their implemented light client by introducing /// their client state and consensus state types into the generic [`Context`] /// object. -pub trait ClientType<'a>: Sized { +pub trait ClientType<'a>: Sized +where + >::Error: Into, + >::Error: Into, +{ type ClientState: ClientStateExecution> + Clone; - type ConsensusState: ConsensusStateTrait + Into + TryFrom; + type ConsensusState: ConsensusStateTrait; } diff --git a/ibc-clients/cw-context/src/context/client_ctx.rs b/ibc-clients/cw-context/src/context/client_ctx.rs index acb45c311..414217590 100644 --- a/ibc-clients/cw-context/src/context/client_ctx.rs +++ b/ibc-clients/cw-context/src/context/client_ctx.rs @@ -16,7 +16,11 @@ use crate::api::ClientType; use crate::context::CONSENSUS_STATE_HEIGHT_MAP; use crate::utils::AnyCodec; -impl<'a, C: ClientType<'a>> ClientValidationContext for Context<'a, C> { +impl<'a, C: ClientType<'a>> ClientValidationContext for Context<'a, C> +where + >::Error: Into, + >::Error: Into, +{ type ClientStateRef = C::ClientState; type ConsensusStateRef = C::ConsensusState; @@ -83,7 +87,11 @@ impl<'a, C: ClientType<'a>> ClientValidationContext for Context<'a, C> { } } -impl<'a, C: ClientType<'a>> ClientExecutionContext for Context<'a, C> { +impl<'a, C: ClientType<'a>> ClientExecutionContext for Context<'a, C> +where + >::Error: Into, + >::Error: Into, +{ type ClientStateMut = C::ClientState; fn store_client_state( diff --git a/ibc-clients/cw-context/src/context/custom_ctx.rs b/ibc-clients/cw-context/src/context/custom_ctx.rs index 36fe86393..54829d8e4 100644 --- a/ibc-clients/cw-context/src/context/custom_ctx.rs +++ b/ibc-clients/cw-context/src/context/custom_ctx.rs @@ -6,13 +6,18 @@ use ibc_core::client::types::Height; use ibc_core::handler::types::error::ContextError; use ibc_core::host::types::identifiers::ClientId; use ibc_core::host::types::path::ClientConsensusStatePath; +use ibc_core::primitives::proto::Any; use ibc_core::primitives::Timestamp; use super::Context; use crate::api::ClientType; use crate::types::HeightTravel; -impl<'a, C: ClientType<'a>> ExtClientValidationContext for Context<'a, C> { +impl<'a, C: ClientType<'a>> ExtClientValidationContext for Context<'a, C> +where + >::Error: Into, + >::Error: Into, +{ fn host_timestamp(&self) -> Result { let time = self.env().block.time; diff --git a/ibc-clients/cw-context/src/context/mod.rs b/ibc-clients/cw-context/src/context/mod.rs index 1000f837c..ea8518297 100644 --- a/ibc-clients/cw-context/src/context/mod.rs +++ b/ibc-clients/cw-context/src/context/mod.rs @@ -33,7 +33,11 @@ pub const CONSENSUS_STATE_HEIGHT_MAP: Map<'_, (u64, u64), Empty> = /// Context is a wrapper around the deps and env that gives access to the /// methods under the ibc-rs Validation and Execution traits. -pub struct Context<'a, C: ClientType<'a>> { +pub struct Context<'a, C: ClientType<'a>> +where + >::Error: Into, + >::Error: Into, +{ deps: Option>, deps_mut: Option>, env: Env, @@ -43,7 +47,11 @@ pub struct Context<'a, C: ClientType<'a>> { client_type: std::marker::PhantomData, } -impl<'a, C: ClientType<'a>> Context<'a, C> { +impl<'a, C: ClientType<'a>> Context<'a, C> +where + >::Error: Into, + >::Error: Into, +{ /// Constructs a new Context object with the given deps and env. pub fn new_ref(deps: Deps<'a>, env: Env) -> Result { let client_id = ClientId::from_str(env.contract.address.as_str())?; @@ -303,7 +311,11 @@ pub trait StorageRef { fn storage_ref(&self) -> &dyn Storage; } -impl<'a, C: ClientType<'a>> StorageRef for Context<'a, C> { +impl<'a, C: ClientType<'a>> StorageRef for Context<'a, C> +where + >::Error: Into, + >::Error: Into, +{ fn storage_ref(&self) -> &dyn Storage { match self.deps { Some(ref deps) => deps.storage, @@ -319,7 +331,11 @@ pub trait StorageMut: StorageRef { fn storage_mut(&mut self) -> &mut dyn Storage; } -impl<'a, C: ClientType<'a>> StorageMut for Context<'a, C> { +impl<'a, C: ClientType<'a>> StorageMut for Context<'a, C> +where + >::Error: Into, + >::Error: Into, +{ fn storage_mut(&mut self) -> &mut dyn Storage { match self.deps_mut { Some(ref mut deps) => deps.storage, diff --git a/ibc-clients/cw-context/src/handlers.rs b/ibc-clients/cw-context/src/handlers.rs index 024d8e08a..fdf9c3ed2 100644 --- a/ibc-clients/cw-context/src/handlers.rs +++ b/ibc-clients/cw-context/src/handlers.rs @@ -1,5 +1,6 @@ use cosmwasm_std::{to_json_binary, Binary}; use ibc_core::client::context::prelude::*; +use ibc_core::client::types::error::ClientError; use ibc_core::host::types::path::ClientConsensusStatePath; use ibc_core::primitives::proto::Any; use prost::Message; @@ -13,12 +14,16 @@ use crate::types::{ VerifyUpgradeAndUpdateStateMsg, }; -impl<'a, C: ClientType<'a>> Context<'a, C> { +impl<'a, C: ClientType<'a>> Context<'a, C> +where + >::Error: Into, + >::Error: Into, +{ /// Instantiates a new client with the given [`InstantiateMsg`] message. pub fn instantiate(&mut self, msg: InstantiateMsg) -> Result { let any = Any::decode(&mut msg.client_state.as_slice())?; - let client_state = C::ClientState::try_from(any)?; + let client_state = C::ClientState::try_from(any).map_err(Into::into)?; let any_consensus_state = Any::decode(&mut msg.consensus_state.as_slice())?; diff --git a/ibc-clients/cw-context/src/utils/codec.rs b/ibc-clients/cw-context/src/utils/codec.rs index f31d9ab2f..dc662ecff 100644 --- a/ibc-clients/cw-context/src/utils/codec.rs +++ b/ibc-clients/cw-context/src/utils/codec.rs @@ -7,13 +7,14 @@ use prost::Message; pub trait AnyCodec { fn decode_any_vec(data: Vec) -> Result where - C: TryFrom, + C: TryFrom, + >::Error: Into, { let raw = Any::decode(&mut data.as_slice()).map_err(|e| ClientError::Other { description: e.to_string(), })?; - C::try_from(raw) + C::try_from(raw).map_err(Into::into) } fn encode_to_any_vec(value: C) -> Vec @@ -24,4 +25,4 @@ pub trait AnyCodec { } } -impl AnyCodec for T where T: TryFrom + Into {} +impl AnyCodec for T where T: TryFrom + Into {} diff --git a/ibc-clients/ics07-tendermint/src/client_state/execution.rs b/ibc-clients/ics07-tendermint/src/client_state/execution.rs index 7e844b21c..5d4fadde5 100644 --- a/ibc-clients/ics07-tendermint/src/client_state/execution.rs +++ b/ibc-clients/ics07-tendermint/src/client_state/execution.rs @@ -15,7 +15,8 @@ impl ClientStateExecution for ClientState where E: ExtClientExecutionContext, E::ClientStateRef: From, - E::ConsensusStateRef: Convertible, + ConsensusStateType: Convertible, + >::Error: Into, { fn initialise( &self, @@ -93,12 +94,12 @@ pub fn initialise( where E: ExtClientExecutionContext, E::ClientStateRef: From, - E::ConsensusStateRef: Convertible, + ConsensusStateType: Convertible, { let host_timestamp = ExtClientValidationContext::host_timestamp(ctx)?; let host_height = ExtClientValidationContext::host_height(ctx)?; - let tm_consensus_state = ConsensusStateType::try_from(consensus_state)?; + let tm_consensus_state: ConsensusStateType = consensus_state.try_into()?; ctx.store_client_state( ClientStatePath::new(client_id.clone()), @@ -138,7 +139,8 @@ pub fn update_state( where E: ExtClientExecutionContext, E::ClientStateRef: From, - E::ConsensusStateRef: Convertible, + ConsensusStateType: Convertible, + >::Error: Into, { let header = TmHeader::try_from(header)?; let header_height = header.height(); @@ -237,10 +239,10 @@ pub fn update_on_upgrade( where E: ExtClientExecutionContext, E::ClientStateRef: From, - E::ConsensusStateRef: Convertible, + ConsensusStateType: Convertible, { let mut upgraded_tm_client_state = ClientState::try_from(upgraded_client_state)?; - let upgraded_tm_cons_state = ConsensusStateType::try_from(upgraded_consensus_state)?; + let upgraded_tm_cons_state: ConsensusStateType = upgraded_consensus_state.try_into()?; upgraded_tm_client_state.0.zero_custom_fields(); @@ -317,7 +319,8 @@ pub fn prune_oldest_consensus_state( where E: ClientExecutionContext + ExtClientValidationContext, E::ClientStateRef: From, - E::ConsensusStateRef: Convertible, + ConsensusStateType: Convertible, + >::Error: Into, { let mut heights = ctx.consensus_state_heights(client_id)?; @@ -330,7 +333,8 @@ where height.revision_height(), ); let consensus_state = ctx.consensus_state(&client_consensus_state_path)?; - let tm_consensus_state = consensus_state.try_into()?; + let tm_consensus_state: ConsensusStateType = + consensus_state.try_into().map_err(Into::into)?; let host_timestamp = ctx.host_timestamp()? @@ -380,7 +384,7 @@ pub fn update_on_recovery( where E: ExtClientExecutionContext, E::ClientStateRef: From, - E::ConsensusStateRef: Convertible, + ConsensusStateType: Convertible, { let substitute_client_state = ClientState::try_from(substitute_client_state)? .inner() @@ -401,7 +405,7 @@ where let host_timestamp = E::host_timestamp(ctx)?; let host_height = E::host_height(ctx)?; - let tm_consensus_state = ConsensusStateType::try_from(substitute_consensus_state)?; + let tm_consensus_state: ConsensusStateType = substitute_consensus_state.try_into()?; ctx.store_consensus_state( ClientConsensusStatePath::new( diff --git a/ibc-clients/ics07-tendermint/src/client_state/misbehaviour.rs b/ibc-clients/ics07-tendermint/src/client_state/misbehaviour.rs index 6750a44eb..79d2b6ea9 100644 --- a/ibc-clients/ics07-tendermint/src/client_state/misbehaviour.rs +++ b/ibc-clients/ics07-tendermint/src/client_state/misbehaviour.rs @@ -28,13 +28,14 @@ pub fn verify_misbehaviour( ) -> Result<(), ClientError> where V: ExtClientValidationContext, - V::ConsensusStateRef: Convertible, + ConsensusStateType: Convertible, + >::Error: Into, H: MerkleHash + Sha256 + Default, { misbehaviour.validate_basic::()?; let header_1 = misbehaviour.header1(); - let trusted_consensus_state_1 = { + let trusted_consensus_state_1: ConsensusStateType = { let consensus_state_path = ClientConsensusStatePath::new( client_id.clone(), header_1.trusted_height.revision_number(), @@ -42,11 +43,11 @@ where ); let consensus_state = ctx.consensus_state(&consensus_state_path)?; - consensus_state.try_into()? + consensus_state.try_into().map_err(Into::into)? }; let header_2 = misbehaviour.header2(); - let trusted_consensus_state_2 = { + let trusted_consensus_state_2: ConsensusStateType = { let consensus_state_path = ClientConsensusStatePath::new( client_id.clone(), header_2.trusted_height.revision_number(), @@ -54,7 +55,7 @@ where ); let consensus_state = ctx.consensus_state(&consensus_state_path)?; - consensus_state.try_into()? + consensus_state.try_into().map_err(Into::into)? }; let current_timestamp = ctx.host_timestamp()?; diff --git a/ibc-clients/ics07-tendermint/src/client_state/update_client.rs b/ibc-clients/ics07-tendermint/src/client_state/update_client.rs index e715643fb..ec5d88c36 100644 --- a/ibc-clients/ics07-tendermint/src/client_state/update_client.rs +++ b/ibc-clients/ics07-tendermint/src/client_state/update_client.rs @@ -22,7 +22,8 @@ pub fn verify_header( ) -> Result<(), ClientError> where V: ExtClientValidationContext, - V::ConsensusStateRef: Convertible, + ConsensusStateType: Convertible, + >::Error: Into, H: MerkleHash + Sha256 + Default, { // Checks that the header fields are valid. @@ -41,9 +42,10 @@ where header.trusted_height.revision_number(), header.trusted_height.revision_height(), ); - let trusted_consensus_state = ctx + let trusted_consensus_state: ConsensusStateType = ctx .consensus_state(&trusted_client_cons_state_path)? - .try_into()?; + .try_into() + .map_err(Into::into)?; header.check_trusted_next_validator_set::( &trusted_consensus_state.next_validators_hash, @@ -107,7 +109,8 @@ pub fn check_for_misbehaviour_on_update( ) -> Result where V: ExtClientValidationContext, - V::ConsensusStateRef: Convertible, + ConsensusStateType: Convertible, + >::Error: Into, { let maybe_existing_consensus_state = { let path_at_header_height = ClientConsensusStatePath::new( @@ -120,7 +123,8 @@ where }; if let Some(existing_consensus_state) = maybe_existing_consensus_state { - let existing_consensus_state = existing_consensus_state.try_into()?; + let existing_consensus_state: ConsensusStateType = + existing_consensus_state.try_into().map_err(Into::into)?; let header_consensus_state = ConsensusStateType::from(header); @@ -138,7 +142,7 @@ where if let Some(prev_cs) = maybe_prev_cs { // New header timestamp cannot occur *before* the // previous consensus state's height - let prev_cs = prev_cs.try_into()?; + let prev_cs: ConsensusStateType = prev_cs.try_into().map_err(Into::into)?; if header.signed_header.header().time <= prev_cs.timestamp() { return Ok(true); @@ -154,7 +158,7 @@ where if let Some(next_cs) = maybe_next_cs { // New (untrusted) header timestamp cannot occur *after* next // consensus state's height - let next_cs = next_cs.try_into()?; + let next_cs: ConsensusStateType = next_cs.try_into().map_err(Into::into)?; if header.signed_header.header().time >= next_cs.timestamp() { return Ok(true); diff --git a/ibc-clients/ics07-tendermint/src/client_state/validation.rs b/ibc-clients/ics07-tendermint/src/client_state/validation.rs index 73349d1ec..aca62f5e5 100644 --- a/ibc-clients/ics07-tendermint/src/client_state/validation.rs +++ b/ibc-clients/ics07-tendermint/src/client_state/validation.rs @@ -21,7 +21,8 @@ use crate::client_state::{verify_header, verify_misbehaviour}; impl ClientStateValidation for ClientState where V: ExtClientValidationContext, - V::ConsensusStateRef: Convertible, + ConsensusStateType: Convertible, + >::Error: Into, { /// The default verification logic exposed by ibc-rs simply delegates to a /// standalone `verify_client_message` function. This is to make it as @@ -93,7 +94,8 @@ pub fn verify_client_message( ) -> Result<(), ClientError> where V: ExtClientValidationContext, - V::ConsensusStateRef: Convertible, + ConsensusStateType: Convertible, + >::Error: Into, H: MerkleHash + Sha256Trait + Default, { match client_message.type_url.as_str() { @@ -163,7 +165,8 @@ pub fn check_for_misbehaviour( ) -> Result where V: ExtClientValidationContext, - V::ConsensusStateRef: Convertible, + ConsensusStateType: Convertible, + >::Error: Into, { match client_message.type_url.as_str() { TENDERMINT_HEADER_TYPE_URL => { @@ -190,19 +193,20 @@ pub fn status( ) -> Result where V: ExtClientValidationContext, - V::ConsensusStateRef: Convertible, + ConsensusStateType: Convertible, + >::Error: Into, { if client_state.is_frozen() { return Ok(Status::Frozen); } - let latest_consensus_state = { + let latest_consensus_state: ConsensusStateType = { match ctx.consensus_state(&ClientConsensusStatePath::new( client_id.clone(), client_state.latest_height.revision_number(), client_state.latest_height.revision_height(), )) { - Ok(cs) => cs.try_into()?, + Ok(cs) => cs.try_into().map_err(Into::into)?, // if the client state does not have an associated consensus state for its latest height // then it must be expired Err(_) => return Ok(Status::Expired), @@ -237,7 +241,7 @@ pub fn check_substitute( ) -> Result<(), ClientError> where V: ExtClientValidationContext, - V::ConsensusStateRef: Convertible, + ConsensusStateType: Convertible, { let ClientStateType { latest_height: _, diff --git a/ibc-core/ics02-client/context/src/client_state.rs b/ibc-core/ics02-client/context/src/client_state.rs index abe496e2f..e6becbf58 100644 --- a/ibc-core/ics02-client/context/src/client_state.rs +++ b/ibc-core/ics02-client/context/src/client_state.rs @@ -10,17 +10,14 @@ use ibc_core_host_types::path::Path; use ibc_primitives::prelude::*; use ibc_primitives::proto::Any; -/// Convenient trait to decode a client state from an [`Any`] type and obtain a -/// handle to the local instance of [`ClientState`]. -pub trait ClientStateDecoder: Into + TryFrom {} - -impl ClientStateDecoder for T where T: Into + TryFrom {} +use crate::context::{ClientExecutionContext, ClientValidationContext}; +use crate::Convertible; /// `ClientState` methods needed in both validation and execution. /// /// They do not require access to a client `ValidationContext` nor /// `ExecutionContext`. -pub trait ClientStateCommon: ClientStateDecoder { +pub trait ClientStateCommon: Convertible { /// Performs basic validation on the `consensus_state`. /// /// Notably, an implementation should verify that it can properly @@ -206,8 +203,6 @@ where ) -> Result<(), ClientError>; } -use crate::context::{ClientExecutionContext, ClientValidationContext}; - /// Primary client trait. Defines all the methods that clients must implement. /// /// `ClientState` is broken up in 3 separate traits to avoid needing to use diff --git a/ibc-core/ics02-client/context/src/consensus_state.rs b/ibc-core/ics02-client/context/src/consensus_state.rs index 7d1bfcb77..556486c67 100644 --- a/ibc-core/ics02-client/context/src/consensus_state.rs +++ b/ibc-core/ics02-client/context/src/consensus_state.rs @@ -1,22 +1,17 @@ //! Defines the trait to be implemented by all concrete consensus state types -use ibc_core_client_types::error::ClientError; use ibc_core_commitment_types::commitment::CommitmentRoot; use ibc_primitives::prelude::*; use ibc_primitives::proto::Any; use ibc_primitives::Timestamp; -/// Convenient trait to decode a consensus state from an [`Any`] type and obtain -/// a handle to the local instance of [`ConsensusState`]. -pub trait ConsensusStateDecoder: Into + TryFrom {} - -impl ConsensusStateDecoder for T where T: Into + TryFrom {} +use crate::Convertible; /// Defines methods that all `ConsensusState`s should provide. /// /// One can think of a "consensus state" as a pruned header, to be stored on chain. In other words, /// a consensus state only contains the header's information needed by IBC message handlers. -pub trait ConsensusState: Send + Sync + ConsensusStateDecoder { +pub trait ConsensusState: Send + Sync + Convertible { /// Commitment root of the consensus state, which is used for key-value pair verification. fn root(&self) -> &CommitmentRoot; diff --git a/ibc-core/ics02-client/context/src/context.rs b/ibc-core/ics02-client/context/src/context.rs index 8f7b4922a..972ec547e 100644 --- a/ibc-core/ics02-client/context/src/context.rs +++ b/ibc-core/ics02-client/context/src/context.rs @@ -153,11 +153,11 @@ pub trait ExtClientExecutionContext: ExtClientValidationContext + ClientExecutio impl ExtClientExecutionContext for T where T: ExtClientValidationContext + ClientExecutionContext {} -/// General-purpose helper converter enabling `TryInto` and `From` conversions +/// General-purpose helper converter enabling `TryFrom` and `Into` conversions /// primarily intended between an enum and its variants. This usually used by /// standalone functions as a trait bound allowing them to obtain the concrete /// local type from the enum containing that concrete type as its variant, like /// when enum `AnyConsensusState` contains the Tendermint `ConsensusState`. -pub trait Convertible: TryInto + From {} +pub trait Convertible: TryFrom + Into {} -impl Convertible for T where T: TryInto + From {} +impl Convertible for T where T: TryFrom + Into {} diff --git a/ibc-core/ics02-client/src/handler/create_client.rs b/ibc-core/ics02-client/src/handler/create_client.rs index 4a4148251..4cb3d34f2 100644 --- a/ibc-core/ics02-client/src/handler/create_client.rs +++ b/ibc-core/ics02-client/src/handler/create_client.rs @@ -8,10 +8,12 @@ use ibc_core_handler_types::error::ContextError; use ibc_core_handler_types::events::{IbcEvent, MessageEvent}; use ibc_core_host::{ClientStateMut, ClientStateRef, ExecutionContext, ValidationContext}; use ibc_primitives::prelude::*; +use ibc_primitives::proto::Any; pub fn validate(ctx: &Ctx, msg: MsgCreateClient) -> Result<(), ContextError> where Ctx: ValidationContext, + as TryFrom>::Error: Into, { let MsgCreateClient { client_state, @@ -26,7 +28,7 @@ where let client_val_ctx = ctx.get_client_validation_context(); - let client_state = ClientStateRef::::try_from(client_state)?; + let client_state = ClientStateRef::::try_from(client_state).map_err(Into::into)?; let client_id = client_state.client_type().build_client_id(id_counter); @@ -51,6 +53,7 @@ where pub fn execute(ctx: &mut Ctx, msg: MsgCreateClient) -> Result<(), ContextError> where Ctx: ExecutionContext, + as TryFrom>::Error: Into, { let MsgCreateClient { client_state, @@ -63,7 +66,7 @@ where let client_exec_ctx = ctx.get_client_execution_context(); - let client_state = ClientStateMut::::try_from(client_state)?; + let client_state = ClientStateMut::::try_from(client_state).map_err(Into::into)?; let client_type = client_state.client_type(); let client_id = client_type.build_client_id(id_counter); diff --git a/ibc-core/ics03-connection/src/handler/conn_open_ack.rs b/ibc-core/ics03-connection/src/handler/conn_open_ack.rs index 4e76a493a..a0630ef33 100644 --- a/ibc-core/ics03-connection/src/handler/conn_open_ack.rs +++ b/ibc-core/ics03-connection/src/handler/conn_open_ack.rs @@ -1,6 +1,7 @@ //! Protocol logic specific to processing ICS3 messages of type `MsgConnectionOpenAck`. use ibc_core_client::context::prelude::*; +use ibc_core_client::types::error::ClientError; use ibc_core_connection_types::error::ConnectionError; use ibc_core_connection_types::events::OpenAck; use ibc_core_connection_types::msgs::MsgConnectionOpenAck; @@ -11,12 +12,13 @@ use ibc_core_host::types::identifiers::ClientId; use ibc_core_host::types::path::{ClientConsensusStatePath, ClientStatePath, ConnectionPath, Path}; use ibc_core_host::{ExecutionContext, ValidationContext}; use ibc_primitives::prelude::*; -use ibc_primitives::proto::Protobuf; +use ibc_primitives::proto::{Any, Protobuf}; use ibc_primitives::ToVec; pub fn validate(ctx_a: &Ctx, msg: MsgConnectionOpenAck) -> Result<(), ContextError> where Ctx: ValidationContext, + >::Error: Into, { let vars = LocalVars::new(ctx_a, &msg)?; validate_impl(ctx_a, &msg, &vars) @@ -29,6 +31,7 @@ fn validate_impl( ) -> Result<(), ContextError> where Ctx: ValidationContext, + >::Error: Into, { ctx_a.validate_message_signer(&msg.signer)?; @@ -46,7 +49,7 @@ where let client_val_ctx_a = ctx_a.get_client_validation_context(); let client_state_of_a_on_b = - Ctx::HostClientState::try_from(msg.client_state_of_a_on_b.clone())?; + Ctx::HostClientState::try_from(msg.client_state_of_a_on_b.clone()).map_err(Into::into)?; ctx_a.validate_self_client(client_state_of_a_on_b)?; diff --git a/ibc-core/ics03-connection/src/handler/conn_open_try.rs b/ibc-core/ics03-connection/src/handler/conn_open_try.rs index d7eb9592f..e85828e7e 100644 --- a/ibc-core/ics03-connection/src/handler/conn_open_try.rs +++ b/ibc-core/ics03-connection/src/handler/conn_open_try.rs @@ -1,5 +1,6 @@ //! Protocol logic specific to processing ICS3 messages of type `MsgConnectionOpenTry`.; use ibc_core_client::context::prelude::*; +use ibc_core_client::types::error::ClientError; use ibc_core_connection_types::error::ConnectionError; use ibc_core_connection_types::events::OpenTry; use ibc_core_connection_types::msgs::MsgConnectionOpenTry; @@ -12,12 +13,13 @@ use ibc_core_host::types::path::{ }; use ibc_core_host::{ExecutionContext, ValidationContext}; use ibc_primitives::prelude::*; -use ibc_primitives::proto::Protobuf; +use ibc_primitives::proto::{Any, Protobuf}; use ibc_primitives::ToVec; pub fn validate(ctx_b: &Ctx, msg: MsgConnectionOpenTry) -> Result<(), ContextError> where Ctx: ValidationContext, + >::Error: Into, { let vars = LocalVars::new(ctx_b, &msg)?; validate_impl(ctx_b, &msg, &vars) @@ -30,13 +32,14 @@ fn validate_impl( ) -> Result<(), ContextError> where Ctx: ValidationContext, + >::Error: Into, { ctx_b.validate_message_signer(&msg.signer)?; let client_val_ctx_b = ctx_b.get_client_validation_context(); let client_state_of_b_on_a = - Ctx::HostClientState::try_from(msg.client_state_of_b_on_a.clone())?; + Ctx::HostClientState::try_from(msg.client_state_of_b_on_a.clone()).map_err(Into::into)?; ctx_b.validate_self_client(client_state_of_b_on_a)?; diff --git a/ibc-core/ics25-handler/src/entrypoint.rs b/ibc-core/ics25-handler/src/entrypoint.rs index 1de98b062..3c271a9bb 100644 --- a/ibc-core/ics25-handler/src/entrypoint.rs +++ b/ibc-core/ics25-handler/src/entrypoint.rs @@ -9,7 +9,9 @@ use ibc_core_channel::handler::{ use ibc_core_channel::types::msgs::{ channel_msg_to_port_id, packet_msg_to_port_id, ChannelMsg, PacketMsg, }; +use ibc_core_client::context::{ClientExecutionContext, ClientValidationContext}; use ibc_core_client::handler::{create_client, update_client, upgrade_client}; +use ibc_core_client::types::error::ClientError; use ibc_core_client::types::msgs::{ClientMsg, MsgUpdateOrMisbehaviour}; use ibc_core_connection::handler::{ conn_open_ack, conn_open_confirm, conn_open_init, conn_open_try, @@ -20,6 +22,7 @@ use ibc_core_handler_types::msgs::MsgEnvelope; use ibc_core_host::{ExecutionContext, ValidationContext}; use ibc_core_router::router::Router; use ibc_core_router::types::error::RouterError; +use ibc_primitives::proto::Any; /// Entrypoint which performs both validation and message execution pub fn dispatch( @@ -29,6 +32,9 @@ pub fn dispatch( ) -> Result<(), ContextError> where Ctx: ExecutionContext, + <::ClientStateRef as TryFrom>::Error: Into, + <::ClientStateMut as TryFrom>::Error: Into, + >::Error: Into, { validate(ctx, router, msg.clone())?; execute(ctx, router, msg) @@ -45,6 +51,8 @@ where pub fn validate(ctx: &Ctx, router: &impl Router, msg: MsgEnvelope) -> Result<(), ContextError> where Ctx: ValidationContext, + <::ClientStateRef as TryFrom>::Error: Into, + >::Error: Into, { match msg { MsgEnvelope::Client(msg) => match msg { @@ -121,6 +129,7 @@ pub fn execute( ) -> Result<(), ContextError> where Ctx: ExecutionContext, + <::ClientStateMut as TryFrom>::Error: Into, { match msg { MsgEnvelope::Client(msg) => match msg {