Skip to content

Commit

Permalink
Bump ibc-proto to v0.29.0 and add memo field to PacketData (#627)
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinji authored May 2, 2023
1 parent 89c5298 commit 91c5ea9
Show file tree
Hide file tree
Showing 30 changed files with 120 additions and 66 deletions.
2 changes: 2 additions & 0 deletions .changelog/unreleased/breaking-changes/559-bump-ibc-proto.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
- Bump ibc-proto to v0.29.0, bump tendermint to v0.30.0, and add `memo` field to
`PacketData` ([#559](https://github.com/cosmos/ibc-rs/issues/559))
14 changes: 7 additions & 7 deletions crates/ibc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ mocks-no-std = ["cfg-if"]

[dependencies]
# Proto definitions for all IBC-related interfaces, e.g., connections or channels.
ibc-proto = { version = "0.26.0", default-features = false, features = ["parity-scale-codec", "borsh"] }
ibc-proto = { version = "0.29.0", default-features = false, features = ["parity-scale-codec", "borsh"] }
ics23 = { version = "0.9.0", default-features = false, features = ["host-functions"] }
time = { version = ">=0.3.0, <0.3.21", default-features = false }
serde_derive = { version = "1.0.104", default-features = false, optional = true }
Expand Down Expand Up @@ -80,20 +80,20 @@ parking_lot = { version = "0.12.1", default-features = false, optional = true }
cfg-if = { version = "1.0.0", optional = true }

[dependencies.tendermint]
version = "0.29"
version = "0.30"
default-features = false

[dependencies.tendermint-proto]
version = "0.29"
version = "0.30"
default-features = false

[dependencies.tendermint-light-client-verifier]
version = "0.29"
version = "0.30"
default-features = false
features = ["rust-crypto"]

[dependencies.tendermint-testgen]
version = "0.29"
version = "0.30"
optional = true
default-features = false

Expand All @@ -102,7 +102,7 @@ env_logger = "0.10.0"
rstest = "0.16.0"
tracing-subscriber = { version = "0.3.14", features = ["fmt", "env-filter", "json"]}
test-log = { version = "0.2.10", features = ["trace"] }
tendermint-rpc = { version = "0.29", features = ["http-client", "websocket-client"] }
tendermint-testgen = { version = "0.29" } # Needed for generating (synthetic) light blocks.
tendermint-rpc = { version = "0.30", features = ["http-client", "websocket-client"] }
tendermint-testgen = { version = "0.30" } # Needed for generating (synthetic) light blocks.
parking_lot = { version = "0.12.1" }
cfg-if = { version = "1.0.0" }
3 changes: 3 additions & 0 deletions crates/ibc/src/applications/transfer/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,7 @@ pub fn on_recv_packet_execute(
receiver: data.receiver,
denom: data.token.denom,
amount: data.token.amount,
memo: data.memo,
success: ack.is_successful(),
};
extras.events.push(recv_event.into());
Expand Down Expand Up @@ -355,6 +356,7 @@ pub fn on_acknowledgement_packet_execute(
receiver: data.receiver,
denom: data.token.denom,
amount: data.token.amount,
memo: data.memo,
acknowledgement: acknowledgement.clone(),
};

Expand Down Expand Up @@ -405,6 +407,7 @@ pub fn on_timeout_packet_execute(
refund_receiver: data.sender,
refund_denom: data.token.denom,
refund_amount: data.token.amount,
memo: data.memo,
};

let extras = ModuleExtras {
Expand Down
14 changes: 13 additions & 1 deletion crates/ibc/src/applications/transfer/events.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::applications::transfer::acknowledgement::TokenTransferAcknowledgement;
use crate::applications::transfer::{Amount, PrefixedDenom, MODULE_ID_STR};
use crate::applications::transfer::{Amount, Memo, PrefixedDenom, MODULE_ID_STR};
use crate::events::ModuleEvent;
use crate::prelude::*;
use crate::signer::Signer;
Expand All @@ -23,6 +23,7 @@ pub struct RecvEvent {
pub receiver: Signer,
pub denom: PrefixedDenom,
pub amount: Amount,
pub memo: Memo,
pub success: bool,
}

Expand All @@ -33,6 +34,7 @@ impl From<RecvEvent> for ModuleEvent {
receiver,
denom,
amount,
memo,
success,
} = ev;
Self {
Expand All @@ -43,6 +45,7 @@ impl From<RecvEvent> for ModuleEvent {
("receiver", receiver).into(),
("denom", denom).into(),
("amount", amount).into(),
("memo", memo).into(),
("success", success).into(),
],
}
Expand All @@ -54,6 +57,7 @@ pub struct AckEvent {
pub receiver: Signer,
pub denom: PrefixedDenom,
pub amount: Amount,
pub memo: Memo,
pub acknowledgement: TokenTransferAcknowledgement,
}

Expand All @@ -64,6 +68,7 @@ impl From<AckEvent> for ModuleEvent {
receiver,
denom,
amount,
memo,
acknowledgement,
} = ev;
Self {
Expand All @@ -74,6 +79,7 @@ impl From<AckEvent> for ModuleEvent {
("receiver", receiver).into(),
("denom", denom).into(),
("amount", amount).into(),
("memo", memo).into(),
("acknowledgement", acknowledgement).into(),
],
}
Expand Down Expand Up @@ -103,6 +109,7 @@ pub struct TimeoutEvent {
pub refund_receiver: Signer,
pub refund_denom: PrefixedDenom,
pub refund_amount: Amount,
pub memo: Memo,
}

impl From<TimeoutEvent> for ModuleEvent {
Expand All @@ -111,6 +118,7 @@ impl From<TimeoutEvent> for ModuleEvent {
refund_receiver,
refund_denom,
refund_amount,
memo,
} = ev;
Self {
kind: EVENT_TYPE_TIMEOUT.to_string(),
Expand All @@ -119,6 +127,7 @@ impl From<TimeoutEvent> for ModuleEvent {
("refund_receiver", refund_receiver).into(),
("refund_denom", refund_denom).into(),
("refund_amount", refund_amount).into(),
("memo", memo).into(),
],
}
}
Expand Down Expand Up @@ -148,6 +157,7 @@ pub struct TransferEvent {
pub receiver: Signer,
pub amount: Amount,
pub denom: PrefixedDenom,
pub memo: Memo,
}

impl From<TransferEvent> for ModuleEvent {
Expand All @@ -157,6 +167,7 @@ impl From<TransferEvent> for ModuleEvent {
receiver,
amount,
denom,
memo,
} = ev;

Self {
Expand All @@ -166,6 +177,7 @@ impl From<TransferEvent> for ModuleEvent {
("receiver", receiver).into(),
("amount", amount).into(),
("denom", denom).into(),
("memo", memo).into(),
],
}
}
Expand Down
47 changes: 47 additions & 0 deletions crates/ibc/src/applications/transfer/memo.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
use core::convert::Infallible;
use core::fmt::{self, Display};
use core::str::FromStr;

use crate::prelude::*;

#[cfg_attr(
feature = "parity-scale-codec",
derive(
parity_scale_codec::Encode,
parity_scale_codec::Decode,
scale_info::TypeInfo
)
)]
#[cfg_attr(
feature = "borsh",
derive(borsh::BorshSerialize, borsh::BorshDeserialize)
)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct Memo(String);

impl AsRef<str> for Memo {
fn as_ref(&self) -> &str {
&self.0
}
}

impl Display for Memo {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{}", self.0)
}
}

