-
Notifications
You must be signed in to change notification settings - Fork 94
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: implement client recovery feature (#1127)
* Add `MsgRecoverClient` domain type * Working on client recovery validation handler logic * Implement recover_client::validate function * Add ClientStateValidation::check_substitute function * Working on `recover_client::execute` function * Stub out `update_on_recovery` function * Implement standalone `update_on_recovery` function * Change `update_on_recovery` function param * Remove `ClientState::initialise` call from `execute` * Implement `check_substitute` in ics07 * Update `update_on_recovery` function * Add `MsgRecoverClient` domain type * Working on client recovery validation handler logic * Implement recover_client::validate function * Add ClientStateValidation::check_substitute function * Working on `recover_client::execute` function * Stub out `update_on_recovery` function * Implement standalone `update_on_recovery` function * Change `update_on_recovery` function param * Remove `ClientState::initialise` call from `execute` * Implement `check_substitute` in ics07 * Update `update_on_recovery` function * Resolve errors upon rebasing * Add additional bounds on `check_substitute` and `update_on_recovery` * Implement TryFrom<AnyClientState> for ClientStateType * Attempt to implement check_substitute and update_on_recovery in ibc-derive * fix: introduce fully-qualified path to get ibc-derive work * Change substitute client state function params to Any * Update change_substitute and update_on_recovery call sites * Add additional bounds on other validation and execution context methods * Implement `update_on_recovery` for MockClientState * Silence unused variables warning * Add missing MockClientState fields * Fix some typos in doc comments * Remove unnecessary trait bound * Change `upgrade_client_proposal_handler` -> `execute_upgrade_client_proposal` * Add upgrade proposal type url * Remove commented-out trait bounds * Convert Any to ClientState instead of ClientStateType * Improve error message wording * Improve error message wording * Remove unnused function paramter * Replace `self` with `&self` * Convert substitute client state to MockClientState instead of Tm client state * Update ClientNotInactive error variant message * Improve `check_substitute` implementation * Make `Status` type `Copy` * Remove some imports and streamline mock client state initialization * rm redundant methods * Remove unnecessary TryFrom impl * tests: add unit tests for client recovery (#1151) * Initial scaffolding for testing client recovery * Add MsgRecoverClient variant to ClientMsg * Stub out `test_recover_client_ok` * Update recover client test fixture * Perform client updates on subject and substitute clients * Create mock headers with timestamps * Extend substitute client state's trusting period * Remove eprintln statements * Add some more tests * Refactor to not require call to `sleep` * Add docstring for `MockClientState::new` * Formatting * Remove recover_client validate and execute calls from dispatch * Remove recover_client validate and execute calls from dispatch * Call recover_client::validate and execute correctly * Change MockClientState default trusting period to 10 seconds * Add changelog entry --------- Co-authored-by: Farhad Shabani <[email protected]> Co-authored-by: Ranadeep Biswas <[email protected]>
- Loading branch information
1 parent
b0ea4ea
commit 2b9de34
Showing
19 changed files
with
632 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
- [ibc-client] Implement [client recovery][client-recovery] feature. | ||
([\#738](https://github.com/cosmos/ibc-rs/issues/738)) | ||
|
||
client-recovery: https://github.com/cosmos/ibc-go/blob/main/docs/architecture/adr-026-ibc-client-recovery-mechanisms.md |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
//! This module implements the processing logic for ICS2 (client abstractions and functions) msgs. | ||
pub mod create_client; | ||
pub mod recover_client; | ||
pub mod update_client; | ||
pub mod upgrade_client; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
//! Protocol logic for processing ICS02 messages of type `MsgRecoverClient`. | ||
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}; | ||
|
||
/// Performs the validation steps associated with the client recovery process. This | ||
/// includes validating that the parameters of the subject and substitute clients match, | ||
/// as well as validating that the substitute client *is* active and that the subject | ||
/// client is *not* active. | ||
pub fn validate<Ctx>(ctx: &Ctx, msg: MsgRecoverClient) -> Result<(), ContextError> | ||
where | ||
Ctx: ValidationContext, | ||
{ | ||
let signer = msg.signer; | ||
let subject_client_id = msg.subject_client_id.clone(); | ||
let substitute_client_id = msg.substitute_client_id.clone(); | ||
|
||
ctx.validate_message_signer(&signer)?; | ||
|
||
let client_val_ctx = ctx.get_client_validation_context(); | ||
|
||
let subject_client_state = client_val_ctx.client_state(&subject_client_id)?; | ||
let substitute_client_state = client_val_ctx.client_state(&substitute_client_id)?; | ||
|
||
let subject_height = subject_client_state.latest_height(); | ||
let substitute_height = substitute_client_state.latest_height(); | ||
|
||
if subject_height >= substitute_height { | ||
return Err(ClientError::ClientRecoveryHeightMismatch { | ||
subject_height, | ||
substitute_height, | ||
} | ||
.into()); | ||
} | ||
|
||
substitute_client_state | ||
.status(ctx.get_client_validation_context(), &substitute_client_id)? | ||
.verify_is_active()?; | ||
|
||
// Verify that the subject client is inactive, i.e., that it is either frozen or expired | ||
subject_client_state | ||
.status(ctx.get_client_validation_context(), &subject_client_id)? | ||
.verify_is_inactive()?; | ||
|
||
// Check that the subject client state and substitute client states match, i.e., that | ||
// all their respective client state parameters match except for frozen height, latest | ||
// height, trusting period, and chain ID | ||
subject_client_state.check_substitute( | ||
ctx.get_client_validation_context(), | ||
substitute_client_state.into(), | ||
)?; | ||
|
||
Ok(()) | ||
} | ||
|
||
/// Executes the steps needed to recover the subject client, namely: | ||
/// - setting the subject's status from either `frozen` or `expired` to `active` | ||
/// - copying the substitute client's consensus state as the subject's consensus state | ||
/// - setting the subject client's processed height and processed time values to match the substitute client's | ||
/// - setting the subject client's latest height, trusting period, and chain ID values to match the substitute client's | ||
pub fn execute<Ctx>(ctx: &mut Ctx, msg: MsgRecoverClient) -> Result<(), ContextError> | ||
where | ||
Ctx: ExecutionContext, | ||
{ | ||
let subject_client_id = msg.subject_client_id.clone(); | ||
let substitute_client_id = msg.substitute_client_id.clone(); | ||
|
||
let client_exec_ctx = ctx.get_client_execution_context(); | ||
|
||
let subject_client_state = client_exec_ctx.client_state(&subject_client_id)?; | ||
let substitute_client_state = client_exec_ctx.client_state(&substitute_client_id)?; | ||
|
||
subject_client_state.update_on_recovery( | ||
ctx.get_client_execution_context(), | ||
&subject_client_id, | ||
substitute_client_state.into(), | ||
)?; | ||
|
||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.