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

Update to ibc-proto v0.38.0 and remove unneeded object-safe trait definitions #3671

Merged
merged 2 commits into from
Oct 20, 2023
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
22 changes: 3 additions & 19 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
4 changes: 1 addition & 3 deletions crates/relayer-types/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,12 @@ 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" }
serde = { version = "1.0" }
serde_json = { version = "1" }
erased-serde = { version = "0.3" }
prost = { version = "0.12" }
bytes = { version = "1.4.0" }
subtle-encoding = { version = "0.5" }
Expand All @@ -39,7 +38,6 @@ derive_more = { version = "0.99.17", default-features = false, features = ["from
uint = { version = "0.9" }
itertools = { version = "0.10.3" }
primitive-types = { version = "0.12.1", default-features = false, features = ["serde_no_std"] }
dyn-clone = "1.0.12"
num-rational = "0.4.1"
regex = "1"

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
Loading