From 2c28380918f1000fd4f509fc2f9fcd4aeb189984 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philippe=20Laferri=C3=A8re?= Date: Fri, 1 Sep 2023 09:08:45 -0400 Subject: [PATCH] Derive borsh for `MsgEnvelope` (#846) * Add BorshSerialize/Deserialize to MsgEnvelope * add tests * changelog --- .../846-borsh-derive-msgenvelope.md | 2 + crates/ibc/src/core/ics02_client/msgs.rs | 4 + .../core/ics02_client/msgs/create_client.rs | 4 + .../core/ics02_client/msgs/misbehaviour.rs | 4 + .../core/ics02_client/msgs/update_client.rs | 4 + .../core/ics02_client/msgs/upgrade_client.rs | 4 + crates/ibc/src/core/ics03_connection/msgs.rs | 4 + .../ics03_connection/msgs/conn_open_ack.rs | 4 + .../msgs/conn_open_confirm.rs | 4 + .../ics03_connection/msgs/conn_open_init.rs | 75 ++++++++++++ .../ics03_connection/msgs/conn_open_try.rs | 109 ++++++++++++++++++ crates/ibc/src/core/ics04_channel/msgs.rs | 8 ++ .../ics04_channel/msgs/acknowledgement.rs | 4 + .../ics04_channel/msgs/chan_close_confirm.rs | 4 + .../ics04_channel/msgs/chan_close_init.rs | 4 + .../core/ics04_channel/msgs/chan_open_ack.rs | 4 + .../ics04_channel/msgs/chan_open_confirm.rs | 4 + .../core/ics04_channel/msgs/chan_open_init.rs | 4 + .../core/ics04_channel/msgs/chan_open_try.rs | 4 + .../core/ics04_channel/msgs/recv_packet.rs | 4 + .../src/core/ics04_channel/msgs/timeout.rs | 4 + .../ics04_channel/msgs/timeout_on_close.rs | 4 + .../src/core/ics23_commitment/commitment.rs | 4 + crates/ibc/src/core/msgs.rs | 4 + 24 files changed, 274 insertions(+) create mode 100644 .changelog/unreleased/improvements/846-borsh-derive-msgenvelope.md diff --git a/.changelog/unreleased/improvements/846-borsh-derive-msgenvelope.md b/.changelog/unreleased/improvements/846-borsh-derive-msgenvelope.md new file mode 100644 index 000000000..cc5ccad7d --- /dev/null +++ b/.changelog/unreleased/improvements/846-borsh-derive-msgenvelope.md @@ -0,0 +1,2 @@ +- Add borsh derive for `MsgEnvelope` + ([#846](https://github.com/cosmos/ibc-rs/pull/846)) diff --git a/crates/ibc/src/core/ics02_client/msgs.rs b/crates/ibc/src/core/ics02_client/msgs.rs index 9bb0375a8..b432211c9 100644 --- a/crates/ibc/src/core/ics02_client/msgs.rs +++ b/crates/ibc/src/core/ics02_client/msgs.rs @@ -16,6 +16,10 @@ pub mod upgrade_client; /// Encodes all the different client messages #[allow(dead_code)] +#[cfg_attr( + feature = "borsh", + derive(borsh::BorshSerialize, borsh::BorshDeserialize) +)] #[derive(Clone, Debug)] pub enum ClientMsg { CreateClient(MsgCreateClient), diff --git a/crates/ibc/src/core/ics02_client/msgs/create_client.rs b/crates/ibc/src/core/ics02_client/msgs/create_client.rs index de3de83f2..c55e8668c 100644 --- a/crates/ibc/src/core/ics02_client/msgs/create_client.rs +++ b/crates/ibc/src/core/ics02_client/msgs/create_client.rs @@ -13,6 +13,10 @@ use crate::signer::Signer; pub(crate) const TYPE_URL: &str = "/ibc.core.client.v1.MsgCreateClient"; /// A type of message that triggers the creation of a new on-chain (IBC) client. +#[cfg_attr( + feature = "borsh", + derive(borsh::BorshSerialize, borsh::BorshDeserialize) +)] #[derive(Clone, Debug, PartialEq, Eq)] pub struct MsgCreateClient { pub client_state: Any, diff --git a/crates/ibc/src/core/ics02_client/msgs/misbehaviour.rs b/crates/ibc/src/core/ics02_client/msgs/misbehaviour.rs index 011db59dd..6ab10266b 100644 --- a/crates/ibc/src/core/ics02_client/msgs/misbehaviour.rs +++ b/crates/ibc/src/core/ics02_client/msgs/misbehaviour.rs @@ -14,6 +14,10 @@ use crate::signer::Signer; pub(crate) const TYPE_URL: &str = "/ibc.core.client.v1.MsgSubmitMisbehaviour"; /// A type of message that submits client misbehaviour proof. +#[cfg_attr( + feature = "borsh", + derive(borsh::BorshSerialize, borsh::BorshDeserialize) +)] #[derive(Clone, Debug, PartialEq, Eq)] pub struct MsgSubmitMisbehaviour { /// client unique identifier diff --git a/crates/ibc/src/core/ics02_client/msgs/update_client.rs b/crates/ibc/src/core/ics02_client/msgs/update_client.rs index 3adfa716f..74e365a44 100644 --- a/crates/ibc/src/core/ics02_client/msgs/update_client.rs +++ b/crates/ibc/src/core/ics02_client/msgs/update_client.rs @@ -17,6 +17,10 @@ pub(crate) const TYPE_URL: &str = "/ibc.core.client.v1.MsgUpdateClient"; /// either with new headers, or evidence of misbehaviour. /// Note that some types of misbehaviour can be detected when a headers /// are updated (`UpdateKind::UpdateClient`). +#[cfg_attr( + feature = "borsh", + derive(borsh::BorshSerialize, borsh::BorshDeserialize) +)] #[derive(Clone, Debug, PartialEq, Eq)] pub struct MsgUpdateClient { pub client_id: ClientId, diff --git a/crates/ibc/src/core/ics02_client/msgs/upgrade_client.rs b/crates/ibc/src/core/ics02_client/msgs/upgrade_client.rs index b5c49613b..c87976e53 100644 --- a/crates/ibc/src/core/ics02_client/msgs/upgrade_client.rs +++ b/crates/ibc/src/core/ics02_client/msgs/upgrade_client.rs @@ -18,6 +18,10 @@ use crate::signer::Signer; pub(crate) const TYPE_URL: &str = "/ibc.core.client.v1.MsgUpgradeClient"; /// A type of message that triggers the upgrade of an on-chain (IBC) client. +#[cfg_attr( + feature = "borsh", + derive(borsh::BorshSerialize, borsh::BorshDeserialize) +)] #[derive(Clone, Debug, PartialEq)] pub struct MsgUpgradeClient { // client unique identifier diff --git a/crates/ibc/src/core/ics03_connection/msgs.rs b/crates/ibc/src/core/ics03_connection/msgs.rs index 55f445ea3..486ce3956 100644 --- a/crates/ibc/src/core/ics03_connection/msgs.rs +++ b/crates/ibc/src/core/ics03_connection/msgs.rs @@ -23,6 +23,10 @@ pub mod conn_open_init; pub mod conn_open_try; /// Enumeration of all possible messages that the ICS3 protocol processes. +#[cfg_attr( + feature = "borsh", + derive(borsh::BorshSerialize, borsh::BorshDeserialize) +)] #[derive(Clone, Debug, PartialEq, Eq)] pub enum ConnectionMsg { OpenInit(MsgConnectionOpenInit), diff --git a/crates/ibc/src/core/ics03_connection/msgs/conn_open_ack.rs b/crates/ibc/src/core/ics03_connection/msgs/conn_open_ack.rs index ad5613d13..5b57756f7 100644 --- a/crates/ibc/src/core/ics03_connection/msgs/conn_open_ack.rs +++ b/crates/ibc/src/core/ics03_connection/msgs/conn_open_ack.rs @@ -16,6 +16,10 @@ pub(crate) const TYPE_URL: &str = "/ibc.core.connection.v1.MsgConnectionOpenAck" /// Per our convention, this message is sent to chain A. /// The handler will check proofs of chain B. +#[cfg_attr( + feature = "borsh", + derive(borsh::BorshSerialize, borsh::BorshDeserialize) +)] #[derive(Clone, Debug, PartialEq, Eq)] pub struct MsgConnectionOpenAck { /// ConnectionId that chain A has chosen for it's ConnectionEnd diff --git a/crates/ibc/src/core/ics03_connection/msgs/conn_open_confirm.rs b/crates/ibc/src/core/ics03_connection/msgs/conn_open_confirm.rs index 69592e31b..4f0337a69 100644 --- a/crates/ibc/src/core/ics03_connection/msgs/conn_open_confirm.rs +++ b/crates/ibc/src/core/ics03_connection/msgs/conn_open_confirm.rs @@ -14,6 +14,10 @@ pub(crate) const TYPE_URL: &str = "/ibc.core.connection.v1.MsgConnectionOpenConf /// Per our convention, this message is sent to chain B. /// The handler will check proofs of chain A. +#[cfg_attr( + feature = "borsh", + derive(borsh::BorshSerialize, borsh::BorshDeserialize) +)] #[derive(Clone, Debug, PartialEq, Eq)] pub struct MsgConnectionOpenConfirm { /// ConnectionId that chain B has chosen for it's ConnectionEnd diff --git a/crates/ibc/src/core/ics03_connection/msgs/conn_open_init.rs b/crates/ibc/src/core/ics03_connection/msgs/conn_open_init.rs index ae7c0e0a9..d6732f258 100644 --- a/crates/ibc/src/core/ics03_connection/msgs/conn_open_init.rs +++ b/crates/ibc/src/core/ics03_connection/msgs/conn_open_init.rs @@ -34,6 +34,64 @@ impl Msg for MsgConnectionOpenInit { } } +/// This module encapsulates the workarounds we need to do to implement +/// `BorshSerialize` and `BorshDeserialize` on `MsgConnectionOpenInit` +#[cfg(feature = "borsh")] +mod borsh_impls { + use borsh::{ + maybestd::io::{self, Read}, + BorshDeserialize, BorshSerialize, + }; + + use super::*; + + #[derive(BorshSerialize, BorshDeserialize)] + pub struct InnerMsgConnectionOpenInit { + /// ClientId on chain A that the connection is being opened for + pub client_id_on_a: ClientId, + pub counterparty: Counterparty, + pub version: Option, + pub delay_period_nanos: u64, + pub signer: Signer, + } + + impl BorshSerialize for MsgConnectionOpenInit { + fn serialize(&self, writer: &mut W) -> io::Result<()> { + let delay_period_nanos: u64 = + self.delay_period.as_nanos().try_into().map_err(|_| { + io::Error::new( + io::ErrorKind::Other, + format!("Duration too long: {} nanos", self.delay_period.as_nanos()), + ) + })?; + + let inner = InnerMsgConnectionOpenInit { + client_id_on_a: self.client_id_on_a.clone(), + counterparty: self.counterparty.clone(), + version: self.version.clone(), + delay_period_nanos, + signer: self.signer.clone(), + }; + + inner.serialize(writer) + } + } + + impl BorshDeserialize for MsgConnectionOpenInit { + fn deserialize_reader(reader: &mut R) -> io::Result { + let inner = InnerMsgConnectionOpenInit::deserialize_reader(reader)?; + + Ok(MsgConnectionOpenInit { + client_id_on_a: inner.client_id_on_a, + counterparty: inner.counterparty, + version: inner.version, + delay_period: Duration::from_nanos(inner.delay_period_nanos), + signer: inner.signer, + }) + } + } +} + impl Protobuf for MsgConnectionOpenInit {} impl TryFrom for MsgConnectionOpenInit { @@ -239,4 +297,21 @@ mod tests { msg_with_counterpary_conn_id_some_back ); } + + /// Test that borsh serialization/deserialization works well with delay periods up to u64::MAX + #[cfg(feature = "borsh")] + #[test] + fn test_borsh() { + let mut raw = get_dummy_raw_msg_conn_open_init(); + raw.delay_period = u64::MAX; + let msg = MsgConnectionOpenInit::try_from(raw.clone()).unwrap(); + + let serialized = borsh::to_vec(&msg).unwrap(); + + let msg_deserialized = + ::try_from_slice(&serialized) + .unwrap(); + + assert_eq!(msg, msg_deserialized); + } } diff --git a/crates/ibc/src/core/ics03_connection/msgs/conn_open_try.rs b/crates/ibc/src/core/ics03_connection/msgs/conn_open_try.rs index 264aff846..11f7fb884 100644 --- a/crates/ibc/src/core/ics03_connection/msgs/conn_open_try.rs +++ b/crates/ibc/src/core/ics03_connection/msgs/conn_open_try.rs @@ -60,6 +60,99 @@ impl Msg for MsgConnectionOpenTry { TYPE_URL.to_string() } } +#[allow(deprecated)] +#[cfg(feature = "borsh")] +mod borsh_impls { + use borsh::{ + maybestd::io::{self, Read}, + BorshDeserialize, BorshSerialize, + }; + + use super::*; + + #[derive(BorshSerialize, BorshDeserialize)] + pub struct InnerMsgConnectionOpenTry { + /// ClientId on B that the connection is being opened for + pub client_id_on_b: ClientId, + /// ClientState of client tracking chain B on chain A + pub client_state_of_b_on_a: Any, + /// ClientId, ConnectionId and prefix of chain A + pub counterparty: Counterparty, + /// Versions supported by chain A + pub versions_on_a: Vec, + /// proof of ConnectionEnd stored on Chain A during ConnOpenInit + pub proof_conn_end_on_a: CommitmentProofBytes, + /// proof that chain A has stored ClientState of chain B on its client + pub proof_client_state_of_b_on_a: CommitmentProofBytes, + /// proof that chain A has stored ConsensusState of chain B on its client + pub proof_consensus_state_of_b_on_a: CommitmentProofBytes, + /// Height at which all proofs in this message were taken + pub proofs_height_on_a: Height, + /// height of latest header of chain A that updated the client on chain B + pub consensus_height_of_b_on_a: Height, + pub delay_period_nanos: u64, + pub signer: Signer, + /// optional proof of host state machines (chain B) that are unable to + /// introspect their own consensus state + pub proof_consensus_state_of_b: Option, + + #[deprecated(since = "0.22.0")] + /// Only kept here for proper conversion to/from the raw type + previous_connection_id: String, + } + + impl BorshSerialize for MsgConnectionOpenTry { + fn serialize(&self, writer: &mut W) -> io::Result<()> { + let delay_period_nanos: u64 = + self.delay_period.as_nanos().try_into().map_err(|_| { + io::Error::new( + io::ErrorKind::Other, + format!("Duration too long: {} nanos", self.delay_period.as_nanos()), + ) + })?; + + let inner = InnerMsgConnectionOpenTry { + client_id_on_b: self.client_id_on_b.clone(), + client_state_of_b_on_a: self.client_state_of_b_on_a.clone(), + counterparty: self.counterparty.clone(), + versions_on_a: self.versions_on_a.clone(), + proof_conn_end_on_a: self.proof_conn_end_on_a.clone(), + proof_client_state_of_b_on_a: self.proof_client_state_of_b_on_a.clone(), + proof_consensus_state_of_b_on_a: self.proof_consensus_state_of_b_on_a.clone(), + proofs_height_on_a: self.proofs_height_on_a, + consensus_height_of_b_on_a: self.consensus_height_of_b_on_a, + delay_period_nanos, + signer: self.signer.clone(), + proof_consensus_state_of_b: self.proof_consensus_state_of_b.clone(), + previous_connection_id: self.previous_connection_id.clone(), + }; + + inner.serialize(writer) + } + } + + impl BorshDeserialize for MsgConnectionOpenTry { + fn deserialize_reader(reader: &mut R) -> io::Result { + let inner = InnerMsgConnectionOpenTry::deserialize_reader(reader)?; + + Ok(MsgConnectionOpenTry { + client_id_on_b: inner.client_id_on_b, + client_state_of_b_on_a: inner.client_state_of_b_on_a, + counterparty: inner.counterparty, + versions_on_a: inner.versions_on_a, + proof_conn_end_on_a: inner.proof_conn_end_on_a, + proof_client_state_of_b_on_a: inner.proof_client_state_of_b_on_a, + proof_consensus_state_of_b_on_a: inner.proof_consensus_state_of_b_on_a, + proofs_height_on_a: inner.proofs_height_on_a, + consensus_height_of_b_on_a: inner.consensus_height_of_b_on_a, + delay_period: Duration::from_nanos(inner.delay_period_nanos), + signer: inner.signer, + proof_consensus_state_of_b: inner.proof_consensus_state_of_b, + previous_connection_id: inner.previous_connection_id, + }) + } + } +} impl Protobuf for MsgConnectionOpenTry {} @@ -357,4 +450,20 @@ mod tests { assert_eq!(raw, raw_back); assert_eq!(msg, msg_back); } + + /// Test that borsh serialization/deserialization works well with delay periods up to u64::MAX + #[cfg(feature = "borsh")] + #[test] + fn test_borsh() { + let mut raw = get_dummy_raw_msg_conn_open_try(10, 34); + raw.delay_period = u64::MAX; + let msg = MsgConnectionOpenTry::try_from(raw.clone()).unwrap(); + + let serialized = borsh::to_vec(&msg).unwrap(); + + let msg_deserialized = + ::try_from_slice(&serialized).unwrap(); + + assert_eq!(msg, msg_deserialized); + } } diff --git a/crates/ibc/src/core/ics04_channel/msgs.rs b/crates/ibc/src/core/ics04_channel/msgs.rs index fad6922d3..728c8926c 100644 --- a/crates/ibc/src/core/ics04_channel/msgs.rs +++ b/crates/ibc/src/core/ics04_channel/msgs.rs @@ -31,6 +31,10 @@ pub use timeout_on_close::MsgTimeoutOnClose; use crate::core::ics24_host::identifier::PortId; /// All channel messages +#[cfg_attr( + feature = "borsh", + derive(borsh::BorshSerialize, borsh::BorshDeserialize) +)] #[derive(Clone, Debug, PartialEq, Eq)] pub enum ChannelMsg { OpenInit(MsgChannelOpenInit), @@ -42,6 +46,10 @@ pub enum ChannelMsg { } /// All packet messages +#[cfg_attr( + feature = "borsh", + derive(borsh::BorshSerialize, borsh::BorshDeserialize) +)] #[derive(Clone, Debug, PartialEq, Eq)] pub enum PacketMsg { Recv(MsgRecvPacket), diff --git a/crates/ibc/src/core/ics04_channel/msgs/acknowledgement.rs b/crates/ibc/src/core/ics04_channel/msgs/acknowledgement.rs index 7e414263e..6f448d6fc 100644 --- a/crates/ibc/src/core/ics04_channel/msgs/acknowledgement.rs +++ b/crates/ibc/src/core/ics04_channel/msgs/acknowledgement.rs @@ -16,6 +16,10 @@ pub(crate) const TYPE_URL: &str = "/ibc.core.channel.v1.MsgAcknowledgement"; /// /// Message definition for packet acknowledgements. /// +#[cfg_attr( + feature = "borsh", + derive(borsh::BorshSerialize, borsh::BorshDeserialize) +)] #[derive(Clone, Debug, PartialEq, Eq)] pub struct MsgAcknowledgement { pub packet: Packet, diff --git a/crates/ibc/src/core/ics04_channel/msgs/chan_close_confirm.rs b/crates/ibc/src/core/ics04_channel/msgs/chan_close_confirm.rs index 6d73b3492..c40c88c5a 100644 --- a/crates/ibc/src/core/ics04_channel/msgs/chan_close_confirm.rs +++ b/crates/ibc/src/core/ics04_channel/msgs/chan_close_confirm.rs @@ -17,6 +17,10 @@ pub(crate) const TYPE_URL: &str = "/ibc.core.channel.v1.MsgChannelCloseConfirm"; /// datagram). /// Per our convention, this message is sent to chain B. /// +#[cfg_attr( + feature = "borsh", + derive(borsh::BorshSerialize, borsh::BorshDeserialize) +)] #[derive(Clone, Debug, PartialEq, Eq)] pub struct MsgChannelCloseConfirm { pub port_id_on_b: PortId, diff --git a/crates/ibc/src/core/ics04_channel/msgs/chan_close_init.rs b/crates/ibc/src/core/ics04_channel/msgs/chan_close_init.rs index 98c8c694c..d3a569217 100644 --- a/crates/ibc/src/core/ics04_channel/msgs/chan_close_init.rs +++ b/crates/ibc/src/core/ics04_channel/msgs/chan_close_init.rs @@ -15,6 +15,10 @@ pub(crate) const TYPE_URL: &str = "/ibc.core.channel.v1.MsgChannelCloseInit"; /// Message definition for the first step in the channel close handshake (`ChanCloseInit` datagram). /// Per our convention, this message is sent to chain A. /// +#[cfg_attr( + feature = "borsh", + derive(borsh::BorshSerialize, borsh::BorshDeserialize) +)] #[derive(Clone, Debug, PartialEq, Eq)] pub struct MsgChannelCloseInit { pub port_id_on_a: PortId, diff --git a/crates/ibc/src/core/ics04_channel/msgs/chan_open_ack.rs b/crates/ibc/src/core/ics04_channel/msgs/chan_open_ack.rs index 2f8587ef3..9fca241ff 100644 --- a/crates/ibc/src/core/ics04_channel/msgs/chan_open_ack.rs +++ b/crates/ibc/src/core/ics04_channel/msgs/chan_open_ack.rs @@ -14,6 +14,10 @@ pub(crate) const TYPE_URL: &str = "/ibc.core.channel.v1.MsgChannelOpenAck"; /// Message definition for the third step in the channel open handshake (`ChanOpenAck` datagram). /// /// Per our convention, this message is sent to chain A. +#[cfg_attr( + feature = "borsh", + derive(borsh::BorshSerialize, borsh::BorshDeserialize) +)] #[derive(Clone, Debug, PartialEq, Eq)] pub struct MsgChannelOpenAck { pub port_id_on_a: PortId, diff --git a/crates/ibc/src/core/ics04_channel/msgs/chan_open_confirm.rs b/crates/ibc/src/core/ics04_channel/msgs/chan_open_confirm.rs index aeaa39706..4bd43bd39 100644 --- a/crates/ibc/src/core/ics04_channel/msgs/chan_open_confirm.rs +++ b/crates/ibc/src/core/ics04_channel/msgs/chan_open_confirm.rs @@ -15,6 +15,10 @@ pub(crate) const TYPE_URL: &str = "/ibc.core.channel.v1.MsgChannelOpenConfirm"; /// datagram). /// Per our convention, this message is sent to chain B. /// +#[cfg_attr( + feature = "borsh", + derive(borsh::BorshSerialize, borsh::BorshDeserialize) +)] #[derive(Clone, Debug, PartialEq, Eq)] pub struct MsgChannelOpenConfirm { pub port_id_on_b: PortId, diff --git a/crates/ibc/src/core/ics04_channel/msgs/chan_open_init.rs b/crates/ibc/src/core/ics04_channel/msgs/chan_open_init.rs index a7dd63505..08f034eb2 100644 --- a/crates/ibc/src/core/ics04_channel/msgs/chan_open_init.rs +++ b/crates/ibc/src/core/ics04_channel/msgs/chan_open_init.rs @@ -18,6 +18,10 @@ pub(crate) const TYPE_URL: &str = "/ibc.core.channel.v1.MsgChannelOpenInit"; /// Message definition for the first step in the channel open handshake (`ChanOpenInit` datagram). /// Per our convention, this message is sent to chain A. /// +#[cfg_attr( + feature = "borsh", + derive(borsh::BorshSerialize, borsh::BorshDeserialize) +)] #[derive(Clone, Debug, PartialEq, Eq)] pub struct MsgChannelOpenInit { pub port_id_on_a: PortId, diff --git a/crates/ibc/src/core/ics04_channel/msgs/chan_open_try.rs b/crates/ibc/src/core/ics04_channel/msgs/chan_open_try.rs index 1759b2deb..ad0e93ca4 100644 --- a/crates/ibc/src/core/ics04_channel/msgs/chan_open_try.rs +++ b/crates/ibc/src/core/ics04_channel/msgs/chan_open_try.rs @@ -19,6 +19,10 @@ pub(crate) const TYPE_URL: &str = "/ibc.core.channel.v1.MsgChannelOpenTry"; /// Message definition for the second step in the channel open handshake (`ChanOpenTry` datagram). /// Per our convention, this message is sent to chain B. /// +#[cfg_attr( + feature = "borsh", + derive(borsh::BorshSerialize, borsh::BorshDeserialize) +)] #[derive(Clone, Debug, PartialEq, Eq)] pub struct MsgChannelOpenTry { pub port_id_on_b: PortId, diff --git a/crates/ibc/src/core/ics04_channel/msgs/recv_packet.rs b/crates/ibc/src/core/ics04_channel/msgs/recv_packet.rs index ae96fe80f..241c67976 100644 --- a/crates/ibc/src/core/ics04_channel/msgs/recv_packet.rs +++ b/crates/ibc/src/core/ics04_channel/msgs/recv_packet.rs @@ -16,6 +16,10 @@ pub(crate) const TYPE_URL: &str = "/ibc.core.channel.v1.MsgRecvPacket"; /// /// Message definition for the "packet receiving" datagram. /// +#[cfg_attr( + feature = "borsh", + derive(borsh::BorshSerialize, borsh::BorshDeserialize) +)] #[derive(Clone, Debug, PartialEq, Eq)] pub struct MsgRecvPacket { /// The packet to be received diff --git a/crates/ibc/src/core/ics04_channel/msgs/timeout.rs b/crates/ibc/src/core/ics04_channel/msgs/timeout.rs index 5595a27ee..b3104bca3 100644 --- a/crates/ibc/src/core/ics04_channel/msgs/timeout.rs +++ b/crates/ibc/src/core/ics04_channel/msgs/timeout.rs @@ -17,6 +17,10 @@ pub(crate) const TYPE_URL: &str = "/ibc.core.channel.v1.MsgTimeout"; /// Message definition for packet timeout domain type, /// which is sent on chain A and needs to prove that a previously sent packet was not received on chain B /// +#[cfg_attr( + feature = "borsh", + derive(borsh::BorshSerialize, borsh::BorshDeserialize) +)] #[derive(Clone, Debug, PartialEq, Eq)] pub struct MsgTimeout { pub packet: Packet, diff --git a/crates/ibc/src/core/ics04_channel/msgs/timeout_on_close.rs b/crates/ibc/src/core/ics04_channel/msgs/timeout_on_close.rs index 90401c4c4..e299d9a18 100644 --- a/crates/ibc/src/core/ics04_channel/msgs/timeout_on_close.rs +++ b/crates/ibc/src/core/ics04_channel/msgs/timeout_on_close.rs @@ -15,6 +15,10 @@ pub(crate) const TYPE_URL: &str = "/ibc.core.channel.v1.MsgTimeoutOnClose"; /// /// Message definition for packet timeout domain type. /// +#[cfg_attr( + feature = "borsh", + derive(borsh::BorshSerialize, borsh::BorshDeserialize) +)] #[derive(Clone, Debug, PartialEq, Eq)] pub struct MsgTimeoutOnClose { pub packet: Packet, diff --git a/crates/ibc/src/core/ics23_commitment/commitment.rs b/crates/ibc/src/core/ics23_commitment/commitment.rs index 98a4d5d9a..b5b876b71 100644 --- a/crates/ibc/src/core/ics23_commitment/commitment.rs +++ b/crates/ibc/src/core/ics23_commitment/commitment.rs @@ -61,6 +61,10 @@ impl From> for CommitmentRoot { /// /// For example, in the case of a proof of membership in a Merkle tree, /// this encodes a Merkle proof. +#[cfg_attr( + feature = "borsh", + derive(borsh::BorshSerialize, borsh::BorshDeserialize) +)] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] #[cfg_attr(feature = "serde", serde(transparent))] #[derive(Clone, PartialEq, Eq)] diff --git a/crates/ibc/src/core/msgs.rs b/crates/ibc/src/core/msgs.rs index b15a0a39d..212d08304 100644 --- a/crates/ibc/src/core/msgs.rs +++ b/crates/ibc/src/core/msgs.rs @@ -36,6 +36,10 @@ pub trait Msg: Clone { } /// Enumeration of all messages that the local ICS26 module is capable of routing. +#[cfg_attr( + feature = "borsh", + derive(borsh::BorshSerialize, borsh::BorshDeserialize) +)] #[derive(Clone, Debug)] pub enum MsgEnvelope { Client(ClientMsg),