Skip to content

Commit

Permalink
feat(wasm-lc): enable misbehaviour
Browse files Browse the repository at this point in the history
Signed-off-by: aeryz <abdullaheryz@protonmail.com>
  • Loading branch information
aeryz committed Sep 7, 2023
1 parent 003ff54 commit a175834
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 17 deletions.
35 changes: 19 additions & 16 deletions lib/ics-008-wasm-client/src/ibc_client.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
<<<<<<< HEAD
use core::fmt::Debug;

use cosmwasm_std::{Binary, Deps, DepsMut, Env, MessageInfo};
Expand All @@ -8,11 +7,6 @@ use unionlabs::{
lightclients::wasm::{client_state::ClientState, consensus_state::ConsensusState},
},
Proto, TryFromProto, TryFromProtoBytesError, TryFromProtoErrorOf,
=======
use cosmwasm_std::{Binary, Deps, DepsMut, Env, MessageInfo};
use unionlabs::{
ibc::core::client::height::Height, TryFromProto, TryFromProtoBytesError, TryFromProtoErrorOf,
>>>>>>> 5fe89c24 (feat(ics008): introduce `IBCClient`)
};

use crate::{
Expand All @@ -25,9 +19,10 @@ pub enum StorageState {
Empty,
}

<<<<<<< HEAD
pub trait IbcClient {
type Error: From<TryFromProtoBytesError<TryFromProtoErrorOf<Self::Header>>> + From<Error>;
type Error: From<TryFromProtoBytesError<TryFromProtoErrorOf<Self::Header>>>
+ From<Error>
+ ToString;
type CustomQuery: cosmwasm_std::CustomQuery;
// TODO(aeryz): see #583
type Header: TryFromProto;
Expand Down Expand Up @@ -104,15 +99,23 @@ pub trait IbcClient {
ExecuteMsg::UpdateStateOnMisbehaviour { client_message } => {
Self::update_state_on_misbehaviour(deps, client_message)
}
ExecuteMsg::CheckForMisbehaviour { client_message } => match client_message {
ClientMessage::Header(header) => {
let header = Self::Header::try_from_proto_bytes(&header.data)?;
Self::verify_header(deps.as_ref(), env, header)
ExecuteMsg::CheckForMisbehaviour { client_message } => {
let res = match client_message {
ClientMessage::Header(header) => {
let header = Self::Header::try_from_proto_bytes(&header.data)?;
Self::check_for_misbehaviour_on_header(deps.as_ref(), header)
}
ClientMessage::Misbehaviour(_) => {
Ok(ContractResult::invalid("Not implemented".to_string()))
}
};

if let Err(e) = res {
Ok(ContractResult::found_misbehaviour(e.to_string()))
} else {
res
}
ClientMessage::Misbehaviour(_) => {
Ok(ContractResult::invalid("Not implemented".to_string()))
}
},
}
ExecuteMsg::VerifyUpgradeAndUpdateState {
upgrade_client_state,
upgrade_consensus_state,
Expand Down
9 changes: 9 additions & 0 deletions lib/ics-008-wasm-client/src/msg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,15 @@ impl ContractResult {
}

pub fn invalid(error_msg: String) -> Self {
Self {
is_valid: false,
error_msg,
data: None,
found_misbehaviour: false,
}
}

pub fn found_misbehaviour(error_msg: String) -> Self {
Self {
is_valid: false,
error_msg,
Expand Down
3 changes: 2 additions & 1 deletion light-clients/ethereum-light-client/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,7 @@ impl IbcClient for EthereumLightClient {
) -> Result<ics008_wasm_client::ContractResult, Self::Error> {
Ok(ContractResult::invalid("Not implemented".to_string()))
}

fn check_for_misbehaviour_on_header(
deps: Deps<Self::CustomQuery>,
header: Self::Header,
Expand Down Expand Up @@ -309,7 +310,7 @@ impl IbcClient for EthereumLightClient {
}
}

// TODO(aeryz): Do we need to check whether this header's timestamp is between
// TODO(#605): Do we need to check whether this header's timestamp is between
// the next and the previous consensus state in terms of height?

Ok(ContractResult::valid(None))
Expand Down

0 comments on commit a175834

Please sign in to comment.