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: revert frozen_height to 0 for active clients in conversions #1064

Merged
merged 4 commits into from
Jan 29, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
20 changes: 16 additions & 4 deletions ibc-clients/ics07-tendermint/types/src/client_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use core::str::FromStr;
use core::time::Duration;

use ibc_core_client_types::error::ClientError;
use ibc_core_client_types::proto::v1::Height as RawHeight;
use ibc_core_client_types::Height;
use ibc_core_commitment_types::specs::ProofSpecs;
use ibc_core_host_types::identifiers::ChainId;
Expand Down Expand Up @@ -283,10 +284,11 @@ impl TryFrom<RawTmClientState> for ClientState {
.try_into()
.map_err(|_| Error::MissingLatestHeight)?;

// In `RawClientState`, a `frozen_height` of `0` means "not frozen".
// See:
// NOTE: In `RawClientState`, a `frozen_height` of `0` means "not
// frozen". See:
// https://github.com/cosmos/ibc-go/blob/8422d0c4c35ef970539466c5bdec1cd27369bab3/modules/light-clients/07-tendermint/types/client_state.go#L74
let frozen_height = raw.frozen_height.and_then(|h| Height::try_from(h).ok());
let frozen_height =
Height::try_from(raw.frozen_height.ok_or(Error::MissingFrozenHeight)?).ok();

// We use set this deprecated field just so that we can properly convert
// it back in its raw form
Expand Down Expand Up @@ -322,7 +324,17 @@ impl From<ClientState> for RawTmClientState {
trusting_period: Some(value.trusting_period.into()),
unbonding_period: Some(value.unbonding_period.into()),
max_clock_drift: Some(value.max_clock_drift.into()),
frozen_height: value.frozen_height.map(|height| height.into()),
// NOTE: The protobuf encoded `frozen_height` of an active client
// must be set to `0` so that `ibc-go` driven chains can properly
// decode the `ClientState` value. In `RawClientState`, a
// `frozen_height` of `0` means "not frozen". See:
// https://github.com/cosmos/ibc-go/blob/8422d0c4c35ef970539466c5bdec1cd27369bab3/modules/light-clients/07-tendermint/types/client_state.go#L74
frozen_height: Some(value.frozen_height.map(|height| height.into()).unwrap_or(
RawHeight {
revision_number: 0,
revision_height: 0,
},
)),
latest_height: Some(value.latest_height.into()),
proof_specs: value.proof_specs.into(),
upgrade_path: value.upgrade_path,
Expand Down
4 changes: 2 additions & 2 deletions ibc-clients/ics07-tendermint/types/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ pub enum Error {
HeaderTimestampTooLow { actual: String, min: String },
/// header revision height = `{height}` is invalid
InvalidHeaderHeight { height: u64 },
/// Disallowed to create a new client with a frozen height
FrozenHeightNotAllowed,
/// frozen height not found
Farhad-Shabani marked this conversation as resolved.
Show resolved Hide resolved
MissingFrozenHeight,
/// the header's trusted revision number (`{trusted_revision}`) and the update's revision number (`{header_revision}`) should be the same
MismatchHeightRevisions {
trusted_revision: u64,
Expand Down
6 changes: 5 additions & 1 deletion ibc-testkit/tests/core/ics02_client/update_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use ibc::clients::tendermint::types::{
use ibc::core::client::context::client_state::{ClientStateCommon, ClientStateValidation};
use ibc::core::client::context::ClientValidationContext;
use ibc::core::client::types::msgs::{ClientMsg, MsgSubmitMisbehaviour, MsgUpdateClient};
use ibc::core::client::types::proto::v1::Height as RawHeight;
use ibc::core::client::types::Height;
use ibc::core::commitment_types::specs::ProofSpecs;
use ibc::core::entrypoint::{execute, validate};
Expand Down Expand Up @@ -588,7 +589,10 @@ fn test_update_synthetic_tendermint_client_duplicate_ok() {
),
proof_specs: ProofSpecs::default().into(),
upgrade_path: Default::default(),
frozen_height: None,
frozen_height: Some(RawHeight {
revision_number: 0,
revision_height: 0,
}),
allow_update_after_expiry: false,
allow_update_after_misbehaviour: false,
};
Expand Down
Loading