impl From<String> for Memo {
fn from(memo: String) -> Self {
Self(memo)
}
}

impl FromStr for Memo {
type Err = Infallible;

fn from_str(memo: &str) -> Result<Self, Infallible> {
Ok(Self(memo.to_owned()))
}
}
2 changes: 2 additions & 0 deletions crates/ibc/src/applications/transfer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,15 @@ pub mod context;
pub mod denom;
pub mod error;
pub mod events;
pub mod memo;
pub mod msgs;
pub mod packet;
pub mod relay;

pub use amount::*;
pub use coin::*;
pub use denom::*;
pub use memo::*;

/// Module identifier for the ICS20 application.
pub const MODULE_ID_STR: &str = "transfer";
Expand Down
5 changes: 5 additions & 0 deletions crates/ibc/src/applications/transfer/msgs/transfer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ impl TryFrom<RawMsgTransfer> for MsgTransfer {
.map_err(|_| TokenTransferError::InvalidToken)?,
sender: raw_msg.sender.into(),
receiver: raw_msg.receiver.into(),
memo: raw_msg.memo.into(),
},
timeout_height_on_b,
timeout_timestamp_on_b,
Expand All @@ -100,6 +101,7 @@ impl From<MsgTransfer> for RawMsgTransfer {
receiver: domain_msg.packet_data.receiver.to_string(),
timeout_height: domain_msg.timeout_height_on_b.into(),
timeout_timestamp: domain_msg.timeout_timestamp_on_b.nanoseconds(),
memo: domain_msg.packet_data.memo.to_string(),
}
}
}
Expand All @@ -123,6 +125,7 @@ impl TryFrom<Any> for MsgTransfer {

#[cfg(test)]
pub mod test_util {
use alloc::borrow::ToOwned;
use core::ops::Add;
use core::time::Duration;
use primitive_types::U256;
Expand Down Expand Up @@ -158,6 +161,7 @@ pub mod test_util {
.into(),
sender: address.clone(),
receiver: address,
memo: "".to_owned().into(),
},
timeout_timestamp_on_b: timeout_timestamp
.unwrap_or_else(|| Timestamp::now().add(Duration::from_secs(10)).unwrap()),
Expand All @@ -176,6 +180,7 @@ pub mod test_util {
token: coin,
sender: msg.packet_data.sender.clone(),
receiver: msg.packet_data.receiver.clone(),
memo: msg.packet_data.memo.clone(),
};
serde_json::to_vec(&data).expect("PacketData's infallible Serialize impl failed")
};
Expand Down
5 changes: 4 additions & 1 deletion crates/ibc/src/applications/transfer/packet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use core::str::FromStr;
use ibc_proto::ibc::applications::transfer::v2::FungibleTokenPacketData as RawPacketData;

use super::error::TokenTransferError;
use super::{Amount, PrefixedCoin, PrefixedDenom};
use super::{Amount, Memo, PrefixedCoin, PrefixedDenom};
use crate::signer::Signer;

#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
Expand All @@ -18,6 +18,7 @@ pub struct PacketData {
pub token: PrefixedCoin,
pub sender: Signer,
pub receiver: Signer,
pub memo: Memo,
}

impl TryFrom<RawPacketData> for PacketData {
Expand All @@ -31,6 +32,7 @@ impl TryFrom<RawPacketData> for PacketData {
token: PrefixedCoin { denom, amount },
sender: raw_pkt_data.sender.into(),
receiver: raw_pkt_data.receiver.into(),
memo: raw_pkt_data.memo.into(),
})
}
}
Expand All @@ -42,6 +44,7 @@ impl From<PacketData> for RawPacketData {
amount: pkt_data.token.amount.to_string(),
sender: pkt_data.sender.to_string(),
receiver: pkt_data.receiver.to_string(),
memo: pkt_data.memo.to_string(),
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ where
receiver: msg.packet_data.receiver,
amount: msg.packet_data.token.amount,
denom: msg.packet_data.token.denom,
memo: msg.packet_data.memo,
};
ctx_a.emit_ibc_event(ModuleEvent::from(transfer_event).into());

