From de7e1903de0fe45470d0ae223ed5714e439deca9 Mon Sep 17 00:00:00 2001 From: Mikhail Zabaluev Date: Tue, 1 Nov 2022 14:13:41 +0200 Subject: [PATCH 01/11] Update to tendermint 0.26 --- Cargo.toml | 3 + ci/no-std-check/Cargo.toml | 6 +- crates/ibc/Cargo.toml | 12 +- crates/ibc/src/core/ics02_client/events.rs | 71 ++++---- .../ibc/src/core/ics03_connection/events.rs | 80 ++++----- crates/ibc/src/core/ics04_channel/events.rs | 167 +++++++----------- crates/ibc/src/core/ics04_channel/timeout.rs | 18 +- crates/ibc/src/core/ics24_host/identifier.rs | 6 + crates/ibc/src/events.rs | 26 +-- 9 files changed, 162 insertions(+), 227 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 6d56e9096..2fdf07b32 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -9,3 +9,6 @@ members = [ exclude = [ "ci/no-std-check", ] + +[patch.crates-io] +ibc-proto = { git = "https://github.com/cosmos/ibc-proto-rs.git", rev = "2cf514366768ddef257db3283a0b8bcb4bf9638a" } diff --git a/ci/no-std-check/Cargo.toml b/ci/no-std-check/Cargo.toml index 8c1cdbd16..b61f6fe1a 100644 --- a/ci/no-std-check/Cargo.toml +++ b/ci/no-std-check/Cargo.toml @@ -7,9 +7,9 @@ resolver = "2" [dependencies] ibc = { path = "../../crates/ibc", default-features = false } ibc-proto = { version = "0.20.1", default-features = false } -tendermint = { version = "0.25.0", default-features = false } -tendermint-proto = { version = "0.25.0", default-features = false } -tendermint-light-client-verifier = { version = "0.25.0", default-features = false } +tendermint = { version = "0.26.0", default-features = false } +tendermint-proto = { version = "0.26.0", default-features = false } +tendermint-light-client-verifier = { version = "0.26.0", default-features = false } sp-core = { version = "5.0.0", default-features = false, optional = true } sp-io = { version = "5.0.0", default-features = false, optional = true } diff --git a/crates/ibc/Cargo.toml b/crates/ibc/Cargo.toml index b45fc0d39..6ed6ab57e 100644 --- a/crates/ibc/Cargo.toml +++ b/crates/ibc/Cargo.toml @@ -48,19 +48,19 @@ primitive-types = { version = "0.12.0", default-features = false, features = ["s dyn-clone = "1.0.8" [dependencies.tendermint] -version = "=0.25.0" +version = "=0.26.0" default-features = false [dependencies.tendermint-proto] -version = "=0.25.0" +version = "=0.26.0" default-features = false [dependencies.tendermint-light-client-verifier] -version = "=0.25.0" +version = "=0.26.0" default-features = false [dependencies.tendermint-testgen] -version = "=0.25.0" +version = "=0.26.0" optional = true default-features = false @@ -70,5 +70,5 @@ tracing-subscriber = { version = "0.3.14", features = ["fmt", "env-filter", "jso test-log = { version = "0.2.10", features = ["trace"] } modelator = "0.4.2" sha2 = { version = "0.10.6" } -tendermint-rpc = { version = "=0.25.0", features = ["http-client", "websocket-client"] } -tendermint-testgen = { version = "=0.25.0" } # Needed for generating (synthetic) light blocks. +tendermint-rpc = { version = "=0.26.0", features = ["http-client", "websocket-client"] } +tendermint-testgen = { version = "=0.26.0" } # Needed for generating (synthetic) light blocks. diff --git a/crates/ibc/src/core/ics02_client/events.rs b/crates/ibc/src/core/ics02_client/events.rs index 4c18ed1b0..9a0fb4cf2 100644 --- a/crates/ibc/src/core/ics02_client/events.rs +++ b/crates/ibc/src/core/ics02_client/events.rs @@ -3,8 +3,7 @@ use derive_more::From; use ibc_proto::google::protobuf::Any; use subtle_encoding::hex; -use tendermint::abci::tag::Tag; -use tendermint::abci::Event as AbciEvent; +use tendermint::abci; use crate::core::ics02_client::client_type::ClientType; use crate::core::ics02_client::height::Height; @@ -31,11 +30,12 @@ struct ClientIdAttribute { client_id: ClientId, } -impl From for Tag { +impl From for abci::EventAttribute { fn from(attr: ClientIdAttribute) -> Self { - Tag { - key: CLIENT_ID_ATTRIBUTE_KEY.parse().unwrap(), - value: attr.client_id.to_string().parse().unwrap(), + Self { + key: CLIENT_ID_ATTRIBUTE_KEY.to_owned(), + value: attr.client_id.into(), + index: false, } } } @@ -45,12 +45,9 @@ struct ClientTypeAttribute { client_type: ClientType, } -impl From for Tag { +impl From for abci::EventAttribute { fn from(attr: ClientTypeAttribute) -> Self { - Tag { - key: CLIENT_TYPE_ATTRIBUTE_KEY.parse().unwrap(), - value: attr.client_type.to_string().parse().unwrap(), - } + (CLIENT_TYPE_ATTRIBUTE_KEY, attr.client_type.as_str()).into() } } @@ -59,12 +56,9 @@ struct ConsensusHeightAttribute { consensus_height: Height, } -impl From for Tag { +impl From for abci::EventAttribute { fn from(attr: ConsensusHeightAttribute) -> Self { - Tag { - key: CONSENSUS_HEIGHT_ATTRIBUTE_KEY.parse().unwrap(), - value: attr.consensus_height.to_string().parse().unwrap(), - } + (CONSENSUS_HEIGHT_ATTRIBUTE_KEY, attr.consensus_height).into() } } @@ -73,17 +67,14 @@ struct ConsensusHeightsAttribute { consensus_heights: Vec, } -impl From for Tag { +impl From for abci::EventAttribute { fn from(attr: ConsensusHeightsAttribute) -> Self { let consensus_heights: Vec = attr .consensus_heights .into_iter() .map(|consensus_height| consensus_height.to_string()) .collect(); - Tag { - key: CONSENSUS_HEIGHTS_ATTRIBUTE_KEY.parse().unwrap(), - value: consensus_heights.join(",").parse().unwrap(), - } + (CONSENSUS_HEIGHTS_ATTRIBUTE_KEY, consensus_heights.join(",")).into() } } @@ -92,15 +83,13 @@ struct HeaderAttribute { header: Any, } -impl From for Tag { +impl From for abci::EventAttribute { fn from(attr: HeaderAttribute) -> Self { - Tag { - key: HEADER_ATTRIBUTE_KEY.parse().unwrap(), - value: String::from_utf8(hex::encode(attr.header.value)) - .unwrap() - .parse() - .unwrap(), - } + ( + HEADER_ATTRIBUTE_KEY, + String::from_utf8(hex::encode(attr.header.value)).unwrap(), + ) + .into() } } @@ -134,10 +123,10 @@ impl CreateClient { } } -impl From for AbciEvent { +impl From for abci::Event { fn from(c: CreateClient) -> Self { - AbciEvent { - type_str: IbcEventType::CreateClient.as_str().to_string(), + Self { + kind: IbcEventType::CreateClient.as_str().to_owned(), attributes: vec![ c.client_id.into(), c.client_type.into(), @@ -197,10 +186,10 @@ impl UpdateClient { } } -impl From for AbciEvent { +impl From for abci::Event { fn from(u: UpdateClient) -> Self { - AbciEvent { - type_str: IbcEventType::UpdateClient.as_str().to_string(), + Self { + kind: IbcEventType::UpdateClient.as_str().to_owned(), attributes: vec![ u.client_id.into(), u.client_type.into(), @@ -237,10 +226,10 @@ impl ClientMisbehaviour { } } -impl From for AbciEvent { +impl From for abci::Event { fn from(c: ClientMisbehaviour) -> Self { - AbciEvent { - type_str: IbcEventType::ClientMisbehaviour.as_str().to_string(), + Self { + kind: IbcEventType::ClientMisbehaviour.as_str().to_owned(), attributes: vec![c.client_id.into(), c.client_type.into()], } } @@ -276,10 +265,10 @@ impl UpgradeClient { } } -impl From for AbciEvent { +impl From for abci::Event { fn from(u: UpgradeClient) -> Self { - AbciEvent { - type_str: IbcEventType::UpgradeClient.as_str().to_string(), + Self { + kind: IbcEventType::UpgradeClient.as_str().to_owned(), attributes: vec![ u.client_id.into(), u.client_type.into(), diff --git a/crates/ibc/src/core/ics03_connection/events.rs b/crates/ibc/src/core/ics03_connection/events.rs index 5db480af7..91c8f6436 100644 --- a/crates/ibc/src/core/ics03_connection/events.rs +++ b/crates/ibc/src/core/ics03_connection/events.rs @@ -1,8 +1,7 @@ //! Types for the IBC events emitted from Tendermint Websocket by the connection module. use serde_derive::{Deserialize, Serialize}; -use tendermint::abci::tag::Tag; -use tendermint::abci::Event as AbciEvent; +use tendermint::abci; use crate::core::ics24_host::identifier::{ClientId, ConnectionId}; use crate::events::IbcEventType; @@ -30,30 +29,25 @@ struct Attributes { /// is infallible, even if it is not represented in the error type. /// Once tendermint-rs improves the API of the `Key` and `Value` types, /// we will be able to remove the `.parse().unwrap()` calls. -impl From for Vec { +impl From for Vec { fn from(a: Attributes) -> Self { - let conn_id = Tag { - key: CONN_ID_ATTRIBUTE_KEY.parse().unwrap(), - value: a.connection_id.to_string().parse().unwrap(), - }; - - let client_id = Tag { - key: CLIENT_ID_ATTRIBUTE_KEY.parse().unwrap(), - value: a.client_id.to_string().parse().unwrap(), - }; - - let counterparty_conn_id = Tag { - key: COUNTERPARTY_CONN_ID_ATTRIBUTE_KEY.parse().unwrap(), - value: match a.counterparty_connection_id { - Some(counterparty_conn_id) => counterparty_conn_id.to_string().parse().unwrap(), - None => "".parse().unwrap(), - }, - }; - - let counterparty_client_id = Tag { - key: COUNTERPARTY_CLIENT_ID_ATTRIBUTE_KEY.parse().unwrap(), - value: a.counterparty_client_id.to_string().parse().unwrap(), - }; + let conn_id = (CONN_ID_ATTRIBUTE_KEY, a.connection_id.as_str()).into(); + let client_id = (CLIENT_ID_ATTRIBUTE_KEY, a.client_id.as_str()).into(); + + let counterparty_conn_id = ( + COUNTERPARTY_CONN_ID_ATTRIBUTE_KEY, + a.counterparty_connection_id + .as_ref() + .map(|id| id.as_str()) + .unwrap_or(""), + ) + .into(); + + let counterparty_client_id = ( + COUNTERPARTY_CLIENT_ID_ATTRIBUTE_KEY, + a.counterparty_client_id.as_str(), + ) + .into(); vec![ conn_id, @@ -96,12 +90,11 @@ impl OpenInit { } } -impl From for AbciEvent { +impl From for abci::Event { fn from(v: OpenInit) -> Self { - let attributes = Vec::::from(v.0); - AbciEvent { - type_str: IbcEventType::OpenInitConnection.as_str().to_string(), - attributes, + abci::Event { + kind: IbcEventType::OpenInitConnection.as_str().to_owned(), + attributes: v.0.into(), } } } @@ -139,12 +132,11 @@ impl OpenTry { } } -impl From for AbciEvent { +impl From for abci::Event { fn from(v: OpenTry) -> Self { - let attributes = Vec::::from(v.0); - AbciEvent { - type_str: IbcEventType::OpenTryConnection.as_str().to_string(), - attributes, + abci::Event { + kind: IbcEventType::OpenTryConnection.as_str().to_owned(), + attributes: v.0.into(), } } } @@ -182,12 +174,11 @@ impl OpenAck { } } -impl From for AbciEvent { +impl From for abci::Event { fn from(v: OpenAck) -> Self { - let attributes = Vec::::from(v.0); - AbciEvent { - type_str: IbcEventType::OpenAckConnection.as_str().to_string(), - attributes, + abci::Event { + kind: IbcEventType::OpenAckConnection.as_str().to_owned(), + attributes: v.0.into(), } } } @@ -225,12 +216,11 @@ impl OpenConfirm { } } -impl From for AbciEvent { +impl From for abci::Event { fn from(v: OpenConfirm) -> Self { - let attributes = Vec::::from(v.0); - AbciEvent { - type_str: IbcEventType::OpenConfirmConnection.as_str().to_string(), - attributes, + abci::Event { + kind: IbcEventType::OpenConfirmConnection.as_str().to_owned(), + attributes: v.0.into(), } } } diff --git a/crates/ibc/src/core/ics04_channel/events.rs b/crates/ibc/src/core/ics04_channel/events.rs index 69fda95da..d8406ec0e 100644 --- a/crates/ibc/src/core/ics04_channel/events.rs +++ b/crates/ibc/src/core/ics04_channel/events.rs @@ -1,8 +1,7 @@ //! Types for the IBC events emitted from Tendermint Websocket by the channels module. use serde_derive::{Deserialize, Serialize}; -use tendermint::abci::tag::Tag; -use tendermint::abci::Event as AbciEvent; +use tendermint::abci; use crate::core::ics04_channel::error::Error; use crate::core::ics04_channel::packet::Packet; @@ -54,36 +53,25 @@ impl Attributes { /// is infallible, even if it is not represented in the error type. /// Once tendermint-rs improves the API of the `Key` and `Value` types, /// we will be able to remove the `.parse().unwrap()` calls. -impl From for Vec { +impl From for Vec { fn from(a: Attributes) -> Self { let mut attributes = vec![]; - let port_id = Tag { - key: PORT_ID_ATTRIBUTE_KEY.parse().unwrap(), - value: a.port_id.to_string().parse().unwrap(), - }; + let port_id = (PORT_ID_ATTRIBUTE_KEY, a.port_id.as_str()).into(); attributes.push(port_id); if let Some(channel_id) = a.channel_id { - let channel_id = Tag { - key: CHANNEL_ID_ATTRIBUTE_KEY.parse().unwrap(), - value: channel_id.to_string().parse().unwrap(), - }; + let channel_id = (CHANNEL_ID_ATTRIBUTE_KEY, channel_id.as_str()).into(); attributes.push(channel_id); } - let connection_id = Tag { - key: CONNECTION_ID_ATTRIBUTE_KEY.parse().unwrap(), - value: a.connection_id.to_string().parse().unwrap(), - }; + let connection_id = (CONNECTION_ID_ATTRIBUTE_KEY, a.connection_id.as_str()).into(); attributes.push(connection_id); - let counterparty_port_id = Tag { - key: COUNTERPARTY_PORT_ID_ATTRIBUTE_KEY.parse().unwrap(), - value: a.counterparty_port_id.to_string().parse().unwrap(), - }; + let counterparty_port_id = ( + COUNTERPARTY_PORT_ID_ATTRIBUTE_KEY, + a.counterparty_port_id.as_str(), + ) + .into(); attributes.push(counterparty_port_id); if let Some(channel_id) = a.counterparty_channel_id { - let channel_id = Tag { - key: COUNTERPARTY_CHANNEL_ID_ATTRIBUTE_KEY.parse().unwrap(), - value: channel_id.to_string().parse().unwrap(), - }; + let channel_id = (COUNTERPARTY_CHANNEL_ID_ATTRIBUTE_KEY, channel_id.as_str()).into(); attributes.push(channel_id); } attributes @@ -98,64 +86,44 @@ impl From for Vec { /// is infallible, even if it is not represented in the error type. /// Once tendermint-rs improves the API of the `Key` and `Value` types, /// we will be able to remove the `.parse().unwrap()` calls. -impl TryFrom for Vec { +impl TryFrom for Vec { type Error = Error; fn try_from(p: Packet) -> Result { let mut attributes = vec![]; - let src_port = Tag { - key: PKT_SRC_PORT_ATTRIBUTE_KEY.parse().unwrap(), - value: p.source_port.to_string().parse().unwrap(), - }; + let src_port = (PKT_SRC_PORT_ATTRIBUTE_KEY, p.source_port.as_str()).into(); attributes.push(src_port); - let src_channel = Tag { - key: PKT_SRC_CHANNEL_ATTRIBUTE_KEY.parse().unwrap(), - value: p.source_channel.to_string().parse().unwrap(), - }; + let src_channel = (PKT_SRC_CHANNEL_ATTRIBUTE_KEY, p.source_channel.as_str()).into(); attributes.push(src_channel); - let dst_port = Tag { - key: PKT_DST_PORT_ATTRIBUTE_KEY.parse().unwrap(), - value: p.destination_port.to_string().parse().unwrap(), - }; + let dst_port = (PKT_DST_PORT_ATTRIBUTE_KEY, p.destination_port.as_str()).into(); attributes.push(dst_port); - let dst_channel = Tag { - key: PKT_DST_CHANNEL_ATTRIBUTE_KEY.parse().unwrap(), - value: p.destination_channel.to_string().parse().unwrap(), - }; + let dst_channel = ( + PKT_DST_CHANNEL_ATTRIBUTE_KEY, + p.destination_channel.as_str(), + ) + .into(); attributes.push(dst_channel); - let sequence = Tag { - key: PKT_SEQ_ATTRIBUTE_KEY.parse().unwrap(), - value: p.sequence.to_string().parse().unwrap(), - }; + let sequence = (PKT_SEQ_ATTRIBUTE_KEY, p.sequence.to_string()).into(); attributes.push(sequence); - let timeout_height = Tag { - key: PKT_TIMEOUT_HEIGHT_ATTRIBUTE_KEY.parse().unwrap(), - value: p.timeout_height.into(), - }; + let timeout_height = ( + PKT_TIMEOUT_HEIGHT_ATTRIBUTE_KEY, + p.timeout_height.to_attribute_value(), + ) + .into(); attributes.push(timeout_height); - let timeout_timestamp = Tag { - key: PKT_TIMEOUT_TIMESTAMP_ATTRIBUTE_KEY.parse().unwrap(), - value: p - .timeout_timestamp - .nanoseconds() - .to_string() - .parse() - .unwrap(), - }; + let timeout_timestamp = ( + PKT_TIMEOUT_TIMESTAMP_ATTRIBUTE_KEY, + p.timeout_timestamp.nanoseconds().to_string(), + ) + .into(); attributes.push(timeout_timestamp); // Note: this attribute forces us to assume that Packet data is valid UTF-8, even // though the standard doesn't require it. It has been deprecated in ibc-go, // and we will deprecate it in v0.22.0. It will be removed in the future. let val = String::from_utf8(p.data).map_err(|_| Error::non_utf8_packet_data())?; - let packet_data = Tag { - key: PKT_DATA_ATTRIBUTE_KEY.parse().unwrap(), - value: val.parse().unwrap(), - }; + let packet_data = (PKT_DATA_ATTRIBUTE_KEY, val).into(); attributes.push(packet_data); - let ack = Tag { - key: PKT_ACK_ATTRIBUTE_KEY.parse().unwrap(), - value: "".parse().unwrap(), - }; + let ack = (PKT_ACK_ATTRIBUTE_KEY, "").into(); attributes.push(ack); Ok(attributes) } @@ -465,13 +433,12 @@ impl_try_from_attribute_for_event!(OpenInit, OpenTry, OpenAck, OpenConfirm, Clos macro_rules! impl_from_ibc_to_abci_event { ($($event:ty),+) => { - $(impl From<$event> for AbciEvent { + $(impl From<$event> for abci::Event { fn from(v: $event) -> Self { - let attributes = Vec::::from(Attributes::from(v)); - let type_str = <$event>::event_type().as_str().to_string(); - AbciEvent { - type_str, - attributes, + let kind = <$event>::event_type().as_str().to_owned(); + Self { + kind, + attributes: Attributes::from(v).into(), } } })+ @@ -513,14 +480,13 @@ impl From for IbcEvent { } } -impl TryFrom for AbciEvent { +impl TryFrom for abci::Event { type Error = Error; fn try_from(v: SendPacket) -> Result { - let attributes = Vec::::try_from(v.packet)?; - Ok(AbciEvent { - type_str: IbcEventType::SendPacket.as_str().to_string(), - attributes, + Ok(Self { + kind: IbcEventType::SendPacket.as_str().to_owned(), + attributes: v.packet.try_into()?, }) } } @@ -551,14 +517,13 @@ impl From for IbcEvent { } } -impl TryFrom for AbciEvent { +impl TryFrom for abci::Event { type Error = Error; fn try_from(v: ReceivePacket) -> Result { - let attributes = Vec::::try_from(v.packet)?; - Ok(AbciEvent { - type_str: IbcEventType::ReceivePacket.as_str().to_string(), - attributes, + Ok(Self { + kind: IbcEventType::ReceivePacket.as_str().to_owned(), + attributes: v.packet.try_into()?, }) } } @@ -591,21 +556,18 @@ impl From for IbcEvent { } } -impl TryFrom for AbciEvent { +impl TryFrom for abci::Event { type Error = Error; fn try_from(v: WriteAcknowledgement) -> Result { - let mut attributes = Vec::::try_from(v.packet)?; + let mut attributes: Vec = v.packet.try_into()?; let val = String::from_utf8(v.ack).expect("hex-encoded string should always be valid UTF-8"); // No actual conversion from string to `Tag::Key` or `Tag::Value` - let ack = Tag { - key: PKT_ACK_ATTRIBUTE_KEY.parse().unwrap(), - value: val.parse().unwrap(), - }; + let ack = (PKT_ACK_ATTRIBUTE_KEY, val).into(); attributes.push(ack); - Ok(AbciEvent { - type_str: IbcEventType::WriteAck.as_str().to_string(), + Ok(Self { + kind: IbcEventType::WriteAck.as_str().to_owned(), attributes, }) } @@ -631,14 +593,13 @@ impl From for IbcEvent { } } -impl TryFrom for AbciEvent { +impl TryFrom for abci::Event { type Error = Error; fn try_from(v: AcknowledgePacket) -> Result { - let attributes = Vec::::try_from(v.packet)?; - Ok(AbciEvent { - type_str: IbcEventType::AckPacket.as_str().to_string(), - attributes, + Ok(Self { + kind: IbcEventType::AckPacket.as_str().to_owned(), + attributes: v.packet.try_into()?, }) } } @@ -669,14 +630,13 @@ impl From for IbcEvent { } } -impl TryFrom for AbciEvent { +impl TryFrom for abci::Event { type Error = Error; fn try_from(v: TimeoutPacket) -> Result { - let attributes = Vec::::try_from(v.packet)?; - Ok(AbciEvent { - type_str: IbcEventType::Timeout.as_str().to_string(), - attributes, + Ok(Self { + kind: IbcEventType::Timeout.as_str().to_owned(), + attributes: v.packet.try_into()?, }) } } @@ -707,14 +667,13 @@ impl From for IbcEvent { } } -impl TryFrom for AbciEvent { +impl TryFrom for abci::Event { type Error = Error; fn try_from(v: TimeoutOnClosePacket) -> Result { - let attributes = Vec::::try_from(v.packet)?; - Ok(AbciEvent { - type_str: IbcEventType::TimeoutOnClose.as_str().to_string(), - attributes, + Ok(Self { + kind: IbcEventType::TimeoutOnClose.as_str().to_owned(), + attributes: v.packet.try_into()?, }) } } diff --git a/crates/ibc/src/core/ics04_channel/timeout.rs b/crates/ibc/src/core/ics04_channel/timeout.rs index 7e91d47b2..de0e00bf9 100644 --- a/crates/ibc/src/core/ics04_channel/timeout.rs +++ b/crates/ibc/src/core/ics04_channel/timeout.rs @@ -3,7 +3,6 @@ use core::fmt::{Display, Error as FmtError, Formatter}; use serde::{Deserialize, Serialize}; use ibc_proto::ibc::core::client::v1::Height as RawHeight; -use tendermint::abci::tag::Value as TagValue; use crate::core::ics02_client::{error::Error as ICS2Error, height::Height}; use crate::prelude::*; @@ -54,6 +53,14 @@ impl TimeoutHeight { Self::Never => false, } } + + /// Returns a string formatted for an ABCI event attribute value. + pub fn to_attribute_value(self) -> String { + match self { + TimeoutHeight::At(height) => height.to_string(), + TimeoutHeight::Never => "0-0".into(), + } + } } impl Default for TimeoutHeight { @@ -111,15 +118,6 @@ impl From for TimeoutHeight { } } -impl From for TagValue { - fn from(timeout_height: TimeoutHeight) -> Self { - match timeout_height { - TimeoutHeight::At(height) => height.to_string().parse().unwrap(), - TimeoutHeight::Never => "0-0".parse().unwrap(), - } - } -} - impl Display for TimeoutHeight { fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), FmtError> { match self { diff --git a/crates/ibc/src/core/ics24_host/identifier.rs b/crates/ibc/src/core/ics24_host/identifier.rs index bfe571e41..1d85ad248 100644 --- a/crates/ibc/src/core/ics24_host/identifier.rs +++ b/crates/ibc/src/core/ics24_host/identifier.rs @@ -193,6 +193,12 @@ impl Default for ClientId { } } +impl From for String { + fn from(id: ClientId) -> Self { + id.0 + } +} + /// Equality check against string literal (satisfies &ClientId == &str). /// ``` /// use core::str::FromStr; diff --git a/crates/ibc/src/events.rs b/crates/ibc/src/events.rs index a03e0841b..c0607ce6b 100644 --- a/crates/ibc/src/events.rs +++ b/crates/ibc/src/events.rs @@ -4,8 +4,7 @@ use core::convert::{TryFrom, TryInto}; use core::str::FromStr; use flex_error::{define_error, TraceError}; use serde_derive::{Deserialize, Serialize}; -use tendermint::abci::tag::Tag; -use tendermint::abci::Event as AbciEvent; +use tendermint::abci; use crate::core::ics02_client::error as client_error; use crate::core::ics02_client::events::{self as ClientEvents}; @@ -235,7 +234,7 @@ pub enum IbcEvent { AppModule(ModuleEvent), } -impl TryFrom for AbciEvent { +impl TryFrom for abci::Event { type Error = Error; fn try_from(event: IbcEvent) -> Result { @@ -329,7 +328,7 @@ pub struct ModuleEvent { pub attributes: Vec, } -impl TryFrom for AbciEvent { +impl TryFrom for abci::Event { type Error = Error; fn try_from(event: ModuleEvent) -> Result { @@ -338,8 +337,8 @@ impl TryFrom for AbciEvent { } let attributes = event.attributes.into_iter().map(Into::into).collect(); - Ok(AbciEvent { - type_str: event.kind, + Ok(abci::Event { + kind: event.kind, attributes, }) } @@ -366,18 +365,9 @@ impl From<(K, V)> for ModuleEventAttribute { } } -impl From for Tag { +impl From for abci::EventAttribute { fn from(attr: ModuleEventAttribute) -> Self { - Self { - key: attr - .key - .parse() - .expect("Key::from_str() impl is infallible"), - value: attr - .key - .parse() - .expect("Value::from_str() impl is infallible"), - } + (attr.key, attr.value).into() } } @@ -399,6 +389,6 @@ pub mod tests { packet.data = vec![128]; let ibc_event = IbcEvent::SendPacket(SendPacket { packet }); - let _ = AbciEvent::try_from(ibc_event); + let _ = abci::Event::try_from(ibc_event); } } From 058f3cabe777a23b9335b80bba8f4befebdcd39c Mon Sep 17 00:00:00 2001 From: Mikhail Zabaluev Date: Wed, 2 Nov 2022 16:01:26 +0200 Subject: [PATCH 02/11] Fix no-std-check with a temporary patch --- ci/no-std-check/Cargo.lock | 21 ++++++++++++--------- ci/no-std-check/Cargo.toml | 4 ++-- 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/ci/no-std-check/Cargo.lock b/ci/no-std-check/Cargo.lock index 831d542ef..7f04c26c8 100644 --- a/ci/no-std-check/Cargo.lock +++ b/ci/no-std-check/Cargo.lock @@ -238,6 +238,9 @@ name = "bytes" version = "1.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ec8a7b6a70fde80372154c65702f00a0f56f3e1c36abbc6c440484be248856db" +dependencies = [ + "serde", +] [[package]] name = "cc" @@ -737,7 +740,7 @@ dependencies = [ [[package]] name = "ibc" -version = "0.19.0" +version = "0.21.1" dependencies = [ "bytes", "derive_more", @@ -765,8 +768,8 @@ dependencies = [ [[package]] name = "ibc-proto" -version = "0.20.1" -source = "git+https://github.com/cosmos/ibc-proto-rs?branch=main#65c050e3a20e3a1ef3c1247788b5013112e207d7" +version = "0.21.0" +source = "git+https://github.com/cosmos/ibc-proto-rs.git?rev=2cf514366768ddef257db3283a0b8bcb4bf9638a#2cf514366768ddef257db3283a0b8bcb4bf9638a" dependencies = [ "base64", "bytes", @@ -2153,9 +2156,9 @@ checksum = "55937e1799185b12863d447f42597ed69d9928686b8d88a1df17376a097d8369" [[package]] name = "tendermint" -version = "0.25.0" +version = "0.26.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a8b18e007aee6b81b449e92ea6e8c2dceec5e26d340a8f244450caf40938c5d9" +checksum = "baa1d2d0ec1b531ba7d196f0dbee5e78ed2a82bfba928e88dff64aeec0b26073" dependencies = [ "async-trait", "bytes", @@ -2182,9 +2185,9 @@ dependencies = [ [[package]] name = "tendermint-light-client-verifier" -version = "0.25.0" +version = "0.26.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "516a490fd9a3a584fab43b634bedbbc00bc6844e65ea1b54b77d59da6fee1d4e" +checksum = "f66e3e75f9be6260fab5d5c9a6688885c478c3d3a14c66c2fde80c78769c20ee" dependencies = [ "derive_more", "flex-error", @@ -2195,9 +2198,9 @@ dependencies = [ [[package]] name = "tendermint-proto" -version = "0.25.0" +version = "0.26.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "41d7f0f8cba8816446b330eeb25f73c3ba7cb9b261677bf78e6ea560b8e1880b" +checksum = "974d6330a19dfa6720e9f663fc59101d207a817db3f9c730d3f31caaa565b574" dependencies = [ "bytes", "flex-error", diff --git a/ci/no-std-check/Cargo.toml b/ci/no-std-check/Cargo.toml index b61f6fe1a..872e82f25 100644 --- a/ci/no-std-check/Cargo.toml +++ b/ci/no-std-check/Cargo.toml @@ -6,7 +6,7 @@ resolver = "2" [dependencies] ibc = { path = "../../crates/ibc", default-features = false } -ibc-proto = { version = "0.20.1", default-features = false } +ibc-proto = { version = "0.21.0", default-features = false } tendermint = { version = "0.26.0", default-features = false } tendermint-proto = { version = "0.26.0", default-features = false } tendermint-light-client-verifier = { version = "0.26.0", default-features = false } @@ -32,4 +32,4 @@ substrate-std = [ ] [patch.crates-io] -ibc-proto = { git = "https://github.com/cosmos/ibc-proto-rs", branch = "main" } +ibc-proto = { git = "https://github.com/cosmos/ibc-proto-rs.git", rev = "2cf514366768ddef257db3283a0b8bcb4bf9638a" } From 45ae4cbd0e47e880345ac54f121e6fcd97d20663 Mon Sep 17 00:00:00 2001 From: Mikhail Zabaluev Date: Mon, 7 Nov 2022 15:08:22 +0200 Subject: [PATCH 03/11] Post-merge updates for tendermint 0.26 --- crates/ibc/src/core/ics04_channel/events.rs | 60 ++++--- .../events/channel_attributes.rs | 53 +++---- .../ics04_channel/events/packet_attributes.rs | 149 +++++++----------- .../ics04_channel/msgs/acknowledgement.rs | 5 + crates/ibc/src/core/ics04_channel/version.rs | 4 + 5 files changed, 112 insertions(+), 159 deletions(-) diff --git a/crates/ibc/src/core/ics04_channel/events.rs b/crates/ibc/src/core/ics04_channel/events.rs index 7ee9e6703..354d66201 100644 --- a/crates/ibc/src/core/ics04_channel/events.rs +++ b/crates/ibc/src/core/ics04_channel/events.rs @@ -68,18 +68,15 @@ impl OpenInit { } } -impl From for AbciEvent { +impl From for abci::Event { fn from(o: OpenInit) -> Self { - AbciEvent { - type_str: IbcEventType::OpenInitChannel.as_str().to_string(), + abci::Event { + kind: IbcEventType::OpenInitChannel.as_str().to_owned(), attributes: vec![ o.port_id.into(), o.channel_id.into(), o.counterparty_port_id.into(), - Tag { - key: COUNTERPARTY_CHANNEL_ID_ATTRIBUTE_KEY.parse().unwrap(), - value: String::from("").parse().unwrap(), - }, + (COUNTERPARTY_CHANNEL_ID_ATTRIBUTE_KEY, "").into(), o.connection_id.into(), o.version.into(), ], @@ -135,10 +132,10 @@ impl OpenTry { } } -impl From for AbciEvent { +impl From for abci::Event { fn from(o: OpenTry) -> Self { - AbciEvent { - type_str: IbcEventType::OpenTryChannel.as_str().to_string(), + abci::Event { + kind: IbcEventType::OpenTryChannel.as_str().to_owned(), attributes: vec![ o.port_id.into(), o.channel_id.into(), @@ -193,10 +190,10 @@ impl OpenAck { } } -impl From for AbciEvent { +impl From for abci::Event { fn from(o: OpenAck) -> Self { - AbciEvent { - type_str: IbcEventType::OpenAckChannel.as_str().to_string(), + abci::Event { + kind: IbcEventType::OpenAckChannel.as_str().to_owned(), attributes: vec![ o.port_id.into(), o.channel_id.into(), @@ -250,10 +247,10 @@ impl OpenConfirm { } } -impl From for AbciEvent { +impl From for abci::Event { fn from(o: OpenConfirm) -> Self { - AbciEvent { - type_str: IbcEventType::OpenConfirmChannel.as_str().to_string(), + abci::Event { + kind: IbcEventType::OpenConfirmChannel.as_str().to_owned(), attributes: vec![ o.port_id.into(), o.channel_id.into(), @@ -307,10 +304,10 @@ impl CloseInit { } } -impl From for AbciEvent { +impl From for abci::Event { fn from(o: CloseInit) -> Self { - AbciEvent { - type_str: IbcEventType::CloseInitChannel.as_str().to_string(), + abci::Event { + kind: IbcEventType::CloseInitChannel.as_str().to_owned(), attributes: vec![ o.port_id.into(), o.channel_id.into(), @@ -364,10 +361,10 @@ impl CloseConfirm { } } -impl From for AbciEvent { +impl From for abci::Event { fn from(o: CloseConfirm) -> Self { - AbciEvent { - type_str: IbcEventType::CloseConfirmChannel.as_str().to_string(), + abci::Event { + kind: IbcEventType::CloseConfirmChannel.as_str().to_owned(), attributes: vec![ o.port_id.into(), o.channel_id.into(), @@ -433,21 +430,18 @@ impl ChannelClosed { } } -impl From for AbciEvent { +impl From for abci::Event { fn from(ev: ChannelClosed) -> Self { - AbciEvent { - type_str: IbcEventType::ChannelClosed.as_str().to_string(), + abci::Event { + kind: IbcEventType::ChannelClosed.as_str().to_owned(), attributes: vec![ ev.port_id.into(), ev.channel_id.into(), ev.counterparty_port_id.into(), - ev.maybe_counterparty_channel_id.map_or( - Tag { - key: COUNTERPARTY_CHANNEL_ID_ATTRIBUTE_KEY.parse().unwrap(), - value: "".parse().unwrap(), - }, - |c| c.into(), - ), + ev.maybe_counterparty_channel_id + .map_or((COUNTERPARTY_CHANNEL_ID_ATTRIBUTE_KEY, "").into(), |c| { + c.into() + }), ev.connection_id.into(), ev.channel_ordering.into(), ], @@ -557,7 +551,7 @@ impl TryFrom for abci::Event { attributes.push(v.dst_connection_id.into()); Ok(abci::Event { - type_str: IbcEventType::ReceivePacket.as_str().to_owned(), + kind: IbcEventType::ReceivePacket.as_str().to_owned(), attributes, }) } diff --git a/crates/ibc/src/core/ics04_channel/events/channel_attributes.rs b/crates/ibc/src/core/ics04_channel/events/channel_attributes.rs index 3873918f7..5dc681645 100644 --- a/crates/ibc/src/core/ics04_channel/events/channel_attributes.rs +++ b/crates/ibc/src/core/ics04_channel/events/channel_attributes.rs @@ -1,8 +1,7 @@ ///! This module holds all the abci event attributes for IBC events emitted ///! during the channel handshake. -use alloc::string::ToString; use derive_more::From; -use tendermint::abci::tag::Tag; +use tendermint::abci; use crate::core::{ ics04_channel::Version, @@ -23,12 +22,9 @@ pub struct PortIdAttribute { pub port_id: PortId, } -impl From for Tag { +impl From for abci::EventAttribute { fn from(attr: PortIdAttribute) -> Self { - Tag { - key: PORT_ID_ATTRIBUTE_KEY.parse().unwrap(), - value: attr.port_id.to_string().parse().unwrap(), - } + (PORT_ID_ATTRIBUTE_KEY, attr.port_id.as_str()).into() } } @@ -37,12 +33,9 @@ pub struct ChannelIdAttribute { pub channel_id: ChannelId, } -impl From for Tag { +impl From for abci::EventAttribute { fn from(attr: ChannelIdAttribute) -> Self { - Tag { - key: CHANNEL_ID_ATTRIBUTE_KEY.parse().unwrap(), - value: attr.channel_id.to_string().parse().unwrap(), - } + (CHANNEL_ID_ATTRIBUTE_KEY, attr.channel_id.as_str()).into() } } @@ -51,12 +44,13 @@ pub struct CounterpartyPortIdAttribute { pub counterparty_port_id: PortId, } -impl From for Tag { +impl From for abci::EventAttribute { fn from(attr: CounterpartyPortIdAttribute) -> Self { - Tag { - key: COUNTERPARTY_PORT_ID_ATTRIBUTE_KEY.parse().unwrap(), - value: attr.counterparty_port_id.to_string().parse().unwrap(), - } + ( + COUNTERPARTY_PORT_ID_ATTRIBUTE_KEY, + attr.counterparty_port_id.as_str(), + ) + .into() } } @@ -65,12 +59,13 @@ pub struct CounterpartyChannelIdAttribute { pub counterparty_channel_id: ChannelId, } -impl From for Tag { +impl From for abci::EventAttribute { fn from(attr: CounterpartyChannelIdAttribute) -> Self { - Tag { - key: COUNTERPARTY_CHANNEL_ID_ATTRIBUTE_KEY.parse().unwrap(), - value: attr.counterparty_channel_id.to_string().parse().unwrap(), - } + ( + COUNTERPARTY_CHANNEL_ID_ATTRIBUTE_KEY, + attr.counterparty_channel_id.as_str(), + ) + .into() } } @@ -85,12 +80,9 @@ pub struct ConnectionIdAttribute { pub connection_id: ConnectionId, } -impl From for Tag { +impl From for abci::EventAttribute { fn from(attr: ConnectionIdAttribute) -> Self { - Tag { - key: CONNECTION_ID_ATTRIBUTE_KEY.parse().unwrap(), - value: attr.connection_id.to_string().parse().unwrap(), - } + (CONNECTION_ID_ATTRIBUTE_KEY, attr.connection_id.as_str()).into() } } @@ -99,11 +91,8 @@ pub struct VersionAttribute { pub version: Version, } -impl From for Tag { +impl From for abci::EventAttribute { fn from(attr: VersionAttribute) -> Self { - Tag { - key: VERSION_ATTRIBUTE_KEY.parse().unwrap(), - value: attr.version.to_string().parse().unwrap(), - } + (VERSION_ATTRIBUTE_KEY, attr.version.as_str()).into() } } diff --git a/crates/ibc/src/core/ics04_channel/events/packet_attributes.rs b/crates/ibc/src/core/ics04_channel/events/packet_attributes.rs index 04cfedae8..8e2251aa0 100644 --- a/crates/ibc/src/core/ics04_channel/events/packet_attributes.rs +++ b/crates/ibc/src/core/ics04_channel/events/packet_attributes.rs @@ -1,7 +1,7 @@ use crate::{ core::{ ics04_channel::{ - channel::Order, msgs::acknowledgement::Acknowledgement, packet::Sequence, + channel::Order, error::Error, msgs::acknowledgement::Acknowledgement, packet::Sequence, timeout::TimeoutHeight, }, ics24_host::identifier::{ChannelId, ConnectionId, PortId}, @@ -11,9 +11,9 @@ use crate::{ }; use derive_more::From; use subtle_encoding::hex; -use tendermint::abci::tag::Tag; +use tendermint::abci; -use crate::core::ics04_channel::error::Error; +use core::str; ///! This module holds all the abci event attributes for IBC events emitted ///! during packet-related datagrams. @@ -37,29 +37,21 @@ pub struct PacketDataAttribute { pub packet_data: Vec, } -impl TryFrom for Vec { +impl TryFrom for Vec { type Error = Error; fn try_from(attr: PacketDataAttribute) -> Result { let tags = vec![ - Tag { - key: PKT_DATA_ATTRIBUTE_KEY.parse().unwrap(), - value: String::from_utf8(attr.packet_data.clone()) - // Note: this attribute forces us to assume that Packet data - // is valid UTF-8, even though the standard doesn't require - // it. It has been deprecated in ibc-go. It will be removed - // in the future. - .map_err(|_| Error::non_utf8_packet_data())? - .parse() - .unwrap(), - }, - Tag { - key: PKT_DATA_HEX_ATTRIBUTE_KEY.parse().unwrap(), - value: String::from_utf8(hex::encode(attr.packet_data)) - .unwrap() - .parse() - .unwrap(), - }, + ( + PKT_DATA_ATTRIBUTE_KEY, + str::from_utf8(&attr.packet_data).map_err(|_| Error::non_utf8_packet_data())?, + ) + .into(), + ( + PKT_DATA_HEX_ATTRIBUTE_KEY, + String::from_utf8(hex::encode(attr.packet_data)).unwrap(), + ) + .into(), ]; Ok(tags) @@ -71,16 +63,13 @@ pub struct TimeoutHeightAttribute { pub timeout_height: TimeoutHeight, } -impl From for Tag { +impl From for abci::EventAttribute { fn from(attr: TimeoutHeightAttribute) -> Self { - Tag { - key: PKT_TIMEOUT_HEIGHT_ATTRIBUTE_KEY.parse().unwrap(), - value: match attr.timeout_height { - TimeoutHeight::Never => "0-0".to_string(), - TimeoutHeight::At(height) => height.to_string(), + match attr.timeout_height { + TimeoutHeight::Never => (PKT_TIMEOUT_HEIGHT_ATTRIBUTE_KEY, "0-0").into(), + TimeoutHeight::At(height) => { + (PKT_TIMEOUT_HEIGHT_ATTRIBUTE_KEY, height.to_string()).into() } - .parse() - .unwrap(), } } } @@ -90,17 +79,13 @@ pub struct TimeoutTimestampAttribute { pub timeout_timestamp: Timestamp, } -impl From for Tag { +impl From for abci::EventAttribute { fn from(attr: TimeoutTimestampAttribute) -> Self { - Tag { - key: PKT_TIMEOUT_TIMESTAMP_ATTRIBUTE_KEY.parse().unwrap(), - value: attr - .timeout_timestamp - .nanoseconds() - .to_string() - .parse() - .unwrap(), - } + ( + PKT_TIMEOUT_TIMESTAMP_ATTRIBUTE_KEY, + attr.timeout_timestamp.nanoseconds().to_string(), + ) + .into() } } @@ -109,12 +94,9 @@ pub struct SequenceAttribute { pub sequence: Sequence, } -impl From for Tag { +impl From for abci::EventAttribute { fn from(attr: SequenceAttribute) -> Self { - Tag { - key: PKT_SEQ_ATTRIBUTE_KEY.parse().unwrap(), - value: u64::from(attr.sequence).to_string().parse().unwrap(), - } + (PKT_SEQ_ATTRIBUTE_KEY, attr.sequence.to_string()).into() } } @@ -123,12 +105,9 @@ pub struct SrcPortIdAttribute { pub src_port_id: PortId, } -impl From for Tag { +impl From for abci::EventAttribute { fn from(attr: SrcPortIdAttribute) -> Self { - Tag { - key: PKT_SRC_PORT_ATTRIBUTE_KEY.parse().unwrap(), - value: attr.src_port_id.as_str().parse().unwrap(), - } + (PKT_SRC_PORT_ATTRIBUTE_KEY, attr.src_port_id.as_str()).into() } } @@ -137,12 +116,9 @@ pub struct SrcChannelIdAttribute { pub src_channel_id: ChannelId, } -impl From for Tag { +impl From for abci::EventAttribute { fn from(attr: SrcChannelIdAttribute) -> Self { - Tag { - key: PKT_SRC_CHANNEL_ATTRIBUTE_KEY.parse().unwrap(), - value: attr.src_channel_id.as_str().parse().unwrap(), - } + (PKT_SRC_CHANNEL_ATTRIBUTE_KEY, attr.src_channel_id.as_str()).into() } } @@ -151,12 +127,9 @@ pub struct DstPortIdAttribute { pub dst_port_id: PortId, } -impl From for Tag { +impl From for abci::EventAttribute { fn from(attr: DstPortIdAttribute) -> Self { - Tag { - key: PKT_DST_PORT_ATTRIBUTE_KEY.parse().unwrap(), - value: attr.dst_port_id.as_str().parse().unwrap(), - } + (PKT_DST_PORT_ATTRIBUTE_KEY, attr.dst_port_id.as_str()).into() } } @@ -165,12 +138,9 @@ pub struct DstChannelIdAttribute { pub dst_channel_id: ChannelId, } -impl From for Tag { +impl From for abci::EventAttribute { fn from(attr: DstChannelIdAttribute) -> Self { - Tag { - key: PKT_DST_CHANNEL_ATTRIBUTE_KEY.parse().unwrap(), - value: attr.dst_channel_id.as_str().parse().unwrap(), - } + (PKT_DST_CHANNEL_ATTRIBUTE_KEY, attr.dst_channel_id.as_str()).into() } } @@ -179,12 +149,9 @@ pub struct ChannelOrderingAttribute { pub order: Order, } -impl From for Tag { +impl From for abci::EventAttribute { fn from(attr: ChannelOrderingAttribute) -> Self { - Tag { - key: PKT_CHANNEL_ORDERING_ATTRIBUTE_KEY.parse().unwrap(), - value: attr.order.as_str().parse().unwrap(), - } + (PKT_CHANNEL_ORDERING_ATTRIBUTE_KEY, attr.order.as_str()).into() } } @@ -193,12 +160,9 @@ pub struct PacketConnectionIdAttribute { pub connection_id: ConnectionId, } -impl From for Tag { +impl From for abci::EventAttribute { fn from(attr: PacketConnectionIdAttribute) -> Self { - Tag { - key: PKT_CONNECTION_ID_ATTRIBUTE_KEY.parse().unwrap(), - value: attr.connection_id.as_str().parse().unwrap(), - } + (PKT_CONNECTION_ID_ATTRIBUTE_KEY, attr.connection_id.as_str()).into() } } @@ -207,29 +171,26 @@ pub struct AcknowledgementAttribute { pub acknowledgement: Acknowledgement, } -impl TryFrom for Vec { +impl TryFrom for Vec { type Error = Error; fn try_from(attr: AcknowledgementAttribute) -> Result { let tags = vec![ - Tag { - key: PKT_ACK_ATTRIBUTE_KEY.parse().unwrap(), - value: String::from_utf8(attr.acknowledgement.as_ref().into()) - // Note: this attribute forces us to assume that Packet data - // is valid UTF-8, even though the standard doesn't require - // it. It has been deprecated in ibc-go. It will be removed - // in the future. - .map_err(|_| Error::non_utf8_packet_data())? - .parse() - .unwrap(), - }, - Tag { - key: PKT_ACK_HEX_ATTRIBUTE_KEY.parse().unwrap(), - value: String::from_utf8(hex::encode(attr.acknowledgement)) - .unwrap() - .parse() - .unwrap(), - }, + ( + PKT_ACK_ATTRIBUTE_KEY, + // Note: this attribute forces us to assume that Packet data + // is valid UTF-8, even though the standard doesn't require + // it. It has been deprecated in ibc-go. It will be removed + // in the future. + str::from_utf8(attr.acknowledgement.as_bytes()) + .map_err(|_| Error::non_utf8_packet_data())?, + ) + .into(), + ( + PKT_ACK_HEX_ATTRIBUTE_KEY, + String::from_utf8(hex::encode(attr.acknowledgement)).unwrap(), + ) + .into(), ]; Ok(tags) diff --git a/crates/ibc/src/core/ics04_channel/msgs/acknowledgement.rs b/crates/ibc/src/core/ics04_channel/msgs/acknowledgement.rs index 14129cd67..3259d48b1 100644 --- a/crates/ibc/src/core/ics04_channel/msgs/acknowledgement.rs +++ b/crates/ibc/src/core/ics04_channel/msgs/acknowledgement.rs @@ -20,6 +20,11 @@ impl Acknowledgement { pub fn is_empty(&self) -> bool { self.0.is_empty() } + + // Returns the data as a slice of bytes. + pub fn as_bytes(&self) -> &[u8] { + self.0.as_slice() + } } impl AsRef<[u8]> for Acknowledgement { diff --git a/crates/ibc/src/core/ics04_channel/version.rs b/crates/ibc/src/core/ics04_channel/version.rs index b1c2921e3..68bbbc111 100644 --- a/crates/ibc/src/core/ics04_channel/version.rs +++ b/crates/ibc/src/core/ics04_channel/version.rs @@ -34,6 +34,10 @@ impl Version { pub fn is_empty(&self) -> bool { self.0.is_empty() } + + pub fn as_str(&self) -> &str { + &self.0 + } } impl From for Version { From afd79ce5632b401878e80588ef09454e4af8123f Mon Sep 17 00:00:00 2001 From: Mikhail Zabaluev Date: Mon, 7 Nov 2022 15:18:49 +0200 Subject: [PATCH 04/11] ics04_channel::events: Use Option::map_or_else Option::map_or requires the alternative value to be non-lazily constructed, so we save some allocations. --- crates/ibc/src/core/ics04_channel/events.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/crates/ibc/src/core/ics04_channel/events.rs b/crates/ibc/src/core/ics04_channel/events.rs index 354d66201..3403d03d0 100644 --- a/crates/ibc/src/core/ics04_channel/events.rs +++ b/crates/ibc/src/core/ics04_channel/events.rs @@ -438,10 +438,10 @@ impl From for abci::Event { ev.port_id.into(), ev.channel_id.into(), ev.counterparty_port_id.into(), - ev.maybe_counterparty_channel_id - .map_or((COUNTERPARTY_CHANNEL_ID_ATTRIBUTE_KEY, "").into(), |c| { - c.into() - }), + ev.maybe_counterparty_channel_id.map_or_else( + || (COUNTERPARTY_CHANNEL_ID_ATTRIBUTE_KEY, "").into(), + |c| c.into(), + ), ev.connection_id.into(), ev.channel_ordering.into(), ], From af8438ed30afd537df318feb8ec757f3d4f2d611 Mon Sep 17 00:00:00 2001 From: Mikhail Zabaluev Date: Wed, 9 Nov 2022 20:35:25 +0200 Subject: [PATCH 05/11] Update ibc-proto to 0.22.0 --- Cargo.toml | 3 --- ci/no-std-check/Cargo.toml | 5 +---- crates/ibc/Cargo.toml | 2 +- 3 files changed, 2 insertions(+), 8 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 2fdf07b32..6d56e9096 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -9,6 +9,3 @@ members = [ exclude = [ "ci/no-std-check", ] - -[patch.crates-io] -ibc-proto = { git = "https://github.com/cosmos/ibc-proto-rs.git", rev = "2cf514366768ddef257db3283a0b8bcb4bf9638a" } diff --git a/ci/no-std-check/Cargo.toml b/ci/no-std-check/Cargo.toml index 872e82f25..be1d1ca95 100644 --- a/ci/no-std-check/Cargo.toml +++ b/ci/no-std-check/Cargo.toml @@ -6,7 +6,7 @@ resolver = "2" [dependencies] ibc = { path = "../../crates/ibc", default-features = false } -ibc-proto = { version = "0.21.0", default-features = false } +ibc-proto = { version = "0.22.0", default-features = false } tendermint = { version = "0.26.0", default-features = false } tendermint-proto = { version = "0.26.0", default-features = false } tendermint-light-client-verifier = { version = "0.26.0", default-features = false } @@ -30,6 +30,3 @@ substrate-std = [ "sp-runtime/std", "sp-std/std", ] - -[patch.crates-io] -ibc-proto = { git = "https://github.com/cosmos/ibc-proto-rs.git", rev = "2cf514366768ddef257db3283a0b8bcb4bf9638a" } diff --git a/crates/ibc/Cargo.toml b/crates/ibc/Cargo.toml index c1e39acb1..2c2f57ed8 100644 --- a/crates/ibc/Cargo.toml +++ b/crates/ibc/Cargo.toml @@ -27,7 +27,7 @@ mocks = ["tendermint-testgen", "clock", "std"] [dependencies] # Proto definitions for all IBC-related interfaces, e.g., connections or channels. -ibc-proto = { version = "0.21.0", default-features = false } +ibc-proto = { version = "0.22.0", default-features = false } ics23 = { version = "=0.8.1", default-features = false, features = ["host-functions"] } time = { version = ">=0.3.0, <0.3.17", default-features = false } serde_derive = { version = "1.0.104", default-features = false } From b301bbee496bc0fca96eab57e642859bfec636cd Mon Sep 17 00:00:00 2001 From: Mikhail Zabaluev Date: Wed, 9 Nov 2022 20:36:28 +0200 Subject: [PATCH 06/11] Rename TimeoutHeight::to_attribute_value Ramify the name as to_event_attribute_value for clarity. --- crates/ibc/src/core/ics04_channel/timeout.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/ibc/src/core/ics04_channel/timeout.rs b/crates/ibc/src/core/ics04_channel/timeout.rs index de0e00bf9..d72537140 100644 --- a/crates/ibc/src/core/ics04_channel/timeout.rs +++ b/crates/ibc/src/core/ics04_channel/timeout.rs @@ -55,7 +55,7 @@ impl TimeoutHeight { } /// Returns a string formatted for an ABCI event attribute value. - pub fn to_attribute_value(self) -> String { + pub fn to_event_attribute_value(self) -> String { match self { TimeoutHeight::At(height) => height.to_string(), TimeoutHeight::Never => "0-0".into(), From 643f2dca3e3e4591f8bf2e20aae7a3972b2b4223 Mon Sep 17 00:00:00 2001 From: Mikhail Zabaluev Date: Thu, 10 Nov 2022 12:17:26 +0200 Subject: [PATCH 07/11] Unpin tendermint version tendermint-rs is now committed to fully following Rust semver conventions. --- crates/ibc/Cargo.toml | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/crates/ibc/Cargo.toml b/crates/ibc/Cargo.toml index 2c2f57ed8..2f88bc249 100644 --- a/crates/ibc/Cargo.toml +++ b/crates/ibc/Cargo.toml @@ -48,19 +48,19 @@ primitive-types = { version = "0.12.0", default-features = false, features = ["s dyn-clone = "1.0.8" [dependencies.tendermint] -version = "=0.26.0" +version = "0.26.0" default-features = false [dependencies.tendermint-proto] -version = "=0.26.0" +version = "0.26.0" default-features = false [dependencies.tendermint-light-client-verifier] -version = "=0.26.0" +version = "0.26.0" default-features = false [dependencies.tendermint-testgen] -version = "=0.26.0" +version = "0.26.0" optional = true default-features = false @@ -70,5 +70,5 @@ tracing-subscriber = { version = "0.3.14", features = ["fmt", "env-filter", "jso test-log = { version = "0.2.10", features = ["trace"] } modelator = "0.4.2" sha2 = { version = "0.10.6" } -tendermint-rpc = { version = "=0.26.0", features = ["http-client", "websocket-client"] } -tendermint-testgen = { version = "=0.26.0" } # Needed for generating (synthetic) light blocks. +tendermint-rpc = { version = "0.26.0", features = ["http-client", "websocket-client"] } +tendermint-testgen = { version = "0.26.0" } # Needed for generating (synthetic) light blocks. From 3f672ec160640325d7ae458437e30231613aaeba Mon Sep 17 00:00:00 2001 From: Mikhail Zabaluev Date: Thu, 10 Nov 2022 12:22:15 +0200 Subject: [PATCH 08/11] Convert ClientIdAttribute like the rest of them --- crates/ibc/src/core/ics02_client/events.rs | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/crates/ibc/src/core/ics02_client/events.rs b/crates/ibc/src/core/ics02_client/events.rs index 9a0fb4cf2..43307e45e 100644 --- a/crates/ibc/src/core/ics02_client/events.rs +++ b/crates/ibc/src/core/ics02_client/events.rs @@ -32,11 +32,7 @@ struct ClientIdAttribute { impl From for abci::EventAttribute { fn from(attr: ClientIdAttribute) -> Self { - Self { - key: CLIENT_ID_ATTRIBUTE_KEY.to_owned(), - value: attr.client_id.into(), - index: false, - } + (CLIENT_ID_ATTRIBUTE_KEY, attr.client_id.as_str()).into() } } From ff5fb1e6dc2bd1bb0565d9ac125fbf2e6ca59e5a Mon Sep 17 00:00:00 2001 From: Mikhail Zabaluev Date: Fri, 11 Nov 2022 13:46:29 +0200 Subject: [PATCH 09/11] Changelog entry for #208 --- .changelog/unreleased/breaking-changes/208-tendermint-0.26.md | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 .changelog/unreleased/breaking-changes/208-tendermint-0.26.md diff --git a/.changelog/unreleased/breaking-changes/208-tendermint-0.26.md b/.changelog/unreleased/breaking-changes/208-tendermint-0.26.md new file mode 100644 index 000000000..a1ada7401 --- /dev/null +++ b/.changelog/unreleased/breaking-changes/208-tendermint-0.26.md @@ -0,0 +1,2 @@ +- Update to tendermint-rs 0.26 and ibc-proto 0.22 + ([#208](https://github.com/cosmos/ibc-rs/issues/208)) \ No newline at end of file From 5eaa6b337e5bd47c83974268d94391ddffb66680 Mon Sep 17 00:00:00 2001 From: Mikhail Zabaluev Date: Wed, 16 Nov 2022 01:03:43 +0200 Subject: [PATCH 10/11] connection events: remove an outdated comment --- crates/ibc/src/core/ics03_connection/events.rs | 7 ------- 1 file changed, 7 deletions(-) diff --git a/crates/ibc/src/core/ics03_connection/events.rs b/crates/ibc/src/core/ics03_connection/events.rs index 91c8f6436..38c6678ca 100644 --- a/crates/ibc/src/core/ics03_connection/events.rs +++ b/crates/ibc/src/core/ics03_connection/events.rs @@ -22,13 +22,6 @@ struct Attributes { } /// Convert attributes to Tendermint ABCI tags -/// -/// # Note -/// The parsing of `Key`s and `Value`s never fails, because the -/// `FromStr` instance of `tendermint::abci::tag::{Key, Value}` -/// is infallible, even if it is not represented in the error type. -/// Once tendermint-rs improves the API of the `Key` and `Value` types, -/// we will be able to remove the `.parse().unwrap()` calls. impl From for Vec { fn from(a: Attributes) -> Self { let conn_id = (CONN_ID_ATTRIBUTE_KEY, a.connection_id.as_str()).into(); From 43b8589fa6211ed50f4025579bcd5912f2becab1 Mon Sep 17 00:00:00 2001 From: Mikhail Zabaluev Date: Wed, 16 Nov 2022 01:07:14 +0200 Subject: [PATCH 11/11] Derive derive_more::Into for ClientId --- crates/ibc/src/core/ics24_host/identifier.rs | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/crates/ibc/src/core/ics24_host/identifier.rs b/crates/ibc/src/core/ics24_host/identifier.rs index d5e562c98..e1add2b56 100644 --- a/crates/ibc/src/core/ics24_host/identifier.rs +++ b/crates/ibc/src/core/ics24_host/identifier.rs @@ -2,6 +2,7 @@ use core::convert::{From, Infallible}; use core::fmt::{Debug, Display, Error as FmtError, Formatter}; use core::str::FromStr; +use derive_more::Into; use serde::{Deserialize, Serialize}; use super::validate::*; @@ -141,7 +142,7 @@ impl From for ChainId { } } -#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize)] +#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize, Into)] pub struct ClientId(String); impl ClientId { @@ -194,12 +195,6 @@ impl Default for ClientId { } } -impl From for String { - fn from(id: ClientId) -> Self { - id.0 - } -} - /// Equality check against string literal (satisfies &ClientId == &str). /// ``` /// use core::str::FromStr;