Skip to content
Open
Changes from all commits
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
24 changes: 24 additions & 0 deletions ibc/modules/src/core/ics02_client/handler/upgrade_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use crate::{
core::{
ics02_client::{
client_consensus::ConsensusState,
client_def::{ClientDef, ConsensusUpdateResult},
client_state::ClientState,
context::ClientTypes,
Expand Down Expand Up @@ -60,6 +61,29 @@ where
return Err(Error::client_frozen(client_id))
}

// need to ensure that the client state is not expired as per
// https://github.com/cosmos/ibc-rs/blob/main/docs/architecture/adr-006-upgrade-client-implementation.md#decisions
let latest_consensus_state =
ctx.consensus_state(&client_id, client_state.latest_height()).map_err(|_| {
Error::consensus_state_not_found(client_id.clone(), client_state.latest_height())
})?;

tracing::debug!("latest consensus state: {:?}", latest_consensus_state);

let now = ctx.host_timestamp();
let last_update_timestamp =
ctx.client_update_time(&client_id, client_state.latest_height()).map_err(|_| {
Error::implementation_specific("Could not find update time for client".to_string())
})?;

let duration = now.duration_since(&last_update_timestamp).ok_or_else(|| {
Error::invalid_consensus_state_timestamp(latest_consensus_state.timestamp(), now)
})?;

if client_state.expired(duration) {
return Err(Error::header_not_within_trust_period(last_update_timestamp, now))
}

let upgrade_client_state = msg.client_state.clone();

if client_state.latest_height() >= upgrade_client_state.latest_height() {
Expand Down