Skip to content

Commit

Permalink
Object safe Protobuf (#2412)
Browse files Browse the repository at this point in the history
* Define protobuf error

* Implement object safe Protobuf trait

* Add test for object safety

* Provide blanket impls for ToBoxed and TryFromIfSized

* Add blanket impl test

* Use more specific bounds

* Seal Protobuf supertraits

* Add mod erased

* Rename erased traits

* Doc comments for Protobuf

* Update code to use ibc_proto::protobuf::Protobuf

* Fix no_std check

* Address review feedback

* Rename Protobuf<T> to Protobuf<Raw>

* Remove Sealed mod

* Rename Into -> CloneInto and return T instead of Box<T>
  • Loading branch information
hu55a1n1 authored Aug 2, 2022
1 parent 0c20629 commit 880d031
Show file tree
Hide file tree
Showing 49 changed files with 335 additions and 45 deletions.
1 change: 1 addition & 0 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 modules/src/applications/transfer/error.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use alloc::string::FromUtf8Error;

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

use crate::core::ics04_channel::channel::Order;
Expand Down
2 changes: 1 addition & 1 deletion modules/src/applications/transfer/msgs/transfer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use crate::prelude::*;
use ibc_proto::cosmos::base::v1beta1::Coin;
use ibc_proto::google::protobuf::Any;
use ibc_proto::ibc::applications::transfer::v1::MsgTransfer as RawMsgTransfer;
use tendermint_proto::Protobuf;
use ibc_proto::protobuf::Protobuf;

use crate::applications::transfer::error::Error;
use crate::core::ics04_channel::timeout::TimeoutHeight;
Expand Down
2 changes: 1 addition & 1 deletion modules/src/clients/ics07_tendermint/client_def.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use core::convert::TryInto;

use ibc_proto::ibc::core::commitment::v1::MerkleProof as RawMerkleProof;
use ibc_proto::protobuf::Protobuf;
use prost::Message;
use tendermint_light_client_verifier::types::{TrustedBlockState, UntrustedBlockState};
use tendermint_light_client_verifier::{ProdVerifier, Verdict, Verifier};
use tendermint_proto::Protobuf;

use crate::clients::ics07_tendermint::client_state::ClientState as TmClientState;
use crate::clients::ics07_tendermint::consensus_state::ConsensusState as TmConsensusState;
Expand Down
2 changes: 1 addition & 1 deletion modules/src/clients/ics07_tendermint/client_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ use crate::prelude::*;
use core::convert::{TryFrom, TryInto};
use core::time::Duration;

use ibc_proto::protobuf::Protobuf;
use serde::{Deserialize, Serialize};
use tendermint_light_client_verifier::options::Options;
use tendermint_proto::Protobuf;

use ibc_proto::ibc::core::client::v1::Height as RawHeight;
use ibc_proto::ibc::lightclients::tendermint::v1::ClientState as RawClientState;
Expand Down
5 changes: 2 additions & 3 deletions modules/src/clients/ics07_tendermint/consensus_state.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
use crate::prelude::*;

use ibc_proto::ibc::lightclients::tendermint::v1::ConsensusState as RawConsensusState;
use ibc_proto::protobuf::Protobuf;
use serde::Serialize;
use tendermint::{hash::Algorithm, time::Time, Hash};
use tendermint_proto::google::protobuf as tpb;
use tendermint_proto::Protobuf;

use ibc_proto::ibc::lightclients::tendermint::v1::ConsensusState as RawConsensusState;

use crate::clients::ics07_tendermint::error::Error;
use crate::clients::ics07_tendermint::header::Header;
Expand Down
2 changes: 1 addition & 1 deletion modules/src/clients/ics07_tendermint/header.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
use core::cmp::Ordering;

use bytes::Buf;
use ibc_proto::protobuf::Protobuf;
use prost::Message;
use serde_derive::{Deserialize, Serialize};
use tendermint::block::signed_header::SignedHeader;
use tendermint::validator::Set as ValidatorSet;
use tendermint_proto::Protobuf;

use crate::alloc::string::ToString;

Expand Down
2 changes: 1 addition & 1 deletion modules/src/clients/ics07_tendermint/misbehaviour.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::prelude::*;

use tendermint_proto::Protobuf;
use ibc_proto::protobuf::Protobuf;

use ibc_proto::ibc::lightclients::tendermint::v1::Misbehaviour as RawMisbehaviour;

Expand Down
2 changes: 1 addition & 1 deletion modules/src/core/ics02_client/client_consensus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ use core::marker::{Send, Sync};

use ibc_proto::google::protobuf::Any as ProtoAny;
use ibc_proto::ibc::core::client::v1::ConsensusStateWithHeight;
use ibc_proto::protobuf::Protobuf;
use serde::Serialize;
use tendermint_proto::Protobuf;

use crate::clients::ics07_tendermint::consensus_state::ConsensusState as TmConsensusState;
use crate::core::ics02_client::client_type::ClientType;
Expand Down
2 changes: 1 addition & 1 deletion modules/src/core/ics02_client/client_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ use core::marker::{Send, Sync};
use core::time::Duration;

use ibc_proto::google::protobuf::Any;
use ibc_proto::protobuf::Protobuf;
use serde::{Deserialize, Serialize};
use tendermint_proto::Protobuf;

use ibc_proto::ibc::core::client::v1::IdentifiedClientState;

Expand Down
2 changes: 1 addition & 1 deletion modules/src/core/ics02_client/error.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::prelude::*;

use flex_error::{define_error, TraceError};
use tendermint_proto::Error as TendermintProtoError;
use ibc_proto::protobuf::Error as TendermintProtoError;

use crate::core::ics02_client::client_type::ClientType;
use crate::core::ics02_client::height::HeightError;
Expand Down
2 changes: 1 addition & 1 deletion modules/src/core/ics02_client/header.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use core::ops::Deref;

use ibc_proto::google::protobuf::Any;
use ibc_proto::protobuf::Protobuf;
use serde_derive::{Deserialize, Serialize};
use subtle_encoding::hex;
use tendermint_proto::Protobuf;

use crate::clients::ics07_tendermint::header::{decode_header, Header as TendermintHeader};
use crate::core::ics02_client::client_type::ClientType;
Expand Down
2 changes: 1 addition & 1 deletion modules/src/core/ics02_client/height.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ use core::num::ParseIntError;
use core::str::FromStr;

use flex_error::{define_error, TraceError};
use ibc_proto::protobuf::Protobuf;
use serde_derive::{Deserialize, Serialize};
use tendermint_proto::Protobuf;

use ibc_proto::ibc::core::client::v1::Height as RawHeight;

Expand Down
2 changes: 1 addition & 1 deletion modules/src/core/ics02_client/misbehaviour.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::prelude::*;

use ibc_proto::google::protobuf::Any;
use tendermint_proto::Protobuf;
use ibc_proto::protobuf::Protobuf;

use crate::clients::ics07_tendermint::misbehaviour::Misbehaviour as TmMisbehaviour;
use crate::core::ics02_client::error::Error;
Expand Down
2 changes: 1 addition & 1 deletion modules/src/core/ics02_client/msgs/create_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
use crate::prelude::*;

use tendermint_proto::Protobuf;
use ibc_proto::protobuf::Protobuf;

use ibc_proto::ibc::core::client::v1::MsgCreateClient as RawMsgCreateClient;

Expand Down
2 changes: 1 addition & 1 deletion modules/src/core/ics02_client/msgs/misbehavior.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::prelude::*;

use ibc_proto::ibc::core::client::v1::MsgSubmitMisbehaviour as RawMsgSubmitMisbehaviour;
use tendermint_proto::Protobuf;
use ibc_proto::protobuf::Protobuf;

use crate::core::ics02_client::error::Error;
use crate::core::ics02_client::misbehaviour::AnyMisbehaviour;
Expand Down
2 changes: 1 addition & 1 deletion modules/src/core/ics02_client/msgs/update_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
use crate::prelude::*;

use tendermint_proto::Protobuf;
use ibc_proto::protobuf::Protobuf;

use ibc_proto::ibc::core::client::v1::MsgUpdateClient as RawMsgUpdateClient;

Expand Down
2 changes: 1 addition & 1 deletion modules/src/core/ics02_client/msgs/upgrade_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
use crate::prelude::*;

use core::str::FromStr;
use tendermint_proto::Protobuf;
use ibc_proto::protobuf::Protobuf;

use ibc_proto::ibc::core::client::v1::MsgUpgradeClient as RawMsgUpgradeClient;
use ibc_proto::ibc::core::commitment::v1::MerkleProof as RawMerkleProof;
Expand Down
2 changes: 1 addition & 1 deletion modules/src/core/ics02_client/trust_threshold.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
use core::{convert::TryFrom, fmt};

use ibc_proto::protobuf::Protobuf;
use serde::{Deserialize, Serialize};
use tendermint_proto::Protobuf;

use ibc_proto::ibc::lightclients::tendermint::v1::Fraction;
use tendermint::trust_threshold::TrustThresholdFraction;
Expand Down
2 changes: 1 addition & 1 deletion modules/src/core/ics03_connection/connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ use core::str::FromStr;
use core::time::Duration;
use core::{fmt, u64};

use ibc_proto::protobuf::Protobuf;
use serde::{Deserialize, Serialize};
use tendermint_proto::Protobuf;

use ibc_proto::ibc::core::connection::v1::{
ConnectionEnd as RawConnectionEnd, Counterparty as RawCounterparty,
Expand Down
2 changes: 1 addition & 1 deletion modules/src/core/ics03_connection/msgs/conn_open_ack.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::prelude::*;

use ibc_proto::ibc::core::connection::v1::MsgConnectionOpenAck as RawMsgConnectionOpenAck;
use tendermint_proto::Protobuf;
use ibc_proto::protobuf::Protobuf;

use crate::core::ics02_client::client_state::AnyClientState;
use crate::core::ics03_connection::error::Error;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::prelude::*;

use tendermint_proto::Protobuf;
use ibc_proto::protobuf::Protobuf;

use ibc_proto::ibc::core::connection::v1::MsgConnectionOpenConfirm as RawMsgConnectionOpenConfirm;

Expand Down
2 changes: 1 addition & 1 deletion modules/src/core/ics03_connection/msgs/conn_open_init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use crate::prelude::*;
use core::time::Duration;

use ibc_proto::ibc::core::connection::v1::MsgConnectionOpenInit as RawMsgConnectionOpenInit;
use tendermint_proto::Protobuf;
use ibc_proto::protobuf::Protobuf;

use crate::core::ics03_connection::connection::Counterparty;
use crate::core::ics03_connection::error::Error;
Expand Down
2 changes: 1 addition & 1 deletion modules/src/core/ics03_connection/msgs/conn_open_try.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use core::{
time::Duration,
};

use tendermint_proto::Protobuf;
use ibc_proto::protobuf::Protobuf;

use ibc_proto::ibc::core::connection::v1::MsgConnectionOpenTry as RawMsgConnectionOpenTry;

Expand Down
2 changes: 1 addition & 1 deletion modules/src/core/ics03_connection/version.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ use core::fmt::Display;
use crate::prelude::*;

use ibc_proto::ibc::core::connection::v1::Version as RawVersion;
use ibc_proto::protobuf::Protobuf;
use serde::{Deserialize, Serialize};
use tendermint_proto::Protobuf;

use crate::core::ics03_connection::error::Error;
use crate::core::ics04_channel::channel::Order;
Expand Down
2 changes: 1 addition & 1 deletion modules/src/core/ics04_channel/channel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ use crate::prelude::*;
use core::fmt;
use core::str::FromStr;

use ibc_proto::protobuf::Protobuf;
use serde::{Deserialize, Serialize};
use tendermint_proto::Protobuf;

use ibc_proto::ibc::core::channel::v1::{
Channel as RawChannel, Counterparty as RawCounterparty,
Expand Down
2 changes: 1 addition & 1 deletion modules/src/core/ics04_channel/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use crate::timestamp::Timestamp;
use crate::Height;

use flex_error::{define_error, TraceError};
use tendermint_proto::Error as TendermintError;
use ibc_proto::protobuf::Error as TendermintError;

define_error! {
#[derive(Debug, PartialEq, Eq)]
Expand Down
2 changes: 1 addition & 1 deletion modules/src/core/ics04_channel/msgs/acknowledgement.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use crate::prelude::*;

use derive_more::{From, Into};
use ibc_proto::ibc::core::channel::v1::MsgAcknowledgement as RawMsgAcknowledgement;
use tendermint_proto::Protobuf;
use ibc_proto::protobuf::Protobuf;

use crate::core::ics04_channel::error::Error;
use crate::core::ics04_channel::packet::Packet;
Expand Down
2 changes: 1 addition & 1 deletion modules/src/core/ics04_channel/msgs/chan_close_confirm.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::prelude::*;

use tendermint_proto::Protobuf;
use ibc_proto::protobuf::Protobuf;

use ibc_proto::ibc::core::channel::v1::MsgChannelCloseConfirm as RawMsgChannelCloseConfirm;

Expand Down
2 changes: 1 addition & 1 deletion modules/src/core/ics04_channel/msgs/chan_close_init.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::prelude::*;

use tendermint_proto::Protobuf;
use ibc_proto::protobuf::Protobuf;

use ibc_proto::ibc::core::channel::v1::MsgChannelCloseInit as RawMsgChannelCloseInit;

Expand Down
2 changes: 1 addition & 1 deletion modules/src/core/ics04_channel/msgs/chan_open_ack.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use crate::signer::Signer;
use crate::tx_msg::Msg;

use ibc_proto::ibc::core::channel::v1::MsgChannelOpenAck as RawMsgChannelOpenAck;
use tendermint_proto::Protobuf;
use ibc_proto::protobuf::Protobuf;

pub const TYPE_URL: &str = "/ibc.core.channel.v1.MsgChannelOpenAck";

Expand Down
2 changes: 1 addition & 1 deletion modules/src/core/ics04_channel/msgs/chan_open_confirm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use crate::signer::Signer;
use crate::tx_msg::Msg;

use ibc_proto::ibc::core::channel::v1::MsgChannelOpenConfirm as RawMsgChannelOpenConfirm;
use tendermint_proto::Protobuf;
use ibc_proto::protobuf::Protobuf;

pub const TYPE_URL: &str = "/ibc.core.channel.v1.MsgChannelOpenConfirm";

Expand Down
2 changes: 1 addition & 1 deletion modules/src/core/ics04_channel/msgs/chan_open_init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use crate::signer::Signer;
use crate::tx_msg::Msg;

use ibc_proto::ibc::core::channel::v1::MsgChannelOpenInit as RawMsgChannelOpenInit;
use tendermint_proto::Protobuf;
use ibc_proto::protobuf::Protobuf;

pub const TYPE_URL: &str = "/ibc.core.channel.v1.MsgChannelOpenInit";

Expand Down
2 changes: 1 addition & 1 deletion modules/src/core/ics04_channel/msgs/chan_open_try.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use crate::signer::Signer;
use crate::tx_msg::Msg;

use ibc_proto::ibc::core::channel::v1::MsgChannelOpenTry as RawMsgChannelOpenTry;
use tendermint_proto::Protobuf;
use ibc_proto::protobuf::Protobuf;

use core::str::FromStr;

Expand Down
2 changes: 1 addition & 1 deletion modules/src/core/ics04_channel/msgs/recv_packet.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::prelude::*;

use tendermint_proto::Protobuf;
use ibc_proto::protobuf::Protobuf;

use ibc_proto::ibc::core::channel::v1::MsgRecvPacket as RawMsgRecvPacket;

Expand Down
2 changes: 1 addition & 1 deletion modules/src/core/ics04_channel/msgs/timeout.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::prelude::*;

use tendermint_proto::Protobuf;
use ibc_proto::protobuf::Protobuf;

use ibc_proto::ibc::core::channel::v1::MsgTimeout as RawMsgTimeout;

Expand Down
2 changes: 1 addition & 1 deletion modules/src/core/ics04_channel/msgs/timeout_on_close.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::prelude::*;

use ibc_proto::ibc::core::channel::v1::MsgTimeoutOnClose as RawMsgTimeoutOnClose;
use tendermint_proto::Protobuf;
use ibc_proto::protobuf::Protobuf;

use crate::core::ics04_channel::error::Error;
use crate::core::ics04_channel::packet::{Packet, Sequence};
Expand Down
2 changes: 1 addition & 1 deletion modules/src/core/ics26_routing/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ define_error! {
| e | { format_args!("unknown type URL {0}", e.url) },

MalformedMessageBytes
[ TraceError<tendermint_proto::Error> ]
[ TraceError<ibc_proto::protobuf::Error> ]
| _ | { "the message is malformed and cannot be decoded" },
}
}
2 changes: 1 addition & 1 deletion modules/src/core/ics26_routing/msgs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use crate::core::ics04_channel::msgs::{
chan_open_init, chan_open_try, recv_packet, timeout, timeout_on_close, ChannelMsg, PacketMsg,
};
use crate::core::ics26_routing::error::Error;
use tendermint_proto::Protobuf;
use ibc_proto::protobuf::Protobuf;

/// Enumeration of all messages that the local ICS26 module is capable of routing.
#[derive(Clone, Debug)]
Expand Down
2 changes: 1 addition & 1 deletion modules/src/mock/client_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ use alloc::collections::btree_map::BTreeMap as HashMap;

use core::time::Duration;

use ibc_proto::protobuf::Protobuf;
use serde::{Deserialize, Serialize};
use tendermint_proto::Protobuf;

use ibc_proto::ibc::mock::ClientState as RawMockClientState;
use ibc_proto::ibc::mock::ConsensusState as RawMockConsensusState;
Expand Down
2 changes: 1 addition & 1 deletion modules/src/mock/header.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use ibc_proto::protobuf::Protobuf;
use serde_derive::{Deserialize, Serialize};
use tendermint_proto::Protobuf;

use ibc_proto::ibc::mock::Header as RawMockHeader;

Expand Down
2 changes: 1 addition & 1 deletion modules/src/mock/misbehaviour.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::prelude::*;

use tendermint_proto::Protobuf;
use ibc_proto::protobuf::Protobuf;

use ibc_proto::ibc::mock::Misbehaviour as RawMisbehaviour;

Expand Down
Loading

0 comments on commit 880d031

Please sign in to comment.