Skip to content

Update MsgUpdateClient handlers to accept misbehaviour reports via its client_message field #1075

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

Merged
merged 13 commits into from
Feb 6, 2024
Merged
Show file tree
Hide file tree
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
20 changes: 10 additions & 10 deletions ibc-clients/ics07-tendermint/src/client_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,15 @@ use ibc_client_tendermint_types::proto::v1::ClientState as RawTmClientState;
use ibc_client_tendermint_types::{
client_type as tm_client_type, ClientState as ClientStateType,
ConsensusState as ConsensusStateType, Header as TmHeader, Misbehaviour as TmMisbehaviour,
TENDERMINT_HEADER_TYPE_URL, TENDERMINT_MISBEHAVIOUR_TYPE_URL,
};
use ibc_core_client::context::client_state::{
ClientStateCommon, ClientStateExecution, ClientStateValidation,
};
use ibc_core_client::context::consensus_state::ConsensusState;
use ibc_core_client::context::{ClientExecutionContext, ClientValidationContext};
use ibc_core_client::types::error::{ClientError, UpgradeClientError};
use ibc_core_client::types::{Height, Status, UpdateKind};
use ibc_core_client::types::{Height, Status};
use ibc_core_commitment_types::commitment::{
CommitmentPrefix, CommitmentProofBytes, CommitmentRoot,
};
Expand Down Expand Up @@ -240,17 +241,17 @@ where
ctx: &V,
client_id: &ClientId,
client_message: Any,
update_kind: &UpdateKind,
) -> Result<(), ClientError> {
match update_kind {
UpdateKind::UpdateClient => {
match client_message.type_url.as_str() {
TENDERMINT_HEADER_TYPE_URL => {
let header = TmHeader::try_from(client_message)?;
self.verify_header(ctx, client_id, header)
}
UpdateKind::SubmitMisbehaviour => {
TENDERMINT_MISBEHAVIOUR_TYPE_URL => {
let misbehaviour = TmMisbehaviour::try_from(client_message)?;
self.verify_misbehaviour(ctx, client_id, misbehaviour)
}
_ => Err(ClientError::InvalidUpdateClientMessage),
}
}

Expand All @@ -259,17 +260,17 @@ where
ctx: &V,
client_id: &ClientId,
client_message: Any,
update_kind: &UpdateKind,
) -> Result<bool, ClientError> {
match update_kind {
UpdateKind::UpdateClient => {
match client_message.type_url.as_str() {
TENDERMINT_HEADER_TYPE_URL => {
let header = TmHeader::try_from(client_message)?;
self.check_for_misbehaviour_update_client(ctx, client_id, header)
}
UpdateKind::SubmitMisbehaviour => {
TENDERMINT_MISBEHAVIOUR_TYPE_URL => {
let misbehaviour = TmMisbehaviour::try_from(client_message)?;
self.check_for_misbehaviour_misbehavior(&misbehaviour)
}
_ => Err(ClientError::InvalidUpdateClientMessage),
}
}

Expand Down Expand Up @@ -407,7 +408,6 @@ where
ctx: &mut E,
client_id: &ClientId,
_client_message: Any,
_update_kind: &UpdateKind,
) -> Result<(), ClientError> {
// NOTE: frozen height is set to `Height {revision_height: 0,
// revision_number: 1}` and it is the same for all misbehaviour. This
Expand Down
2 changes: 1 addition & 1 deletion ibc-clients/ics07-tendermint/types/src/misbehaviour.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use ibc_proto::Protobuf;
use crate::error::Error;
use crate::header::Header;

const TENDERMINT_MISBEHAVIOUR_TYPE_URL: &str = "/ibc.lightclients.tendermint.v1.Misbehaviour";
pub const TENDERMINT_MISBEHAVIOUR_TYPE_URL: &str = "/ibc.lightclients.tendermint.v1.Misbehaviour";

/// Tendermint light client's misbehaviour type
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
Expand Down
5 changes: 1 addition & 4 deletions ibc-core/ics02-client/context/src/client_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
use core::marker::{Send, Sync};

use ibc_core_client_types::error::ClientError;
use ibc_core_client_types::{Height, Status, UpdateKind};
use ibc_core_client_types::{Height, Status};
use ibc_core_commitment_types::commitment::{
CommitmentPrefix, CommitmentProofBytes, CommitmentRoot,
};
Expand Down Expand Up @@ -107,7 +107,6 @@ where
ctx: &V,
client_id: &ClientId,
client_message: Any,
update_kind: &UpdateKind,
) -> Result<(), ClientError>;

/// Checks for evidence of a misbehaviour in Header or Misbehaviour type. It
Expand All @@ -117,7 +116,6 @@ where
ctx: &V,
client_id: &ClientId,
client_message: Any,
update_kind: &UpdateKind,
) -> Result<bool, ClientError>;

/// Returns the status of the client. Only Active clients are allowed to process packets.
Expand Down Expand Up @@ -168,7 +166,6 @@ where
ctx: &mut E,
client_id: &ClientId,
client_message: Any,
update_kind: &UpdateKind,
) -> Result<(), ClientError>;

// Update the client state and consensus state in the store with the upgraded ones.
Expand Down
8 changes: 0 additions & 8 deletions ibc-core/ics02-client/src/handler/update_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,6 @@ where
ctx.validate_message_signer(msg.signer())?;

let client_id = msg.client_id().clone();
let update_kind = match msg {
MsgUpdateOrMisbehaviour::UpdateClient(_) => UpdateKind::UpdateClient,
MsgUpdateOrMisbehaviour::Misbehaviour(_) => UpdateKind::SubmitMisbehaviour,
};

// Read client state from the host chain store. The client should already exist.
let client_state = ctx.client_state(&client_id)?;
Expand All @@ -38,7 +34,6 @@ where
ctx.get_client_validation_context(),
&client_id,
client_message,
&update_kind,
)?;

Ok(())
Expand All @@ -54,22 +49,19 @@ where
MsgUpdateOrMisbehaviour::Misbehaviour(_) => UpdateKind::SubmitMisbehaviour,
};
let client_message = msg.client_message();

