From 005ae23ca7b0555595a7c3a64e723cdc36d4cfb3 Mon Sep 17 00:00:00 2001 From: Sean Chen Date: Thu, 25 Apr 2024 11:04:26 -0500 Subject: [PATCH 01/14] Pass substitute consensus state into client recovery methods --- .../src/client_state/execution.rs | 15 +++++++++++++++ ibc-core/ics02-client/context/src/client_state.rs | 1 + .../ics02-client/src/handler/recover_client.rs | 9 ++++++++- 3 files changed, 24 insertions(+), 1 deletion(-) diff --git a/ibc-clients/ics07-tendermint/src/client_state/execution.rs b/ibc-clients/ics07-tendermint/src/client_state/execution.rs index 50d372fa3..5f0cb36f4 100644 --- a/ibc-clients/ics07-tendermint/src/client_state/execution.rs +++ b/ibc-clients/ics07-tendermint/src/client_state/execution.rs @@ -65,6 +65,7 @@ where ctx: &mut E, subject_client_id: &ClientId, substitute_client_state: Any, + substitute_consensus_state: Any, ) -> Result<(), ClientError> { let subject_client_state = self.inner().clone(); @@ -73,6 +74,7 @@ where ctx, subject_client_id, substitute_client_state, + substitute_consensus_state, ) } } @@ -373,10 +375,12 @@ pub fn update_on_recovery( ctx: &mut E, subject_client_id: &ClientId, substitute_client_state: Any, + substitute_consensus_state: Any, ) -> Result<(), ClientError> where E: ExtClientExecutionContext, E::ClientStateRef: From, + E::ConsensusStateRef: Convertible, { let substitute_client_state = ClientState::try_from(substitute_client_state)? .inner() @@ -397,11 +401,22 @@ 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)?; + ctx.store_client_state( ClientStatePath::new(subject_client_id.clone()), new_client_state.into(), )?; + ctx.store_consensus_state( + ClientConsensusStatePath::new( + subject_client_id.clone(), + new_client_state.latest_height.revision_number(), + new_client_state.latest_height.revision_height(), + ), + tm_consensus_state.into(), + )?; + ctx.store_update_meta( subject_client_id.clone(), 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 849678b77..2254ce1c3 100644 --- a/ibc-core/ics02-client/context/src/client_state.rs +++ b/ibc-core/ics02-client/context/src/client_state.rs @@ -202,6 +202,7 @@ where ctx: &mut E, subject_client_id: &ClientId, substitute_client_state: Any, + substitute_consensus_state: Any, ) -> Result<(), ClientError>; } diff --git a/ibc-core/ics02-client/src/handler/recover_client.rs b/ibc-core/ics02-client/src/handler/recover_client.rs index 431afadf5..b434e460b 100644 --- a/ibc-core/ics02-client/src/handler/recover_client.rs +++ b/ibc-core/ics02-client/src/handler/recover_client.rs @@ -4,7 +4,7 @@ use ibc_core_client_context::prelude::*; use ibc_core_client_types::error::ClientError; use ibc_core_client_types::msgs::MsgRecoverClient; use ibc_core_handler_types::error::ContextError; -use ibc_core_host::{ExecutionContext, ValidationContext}; +use ibc_core_host::{types::path::ClientConsensusStatePath, ExecutionContext, ValidationContext}; /// Performs the validation steps associated with the client recovery process. This /// includes validating that the parameters of the subject and substitute clients match, @@ -72,11 +72,18 @@ where let subject_client_state = client_exec_ctx.client_state(&subject_client_id)?; let substitute_client_state = client_exec_ctx.client_state(&substitute_client_id)?; + let substitute_consensus_state = + client_exec_ctx.consensus_state(&ClientConsensusStatePath::new( + substitute_client_id.clone(), + substitute_client_state.latest_height().revision_number(), + substitute_client_state.latest_height().revision_height(), + ))?; subject_client_state.update_on_recovery( ctx.get_client_execution_context(), &subject_client_id, substitute_client_state.into(), + substitute_consensus_state.into(), )?; Ok(()) From b87deea0f4e9db15f339cf13dea09ff1c4cf5eb4 Mon Sep 17 00:00:00 2001 From: Sean Chen Date: Thu, 25 Apr 2024 11:11:29 -0500 Subject: [PATCH 02/14] Fix update_on_recovery call in ibc-clients/cw-context --- ibc-clients/cw-context/src/handlers.rs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/ibc-clients/cw-context/src/handlers.rs b/ibc-clients/cw-context/src/handlers.rs index c7ab323dd..024d8e08a 100644 --- a/ibc-clients/cw-context/src/handlers.rs +++ b/ibc-clients/cw-context/src/handlers.rs @@ -126,6 +126,12 @@ impl<'a, C: ClientType<'a>> Context<'a, C> { SudoMsg::MigrateClientStore(_) => { self.set_substitute_prefix(); let substitute_client_state = self.client_state(&client_id)?; + let substitute_consensus_state = + self.consensus_state(&ClientConsensusStatePath::new( + client_id.clone(), + substitute_client_state.latest_height().revision_number(), + substitute_client_state.latest_height().revision_height(), + ))?; self.set_subject_prefix(); client_state.check_substitute(self, substitute_client_state.clone().into())?; @@ -134,6 +140,7 @@ impl<'a, C: ClientType<'a>> Context<'a, C> { self, &self.client_id(), substitute_client_state.into(), + substitute_consensus_state.into(), )?; ContractResult::success() From da7cfa4bf6e2a1c7bf01f68d4bdb018f57e83e24 Mon Sep 17 00:00:00 2001 From: Ranadeep Biswas Date: Thu, 25 Apr 2024 18:25:56 +0200 Subject: [PATCH 03/14] refactor encode_vec to into_any --- ibc-clients/ics07-tendermint/src/consensus_state.rs | 4 ++-- ibc-core/ics02-client/context/src/consensus_state.rs | 3 ++- ibc-core/ics02-client/src/handler/recover_client.rs | 2 +- ibc-core/ics03-connection/src/handler/conn_open_ack.rs | 2 +- ibc-core/ics03-connection/src/handler/conn_open_try.rs | 2 +- ibc-derive/src/consensus_state.rs | 9 +++++---- .../src/testapp/ibc/clients/mock/consensus_state.rs | 4 ++-- 7 files changed, 14 insertions(+), 12 deletions(-) diff --git a/ibc-clients/ics07-tendermint/src/consensus_state.rs b/ibc-clients/ics07-tendermint/src/consensus_state.rs index f2473d63a..426171d37 100644 --- a/ibc-clients/ics07-tendermint/src/consensus_state.rs +++ b/ibc-clients/ics07-tendermint/src/consensus_state.rs @@ -90,7 +90,7 @@ impl ConsensusStateTrait for ConsensusState { self.0.timestamp.into() } - fn encode_vec(self) -> Vec { - >::encode_vec(self) + fn into_any(self) -> Any { + self.into() } } diff --git a/ibc-core/ics02-client/context/src/consensus_state.rs b/ibc-core/ics02-client/context/src/consensus_state.rs index 195e19625..41e58b460 100644 --- a/ibc-core/ics02-client/context/src/consensus_state.rs +++ b/ibc-core/ics02-client/context/src/consensus_state.rs @@ -2,6 +2,7 @@ use ibc_core_commitment_types::commitment::CommitmentRoot; use ibc_primitives::prelude::*; +use ibc_primitives::proto::Any; use ibc_primitives::Timestamp; /// Defines methods that all `ConsensusState`s should provide. @@ -18,5 +19,5 @@ pub trait ConsensusState: Send + Sync { /// Serializes the `ConsensusState`. This is expected to be implemented as /// first converting to the raw type (i.e. the protobuf definition), and then /// serializing that. - fn encode_vec(self) -> Vec; + fn into_any(self) -> Any; } diff --git a/ibc-core/ics02-client/src/handler/recover_client.rs b/ibc-core/ics02-client/src/handler/recover_client.rs index b434e460b..156f27c44 100644 --- a/ibc-core/ics02-client/src/handler/recover_client.rs +++ b/ibc-core/ics02-client/src/handler/recover_client.rs @@ -83,7 +83,7 @@ where ctx.get_client_execution_context(), &subject_client_id, substitute_client_state.into(), - substitute_consensus_state.into(), + substitute_consensus_state.into_any(), )?; Ok(()) 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 aca9bad68..c6efc7348 100644 --- a/ibc-core/ics03-connection/src/handler/conn_open_ack.rs +++ b/ibc-core/ics03-connection/src/handler/conn_open_ack.rs @@ -128,7 +128,7 @@ where &msg.proof_consensus_state_of_a_on_b, consensus_state_of_b_on_a.root(), Path::ClientConsensusState(client_cons_state_path_on_b), - expected_consensus_state_of_a_on_b.encode_vec(), + expected_consensus_state_of_a_on_b.into_any().to_vec(), ) .map_err(|e| ConnectionError::ConsensusStateVerificationFailure { height: msg.proofs_height_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 99e15f209..f428161d8 100644 --- a/ibc-core/ics03-connection/src/handler/conn_open_try.rs +++ b/ibc-core/ics03-connection/src/handler/conn_open_try.rs @@ -124,7 +124,7 @@ where &msg.proof_consensus_state_of_b_on_a, consensus_state_of_a_on_b.root(), Path::ClientConsensusState(client_cons_state_path_on_a), - expected_consensus_state_of_b_on_a.encode_vec(), + expected_consensus_state_of_b_on_a.into_any().to_vec(), ) .map_err(|e| ConnectionError::ConsensusStateVerificationFailure { height: msg.proofs_height_on_a, diff --git a/ibc-derive/src/consensus_state.rs b/ibc-derive/src/consensus_state.rs index 4ac97a578..0d4f6c6ec 100644 --- a/ibc-derive/src/consensus_state.rs +++ b/ibc-derive/src/consensus_state.rs @@ -20,15 +20,16 @@ pub fn consensus_state_derive_impl(ast: DeriveInput, imports: &Imports) -> Token quote! {timestamp(cs)}, imports, ); - let encode_vec_impl = delegate_call_in_match( + let into_any_impl = delegate_call_in_match( enum_name, enum_variants.iter(), - quote! {encode_vec(cs)}, + quote! {into_any(cs)}, imports, ); let CommitmentRoot = imports.commitment_root(); let ConsensusState = imports.consensus_state(); + let proto_any = imports.any(); let Timestamp = imports.timestamp(); quote! { @@ -45,9 +46,9 @@ pub fn consensus_state_derive_impl(ast: DeriveInput, imports: &Imports) -> Token } } - fn encode_vec(self) -> Vec { + fn into_any(self) -> #proto_any { match self { - #(#encode_vec_impl),* + #(#into_any_impl),* } } } diff --git a/ibc-testkit/src/testapp/ibc/clients/mock/consensus_state.rs b/ibc-testkit/src/testapp/ibc/clients/mock/consensus_state.rs index 8a2e31e58..dbc611f11 100644 --- a/ibc-testkit/src/testapp/ibc/clients/mock/consensus_state.rs +++ b/ibc-testkit/src/testapp/ibc/clients/mock/consensus_state.rs @@ -99,7 +99,7 @@ impl ConsensusState for MockConsensusState { self.header.timestamp } - fn encode_vec(self) -> Vec { - >::encode_vec(self) + fn into_any(self) -> Any { + self.into() } } From d83d85b3f90102ff20ecdf835b17c23c61898ed1 Mon Sep 17 00:00:00 2001 From: Ranadeep Biswas Date: Thu, 25 Apr 2024 18:27:32 +0200 Subject: [PATCH 04/14] consume new_client_state later --- .../ics07-tendermint/src/client_state/execution.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/ibc-clients/ics07-tendermint/src/client_state/execution.rs b/ibc-clients/ics07-tendermint/src/client_state/execution.rs index 5f0cb36f4..7e844b21c 100644 --- a/ibc-clients/ics07-tendermint/src/client_state/execution.rs +++ b/ibc-clients/ics07-tendermint/src/client_state/execution.rs @@ -403,11 +403,6 @@ where let tm_consensus_state = ConsensusStateType::try_from(substitute_consensus_state)?; - ctx.store_client_state( - ClientStatePath::new(subject_client_id.clone()), - new_client_state.into(), - )?; - ctx.store_consensus_state( ClientConsensusStatePath::new( subject_client_id.clone(), @@ -417,6 +412,11 @@ where tm_consensus_state.into(), )?; + ctx.store_client_state( + ClientStatePath::new(subject_client_id.clone()), + new_client_state.into(), + )?; + ctx.store_update_meta( subject_client_id.clone(), latest_height, From a47744e177392cb0b11fcaf8cf1b65e85702cb38 Mon Sep 17 00:00:00 2001 From: Ranadeep Biswas Date: Thu, 25 Apr 2024 18:27:51 +0200 Subject: [PATCH 05/14] update ibc_derive --- ibc-derive/src/client_state/traits/client_state_execution.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/ibc-derive/src/client_state/traits/client_state_execution.rs b/ibc-derive/src/client_state/traits/client_state_execution.rs index 64c9770c2..ddecb00ad 100644 --- a/ibc-derive/src/client_state/traits/client_state_execution.rs +++ b/ibc-derive/src/client_state/traits/client_state_execution.rs @@ -47,7 +47,7 @@ pub(crate) fn impl_ClientStateExecution( client_state_enum_name, enum_variants.iter(), opts, - quote! { update_on_recovery(cs, ctx, client_id, substitute_client_state) }, + quote! { update_on_recovery(cs, ctx, client_id, substitute_client_state, substitute_consensus_state) }, imports, ); @@ -121,6 +121,7 @@ pub(crate) fn impl_ClientStateExecution( ctx: &mut #E, client_id: &#ClientId, substitute_client_state: #Any, + substitute_consensus_state: #Any, ) -> core::result::Result<(), #ClientError> { match self { #(#update_on_recovery_impl),* From 66321c63c5e320cb0167991382dcd01709ddb104 Mon Sep 17 00:00:00 2001 From: Ranadeep Biswas Date: Thu, 25 Apr 2024 18:30:53 +0200 Subject: [PATCH 06/14] update mock client state --- .../src/testapp/ibc/clients/mock/client_state.rs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/ibc-testkit/src/testapp/ibc/clients/mock/client_state.rs b/ibc-testkit/src/testapp/ibc/clients/mock/client_state.rs index 6bb841f0e..38df856a7 100644 --- a/ibc-testkit/src/testapp/ibc/clients/mock/client_state.rs +++ b/ibc-testkit/src/testapp/ibc/clients/mock/client_state.rs @@ -440,6 +440,7 @@ where ctx: &mut E, subject_client_id: &ClientId, substitute_client_state: Any, + substitute_consensus_state: Any, ) -> Result<(), ClientError> { let substitute_client_state = MockClientState::try_from(substitute_client_state)?; @@ -453,6 +454,17 @@ where let host_timestamp = ctx.host_timestamp()?; let host_height = ctx.host_height()?; + let mock_consensus_state = MockConsensusState::try_from(substitute_consensus_state)?; + + ctx.store_consensus_state( + ClientConsensusStatePath::new( + subject_client_id.clone(), + new_mock_client_state.latest_height().revision_number(), + new_mock_client_state.latest_height().revision_height(), + ), + mock_consensus_state.into(), + )?; + ctx.store_client_state( ClientStatePath::new(subject_client_id.clone()), new_mock_client_state.into(), From 4c67e838116ee881c6b2f933a2ab271e0e884a3b Mon Sep 17 00:00:00 2001 From: Ranadeep Biswas Date: Thu, 25 Apr 2024 18:35:13 +0200 Subject: [PATCH 07/14] cargo format --- ibc-core/ics02-client/src/handler/recover_client.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/ibc-core/ics02-client/src/handler/recover_client.rs b/ibc-core/ics02-client/src/handler/recover_client.rs index 156f27c44..1659c892c 100644 --- a/ibc-core/ics02-client/src/handler/recover_client.rs +++ b/ibc-core/ics02-client/src/handler/recover_client.rs @@ -4,7 +4,8 @@ use ibc_core_client_context::prelude::*; use ibc_core_client_types::error::ClientError; use ibc_core_client_types::msgs::MsgRecoverClient; use ibc_core_handler_types::error::ContextError; -use ibc_core_host::{types::path::ClientConsensusStatePath, ExecutionContext, ValidationContext}; +use ibc_core_host::types::path::ClientConsensusStatePath; +use ibc_core_host::{ExecutionContext, ValidationContext}; /// Performs the validation steps associated with the client recovery process. This /// includes validating that the parameters of the subject and substitute clients match, From e449bb762f87b3f793f682383457f4c9fe20c5ba Mon Sep 17 00:00:00 2001 From: Sean Chen Date: Thu, 25 Apr 2024 11:36:30 -0500 Subject: [PATCH 08/14] Change `use` statement formatting --- ibc-core/ics02-client/src/handler/recover_client.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/ibc-core/ics02-client/src/handler/recover_client.rs b/ibc-core/ics02-client/src/handler/recover_client.rs index 156f27c44..1659c892c 100644 --- a/ibc-core/ics02-client/src/handler/recover_client.rs +++ b/ibc-core/ics02-client/src/handler/recover_client.rs @@ -4,7 +4,8 @@ use ibc_core_client_context::prelude::*; use ibc_core_client_types::error::ClientError; use ibc_core_client_types::msgs::MsgRecoverClient; use ibc_core_handler_types::error::ContextError; -use ibc_core_host::{types::path::ClientConsensusStatePath, ExecutionContext, ValidationContext}; +use ibc_core_host::types::path::ClientConsensusStatePath; +use ibc_core_host::{ExecutionContext, ValidationContext}; /// Performs the validation steps associated with the client recovery process. This /// includes validating that the parameters of the subject and substitute clients match, From 57bfb99ef4224f0722e534b72483e36fed169103 Mon Sep 17 00:00:00 2001 From: Ranadeep Biswas Date: Thu, 25 Apr 2024 18:47:25 +0200 Subject: [PATCH 09/14] add store_update_meta at MockClientState::initialise --- ibc-testkit/src/testapp/ibc/clients/mock/client_state.rs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/ibc-testkit/src/testapp/ibc/clients/mock/client_state.rs b/ibc-testkit/src/testapp/ibc/clients/mock/client_state.rs index 38df856a7..05ff95440 100644 --- a/ibc-testkit/src/testapp/ibc/clients/mock/client_state.rs +++ b/ibc-testkit/src/testapp/ibc/clients/mock/client_state.rs @@ -343,6 +343,12 @@ where ), mock_consensus_state.into(), )?; + ctx.store_update_meta( + client_id.clone(), + self.latest_height(), + ctx.host_timestamp()?, + ctx.host_height()?, + )?; Ok(()) } From 18375cbf5425d0fc9476b71e402f4a2d5c693811 Mon Sep 17 00:00:00 2001 From: Ranadeep Biswas Date: Thu, 25 Apr 2024 18:50:20 +0200 Subject: [PATCH 10/14] consistent naming --- ibc-derive/src/consensus_state.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ibc-derive/src/consensus_state.rs b/ibc-derive/src/consensus_state.rs index 0d4f6c6ec..581d00fe7 100644 --- a/ibc-derive/src/consensus_state.rs +++ b/ibc-derive/src/consensus_state.rs @@ -29,7 +29,7 @@ pub fn consensus_state_derive_impl(ast: DeriveInput, imports: &Imports) -> Token let CommitmentRoot = imports.commitment_root(); let ConsensusState = imports.consensus_state(); - let proto_any = imports.any(); + let ProtoAny = imports.any(); let Timestamp = imports.timestamp(); quote! { @@ -46,7 +46,7 @@ pub fn consensus_state_derive_impl(ast: DeriveInput, imports: &Imports) -> Token } } - fn into_any(self) -> #proto_any { + fn into_any(self) -> #ProtoAny { match self { #(#into_any_impl),* } From c1c8165d4023e07571243df2295a242f3042f0a4 Mon Sep 17 00:00:00 2001 From: Sean Chen Date: Thu, 25 Apr 2024 13:14:27 -0500 Subject: [PATCH 11/14] Remove `into_any` trait methods --- .../ics07-tendermint/src/consensus_state.rs | 4 ---- .../ics02-client/context/src/consensus_state.rs | 14 ++++++++------ .../ics02-client/src/handler/recover_client.rs | 2 +- .../ics03-connection/src/handler/conn_open_ack.rs | 2 +- .../ics03-connection/src/handler/conn_open_try.rs | 2 +- .../testapp/ibc/clients/mock/consensus_state.rs | 4 ---- 6 files changed, 11 insertions(+), 17 deletions(-) diff --git a/ibc-clients/ics07-tendermint/src/consensus_state.rs b/ibc-clients/ics07-tendermint/src/consensus_state.rs index 426171d37..d923ebb73 100644 --- a/ibc-clients/ics07-tendermint/src/consensus_state.rs +++ b/ibc-clients/ics07-tendermint/src/consensus_state.rs @@ -89,8 +89,4 @@ impl ConsensusStateTrait for ConsensusState { fn timestamp(&self) -> Timestamp { self.0.timestamp.into() } - - fn into_any(self) -> Any { - self.into() - } } diff --git a/ibc-core/ics02-client/context/src/consensus_state.rs b/ibc-core/ics02-client/context/src/consensus_state.rs index 41e58b460..cc584e421 100644 --- a/ibc-core/ics02-client/context/src/consensus_state.rs +++ b/ibc-core/ics02-client/context/src/consensus_state.rs @@ -1,23 +1,25 @@ //! 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 {} + /// 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 { +pub trait ConsensusState: Send + Sync + ConsensusStateDecoder { /// Commitment root of the consensus state, which is used for key-value pair verification. fn root(&self) -> &CommitmentRoot; /// The timestamp of the consensus state fn timestamp(&self) -> Timestamp; - - /// Serializes the `ConsensusState`. This is expected to be implemented as - /// first converting to the raw type (i.e. the protobuf definition), and then - /// serializing that. - fn into_any(self) -> Any; } diff --git a/ibc-core/ics02-client/src/handler/recover_client.rs b/ibc-core/ics02-client/src/handler/recover_client.rs index 1659c892c..1676c6e80 100644 --- a/ibc-core/ics02-client/src/handler/recover_client.rs +++ b/ibc-core/ics02-client/src/handler/recover_client.rs @@ -84,7 +84,7 @@ where ctx.get_client_execution_context(), &subject_client_id, substitute_client_state.into(), - substitute_consensus_state.into_any(), + substitute_consensus_state.into(), )?; Ok(()) 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 c6efc7348..4e76a493a 100644 --- a/ibc-core/ics03-connection/src/handler/conn_open_ack.rs +++ b/ibc-core/ics03-connection/src/handler/conn_open_ack.rs @@ -128,7 +128,7 @@ where &msg.proof_consensus_state_of_a_on_b, consensus_state_of_b_on_a.root(), Path::ClientConsensusState(client_cons_state_path_on_b), - expected_consensus_state_of_a_on_b.into_any().to_vec(), + expected_consensus_state_of_a_on_b.into().to_vec(), ) .map_err(|e| ConnectionError::ConsensusStateVerificationFailure { height: msg.proofs_height_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 f428161d8..d7eb9592f 100644 --- a/ibc-core/ics03-connection/src/handler/conn_open_try.rs +++ b/ibc-core/ics03-connection/src/handler/conn_open_try.rs @@ -124,7 +124,7 @@ where &msg.proof_consensus_state_of_b_on_a, consensus_state_of_a_on_b.root(), Path::ClientConsensusState(client_cons_state_path_on_a), - expected_consensus_state_of_b_on_a.into_any().to_vec(), + expected_consensus_state_of_b_on_a.into().to_vec(), ) .map_err(|e| ConnectionError::ConsensusStateVerificationFailure { height: msg.proofs_height_on_a, diff --git a/ibc-testkit/src/testapp/ibc/clients/mock/consensus_state.rs b/ibc-testkit/src/testapp/ibc/clients/mock/consensus_state.rs index dbc611f11..dec5e9431 100644 --- a/ibc-testkit/src/testapp/ibc/clients/mock/consensus_state.rs +++ b/ibc-testkit/src/testapp/ibc/clients/mock/consensus_state.rs @@ -98,8 +98,4 @@ impl ConsensusState for MockConsensusState { fn timestamp(&self) -> Timestamp { self.header.timestamp } - - fn into_any(self) -> Any { - self.into() - } } From d1edd8613b075ccec952774efc6a6c7b3ff906a4 Mon Sep 17 00:00:00 2001 From: Ranadeep Biswas Date: Fri, 26 Apr 2024 09:01:18 +0200 Subject: [PATCH 12/14] rm ConsensusState::into_any from ibc-derive --- ibc-derive/src/consensus_state.rs | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/ibc-derive/src/consensus_state.rs b/ibc-derive/src/consensus_state.rs index 581d00fe7..87fafcffe 100644 --- a/ibc-derive/src/consensus_state.rs +++ b/ibc-derive/src/consensus_state.rs @@ -20,16 +20,9 @@ pub fn consensus_state_derive_impl(ast: DeriveInput, imports: &Imports) -> Token quote! {timestamp(cs)}, imports, ); - let into_any_impl = delegate_call_in_match( - enum_name, - enum_variants.iter(), - quote! {into_any(cs)}, - imports, - ); let CommitmentRoot = imports.commitment_root(); let ConsensusState = imports.consensus_state(); - let ProtoAny = imports.any(); let Timestamp = imports.timestamp(); quote! { @@ -45,12 +38,6 @@ pub fn consensus_state_derive_impl(ast: DeriveInput, imports: &Imports) -> Token #(#timestamp_impl),* } } - - fn into_any(self) -> #ProtoAny { - match self { - #(#into_any_impl),* - } - } } } } From 0f9f1ee0720c9bec64c7ee5c82266d7b4b0bb195 Mon Sep 17 00:00:00 2001 From: Ranadeep Biswas Date: Fri, 26 Apr 2024 10:23:42 +0200 Subject: [PATCH 13/14] test consensus state recovery --- .../tests/core/ics02_client/recover_client.rs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/ibc-testkit/tests/core/ics02_client/recover_client.rs b/ibc-testkit/tests/core/ics02_client/recover_client.rs index 22fc227a7..e99098d65 100644 --- a/ibc-testkit/tests/core/ics02_client/recover_client.rs +++ b/ibc-testkit/tests/core/ics02_client/recover_client.rs @@ -7,6 +7,7 @@ use ibc::core::client::types::Height; use ibc::core::entrypoint::{execute, validate}; use ibc::core::handler::types::msgs::MsgEnvelope; use ibc::core::host::types::identifiers::ClientId; +use ibc::core::host::types::path::ClientConsensusStatePath; use ibc::core::host::ValidationContext; use ibc::core::primitives::{Signer, Timestamp}; use ibc_testkit::fixtures::core::signer::dummy_account_id; @@ -126,10 +127,27 @@ fn test_recover_client_ok() { assert!(res.is_ok(), "client recovery execution happy path"); + // client state is copied. assert_eq!( ctx.client_state(&msg.subject_client_id).unwrap(), ctx.client_state(&msg.substitute_client_id).unwrap(), ); + + // latest consensus state is copied. + assert_eq!( + ctx.consensus_state(&ClientConsensusStatePath::new( + msg.subject_client_id, + substitute_height.revision_number(), + substitute_height.revision_height(), + )) + .unwrap(), + ctx.consensus_state(&ClientConsensusStatePath::new( + msg.substitute_client_id, + substitute_height.revision_number(), + substitute_height.revision_height(), + )) + .unwrap(), + ); } #[rstest] From 6f52da083289556f9623a821b24af693f97dcdb4 Mon Sep 17 00:00:00 2001 From: Ranadeep Biswas Date: Fri, 26 Apr 2024 13:30:46 +0200 Subject: [PATCH 14/14] link on doc strings --- ibc-core/ics02-client/context/src/client_state.rs | 4 ++-- ibc-core/ics02-client/context/src/consensus_state.rs | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/ibc-core/ics02-client/context/src/client_state.rs b/ibc-core/ics02-client/context/src/client_state.rs index 2254ce1c3..abe496e2f 100644 --- a/ibc-core/ics02-client/context/src/client_state.rs +++ b/ibc-core/ics02-client/context/src/client_state.rs @@ -10,8 +10,8 @@ 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`. +/// 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 {} diff --git a/ibc-core/ics02-client/context/src/consensus_state.rs b/ibc-core/ics02-client/context/src/consensus_state.rs index cc584e421..7d1bfcb77 100644 --- a/ibc-core/ics02-client/context/src/consensus_state.rs +++ b/ibc-core/ics02-client/context/src/consensus_state.rs @@ -6,8 +6,8 @@ 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`. +/// 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 {}