Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(ibc-core): copy substitute consensus state during client recovery #1197

Merged
merged 17 commits into from
Apr 26, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Pass substitute consensus state into client recovery methods
seanchen1991 committed Apr 25, 2024
commit 005ae23ca7b0555595a7c3a64e723cdc36d4cfb3
15 changes: 15 additions & 0 deletions ibc-clients/ics07-tendermint/src/client_state/execution.rs
Original file line number Diff line number Diff line change
@@ -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<E>(
ctx: &mut E,
subject_client_id: &ClientId,
substitute_client_state: Any,
substitute_consensus_state: Any,
) -> Result<(), ClientError>
where
E: ExtClientExecutionContext,
E::ClientStateRef: From<ClientStateType>,
E::ConsensusStateRef: Convertible<ConsensusStateType, ClientError>,
{
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,
1 change: 1 addition & 0 deletions ibc-core/ics02-client/context/src/client_state.rs
Original file line number Diff line number Diff line change
@@ -202,6 +202,7 @@ where
ctx: &mut E,
subject_client_id: &ClientId,
substitute_client_state: Any,
substitute_consensus_state: Any,
) -> Result<(), ClientError>;
}

9 changes: 8 additions & 1 deletion ibc-core/ics02-client/src/handler/recover_client.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
//! Protocol logic for processing ICS02 messages of type `MsgRecoverClient`.

use ibc_core_client_context::prelude::*;
use ibc_core_client_types::error::ClientError;

Check warning on line 4 in ibc-core/ics02-client/src/handler/recover_client.rs

GitHub Actions / nightly_fmt

Diff in /home/runner/work/ibc-rs/ibc-rs/ibc-core/ics02-client/src/handler/recover_client.rs
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 @@

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(),

Check failure on line 86 in ibc-core/ics02-client/src/handler/recover_client.rs

GitHub Actions / Check no_std panic conflict

the trait bound `ibc_primitives::proto::Any: From<<<Ctx as ExecutionContext>::E as ibc_core_client_context::ClientValidationContext>::ConsensusStateRef>` is not satisfied

Check failure on line 86 in ibc-core/ics02-client/src/handler/recover_client.rs

GitHub Actions / Check no_std substrate support

the trait bound `ibc_primitives::proto::Any: From<<<Ctx as ExecutionContext>::E as ibc_core_client_context::ClientValidationContext>::ConsensusStateRef>` is not satisfied

Check failure on line 86 in ibc-core/ics02-client/src/handler/recover_client.rs

GitHub Actions / Compile and upload Tendermint CosmWasm client

the trait bound `ibc_primitives::proto::Any: From<<<Ctx as ExecutionContext>::E as ibc_core_client_context::ClientValidationContext>::ConsensusStateRef>` is not satisfied

Check failure on line 86 in ibc-core/ics02-client/src/handler/recover_client.rs

GitHub Actions / Code Coverage

the trait bound `ibc_primitives::proto::Any: From<<<Ctx as ExecutionContext>::E as ibc_core_client_context::ClientValidationContext>::ConsensusStateRef>` is not satisfied

Check failure on line 86 in ibc-core/ics02-client/src/handler/recover_client.rs

GitHub Actions / doc_all_features

the trait bound `ibc_primitives::proto::Any: From<<<Ctx as ExecutionContext>::E as ibc_core_client_context::ClientValidationContext>::ConsensusStateRef>` is not satisfied

Check failure on line 86 in ibc-core/ics02-client/src/handler/recover_client.rs

GitHub Actions / doc_no_default_features

the trait bound `ibc_primitives::proto::Any: From<<<Ctx as ExecutionContext>::E as ibc_core_client_context::ClientValidationContext>::ConsensusStateRef>` is not satisfied

Check failure on line 86 in ibc-core/ics02-client/src/handler/recover_client.rs

GitHub Actions / test-stable

the trait bound `ibc_primitives::proto::Any: From<<<Ctx as ExecutionContext>::E as ibc_core_client_context::ClientValidationContext>::ConsensusStateRef>` is not satisfied

Check failure on line 86 in ibc-core/ics02-client/src/handler/recover_client.rs

GitHub Actions / clippy

the trait bound `ibc_primitives::proto::Any: core::convert::From<<<Ctx as ibc_core_host::ExecutionContext>::E as ibc_core_client_context::ClientValidationContext>::ConsensusStateRef>` is not satisfied

error[E0277]: the trait bound `ibc_primitives::proto::Any: core::convert::From<<<Ctx as ibc_core_host::ExecutionContext>::E as ibc_core_client_context::ClientValidationContext>::ConsensusStateRef>` is not satisfied --> ibc-core/ics02-client/src/handler/recover_client.rs:86:36 | 86 | substitute_consensus_state.into(), | ^^^^ the trait `core::convert::From<<<Ctx as ibc_core_host::ExecutionContext>::E as ibc_core_client_context::ClientValidationContext>::ConsensusStateRef>` is not implemented for `ibc_primitives::proto::Any`, which is required by `<<Ctx as ibc_core_host::ExecutionContext>::E as ibc_core_client_context::ClientValidationContext>::ConsensusStateRef: core::convert::Into<_>` | = note: required for `<<Ctx as ibc_core_host::ExecutionContext>::E as ibc_core_client_context::ClientValidationContext>::ConsensusStateRef` to implement `core::convert::Into<ibc_primitives::proto::Any>` help: consider extending the `where` clause, but there might be an alternative better way to express this requirement | 66 | Ctx: ExecutionContext, ibc_primitives::proto::Any: core::convert::From<<<Ctx as ibc_core_host::ExecutionContext>::E as ibc_core_client_context::ClientValidationContext>::ConsensusStateRef> | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
)?;

Ok(())