let client_state = ctx.client_state(&client_id)?;

let found_misbehaviour = client_state.check_for_misbehaviour(
ctx.get_client_validation_context(),
&client_id,
client_message.clone(),
&update_kind,
)?;

if found_misbehaviour {
client_state.update_state_on_misbehaviour(
ctx.get_client_execution_context(),
&client_id,
client_message,
&update_kind,
)?;

let event = IbcEvent::ClientMisbehaviour(ClientMisbehaviour::new(
Expand Down
2 changes: 2 additions & 0 deletions ibc-core/ics02-client/types/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@ pub enum ClientError {
ClientSpecific { description: String },
/// client counter overflow error
CounterOverflow,
/// update client message did not contain valid header or misbehaviour
InvalidUpdateClientMessage,
/// other error: `{description}`
Other { description: String },
}
Expand Down
4 changes: 1 addition & 3 deletions ibc-derive/src/client_state/traits/client_state_execution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ pub(crate) fn impl_ClientStateExecution(
client_state_enum_name,
enum_variants.iter(),
opts,
quote! { update_state_on_misbehaviour(cs, ctx, client_id, client_message, update_kind) },
quote! { update_state_on_misbehaviour(cs, ctx, client_id, client_message) },
imports,
);

Expand All @@ -48,7 +48,6 @@ pub(crate) fn impl_ClientStateExecution(
let ClientId = imports.client_id();
let ClientError = imports.client_error();
let ClientStateExecution = imports.client_state_execution();
let UpdateKind = imports.update_kind();
let Height = imports.height();

// The types we need for the generated code.
Expand Down Expand Up @@ -91,7 +90,6 @@ pub(crate) fn impl_ClientStateExecution(
ctx: &mut #ClientExecutionContext,
client_id: &#ClientId,
client_message: #Any,
update_kind: &#UpdateKind,
) -> core::result::Result<(), #ClientError> {
match self {
#(#update_state_on_misbehaviour_impl),*
Expand Down
7 changes: 2 additions & 5 deletions ibc-derive/src/client_state/traits/client_state_validation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@ pub(crate) fn impl_ClientStateValidation(
client_state_enum_name,
enum_variants.iter(),
opts,
quote! { verify_client_message(cs, ctx, client_id, client_message, update_kind) },
quote! { verify_client_message(cs, ctx, client_id, client_message) },
imports,
);

let check_for_misbehaviour_impl = delegate_call_in_match(
client_state_enum_name,
enum_variants.iter(),
opts,
quote! { check_for_misbehaviour(cs, ctx, client_id, client_message, update_kind) },
quote! { check_for_misbehaviour(cs, ctx, client_id, client_message) },
imports,
);

Expand All @@ -43,7 +43,6 @@ pub(crate) fn impl_ClientStateValidation(
let ClientError = imports.client_error();
let ClientStateValidation = imports.client_state_validation();
let Status = imports.status();
let UpdateKind = imports.update_kind();

// The types we need for the generated code.
let HostClientState = client_state_enum_name;
Expand All @@ -63,7 +62,6 @@ pub(crate) fn impl_ClientStateValidation(
ctx: &#ClientValidationContext,
client_id: &#ClientId,
client_message: #Any,
update_kind: &#UpdateKind,
) -> core::result::Result<(), #ClientError> {
match self {
#(#verify_client_message_impl),*
Expand All @@ -75,7 +73,6 @@ pub(crate) fn impl_ClientStateValidation(
ctx: &#ClientValidationContext,
client_id: &#ClientId,
client_message: #Any,
update_kind: &#UpdateKind,
) -> core::result::Result<bool, #ClientError> {
match self {
#(#check_for_misbehaviour_impl),*
Expand Down
5 changes: 0 additions & 5 deletions ibc-derive/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,11 +102,6 @@ impl Imports {
quote! {#prefix::primitives::Timestamp}
}

pub fn update_kind(&self) -> TokenStream {
let prefix = self.prefix();
quote! {#prefix::client::types::UpdateKind}
}

pub fn status(&self) -> TokenStream {
let prefix = self.prefix();
quote! {#prefix::client::types::Status}
Expand Down
23 changes: 11 additions & 12 deletions ibc-testkit/src/testapp/ibc/clients/mock/client_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use ibc::core::client::context::client_state::{
};
use ibc::core::client::context::{ClientExecutionContext, ClientValidationContext};
use ibc::core::client::types::error::{ClientError, UpgradeClientError};
use ibc::core::client::types::{Height, Status, UpdateKind};
use ibc::core::client::types::{Height, Status};
use ibc::core::commitment_types::commitment::{
CommitmentPrefix, CommitmentProofBytes, CommitmentRoot,
};
Expand All @@ -19,8 +19,8 @@ use ibc::primitives::proto::{Any, Protobuf};

use crate::testapp::ibc::clients::mock::client_state::client_type as mock_client_type;
use crate::testapp::ibc::clients::mock::consensus_state::MockConsensusState;
use crate::testapp::ibc::clients::mock::header::MockHeader;
use crate::testapp::ibc::clients::mock::misbehaviour::Misbehaviour;
use crate::testapp::ibc::clients::mock::header::{MockHeader, MOCK_HEADER_TYPE_URL};
use crate::testapp::ibc::clients::mock::misbehaviour::{Misbehaviour, MOCK_MISBEHAVIOUR_TYPE_URL};
use crate::testapp::ibc::clients::mock::proto::{
ClientState as RawMockClientState, Header as RawMockHeader,
};
Expand Down Expand Up @@ -223,10 +223,9 @@ where
_ctx: &V,
_client_id: &ClientId,
client_message: Any,
update_kind: &UpdateKind,
) -> Result<(), ClientError> {
match update_kind {
UpdateKind::UpdateClient => {
match client_message.type_url.as_str() {
MOCK_HEADER_TYPE_URL => {
let header = MockHeader::try_from(client_message)?;

if self.latest_height() >= header.height() {
Expand All @@ -236,9 +235,10 @@ where
});
}
}
UpdateKind::SubmitMisbehaviour => {
MOCK_MISBEHAVIOUR_TYPE_URL => {
let _misbehaviour = Misbehaviour::try_from(client_message)?;
}
_ => {}
}

Ok(())
Expand All @@ -249,11 +249,10 @@ where
_ctx: &V,
_client_id: &ClientId,
client_message: Any,
update_kind: &UpdateKind,
) -> Result<bool, ClientError> {
match update_kind {
UpdateKind::UpdateClient => Ok(false),
UpdateKind::SubmitMisbehaviour => {
match client_message.type_url.as_str() {
MOCK_HEADER_TYPE_URL => Ok(false),
MOCK_MISBEHAVIOUR_TYPE_URL => {
let misbehaviour = Misbehaviour::try_from(client_message)?;
let header_1 = misbehaviour.header1;
let header_2 = misbehaviour.header2;
Expand All @@ -263,6 +262,7 @@ where

Ok(header_heights_equal && headers_are_in_future)
}
_ => Ok(false),
}
}

Expand Down Expand Up @@ -365,7 +365,6 @@ where
ctx: &mut E,
client_id: &ClientId,
_client_message: Any,
_update_kind: &UpdateKind,
) -> Result<(), ClientError> {
let frozen_client_state = self.with_frozen_height(Height::min(0));

Expand Down
Loading