Skip to content

Commit

Permalink
Update to ibc-proto v0.38.0 and remove unneeded object-safe trait def…
Browse files Browse the repository at this point in the history
…initions
  • Loading branch information
romac committed Oct 20, 2023
1 parent 3a41f69 commit 46360c9
Show file tree
Hide file tree
Showing 79 changed files with 268 additions and 853 deletions.
5 changes: 3 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion crates/chain-registry/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ description = """
"""

[dependencies]
ibc-proto = { version = "0.38.0-pre.1", features = ["serde"] }
ibc-proto = { version = "0.38.0", features = ["serde"] }
ibc-relayer-types = { version = "0.25.0", path = "../relayer-types" }
tendermint-rpc = { version = "0.34.0", features = [
"http-client",
Expand Down
2 changes: 1 addition & 1 deletion crates/relayer-types/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ mocks = ["tendermint-testgen", "clock"]

[dependencies]
# Proto definitions for all IBC-related interfaces, e.g., connections or channels.
ibc-proto = { version = "0.38.0-pre.1" }
ibc-proto = { version = "0.38.0" }
ics23 = { version = "0.11.0", features = ["std", "host-functions"] }
time = { version = "0.3" }
serde_derive = { version = "1.0.104" }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use ibc_proto::google::protobuf::Any;
use ibc_proto::ibc::applications::interchain_accounts::v1::CosmosTx as RawCosmosTx;
use ibc_proto::protobuf::Protobuf;
use ibc_proto::Protobuf;
use serde_derive::Deserialize;
use serde_derive::Serialize;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use serde::{Deserialize, Serialize};

use ibc_proto::ibc::applications::interchain_accounts::controller::v1::MsgRegisterInterchainAccount as RawMsgRegisterInterchainAccount;
use ibc_proto::protobuf::Protobuf;
use ibc_proto::Protobuf;

use crate::applications::ics27_ica::error::Error;
use crate::core::ics04_channel::version::Version;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use serde_derive::{Deserialize, Serialize};

use ibc_proto::ibc::applications::interchain_accounts::controller::v1::MsgSendTx as RawMsgSendTx;
use ibc_proto::protobuf::Protobuf;
use ibc_proto::Protobuf;

use crate::applications::ics27_ica::error::Error;
use crate::applications::ics27_ica::packet_data::InterchainAccountPacketData;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use core::fmt;

use ibc_proto::interchain_security::ccv::provider::v1::MsgSubmitConsumerDoubleVoting as RawIcsDoubleVoting;
use ibc_proto::protobuf::Protobuf;
use ibc_proto::Protobuf;
use tendermint::evidence::DuplicateVoteEvidence;

use crate::clients::ics07_tendermint::header::Header;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use core::fmt;
use serde::{Deserialize, Serialize};

use ibc_proto::interchain_security::ccv::provider::v1::MsgSubmitConsumerMisbehaviour as RawIcsMisbehaviour;
use ibc_proto::protobuf::Protobuf;
use ibc_proto::Protobuf;

use crate::clients::ics07_tendermint::misbehaviour::Misbehaviour;
use crate::signer::Signer;
Expand Down
5 changes: 3 additions & 2 deletions crates/relayer-types/src/applications/transfer/error.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
use flex_error::{define_error, DisplayOnly, TraceError};
use ibc_proto::protobuf::Error as TendermintProtoError;
use std::convert::Infallible;
use std::str::Utf8Error;
use std::string::FromUtf8Error;

use flex_error::{define_error, DisplayOnly, TraceError};
use subtle_encoding::Error as EncodingError;
use tendermint_proto::Error as TendermintProtoError;
use uint::FromDecStrErr;

use crate::core::ics04_channel::channel::Ordering;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::fmt::Display;
use std::str::FromStr;

use ibc_proto::protobuf::Protobuf;
use ibc_proto::Protobuf;
use serde_derive::Deserialize;
use serde_derive::Serialize;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
use ibc_proto::cosmos::base::v1beta1::Coin;
use ibc_proto::google::protobuf::Any;
use ibc_proto::ibc::applications::transfer::v1::MsgTransfer as RawMsgTransfer;
use ibc_proto::protobuf::Protobuf;
use ibc_proto::Protobuf;

use crate::applications::transfer::error::Error;
use crate::core::ics04_channel::timeout::TimeoutHeight;
Expand Down
19 changes: 6 additions & 13 deletions crates/relayer-types/src/clients/ics07_tendermint/client_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,13 @@ use serde::{Deserialize, Serialize};
use ibc_proto::google::protobuf::Any;
use ibc_proto::ibc::core::client::v1::Height as RawHeight;
use ibc_proto::ibc::lightclients::tendermint::v1::ClientState as RawTmClientState;
use ibc_proto::protobuf::Protobuf;
use ibc_proto::Protobuf;

use tendermint_light_client_verifier::options::Options;

use crate::clients::ics07_tendermint::error::Error;
use crate::clients::ics07_tendermint::header::Header as TmHeader;
use crate::core::ics02_client::client_state::{
ClientState as Ics2ClientState, UpgradeOptions as CoreUpgradeOptions,
};
use crate::core::ics02_client::client_state::ClientState as Ics2ClientState;
use crate::core::ics02_client::client_type::ClientType;
use crate::core::ics02_client::error::Error as Ics02Error;
use crate::core::ics02_client::trust_threshold::TrustThreshold;
Expand Down Expand Up @@ -199,9 +197,9 @@ pub struct UpgradeOptions {
pub unbonding_period: Duration,
}

impl CoreUpgradeOptions for UpgradeOptions {}

impl Ics2ClientState for ClientState {
type UpgradeOptions = UpgradeOptions;

fn chain_id(&self) -> ChainId {
self.chain_id.clone()
}
Expand All @@ -221,14 +219,9 @@ impl Ics2ClientState for ClientState {
fn upgrade(
&mut self,
upgrade_height: Height,
upgrade_options: &dyn CoreUpgradeOptions,
upgrade_options: UpgradeOptions,
chain_id: ChainId,
) {
let upgrade_options = upgrade_options
.as_any()
.downcast_ref::<UpgradeOptions>()
.expect("UpgradeOptions not of type Tendermint");

// Reset custom fields to zero values
self.trusting_period = ZERO_DURATION;
self.trust_threshold = TrustThreshold::CLIENT_STATE_RESET;
Expand Down Expand Up @@ -363,7 +356,7 @@ impl From<ClientState> for Any {
fn from(client_state: ClientState) -> Self {
Any {
type_url: TENDERMINT_CLIENT_STATE_TYPE_URL.to_string(),
value: Protobuf::<RawTmClientState>::encode_vec(&client_state),
value: Protobuf::<RawTmClientState>::encode_vec(client_state),
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use ibc_proto::google::protobuf::Any;
use ibc_proto::ibc::lightclients::tendermint::v1::ConsensusState as RawConsensusState;
use ibc_proto::protobuf::Protobuf;
use ibc_proto::Protobuf;
use serde::{Deserialize, Serialize};
use tendermint::{hash::Algorithm, time::Time, Hash};
use tendermint_proto::google::protobuf as tpb;
Expand Down Expand Up @@ -123,7 +123,7 @@ impl From<ConsensusState> for Any {
fn from(consensus_state: ConsensusState) -> Self {
Any {
type_url: TENDERMINT_CONSENSUS_STATE_TYPE_URL.to_string(),
value: Protobuf::<RawConsensusState>::encode_vec(&consensus_state),
value: Protobuf::<RawConsensusState>::encode_vec(consensus_state),
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions crates/relayer-types/src/clients/ics07_tendermint/header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::fmt::{Display, Error as FmtError, Formatter};
use bytes::Buf;
use ibc_proto::google::protobuf::Any;
use ibc_proto::ibc::lightclients::tendermint::v1::Header as RawHeader;
use ibc_proto::protobuf::Protobuf;
use ibc_proto::Protobuf;
use prost::Message;
use serde_derive::{Deserialize, Serialize};
use tendermint::block::signed_header::SignedHeader;
Expand Down Expand Up @@ -127,7 +127,7 @@ impl From<Header> for Any {
fn from(header: Header) -> Self {
Any {
type_url: TENDERMINT_HEADER_TYPE_URL.to_string(),
value: Protobuf::<RawHeader>::encode_vec(&header),
value: Protobuf::<RawHeader>::encode_vec(header),
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use ibc_proto::ibc::lightclients::tendermint::v1::Misbehaviour as RawMisbehaviour;
use ibc_proto::protobuf::Protobuf;
use ibc_proto::Protobuf;
use serde::{Deserialize, Serialize};

use crate::clients::ics07_tendermint::error::Error;
Expand Down
82 changes: 5 additions & 77 deletions crates/relayer-types/src/core/ics02_client/client_state.rs
Original file line number Diff line number Diff line change
@@ -1,30 +1,16 @@
use core::fmt::Debug;
use std::marker::{Send, Sync};
use std::time::Duration;

use dyn_clone::DynClone;
use erased_serde::Serialize as ErasedSerialize;
use ibc_proto::google::protobuf::Any;
use ibc_proto::protobuf::Protobuf as ErasedProtobuf;

use crate::core::ics02_client::client_type::ClientType;
use crate::core::ics02_client::error::Error;
use crate::core::ics24_host::identifier::ChainId;
use crate::dynamic_typing::AsAny;

use crate::Height;

use super::consensus_state::ConsensusState;

pub trait ClientState:
AsAny
+ sealed::ErasedPartialEqClientState
+ DynClone
+ ErasedSerialize
+ ErasedProtobuf<Any, Error = Error>
+ core::fmt::Debug
+ Send
+ Sync
pub trait ClientState: Clone + Debug + Send + Sync // Any: From<Self>,
{
type UpgradeOptions;

/// Return the chain identifier which this client is serving (i.e., the client is verifying
/// consensus states from this chain).
fn chain_id(&self) -> ChainId;
Expand Down Expand Up @@ -53,65 +39,7 @@ pub trait ClientState:
fn upgrade(
&mut self,
upgrade_height: Height,
upgrade_options: &dyn UpgradeOptions,
upgrade_options: Self::UpgradeOptions,
chain_id: ChainId,
);

/// Convert into a boxed trait object
fn into_box(self) -> Box<dyn ClientState>
where
Self: Sized,
{
Box::new(self)
}
}

// Implements `Clone` for `Box<dyn ClientState>`
dyn_clone::clone_trait_object!(ClientState);

// Implements `serde::Serialize` for all types that have ClientState as supertrait
erased_serde::serialize_trait_object!(ClientState);

impl PartialEq for dyn ClientState {
fn eq(&self, other: &Self) -> bool {
self.eq_client_state(other)
}
}

// see https://github.com/rust-lang/rust/issues/31740
impl PartialEq<&Self> for Box<dyn ClientState> {
fn eq(&self, other: &&Self) -> bool {
self.eq_client_state(other.as_ref())
}
}

pub fn downcast_client_state<CS: ClientState>(h: &dyn ClientState) -> Option<&CS> {
h.as_any().downcast_ref::<CS>()
}

pub trait UpgradeOptions: AsAny {}

pub struct UpdatedState {
pub client_state: Box<dyn ClientState>,
pub consensus_state: Box<dyn ConsensusState>,
}

mod sealed {
use super::*;

pub trait ErasedPartialEqClientState {
fn eq_client_state(&self, other: &dyn ClientState) -> bool;
}

impl<CS> ErasedPartialEqClientState for CS
where
CS: ClientState + PartialEq,
{
fn eq_client_state(&self, other: &dyn ClientState) -> bool {
other
.as_any()
.downcast_ref::<CS>()
.map_or(false, |h| self == h)
}
}
}
Loading

0 comments on commit 46360c9

Please sign in to comment.