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 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 8c1cdbd16..be1d1ca95 100644 --- a/ci/no-std-check/Cargo.toml +++ b/ci/no-std-check/Cargo.toml @@ -6,10 +6,10 @@ 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 } +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 } sp-core = { version = "5.0.0", default-features = false, optional = true } sp-io = { version = "5.0.0", default-features = false, optional = true } @@ -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", branch = "main" } diff --git a/crates/ibc/Cargo.toml b/crates/ibc/Cargo.toml index 9c3b19a54..2f88bc249 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 } @@ -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..43307e45e 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,12 +30,9 @@ 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(), - } + (CLIENT_ID_ATTRIBUTE_KEY, attr.client_id.as_str()).into() } } @@ -45,12 +41,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 +52,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 +63,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 +79,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 +119,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 +182,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 +222,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 +261,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..38c6678ca 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; @@ -23,37 +22,25 @@ 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 { +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 +83,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 +125,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 +167,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 +209,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 2c15cc591..e77f03339 100644 --- a/crates/ibc/src/core/ics04_channel/events.rs +++ b/crates/ibc/src/core/ics04_channel/events.rs @@ -3,8 +3,7 @@ mod channel_attributes; mod packet_attributes; -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; @@ -72,18 +71,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(), ], @@ -139,10 +135,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(), @@ -197,10 +193,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(), @@ -254,10 +250,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(), @@ -311,10 +307,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(), @@ -368,10 +364,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(), @@ -437,19 +433,16 @@ 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(), - }, + ev.maybe_counterparty_channel_id.map_or_else( + || (COUNTERPARTY_CHANNEL_ID_ATTRIBUTE_KEY, "").into(), |c| c.into(), ), ev.connection_id.into(), @@ -530,7 +523,7 @@ impl SendPacket { } } -impl TryFrom for AbciEvent { +impl TryFrom for abci::Event { type Error = Error; fn try_from(v: SendPacket) -> Result { @@ -546,8 +539,8 @@ impl TryFrom for AbciEvent { attributes.push(v.channel_ordering.into()); attributes.push(v.src_connection_id.into()); - Ok(AbciEvent { - type_str: IbcEventType::SendPacket.as_str().to_string(), + Ok(abci::Event { + kind: IbcEventType::SendPacket.as_str().to_owned(), attributes, }) } @@ -624,7 +617,7 @@ impl ReceivePacket { } } -impl TryFrom for AbciEvent { +impl TryFrom for abci::Event { type Error = Error; fn try_from(v: ReceivePacket) -> Result { @@ -640,8 +633,8 @@ impl TryFrom for AbciEvent { attributes.push(v.channel_ordering.into()); attributes.push(v.dst_connection_id.into()); - Ok(AbciEvent { - type_str: IbcEventType::ReceivePacket.as_str().to_string(), + Ok(abci::Event { + kind: IbcEventType::ReceivePacket.as_str().to_owned(), attributes, }) } @@ -722,7 +715,7 @@ impl WriteAcknowledgement { } } -impl TryFrom for AbciEvent { +impl TryFrom for abci::Event { type Error = Error; fn try_from(v: WriteAcknowledgement) -> Result { @@ -738,8 +731,8 @@ impl TryFrom for AbciEvent { attributes.append(&mut v.acknowledgement.try_into()?); attributes.push(v.dst_connection_id.into()); - Ok(AbciEvent { - type_str: IbcEventType::WriteAck.as_str().to_string(), + Ok(abci::Event { + kind: IbcEventType::WriteAck.as_str().to_owned(), attributes, }) } @@ -810,12 +803,12 @@ impl AcknowledgePacket { } } -impl TryFrom for AbciEvent { +impl TryFrom for abci::Event { type Error = Error; fn try_from(v: AcknowledgePacket) -> Result { - Ok(AbciEvent { - type_str: IbcEventType::AckPacket.as_str().to_string(), + Ok(abci::Event { + kind: IbcEventType::AckPacket.as_str().to_owned(), attributes: vec![ v.timeout_height.into(), v.timeout_timestamp.into(), @@ -890,12 +883,12 @@ impl TimeoutPacket { } } -impl TryFrom for AbciEvent { +impl TryFrom for abci::Event { type Error = Error; fn try_from(v: TimeoutPacket) -> Result { - Ok(AbciEvent { - type_str: IbcEventType::Timeout.as_str().to_string(), + Ok(abci::Event { + kind: IbcEventType::Timeout.as_str().to_owned(), attributes: vec![ v.timeout_height.into(), v.timeout_timestamp.into(), 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/timeout.rs b/crates/ibc/src/core/ics04_channel/timeout.rs index 7e91d47b2..d72537140 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_event_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/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 { diff --git a/crates/ibc/src/core/ics24_host/identifier.rs b/crates/ibc/src/core/ics24_host/identifier.rs index 531deb2a4..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 { diff --git a/crates/ibc/src/events.rs b/crates/ibc/src/events.rs index 3a109854a..eb6bcb1d1 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}; @@ -233,7 +232,7 @@ pub enum IbcEvent { AppModule(ModuleEvent), } -impl TryFrom for AbciEvent { +impl TryFrom for abci::Event { type Error = Error; fn try_from(event: IbcEvent) -> Result { @@ -298,7 +297,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 { @@ -307,8 +306,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, }) } @@ -335,18 +334,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() } } @@ -376,6 +366,6 @@ pub mod tests { Order::Unordered, ConnectionId::default(), )); - let _ = AbciEvent::try_from(ibc_event); + let _ = abci::Event::try_from(ibc_event); } }