Expand Down
9 changes: 3 additions & 6 deletions crates/ibc/src/clients/ics07_tendermint/client_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -422,8 +422,7 @@ impl Ics2ClientState for ClientState {

upgraded_tm_client_state.zero_custom_fields();
let client_state_value =
Protobuf::<RawTmClientState>::encode_vec(&upgraded_tm_client_state)
.map_err(ClientError::Encode)?;
Protobuf::<RawTmClientState>::encode_vec(&upgraded_tm_client_state);

// Verify the proof of the upgraded client state
merkle_proof_upgrade_client
Expand All @@ -444,8 +443,7 @@ impl Ics2ClientState for ClientState {
key_path: cons_upgrade_path,
};

let cons_state_value = Protobuf::<RawTmConsensusState>::encode_vec(&upgraded_tm_cons_state)
.map_err(ClientError::Encode)?;
let cons_state_value = Protobuf::<RawTmConsensusState>::encode_vec(&upgraded_tm_cons_state);

// Verify the proof of the upgraded consensus state
merkle_proof_upgrade_cons_state
Expand Down Expand Up @@ -725,8 +723,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)
.expect("encoding to `Any` from `TmClientState`"),
value: Protobuf::<RawTmClientState>::encode_vec(&client_state),
}
}
}
Expand Down
3 changes: 1 addition & 2 deletions crates/ibc/src/clients/ics07_tendermint/consensus_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,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)
.expect("encoding to `Any` from `TmConsensusState`"),
value: Protobuf::<RawConsensusState>::encode_vec(&consensus_state),
}
}
}
Expand Down
3 changes: 1 addition & 2 deletions crates/ibc/src/clients/ics07_tendermint/header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,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)
.expect("encoding to `Any` from `TmHeader`"),
value: Protobuf::<RawHeader>::encode_vec(&header),
}
}
}
Expand Down
3 changes: 1 addition & 2 deletions crates/ibc/src/clients/ics07_tendermint/misbehaviour.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,7 @@ impl From<Misbehaviour> for Any {
fn from(misbehaviour: Misbehaviour) -> Self {
Any {
type_url: TENDERMINT_MISBEHAVIOUR_TYPE_URL.to_string(),
value: Protobuf::<RawMisbehaviour>::encode_vec(&misbehaviour)
.expect("encoding to `Any` from `TmMisbehaviour`"),
value: Protobuf::<RawMisbehaviour>::encode_vec(&misbehaviour),
}
}
}
Expand Down
1 change: 1 addition & 0 deletions crates/ibc/src/core/handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,7 @@ mod tests {
},
sender: msg_transfer_two.packet_data.sender.clone(),
receiver: msg_transfer_two.packet_data.receiver.clone(),
memo: "".to_owned().into(),
};
serde_json::to_vec(&data).expect("PacketData's infallible Serialize impl failed")
};
Expand Down
2 changes: 0 additions & 2 deletions crates/ibc/src/core/ics02_client/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,6 @@ pub enum ClientError {
MissingRawConsensusState,
/// invalid client id in the update client message: `{0}`
InvalidMsgUpdateClientId(ValidationError),
/// Encode error: `{0}`
Encode(TendermintProtoError),
/// decode error: `{0}`
Decode(prost::DecodeError),
/// invalid client identifier error: `{0}`
Expand Down
Loading

0 comments on commit 91c5ea9

Please sign in to comment.