From ad86a766d7ff0dca659549ca60ddc34595143b14 Mon Sep 17 00:00:00 2001 From: Sean Chen Date: Mon, 26 Aug 2024 10:19:17 -0500 Subject: [PATCH 01/73] Define DecodingError in ibc-primitives --- .../ics721-nft-transfer/types/src/data.rs | 8 ++++-- .../ics721-nft-transfer/types/src/error.rs | 19 +++++++++---- .../ics721-nft-transfer/types/src/packet.rs | 24 ++++++++-------- ibc-primitives/src/types/error.rs | 28 +++++++++++++++++++ ibc-primitives/src/types/mod.rs | 2 ++ 5 files changed, 61 insertions(+), 20 deletions(-) create mode 100644 ibc-primitives/src/types/error.rs diff --git a/ibc-apps/ics721-nft-transfer/types/src/data.rs b/ibc-apps/ics721-nft-transfer/types/src/data.rs index 8150545bb..ea0d37126 100644 --- a/ibc-apps/ics721-nft-transfer/types/src/data.rs +++ b/ibc-apps/ics721-nft-transfer/types/src/data.rs @@ -6,7 +6,7 @@ use core::str::FromStr; use base64::prelude::BASE64_STANDARD; #[cfg(feature = "serde")] use base64::Engine; -use ibc_core::primitives::prelude::*; +use ibc_core::primitives::{prelude::*, DecodingError}; use mime::Mime; use crate::error::NftTransferError; @@ -97,8 +97,10 @@ impl FromStr for Ics721Data { type Err = NftTransferError; fn from_str(s: &str) -> Result { - serde_json::from_str(s).map_err(|e| NftTransferError::InvalidJsonData { - description: e.to_string(), + serde_json::from_str(s).map_err(|e| { + NftTransferError::DecodingError(DecodingError::InvalidJson { + description: e.to_string(), + }) }) } } diff --git a/ibc-apps/ics721-nft-transfer/types/src/error.rs b/ibc-apps/ics721-nft-transfer/types/src/error.rs index 626eb9f6d..a94eb0941 100644 --- a/ibc-apps/ics721-nft-transfer/types/src/error.rs +++ b/ibc-apps/ics721-nft-transfer/types/src/error.rs @@ -1,24 +1,26 @@ //! Defines the Non-Fungible Token Transfer (ICS-721) error types. use core::convert::Infallible; -use displaydoc::Display; use ibc_core::channel::types::acknowledgement::StatusValue; use ibc_core::channel::types::channel::Order; use ibc_core::handler::types::error::ContextError; use ibc_core::host::types::error::IdentifierError; use ibc_core::host::types::identifiers::{ChannelId, PortId}; use ibc_core::primitives::prelude::*; +use ibc_core::primitives::DecodingError; + +use displaydoc::Display; #[derive(Display, Debug)] pub enum NftTransferError { /// context error: `{0}` ContextError(ContextError), + /// decoding error: `{0}` + DecodingError(DecodingError), /// invalid identifier: `{0}` InvalidIdentifier(IdentifierError), /// invalid URI: `{0}` InvalidUri(http::uri::InvalidUri), - /// invalid json data: `{description}` - InvalidJsonData { description: String }, /// invalid trace `{0}` InvalidTrace(String), /// missing destination channel `{channel_id}` on port `{port_id}` @@ -57,6 +59,7 @@ impl std::error::Error for NftTransferError { Self::ContextError(e) => Some(e), Self::InvalidUri(e) => Some(e), Self::InvalidIdentifier(e) => Some(e), + Self::DecodingError(e) => Some(e), _ => None, } } @@ -69,17 +72,23 @@ impl From for NftTransferError { } impl From for NftTransferError { - fn from(err: ContextError) -> NftTransferError { + fn from(err: ContextError) -> Self { Self::ContextError(err) } } impl From for NftTransferError { - fn from(err: IdentifierError) -> NftTransferError { + fn from(err: IdentifierError) -> Self { Self::InvalidIdentifier(err) } } +impl From for NftTransferError { + fn from(err: DecodingError) -> Self { + Self::DecodingError(err) + } +} + impl From for StatusValue { fn from(err: NftTransferError) -> Self { StatusValue::new(err.to_string()).expect("error message must not be empty") diff --git a/ibc-apps/ics721-nft-transfer/types/src/packet.rs b/ibc-apps/ics721-nft-transfer/types/src/packet.rs index 027e5fcb1..06009d372 100644 --- a/ibc-apps/ics721-nft-transfer/types/src/packet.rs +++ b/ibc-apps/ics721-nft-transfer/types/src/packet.rs @@ -2,10 +2,10 @@ use base64::prelude::BASE64_STANDARD; use base64::Engine; -use ibc_core::primitives::prelude::*; #[cfg(feature = "serde")] use ibc_core::primitives::serializers; use ibc_core::primitives::Signer; +use ibc_core::primitives::{prelude::*, DecodingError}; use ibc_proto::ibc::applications::nft_transfer::v1::NonFungibleTokenPacketData as RawPacketData; use crate::class::{ClassData, ClassUri, PrefixedClassId}; @@ -128,13 +128,12 @@ impl TryFrom for PacketData { } else { let decoded = BASE64_STANDARD .decode(raw_pkt_data.class_data) - .map_err(|e| NftTransferError::InvalidJsonData { - description: e.to_string(), - })?; - let data_str = - String::from_utf8(decoded).map_err(|e| NftTransferError::InvalidJsonData { + .map_err(|e| DecodingError::InvalidJson { description: e.to_string(), })?; + let data_str = String::from_utf8(decoded).map_err(|e| DecodingError::InvalidUtf8 { + description: e.to_string(), + })?; Some(data_str.parse()?) }; @@ -145,13 +144,14 @@ impl TryFrom for PacketData { .token_data .iter() .map(|data| { - let decoded = BASE64_STANDARD.decode(data).map_err(|e| { - NftTransferError::InvalidJsonData { - description: e.to_string(), - } - })?; + let decoded = + BASE64_STANDARD + .decode(data) + .map_err(|e| DecodingError::InvalidJson { + description: e.to_string(), + })?; let data_str = - String::from_utf8(decoded).map_err(|e| NftTransferError::InvalidJsonData { + String::from_utf8(decoded).map_err(|e| DecodingError::InvalidUtf8 { description: e.to_string(), })?; data_str.parse() diff --git a/ibc-primitives/src/types/error.rs b/ibc-primitives/src/types/error.rs new file mode 100644 index 000000000..a84815c6b --- /dev/null +++ b/ibc-primitives/src/types/error.rs @@ -0,0 +1,28 @@ +//! Foundational error types that are applicable across multiple ibc-rs workspaces. + +use alloc::string::String; + +use displaydoc::Display; + +/// Causes of decoding failures +#[cfg_attr(feature = "serde", derive(serde::Serialize))] +#[derive(Debug, Display)] +pub enum DecodingError { + /// invalid identifier: `{0}` + InvalidIdentifier(String), + /// invalid field: `{0}` + InvalidField(String), + /// invalid JSON data: `{description}` + InvalidJson { description: String }, + /// invalid UTF-8 data: `{description}` + InvalidUtf8 { description: String }, + /// missing field: `{0}` + MissingField(String), + /// mismatched type URLs: expected `{expected}`, actual `{actual}` + MismatchedTypeUrls { expected: String, actual: String }, + /// failed to decode: `{description}` + FailedToDecode { description: String }, +} + +#[cfg(feature = "std")] +impl std::error::Error for DecodingError {} diff --git a/ibc-primitives/src/types/mod.rs b/ibc-primitives/src/types/mod.rs index 8df0d3c40..85849f97c 100644 --- a/ibc-primitives/src/types/mod.rs +++ b/ibc-primitives/src/types/mod.rs @@ -1,5 +1,7 @@ +mod error; mod signer; mod timestamp; +pub use error::*; pub use signer::*; pub use timestamp::*; From 7a2ee6e22094e1c2d431dacb328a085fb6c98e31 Mon Sep 17 00:00:00 2001 From: Sean Chen Date: Mon, 26 Aug 2024 10:57:46 -0500 Subject: [PATCH 02/73] Utilize DecodingError in ics721 --- ibc-apps/ics721-nft-transfer/types/src/class.rs | 6 ++++-- ibc-apps/ics721-nft-transfer/types/src/error.rs | 10 +--------- .../ics721-nft-transfer/types/src/msgs/transfer.rs | 6 +++--- ibc-apps/ics721-nft-transfer/types/src/token.rs | 6 ++++-- ibc-primitives/Cargo.toml | 1 + ibc-primitives/src/types/error.rs | 10 ++++++---- 6 files changed, 19 insertions(+), 20 deletions(-) diff --git a/ibc-apps/ics721-nft-transfer/types/src/class.rs b/ibc-apps/ics721-nft-transfer/types/src/class.rs index 8a7c941e6..4d5a7f63f 100644 --- a/ibc-apps/ics721-nft-transfer/types/src/class.rs +++ b/ibc-apps/ics721-nft-transfer/types/src/class.rs @@ -5,9 +5,9 @@ use core::str::FromStr; use http::Uri; pub use ibc_app_transfer_types::{TracePath, TracePrefix}; use ibc_core::host::types::identifiers::{ChannelId, PortId}; -use ibc_core::primitives::prelude::*; #[cfg(feature = "serde")] use ibc_core::primitives::serializers; +use ibc_core::primitives::{prelude::*, DecodingError}; use ibc_proto::ibc::applications::nft_transfer::v1::ClassTrace as RawClassTrace; use crate::data::Data; @@ -248,7 +248,9 @@ impl FromStr for ClassUri { fn from_str(class_uri: &str) -> Result { match Uri::from_str(class_uri) { Ok(uri) => Ok(Self(uri)), - Err(err) => Err(NftTransferError::InvalidUri(err)), + Err(err) => Err(NftTransferError::DecodingError(DecodingError::InvalidUri( + err, + ))), } } } diff --git a/ibc-apps/ics721-nft-transfer/types/src/error.rs b/ibc-apps/ics721-nft-transfer/types/src/error.rs index a94eb0941..bf78bf405 100644 --- a/ibc-apps/ics721-nft-transfer/types/src/error.rs +++ b/ibc-apps/ics721-nft-transfer/types/src/error.rs @@ -17,10 +17,6 @@ pub enum NftTransferError { ContextError(ContextError), /// decoding error: `{0}` DecodingError(DecodingError), - /// invalid identifier: `{0}` - InvalidIdentifier(IdentifierError), - /// invalid URI: `{0}` - InvalidUri(http::uri::InvalidUri), /// invalid trace `{0}` InvalidTrace(String), /// missing destination channel `{channel_id}` on port `{port_id}` @@ -44,8 +40,6 @@ pub enum NftTransferError { FailedToDeserializeAck, /// failed to parse account ID FailedToParseAccount, - /// failed to decode raw msg: `{description}` - FailedToDecodeRawMsg { description: String }, /// channel cannot be closed UnsupportedClosedChannel, /// unknown msg type: `{0}` @@ -57,8 +51,6 @@ impl std::error::Error for NftTransferError { fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { match &self { Self::ContextError(e) => Some(e), - Self::InvalidUri(e) => Some(e), - Self::InvalidIdentifier(e) => Some(e), Self::DecodingError(e) => Some(e), _ => None, } @@ -79,7 +71,7 @@ impl From for NftTransferError { impl From for NftTransferError { fn from(err: IdentifierError) -> Self { - Self::InvalidIdentifier(err) + Self::DecodingError(DecodingError::InvalidIdentifier(err.to_string())) } } diff --git a/ibc-apps/ics721-nft-transfer/types/src/msgs/transfer.rs b/ibc-apps/ics721-nft-transfer/types/src/msgs/transfer.rs index 499d7d448..d6ef7bec5 100644 --- a/ibc-apps/ics721-nft-transfer/types/src/msgs/transfer.rs +++ b/ibc-apps/ics721-nft-transfer/types/src/msgs/transfer.rs @@ -4,7 +4,7 @@ use ibc_core::channel::types::error::PacketError; use ibc_core::channel::types::timeout::{TimeoutHeight, TimeoutTimestamp}; use ibc_core::handler::types::error::ContextError; use ibc_core::host::types::identifiers::{ChannelId, PortId}; -use ibc_core::primitives::prelude::*; +use ibc_core::primitives::{prelude::*, DecodingError}; use ibc_proto::google::protobuf::Any; use ibc_proto::ibc::applications::nft_transfer::v1::MsgTransfer as RawMsgTransfer; use ibc_proto::Protobuf; @@ -123,9 +123,9 @@ impl TryFrom for MsgTransfer { fn try_from(raw: Any) -> Result { match raw.type_url.as_str() { TYPE_URL => MsgTransfer::decode_vec(&raw.value).map_err(|e| { - NftTransferError::FailedToDecodeRawMsg { + NftTransferError::DecodingError(DecodingError::FailedToDecodeRawMsg { description: e.to_string(), - } + }) }), _ => Err(NftTransferError::UnknownMsgType(raw.type_url)), } diff --git a/ibc-apps/ics721-nft-transfer/types/src/token.rs b/ibc-apps/ics721-nft-transfer/types/src/token.rs index fa11e93a1..31d245374 100644 --- a/ibc-apps/ics721-nft-transfer/types/src/token.rs +++ b/ibc-apps/ics721-nft-transfer/types/src/token.rs @@ -3,9 +3,9 @@ use core::fmt::{self, Display}; use core::str::FromStr; use http::Uri; -use ibc_core::primitives::prelude::*; #[cfg(feature = "serde")] use ibc_core::primitives::serializers; +use ibc_core::primitives::{prelude::*, DecodingError}; use crate::data::Data; use crate::error::NftTransferError; @@ -182,7 +182,9 @@ impl FromStr for TokenUri { fn from_str(token_uri: &str) -> Result { match Uri::from_str(token_uri) { Ok(uri) => Ok(Self(uri)), - Err(err) => Err(NftTransferError::InvalidUri(err)), + Err(err) => Err(NftTransferError::DecodingError(DecodingError::InvalidUri( + err, + ))), } } } diff --git a/ibc-primitives/Cargo.toml b/ibc-primitives/Cargo.toml index 2c56cd6de..0e419381e 100644 --- a/ibc-primitives/Cargo.toml +++ b/ibc-primitives/Cargo.toml @@ -23,6 +23,7 @@ all-features = true borsh = { workspace = true, optional = true } derive_more = { workspace = true } displaydoc = { workspace = true } +http = { version = "1.1.0" } prost = { workspace = true } schemars = { workspace = true, optional = true } serde = { workspace = true, optional = true } diff --git a/ibc-primitives/src/types/error.rs b/ibc-primitives/src/types/error.rs index a84815c6b..37d4201f5 100644 --- a/ibc-primitives/src/types/error.rs +++ b/ibc-primitives/src/types/error.rs @@ -3,12 +3,12 @@ use alloc::string::String; use displaydoc::Display; +use http::uri::InvalidUri; /// Causes of decoding failures -#[cfg_attr(feature = "serde", derive(serde::Serialize))] #[derive(Debug, Display)] pub enum DecodingError { - /// invalid identifier: `{0}` + /// invalid identifier error: `{0}` InvalidIdentifier(String), /// invalid field: `{0}` InvalidField(String), @@ -16,12 +16,14 @@ pub enum DecodingError { InvalidJson { description: String }, /// invalid UTF-8 data: `{description}` InvalidUtf8 { description: String }, + /// invalid URI: `{0}` + InvalidUri(InvalidUri), /// missing field: `{0}` MissingField(String), /// mismatched type URLs: expected `{expected}`, actual `{actual}` MismatchedTypeUrls { expected: String, actual: String }, - /// failed to decode: `{description}` - FailedToDecode { description: String }, + /// failed to decode raw msg: `{description}` + FailedToDecodeRawMsg { description: String }, } #[cfg(feature = "std")] From a48cec25b7ae3f7eb25b584ae166e2c1fece9430 Mon Sep 17 00:00:00 2001 From: Sean Chen Date: Mon, 26 Aug 2024 11:25:34 -0500 Subject: [PATCH 03/73] Start using DecodingError in ClientError --- .../ics07-tendermint/types/src/header.rs | 17 +++++++++++------ ibc-core/ics02-client/types/src/error.rs | 6 +++++- ibc-primitives/src/types/error.rs | 4 ++-- 3 files changed, 18 insertions(+), 9 deletions(-) diff --git a/ibc-clients/ics07-tendermint/types/src/header.rs b/ibc-clients/ics07-tendermint/types/src/header.rs index 72fc83333..f3313ab5b 100644 --- a/ibc-clients/ics07-tendermint/types/src/header.rs +++ b/ibc-clients/ics07-tendermint/types/src/header.rs @@ -6,8 +6,8 @@ use core::str::FromStr; use ibc_core_client_types::error::ClientError; use ibc_core_client_types::Height; use ibc_core_host_types::identifiers::ChainId; -use ibc_primitives::prelude::*; use ibc_primitives::Timestamp; +use ibc_primitives::{prelude::*, DecodingError}; use ibc_proto::google::protobuf::Any; use ibc_proto::ibc::lightclients::tendermint::v1::Header as RawHeader; use ibc_proto::Protobuf; @@ -199,15 +199,20 @@ impl TryFrom for Header { type Error = ClientError; fn try_from(raw: Any) -> Result { - fn decode_header(value: &[u8]) -> Result { - let header = Protobuf::::decode(value).map_err(|e| ClientError::Other { - description: e.to_string(), + fn decode_header(value: &[u8]) -> Result { + let header = Protobuf::::decode(value).map_err(|e| { + DecodingError::FailedToDecodeRawValue { + description: e.to_string(), + } })?; Ok(header) } match raw.type_url.as_str() { - TENDERMINT_HEADER_TYPE_URL => decode_header(&raw.value), - _ => Err(ClientError::InvalidHeaderType(raw.type_url)), + TENDERMINT_HEADER_TYPE_URL => decode_header(&raw.value).map_err(ClientError::Decoding), + _ => Err(ClientError::Decoding(DecodingError::MismatchedTypeUrls { + expected: TENDERMINT_HEADER_TYPE_URL.to_string(), + actual: raw.type_url.to_string(), + })), } } } diff --git a/ibc-core/ics02-client/types/src/error.rs b/ibc-core/ics02-client/types/src/error.rs index 9b16557ad..f3abf6b1f 100644 --- a/ibc-core/ics02-client/types/src/error.rs +++ b/ibc-core/ics02-client/types/src/error.rs @@ -7,7 +7,7 @@ use ibc_core_commitment_types::error::CommitmentError; use ibc_core_host_types::error::IdentifierError; use ibc_core_host_types::identifiers::ClientId; use ibc_primitives::prelude::*; -use ibc_primitives::Timestamp; +use ibc_primitives::{DecodingError, Timestamp}; use super::status::Status; use crate::height::Height; @@ -17,6 +17,8 @@ use crate::height::Height; pub enum ClientError { /// upgrade client error: `{0}` Upgrade(UpgradeClientError), + /// decoding error: `{0}` + Decoding(DecodingError), /// invalid client status: `{0}` InvalidStatus(Status), /// invalid trust threshold: `{numerator}`/`{denominator}` @@ -29,6 +31,7 @@ pub enum ClientError { InvalidHeaderType(String), /// invalid update client message InvalidUpdateClientMessage, + // TODO(seanchen1991): Should this be removed in favor of DecodingError::InvalidIdentifier? /// invalid client identifier: `{0}` InvalidClientIdentifier(IdentifierError), /// invalid raw header: `{description}` @@ -114,6 +117,7 @@ impl std::error::Error for ClientError { match &self { Self::InvalidClientIdentifier(e) => Some(e), Self::FailedICS23Verification(e) => Some(e), + Self::Decoding(e) => Some(e), _ => None, } } diff --git a/ibc-primitives/src/types/error.rs b/ibc-primitives/src/types/error.rs index 37d4201f5..21273cc8e 100644 --- a/ibc-primitives/src/types/error.rs +++ b/ibc-primitives/src/types/error.rs @@ -22,8 +22,8 @@ pub enum DecodingError { MissingField(String), /// mismatched type URLs: expected `{expected}`, actual `{actual}` MismatchedTypeUrls { expected: String, actual: String }, - /// failed to decode raw msg: `{description}` - FailedToDecodeRawMsg { description: String }, + /// failed to decode a raw value: `{description}` + FailedToDecodeRawValue { description: String }, } #[cfg(feature = "std")] From 1bc70348938aa316df11e235af9b04ce9117e9b9 Mon Sep 17 00:00:00 2001 From: Sean Chen Date: Mon, 26 Aug 2024 14:42:39 -0500 Subject: [PATCH 04/73] Define StatusError type --- .../ics721-nft-transfer/types/src/class.rs | 4 +-- .../ics721-nft-transfer/types/src/data.rs | 2 +- .../ics721-nft-transfer/types/src/error.rs | 8 ++--- .../types/src/msgs/transfer.rs | 2 +- .../ics721-nft-transfer/types/src/token.rs | 4 +-- .../types/src/consensus_state.rs | 18 +++++----- .../ics07-tendermint/types/src/header.rs | 6 +--- .../ics08-wasm/types/src/consensus_state.rs | 20 +++++------ ibc-core/ics02-client/types/src/error.rs | 8 +++-- ibc-core/ics02-client/types/src/status.rs | 33 +++++++++++++------ ibc-core/ics25-handler/types/src/error.rs | 1 + ibc-primitives/Cargo.toml | 3 +- ibc-primitives/src/types/error.rs | 16 +++++++-- .../testapp/ibc/clients/mock/client_state.rs | 17 ++++++---- .../src/testapp/ibc/clients/mock/header.rs | 11 +++---- .../testapp/ibc/clients/mock/misbehaviour.rs | 17 ++++++---- 16 files changed, 99 insertions(+), 71 deletions(-) diff --git a/ibc-apps/ics721-nft-transfer/types/src/class.rs b/ibc-apps/ics721-nft-transfer/types/src/class.rs index 4d5a7f63f..98ae0a765 100644 --- a/ibc-apps/ics721-nft-transfer/types/src/class.rs +++ b/ibc-apps/ics721-nft-transfer/types/src/class.rs @@ -248,9 +248,7 @@ impl FromStr for ClassUri { fn from_str(class_uri: &str) -> Result { match Uri::from_str(class_uri) { Ok(uri) => Ok(Self(uri)), - Err(err) => Err(NftTransferError::DecodingError(DecodingError::InvalidUri( - err, - ))), + Err(err) => Err(NftTransferError::Decoding(DecodingError::InvalidUri(err))), } } } diff --git a/ibc-apps/ics721-nft-transfer/types/src/data.rs b/ibc-apps/ics721-nft-transfer/types/src/data.rs index ea0d37126..8b91d3025 100644 --- a/ibc-apps/ics721-nft-transfer/types/src/data.rs +++ b/ibc-apps/ics721-nft-transfer/types/src/data.rs @@ -98,7 +98,7 @@ impl FromStr for Ics721Data { fn from_str(s: &str) -> Result { serde_json::from_str(s).map_err(|e| { - NftTransferError::DecodingError(DecodingError::InvalidJson { + NftTransferError::Decoding(DecodingError::InvalidJson { description: e.to_string(), }) }) diff --git a/ibc-apps/ics721-nft-transfer/types/src/error.rs b/ibc-apps/ics721-nft-transfer/types/src/error.rs index bf78bf405..637f13f1d 100644 --- a/ibc-apps/ics721-nft-transfer/types/src/error.rs +++ b/ibc-apps/ics721-nft-transfer/types/src/error.rs @@ -16,7 +16,7 @@ pub enum NftTransferError { /// context error: `{0}` ContextError(ContextError), /// decoding error: `{0}` - DecodingError(DecodingError), + Decoding(DecodingError), /// invalid trace `{0}` InvalidTrace(String), /// missing destination channel `{channel_id}` on port `{port_id}` @@ -51,7 +51,7 @@ impl std::error::Error for NftTransferError { fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { match &self { Self::ContextError(e) => Some(e), - Self::DecodingError(e) => Some(e), + Self::Decoding(e) => Some(e), _ => None, } } @@ -71,13 +71,13 @@ impl From for NftTransferError { impl From for NftTransferError { fn from(err: IdentifierError) -> Self { - Self::DecodingError(DecodingError::InvalidIdentifier(err.to_string())) + Self::Decoding(DecodingError::InvalidIdentifier(err.to_string())) } } impl From for NftTransferError { fn from(err: DecodingError) -> Self { - Self::DecodingError(err) + Self::Decoding(err) } } diff --git a/ibc-apps/ics721-nft-transfer/types/src/msgs/transfer.rs b/ibc-apps/ics721-nft-transfer/types/src/msgs/transfer.rs index d6ef7bec5..c98aceb5f 100644 --- a/ibc-apps/ics721-nft-transfer/types/src/msgs/transfer.rs +++ b/ibc-apps/ics721-nft-transfer/types/src/msgs/transfer.rs @@ -123,7 +123,7 @@ impl TryFrom for MsgTransfer { fn try_from(raw: Any) -> Result { match raw.type_url.as_str() { TYPE_URL => MsgTransfer::decode_vec(&raw.value).map_err(|e| { - NftTransferError::DecodingError(DecodingError::FailedToDecodeRawMsg { + NftTransferError::Decoding(DecodingError::FailedToDecodeProto { description: e.to_string(), }) }), diff --git a/ibc-apps/ics721-nft-transfer/types/src/token.rs b/ibc-apps/ics721-nft-transfer/types/src/token.rs index 31d245374..374b3e54b 100644 --- a/ibc-apps/ics721-nft-transfer/types/src/token.rs +++ b/ibc-apps/ics721-nft-transfer/types/src/token.rs @@ -182,9 +182,7 @@ impl FromStr for TokenUri { fn from_str(token_uri: &str) -> Result { match Uri::from_str(token_uri) { Ok(uri) => Ok(Self(uri)), - Err(err) => Err(NftTransferError::DecodingError(DecodingError::InvalidUri( - err, - ))), + Err(err) => Err(NftTransferError::Decoding(DecodingError::InvalidUri(err))), } } } diff --git a/ibc-clients/ics07-tendermint/types/src/consensus_state.rs b/ibc-clients/ics07-tendermint/types/src/consensus_state.rs index ec66fb264..e12fe66dc 100644 --- a/ibc-clients/ics07-tendermint/types/src/consensus_state.rs +++ b/ibc-clients/ics07-tendermint/types/src/consensus_state.rs @@ -2,7 +2,7 @@ use ibc_core_client_types::error::ClientError; use ibc_core_commitment_types::commitment::CommitmentRoot; -use ibc_primitives::prelude::*; +use ibc_primitives::{prelude::*, DecodingError}; use ibc_proto::google::protobuf::Any; use ibc_proto::ibc::lightclients::tendermint::v1::ConsensusState as RawConsensusState; use ibc_proto::Protobuf; @@ -107,17 +107,19 @@ impl TryFrom for ConsensusState { type Error = ClientError; fn try_from(raw: Any) -> Result { - fn decode_consensus_state(value: &[u8]) -> Result { - let client_state = - Protobuf::::decode(value).map_err(|e| ClientError::Other { - description: e.to_string(), - })?; + fn decode_consensus_state(value: &[u8]) -> Result { + let client_state = Protobuf::::decode(value)?; Ok(client_state) } match raw.type_url.as_str() { - TENDERMINT_CONSENSUS_STATE_TYPE_URL => decode_consensus_state(&raw.value), - _ => Err(ClientError::InvalidConsensusStateType(raw.type_url)), + TENDERMINT_CONSENSUS_STATE_TYPE_URL => { + decode_consensus_state(&raw.value).map_err(ClientError::Decoding) + } + _ => Err(ClientError::Decoding(DecodingError::MismatchedTypeUrls { + expected: TENDERMINT_CONSENSUS_STATE_TYPE_URL.to_string(), + actual: raw.type_url.to_string(), + })), } } } diff --git a/ibc-clients/ics07-tendermint/types/src/header.rs b/ibc-clients/ics07-tendermint/types/src/header.rs index f3313ab5b..15dd6315a 100644 --- a/ibc-clients/ics07-tendermint/types/src/header.rs +++ b/ibc-clients/ics07-tendermint/types/src/header.rs @@ -200,11 +200,7 @@ impl TryFrom for Header { fn try_from(raw: Any) -> Result { fn decode_header(value: &[u8]) -> Result { - let header = Protobuf::::decode(value).map_err(|e| { - DecodingError::FailedToDecodeRawValue { - description: e.to_string(), - } - })?; + let header = Protobuf::::decode(value)?; Ok(header) } match raw.type_url.as_str() { diff --git a/ibc-clients/ics08-wasm/types/src/consensus_state.rs b/ibc-clients/ics08-wasm/types/src/consensus_state.rs index 597cc4e87..9d50f7177 100644 --- a/ibc-clients/ics08-wasm/types/src/consensus_state.rs +++ b/ibc-clients/ics08-wasm/types/src/consensus_state.rs @@ -1,8 +1,8 @@ //! Defines the consensus state type for the ICS-08 Wasm light client. use ibc_core_client::types::error::ClientError; -use ibc_primitives::prelude::*; use ibc_primitives::proto::{Any, Protobuf}; +use ibc_primitives::{prelude::*, DecodingError}; use ibc_proto::ibc::lightclients::wasm::v1::ConsensusState as RawConsensusState; #[cfg(feature = "serde")] @@ -57,18 +57,18 @@ impl TryFrom for ConsensusState { type Error = ClientError; fn try_from(any: Any) -> Result { - fn decode_consensus_state(value: &[u8]) -> Result { - let consensus_state = - Protobuf::::decode(value).map_err(|e| ClientError::Other { - description: e.to_string(), - })?; + fn decode_consensus_state(value: &[u8]) -> Result { + let consensus_state = Protobuf::::decode(value)?; Ok(consensus_state) } match any.type_url.as_str() { - WASM_CONSENSUS_STATE_TYPE_URL => decode_consensus_state(&any.value), - _ => Err(ClientError::Other { - description: "type_url does not match".into(), - }), + WASM_CONSENSUS_STATE_TYPE_URL => { + decode_consensus_state(&any.value).map_err(ClientError::Decoding) + } + _ => Err(ClientError::Decoding(DecodingError::MismatchedTypeUrls { + expected: WASM_CONSENSUS_STATE_TYPE_URL.to_string(), + actual: any.type_url.to_string(), + })), } } } diff --git a/ibc-core/ics02-client/types/src/error.rs b/ibc-core/ics02-client/types/src/error.rs index f3abf6b1f..d4ea1a9e5 100644 --- a/ibc-core/ics02-client/types/src/error.rs +++ b/ibc-core/ics02-client/types/src/error.rs @@ -27,8 +27,6 @@ pub enum ClientError { InvalidClientStateType(String), /// invalid client consensus state type: `{0}` InvalidConsensusStateType(String), - /// invalid header type: `{0}` - InvalidHeaderType(String), /// invalid update client message InvalidUpdateClientMessage, // TODO(seanchen1991): Should this be removed in favor of DecodingError::InvalidIdentifier? @@ -111,6 +109,12 @@ impl From for ClientError { } } +impl From for ClientError { + fn from(e: DecodingError) -> Self { + Self::Decoding(e) + } +} + #[cfg(feature = "std")] impl std::error::Error for ClientError { fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { diff --git a/ibc-core/ics02-client/types/src/status.rs b/ibc-core/ics02-client/types/src/status.rs index 5fe9b9e0a..03833dcad 100644 --- a/ibc-core/ics02-client/types/src/status.rs +++ b/ibc-core/ics02-client/types/src/status.rs @@ -1,10 +1,9 @@ use core::fmt::{Debug, Display, Formatter}; use core::str::FromStr; +use displaydoc::Display; use ibc_primitives::prelude::*; -use crate::error::ClientError; - /// `UpdateKind` represents the 2 ways that a client can be updated /// in IBC: either through a `MsgUpdateClient`, or a `MsgSubmitMisbehaviour`. #[derive(Clone, Debug, PartialEq, Eq)] @@ -33,6 +32,15 @@ pub enum Status { Unauthorized, } +/// Encapsulates Status-related errors +#[derive(Debug, Display)] +pub enum StatusError { + /// invalid client status: `{0}` + InvalidStatus(String), + /// mismatched client status: expected `{expected}`, actual `{actual}` + MismatchedStatus { expected: Status, actual: Status }, +} + impl Status { pub fn is_active(&self) -> bool { *self == Status::Active @@ -47,18 +55,25 @@ impl Status { } /// Checks whether the status is active; returns `Err` if not. - pub fn verify_is_active(&self) -> Result<(), ClientError> { + pub fn verify_is_active(&self) -> Result<(), StatusError> { match self { Self::Active => Ok(()), - &status => Err(ClientError::InvalidStatus(status)), + &status => Err(StatusError::MismatchedStatus { + expected: Status::Active, + actual: status, + }), } } /// Checks whether the client is either frozen or expired; returns `Err` if not. - pub fn verify_is_inactive(&self) -> Result<(), ClientError> { + pub fn verify_is_inactive(&self) -> Result<(), StatusError> { match self { Self::Frozen | Self::Expired => Ok(()), - &status => Err(ClientError::InvalidStatus(status)), + &status => Err(StatusError::MismatchedStatus { + // `Status::Expired` is also allowed in this context + expected: Status::Frozen, + actual: status, + }), } } } @@ -70,7 +85,7 @@ impl Display for Status { } impl FromStr for Status { - type Err = ClientError; + type Err = StatusError; fn from_str(s: &str) -> Result { match s { @@ -78,9 +93,7 @@ impl FromStr for Status { "FROZEN" => Ok(Status::Frozen), "EXPIRED" => Ok(Status::Expired), "UNAUTHORIZED" => Ok(Status::Unauthorized), - _ => Err(ClientError::Other { - description: format!("invalid status string: {s}"), - }), + _ => Err(StatusError::InvalidStatus(s.to_string())), } } } diff --git a/ibc-core/ics25-handler/types/src/error.rs b/ibc-core/ics25-handler/types/src/error.rs index 5bea4b54d..84bc0b939 100644 --- a/ibc-core/ics25-handler/types/src/error.rs +++ b/ibc-core/ics25-handler/types/src/error.rs @@ -23,6 +23,7 @@ pub enum ContextError { RouterError(RouterError), } +// TODO(seanchen1991): Figure out how to remove this impl From for ClientError { fn from(context_error: ContextError) -> Self { match context_error { diff --git a/ibc-primitives/Cargo.toml b/ibc-primitives/Cargo.toml index 0e419381e..e4a5d723d 100644 --- a/ibc-primitives/Cargo.toml +++ b/ibc-primitives/Cargo.toml @@ -33,7 +33,8 @@ time = { version = ">=0.3.0, <0.3.37", default-features = false } ibc-proto = { workspace = true } # cosmos dependencies -tendermint = { workspace = true } +tendermint = { workspace = true } +tendermint-proto = { workspace = true } # parity dependencies parity-scale-codec = { workspace = true, optional = true } diff --git a/ibc-primitives/src/types/error.rs b/ibc-primitives/src/types/error.rs index 21273cc8e..b8aa169e5 100644 --- a/ibc-primitives/src/types/error.rs +++ b/ibc-primitives/src/types/error.rs @@ -1,10 +1,12 @@ //! Foundational error types that are applicable across multiple ibc-rs workspaces. -use alloc::string::String; +use alloc::string::{String, ToString}; use displaydoc::Display; use http::uri::InvalidUri; +use tendermint_proto::Error as ProtoError; + /// Causes of decoding failures #[derive(Debug, Display)] pub enum DecodingError { @@ -22,8 +24,16 @@ pub enum DecodingError { MissingField(String), /// mismatched type URLs: expected `{expected}`, actual `{actual}` MismatchedTypeUrls { expected: String, actual: String }, - /// failed to decode a raw value: `{description}` - FailedToDecodeRawValue { description: String }, + /// failed to decode proto value: `{description}` + FailedToDecodeProto { description: String }, +} + +impl From for DecodingError { + fn from(e: ProtoError) -> Self { + Self::FailedToDecodeProto { + description: e.to_string(), + } + } } #[cfg(feature = "std")] diff --git a/ibc-testkit/src/testapp/ibc/clients/mock/client_state.rs b/ibc-testkit/src/testapp/ibc/clients/mock/client_state.rs index 780392577..01566b1b8 100644 --- a/ibc-testkit/src/testapp/ibc/clients/mock/client_state.rs +++ b/ibc-testkit/src/testapp/ibc/clients/mock/client_state.rs @@ -14,6 +14,7 @@ use ibc::core::host::types::path::{ClientConsensusStatePath, ClientStatePath, Pa use ibc::core::primitives::prelude::*; use ibc::core::primitives::Timestamp; use ibc::primitives::proto::{Any, Protobuf}; +use ibc::primitives::DecodingError; use crate::testapp::ibc::clients::mock::client_state::client_type as mock_client_type; use crate::testapp::ibc::clients::mock::consensus_state::MockConsensusState; @@ -127,16 +128,18 @@ impl TryFrom for MockClientState { type Error = ClientError; fn try_from(raw: Any) -> Result { - fn decode_client_state(value: &[u8]) -> Result { - let client_state = - Protobuf::::decode(value).map_err(|e| ClientError::Other { - description: e.to_string(), - })?; + fn decode_client_state(value: &[u8]) -> Result { + let client_state = Protobuf::::decode(value)?; Ok(client_state) } match raw.type_url.as_str() { - MOCK_CLIENT_STATE_TYPE_URL => decode_client_state(&raw.value), - _ => Err(ClientError::InvalidClientStateType(raw.type_url)), + MOCK_CLIENT_STATE_TYPE_URL => { + decode_client_state(&raw.value).map_err(ClientError::Decoding) + } + _ => Err(ClientError::Decoding(DecodingError::MismatchedTypeUrls { + expected: MOCK_CLIENT_STATE_TYPE_URL.to_string(), + actual: raw.type_url.to_string(), + })), } } } diff --git a/ibc-testkit/src/testapp/ibc/clients/mock/header.rs b/ibc-testkit/src/testapp/ibc/clients/mock/header.rs index fac7bf00c..f943476ce 100644 --- a/ibc-testkit/src/testapp/ibc/clients/mock/header.rs +++ b/ibc-testkit/src/testapp/ibc/clients/mock/header.rs @@ -95,12 +95,11 @@ impl TryFrom for MockHeader { fn try_from(raw: Any) -> Result { match raw.type_url.as_str() { - MOCK_HEADER_TYPE_URL => Ok(Protobuf::::decode_vec(&raw.value).map_err( - |e| ClientError::InvalidRawHeader { - description: e.to_string(), - }, - )?), - _ => Err(ClientError::InvalidHeaderType(raw.type_url)), + MOCK_HEADER_TYPE_URL => Ok(Protobuf::::decode_vec(&raw.value)?), + _ => Err(ClientError::Decoding(DecodingError::MismatchedTypeUrls { + expected: MOCK_HEADER_TYPE_URL.to_string(), + actual: raw.type_url.to_string(), + })), } } } diff --git a/ibc-testkit/src/testapp/ibc/clients/mock/misbehaviour.rs b/ibc-testkit/src/testapp/ibc/clients/mock/misbehaviour.rs index e07c310a1..24d355ebd 100644 --- a/ibc-testkit/src/testapp/ibc/clients/mock/misbehaviour.rs +++ b/ibc-testkit/src/testapp/ibc/clients/mock/misbehaviour.rs @@ -2,6 +2,7 @@ use ibc::core::client::types::error::ClientError; use ibc::core::host::types::identifiers::ClientId; use ibc::core::primitives::prelude::*; use ibc::primitives::proto::{Any, Protobuf}; +use ibc::primitives::DecodingError; use crate::testapp::ibc::clients::mock::header::MockHeader; use crate::testapp::ibc::clients::mock::proto::Misbehaviour as RawMisbehaviour; @@ -52,16 +53,18 @@ impl TryFrom for Misbehaviour { type Error = ClientError; fn try_from(raw: Any) -> Result { - fn decode_misbehaviour(value: &[u8]) -> Result { - let raw_misbehaviour = - Protobuf::::decode(value).map_err(|e| ClientError::Other { - description: e.to_string(), - })?; + fn decode_misbehaviour(value: &[u8]) -> Result { + let raw_misbehaviour = Protobuf::::decode(value)?; Ok(raw_misbehaviour) } match raw.type_url.as_str() { - MOCK_MISBEHAVIOUR_TYPE_URL => decode_misbehaviour(&raw.value), - _ => Err(ClientError::InvalidMisbehaviourType(raw.type_url)), + MOCK_MISBEHAVIOUR_TYPE_URL => { + decode_misbehaviour(&raw.value).map_err(ClientError::Decoding) + } + _ => Err(ClientError::Decoding(DecodingError::MismatchedTypeUrls { + expected: MOCK_MISBEHAVIOUR_TYPE_URL.to_string(), + actual: raw.type_url.to_string(), + })), } } } From 811d2d5235338a0f7ddf3249ede3fb22cc715f8d Mon Sep 17 00:00:00 2001 From: Sean Chen Date: Mon, 26 Aug 2024 15:45:37 -0500 Subject: [PATCH 05/73] Wire up StatusError --- .../src/client_state/common.rs | 6 ++++-- .../types/src/consensus_state.rs | 2 +- .../ics07-tendermint/types/src/header.rs | 2 +- .../types/src/misbehaviour.rs | 18 ++++++++++-------- .../ics02-client/src/handler/create_client.rs | 4 ++-- .../src/handler/recover_client.rs | 6 ++++-- .../ics02-client/src/handler/update_client.rs | 3 ++- .../src/handler/upgrade_client.rs | 3 ++- ibc-core/ics02-client/types/src/error.rs | 13 ++++++++++--- ibc-core/ics02-client/types/src/status.rs | 18 +++++++----------- .../src/handler/conn_open_ack.rs | 4 +++- .../src/handler/conn_open_confirm.rs | 5 ++++- .../src/handler/conn_open_init.rs | 4 +++- .../src/handler/conn_open_try.rs | 4 +++- .../src/handler/acknowledgement.rs | 5 ++++- .../src/handler/chan_close_confirm.rs | 5 ++++- .../src/handler/chan_close_init.rs | 4 +++- .../src/handler/chan_open_ack.rs | 5 ++++- .../src/handler/chan_open_confirm.rs | 5 ++++- .../src/handler/chan_open_init.rs | 4 +++- .../src/handler/chan_open_try.rs | 4 +++- .../ics04-channel/src/handler/recv_packet.rs | 4 +++- .../ics04-channel/src/handler/send_packet.rs | 4 +++- ibc-core/ics04-channel/src/handler/timeout.rs | 4 +++- .../src/handler/timeout_on_close.rs | 4 +++- .../cosmos/src/validate_self_client.rs | 4 ++-- .../testapp/ibc/clients/mock/client_state.rs | 2 +- .../ibc/clients/mock/consensus_state.rs | 19 ++++++++++--------- .../src/testapp/ibc/clients/mock/header.rs | 2 +- .../testapp/ibc/clients/mock/misbehaviour.rs | 2 +- ibc-testkit/src/testapp/ibc/core/core_ctx.rs | 2 +- 31 files changed, 109 insertions(+), 62 deletions(-) diff --git a/ibc-clients/ics07-tendermint/src/client_state/common.rs b/ibc-clients/ics07-tendermint/src/client_state/common.rs index 66ac52aec..3671e6bd6 100644 --- a/ibc-clients/ics07-tendermint/src/client_state/common.rs +++ b/ibc-clients/ics07-tendermint/src/client_state/common.rs @@ -4,7 +4,7 @@ use ibc_client_tendermint_types::{client_type as tm_client_type, ClientState as use ibc_core_client::context::client_state::ClientStateCommon; use ibc_core_client::context::consensus_state::ConsensusState; use ibc_core_client::types::error::{ClientError, UpgradeClientError}; -use ibc_core_client::types::{Height, Status}; +use ibc_core_client::types::{Height, Status, StatusError}; use ibc_core_commitment_types::commitment::{ CommitmentPrefix, CommitmentProofBytes, CommitmentRoot, }; @@ -166,7 +166,9 @@ pub fn verify_consensus_state( }; if consensus_state_status(&tm_consensus_state, host_timestamp, trusting_period)?.is_expired() { - return Err(ClientError::InvalidStatus(Status::Expired)); + return Err(ClientError::Status(StatusError::UnexpectedStatus( + Status::Expired, + ))); } Ok(()) diff --git a/ibc-clients/ics07-tendermint/types/src/consensus_state.rs b/ibc-clients/ics07-tendermint/types/src/consensus_state.rs index e12fe66dc..82c6b2c7a 100644 --- a/ibc-clients/ics07-tendermint/types/src/consensus_state.rs +++ b/ibc-clients/ics07-tendermint/types/src/consensus_state.rs @@ -118,7 +118,7 @@ impl TryFrom for ConsensusState { } _ => Err(ClientError::Decoding(DecodingError::MismatchedTypeUrls { expected: TENDERMINT_CONSENSUS_STATE_TYPE_URL.to_string(), - actual: raw.type_url.to_string(), + actual: raw.type_url, })), } } diff --git a/ibc-clients/ics07-tendermint/types/src/header.rs b/ibc-clients/ics07-tendermint/types/src/header.rs index 15dd6315a..e15044653 100644 --- a/ibc-clients/ics07-tendermint/types/src/header.rs +++ b/ibc-clients/ics07-tendermint/types/src/header.rs @@ -207,7 +207,7 @@ impl TryFrom for Header { TENDERMINT_HEADER_TYPE_URL => decode_header(&raw.value).map_err(ClientError::Decoding), _ => Err(ClientError::Decoding(DecodingError::MismatchedTypeUrls { expected: TENDERMINT_HEADER_TYPE_URL.to_string(), - actual: raw.type_url.to_string(), + actual: raw.type_url, })), } } diff --git a/ibc-clients/ics07-tendermint/types/src/misbehaviour.rs b/ibc-clients/ics07-tendermint/types/src/misbehaviour.rs index dc35a34ec..fd314b6eb 100644 --- a/ibc-clients/ics07-tendermint/types/src/misbehaviour.rs +++ b/ibc-clients/ics07-tendermint/types/src/misbehaviour.rs @@ -2,7 +2,7 @@ use ibc_core_client_types::error::ClientError; use ibc_core_host_types::identifiers::ClientId; -use ibc_primitives::prelude::*; +use ibc_primitives::{prelude::*, DecodingError}; use ibc_proto::google::protobuf::Any; use ibc_proto::ibc::lightclients::tendermint::v1::Misbehaviour as RawMisbehaviour; use ibc_proto::Protobuf; @@ -114,16 +114,18 @@ impl TryFrom for Misbehaviour { type Error = ClientError; fn try_from(raw: Any) -> Result { - fn decode_misbehaviour(value: &[u8]) -> Result { - let misbehaviour = - Protobuf::::decode(value).map_err(|e| ClientError::Other { - description: e.to_string(), - })?; + fn decode_misbehaviour(value: &[u8]) -> Result { + let misbehaviour = Protobuf::::decode(value)?; Ok(misbehaviour) } match raw.type_url.as_str() { - TENDERMINT_MISBEHAVIOUR_TYPE_URL => decode_misbehaviour(&raw.value), - _ => Err(ClientError::InvalidMisbehaviourType(raw.type_url)), + TENDERMINT_MISBEHAVIOUR_TYPE_URL => { + decode_misbehaviour(&raw.value).map_err(ClientError::Decoding) + } + _ => Err(ClientError::Decoding(DecodingError::MismatchedTypeUrls { + expected: TENDERMINT_MISBEHAVIOUR_TYPE_URL.to_string(), + actual: raw.type_url, + })), } } } diff --git a/ibc-core/ics02-client/src/handler/create_client.rs b/ibc-core/ics02-client/src/handler/create_client.rs index 263f8ffa4..d775ddf02 100644 --- a/ibc-core/ics02-client/src/handler/create_client.rs +++ b/ibc-core/ics02-client/src/handler/create_client.rs @@ -4,7 +4,7 @@ use ibc_core_client_context::prelude::*; use ibc_core_client_types::error::ClientError; use ibc_core_client_types::events::CreateClient; use ibc_core_client_types::msgs::MsgCreateClient; -use ibc_core_client_types::Status; +use ibc_core_client_types::{Status, StatusError}; use ibc_core_handler_types::error::ContextError; use ibc_core_handler_types::events::{IbcEvent, MessageEvent}; use ibc_core_host::{ClientStateMut, ClientStateRef, ExecutionContext, ValidationContext}; @@ -36,7 +36,7 @@ where let status = client_state.status(client_val_ctx, &client_id)?; if status.is_frozen() { - return Err(ClientError::InvalidStatus(Status::Frozen).into()); + return Err(ClientError::Status(StatusError::UnexpectedStatus(Status::Frozen)).into()); }; let host_timestamp = ctx.host_timestamp()?; diff --git a/ibc-core/ics02-client/src/handler/recover_client.rs b/ibc-core/ics02-client/src/handler/recover_client.rs index 7994edab3..8c24bbbce 100644 --- a/ibc-core/ics02-client/src/handler/recover_client.rs +++ b/ibc-core/ics02-client/src/handler/recover_client.rs @@ -39,12 +39,14 @@ where substitute_client_state .status(ctx.get_client_validation_context(), &substitute_client_id)? - .verify_is_active()?; + .verify_is_active() + .map_err(ClientError::Status)?; // TODO(seanchen1991): Why is this `map_err` necessary? // Verify that the subject client is inactive, i.e., that it is either frozen or expired subject_client_state .status(ctx.get_client_validation_context(), &subject_client_id)? - .verify_is_inactive()?; + .verify_is_inactive() + .map_err(ClientError::Status)?; // Check that the subject client state and substitute client states match, i.e., that // all their respective client state parameters match except for frozen height, latest diff --git a/ibc-core/ics02-client/src/handler/update_client.rs b/ibc-core/ics02-client/src/handler/update_client.rs index 66ce95ce1..f67debcbd 100644 --- a/ibc-core/ics02-client/src/handler/update_client.rs +++ b/ibc-core/ics02-client/src/handler/update_client.rs @@ -26,7 +26,8 @@ where client_state .status(client_val_ctx, &client_id)? - .verify_is_active()?; + .verify_is_active() + .map_err(ClientError::Status)?; let client_message = msg.client_message(); diff --git a/ibc-core/ics02-client/src/handler/upgrade_client.rs b/ibc-core/ics02-client/src/handler/upgrade_client.rs index 7dce4cdaa..c79cbcb93 100644 --- a/ibc-core/ics02-client/src/handler/upgrade_client.rs +++ b/ibc-core/ics02-client/src/handler/upgrade_client.rs @@ -28,7 +28,8 @@ where // Check if the client is active. old_client_state .status(client_val_ctx, &client_id)? - .verify_is_active()?; + .verify_is_active() + .map_err(ClientError::Status)?; // Read the latest consensus state from the host chain store. let old_client_cons_state_path = ClientConsensusStatePath::new( diff --git a/ibc-core/ics02-client/types/src/error.rs b/ibc-core/ics02-client/types/src/error.rs index d4ea1a9e5..aaa085331 100644 --- a/ibc-core/ics02-client/types/src/error.rs +++ b/ibc-core/ics02-client/types/src/error.rs @@ -9,8 +9,8 @@ use ibc_core_host_types::identifiers::ClientId; use ibc_primitives::prelude::*; use ibc_primitives::{DecodingError, Timestamp}; -use super::status::Status; use crate::height::Height; +use crate::StatusError; /// Encodes all the possible client errors #[derive(Debug, Display)] @@ -19,8 +19,8 @@ pub enum ClientError { Upgrade(UpgradeClientError), /// decoding error: `{0}` Decoding(DecodingError), - /// invalid client status: `{0}` - InvalidStatus(Status), + /// client status error: `{0}` + Status(StatusError), /// invalid trust threshold: `{numerator}`/`{denominator}` InvalidTrustThreshold { numerator: u64, denominator: u64 }, /// invalid client state type: `{0}` @@ -115,12 +115,19 @@ impl From for ClientError { } } +impl From for ClientError { + fn from(e: StatusError) -> Self { + Self::Status(e) + } +} + #[cfg(feature = "std")] impl std::error::Error for ClientError { fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { match &self { Self::InvalidClientIdentifier(e) => Some(e), Self::FailedICS23Verification(e) => Some(e), + Self::Status(e) => Some(e), Self::Decoding(e) => Some(e), _ => None, } diff --git a/ibc-core/ics02-client/types/src/status.rs b/ibc-core/ics02-client/types/src/status.rs index 03833dcad..e63df1793 100644 --- a/ibc-core/ics02-client/types/src/status.rs +++ b/ibc-core/ics02-client/types/src/status.rs @@ -37,8 +37,8 @@ pub enum Status { pub enum StatusError { /// invalid client status: `{0}` InvalidStatus(String), - /// mismatched client status: expected `{expected}`, actual `{actual}` - MismatchedStatus { expected: Status, actual: Status }, + /// unexpected status `{0}` found + UnexpectedStatus(Status), } impl Status { @@ -58,10 +58,7 @@ impl Status { pub fn verify_is_active(&self) -> Result<(), StatusError> { match self { Self::Active => Ok(()), - &status => Err(StatusError::MismatchedStatus { - expected: Status::Active, - actual: status, - }), + &status => Err(StatusError::UnexpectedStatus(status)), } } @@ -69,11 +66,7 @@ impl Status { pub fn verify_is_inactive(&self) -> Result<(), StatusError> { match self { Self::Frozen | Self::Expired => Ok(()), - &status => Err(StatusError::MismatchedStatus { - // `Status::Expired` is also allowed in this context - expected: Status::Frozen, - actual: status, - }), + &status => Err(StatusError::UnexpectedStatus(status)), } } } @@ -97,3 +90,6 @@ impl FromStr for Status { } } } + +#[cfg(feature = "std")] +impl std::error::Error for StatusError {} diff --git a/ibc-core/ics03-connection/src/handler/conn_open_ack.rs b/ibc-core/ics03-connection/src/handler/conn_open_ack.rs index a061b3f06..05bdc0fcb 100644 --- a/ibc-core/ics03-connection/src/handler/conn_open_ack.rs +++ b/ibc-core/ics03-connection/src/handler/conn_open_ack.rs @@ -67,7 +67,9 @@ where client_state_of_b_on_a .status(client_val_ctx_a, vars.client_id_on_a())? - .verify_is_active()?; + .verify_is_active() + .map_err(ClientError::Status)?; + client_state_of_b_on_a.validate_proof_height(msg.proofs_height_on_b)?; let client_cons_state_path_on_a = ClientConsensusStatePath::new( diff --git a/ibc-core/ics03-connection/src/handler/conn_open_confirm.rs b/ibc-core/ics03-connection/src/handler/conn_open_confirm.rs index e1751cfc9..2dd0105f3 100644 --- a/ibc-core/ics03-connection/src/handler/conn_open_confirm.rs +++ b/ibc-core/ics03-connection/src/handler/conn_open_confirm.rs @@ -1,6 +1,7 @@ //! Protocol logic specific to processing ICS3 messages of type `MsgConnectionOpenConfirm`. use ibc_core_client::context::prelude::*; +use ibc_core_client::types::error::ClientError; use ibc_core_connection_types::error::ConnectionError; use ibc_core_connection_types::events::OpenConfirm; use ibc_core_connection_types::msgs::MsgConnectionOpenConfirm; @@ -47,7 +48,9 @@ where client_state_of_a_on_b .status(client_val_ctx_b, client_id_on_b)? - .verify_is_active()?; + .verify_is_active() + .map_err(ClientError::Status)?; + client_state_of_a_on_b.validate_proof_height(msg.proof_height_on_a)?; let client_cons_state_path_on_b = ClientConsensusStatePath::new( diff --git a/ibc-core/ics03-connection/src/handler/conn_open_init.rs b/ibc-core/ics03-connection/src/handler/conn_open_init.rs index 8d4286616..ad6c8de4f 100644 --- a/ibc-core/ics03-connection/src/handler/conn_open_init.rs +++ b/ibc-core/ics03-connection/src/handler/conn_open_init.rs @@ -1,5 +1,6 @@ //! Protocol logic specific to ICS3 messages of type `MsgConnectionOpenInit`. use ibc_core_client::context::prelude::*; +use ibc_core_client::types::error::ClientError; use ibc_core_connection_types::events::OpenInit; use ibc_core_connection_types::msgs::MsgConnectionOpenInit; use ibc_core_connection_types::{ConnectionEnd, Counterparty, State}; @@ -23,7 +24,8 @@ where client_state_of_b_on_a .status(client_val_ctx_a, &msg.client_id_on_a)? - .verify_is_active()?; + .verify_is_active() + .map_err(ClientError::Status)?; if let Some(version) = msg.version { version.verify_is_supported(&ctx_a.get_compatible_versions())?; diff --git a/ibc-core/ics03-connection/src/handler/conn_open_try.rs b/ibc-core/ics03-connection/src/handler/conn_open_try.rs index 34bb18ae0..606a55a49 100644 --- a/ibc-core/ics03-connection/src/handler/conn_open_try.rs +++ b/ibc-core/ics03-connection/src/handler/conn_open_try.rs @@ -67,7 +67,9 @@ where client_state_of_a_on_b .status(client_val_ctx_b, &msg.client_id_on_b)? - .verify_is_active()?; + .verify_is_active() + .map_err(ClientError::Status)?; + client_state_of_a_on_b.validate_proof_height(msg.proofs_height_on_a)?; let client_cons_state_path_on_b = ClientConsensusStatePath::new( diff --git a/ibc-core/ics04-channel/src/handler/acknowledgement.rs b/ibc-core/ics04-channel/src/handler/acknowledgement.rs index 68bc43128..659befb1b 100644 --- a/ibc-core/ics04-channel/src/handler/acknowledgement.rs +++ b/ibc-core/ics04-channel/src/handler/acknowledgement.rs @@ -4,6 +4,7 @@ use ibc_core_channel_types::error::{ChannelError, PacketError}; use ibc_core_channel_types::events::AcknowledgePacket; use ibc_core_channel_types::msgs::MsgAcknowledgement; use ibc_core_client::context::prelude::*; +use ibc_core_client::types::error::ClientError; use ibc_core_connection::delay::verify_conn_delay_passed; use ibc_core_connection::types::State as ConnectionState; use ibc_core_handler_types::error::ContextError; @@ -176,7 +177,9 @@ where client_state_of_b_on_a .status(ctx_a.get_client_validation_context(), client_id_on_a)? - .verify_is_active()?; + .verify_is_active() + .map_err(ClientError::Status)?; + client_state_of_b_on_a.validate_proof_height(msg.proof_height_on_b)?; let client_cons_state_path_on_a = ClientConsensusStatePath::new( diff --git a/ibc-core/ics04-channel/src/handler/chan_close_confirm.rs b/ibc-core/ics04-channel/src/handler/chan_close_confirm.rs index 4f2dc0293..25f8ebbc9 100644 --- a/ibc-core/ics04-channel/src/handler/chan_close_confirm.rs +++ b/ibc-core/ics04-channel/src/handler/chan_close_confirm.rs @@ -5,6 +5,7 @@ use ibc_core_channel_types::error::ChannelError; use ibc_core_channel_types::events::CloseConfirm; use ibc_core_channel_types::msgs::MsgChannelCloseConfirm; use ibc_core_client::context::prelude::*; +use ibc_core_client::types::error::ClientError; use ibc_core_connection::types::State as ConnectionState; use ibc_core_connection_types::error::ConnectionError; use ibc_core_handler_types::error::ContextError; @@ -113,7 +114,9 @@ where client_state_of_a_on_b .status(ctx_b.get_client_validation_context(), client_id_on_b)? - .verify_is_active()?; + .verify_is_active() + .map_err(ClientError::Status)?; + client_state_of_a_on_b.validate_proof_height(msg.proof_height_on_a)?; let client_cons_state_path_on_b = ClientConsensusStatePath::new( diff --git a/ibc-core/ics04-channel/src/handler/chan_close_init.rs b/ibc-core/ics04-channel/src/handler/chan_close_init.rs index 6bdab73f6..dbe604ef6 100644 --- a/ibc-core/ics04-channel/src/handler/chan_close_init.rs +++ b/ibc-core/ics04-channel/src/handler/chan_close_init.rs @@ -4,6 +4,7 @@ use ibc_core_channel_types::error::ChannelError; use ibc_core_channel_types::events::CloseInit; use ibc_core_channel_types::msgs::MsgChannelCloseInit; use ibc_core_client::context::prelude::*; +use ibc_core_client::types::error::ClientError; use ibc_core_connection::types::State as ConnectionState; use ibc_core_handler_types::error::ContextError; use ibc_core_handler_types::events::{IbcEvent, MessageEvent}; @@ -110,7 +111,8 @@ where let client_state_of_b_on_a = client_val_ctx_a.client_state(client_id_on_a)?; client_state_of_b_on_a .status(ctx_a.get_client_validation_context(), client_id_on_a)? - .verify_is_active()?; + .verify_is_active() + .map_err(ClientError::Status)?; Ok(()) } diff --git a/ibc-core/ics04-channel/src/handler/chan_open_ack.rs b/ibc-core/ics04-channel/src/handler/chan_open_ack.rs index 9369733a0..34d43c33a 100644 --- a/ibc-core/ics04-channel/src/handler/chan_open_ack.rs +++ b/ibc-core/ics04-channel/src/handler/chan_open_ack.rs @@ -4,6 +4,7 @@ use ibc_core_channel_types::error::ChannelError; use ibc_core_channel_types::events::OpenAck; use ibc_core_channel_types::msgs::MsgChannelOpenAck; use ibc_core_client::context::prelude::*; +use ibc_core_client::types::error::ClientError; use ibc_core_connection::types::State as ConnectionState; use ibc_core_connection_types::error::ConnectionError; use ibc_core_handler_types::error::ContextError; @@ -114,7 +115,9 @@ where client_state_of_b_on_a .status(ctx_a.get_client_validation_context(), client_id_on_a)? - .verify_is_active()?; + .verify_is_active() + .map_err(ClientError::Status)?; + client_state_of_b_on_a.validate_proof_height(msg.proof_height_on_b)?; let client_cons_state_path_on_a = ClientConsensusStatePath::new( diff --git a/ibc-core/ics04-channel/src/handler/chan_open_confirm.rs b/ibc-core/ics04-channel/src/handler/chan_open_confirm.rs index 9d375a295..a3d05dddf 100644 --- a/ibc-core/ics04-channel/src/handler/chan_open_confirm.rs +++ b/ibc-core/ics04-channel/src/handler/chan_open_confirm.rs @@ -5,6 +5,7 @@ use ibc_core_channel_types::error::ChannelError; use ibc_core_channel_types::events::OpenConfirm; use ibc_core_channel_types::msgs::MsgChannelOpenConfirm; use ibc_core_client::context::prelude::*; +use ibc_core_client::types::error::ClientError; use ibc_core_connection::types::State as ConnectionState; use ibc_core_connection_types::error::ConnectionError; use ibc_core_handler_types::error::ContextError; @@ -118,7 +119,9 @@ where client_state_of_a_on_b .status(ctx_b.get_client_validation_context(), client_id_on_b)? - .verify_is_active()?; + .verify_is_active() + .map_err(ClientError::Status)?; + client_state_of_a_on_b.validate_proof_height(msg.proof_height_on_a)?; let client_cons_state_path_on_b = ClientConsensusStatePath::new( diff --git a/ibc-core/ics04-channel/src/handler/chan_open_init.rs b/ibc-core/ics04-channel/src/handler/chan_open_init.rs index 58a161d0b..a8b917cf9 100644 --- a/ibc-core/ics04-channel/src/handler/chan_open_init.rs +++ b/ibc-core/ics04-channel/src/handler/chan_open_init.rs @@ -4,6 +4,7 @@ use ibc_core_channel_types::channel::{ChannelEnd, Counterparty, State}; use ibc_core_channel_types::events::OpenInit; use ibc_core_channel_types::msgs::MsgChannelOpenInit; use ibc_core_client::context::prelude::*; +use ibc_core_client::types::error::ClientError; use ibc_core_handler_types::error::ContextError; use ibc_core_handler_types::events::{IbcEvent, MessageEvent}; use ibc_core_host::types::identifiers::ChannelId; @@ -125,7 +126,8 @@ where client_state_of_b_on_a .status(ctx_a.get_client_validation_context(), client_id_on_a)? - .verify_is_active()?; + .verify_is_active() + .map_err(ClientError::Status)?; let conn_version = conn_end_on_a.versions(); diff --git a/ibc-core/ics04-channel/src/handler/chan_open_try.rs b/ibc-core/ics04-channel/src/handler/chan_open_try.rs index 48138ce69..54807c1be 100644 --- a/ibc-core/ics04-channel/src/handler/chan_open_try.rs +++ b/ibc-core/ics04-channel/src/handler/chan_open_try.rs @@ -5,6 +5,7 @@ use ibc_core_channel_types::error::ChannelError; use ibc_core_channel_types::events::OpenTry; use ibc_core_channel_types::msgs::MsgChannelOpenTry; use ibc_core_client::context::prelude::*; +use ibc_core_client::types::error::ClientError; use ibc_core_connection::types::State as ConnectionState; use ibc_core_connection_types::error::ConnectionError; use ibc_core_handler_types::error::ContextError; @@ -140,7 +141,8 @@ where client_state_of_a_on_b .status(ctx_b.get_client_validation_context(), client_id_on_b)? - .verify_is_active()?; + .verify_is_active() + .map_err(ClientError::Status)?; client_state_of_a_on_b.validate_proof_height(msg.proof_height_on_a)?; diff --git a/ibc-core/ics04-channel/src/handler/recv_packet.rs b/ibc-core/ics04-channel/src/handler/recv_packet.rs index f3229f493..e9f7b7101 100644 --- a/ibc-core/ics04-channel/src/handler/recv_packet.rs +++ b/ibc-core/ics04-channel/src/handler/recv_packet.rs @@ -5,6 +5,7 @@ use ibc_core_channel_types::events::{ReceivePacket, WriteAcknowledgement}; use ibc_core_channel_types::msgs::MsgRecvPacket; use ibc_core_channel_types::packet::Receipt; use ibc_core_client::context::prelude::*; +use ibc_core_client::types::error::ClientError; use ibc_core_connection::delay::verify_conn_delay_passed; use ibc_core_connection::types::State as ConnectionState; use ibc_core_handler_types::error::ContextError; @@ -186,7 +187,8 @@ where client_state_of_a_on_b .status(ctx_b.get_client_validation_context(), client_id_on_b)? - .verify_is_active()?; + .verify_is_active() + .map_err(ClientError::Status)?; client_state_of_a_on_b.validate_proof_height(msg.proof_height_on_a)?; diff --git a/ibc-core/ics04-channel/src/handler/send_packet.rs b/ibc-core/ics04-channel/src/handler/send_packet.rs index 6680bf6fb..714242383 100644 --- a/ibc-core/ics04-channel/src/handler/send_packet.rs +++ b/ibc-core/ics04-channel/src/handler/send_packet.rs @@ -4,6 +4,7 @@ use ibc_core_channel_types::error::PacketError; use ibc_core_channel_types::events::SendPacket; use ibc_core_channel_types::packet::Packet; use ibc_core_client::context::prelude::*; +use ibc_core_client::types::error::ClientError; use ibc_core_handler_types::error::ContextError; use ibc_core_handler_types::events::{IbcEvent, MessageEvent}; use ibc_core_host::types::path::{ @@ -59,7 +60,8 @@ pub fn send_packet_validate( client_state_of_b_on_a .status(ctx_a.get_client_validation_context(), client_id_on_a)? - .verify_is_active()?; + .verify_is_active() + .map_err(ClientError::Status)?; let latest_height_on_a = client_state_of_b_on_a.latest_height(); diff --git a/ibc-core/ics04-channel/src/handler/timeout.rs b/ibc-core/ics04-channel/src/handler/timeout.rs index 9ce98bc0a..5963f810a 100644 --- a/ibc-core/ics04-channel/src/handler/timeout.rs +++ b/ibc-core/ics04-channel/src/handler/timeout.rs @@ -4,6 +4,7 @@ use ibc_core_channel_types::error::{ChannelError, PacketError}; use ibc_core_channel_types::events::{ChannelClosed, TimeoutPacket}; use ibc_core_channel_types::msgs::{MsgTimeout, MsgTimeoutOnClose}; use ibc_core_client::context::prelude::*; +use ibc_core_client::types::error::ClientError; use ibc_core_connection::delay::verify_conn_delay_passed; use ibc_core_handler_types::error::ContextError; use ibc_core_handler_types::events::{IbcEvent, MessageEvent}; @@ -186,7 +187,8 @@ where client_state_of_b_on_a .status(ctx_a.get_client_validation_context(), client_id_on_a)? - .verify_is_active()?; + .verify_is_active() + .map_err(ClientError::Status)?; client_state_of_b_on_a.validate_proof_height(msg.proof_height_on_b)?; diff --git a/ibc-core/ics04-channel/src/handler/timeout_on_close.rs b/ibc-core/ics04-channel/src/handler/timeout_on_close.rs index c52225f81..eda55002a 100644 --- a/ibc-core/ics04-channel/src/handler/timeout_on_close.rs +++ b/ibc-core/ics04-channel/src/handler/timeout_on_close.rs @@ -3,6 +3,7 @@ use ibc_core_channel_types::commitment::compute_packet_commitment; use ibc_core_channel_types::error::{ChannelError, PacketError}; use ibc_core_channel_types::msgs::MsgTimeoutOnClose; use ibc_core_client::context::prelude::*; +use ibc_core_client::types::error::ClientError; use ibc_core_connection::delay::verify_conn_delay_passed; use ibc_core_connection::types::error::ConnectionError; use ibc_core_handler_types::error::ContextError; @@ -70,7 +71,8 @@ where client_state_of_b_on_a .status(ctx_a.get_client_validation_context(), client_id_on_a)? - .verify_is_active()?; + .verify_is_active() + .map_err(ClientError::Status)?; client_state_of_b_on_a.validate_proof_height(msg.proof_height_on_b)?; diff --git a/ibc-core/ics24-host/cosmos/src/validate_self_client.rs b/ibc-core/ics24-host/cosmos/src/validate_self_client.rs index d2f2d2eba..446c3ebbf 100644 --- a/ibc-core/ics24-host/cosmos/src/validate_self_client.rs +++ b/ibc-core/ics24-host/cosmos/src/validate_self_client.rs @@ -2,7 +2,7 @@ use core::time::Duration; use ibc_client_tendermint::types::ClientState as TmClientState; use ibc_core_client_types::error::ClientError; -use ibc_core_client_types::{Height, Status}; +use ibc_core_client_types::{Height, Status, StatusError}; use ibc_core_commitment_types::specs::ProofSpecs; use ibc_core_connection_types::error::ConnectionError; use ibc_core_handler_types::error::ContextError; @@ -25,7 +25,7 @@ pub trait ValidateSelfClientContext { .map_err(ClientError::from)?; if client_state_of_host_on_counterparty.is_frozen() { - return Err(ClientError::InvalidStatus(Status::Frozen).into()); + return Err(ClientError::Status(StatusError::UnexpectedStatus(Status::Frozen)).into()); } let self_chain_id = self.chain_id(); diff --git a/ibc-testkit/src/testapp/ibc/clients/mock/client_state.rs b/ibc-testkit/src/testapp/ibc/clients/mock/client_state.rs index 01566b1b8..d8f9685ff 100644 --- a/ibc-testkit/src/testapp/ibc/clients/mock/client_state.rs +++ b/ibc-testkit/src/testapp/ibc/clients/mock/client_state.rs @@ -138,7 +138,7 @@ impl TryFrom for MockClientState { } _ => Err(ClientError::Decoding(DecodingError::MismatchedTypeUrls { expected: MOCK_CLIENT_STATE_TYPE_URL.to_string(), - actual: raw.type_url.to_string(), + actual: raw.type_url, })), } } diff --git a/ibc-testkit/src/testapp/ibc/clients/mock/consensus_state.rs b/ibc-testkit/src/testapp/ibc/clients/mock/consensus_state.rs index 96273f780..1121e5147 100644 --- a/ibc-testkit/src/testapp/ibc/clients/mock/consensus_state.rs +++ b/ibc-testkit/src/testapp/ibc/clients/mock/consensus_state.rs @@ -4,6 +4,7 @@ use ibc::core::commitment_types::commitment::CommitmentRoot; use ibc::core::primitives::prelude::*; use ibc::core::primitives::Timestamp; use ibc::primitives::proto::{Any, Protobuf}; +use ibc::primitives::DecodingError; use crate::testapp::ibc::clients::mock::header::MockHeader; use crate::testapp::ibc::clients::mock::proto::ConsensusState as RawMockConsensusState; @@ -64,18 +65,18 @@ impl TryFrom for MockConsensusState { type Error = ClientError; fn try_from(raw: Any) -> Result { - fn decode_consensus_state(value: &[u8]) -> Result { - let mock_consensus_state = - Protobuf::::decode(value).map_err(|e| { - ClientError::Other { - description: e.to_string(), - } - })?; + fn decode_consensus_state(value: &[u8]) -> Result { + let mock_consensus_state = Protobuf::::decode(value)?; Ok(mock_consensus_state) } match raw.type_url.as_str() { - MOCK_CONSENSUS_STATE_TYPE_URL => decode_consensus_state(&raw.value), - _ => Err(ClientError::InvalidConsensusStateType(raw.type_url)), + MOCK_CONSENSUS_STATE_TYPE_URL => { + decode_consensus_state(&raw.value).map_err(ClientError::Decoding) + } + _ => Err(ClientError::Decoding(DecodingError::MismatchedTypeUrls { + expected: MOCK_CONSENSUS_STATE_TYPE_URL.to_string(), + actual: raw.type_url, + })), } } } diff --git a/ibc-testkit/src/testapp/ibc/clients/mock/header.rs b/ibc-testkit/src/testapp/ibc/clients/mock/header.rs index f943476ce..e95e4685f 100644 --- a/ibc-testkit/src/testapp/ibc/clients/mock/header.rs +++ b/ibc-testkit/src/testapp/ibc/clients/mock/header.rs @@ -98,7 +98,7 @@ impl TryFrom for MockHeader { MOCK_HEADER_TYPE_URL => Ok(Protobuf::::decode_vec(&raw.value)?), _ => Err(ClientError::Decoding(DecodingError::MismatchedTypeUrls { expected: MOCK_HEADER_TYPE_URL.to_string(), - actual: raw.type_url.to_string(), + actual: raw.type_url, })), } } diff --git a/ibc-testkit/src/testapp/ibc/clients/mock/misbehaviour.rs b/ibc-testkit/src/testapp/ibc/clients/mock/misbehaviour.rs index 24d355ebd..af8434b25 100644 --- a/ibc-testkit/src/testapp/ibc/clients/mock/misbehaviour.rs +++ b/ibc-testkit/src/testapp/ibc/clients/mock/misbehaviour.rs @@ -63,7 +63,7 @@ impl TryFrom for Misbehaviour { } _ => Err(ClientError::Decoding(DecodingError::MismatchedTypeUrls { expected: MOCK_MISBEHAVIOUR_TYPE_URL.to_string(), - actual: raw.type_url.to_string(), + actual: raw.type_url, })), } } diff --git a/ibc-testkit/src/testapp/ibc/core/core_ctx.rs b/ibc-testkit/src/testapp/ibc/core/core_ctx.rs index 5f572cf6b..b01dfa3f7 100644 --- a/ibc-testkit/src/testapp/ibc/core/core_ctx.rs +++ b/ibc-testkit/src/testapp/ibc/core/core_ctx.rs @@ -80,7 +80,7 @@ where client_state_of_host_on_counterparty: Self::HostClientState, ) -> Result<(), ContextError> { if client_state_of_host_on_counterparty.is_frozen() { - return Err(ClientError::InvalidStatus(Status::Frozen).into()); + return Err(ClientError::Status(StatusError::UnexpectedStatus(Status::Frozen)).into()); } let latest_height = self.host_height()?; From 56105ad6a6f1bafc1e42118d09b721fc97e46e54 Mon Sep 17 00:00:00 2001 From: Sean Chen Date: Tue, 27 Aug 2024 12:46:42 -0500 Subject: [PATCH 06/73] Wiring up DecodingError --- ibc-apps/ics20-transfer/types/src/error.rs | 20 ++++++++-------- .../ics20-transfer/types/src/msgs/transfer.rs | 16 +++++++------ .../ics721-nft-transfer/types/src/error.rs | 2 -- .../types/src/msgs/transfer.rs | 14 ++++++----- .../ics08-wasm/types/src/client_state.rs | 24 +++++++++---------- ibc-clients/ics08-wasm/types/src/error.rs | 7 +++--- ibc-core/ics02-client/types/src/error.rs | 12 ++-------- .../cosmos/src/upgrade_proposal/plan.rs | 24 ++++++++----------- ibc-primitives/src/types/error.rs | 10 ++++---- 9 files changed, 58 insertions(+), 71 deletions(-) diff --git a/ibc-apps/ics20-transfer/types/src/error.rs b/ibc-apps/ics20-transfer/types/src/error.rs index 7924e2609..38c9581a7 100644 --- a/ibc-apps/ics20-transfer/types/src/error.rs +++ b/ibc-apps/ics20-transfer/types/src/error.rs @@ -8,12 +8,15 @@ use ibc_core::handler::types::error::ContextError; use ibc_core::host::types::error::IdentifierError; use ibc_core::host::types::identifiers::{ChannelId, PortId}; use ibc_core::primitives::prelude::*; +use ibc_core::primitives::DecodingError; use uint::FromDecStrErr; #[derive(Display, Debug)] pub enum TokenTransferError { /// context error: `{0}` ContextError(ContextError), + /// decoding error: `{0}` + Decoding(DecodingError), /// invalid identifier: `{0}` InvalidIdentifier(IdentifierError), /// invalid trace: `{0}` @@ -41,14 +44,10 @@ pub enum TokenTransferError { // to a host-relevant error /// failed to parse account ID FailedToParseAccount, - /// failed to decode raw msg: `{description}` - FailedToDecodeRawMsg { description: String }, /// channel cannot be closed UnsupportedClosedChannel, /// empty base denomination EmptyBaseDenom, - /// unknown msg type: `{0}` - UnknownMsgType(String), } #[cfg(feature = "std")] @@ -58,6 +57,7 @@ impl std::error::Error for TokenTransferError { Self::ContextError(e) => Some(e), Self::InvalidIdentifier(e) => Some(e), Self::InvalidAmount(e) => Some(e), + Self::Decoding(e) => Some(e), _ => None, } } @@ -70,19 +70,19 @@ impl From for TokenTransferError { } impl From for TokenTransferError { - fn from(err: ContextError) -> TokenTransferError { - Self::ContextError(err) + fn from(e: ContextError) -> Self { + Self::ContextError(e) } } impl From for TokenTransferError { - fn from(err: IdentifierError) -> TokenTransferError { - Self::InvalidIdentifier(err) + fn from(e: IdentifierError) -> Self { + Self::InvalidIdentifier(e) } } impl From for StatusValue { - fn from(err: TokenTransferError) -> Self { - StatusValue::new(err.to_string()).expect("error message must not be empty") + fn from(e: TokenTransferError) -> Self { + StatusValue::new(e.to_string()).expect("error message must not be empty") } } diff --git a/ibc-apps/ics20-transfer/types/src/msgs/transfer.rs b/ibc-apps/ics20-transfer/types/src/msgs/transfer.rs index 048ea956c..d10d538a3 100644 --- a/ibc-apps/ics20-transfer/types/src/msgs/transfer.rs +++ b/ibc-apps/ics20-transfer/types/src/msgs/transfer.rs @@ -4,7 +4,7 @@ use ibc_core::channel::types::error::PacketError; use ibc_core::channel::types::timeout::{TimeoutHeight, TimeoutTimestamp}; use ibc_core::handler::types::error::ContextError; use ibc_core::host::types::identifiers::{ChannelId, PortId}; -use ibc_core::primitives::prelude::*; +use ibc_core::primitives::{prelude::*, DecodingError}; use ibc_proto::google::protobuf::Any; use ibc_proto::ibc::applications::transfer::v1::MsgTransfer as RawMsgTransfer; use ibc_proto::Protobuf; @@ -104,12 +104,14 @@ impl TryFrom for MsgTransfer { fn try_from(raw: Any) -> Result { match raw.type_url.as_str() { - TYPE_URL => MsgTransfer::decode_vec(&raw.value).map_err(|e| { - TokenTransferError::FailedToDecodeRawMsg { - description: e.to_string(), - } - }), - _ => Err(TokenTransferError::UnknownMsgType(raw.type_url)), + TYPE_URL => MsgTransfer::decode_vec(&raw.value) + .map_err(|e| TokenTransferError::Decoding(DecodingError::FailedToDecodeProto(e))), + _ => Err(TokenTransferError::Decoding( + DecodingError::MismatchedTypeUrls { + expected: TYPE_URL.to_string(), + actual: raw.type_url, + }, + )), } } } diff --git a/ibc-apps/ics721-nft-transfer/types/src/error.rs b/ibc-apps/ics721-nft-transfer/types/src/error.rs index 637f13f1d..744665564 100644 --- a/ibc-apps/ics721-nft-transfer/types/src/error.rs +++ b/ibc-apps/ics721-nft-transfer/types/src/error.rs @@ -42,8 +42,6 @@ pub enum NftTransferError { FailedToParseAccount, /// channel cannot be closed UnsupportedClosedChannel, - /// unknown msg type: `{0}` - UnknownMsgType(String), } #[cfg(feature = "std")] diff --git a/ibc-apps/ics721-nft-transfer/types/src/msgs/transfer.rs b/ibc-apps/ics721-nft-transfer/types/src/msgs/transfer.rs index c98aceb5f..56be700ca 100644 --- a/ibc-apps/ics721-nft-transfer/types/src/msgs/transfer.rs +++ b/ibc-apps/ics721-nft-transfer/types/src/msgs/transfer.rs @@ -122,12 +122,14 @@ impl TryFrom for MsgTransfer { fn try_from(raw: Any) -> Result { match raw.type_url.as_str() { - TYPE_URL => MsgTransfer::decode_vec(&raw.value).map_err(|e| { - NftTransferError::Decoding(DecodingError::FailedToDecodeProto { - description: e.to_string(), - }) - }), - _ => Err(NftTransferError::UnknownMsgType(raw.type_url)), + TYPE_URL => MsgTransfer::decode_vec(&raw.value) + .map_err(|e| NftTransferError::Decoding(DecodingError::FailedToDecodeProto(e))), + _ => Err(NftTransferError::Decoding( + DecodingError::MismatchedTypeUrls { + expected: TYPE_URL.to_string(), + actual: raw.type_url, + }, + )), } } } diff --git a/ibc-clients/ics08-wasm/types/src/client_state.rs b/ibc-clients/ics08-wasm/types/src/client_state.rs index c8c4aca41..a99bb7547 100644 --- a/ibc-clients/ics08-wasm/types/src/client_state.rs +++ b/ibc-clients/ics08-wasm/types/src/client_state.rs @@ -3,6 +3,7 @@ use ibc_core_client::types::Height; use ibc_primitives::prelude::*; use ibc_primitives::proto::{Any, Protobuf}; +use ibc_primitives::DecodingError; use ibc_proto::ibc::lightclients::wasm::v1::ClientState as RawClientState; use crate::error::WasmClientError; @@ -69,22 +70,21 @@ impl TryFrom for ClientState { type Error = WasmClientError; fn try_from(any: Any) -> Result { - fn decode_client_state(value: &[u8]) -> Result { - let client_state = Protobuf::::decode(value).map_err(|e| { - WasmClientError::DecodingError { - description: e.to_string(), - } - })?; - + fn decode_client_state(value: &[u8]) -> Result { + let client_state = Protobuf::::decode(value)?; Ok(client_state) } match any.type_url.as_str() { - WASM_CLIENT_STATE_TYPE_URL => decode_client_state(&any.value), - other_type_url => Err(WasmClientError::MismatchedTypeUrls { - expected: WASM_CLIENT_STATE_TYPE_URL.to_string(), - actual: other_type_url.to_string(), - }), + WASM_CLIENT_STATE_TYPE_URL => { + decode_client_state(&any.value).map_err(WasmClientError::Decoding) + } + _ => Err(WasmClientError::Decoding( + DecodingError::MismatchedTypeUrls { + expected: WASM_CLIENT_STATE_TYPE_URL.to_string(), + actual: any.type_url, + }, + )), } } } diff --git a/ibc-clients/ics08-wasm/types/src/error.rs b/ibc-clients/ics08-wasm/types/src/error.rs index ecb3e1984..3ec6c9ea5 100644 --- a/ibc-clients/ics08-wasm/types/src/error.rs +++ b/ibc-clients/ics08-wasm/types/src/error.rs @@ -3,20 +3,19 @@ use displaydoc::Display; use ibc_core_host_types::error::IdentifierError; use ibc_primitives::prelude::*; +use ibc_primitives::DecodingError; /// The main error type #[derive(Debug, Display)] pub enum WasmClientError { + /// decoding error: `{0}` + Decoding(DecodingError), /// invalid identifier: `{0}` InvalidIdentifier(IdentifierError), /// invalid client state latest height InvalidLatestHeight, /// missing latest height MissingLatestHeight, - /// mismatched type URLs: expected `{expected}`, actual `{actual}` - MismatchedTypeUrls { expected: String, actual: String }, - /// decoding error: `{description}` - DecodingError { description: String }, } #[cfg(feature = "std")] diff --git a/ibc-core/ics02-client/types/src/error.rs b/ibc-core/ics02-client/types/src/error.rs index aaa085331..6ecb663dd 100644 --- a/ibc-core/ics02-client/types/src/error.rs +++ b/ibc-core/ics02-client/types/src/error.rs @@ -109,12 +109,6 @@ impl From for ClientError { } } -impl From for ClientError { - fn from(e: DecodingError) -> Self { - Self::Decoding(e) - } -} - impl From for ClientError { fn from(e: StatusError) -> Self { Self::Status(e) @@ -137,6 +131,8 @@ impl std::error::Error for ClientError { /// Encodes all the possible upgrade client errors #[derive(Debug, Display)] pub enum UpgradeClientError { + /// decoding error: `{0}` + Decoding(DecodingError), /// invalid proof for the upgraded client state: `{0}` InvalidUpgradeClientProof(CommitmentError), /// invalid proof for the upgraded consensus state: `{0}` @@ -147,14 +143,10 @@ pub enum UpgradeClientError { InvalidUpgradeProposal { description: String }, /// invalid upgrade plan: `{description}` InvalidUpgradePlan { description: String }, - /// mismatched type URLs: expected `{expected}`, actual `{actual}` - MismatchedTypeUrls { expected: String, actual: String }, /// missing upgraded client state MissingUpgradedClientState, /// missing upgraded consensus state MissingUpgradedConsensusState, - /// failed to decode raw upgrade plan: `{description}` - FailedToDecodeRawUpgradePlan { description: String }, /// failed to store upgrade plan: `{description}` FailedToStoreUpgradePlan { description: String }, /// failed to store upgraded client state: `{description}` diff --git a/ibc-core/ics24-host/cosmos/src/upgrade_proposal/plan.rs b/ibc-core/ics24-host/cosmos/src/upgrade_proposal/plan.rs index f66487cc7..7880c1810 100644 --- a/ibc-core/ics24-host/cosmos/src/upgrade_proposal/plan.rs +++ b/ibc-core/ics24-host/cosmos/src/upgrade_proposal/plan.rs @@ -1,7 +1,7 @@ //! Definition of domain `Plan` type. use ibc_core_client_types::error::UpgradeClientError; -use ibc_primitives::prelude::*; +use ibc_primitives::{prelude::*, DecodingError}; use ibc_proto::cosmos::upgrade::v1beta1::Plan as RawPlan; use ibc_proto::google::protobuf::Any; use ibc_proto::Protobuf; @@ -82,20 +82,16 @@ impl TryFrom for Plan { type Error = UpgradeClientError; fn try_from(any: Any) -> Result { - if any.type_url != TYPE_URL { - return Err(UpgradeClientError::MismatchedTypeUrls { - expected: TYPE_URL.to_string(), - actual: any.type_url, - }); + match any.type_url.as_str() { + TYPE_URL => Protobuf::::decode_vec(&any.value) + .map_err(|e| UpgradeClientError::Decoding(DecodingError::FailedToDecodeProto(e))), + _ => Err(UpgradeClientError::Decoding( + DecodingError::MismatchedTypeUrls { + expected: TYPE_URL.to_string(), + actual: any.type_url, + }, + )), } - - let plan = Protobuf::::decode_vec(&any.value).map_err(|e| { - UpgradeClientError::FailedToDecodeRawUpgradePlan { - description: e.to_string(), - } - })?; - - Ok(plan) } } diff --git a/ibc-primitives/src/types/error.rs b/ibc-primitives/src/types/error.rs index b8aa169e5..e76d74b44 100644 --- a/ibc-primitives/src/types/error.rs +++ b/ibc-primitives/src/types/error.rs @@ -1,6 +1,6 @@ //! Foundational error types that are applicable across multiple ibc-rs workspaces. -use alloc::string::{String, ToString}; +use alloc::string::String; use displaydoc::Display; use http::uri::InvalidUri; @@ -24,15 +24,13 @@ pub enum DecodingError { MissingField(String), /// mismatched type URLs: expected `{expected}`, actual `{actual}` MismatchedTypeUrls { expected: String, actual: String }, - /// failed to decode proto value: `{description}` - FailedToDecodeProto { description: String }, + /// failed to decode proto; error: `{0}` + FailedToDecodeProto(ProtoError), } impl From for DecodingError { fn from(e: ProtoError) -> Self { - Self::FailedToDecodeProto { - description: e.to_string(), - } + Self::FailedToDecodeProto(e) } } From fc528658d437c89144735820a12900f4c82428cb Mon Sep 17 00:00:00 2001 From: Sean Chen Date: Tue, 27 Aug 2024 13:17:17 -0500 Subject: [PATCH 07/73] Add DecodingError to RouterError --- ibc-core/ics25-handler/types/src/msgs.rs | 73 ++++++++++++----------- ibc-core/ics26-routing/types/src/error.rs | 5 +- ibc-primitives/src/types/error.rs | 2 + 3 files changed, 42 insertions(+), 38 deletions(-) diff --git a/ibc-core/ics25-handler/types/src/msgs.rs b/ibc-core/ics25-handler/types/src/msgs.rs index e3276b951..cfb13e631 100644 --- a/ibc-core/ics25-handler/types/src/msgs.rs +++ b/ibc-core/ics25-handler/types/src/msgs.rs @@ -19,6 +19,7 @@ use ibc_core_connection_types::msgs::{ }; use ibc_core_router_types::error::RouterError; use ibc_primitives::prelude::*; +use ibc_primitives::DecodingError; use ibc_proto::google::protobuf::Any; use ibc_proto::Protobuf; @@ -46,34 +47,34 @@ impl TryFrom for MsgEnvelope { CREATE_CLIENT_TYPE_URL => { // Pop out the message and then wrap it in the corresponding type. let domain_msg = MsgCreateClient::decode_vec(&any_msg.value).map_err(|e| { - RouterError::MalformedMessageBytes { + RouterError::Decoding(DecodingError::MalformedBytes { description: e.to_string(), - } + }) })?; Ok(MsgEnvelope::Client(ClientMsg::CreateClient(domain_msg))) } UPDATE_CLIENT_TYPE_URL => { let domain_msg = MsgUpdateClient::decode_vec(&any_msg.value).map_err(|e| { - RouterError::MalformedMessageBytes { + RouterError::Decoding(DecodingError::MalformedBytes { description: e.to_string(), - } + }) })?; Ok(MsgEnvelope::Client(ClientMsg::UpdateClient(domain_msg))) } UPGRADE_CLIENT_TYPE_URL => { let domain_msg = MsgUpgradeClient::decode_vec(&any_msg.value).map_err(|e| { - RouterError::MalformedMessageBytes { + RouterError::Decoding(DecodingError::MalformedBytes { description: e.to_string(), - } + }) })?; Ok(MsgEnvelope::Client(ClientMsg::UpgradeClient(domain_msg))) } SUBMIT_MISBEHAVIOUR_TYPE_URL => { let domain_msg = MsgSubmitMisbehaviour::decode_vec(&any_msg.value).map_err(|e| { - RouterError::MalformedMessageBytes { + RouterError::Decoding(DecodingError::MalformedBytes { description: e.to_string(), - } + }) })?; Ok(MsgEnvelope::Client(ClientMsg::Misbehaviour(domain_msg))) } @@ -82,34 +83,34 @@ impl TryFrom for MsgEnvelope { CONN_OPEN_INIT_TYPE_URL => { let domain_msg = MsgConnectionOpenInit::decode_vec(&any_msg.value).map_err(|e| { - RouterError::MalformedMessageBytes { + RouterError::Decoding(DecodingError::MalformedBytes { description: e.to_string(), - } + }) })?; Ok(MsgEnvelope::Connection(ConnectionMsg::OpenInit(domain_msg))) } CONN_OPEN_TRY_TYPE_URL => { let domain_msg = MsgConnectionOpenTry::decode_vec(&any_msg.value).map_err(|e| { - RouterError::MalformedMessageBytes { + RouterError::Decoding(DecodingError::MalformedBytes { description: e.to_string(), - } + }) })?; Ok(MsgEnvelope::Connection(ConnectionMsg::OpenTry(domain_msg))) } CONN_OPEN_ACK_TYPE_URL => { let domain_msg = MsgConnectionOpenAck::decode_vec(&any_msg.value).map_err(|e| { - RouterError::MalformedMessageBytes { + RouterError::Decoding(DecodingError::MalformedBytes { description: e.to_string(), - } + }) })?; Ok(MsgEnvelope::Connection(ConnectionMsg::OpenAck(domain_msg))) } CONN_OPEN_CONFIRM_TYPE_URL => { let domain_msg = MsgConnectionOpenConfirm::decode_vec(&any_msg.value).map_err(|e| { - RouterError::MalformedMessageBytes { + RouterError::Decoding(DecodingError::MalformedBytes { description: e.to_string(), - } + }) })?; Ok(MsgEnvelope::Connection(ConnectionMsg::OpenConfirm( domain_msg, @@ -119,84 +120,84 @@ impl TryFrom for MsgEnvelope { // ICS04 channel messages CHAN_OPEN_INIT_TYPE_URL => { let domain_msg = MsgChannelOpenInit::decode_vec(&any_msg.value).map_err(|e| { - RouterError::MalformedMessageBytes { + RouterError::Decoding(DecodingError::MalformedBytes { description: e.to_string(), - } + }) })?; Ok(MsgEnvelope::Channel(ChannelMsg::OpenInit(domain_msg))) } CHAN_OPEN_TRY_TYPE_URL => { let domain_msg = MsgChannelOpenTry::decode_vec(&any_msg.value).map_err(|e| { - RouterError::MalformedMessageBytes { + RouterError::Decoding(DecodingError::MalformedBytes { description: e.to_string(), - } + }) })?; Ok(MsgEnvelope::Channel(ChannelMsg::OpenTry(domain_msg))) } CHAN_OPEN_ACK_TYPE_URL => { let domain_msg = MsgChannelOpenAck::decode_vec(&any_msg.value).map_err(|e| { - RouterError::MalformedMessageBytes { + RouterError::Decoding(DecodingError::MalformedBytes { description: e.to_string(), - } + }) })?; Ok(MsgEnvelope::Channel(ChannelMsg::OpenAck(domain_msg))) } CHAN_OPEN_CONFIRM_TYPE_URL => { let domain_msg = MsgChannelOpenConfirm::decode_vec(&any_msg.value).map_err(|e| { - RouterError::MalformedMessageBytes { + RouterError::Decoding(DecodingError::MalformedBytes { description: e.to_string(), - } + }) })?; Ok(MsgEnvelope::Channel(ChannelMsg::OpenConfirm(domain_msg))) } CHAN_CLOSE_INIT_TYPE_URL => { let domain_msg = MsgChannelCloseInit::decode_vec(&any_msg.value).map_err(|e| { - RouterError::MalformedMessageBytes { + RouterError::Decoding(DecodingError::MalformedBytes { description: e.to_string(), - } + }) })?; Ok(MsgEnvelope::Channel(ChannelMsg::CloseInit(domain_msg))) } CHAN_CLOSE_CONFIRM_TYPE_URL => { let domain_msg = MsgChannelCloseConfirm::decode_vec(&any_msg.value).map_err(|e| { - RouterError::MalformedMessageBytes { + RouterError::Decoding(DecodingError::MalformedBytes { description: e.to_string(), - } + }) })?; Ok(MsgEnvelope::Channel(ChannelMsg::CloseConfirm(domain_msg))) } // ICS04 packet messages RECV_PACKET_TYPE_URL => { let domain_msg = MsgRecvPacket::decode_vec(&any_msg.value).map_err(|e| { - RouterError::MalformedMessageBytes { + RouterError::Decoding(DecodingError::MalformedBytes { description: e.to_string(), - } + }) })?; Ok(MsgEnvelope::Packet(PacketMsg::Recv(domain_msg))) } ACKNOWLEDGEMENT_TYPE_URL => { let domain_msg = MsgAcknowledgement::decode_vec(&any_msg.value).map_err(|e| { - RouterError::MalformedMessageBytes { + RouterError::Decoding(DecodingError::MalformedBytes { description: e.to_string(), - } + }) })?; Ok(MsgEnvelope::Packet(PacketMsg::Ack(domain_msg))) } TIMEOUT_TYPE_URL => { let domain_msg = MsgTimeout::decode_vec(&any_msg.value).map_err(|e| { - RouterError::MalformedMessageBytes { + RouterError::Decoding(DecodingError::MalformedBytes { description: e.to_string(), - } + }) })?; Ok(MsgEnvelope::Packet(PacketMsg::Timeout(domain_msg))) } TIMEOUT_ON_CLOSE_TYPE_URL => { let domain_msg = MsgTimeoutOnClose::decode_vec(&any_msg.value).map_err(|e| { - RouterError::MalformedMessageBytes { + RouterError::Decoding(DecodingError::MalformedBytes { description: e.to_string(), - } + }) })?; Ok(MsgEnvelope::Packet(PacketMsg::TimeoutOnClose(domain_msg))) } diff --git a/ibc-core/ics26-routing/types/src/error.rs b/ibc-core/ics26-routing/types/src/error.rs index 663cbcc6a..b9de1e97a 100644 --- a/ibc-core/ics26-routing/types/src/error.rs +++ b/ibc-core/ics26-routing/types/src/error.rs @@ -1,12 +1,13 @@ use displaydoc::Display; use ibc_core_host_types::identifiers::PortId; use ibc_primitives::prelude::*; +use ibc_primitives::DecodingError; /// Error type for the router module. #[derive(Debug, Display)] pub enum RouterError { - /// malformed message that could not be decoded: `{description}` - MalformedMessageBytes { description: String }, + /// decoding error: `{0}` + Decoding(DecodingError), /// missing module MissingModule, /// unknown message type URL `{0}` diff --git a/ibc-primitives/src/types/error.rs b/ibc-primitives/src/types/error.rs index e76d74b44..d7f06f80e 100644 --- a/ibc-primitives/src/types/error.rs +++ b/ibc-primitives/src/types/error.rs @@ -20,6 +20,8 @@ pub enum DecodingError { InvalidUtf8 { description: String }, /// invalid URI: `{0}` InvalidUri(InvalidUri), + /// malformed bytes that could not be decoded: `{description}` + MalformedBytes { description: String }, /// missing field: `{0}` MissingField(String), /// mismatched type URLs: expected `{expected}`, actual `{actual}` From 3bb4953092bf23b1757c2e371bf8bc9d69575575 Mon Sep 17 00:00:00 2001 From: Sean Chen Date: Tue, 27 Aug 2024 13:37:51 -0500 Subject: [PATCH 08/73] Remove unused From impl --- ibc-testkit/src/testapp/ibc/clients/mock/consensus_state.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ibc-testkit/src/testapp/ibc/clients/mock/consensus_state.rs b/ibc-testkit/src/testapp/ibc/clients/mock/consensus_state.rs index 1121e5147..4c364d61b 100644 --- a/ibc-testkit/src/testapp/ibc/clients/mock/consensus_state.rs +++ b/ibc-testkit/src/testapp/ibc/clients/mock/consensus_state.rs @@ -65,7 +65,7 @@ impl TryFrom for MockConsensusState { type Error = ClientError; fn try_from(raw: Any) -> Result { - fn decode_consensus_state(value: &[u8]) -> Result { + fn decode_consensus_state(value: &[u8]) -> Result { let mock_consensus_state = Protobuf::::decode(value)?; Ok(mock_consensus_state) } From 578dfc921dda1e0953467c9bfb896c14fa56fac2 Mon Sep 17 00:00:00 2001 From: Sean Chen Date: Tue, 27 Aug 2024 13:39:16 -0500 Subject: [PATCH 09/73] Change format of an import --- ibc-apps/ics20-transfer/types/src/msgs/transfer.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/ibc-apps/ics20-transfer/types/src/msgs/transfer.rs b/ibc-apps/ics20-transfer/types/src/msgs/transfer.rs index d10d538a3..022f5559c 100644 --- a/ibc-apps/ics20-transfer/types/src/msgs/transfer.rs +++ b/ibc-apps/ics20-transfer/types/src/msgs/transfer.rs @@ -4,7 +4,8 @@ use ibc_core::channel::types::error::PacketError; use ibc_core::channel::types::timeout::{TimeoutHeight, TimeoutTimestamp}; use ibc_core::handler::types::error::ContextError; use ibc_core::host::types::identifiers::{ChannelId, PortId}; -use ibc_core::primitives::{prelude::*, DecodingError}; +use ibc_core::primitives::prelude::*; +use ibc_core::primitives::DecodingError; use ibc_proto::google::protobuf::Any; use ibc_proto::ibc::applications::transfer::v1::MsgTransfer as RawMsgTransfer; use ibc_proto::Protobuf; From d3de049b53d13cd6e0bc2d6f073ac6db1ec2e97b Mon Sep 17 00:00:00 2001 From: Sean Chen Date: Tue, 27 Aug 2024 13:39:56 -0500 Subject: [PATCH 10/73] Change format of an import --- ibc-apps/ics721-nft-transfer/types/src/class.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/ibc-apps/ics721-nft-transfer/types/src/class.rs b/ibc-apps/ics721-nft-transfer/types/src/class.rs index 98ae0a765..2869e130a 100644 --- a/ibc-apps/ics721-nft-transfer/types/src/class.rs +++ b/ibc-apps/ics721-nft-transfer/types/src/class.rs @@ -5,9 +5,10 @@ use core::str::FromStr; use http::Uri; pub use ibc_app_transfer_types::{TracePath, TracePrefix}; use ibc_core::host::types::identifiers::{ChannelId, PortId}; +use ibc_core::primitives::prelude::*; #[cfg(feature = "serde")] use ibc_core::primitives::serializers; -use ibc_core::primitives::{prelude::*, DecodingError}; +use ibc_core::primitives::DecodingError; use ibc_proto::ibc::applications::nft_transfer::v1::ClassTrace as RawClassTrace; use crate::data::Data; From 164e0b98b7e4155819932f8474d651a4682cbdf5 Mon Sep 17 00:00:00 2001 From: Sean Chen Date: Tue, 27 Aug 2024 13:52:22 -0500 Subject: [PATCH 11/73] Change format of an import --- ibc-apps/ics721-nft-transfer/types/src/data.rs | 3 ++- ibc-apps/ics721-nft-transfer/types/src/msgs/transfer.rs | 3 ++- ibc-apps/ics721-nft-transfer/types/src/packet.rs | 4 ++-- ibc-apps/ics721-nft-transfer/types/src/token.rs | 3 ++- ibc-clients/ics07-tendermint/types/src/consensus_state.rs | 3 ++- ibc-clients/ics07-tendermint/types/src/header.rs | 3 ++- ibc-clients/ics07-tendermint/types/src/misbehaviour.rs | 3 ++- ibc-clients/ics08-wasm/types/src/consensus_state.rs | 3 ++- ibc-core/ics02-client/types/src/status.rs | 2 +- ibc-core/ics24-host/cosmos/src/upgrade_proposal/plan.rs | 3 ++- ibc-primitives/src/types/error.rs | 4 ---- 11 files changed, 19 insertions(+), 15 deletions(-) diff --git a/ibc-apps/ics721-nft-transfer/types/src/data.rs b/ibc-apps/ics721-nft-transfer/types/src/data.rs index 8b91d3025..d78d9fb4e 100644 --- a/ibc-apps/ics721-nft-transfer/types/src/data.rs +++ b/ibc-apps/ics721-nft-transfer/types/src/data.rs @@ -6,7 +6,8 @@ use core::str::FromStr; use base64::prelude::BASE64_STANDARD; #[cfg(feature = "serde")] use base64::Engine; -use ibc_core::primitives::{prelude::*, DecodingError}; +use ibc_core::primitives::prelude::*; +use ibc_core::primitives::DecodingError; use mime::Mime; use crate::error::NftTransferError; diff --git a/ibc-apps/ics721-nft-transfer/types/src/msgs/transfer.rs b/ibc-apps/ics721-nft-transfer/types/src/msgs/transfer.rs index 56be700ca..cfb279c27 100644 --- a/ibc-apps/ics721-nft-transfer/types/src/msgs/transfer.rs +++ b/ibc-apps/ics721-nft-transfer/types/src/msgs/transfer.rs @@ -4,7 +4,8 @@ use ibc_core::channel::types::error::PacketError; use ibc_core::channel::types::timeout::{TimeoutHeight, TimeoutTimestamp}; use ibc_core::handler::types::error::ContextError; use ibc_core::host::types::identifiers::{ChannelId, PortId}; -use ibc_core::primitives::{prelude::*, DecodingError}; +use ibc_core::primitives::prelude::*; +use ibc_core::primitives::DecodingError; use ibc_proto::google::protobuf::Any; use ibc_proto::ibc::applications::nft_transfer::v1::MsgTransfer as RawMsgTransfer; use ibc_proto::Protobuf; diff --git a/ibc-apps/ics721-nft-transfer/types/src/packet.rs b/ibc-apps/ics721-nft-transfer/types/src/packet.rs index 06009d372..1eb970bba 100644 --- a/ibc-apps/ics721-nft-transfer/types/src/packet.rs +++ b/ibc-apps/ics721-nft-transfer/types/src/packet.rs @@ -2,10 +2,10 @@ use base64::prelude::BASE64_STANDARD; use base64::Engine; +use ibc_core::primitives::prelude::*; #[cfg(feature = "serde")] use ibc_core::primitives::serializers; -use ibc_core::primitives::Signer; -use ibc_core::primitives::{prelude::*, DecodingError}; +use ibc_core::primitives::{DecodingError, Signer}; use ibc_proto::ibc::applications::nft_transfer::v1::NonFungibleTokenPacketData as RawPacketData; use crate::class::{ClassData, ClassUri, PrefixedClassId}; diff --git a/ibc-apps/ics721-nft-transfer/types/src/token.rs b/ibc-apps/ics721-nft-transfer/types/src/token.rs index 374b3e54b..aeb141f20 100644 --- a/ibc-apps/ics721-nft-transfer/types/src/token.rs +++ b/ibc-apps/ics721-nft-transfer/types/src/token.rs @@ -3,9 +3,10 @@ use core::fmt::{self, Display}; use core::str::FromStr; use http::Uri; +use ibc_core::primitives::prelude::*; #[cfg(feature = "serde")] use ibc_core::primitives::serializers; -use ibc_core::primitives::{prelude::*, DecodingError}; +use ibc_core::primitives::DecodingError; use crate::data::Data; use crate::error::NftTransferError; diff --git a/ibc-clients/ics07-tendermint/types/src/consensus_state.rs b/ibc-clients/ics07-tendermint/types/src/consensus_state.rs index 82c6b2c7a..62e0b35de 100644 --- a/ibc-clients/ics07-tendermint/types/src/consensus_state.rs +++ b/ibc-clients/ics07-tendermint/types/src/consensus_state.rs @@ -2,7 +2,8 @@ use ibc_core_client_types::error::ClientError; use ibc_core_commitment_types::commitment::CommitmentRoot; -use ibc_primitives::{prelude::*, DecodingError}; +use ibc_primitives::prelude::*; +use ibc_primitives::DecodingError; use ibc_proto::google::protobuf::Any; use ibc_proto::ibc::lightclients::tendermint::v1::ConsensusState as RawConsensusState; use ibc_proto::Protobuf; diff --git a/ibc-clients/ics07-tendermint/types/src/header.rs b/ibc-clients/ics07-tendermint/types/src/header.rs index e15044653..b63f80408 100644 --- a/ibc-clients/ics07-tendermint/types/src/header.rs +++ b/ibc-clients/ics07-tendermint/types/src/header.rs @@ -6,8 +6,9 @@ use core::str::FromStr; use ibc_core_client_types::error::ClientError; use ibc_core_client_types::Height; use ibc_core_host_types::identifiers::ChainId; +use ibc_primitives::prelude::*; +use ibc_primitives::DecodingError; use ibc_primitives::Timestamp; -use ibc_primitives::{prelude::*, DecodingError}; use ibc_proto::google::protobuf::Any; use ibc_proto::ibc::lightclients::tendermint::v1::Header as RawHeader; use ibc_proto::Protobuf; diff --git a/ibc-clients/ics07-tendermint/types/src/misbehaviour.rs b/ibc-clients/ics07-tendermint/types/src/misbehaviour.rs index fd314b6eb..b50cdb0d4 100644 --- a/ibc-clients/ics07-tendermint/types/src/misbehaviour.rs +++ b/ibc-clients/ics07-tendermint/types/src/misbehaviour.rs @@ -2,7 +2,8 @@ use ibc_core_client_types::error::ClientError; use ibc_core_host_types::identifiers::ClientId; -use ibc_primitives::{prelude::*, DecodingError}; +use ibc_primitives::prelude::*; +use ibc_primitives::DecodingError; use ibc_proto::google::protobuf::Any; use ibc_proto::ibc::lightclients::tendermint::v1::Misbehaviour as RawMisbehaviour; use ibc_proto::Protobuf; diff --git a/ibc-clients/ics08-wasm/types/src/consensus_state.rs b/ibc-clients/ics08-wasm/types/src/consensus_state.rs index 9d50f7177..ed84364a6 100644 --- a/ibc-clients/ics08-wasm/types/src/consensus_state.rs +++ b/ibc-clients/ics08-wasm/types/src/consensus_state.rs @@ -1,8 +1,9 @@ //! Defines the consensus state type for the ICS-08 Wasm light client. use ibc_core_client::types::error::ClientError; +use ibc_primitives::prelude::*; use ibc_primitives::proto::{Any, Protobuf}; -use ibc_primitives::{prelude::*, DecodingError}; +use ibc_primitives::DecodingError; use ibc_proto::ibc::lightclients::wasm::v1::ConsensusState as RawConsensusState; #[cfg(feature = "serde")] diff --git a/ibc-core/ics02-client/types/src/status.rs b/ibc-core/ics02-client/types/src/status.rs index e63df1793..a16d1218d 100644 --- a/ibc-core/ics02-client/types/src/status.rs +++ b/ibc-core/ics02-client/types/src/status.rs @@ -37,7 +37,7 @@ pub enum Status { pub enum StatusError { /// invalid client status: `{0}` InvalidStatus(String), - /// unexpected status `{0}` found + /// unexpected status found: `{0}` UnexpectedStatus(Status), } diff --git a/ibc-core/ics24-host/cosmos/src/upgrade_proposal/plan.rs b/ibc-core/ics24-host/cosmos/src/upgrade_proposal/plan.rs index 7880c1810..3a37c87f5 100644 --- a/ibc-core/ics24-host/cosmos/src/upgrade_proposal/plan.rs +++ b/ibc-core/ics24-host/cosmos/src/upgrade_proposal/plan.rs @@ -1,7 +1,8 @@ //! Definition of domain `Plan` type. use ibc_core_client_types::error::UpgradeClientError; -use ibc_primitives::{prelude::*, DecodingError}; +use ibc_primitives::prelude::*; +use ibc_primitives::DecodingError; use ibc_proto::cosmos::upgrade::v1beta1::Plan as RawPlan; use ibc_proto::google::protobuf::Any; use ibc_proto::Protobuf; diff --git a/ibc-primitives/src/types/error.rs b/ibc-primitives/src/types/error.rs index d7f06f80e..859f94ba6 100644 --- a/ibc-primitives/src/types/error.rs +++ b/ibc-primitives/src/types/error.rs @@ -12,8 +12,6 @@ use tendermint_proto::Error as ProtoError; pub enum DecodingError { /// invalid identifier error: `{0}` InvalidIdentifier(String), - /// invalid field: `{0}` - InvalidField(String), /// invalid JSON data: `{description}` InvalidJson { description: String }, /// invalid UTF-8 data: `{description}` @@ -22,8 +20,6 @@ pub enum DecodingError { InvalidUri(InvalidUri), /// malformed bytes that could not be decoded: `{description}` MalformedBytes { description: String }, - /// missing field: `{0}` - MissingField(String), /// mismatched type URLs: expected `{expected}`, actual `{actual}` MismatchedTypeUrls { expected: String, actual: String }, /// failed to decode proto; error: `{0}` From c309f72cba5cda6cdc577aa5aa79be509ae7a48b Mon Sep 17 00:00:00 2001 From: Sean Chen Date: Tue, 27 Aug 2024 15:36:08 -0500 Subject: [PATCH 12/73] Move DecodingError into ics24 --- ibc-apps/ics20-transfer/types/src/error.rs | 2 +- .../ics20-transfer/types/src/msgs/transfer.rs | 2 +- .../ics721-nft-transfer/types/src/class.rs | 2 +- .../ics721-nft-transfer/types/src/data.rs | 2 +- .../ics721-nft-transfer/types/src/error.rs | 18 +++++----- .../types/src/msgs/transfer.rs | 2 +- .../ics721-nft-transfer/types/src/packet.rs | 3 +- .../ics721-nft-transfer/types/src/token.rs | 2 +- .../src/client_state/common.rs | 2 +- .../types/src/consensus_state.rs | 2 +- .../ics07-tendermint/types/src/header.rs | 2 +- .../types/src/misbehaviour.rs | 2 +- .../ics08-wasm/types/src/client_state.rs | 2 +- .../ics08-wasm/types/src/consensus_state.rs | 2 +- ibc-clients/ics08-wasm/types/src/error.rs | 2 +- .../ics02-client/src/handler/create_client.rs | 4 ++- .../src/handler/recover_client.rs | 4 +-- .../ics02-client/src/handler/update_client.rs | 2 +- .../src/handler/upgrade_client.rs | 2 +- ibc-core/ics02-client/types/src/error.rs | 12 ++++--- .../src/handler/conn_open_ack.rs | 2 +- .../src/handler/conn_open_confirm.rs | 2 +- .../src/handler/conn_open_init.rs | 2 +- .../src/handler/conn_open_try.rs | 2 +- .../src/handler/acknowledgement.rs | 2 +- .../src/handler/chan_close_confirm.rs | 2 +- .../src/handler/chan_close_init.rs | 2 +- .../src/handler/chan_open_ack.rs | 2 +- .../src/handler/chan_open_confirm.rs | 2 +- .../src/handler/chan_open_init.rs | 2 +- .../src/handler/chan_open_try.rs | 2 +- .../ics04-channel/src/handler/recv_packet.rs | 2 +- .../ics04-channel/src/handler/send_packet.rs | 2 +- ibc-core/ics04-channel/src/handler/timeout.rs | 2 +- .../src/handler/timeout_on_close.rs | 2 +- .../cosmos/src/upgrade_proposal/plan.rs | 2 +- .../cosmos/src/validate_self_client.rs | 4 ++- ibc-core/ics24-host/types/Cargo.toml | 4 +++ ibc-core/ics24-host/types/src/error.rs | 35 ++++++++++++++++++ ibc-core/ics24-host/types/src/lib.rs | 2 ++ ibc-core/ics25-handler/types/src/msgs.rs | 2 +- ibc-core/ics26-routing/types/src/error.rs | 3 +- ibc-primitives/Cargo.toml | 1 - ibc-primitives/src/types/error.rs | 36 ------------------- ibc-primitives/src/types/mod.rs | 2 -- ibc-query/src/error.rs | 13 ++++++- .../testapp/ibc/clients/mock/client_state.rs | 8 +++-- .../ibc/clients/mock/consensus_state.rs | 2 +- .../src/testapp/ibc/clients/mock/header.rs | 4 ++- .../testapp/ibc/clients/mock/misbehaviour.rs | 2 +- ibc-testkit/src/testapp/ibc/core/core_ctx.rs | 6 ++-- .../tests/core/ics02_client/create_client.rs | 14 ++++---- 52 files changed, 134 insertions(+), 107 deletions(-) delete mode 100644 ibc-primitives/src/types/error.rs diff --git a/ibc-apps/ics20-transfer/types/src/error.rs b/ibc-apps/ics20-transfer/types/src/error.rs index 38c9581a7..b71ccddda 100644 --- a/ibc-apps/ics20-transfer/types/src/error.rs +++ b/ibc-apps/ics20-transfer/types/src/error.rs @@ -5,10 +5,10 @@ use displaydoc::Display; use ibc_core::channel::types::acknowledgement::StatusValue; use ibc_core::channel::types::channel::Order; use ibc_core::handler::types::error::ContextError; +use ibc_core::host::types::error::DecodingError; use ibc_core::host::types::error::IdentifierError; use ibc_core::host::types::identifiers::{ChannelId, PortId}; use ibc_core::primitives::prelude::*; -use ibc_core::primitives::DecodingError; use uint::FromDecStrErr; #[derive(Display, Debug)] diff --git a/ibc-apps/ics20-transfer/types/src/msgs/transfer.rs b/ibc-apps/ics20-transfer/types/src/msgs/transfer.rs index 022f5559c..b8809d6c9 100644 --- a/ibc-apps/ics20-transfer/types/src/msgs/transfer.rs +++ b/ibc-apps/ics20-transfer/types/src/msgs/transfer.rs @@ -3,9 +3,9 @@ use ibc_core::channel::types::error::PacketError; use ibc_core::channel::types::timeout::{TimeoutHeight, TimeoutTimestamp}; use ibc_core::handler::types::error::ContextError; +use ibc_core::host::types::error::DecodingError; use ibc_core::host::types::identifiers::{ChannelId, PortId}; use ibc_core::primitives::prelude::*; -use ibc_core::primitives::DecodingError; use ibc_proto::google::protobuf::Any; use ibc_proto::ibc::applications::transfer::v1::MsgTransfer as RawMsgTransfer; use ibc_proto::Protobuf; diff --git a/ibc-apps/ics721-nft-transfer/types/src/class.rs b/ibc-apps/ics721-nft-transfer/types/src/class.rs index 2869e130a..c4aaa5ae5 100644 --- a/ibc-apps/ics721-nft-transfer/types/src/class.rs +++ b/ibc-apps/ics721-nft-transfer/types/src/class.rs @@ -4,11 +4,11 @@ use core::str::FromStr; use http::Uri; pub use ibc_app_transfer_types::{TracePath, TracePrefix}; +use ibc_core::host::types::error::DecodingError; use ibc_core::host::types::identifiers::{ChannelId, PortId}; use ibc_core::primitives::prelude::*; #[cfg(feature = "serde")] use ibc_core::primitives::serializers; -use ibc_core::primitives::DecodingError; use ibc_proto::ibc::applications::nft_transfer::v1::ClassTrace as RawClassTrace; use crate::data::Data; diff --git a/ibc-apps/ics721-nft-transfer/types/src/data.rs b/ibc-apps/ics721-nft-transfer/types/src/data.rs index d78d9fb4e..bbbfb3f3d 100644 --- a/ibc-apps/ics721-nft-transfer/types/src/data.rs +++ b/ibc-apps/ics721-nft-transfer/types/src/data.rs @@ -6,8 +6,8 @@ use core::str::FromStr; use base64::prelude::BASE64_STANDARD; #[cfg(feature = "serde")] use base64::Engine; +use ibc_core::host::types::error::DecodingError; use ibc_core::primitives::prelude::*; -use ibc_core::primitives::DecodingError; use mime::Mime; use crate::error::NftTransferError; diff --git a/ibc-apps/ics721-nft-transfer/types/src/error.rs b/ibc-apps/ics721-nft-transfer/types/src/error.rs index 744665564..32f55ce29 100644 --- a/ibc-apps/ics721-nft-transfer/types/src/error.rs +++ b/ibc-apps/ics721-nft-transfer/types/src/error.rs @@ -4,10 +4,10 @@ use core::convert::Infallible; use ibc_core::channel::types::acknowledgement::StatusValue; use ibc_core::channel::types::channel::Order; use ibc_core::handler::types::error::ContextError; +use ibc_core::host::types::error::DecodingError; use ibc_core::host::types::error::IdentifierError; use ibc_core::host::types::identifiers::{ChannelId, PortId}; use ibc_core::primitives::prelude::*; -use ibc_core::primitives::DecodingError; use displaydoc::Display; @@ -62,25 +62,25 @@ impl From for NftTransferError { } impl From for NftTransferError { - fn from(err: ContextError) -> Self { - Self::ContextError(err) + fn from(e: ContextError) -> Self { + Self::ContextError(e) } } impl From for NftTransferError { - fn from(err: IdentifierError) -> Self { - Self::Decoding(DecodingError::InvalidIdentifier(err.to_string())) + fn from(e: IdentifierError) -> Self { + Self::Decoding(DecodingError::InvalidIdentifier(e)) } } impl From for NftTransferError { - fn from(err: DecodingError) -> Self { - Self::Decoding(err) + fn from(e: DecodingError) -> Self { + Self::Decoding(e) } } impl From for StatusValue { - fn from(err: NftTransferError) -> Self { - StatusValue::new(err.to_string()).expect("error message must not be empty") + fn from(e: NftTransferError) -> Self { + StatusValue::new(e.to_string()).expect("error message must not be empty") } } diff --git a/ibc-apps/ics721-nft-transfer/types/src/msgs/transfer.rs b/ibc-apps/ics721-nft-transfer/types/src/msgs/transfer.rs index cfb279c27..8412f333f 100644 --- a/ibc-apps/ics721-nft-transfer/types/src/msgs/transfer.rs +++ b/ibc-apps/ics721-nft-transfer/types/src/msgs/transfer.rs @@ -3,9 +3,9 @@ use ibc_core::channel::types::error::PacketError; use ibc_core::channel::types::timeout::{TimeoutHeight, TimeoutTimestamp}; use ibc_core::handler::types::error::ContextError; +use ibc_core::host::types::error::DecodingError; use ibc_core::host::types::identifiers::{ChannelId, PortId}; use ibc_core::primitives::prelude::*; -use ibc_core::primitives::DecodingError; use ibc_proto::google::protobuf::Any; use ibc_proto::ibc::applications::nft_transfer::v1::MsgTransfer as RawMsgTransfer; use ibc_proto::Protobuf; diff --git a/ibc-apps/ics721-nft-transfer/types/src/packet.rs b/ibc-apps/ics721-nft-transfer/types/src/packet.rs index 1eb970bba..4dcde60a8 100644 --- a/ibc-apps/ics721-nft-transfer/types/src/packet.rs +++ b/ibc-apps/ics721-nft-transfer/types/src/packet.rs @@ -2,10 +2,11 @@ use base64::prelude::BASE64_STANDARD; use base64::Engine; +use ibc_core::host::types::error::DecodingError; use ibc_core::primitives::prelude::*; #[cfg(feature = "serde")] use ibc_core::primitives::serializers; -use ibc_core::primitives::{DecodingError, Signer}; +use ibc_core::primitives::Signer; use ibc_proto::ibc::applications::nft_transfer::v1::NonFungibleTokenPacketData as RawPacketData; use crate::class::{ClassData, ClassUri, PrefixedClassId}; diff --git a/ibc-apps/ics721-nft-transfer/types/src/token.rs b/ibc-apps/ics721-nft-transfer/types/src/token.rs index aeb141f20..3c1e56aeb 100644 --- a/ibc-apps/ics721-nft-transfer/types/src/token.rs +++ b/ibc-apps/ics721-nft-transfer/types/src/token.rs @@ -3,10 +3,10 @@ use core::fmt::{self, Display}; use core::str::FromStr; use http::Uri; +use ibc_core::host::types::error::DecodingError; use ibc_core::primitives::prelude::*; #[cfg(feature = "serde")] use ibc_core::primitives::serializers; -use ibc_core::primitives::DecodingError; use crate::data::Data; use crate::error::NftTransferError; diff --git a/ibc-clients/ics07-tendermint/src/client_state/common.rs b/ibc-clients/ics07-tendermint/src/client_state/common.rs index 3671e6bd6..4528447cf 100644 --- a/ibc-clients/ics07-tendermint/src/client_state/common.rs +++ b/ibc-clients/ics07-tendermint/src/client_state/common.rs @@ -166,7 +166,7 @@ pub fn verify_consensus_state( }; if consensus_state_status(&tm_consensus_state, host_timestamp, trusting_period)?.is_expired() { - return Err(ClientError::Status(StatusError::UnexpectedStatus( + return Err(ClientError::ClientStatus(StatusError::UnexpectedStatus( Status::Expired, ))); } diff --git a/ibc-clients/ics07-tendermint/types/src/consensus_state.rs b/ibc-clients/ics07-tendermint/types/src/consensus_state.rs index 62e0b35de..3008b756b 100644 --- a/ibc-clients/ics07-tendermint/types/src/consensus_state.rs +++ b/ibc-clients/ics07-tendermint/types/src/consensus_state.rs @@ -2,8 +2,8 @@ use ibc_core_client_types::error::ClientError; use ibc_core_commitment_types::commitment::CommitmentRoot; +use ibc_core_host_types::error::DecodingError; use ibc_primitives::prelude::*; -use ibc_primitives::DecodingError; use ibc_proto::google::protobuf::Any; use ibc_proto::ibc::lightclients::tendermint::v1::ConsensusState as RawConsensusState; use ibc_proto::Protobuf; diff --git a/ibc-clients/ics07-tendermint/types/src/header.rs b/ibc-clients/ics07-tendermint/types/src/header.rs index b63f80408..085bec887 100644 --- a/ibc-clients/ics07-tendermint/types/src/header.rs +++ b/ibc-clients/ics07-tendermint/types/src/header.rs @@ -5,9 +5,9 @@ use core::str::FromStr; use ibc_core_client_types::error::ClientError; use ibc_core_client_types::Height; +use ibc_core_host_types::error::DecodingError; use ibc_core_host_types::identifiers::ChainId; use ibc_primitives::prelude::*; -use ibc_primitives::DecodingError; use ibc_primitives::Timestamp; use ibc_proto::google::protobuf::Any; use ibc_proto::ibc::lightclients::tendermint::v1::Header as RawHeader; diff --git a/ibc-clients/ics07-tendermint/types/src/misbehaviour.rs b/ibc-clients/ics07-tendermint/types/src/misbehaviour.rs index b50cdb0d4..059b4b4ee 100644 --- a/ibc-clients/ics07-tendermint/types/src/misbehaviour.rs +++ b/ibc-clients/ics07-tendermint/types/src/misbehaviour.rs @@ -1,9 +1,9 @@ //! Defines the misbehaviour type for the tendermint light client use ibc_core_client_types::error::ClientError; +use ibc_core_host_types::error::DecodingError; use ibc_core_host_types::identifiers::ClientId; use ibc_primitives::prelude::*; -use ibc_primitives::DecodingError; use ibc_proto::google::protobuf::Any; use ibc_proto::ibc::lightclients::tendermint::v1::Misbehaviour as RawMisbehaviour; use ibc_proto::Protobuf; diff --git a/ibc-clients/ics08-wasm/types/src/client_state.rs b/ibc-clients/ics08-wasm/types/src/client_state.rs index a99bb7547..acc2fbecd 100644 --- a/ibc-clients/ics08-wasm/types/src/client_state.rs +++ b/ibc-clients/ics08-wasm/types/src/client_state.rs @@ -1,9 +1,9 @@ //! Defines the client state type for the ICS-08 Wasm light client. use ibc_core_client::types::Height; +use ibc_core_host_types::error::DecodingError; use ibc_primitives::prelude::*; use ibc_primitives::proto::{Any, Protobuf}; -use ibc_primitives::DecodingError; use ibc_proto::ibc::lightclients::wasm::v1::ClientState as RawClientState; use crate::error::WasmClientError; diff --git a/ibc-clients/ics08-wasm/types/src/consensus_state.rs b/ibc-clients/ics08-wasm/types/src/consensus_state.rs index ed84364a6..588455b9b 100644 --- a/ibc-clients/ics08-wasm/types/src/consensus_state.rs +++ b/ibc-clients/ics08-wasm/types/src/consensus_state.rs @@ -1,9 +1,9 @@ //! Defines the consensus state type for the ICS-08 Wasm light client. use ibc_core_client::types::error::ClientError; +use ibc_core_host_types::error::DecodingError; use ibc_primitives::prelude::*; use ibc_primitives::proto::{Any, Protobuf}; -use ibc_primitives::DecodingError; use ibc_proto::ibc::lightclients::wasm::v1::ConsensusState as RawConsensusState; #[cfg(feature = "serde")] diff --git a/ibc-clients/ics08-wasm/types/src/error.rs b/ibc-clients/ics08-wasm/types/src/error.rs index 3ec6c9ea5..513bdddad 100644 --- a/ibc-clients/ics08-wasm/types/src/error.rs +++ b/ibc-clients/ics08-wasm/types/src/error.rs @@ -1,9 +1,9 @@ //! Defines the error type for the ICS-08 Wasm light client. use displaydoc::Display; +use ibc_core_host_types::error::DecodingError; use ibc_core_host_types::error::IdentifierError; use ibc_primitives::prelude::*; -use ibc_primitives::DecodingError; /// The main error type #[derive(Debug, Display)] diff --git a/ibc-core/ics02-client/src/handler/create_client.rs b/ibc-core/ics02-client/src/handler/create_client.rs index d775ddf02..1663c2cc4 100644 --- a/ibc-core/ics02-client/src/handler/create_client.rs +++ b/ibc-core/ics02-client/src/handler/create_client.rs @@ -36,7 +36,9 @@ where let status = client_state.status(client_val_ctx, &client_id)?; if status.is_frozen() { - return Err(ClientError::Status(StatusError::UnexpectedStatus(Status::Frozen)).into()); + return Err( + ClientError::ClientStatus(StatusError::UnexpectedStatus(Status::Frozen)).into(), + ); }; let host_timestamp = ctx.host_timestamp()?; diff --git a/ibc-core/ics02-client/src/handler/recover_client.rs b/ibc-core/ics02-client/src/handler/recover_client.rs index 8c24bbbce..c48aae2ec 100644 --- a/ibc-core/ics02-client/src/handler/recover_client.rs +++ b/ibc-core/ics02-client/src/handler/recover_client.rs @@ -40,13 +40,13 @@ where substitute_client_state .status(ctx.get_client_validation_context(), &substitute_client_id)? .verify_is_active() - .map_err(ClientError::Status)?; // TODO(seanchen1991): Why is this `map_err` necessary? + .map_err(ClientError::ClientStatus)?; // TODO(seanchen1991): Why is this `map_err` necessary? // Verify that the subject client is inactive, i.e., that it is either frozen or expired subject_client_state .status(ctx.get_client_validation_context(), &subject_client_id)? .verify_is_inactive() - .map_err(ClientError::Status)?; + .map_err(ClientError::ClientStatus)?; // Check that the subject client state and substitute client states match, i.e., that // all their respective client state parameters match except for frozen height, latest diff --git a/ibc-core/ics02-client/src/handler/update_client.rs b/ibc-core/ics02-client/src/handler/update_client.rs index f67debcbd..d2a18b8b5 100644 --- a/ibc-core/ics02-client/src/handler/update_client.rs +++ b/ibc-core/ics02-client/src/handler/update_client.rs @@ -27,7 +27,7 @@ where client_state .status(client_val_ctx, &client_id)? .verify_is_active() - .map_err(ClientError::Status)?; + .map_err(ClientError::ClientStatus)?; let client_message = msg.client_message(); diff --git a/ibc-core/ics02-client/src/handler/upgrade_client.rs b/ibc-core/ics02-client/src/handler/upgrade_client.rs index c79cbcb93..475e86c1d 100644 --- a/ibc-core/ics02-client/src/handler/upgrade_client.rs +++ b/ibc-core/ics02-client/src/handler/upgrade_client.rs @@ -29,7 +29,7 @@ where old_client_state .status(client_val_ctx, &client_id)? .verify_is_active() - .map_err(ClientError::Status)?; + .map_err(ClientError::ClientStatus)?; // Read the latest consensus state from the host chain store. let old_client_cons_state_path = ClientConsensusStatePath::new( diff --git a/ibc-core/ics02-client/types/src/error.rs b/ibc-core/ics02-client/types/src/error.rs index 6ecb663dd..e11268cd7 100644 --- a/ibc-core/ics02-client/types/src/error.rs +++ b/ibc-core/ics02-client/types/src/error.rs @@ -4,10 +4,10 @@ use core::convert::Infallible; use displaydoc::Display; use ibc_core_commitment_types::error::CommitmentError; -use ibc_core_host_types::error::IdentifierError; +use ibc_core_host_types::error::{DecodingError, IdentifierError}; use ibc_core_host_types::identifiers::ClientId; use ibc_primitives::prelude::*; -use ibc_primitives::{DecodingError, Timestamp}; +use ibc_primitives::Timestamp; use crate::height::Height; use crate::StatusError; @@ -20,7 +20,9 @@ pub enum ClientError { /// decoding error: `{0}` Decoding(DecodingError), /// client status error: `{0}` - Status(StatusError), + ClientStatus(StatusError), + /// invalid header type: `{0}` + InvalidHeaderType(String), /// invalid trust threshold: `{numerator}`/`{denominator}` InvalidTrustThreshold { numerator: u64, denominator: u64 }, /// invalid client state type: `{0}` @@ -111,7 +113,7 @@ impl From for ClientError { impl From for ClientError { fn from(e: StatusError) -> Self { - Self::Status(e) + Self::ClientStatus(e) } } @@ -121,7 +123,7 @@ impl std::error::Error for ClientError { match &self { Self::InvalidClientIdentifier(e) => Some(e), Self::FailedICS23Verification(e) => Some(e), - Self::Status(e) => Some(e), + Self::ClientStatus(e) => Some(e), Self::Decoding(e) => Some(e), _ => None, } diff --git a/ibc-core/ics03-connection/src/handler/conn_open_ack.rs b/ibc-core/ics03-connection/src/handler/conn_open_ack.rs index 05bdc0fcb..493bb1f8d 100644 --- a/ibc-core/ics03-connection/src/handler/conn_open_ack.rs +++ b/ibc-core/ics03-connection/src/handler/conn_open_ack.rs @@ -68,7 +68,7 @@ where client_state_of_b_on_a .status(client_val_ctx_a, vars.client_id_on_a())? .verify_is_active() - .map_err(ClientError::Status)?; + .map_err(ClientError::ClientStatus)?; client_state_of_b_on_a.validate_proof_height(msg.proofs_height_on_b)?; diff --git a/ibc-core/ics03-connection/src/handler/conn_open_confirm.rs b/ibc-core/ics03-connection/src/handler/conn_open_confirm.rs index 2dd0105f3..b622a3037 100644 --- a/ibc-core/ics03-connection/src/handler/conn_open_confirm.rs +++ b/ibc-core/ics03-connection/src/handler/conn_open_confirm.rs @@ -49,7 +49,7 @@ where client_state_of_a_on_b .status(client_val_ctx_b, client_id_on_b)? .verify_is_active() - .map_err(ClientError::Status)?; + .map_err(ClientError::ClientStatus)?; client_state_of_a_on_b.validate_proof_height(msg.proof_height_on_a)?; diff --git a/ibc-core/ics03-connection/src/handler/conn_open_init.rs b/ibc-core/ics03-connection/src/handler/conn_open_init.rs index ad6c8de4f..f6196a787 100644 --- a/ibc-core/ics03-connection/src/handler/conn_open_init.rs +++ b/ibc-core/ics03-connection/src/handler/conn_open_init.rs @@ -25,7 +25,7 @@ where client_state_of_b_on_a .status(client_val_ctx_a, &msg.client_id_on_a)? .verify_is_active() - .map_err(ClientError::Status)?; + .map_err(ClientError::ClientStatus)?; if let Some(version) = msg.version { version.verify_is_supported(&ctx_a.get_compatible_versions())?; diff --git a/ibc-core/ics03-connection/src/handler/conn_open_try.rs b/ibc-core/ics03-connection/src/handler/conn_open_try.rs index 606a55a49..4c86a6261 100644 --- a/ibc-core/ics03-connection/src/handler/conn_open_try.rs +++ b/ibc-core/ics03-connection/src/handler/conn_open_try.rs @@ -68,7 +68,7 @@ where client_state_of_a_on_b .status(client_val_ctx_b, &msg.client_id_on_b)? .verify_is_active() - .map_err(ClientError::Status)?; + .map_err(ClientError::ClientStatus)?; client_state_of_a_on_b.validate_proof_height(msg.proofs_height_on_a)?; diff --git a/ibc-core/ics04-channel/src/handler/acknowledgement.rs b/ibc-core/ics04-channel/src/handler/acknowledgement.rs index 659befb1b..a0cb98e86 100644 --- a/ibc-core/ics04-channel/src/handler/acknowledgement.rs +++ b/ibc-core/ics04-channel/src/handler/acknowledgement.rs @@ -178,7 +178,7 @@ where client_state_of_b_on_a .status(ctx_a.get_client_validation_context(), client_id_on_a)? .verify_is_active() - .map_err(ClientError::Status)?; + .map_err(ClientError::ClientStatus)?; client_state_of_b_on_a.validate_proof_height(msg.proof_height_on_b)?; diff --git a/ibc-core/ics04-channel/src/handler/chan_close_confirm.rs b/ibc-core/ics04-channel/src/handler/chan_close_confirm.rs index 25f8ebbc9..fb3479864 100644 --- a/ibc-core/ics04-channel/src/handler/chan_close_confirm.rs +++ b/ibc-core/ics04-channel/src/handler/chan_close_confirm.rs @@ -115,7 +115,7 @@ where client_state_of_a_on_b .status(ctx_b.get_client_validation_context(), client_id_on_b)? .verify_is_active() - .map_err(ClientError::Status)?; + .map_err(ClientError::ClientStatus)?; client_state_of_a_on_b.validate_proof_height(msg.proof_height_on_a)?; diff --git a/ibc-core/ics04-channel/src/handler/chan_close_init.rs b/ibc-core/ics04-channel/src/handler/chan_close_init.rs index dbe604ef6..ba2bd2585 100644 --- a/ibc-core/ics04-channel/src/handler/chan_close_init.rs +++ b/ibc-core/ics04-channel/src/handler/chan_close_init.rs @@ -112,7 +112,7 @@ where client_state_of_b_on_a .status(ctx_a.get_client_validation_context(), client_id_on_a)? .verify_is_active() - .map_err(ClientError::Status)?; + .map_err(ClientError::ClientStatus)?; Ok(()) } diff --git a/ibc-core/ics04-channel/src/handler/chan_open_ack.rs b/ibc-core/ics04-channel/src/handler/chan_open_ack.rs index 34d43c33a..bc3506652 100644 --- a/ibc-core/ics04-channel/src/handler/chan_open_ack.rs +++ b/ibc-core/ics04-channel/src/handler/chan_open_ack.rs @@ -116,7 +116,7 @@ where client_state_of_b_on_a .status(ctx_a.get_client_validation_context(), client_id_on_a)? .verify_is_active() - .map_err(ClientError::Status)?; + .map_err(ClientError::ClientStatus)?; client_state_of_b_on_a.validate_proof_height(msg.proof_height_on_b)?; diff --git a/ibc-core/ics04-channel/src/handler/chan_open_confirm.rs b/ibc-core/ics04-channel/src/handler/chan_open_confirm.rs index a3d05dddf..71ad5a00f 100644 --- a/ibc-core/ics04-channel/src/handler/chan_open_confirm.rs +++ b/ibc-core/ics04-channel/src/handler/chan_open_confirm.rs @@ -120,7 +120,7 @@ where client_state_of_a_on_b .status(ctx_b.get_client_validation_context(), client_id_on_b)? .verify_is_active() - .map_err(ClientError::Status)?; + .map_err(ClientError::ClientStatus)?; client_state_of_a_on_b.validate_proof_height(msg.proof_height_on_a)?; diff --git a/ibc-core/ics04-channel/src/handler/chan_open_init.rs b/ibc-core/ics04-channel/src/handler/chan_open_init.rs index a8b917cf9..0553b7b1d 100644 --- a/ibc-core/ics04-channel/src/handler/chan_open_init.rs +++ b/ibc-core/ics04-channel/src/handler/chan_open_init.rs @@ -127,7 +127,7 @@ where client_state_of_b_on_a .status(ctx_a.get_client_validation_context(), client_id_on_a)? .verify_is_active() - .map_err(ClientError::Status)?; + .map_err(ClientError::ClientStatus)?; let conn_version = conn_end_on_a.versions(); diff --git a/ibc-core/ics04-channel/src/handler/chan_open_try.rs b/ibc-core/ics04-channel/src/handler/chan_open_try.rs index 54807c1be..738f8d67c 100644 --- a/ibc-core/ics04-channel/src/handler/chan_open_try.rs +++ b/ibc-core/ics04-channel/src/handler/chan_open_try.rs @@ -142,7 +142,7 @@ where client_state_of_a_on_b .status(ctx_b.get_client_validation_context(), client_id_on_b)? .verify_is_active() - .map_err(ClientError::Status)?; + .map_err(ClientError::ClientStatus)?; client_state_of_a_on_b.validate_proof_height(msg.proof_height_on_a)?; diff --git a/ibc-core/ics04-channel/src/handler/recv_packet.rs b/ibc-core/ics04-channel/src/handler/recv_packet.rs index e9f7b7101..fe7230b20 100644 --- a/ibc-core/ics04-channel/src/handler/recv_packet.rs +++ b/ibc-core/ics04-channel/src/handler/recv_packet.rs @@ -188,7 +188,7 @@ where client_state_of_a_on_b .status(ctx_b.get_client_validation_context(), client_id_on_b)? .verify_is_active() - .map_err(ClientError::Status)?; + .map_err(ClientError::ClientStatus)?; client_state_of_a_on_b.validate_proof_height(msg.proof_height_on_a)?; diff --git a/ibc-core/ics04-channel/src/handler/send_packet.rs b/ibc-core/ics04-channel/src/handler/send_packet.rs index 714242383..6247197cf 100644 --- a/ibc-core/ics04-channel/src/handler/send_packet.rs +++ b/ibc-core/ics04-channel/src/handler/send_packet.rs @@ -61,7 +61,7 @@ pub fn send_packet_validate( client_state_of_b_on_a .status(ctx_a.get_client_validation_context(), client_id_on_a)? .verify_is_active() - .map_err(ClientError::Status)?; + .map_err(ClientError::ClientStatus)?; let latest_height_on_a = client_state_of_b_on_a.latest_height(); diff --git a/ibc-core/ics04-channel/src/handler/timeout.rs b/ibc-core/ics04-channel/src/handler/timeout.rs index 5963f810a..325803985 100644 --- a/ibc-core/ics04-channel/src/handler/timeout.rs +++ b/ibc-core/ics04-channel/src/handler/timeout.rs @@ -188,7 +188,7 @@ where client_state_of_b_on_a .status(ctx_a.get_client_validation_context(), client_id_on_a)? .verify_is_active() - .map_err(ClientError::Status)?; + .map_err(ClientError::ClientStatus)?; client_state_of_b_on_a.validate_proof_height(msg.proof_height_on_b)?; diff --git a/ibc-core/ics04-channel/src/handler/timeout_on_close.rs b/ibc-core/ics04-channel/src/handler/timeout_on_close.rs index eda55002a..0d31ae234 100644 --- a/ibc-core/ics04-channel/src/handler/timeout_on_close.rs +++ b/ibc-core/ics04-channel/src/handler/timeout_on_close.rs @@ -72,7 +72,7 @@ where client_state_of_b_on_a .status(ctx_a.get_client_validation_context(), client_id_on_a)? .verify_is_active() - .map_err(ClientError::Status)?; + .map_err(ClientError::ClientStatus)?; client_state_of_b_on_a.validate_proof_height(msg.proof_height_on_b)?; diff --git a/ibc-core/ics24-host/cosmos/src/upgrade_proposal/plan.rs b/ibc-core/ics24-host/cosmos/src/upgrade_proposal/plan.rs index 3a37c87f5..33f1ad782 100644 --- a/ibc-core/ics24-host/cosmos/src/upgrade_proposal/plan.rs +++ b/ibc-core/ics24-host/cosmos/src/upgrade_proposal/plan.rs @@ -1,8 +1,8 @@ //! Definition of domain `Plan` type. use ibc_core_client_types::error::UpgradeClientError; +use ibc_core_host_types::error::DecodingError; use ibc_primitives::prelude::*; -use ibc_primitives::DecodingError; use ibc_proto::cosmos::upgrade::v1beta1::Plan as RawPlan; use ibc_proto::google::protobuf::Any; use ibc_proto::Protobuf; diff --git a/ibc-core/ics24-host/cosmos/src/validate_self_client.rs b/ibc-core/ics24-host/cosmos/src/validate_self_client.rs index 446c3ebbf..6f72e2937 100644 --- a/ibc-core/ics24-host/cosmos/src/validate_self_client.rs +++ b/ibc-core/ics24-host/cosmos/src/validate_self_client.rs @@ -25,7 +25,9 @@ pub trait ValidateSelfClientContext { .map_err(ClientError::from)?; if client_state_of_host_on_counterparty.is_frozen() { - return Err(ClientError::Status(StatusError::UnexpectedStatus(Status::Frozen)).into()); + return Err( + ClientError::ClientStatus(StatusError::UnexpectedStatus(Status::Frozen)).into(), + ); } let self_chain_id = self.chain_id(); diff --git a/ibc-core/ics24-host/types/Cargo.toml b/ibc-core/ics24-host/types/Cargo.toml index 7ad95dcc0..b1126d300 100644 --- a/ibc-core/ics24-host/types/Cargo.toml +++ b/ibc-core/ics24-host/types/Cargo.toml @@ -23,6 +23,7 @@ all-features = true borsh = { workspace = true, optional = true } derive_more = { workspace = true } displaydoc = { workspace = true } +http = { version = "1.1.0" } schemars = { workspace = true, optional = true } serde = { workspace = true, optional = true } @@ -33,6 +34,9 @@ ibc-primitives = { workspace = true } parity-scale-codec = { workspace = true, optional = true } scale-info = { workspace = true, optional = true } +# cosmos dependencies +tendermint-proto = { workspace = true } + [dev-dependencies] rstest = { workspace = true } serde-json = { workspace = true } diff --git a/ibc-core/ics24-host/types/src/error.rs b/ibc-core/ics24-host/types/src/error.rs index 72d8535c2..721adfa5f 100644 --- a/ibc-core/ics24-host/types/src/error.rs +++ b/ibc-core/ics24-host/types/src/error.rs @@ -1,5 +1,12 @@ +//! Foundational error types that are applicable across multiple ibc-rs workspaces. + +use alloc::string::String; + use displaydoc::Display; +use http::uri::InvalidUri; + use ibc_primitives::prelude::*; +use tendermint_proto::Error as ProtoError; /// Errors that arise when parsing identifiers. #[cfg_attr(feature = "serde", derive(serde::Serialize))] @@ -17,5 +24,33 @@ pub enum IdentifierError { OverflowedRevisionNumber, } +/// Errors that result in decoding failures +#[derive(Debug, Display)] +pub enum DecodingError { + /// invalid identifier error: `{0}` + InvalidIdentifier(IdentifierError), + /// invalid JSON data: `{description}` + InvalidJson { description: String }, + /// invalid UTF-8 data: `{description}` + InvalidUtf8 { description: String }, + /// invalid URI: `{0}` + InvalidUri(InvalidUri), + /// malformed bytes that could not be decoded: `{description}` + MalformedBytes { description: String }, + /// mismatched type URLs: expected `{expected}`, actual `{actual}` + MismatchedTypeUrls { expected: String, actual: String }, + /// failed to decode proto; error: `{0}` + FailedToDecodeProto(ProtoError), +} + +impl From for DecodingError { + fn from(e: ProtoError) -> Self { + Self::FailedToDecodeProto(e) + } +} + #[cfg(feature = "std")] impl std::error::Error for IdentifierError {} + +#[cfg(feature = "std")] +impl std::error::Error for DecodingError {} diff --git a/ibc-core/ics24-host/types/src/lib.rs b/ibc-core/ics24-host/types/src/lib.rs index f466de4c2..1fae79ac6 100644 --- a/ibc-core/ics24-host/types/src/lib.rs +++ b/ibc-core/ics24-host/types/src/lib.rs @@ -12,6 +12,8 @@ rust_2018_idioms )] +extern crate alloc; + #[cfg(feature = "std")] extern crate std; diff --git a/ibc-core/ics25-handler/types/src/msgs.rs b/ibc-core/ics25-handler/types/src/msgs.rs index cfb13e631..7f1b5c9a5 100644 --- a/ibc-core/ics25-handler/types/src/msgs.rs +++ b/ibc-core/ics25-handler/types/src/msgs.rs @@ -17,9 +17,9 @@ use ibc_core_connection_types::msgs::{ MsgConnectionOpenTry, CONN_OPEN_ACK_TYPE_URL, CONN_OPEN_CONFIRM_TYPE_URL, CONN_OPEN_INIT_TYPE_URL, CONN_OPEN_TRY_TYPE_URL, }; +use ibc_core_host_types::error::DecodingError; use ibc_core_router_types::error::RouterError; use ibc_primitives::prelude::*; -use ibc_primitives::DecodingError; use ibc_proto::google::protobuf::Any; use ibc_proto::Protobuf; diff --git a/ibc-core/ics26-routing/types/src/error.rs b/ibc-core/ics26-routing/types/src/error.rs index b9de1e97a..b64eb2fe6 100644 --- a/ibc-core/ics26-routing/types/src/error.rs +++ b/ibc-core/ics26-routing/types/src/error.rs @@ -1,7 +1,8 @@ use displaydoc::Display; + +use ibc_core_host_types::error::DecodingError; use ibc_core_host_types::identifiers::PortId; use ibc_primitives::prelude::*; -use ibc_primitives::DecodingError; /// Error type for the router module. #[derive(Debug, Display)] diff --git a/ibc-primitives/Cargo.toml b/ibc-primitives/Cargo.toml index e4a5d723d..1e090acf6 100644 --- a/ibc-primitives/Cargo.toml +++ b/ibc-primitives/Cargo.toml @@ -23,7 +23,6 @@ all-features = true borsh = { workspace = true, optional = true } derive_more = { workspace = true } displaydoc = { workspace = true } -http = { version = "1.1.0" } prost = { workspace = true } schemars = { workspace = true, optional = true } serde = { workspace = true, optional = true } diff --git a/ibc-primitives/src/types/error.rs b/ibc-primitives/src/types/error.rs deleted file mode 100644 index 859f94ba6..000000000 --- a/ibc-primitives/src/types/error.rs +++ /dev/null @@ -1,36 +0,0 @@ -//! Foundational error types that are applicable across multiple ibc-rs workspaces. - -use alloc::string::String; - -use displaydoc::Display; -use http::uri::InvalidUri; - -use tendermint_proto::Error as ProtoError; - -/// Causes of decoding failures -#[derive(Debug, Display)] -pub enum DecodingError { - /// invalid identifier error: `{0}` - InvalidIdentifier(String), - /// invalid JSON data: `{description}` - InvalidJson { description: String }, - /// invalid UTF-8 data: `{description}` - InvalidUtf8 { description: String }, - /// invalid URI: `{0}` - InvalidUri(InvalidUri), - /// malformed bytes that could not be decoded: `{description}` - MalformedBytes { description: String }, - /// mismatched type URLs: expected `{expected}`, actual `{actual}` - MismatchedTypeUrls { expected: String, actual: String }, - /// failed to decode proto; error: `{0}` - FailedToDecodeProto(ProtoError), -} - -impl From for DecodingError { - fn from(e: ProtoError) -> Self { - Self::FailedToDecodeProto(e) - } -} - -#[cfg(feature = "std")] -impl std::error::Error for DecodingError {} diff --git a/ibc-primitives/src/types/mod.rs b/ibc-primitives/src/types/mod.rs index 85849f97c..8df0d3c40 100644 --- a/ibc-primitives/src/types/mod.rs +++ b/ibc-primitives/src/types/mod.rs @@ -1,7 +1,5 @@ -mod error; mod signer; mod timestamp; -pub use error::*; pub use signer::*; pub use timestamp::*; diff --git a/ibc-query/src/error.rs b/ibc-query/src/error.rs index 4c41120eb..8e8bd3949 100644 --- a/ibc-query/src/error.rs +++ b/ibc-query/src/error.rs @@ -1,12 +1,14 @@ use alloc::string::{String, ToString}; use displaydoc::Display; +use tonic::Status; + use ibc::core::channel::types::error::{ChannelError, PacketError}; use ibc::core::client::types::error::ClientError; +use ibc::core::client::types::StatusError; use ibc::core::connection::types::error::ConnectionError; use ibc::core::handler::types::error::ContextError; use ibc::core::host::types::error::IdentifierError; -use tonic::Status; /// The main error type of the ibc-query crate. This type mainly /// serves to surface lower-level errors that occur when executing @@ -15,6 +17,8 @@ use tonic::Status; pub enum QueryError { /// context error: `{0}` ContextError(ContextError), + /// client status error: `{0}` + ClientStatus(StatusError), /// identifier error: `{0}` IdentifierError(IdentifierError), /// missing proof: `{0}` @@ -38,6 +42,7 @@ impl From for Status { match e { QueryError::ContextError(ctx_err) => Self::internal(ctx_err.to_string()), QueryError::IdentifierError(id_err) => Self::internal(id_err.to_string()), + QueryError::ClientStatus(status_err) => Self::invalid_argument(status_err.to_string()), QueryError::MissingProof(description) => Self::not_found(description), QueryError::MissingField(description) => Self::invalid_argument(description), } @@ -79,3 +84,9 @@ impl From for QueryError { Self::IdentifierError(e) } } + +impl From for QueryError { + fn from(e: StatusError) -> Self { + Self::ClientStatus(e) + } +} diff --git a/ibc-testkit/src/testapp/ibc/clients/mock/client_state.rs b/ibc-testkit/src/testapp/ibc/clients/mock/client_state.rs index d8f9685ff..6f8cd0533 100644 --- a/ibc-testkit/src/testapp/ibc/clients/mock/client_state.rs +++ b/ibc-testkit/src/testapp/ibc/clients/mock/client_state.rs @@ -4,17 +4,17 @@ use core::time::Duration; use ibc::clients::tendermint::client_state::consensus_state_status; use ibc::core::client::context::prelude::*; use ibc::core::client::types::error::{ClientError, UpgradeClientError}; -use ibc::core::client::types::{Height, Status}; +use ibc::core::client::types::{Height, Status, StatusError}; use ibc::core::commitment_types::commitment::{ CommitmentPrefix, CommitmentProofBytes, CommitmentRoot, }; use ibc::core::handler::types::error::ContextError; +use ibc::core::host::types::error::DecodingError; use ibc::core::host::types::identifiers::{ClientId, ClientType}; use ibc::core::host::types::path::{ClientConsensusStatePath, ClientStatePath, Path, PathBytes}; use ibc::core::primitives::prelude::*; use ibc::core::primitives::Timestamp; use ibc::primitives::proto::{Any, Protobuf}; -use ibc::primitives::DecodingError; use crate::testapp::ibc::clients::mock::client_state::client_type as mock_client_type; use crate::testapp::ibc::clients::mock::consensus_state::MockConsensusState; @@ -172,7 +172,9 @@ impl ClientStateCommon for MockClientState { if consensus_state_status(&mock_consensus_state, host_timestamp, self.trusting_period)? .is_expired() { - return Err(ClientError::InvalidStatus(Status::Expired)); + return Err(ClientError::ClientStatus(StatusError::UnexpectedStatus( + Status::Expired, + ))); } Ok(()) diff --git a/ibc-testkit/src/testapp/ibc/clients/mock/consensus_state.rs b/ibc-testkit/src/testapp/ibc/clients/mock/consensus_state.rs index 4c364d61b..e5d7a2ad5 100644 --- a/ibc-testkit/src/testapp/ibc/clients/mock/consensus_state.rs +++ b/ibc-testkit/src/testapp/ibc/clients/mock/consensus_state.rs @@ -1,10 +1,10 @@ use ibc::core::client::context::consensus_state::ConsensusState; use ibc::core::client::types::error::ClientError; use ibc::core::commitment_types::commitment::CommitmentRoot; +use ibc::core::host::types::error::DecodingError; use ibc::core::primitives::prelude::*; use ibc::core::primitives::Timestamp; use ibc::primitives::proto::{Any, Protobuf}; -use ibc::primitives::DecodingError; use crate::testapp::ibc::clients::mock::header::MockHeader; use crate::testapp::ibc::clients::mock::proto::ConsensusState as RawMockConsensusState; diff --git a/ibc-testkit/src/testapp/ibc/clients/mock/header.rs b/ibc-testkit/src/testapp/ibc/clients/mock/header.rs index e95e4685f..f6ac8f11e 100644 --- a/ibc-testkit/src/testapp/ibc/clients/mock/header.rs +++ b/ibc-testkit/src/testapp/ibc/clients/mock/header.rs @@ -3,6 +3,7 @@ use core::fmt::{Display, Error as FmtError, Formatter}; use ibc::core::client::types::error::ClientError; use ibc::core::client::types::Height; +use ibc::core::host::types::error::DecodingError; use ibc::core::primitives::Timestamp; use ibc::primitives::proto::{Any, Protobuf}; @@ -95,7 +96,8 @@ impl TryFrom for MockHeader { fn try_from(raw: Any) -> Result { match raw.type_url.as_str() { - MOCK_HEADER_TYPE_URL => Ok(Protobuf::::decode_vec(&raw.value)?), + MOCK_HEADER_TYPE_URL => Protobuf::::decode_vec(&raw.value) + .map_err(|e| ClientError::Decoding(DecodingError::FailedToDecodeProto(e))), _ => Err(ClientError::Decoding(DecodingError::MismatchedTypeUrls { expected: MOCK_HEADER_TYPE_URL.to_string(), actual: raw.type_url, diff --git a/ibc-testkit/src/testapp/ibc/clients/mock/misbehaviour.rs b/ibc-testkit/src/testapp/ibc/clients/mock/misbehaviour.rs index af8434b25..83b07623a 100644 --- a/ibc-testkit/src/testapp/ibc/clients/mock/misbehaviour.rs +++ b/ibc-testkit/src/testapp/ibc/clients/mock/misbehaviour.rs @@ -1,8 +1,8 @@ use ibc::core::client::types::error::ClientError; +use ibc::core::host::types::error::DecodingError; use ibc::core::host::types::identifiers::ClientId; use ibc::core::primitives::prelude::*; use ibc::primitives::proto::{Any, Protobuf}; -use ibc::primitives::DecodingError; use crate::testapp::ibc::clients::mock::header::MockHeader; use crate::testapp::ibc::clients::mock::proto::Misbehaviour as RawMisbehaviour; diff --git a/ibc-testkit/src/testapp/ibc/core/core_ctx.rs b/ibc-testkit/src/testapp/ibc/core/core_ctx.rs index b01dfa3f7..41333372e 100644 --- a/ibc-testkit/src/testapp/ibc/core/core_ctx.rs +++ b/ibc-testkit/src/testapp/ibc/core/core_ctx.rs @@ -11,7 +11,7 @@ use ibc::core::channel::types::error::{ChannelError, PacketError}; use ibc::core::channel::types::packet::{PacketState, Receipt}; use ibc::core::client::context::consensus_state::ConsensusState; use ibc::core::client::types::error::ClientError; -use ibc::core::client::types::{Height, Status}; +use ibc::core::client::types::{Height, Status, StatusError}; use ibc::core::commitment_types::commitment::CommitmentPrefix; use ibc::core::commitment_types::merkle::MerkleProof; use ibc::core::connection::types::error::ConnectionError; @@ -80,7 +80,9 @@ where client_state_of_host_on_counterparty: Self::HostClientState, ) -> Result<(), ContextError> { if client_state_of_host_on_counterparty.is_frozen() { - return Err(ClientError::Status(StatusError::UnexpectedStatus(Status::Frozen)).into()); + return Err( + ClientError::ClientStatus(StatusError::UnexpectedStatus(Status::Frozen)).into(), + ); } let latest_height = self.host_height()?; diff --git a/tests-integration/tests/core/ics02_client/create_client.rs b/tests-integration/tests/core/ics02_client/create_client.rs index 78c4f8392..3ab8712a3 100644 --- a/tests-integration/tests/core/ics02_client/create_client.rs +++ b/tests-integration/tests/core/ics02_client/create_client.rs @@ -13,7 +13,7 @@ use ibc::core::handler::types::msgs::MsgEnvelope; use ibc::core::host::types::identifiers::ClientId; use ibc::core::host::types::path::{ClientConsensusStatePath, NextClientSequencePath}; use ibc::core::host::{ClientStateRef, ValidationContext}; -use ibc_core_client_types::Status; +use ibc_core_client_types::{Status, StatusError}; use ibc_query::core::context::ProvableContext; use ibc_testkit::context::{MockContext, TendermintContext}; use ibc_testkit::fixtures::clients::tendermint::dummy_tm_client_state_from_header; @@ -180,8 +180,8 @@ fn test_create_expired_mock_client() { let fxt = create_client_fixture(Ctx::Default, Msg::ExpiredMockHeader); create_client_validate( &fxt, - Expect::Failure(Some(ContextError::ClientError(ClientError::InvalidStatus( - Status::Expired, + Expect::Failure(Some(ContextError::ClientError(ClientError::ClientStatus( + StatusError::UnexpectedStatus(Status::Expired), )))), ); } @@ -206,8 +206,8 @@ fn test_create_expired_tm_client() { let fxt = create_client_fixture(Ctx::Default, Msg::ExpiredTendermintHeader); create_client_validate( &fxt, - Expect::Failure(Some(ContextError::ClientError(ClientError::InvalidStatus( - Status::Expired, + Expect::Failure(Some(ContextError::ClientError(ClientError::ClientStatus( + StatusError::UnexpectedStatus(Status::Expired), )))), ); } @@ -218,8 +218,8 @@ fn test_create_frozen_tm_client() { let fxt = create_client_fixture(Ctx::Default, Msg::FrozenTendermintHeader); create_client_validate( &fxt, - Expect::Failure(Some(ContextError::ClientError(ClientError::InvalidStatus( - Status::Frozen, + Expect::Failure(Some(ContextError::ClientError(ClientError::ClientStatus( + StatusError::UnexpectedStatus(Status::Frozen), )))), ); } From ec37db2af39fa0e33eeeb97943462837de5e2a47 Mon Sep 17 00:00:00 2001 From: Sean Chen Date: Wed, 28 Aug 2024 09:36:23 -0500 Subject: [PATCH 13/73] Cargo nightly fmt --- ibc-apps/ics20-transfer/types/src/error.rs | 3 +-- ibc-apps/ics721-nft-transfer/types/src/error.rs | 6 ++---- ibc-clients/ics08-wasm/types/src/error.rs | 3 +-- ibc-core/ics24-host/types/src/error.rs | 1 - ibc-core/ics26-routing/types/src/error.rs | 1 - ibc-query/src/error.rs | 3 +-- 6 files changed, 5 insertions(+), 12 deletions(-) diff --git a/ibc-apps/ics20-transfer/types/src/error.rs b/ibc-apps/ics20-transfer/types/src/error.rs index b71ccddda..291a12635 100644 --- a/ibc-apps/ics20-transfer/types/src/error.rs +++ b/ibc-apps/ics20-transfer/types/src/error.rs @@ -5,8 +5,7 @@ use displaydoc::Display; use ibc_core::channel::types::acknowledgement::StatusValue; use ibc_core::channel::types::channel::Order; use ibc_core::handler::types::error::ContextError; -use ibc_core::host::types::error::DecodingError; -use ibc_core::host::types::error::IdentifierError; +use ibc_core::host::types::error::{DecodingError, IdentifierError}; use ibc_core::host::types::identifiers::{ChannelId, PortId}; use ibc_core::primitives::prelude::*; use uint::FromDecStrErr; diff --git a/ibc-apps/ics721-nft-transfer/types/src/error.rs b/ibc-apps/ics721-nft-transfer/types/src/error.rs index 32f55ce29..8e5497c6b 100644 --- a/ibc-apps/ics721-nft-transfer/types/src/error.rs +++ b/ibc-apps/ics721-nft-transfer/types/src/error.rs @@ -1,16 +1,14 @@ //! Defines the Non-Fungible Token Transfer (ICS-721) error types. use core::convert::Infallible; +use displaydoc::Display; use ibc_core::channel::types::acknowledgement::StatusValue; use ibc_core::channel::types::channel::Order; use ibc_core::handler::types::error::ContextError; -use ibc_core::host::types::error::DecodingError; -use ibc_core::host::types::error::IdentifierError; +use ibc_core::host::types::error::{DecodingError, IdentifierError}; use ibc_core::host::types::identifiers::{ChannelId, PortId}; use ibc_core::primitives::prelude::*; -use displaydoc::Display; - #[derive(Display, Debug)] pub enum NftTransferError { /// context error: `{0}` diff --git a/ibc-clients/ics08-wasm/types/src/error.rs b/ibc-clients/ics08-wasm/types/src/error.rs index 513bdddad..b94a14b53 100644 --- a/ibc-clients/ics08-wasm/types/src/error.rs +++ b/ibc-clients/ics08-wasm/types/src/error.rs @@ -1,8 +1,7 @@ //! Defines the error type for the ICS-08 Wasm light client. use displaydoc::Display; -use ibc_core_host_types::error::DecodingError; -use ibc_core_host_types::error::IdentifierError; +use ibc_core_host_types::error::{DecodingError, IdentifierError}; use ibc_primitives::prelude::*; /// The main error type diff --git a/ibc-core/ics24-host/types/src/error.rs b/ibc-core/ics24-host/types/src/error.rs index 721adfa5f..972b36c40 100644 --- a/ibc-core/ics24-host/types/src/error.rs +++ b/ibc-core/ics24-host/types/src/error.rs @@ -4,7 +4,6 @@ use alloc::string::String; use displaydoc::Display; use http::uri::InvalidUri; - use ibc_primitives::prelude::*; use tendermint_proto::Error as ProtoError; diff --git a/ibc-core/ics26-routing/types/src/error.rs b/ibc-core/ics26-routing/types/src/error.rs index b64eb2fe6..aab2fa8fd 100644 --- a/ibc-core/ics26-routing/types/src/error.rs +++ b/ibc-core/ics26-routing/types/src/error.rs @@ -1,5 +1,4 @@ use displaydoc::Display; - use ibc_core_host_types::error::DecodingError; use ibc_core_host_types::identifiers::PortId; use ibc_primitives::prelude::*; diff --git a/ibc-query/src/error.rs b/ibc-query/src/error.rs index 8e8bd3949..badea0b59 100644 --- a/ibc-query/src/error.rs +++ b/ibc-query/src/error.rs @@ -1,14 +1,13 @@ use alloc::string::{String, ToString}; use displaydoc::Display; -use tonic::Status; - use ibc::core::channel::types::error::{ChannelError, PacketError}; use ibc::core::client::types::error::ClientError; use ibc::core::client::types::StatusError; use ibc::core::connection::types::error::ConnectionError; use ibc::core::handler::types::error::ContextError; use ibc::core::host::types::error::IdentifierError; +use tonic::Status; /// The main error type of the ibc-query crate. This type mainly /// serves to surface lower-level errors that occur when executing From 6900bd973edfe66b822866f9654e7dd9ad0c2aba Mon Sep 17 00:00:00 2001 From: Sean Chen Date: Wed, 28 Aug 2024 10:41:04 -0500 Subject: [PATCH 14/73] Use DecodingError in more places --- .../ics20-transfer/types/src/msgs/transfer.rs | 2 +- .../ics721-nft-transfer/types/src/error.rs | 4 +- .../types/src/msgs/transfer.rs | 2 +- .../ics721-nft-transfer/types/src/packet.rs | 22 +-- .../types/src/client_state.rs | 17 ++- .../ics23-commitment/types/src/commitment.rs | 3 +- ibc-core/ics23-commitment/types/src/error.rs | 12 +- .../cosmos/src/upgrade_proposal/plan.rs | 2 +- ibc-core/ics24-host/types/Cargo.toml | 1 + ibc-core/ics24-host/types/src/error.rs | 20 +-- ibc-core/ics25-handler/types/src/msgs.rs | 131 +++++------------- .../src/testapp/ibc/clients/mock/header.rs | 2 +- 12 files changed, 82 insertions(+), 136 deletions(-) diff --git a/ibc-apps/ics20-transfer/types/src/msgs/transfer.rs b/ibc-apps/ics20-transfer/types/src/msgs/transfer.rs index b8809d6c9..eefcdbf5d 100644 --- a/ibc-apps/ics20-transfer/types/src/msgs/transfer.rs +++ b/ibc-apps/ics20-transfer/types/src/msgs/transfer.rs @@ -106,7 +106,7 @@ impl TryFrom for MsgTransfer { fn try_from(raw: Any) -> Result { match raw.type_url.as_str() { TYPE_URL => MsgTransfer::decode_vec(&raw.value) - .map_err(|e| TokenTransferError::Decoding(DecodingError::FailedToDecodeProto(e))), + .map_err(|e| TokenTransferError::Decoding(DecodingError::Protobuf(e))), _ => Err(TokenTransferError::Decoding( DecodingError::MismatchedTypeUrls { expected: TYPE_URL.to_string(), diff --git a/ibc-apps/ics721-nft-transfer/types/src/error.rs b/ibc-apps/ics721-nft-transfer/types/src/error.rs index 8e5497c6b..d7303ce17 100644 --- a/ibc-apps/ics721-nft-transfer/types/src/error.rs +++ b/ibc-apps/ics721-nft-transfer/types/src/error.rs @@ -15,6 +15,8 @@ pub enum NftTransferError { ContextError(ContextError), /// decoding error: `{0}` Decoding(DecodingError), + /// identifier error: `{0}` + Identifier(IdentifierError), /// invalid trace `{0}` InvalidTrace(String), /// missing destination channel `{channel_id}` on port `{port_id}` @@ -67,7 +69,7 @@ impl From for NftTransferError { impl From for NftTransferError { fn from(e: IdentifierError) -> Self { - Self::Decoding(DecodingError::InvalidIdentifier(e)) + Self::Identifier(e) } } diff --git a/ibc-apps/ics721-nft-transfer/types/src/msgs/transfer.rs b/ibc-apps/ics721-nft-transfer/types/src/msgs/transfer.rs index 8412f333f..abd73e681 100644 --- a/ibc-apps/ics721-nft-transfer/types/src/msgs/transfer.rs +++ b/ibc-apps/ics721-nft-transfer/types/src/msgs/transfer.rs @@ -124,7 +124,7 @@ impl TryFrom for MsgTransfer { fn try_from(raw: Any) -> Result { match raw.type_url.as_str() { TYPE_URL => MsgTransfer::decode_vec(&raw.value) - .map_err(|e| NftTransferError::Decoding(DecodingError::FailedToDecodeProto(e))), + .map_err(|e| NftTransferError::Decoding(DecodingError::Protobuf(e))), _ => Err(NftTransferError::Decoding( DecodingError::MismatchedTypeUrls { expected: TYPE_URL.to_string(), diff --git a/ibc-apps/ics721-nft-transfer/types/src/packet.rs b/ibc-apps/ics721-nft-transfer/types/src/packet.rs index 4dcde60a8..a0bd962fe 100644 --- a/ibc-apps/ics721-nft-transfer/types/src/packet.rs +++ b/ibc-apps/ics721-nft-transfer/types/src/packet.rs @@ -129,12 +129,8 @@ impl TryFrom for PacketData { } else { let decoded = BASE64_STANDARD .decode(raw_pkt_data.class_data) - .map_err(|e| DecodingError::InvalidJson { - description: e.to_string(), - })?; - let data_str = String::from_utf8(decoded).map_err(|e| DecodingError::InvalidUtf8 { - description: e.to_string(), - })?; + .map_err(DecodingError::Base64)?; + let data_str = String::from_utf8(decoded).map_err(DecodingError::Utf8)?; Some(data_str.parse()?) }; @@ -145,16 +141,10 @@ impl TryFrom for PacketData { .token_data .iter() .map(|data| { - let decoded = - BASE64_STANDARD - .decode(data) - .map_err(|e| DecodingError::InvalidJson { - description: e.to_string(), - })?; - let data_str = - String::from_utf8(decoded).map_err(|e| DecodingError::InvalidUtf8 { - description: e.to_string(), - })?; + let decoded = BASE64_STANDARD + .decode(data) + .map_err(DecodingError::Base64)?; + let data_str = String::from_utf8(decoded).map_err(DecodingError::Utf8)?; data_str.parse() }) .collect(); diff --git a/ibc-clients/ics07-tendermint/types/src/client_state.rs b/ibc-clients/ics07-tendermint/types/src/client_state.rs index 98ce38460..3595a7e4e 100644 --- a/ibc-clients/ics07-tendermint/types/src/client_state.rs +++ b/ibc-clients/ics07-tendermint/types/src/client_state.rs @@ -8,6 +8,7 @@ use ibc_core_client_types::error::ClientError; use ibc_core_client_types::proto::v1::Height as RawHeight; use ibc_core_client_types::Height; use ibc_core_commitment_types::specs::ProofSpecs; +use ibc_core_host_types::error::DecodingError; use ibc_core_host_types::identifiers::ChainId; use ibc_primitives::prelude::*; use ibc_primitives::ZERO_DURATION; @@ -341,17 +342,19 @@ impl TryFrom for ClientState { type Error = ClientError; fn try_from(raw: Any) -> Result { - fn decode_client_state(value: &[u8]) -> Result { - let client_state = - Protobuf::::decode(value).map_err(|e| ClientError::Other { - description: e.to_string(), - })?; + fn decode_client_state(value: &[u8]) -> Result { + let client_state = Protobuf::::decode(value)?; Ok(client_state) } match raw.type_url.as_str() { - TENDERMINT_CLIENT_STATE_TYPE_URL => decode_client_state(&raw.value), - _ => Err(ClientError::InvalidClientStateType(raw.type_url)), + TENDERMINT_CLIENT_STATE_TYPE_URL => { + decode_client_state(&raw.value).map_err(ClientError::Decoding) + } + _ => Err(ClientError::Decoding(DecodingError::MismatchedTypeUrls { + expected: TENDERMINT_CLIENT_STATE_TYPE_URL.to_string(), + actual: raw.type_url, + })), } } } diff --git a/ibc-core/ics23-commitment/types/src/commitment.rs b/ibc-core/ics23-commitment/types/src/commitment.rs index 43506a798..f43162668 100644 --- a/ibc-core/ics23-commitment/types/src/commitment.rs +++ b/ibc-core/ics23-commitment/types/src/commitment.rs @@ -2,6 +2,7 @@ use core::fmt; +use ibc_core_host_types::error::DecodingError; use ibc_primitives::prelude::*; use ibc_primitives::ToVec; use ibc_proto::ibc::core::commitment::v1::MerkleProof as RawMerkleProof; @@ -122,7 +123,7 @@ impl<'a> TryFrom<&'a CommitmentProofBytes> for MerkleProof { fn try_from(value: &'a CommitmentProofBytes) -> Result { Protobuf::::decode(value.as_ref()) - .map_err(|e| CommitmentError::FailedDecoding(e.to_string())) + .map_err(|e| CommitmentError::Decoding(DecodingError::Protobuf(e))) } } diff --git a/ibc-core/ics23-commitment/types/src/error.rs b/ibc-core/ics23-commitment/types/src/error.rs index 81ee26e06..8505de71d 100644 --- a/ibc-core/ics23-commitment/types/src/error.rs +++ b/ibc-core/ics23-commitment/types/src/error.rs @@ -1,10 +1,14 @@ //! Defines the commitment error type use displaydoc::Display; + +use ibc_core_host_types::error::DecodingError; use ibc_primitives::prelude::*; #[derive(Debug, Display)] pub enum CommitmentError { + /// decoding error: `{0}` + Decoding(DecodingError), /// empty commitment prefix EmptyCommitmentPrefix, /// empty commitment root @@ -31,11 +35,15 @@ pub enum CommitmentError { InvalidHashOp(i32), /// invalid length operation: `{0}` InvalidLengthOp(i32), - /// failed decoding commitment proof: `{0}` - FailedDecoding(String), /// failed to verify membership FailedToVerifyMembership, } +impl From for CommitmentError { + fn from(e: DecodingError) -> Self { + Self::Decoding(e) + } +} + #[cfg(feature = "std")] impl std::error::Error for CommitmentError {} diff --git a/ibc-core/ics24-host/cosmos/src/upgrade_proposal/plan.rs b/ibc-core/ics24-host/cosmos/src/upgrade_proposal/plan.rs index 33f1ad782..0a7251351 100644 --- a/ibc-core/ics24-host/cosmos/src/upgrade_proposal/plan.rs +++ b/ibc-core/ics24-host/cosmos/src/upgrade_proposal/plan.rs @@ -85,7 +85,7 @@ impl TryFrom for Plan { fn try_from(any: Any) -> Result { match any.type_url.as_str() { TYPE_URL => Protobuf::::decode_vec(&any.value) - .map_err(|e| UpgradeClientError::Decoding(DecodingError::FailedToDecodeProto(e))), + .map_err(|e| UpgradeClientError::Decoding(DecodingError::Protobuf(e))), _ => Err(UpgradeClientError::Decoding( DecodingError::MismatchedTypeUrls { expected: TYPE_URL.to_string(), diff --git a/ibc-core/ics24-host/types/Cargo.toml b/ibc-core/ics24-host/types/Cargo.toml index b1126d300..d603049c0 100644 --- a/ibc-core/ics24-host/types/Cargo.toml +++ b/ibc-core/ics24-host/types/Cargo.toml @@ -20,6 +20,7 @@ all-features = true [dependencies] # external dependencies +base64 = { workspace = true } borsh = { workspace = true, optional = true } derive_more = { workspace = true } displaydoc = { workspace = true } diff --git a/ibc-core/ics24-host/types/src/error.rs b/ibc-core/ics24-host/types/src/error.rs index 972b36c40..e048f1e95 100644 --- a/ibc-core/ics24-host/types/src/error.rs +++ b/ibc-core/ics24-host/types/src/error.rs @@ -1,9 +1,11 @@ //! Foundational error types that are applicable across multiple ibc-rs workspaces. -use alloc::string::String; +use alloc::string::{FromUtf8Error, String}; +use base64::DecodeError as Base64Error; use displaydoc::Display; use http::uri::InvalidUri; + use ibc_primitives::prelude::*; use tendermint_proto::Error as ProtoError; @@ -26,25 +28,23 @@ pub enum IdentifierError { /// Errors that result in decoding failures #[derive(Debug, Display)] pub enum DecodingError { - /// invalid identifier error: `{0}` - InvalidIdentifier(IdentifierError), + /// base64 decoding error: `{0}` + Base64(Base64Error), + /// utf-8 decoding error: `{0}` + Utf8(FromUtf8Error), + /// protobuf decoding error: `{0}` + Protobuf(ProtoError), /// invalid JSON data: `{description}` InvalidJson { description: String }, - /// invalid UTF-8 data: `{description}` - InvalidUtf8 { description: String }, /// invalid URI: `{0}` InvalidUri(InvalidUri), - /// malformed bytes that could not be decoded: `{description}` - MalformedBytes { description: String }, /// mismatched type URLs: expected `{expected}`, actual `{actual}` MismatchedTypeUrls { expected: String, actual: String }, - /// failed to decode proto; error: `{0}` - FailedToDecodeProto(ProtoError), } impl From for DecodingError { fn from(e: ProtoError) -> Self { - Self::FailedToDecodeProto(e) + Self::Protobuf(e) } } diff --git a/ibc-core/ics25-handler/types/src/msgs.rs b/ibc-core/ics25-handler/types/src/msgs.rs index 7f1b5c9a5..64b13665f 100644 --- a/ibc-core/ics25-handler/types/src/msgs.rs +++ b/ibc-core/ics25-handler/types/src/msgs.rs @@ -46,72 +46,45 @@ impl TryFrom for MsgEnvelope { // ICS2 messages CREATE_CLIENT_TYPE_URL => { // Pop out the message and then wrap it in the corresponding type. - let domain_msg = MsgCreateClient::decode_vec(&any_msg.value).map_err(|e| { - RouterError::Decoding(DecodingError::MalformedBytes { - description: e.to_string(), - }) - })?; + let domain_msg = MsgCreateClient::decode_vec(&any_msg.value) + .map_err(|e| RouterError::Decoding(DecodingError::Protobuf(e)))?; Ok(MsgEnvelope::Client(ClientMsg::CreateClient(domain_msg))) } UPDATE_CLIENT_TYPE_URL => { - let domain_msg = MsgUpdateClient::decode_vec(&any_msg.value).map_err(|e| { - RouterError::Decoding(DecodingError::MalformedBytes { - description: e.to_string(), - }) - })?; + let domain_msg = MsgUpdateClient::decode_vec(&any_msg.value) + .map_err(|e| RouterError::Decoding(DecodingError::Protobuf(e)))?; Ok(MsgEnvelope::Client(ClientMsg::UpdateClient(domain_msg))) } UPGRADE_CLIENT_TYPE_URL => { - let domain_msg = MsgUpgradeClient::decode_vec(&any_msg.value).map_err(|e| { - RouterError::Decoding(DecodingError::MalformedBytes { - description: e.to_string(), - }) - })?; + let domain_msg = MsgUpgradeClient::decode_vec(&any_msg.value) + .map_err(|e| RouterError::Decoding(DecodingError::Protobuf(e)))?; Ok(MsgEnvelope::Client(ClientMsg::UpgradeClient(domain_msg))) } SUBMIT_MISBEHAVIOUR_TYPE_URL => { - let domain_msg = - MsgSubmitMisbehaviour::decode_vec(&any_msg.value).map_err(|e| { - RouterError::Decoding(DecodingError::MalformedBytes { - description: e.to_string(), - }) - })?; + let domain_msg = MsgSubmitMisbehaviour::decode_vec(&any_msg.value) + .map_err(|e| RouterError::Decoding(DecodingError::Protobuf(e)))?; Ok(MsgEnvelope::Client(ClientMsg::Misbehaviour(domain_msg))) } // ICS03 CONN_OPEN_INIT_TYPE_URL => { - let domain_msg = - MsgConnectionOpenInit::decode_vec(&any_msg.value).map_err(|e| { - RouterError::Decoding(DecodingError::MalformedBytes { - description: e.to_string(), - }) - })?; + let domain_msg = MsgConnectionOpenInit::decode_vec(&any_msg.value) + .map_err(|e| RouterError::Decoding(DecodingError::Protobuf(e)))?; Ok(MsgEnvelope::Connection(ConnectionMsg::OpenInit(domain_msg))) } CONN_OPEN_TRY_TYPE_URL => { - let domain_msg = MsgConnectionOpenTry::decode_vec(&any_msg.value).map_err(|e| { - RouterError::Decoding(DecodingError::MalformedBytes { - description: e.to_string(), - }) - })?; + let domain_msg = MsgConnectionOpenTry::decode_vec(&any_msg.value) + .map_err(|e| RouterError::Decoding(DecodingError::Protobuf(e)))?; Ok(MsgEnvelope::Connection(ConnectionMsg::OpenTry(domain_msg))) } CONN_OPEN_ACK_TYPE_URL => { - let domain_msg = MsgConnectionOpenAck::decode_vec(&any_msg.value).map_err(|e| { - RouterError::Decoding(DecodingError::MalformedBytes { - description: e.to_string(), - }) - })?; + let domain_msg = MsgConnectionOpenAck::decode_vec(&any_msg.value) + .map_err(|e| RouterError::Decoding(DecodingError::Protobuf(e)))?; Ok(MsgEnvelope::Connection(ConnectionMsg::OpenAck(domain_msg))) } CONN_OPEN_CONFIRM_TYPE_URL => { - let domain_msg = - MsgConnectionOpenConfirm::decode_vec(&any_msg.value).map_err(|e| { - RouterError::Decoding(DecodingError::MalformedBytes { - description: e.to_string(), - }) - })?; + let domain_msg = MsgConnectionOpenConfirm::decode_vec(&any_msg.value) + .map_err(|e| RouterError::Decoding(DecodingError::Protobuf(e)))?; Ok(MsgEnvelope::Connection(ConnectionMsg::OpenConfirm( domain_msg, ))) @@ -119,86 +92,54 @@ impl TryFrom for MsgEnvelope { // ICS04 channel messages CHAN_OPEN_INIT_TYPE_URL => { - let domain_msg = MsgChannelOpenInit::decode_vec(&any_msg.value).map_err(|e| { - RouterError::Decoding(DecodingError::MalformedBytes { - description: e.to_string(), - }) - })?; + let domain_msg = MsgChannelOpenInit::decode_vec(&any_msg.value) + .map_err(|e| RouterError::Decoding(DecodingError::Protobuf(e)))?; Ok(MsgEnvelope::Channel(ChannelMsg::OpenInit(domain_msg))) } CHAN_OPEN_TRY_TYPE_URL => { - let domain_msg = MsgChannelOpenTry::decode_vec(&any_msg.value).map_err(|e| { - RouterError::Decoding(DecodingError::MalformedBytes { - description: e.to_string(), - }) - })?; + let domain_msg = MsgChannelOpenTry::decode_vec(&any_msg.value) + .map_err(|e| RouterError::Decoding(DecodingError::Protobuf(e)))?; Ok(MsgEnvelope::Channel(ChannelMsg::OpenTry(domain_msg))) } CHAN_OPEN_ACK_TYPE_URL => { - let domain_msg = MsgChannelOpenAck::decode_vec(&any_msg.value).map_err(|e| { - RouterError::Decoding(DecodingError::MalformedBytes { - description: e.to_string(), - }) - })?; + let domain_msg = MsgChannelOpenAck::decode_vec(&any_msg.value) + .map_err(|e| RouterError::Decoding(DecodingError::Protobuf(e)))?; Ok(MsgEnvelope::Channel(ChannelMsg::OpenAck(domain_msg))) } CHAN_OPEN_CONFIRM_TYPE_URL => { - let domain_msg = - MsgChannelOpenConfirm::decode_vec(&any_msg.value).map_err(|e| { - RouterError::Decoding(DecodingError::MalformedBytes { - description: e.to_string(), - }) - })?; + let domain_msg = MsgChannelOpenConfirm::decode_vec(&any_msg.value) + .map_err(|e| RouterError::Decoding(DecodingError::Protobuf(e)))?; Ok(MsgEnvelope::Channel(ChannelMsg::OpenConfirm(domain_msg))) } CHAN_CLOSE_INIT_TYPE_URL => { - let domain_msg = MsgChannelCloseInit::decode_vec(&any_msg.value).map_err(|e| { - RouterError::Decoding(DecodingError::MalformedBytes { - description: e.to_string(), - }) - })?; + let domain_msg = MsgChannelCloseInit::decode_vec(&any_msg.value) + .map_err(|e| RouterError::Decoding(DecodingError::Protobuf(e)))?; Ok(MsgEnvelope::Channel(ChannelMsg::CloseInit(domain_msg))) } CHAN_CLOSE_CONFIRM_TYPE_URL => { - let domain_msg = - MsgChannelCloseConfirm::decode_vec(&any_msg.value).map_err(|e| { - RouterError::Decoding(DecodingError::MalformedBytes { - description: e.to_string(), - }) - })?; + let domain_msg = MsgChannelCloseConfirm::decode_vec(&any_msg.value) + .map_err(|e| RouterError::Decoding(DecodingError::Protobuf(e)))?; Ok(MsgEnvelope::Channel(ChannelMsg::CloseConfirm(domain_msg))) } // ICS04 packet messages RECV_PACKET_TYPE_URL => { - let domain_msg = MsgRecvPacket::decode_vec(&any_msg.value).map_err(|e| { - RouterError::Decoding(DecodingError::MalformedBytes { - description: e.to_string(), - }) - })?; + let domain_msg = MsgRecvPacket::decode_vec(&any_msg.value) + .map_err(|e| RouterError::Decoding(DecodingError::Protobuf(e)))?; Ok(MsgEnvelope::Packet(PacketMsg::Recv(domain_msg))) } ACKNOWLEDGEMENT_TYPE_URL => { - let domain_msg = MsgAcknowledgement::decode_vec(&any_msg.value).map_err(|e| { - RouterError::Decoding(DecodingError::MalformedBytes { - description: e.to_string(), - }) - })?; + let domain_msg = MsgAcknowledgement::decode_vec(&any_msg.value) + .map_err(|e| RouterError::Decoding(DecodingError::Protobuf(e)))?; Ok(MsgEnvelope::Packet(PacketMsg::Ack(domain_msg))) } TIMEOUT_TYPE_URL => { - let domain_msg = MsgTimeout::decode_vec(&any_msg.value).map_err(|e| { - RouterError::Decoding(DecodingError::MalformedBytes { - description: e.to_string(), - }) - })?; + let domain_msg = MsgTimeout::decode_vec(&any_msg.value) + .map_err(|e| RouterError::Decoding(DecodingError::Protobuf(e)))?; Ok(MsgEnvelope::Packet(PacketMsg::Timeout(domain_msg))) } TIMEOUT_ON_CLOSE_TYPE_URL => { - let domain_msg = MsgTimeoutOnClose::decode_vec(&any_msg.value).map_err(|e| { - RouterError::Decoding(DecodingError::MalformedBytes { - description: e.to_string(), - }) - })?; + let domain_msg = MsgTimeoutOnClose::decode_vec(&any_msg.value) + .map_err(|e| RouterError::Decoding(DecodingError::Protobuf(e)))?; Ok(MsgEnvelope::Packet(PacketMsg::TimeoutOnClose(domain_msg))) } _ => Err(RouterError::UnknownMessageTypeUrl(any_msg.type_url)), diff --git a/ibc-testkit/src/testapp/ibc/clients/mock/header.rs b/ibc-testkit/src/testapp/ibc/clients/mock/header.rs index f6ac8f11e..a485d2341 100644 --- a/ibc-testkit/src/testapp/ibc/clients/mock/header.rs +++ b/ibc-testkit/src/testapp/ibc/clients/mock/header.rs @@ -97,7 +97,7 @@ impl TryFrom for MockHeader { fn try_from(raw: Any) -> Result { match raw.type_url.as_str() { MOCK_HEADER_TYPE_URL => Protobuf::::decode_vec(&raw.value) - .map_err(|e| ClientError::Decoding(DecodingError::FailedToDecodeProto(e))), + .map_err(|e| ClientError::Decoding(DecodingError::Protobuf(e))), _ => Err(ClientError::Decoding(DecodingError::MismatchedTypeUrls { expected: MOCK_HEADER_TYPE_URL.to_string(), actual: raw.type_url, From 452ad435ff1867558c2819af76b1f4bd6376bbf8 Mon Sep 17 00:00:00 2001 From: Sean Chen Date: Wed, 28 Aug 2024 10:41:16 -0500 Subject: [PATCH 15/73] cargo fmt --- ibc-core/ics23-commitment/types/src/error.rs | 1 - ibc-core/ics24-host/types/src/error.rs | 1 - 2 files changed, 2 deletions(-) diff --git a/ibc-core/ics23-commitment/types/src/error.rs b/ibc-core/ics23-commitment/types/src/error.rs index 8505de71d..511aa3fb9 100644 --- a/ibc-core/ics23-commitment/types/src/error.rs +++ b/ibc-core/ics23-commitment/types/src/error.rs @@ -1,7 +1,6 @@ //! Defines the commitment error type use displaydoc::Display; - use ibc_core_host_types::error::DecodingError; use ibc_primitives::prelude::*; diff --git a/ibc-core/ics24-host/types/src/error.rs b/ibc-core/ics24-host/types/src/error.rs index e048f1e95..da843b20b 100644 --- a/ibc-core/ics24-host/types/src/error.rs +++ b/ibc-core/ics24-host/types/src/error.rs @@ -5,7 +5,6 @@ use alloc::string::{FromUtf8Error, String}; use base64::DecodeError as Base64Error; use displaydoc::Display; use http::uri::InvalidUri; - use ibc_primitives::prelude::*; use tendermint_proto::Error as ProtoError; From dcdd2110c7390c2d0080bd5beb9cea7913a8810d Mon Sep 17 00:00:00 2001 From: Sean Chen Date: Wed, 28 Aug 2024 12:49:41 -0500 Subject: [PATCH 16/73] cargo fmt --- ibc-core/ics03-connection/src/handler/mod.rs | 5 ++--- ibc-core/ics03-connection/types/src/error.rs | 4 +++- ibc-core/ics24-host/types/Cargo.toml | 1 + ibc-core/ics24-host/types/src/error.rs | 3 +++ 4 files changed, 9 insertions(+), 4 deletions(-) diff --git a/ibc-core/ics03-connection/src/handler/mod.rs b/ibc-core/ics03-connection/src/handler/mod.rs index effc57fda..15f00a645 100644 --- a/ibc-core/ics03-connection/src/handler/mod.rs +++ b/ibc-core/ics03-connection/src/handler/mod.rs @@ -1,5 +1,6 @@ use ibc_core_client::types::error::ClientError; use ibc_core_handler_types::error::ContextError; +use ibc_core_host::types::error::DecodingError; use ibc_core_host::types::identifiers::ClientId; use ibc_primitives::proto::Any; @@ -36,9 +37,7 @@ where let any_client_state = ::decode(wasm_client_state.data.as_slice()) .map_err(|e| { - ContextError::ConnectionError(ConnectionError::InvalidClientState { - description: e.to_string(), - }) + ContextError::ConnectionError(ConnectionError::Decoding(DecodingError::Prost(e))) })?; Ok(CS::try_from(any_client_state).map_err(Into::::into)?) diff --git a/ibc-core/ics03-connection/types/src/error.rs b/ibc-core/ics03-connection/types/src/error.rs index 6062dfae6..7016256b7 100644 --- a/ibc-core/ics03-connection/types/src/error.rs +++ b/ibc-core/ics03-connection/types/src/error.rs @@ -3,7 +3,7 @@ use displaydoc::Display; use ibc_core_client_types::error::ClientError; use ibc_core_client_types::Height; -use ibc_core_host_types::error::IdentifierError; +use ibc_core_host_types::error::{DecodingError, IdentifierError}; use ibc_core_host_types::identifiers::ConnectionId; use ibc_primitives::prelude::*; use ibc_primitives::{Timestamp, TimestampError}; @@ -12,6 +12,8 @@ use crate::version::Version; #[derive(Debug, Display)] pub enum ConnectionError { + /// decoding error: `{0}` + Decoding(DecodingError), /// invalid identifier: `{0}` InvalidIdentifier(IdentifierError), /// invalid state for initializing new ConnectionEnd; expected `Init` connection state and a single version diff --git a/ibc-core/ics24-host/types/Cargo.toml b/ibc-core/ics24-host/types/Cargo.toml index d603049c0..4bf0eb6a0 100644 --- a/ibc-core/ics24-host/types/Cargo.toml +++ b/ibc-core/ics24-host/types/Cargo.toml @@ -25,6 +25,7 @@ borsh = { workspace = true, optional = true } derive_more = { workspace = true } displaydoc = { workspace = true } http = { version = "1.1.0" } +prost = { workspace = true } schemars = { workspace = true, optional = true } serde = { workspace = true, optional = true } diff --git a/ibc-core/ics24-host/types/src/error.rs b/ibc-core/ics24-host/types/src/error.rs index da843b20b..b026b05d0 100644 --- a/ibc-core/ics24-host/types/src/error.rs +++ b/ibc-core/ics24-host/types/src/error.rs @@ -6,6 +6,7 @@ use base64::DecodeError as Base64Error; use displaydoc::Display; use http::uri::InvalidUri; use ibc_primitives::prelude::*; +use prost::DecodeError as ProstError; use tendermint_proto::Error as ProtoError; /// Errors that arise when parsing identifiers. @@ -33,6 +34,8 @@ pub enum DecodingError { Utf8(FromUtf8Error), /// protobuf decoding error: `{0}` Protobuf(ProtoError), + /// prost decoding error: `{0}` + Prost(ProstError), /// invalid JSON data: `{description}` InvalidJson { description: String }, /// invalid URI: `{0}` From 56c63dee0031d2bdecaeaa55e926ed832a5f448e Mon Sep 17 00:00:00 2001 From: Sean Chen Date: Wed, 28 Aug 2024 12:52:24 -0500 Subject: [PATCH 17/73] Update cw-check Cargo.lock --- ci/cw-check/Cargo.lock | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/ci/cw-check/Cargo.lock b/ci/cw-check/Cargo.lock index 2ba932c42..78413a1c2 100644 --- a/ci/cw-check/Cargo.lock +++ b/ci/cw-check/Cargo.lock @@ -658,6 +658,12 @@ dependencies = [ "paste", ] +[[package]] +name = "fnv" +version = "1.0.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" + [[package]] name = "futures" version = "0.3.30" @@ -786,6 +792,17 @@ dependencies = [ "digest", ] +[[package]] +name = "http" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "21b9ddb458710bc376481b842f5da65cdf31522de232c1ca8146abce2a358258" +dependencies = [ + "bytes", + "fnv", + "itoa", +] + [[package]] name = "ibc-app-transfer" version = "0.54.0" @@ -1031,13 +1048,17 @@ dependencies = [ name = "ibc-core-host-types" version = "0.54.0" dependencies = [ + "base64 0.22.1", "derive_more 0.99.18", "displaydoc", + "http", "ibc-primitives", "parity-scale-codec", + "prost", "scale-info", "schemars", "serde", + "tendermint-proto", ] [[package]] @@ -1092,6 +1113,7 @@ dependencies = [ "schemars", "serde", "tendermint", + "tendermint-proto", "time", ] From 334f249c28d625d4144de6b17712e5cf647d00f6 Mon Sep 17 00:00:00 2001 From: Sean Chen Date: Wed, 28 Aug 2024 12:56:35 -0500 Subject: [PATCH 18/73] Add necessary wasm-client feature attribute --- ibc-core/ics03-connection/src/handler/mod.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/ibc-core/ics03-connection/src/handler/mod.rs b/ibc-core/ics03-connection/src/handler/mod.rs index 15f00a645..3421ebb16 100644 --- a/ibc-core/ics03-connection/src/handler/mod.rs +++ b/ibc-core/ics03-connection/src/handler/mod.rs @@ -1,5 +1,6 @@ use ibc_core_client::types::error::ClientError; use ibc_core_handler_types::error::ContextError; +#[cfg(feature = "wasm-client")] use ibc_core_host::types::error::DecodingError; use ibc_core_host::types::identifiers::ClientId; use ibc_primitives::proto::Any; From 2f179b625b2047f0e89cb60e74c2ab59a56481cd Mon Sep 17 00:00:00 2001 From: Sean Chen Date: Wed, 28 Aug 2024 13:23:42 -0500 Subject: [PATCH 19/73] Move InvalidUri error variant back to NftTransferError --- ibc-apps/ics721-nft-transfer/types/src/class.rs | 3 +-- ibc-apps/ics721-nft-transfer/types/src/error.rs | 5 ++++- ibc-apps/ics721-nft-transfer/types/src/token.rs | 3 +-- ibc-core/ics24-host/types/Cargo.toml | 1 - ibc-core/ics24-host/types/src/error.rs | 3 --- 5 files changed, 6 insertions(+), 9 deletions(-) diff --git a/ibc-apps/ics721-nft-transfer/types/src/class.rs b/ibc-apps/ics721-nft-transfer/types/src/class.rs index c4aaa5ae5..8a7c941e6 100644 --- a/ibc-apps/ics721-nft-transfer/types/src/class.rs +++ b/ibc-apps/ics721-nft-transfer/types/src/class.rs @@ -4,7 +4,6 @@ use core::str::FromStr; use http::Uri; pub use ibc_app_transfer_types::{TracePath, TracePrefix}; -use ibc_core::host::types::error::DecodingError; use ibc_core::host::types::identifiers::{ChannelId, PortId}; use ibc_core::primitives::prelude::*; #[cfg(feature = "serde")] @@ -249,7 +248,7 @@ impl FromStr for ClassUri { fn from_str(class_uri: &str) -> Result { match Uri::from_str(class_uri) { Ok(uri) => Ok(Self(uri)), - Err(err) => Err(NftTransferError::Decoding(DecodingError::InvalidUri(err))), + Err(err) => Err(NftTransferError::InvalidUri(err)), } } } diff --git a/ibc-apps/ics721-nft-transfer/types/src/error.rs b/ibc-apps/ics721-nft-transfer/types/src/error.rs index d7303ce17..c04b391b6 100644 --- a/ibc-apps/ics721-nft-transfer/types/src/error.rs +++ b/ibc-apps/ics721-nft-transfer/types/src/error.rs @@ -2,6 +2,7 @@ use core::convert::Infallible; use displaydoc::Display; +use http::uri::InvalidUri; use ibc_core::channel::types::acknowledgement::StatusValue; use ibc_core::channel::types::channel::Order; use ibc_core::handler::types::error::ContextError; @@ -17,8 +18,10 @@ pub enum NftTransferError { Decoding(DecodingError), /// identifier error: `{0}` Identifier(IdentifierError), - /// invalid trace `{0}` + /// invalid trace: `{0}` InvalidTrace(String), + /// invalid URI error: `{0}` + InvalidUri(InvalidUri), /// missing destination channel `{channel_id}` on port `{port_id}` MissingDestinationChannel { port_id: PortId, diff --git a/ibc-apps/ics721-nft-transfer/types/src/token.rs b/ibc-apps/ics721-nft-transfer/types/src/token.rs index 3c1e56aeb..fa11e93a1 100644 --- a/ibc-apps/ics721-nft-transfer/types/src/token.rs +++ b/ibc-apps/ics721-nft-transfer/types/src/token.rs @@ -3,7 +3,6 @@ use core::fmt::{self, Display}; use core::str::FromStr; use http::Uri; -use ibc_core::host::types::error::DecodingError; use ibc_core::primitives::prelude::*; #[cfg(feature = "serde")] use ibc_core::primitives::serializers; @@ -183,7 +182,7 @@ impl FromStr for TokenUri { fn from_str(token_uri: &str) -> Result { match Uri::from_str(token_uri) { Ok(uri) => Ok(Self(uri)), - Err(err) => Err(NftTransferError::Decoding(DecodingError::InvalidUri(err))), + Err(err) => Err(NftTransferError::InvalidUri(err)), } } } diff --git a/ibc-core/ics24-host/types/Cargo.toml b/ibc-core/ics24-host/types/Cargo.toml index 4bf0eb6a0..fa69e483f 100644 --- a/ibc-core/ics24-host/types/Cargo.toml +++ b/ibc-core/ics24-host/types/Cargo.toml @@ -24,7 +24,6 @@ base64 = { workspace = true } borsh = { workspace = true, optional = true } derive_more = { workspace = true } displaydoc = { workspace = true } -http = { version = "1.1.0" } prost = { workspace = true } schemars = { workspace = true, optional = true } serde = { workspace = true, optional = true } diff --git a/ibc-core/ics24-host/types/src/error.rs b/ibc-core/ics24-host/types/src/error.rs index b026b05d0..1e583f8aa 100644 --- a/ibc-core/ics24-host/types/src/error.rs +++ b/ibc-core/ics24-host/types/src/error.rs @@ -4,7 +4,6 @@ use alloc::string::{FromUtf8Error, String}; use base64::DecodeError as Base64Error; use displaydoc::Display; -use http::uri::InvalidUri; use ibc_primitives::prelude::*; use prost::DecodeError as ProstError; use tendermint_proto::Error as ProtoError; @@ -38,8 +37,6 @@ pub enum DecodingError { Prost(ProstError), /// invalid JSON data: `{description}` InvalidJson { description: String }, - /// invalid URI: `{0}` - InvalidUri(InvalidUri), /// mismatched type URLs: expected `{expected}`, actual `{actual}` MismatchedTypeUrls { expected: String, actual: String }, } From a64b377c1481d91d4d9a62e475409535f7df258c Mon Sep 17 00:00:00 2001 From: Sean Chen Date: Wed, 28 Aug 2024 13:26:21 -0500 Subject: [PATCH 20/73] Regenerate cw hcheck cargo.lock --- ci/cw-check/Cargo.lock | 18 ------------------ 1 file changed, 18 deletions(-) diff --git a/ci/cw-check/Cargo.lock b/ci/cw-check/Cargo.lock index 78413a1c2..e0be4007f 100644 --- a/ci/cw-check/Cargo.lock +++ b/ci/cw-check/Cargo.lock @@ -658,12 +658,6 @@ dependencies = [ "paste", ] -[[package]] -name = "fnv" -version = "1.0.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" - [[package]] name = "futures" version = "0.3.30" @@ -792,17 +786,6 @@ dependencies = [ "digest", ] -[[package]] -name = "http" -version = "1.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "21b9ddb458710bc376481b842f5da65cdf31522de232c1ca8146abce2a358258" -dependencies = [ - "bytes", - "fnv", - "itoa", -] - [[package]] name = "ibc-app-transfer" version = "0.54.0" @@ -1051,7 +1034,6 @@ dependencies = [ "base64 0.22.1", "derive_more 0.99.18", "displaydoc", - "http", "ibc-primitives", "parity-scale-codec", "prost", From 3a4d8220bc72fa17c30ca8d77cb8140eb3c9e1a3 Mon Sep 17 00:00:00 2001 From: Sean Chen Date: Wed, 28 Aug 2024 13:43:52 -0500 Subject: [PATCH 21/73] Add serde feature attribute --- ibc-apps/ics721-nft-transfer/types/src/data.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/ibc-apps/ics721-nft-transfer/types/src/data.rs b/ibc-apps/ics721-nft-transfer/types/src/data.rs index bbbfb3f3d..a54d990af 100644 --- a/ibc-apps/ics721-nft-transfer/types/src/data.rs +++ b/ibc-apps/ics721-nft-transfer/types/src/data.rs @@ -6,6 +6,7 @@ use core::str::FromStr; use base64::prelude::BASE64_STANDARD; #[cfg(feature = "serde")] use base64::Engine; +#[cfg(feature = "serde")] use ibc_core::host::types::error::DecodingError; use ibc_core::primitives::prelude::*; use mime::Mime; From fb4ceacd0e103527bdf801cdf94624d40615c7a0 Mon Sep 17 00:00:00 2001 From: Sean Chen Date: Thu, 29 Aug 2024 13:50:27 -0500 Subject: [PATCH 22/73] Remove ClientError::InvalidClientIdentifier error variant in favor of DecodingError::InvalidIdentifier --- ibc-core/ics02-client/types/src/error.rs | 6 +----- ibc-core/ics02-client/types/src/msgs/misbehaviour.rs | 3 ++- ibc-core/ics02-client/types/src/msgs/recover_client.rs | 5 +++-- ibc-core/ics02-client/types/src/msgs/update_client.rs | 3 ++- ibc-core/ics02-client/types/src/msgs/upgrade_client.rs | 3 ++- ibc-core/ics24-host/types/src/error.rs | 2 ++ 6 files changed, 12 insertions(+), 10 deletions(-) diff --git a/ibc-core/ics02-client/types/src/error.rs b/ibc-core/ics02-client/types/src/error.rs index e11268cd7..5c3d0f0e7 100644 --- a/ibc-core/ics02-client/types/src/error.rs +++ b/ibc-core/ics02-client/types/src/error.rs @@ -4,7 +4,7 @@ use core::convert::Infallible; use displaydoc::Display; use ibc_core_commitment_types::error::CommitmentError; -use ibc_core_host_types::error::{DecodingError, IdentifierError}; +use ibc_core_host_types::error::DecodingError; use ibc_core_host_types::identifiers::ClientId; use ibc_primitives::prelude::*; use ibc_primitives::Timestamp; @@ -31,9 +31,6 @@ pub enum ClientError { InvalidConsensusStateType(String), /// invalid update client message InvalidUpdateClientMessage, - // TODO(seanchen1991): Should this be removed in favor of DecodingError::InvalidIdentifier? - /// invalid client identifier: `{0}` - InvalidClientIdentifier(IdentifierError), /// invalid raw header: `{description}` InvalidRawHeader { description: String }, /// invalid misbehaviour type: `{0}` @@ -121,7 +118,6 @@ impl From for ClientError { impl std::error::Error for ClientError { fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { match &self { - Self::InvalidClientIdentifier(e) => Some(e), Self::FailedICS23Verification(e) => Some(e), Self::ClientStatus(e) => Some(e), Self::Decoding(e) => Some(e), diff --git a/ibc-core/ics02-client/types/src/msgs/misbehaviour.rs b/ibc-core/ics02-client/types/src/msgs/misbehaviour.rs index 7d14f133f..e5b083196 100644 --- a/ibc-core/ics02-client/types/src/msgs/misbehaviour.rs +++ b/ibc-core/ics02-client/types/src/msgs/misbehaviour.rs @@ -1,5 +1,6 @@ //! Definition of domain type message `MsgSubmitMisbehaviour`. +use ibc_core_host_types::error::DecodingError; use ibc_core_host_types::identifiers::ClientId; use ibc_primitives::prelude::*; use ibc_primitives::Signer; @@ -48,7 +49,7 @@ impl TryFrom for MsgSubmitMisbehaviour { client_id: raw .client_id .parse() - .map_err(ClientError::InvalidClientIdentifier)?, + .map_err(|e| ClientError::Decoding(DecodingError::InvalidIdentifier(e)))?, misbehaviour: raw_misbehaviour, signer: raw.signer.into(), }) diff --git a/ibc-core/ics02-client/types/src/msgs/recover_client.rs b/ibc-core/ics02-client/types/src/msgs/recover_client.rs index 62fc738fe..d71c8d90c 100644 --- a/ibc-core/ics02-client/types/src/msgs/recover_client.rs +++ b/ibc-core/ics02-client/types/src/msgs/recover_client.rs @@ -1,5 +1,6 @@ //! Definition of domain type message `MsgRecoverClient`. +use ibc_core_host_types::error::DecodingError; use ibc_core_host_types::identifiers::ClientId; use ibc_primitives::prelude::*; use ibc_primitives::Signer; @@ -45,11 +46,11 @@ impl TryFrom for MsgRecoverClient { subject_client_id: raw .subject_client_id .parse() - .map_err(ClientError::InvalidClientIdentifier)?, + .map_err(|e| ClientError::Decoding(DecodingError::InvalidIdentifier(e)))?, substitute_client_id: raw .substitute_client_id .parse() - .map_err(ClientError::InvalidClientIdentifier)?, + .map_err(|e| ClientError::Decoding(DecodingError::InvalidIdentifier(e)))?, signer: raw.signer.into(), }) } diff --git a/ibc-core/ics02-client/types/src/msgs/update_client.rs b/ibc-core/ics02-client/types/src/msgs/update_client.rs index 9eb088017..26d719fac 100644 --- a/ibc-core/ics02-client/types/src/msgs/update_client.rs +++ b/ibc-core/ics02-client/types/src/msgs/update_client.rs @@ -1,5 +1,6 @@ //! Definition of domain type message `MsgUpdateClient`. +use ibc_core_host_types::error::DecodingError; use ibc_core_host_types::identifiers::ClientId; use ibc_primitives::prelude::*; use ibc_primitives::Signer; @@ -37,7 +38,7 @@ impl TryFrom for MsgUpdateClient { client_id: raw .client_id .parse() - .map_err(ClientError::InvalidClientIdentifier)?, + .map_err(|e| ClientError::Decoding(DecodingError::InvalidIdentifier(e)))?, client_message: raw .client_message .ok_or(ClientError::MissingRawClientMessage)?, diff --git a/ibc-core/ics02-client/types/src/msgs/upgrade_client.rs b/ibc-core/ics02-client/types/src/msgs/upgrade_client.rs index c3d9a956b..1fbff9e7d 100644 --- a/ibc-core/ics02-client/types/src/msgs/upgrade_client.rs +++ b/ibc-core/ics02-client/types/src/msgs/upgrade_client.rs @@ -4,6 +4,7 @@ use core::str::FromStr; use ibc_core_commitment_types::commitment::CommitmentProofBytes; use ibc_core_commitment_types::error::CommitmentError; +use ibc_core_host_types::error::DecodingError; use ibc_core_host_types::identifiers::ClientId; use ibc_primitives::prelude::*; use ibc_primitives::Signer; @@ -78,7 +79,7 @@ impl TryFrom for MsgUpgradeClient { Ok(MsgUpgradeClient { client_id: ClientId::from_str(&proto_msg.client_id) - .map_err(ClientError::InvalidClientIdentifier)?, + .map_err(|e| ClientError::Decoding(DecodingError::InvalidIdentifier(e)))?, upgraded_client_state: raw_client_state, upgraded_consensus_state: raw_consensus_state, proof_upgrade_client: c_bytes, diff --git a/ibc-core/ics24-host/types/src/error.rs b/ibc-core/ics24-host/types/src/error.rs index 1e583f8aa..1fa203a65 100644 --- a/ibc-core/ics24-host/types/src/error.rs +++ b/ibc-core/ics24-host/types/src/error.rs @@ -37,6 +37,8 @@ pub enum DecodingError { Prost(ProstError), /// invalid JSON data: `{description}` InvalidJson { description: String }, + /// invalid identifier error: `{0}` + InvalidIdentifier(IdentifierError), /// mismatched type URLs: expected `{expected}`, actual `{actual}` MismatchedTypeUrls { expected: String, actual: String }, } From 4cd30ab161fa4753fe3a19ca03b1e9cc43067dc6 Mon Sep 17 00:00:00 2001 From: Sean Chen Date: Thu, 29 Aug 2024 15:05:19 -0500 Subject: [PATCH 23/73] Add derive_more::From on NftTransferError --- ibc-apps/ics20-transfer/types/src/error.rs | 3 ++- .../ics721-nft-transfer/types/src/error.rs | 21 ++----------------- 2 files changed, 4 insertions(+), 20 deletions(-) diff --git a/ibc-apps/ics20-transfer/types/src/error.rs b/ibc-apps/ics20-transfer/types/src/error.rs index 291a12635..ff50b055c 100644 --- a/ibc-apps/ics20-transfer/types/src/error.rs +++ b/ibc-apps/ics20-transfer/types/src/error.rs @@ -2,13 +2,14 @@ use core::convert::Infallible; use displaydoc::Display; +use uint::FromDecStrErr; + use ibc_core::channel::types::acknowledgement::StatusValue; use ibc_core::channel::types::channel::Order; use ibc_core::handler::types::error::ContextError; use ibc_core::host::types::error::{DecodingError, IdentifierError}; use ibc_core::host::types::identifiers::{ChannelId, PortId}; use ibc_core::primitives::prelude::*; -use uint::FromDecStrErr; #[derive(Display, Debug)] pub enum TokenTransferError { diff --git a/ibc-apps/ics721-nft-transfer/types/src/error.rs b/ibc-apps/ics721-nft-transfer/types/src/error.rs index c04b391b6..281450111 100644 --- a/ibc-apps/ics721-nft-transfer/types/src/error.rs +++ b/ibc-apps/ics721-nft-transfer/types/src/error.rs @@ -3,6 +3,7 @@ use core::convert::Infallible; use displaydoc::Display; use http::uri::InvalidUri; + use ibc_core::channel::types::acknowledgement::StatusValue; use ibc_core::channel::types::channel::Order; use ibc_core::handler::types::error::ContextError; @@ -10,7 +11,7 @@ use ibc_core::host::types::error::{DecodingError, IdentifierError}; use ibc_core::host::types::identifiers::{ChannelId, PortId}; use ibc_core::primitives::prelude::*; -#[derive(Display, Debug)] +#[derive(Display, Debug, derive_more::From)] pub enum NftTransferError { /// context error: `{0}` ContextError(ContextError), @@ -64,24 +65,6 @@ impl From for NftTransferError { } } -impl From for NftTransferError { - fn from(e: ContextError) -> Self { - Self::ContextError(e) - } -} - -impl From for NftTransferError { - fn from(e: IdentifierError) -> Self { - Self::Identifier(e) - } -} - -impl From for NftTransferError { - fn from(e: DecodingError) -> Self { - Self::Decoding(e) - } -} - impl From for StatusValue { fn from(e: NftTransferError) -> Self { StatusValue::new(e.to_string()).expect("error message must not be empty") From 494e23efb97e2d65166dd6f895f6848aba72e52d Mon Sep 17 00:00:00 2001 From: Sean Chen Date: Thu, 29 Aug 2024 15:33:28 -0500 Subject: [PATCH 24/73] Stashing changes --- ibc-apps/ics20-transfer/types/src/error.rs | 8 ++++---- ibc-apps/ics721-nft-transfer/types/src/error.rs | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/ibc-apps/ics20-transfer/types/src/error.rs b/ibc-apps/ics20-transfer/types/src/error.rs index ff50b055c..252ab1727 100644 --- a/ibc-apps/ics20-transfer/types/src/error.rs +++ b/ibc-apps/ics20-transfer/types/src/error.rs @@ -17,8 +17,8 @@ pub enum TokenTransferError { ContextError(ContextError), /// decoding error: `{0}` Decoding(DecodingError), - /// invalid identifier: `{0}` - InvalidIdentifier(IdentifierError), + /// identifier error: `{0}` + Identifier(IdentifierError), /// invalid trace: `{0}` InvalidTrace(String), /// invalid amount: `{0}` @@ -55,7 +55,7 @@ impl std::error::Error for TokenTransferError { fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { match &self { Self::ContextError(e) => Some(e), - Self::InvalidIdentifier(e) => Some(e), + Self::Identifier(e) => Some(e), Self::InvalidAmount(e) => Some(e), Self::Decoding(e) => Some(e), _ => None, @@ -77,7 +77,7 @@ impl From for TokenTransferError { impl From for TokenTransferError { fn from(e: IdentifierError) -> Self { - Self::InvalidIdentifier(e) + Self::Identifier(e) } } diff --git a/ibc-apps/ics721-nft-transfer/types/src/error.rs b/ibc-apps/ics721-nft-transfer/types/src/error.rs index 281450111..c847e5589 100644 --- a/ibc-apps/ics721-nft-transfer/types/src/error.rs +++ b/ibc-apps/ics721-nft-transfer/types/src/error.rs @@ -11,7 +11,7 @@ use ibc_core::host::types::error::{DecodingError, IdentifierError}; use ibc_core::host::types::identifiers::{ChannelId, PortId}; use ibc_core::primitives::prelude::*; -#[derive(Display, Debug, derive_more::From)] +#[derive(Display, Debug)] pub enum NftTransferError { /// context error: `{0}` ContextError(ContextError), From 72217f4015dedcf87dee1bc85e673959b97b8539 Mon Sep 17 00:00:00 2001 From: Sean Chen Date: Thu, 29 Aug 2024 15:33:32 -0500 Subject: [PATCH 25/73] Revert "Add derive_more::From on NftTransferError" This reverts commit 234ebeec9179151f5659e529f7d2bfc8e1d60966. --- ibc-apps/ics20-transfer/types/src/error.rs | 3 +-- .../ics721-nft-transfer/types/src/error.rs | 19 ++++++++++++++++++- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/ibc-apps/ics20-transfer/types/src/error.rs b/ibc-apps/ics20-transfer/types/src/error.rs index 252ab1727..72a68f4c3 100644 --- a/ibc-apps/ics20-transfer/types/src/error.rs +++ b/ibc-apps/ics20-transfer/types/src/error.rs @@ -2,14 +2,13 @@ use core::convert::Infallible; use displaydoc::Display; -use uint::FromDecStrErr; - use ibc_core::channel::types::acknowledgement::StatusValue; use ibc_core::channel::types::channel::Order; use ibc_core::handler::types::error::ContextError; use ibc_core::host::types::error::{DecodingError, IdentifierError}; use ibc_core::host::types::identifiers::{ChannelId, PortId}; use ibc_core::primitives::prelude::*; +use uint::FromDecStrErr; #[derive(Display, Debug)] pub enum TokenTransferError { diff --git a/ibc-apps/ics721-nft-transfer/types/src/error.rs b/ibc-apps/ics721-nft-transfer/types/src/error.rs index c847e5589..c04b391b6 100644 --- a/ibc-apps/ics721-nft-transfer/types/src/error.rs +++ b/ibc-apps/ics721-nft-transfer/types/src/error.rs @@ -3,7 +3,6 @@ use core::convert::Infallible; use displaydoc::Display; use http::uri::InvalidUri; - use ibc_core::channel::types::acknowledgement::StatusValue; use ibc_core::channel::types::channel::Order; use ibc_core::handler::types::error::ContextError; @@ -65,6 +64,24 @@ impl From for NftTransferError { } } +impl From for NftTransferError { + fn from(e: ContextError) -> Self { + Self::ContextError(e) + } +} + +impl From for NftTransferError { + fn from(e: IdentifierError) -> Self { + Self::Identifier(e) + } +} + +impl From for NftTransferError { + fn from(e: DecodingError) -> Self { + Self::Decoding(e) + } +} + impl From for StatusValue { fn from(e: NftTransferError) -> Self { StatusValue::new(e.to_string()).expect("error message must not be empty") From a36b2d7fec5559abc69389c0ef6332802a25c2f2 Mon Sep 17 00:00:00 2001 From: Sean Chen Date: Thu, 29 Aug 2024 15:42:40 -0500 Subject: [PATCH 26/73] Remove RouterError::UnknownMessageTypeUrl --- ibc-core/ics24-host/types/src/error.rs | 2 + ibc-core/ics25-handler/types/src/msgs.rs | 47 ++++++++++++----------- ibc-core/ics26-routing/types/src/error.rs | 4 +- 3 files changed, 27 insertions(+), 26 deletions(-) diff --git a/ibc-core/ics24-host/types/src/error.rs b/ibc-core/ics24-host/types/src/error.rs index 1fa203a65..ad0c98b3c 100644 --- a/ibc-core/ics24-host/types/src/error.rs +++ b/ibc-core/ics24-host/types/src/error.rs @@ -41,6 +41,8 @@ pub enum DecodingError { InvalidIdentifier(IdentifierError), /// mismatched type URLs: expected `{expected}`, actual `{actual}` MismatchedTypeUrls { expected: String, actual: String }, + /// unknown type URL: `{0}` + UnknownTypeUrl(String), } impl From for DecodingError { diff --git a/ibc-core/ics25-handler/types/src/msgs.rs b/ibc-core/ics25-handler/types/src/msgs.rs index 64b13665f..b2a34c773 100644 --- a/ibc-core/ics25-handler/types/src/msgs.rs +++ b/ibc-core/ics25-handler/types/src/msgs.rs @@ -46,45 +46,45 @@ impl TryFrom for MsgEnvelope { // ICS2 messages CREATE_CLIENT_TYPE_URL => { // Pop out the message and then wrap it in the corresponding type. - let domain_msg = MsgCreateClient::decode_vec(&any_msg.value) - .map_err(|e| RouterError::Decoding(DecodingError::Protobuf(e)))?; + let domain_msg = + MsgCreateClient::decode_vec(&any_msg.value).map_err(DecodingError::Protobuf)?; Ok(MsgEnvelope::Client(ClientMsg::CreateClient(domain_msg))) } UPDATE_CLIENT_TYPE_URL => { - let domain_msg = MsgUpdateClient::decode_vec(&any_msg.value) - .map_err(|e| RouterError::Decoding(DecodingError::Protobuf(e)))?; + let domain_msg = + MsgUpdateClient::decode_vec(&any_msg.value).map_err(DecodingError::Protobuf)?; Ok(MsgEnvelope::Client(ClientMsg::UpdateClient(domain_msg))) } UPGRADE_CLIENT_TYPE_URL => { let domain_msg = MsgUpgradeClient::decode_vec(&any_msg.value) - .map_err(|e| RouterError::Decoding(DecodingError::Protobuf(e)))?; + .map_err(DecodingError::Protobuf)?; Ok(MsgEnvelope::Client(ClientMsg::UpgradeClient(domain_msg))) } SUBMIT_MISBEHAVIOUR_TYPE_URL => { let domain_msg = MsgSubmitMisbehaviour::decode_vec(&any_msg.value) - .map_err(|e| RouterError::Decoding(DecodingError::Protobuf(e)))?; + .map_err(DecodingError::Protobuf)?; Ok(MsgEnvelope::Client(ClientMsg::Misbehaviour(domain_msg))) } // ICS03 CONN_OPEN_INIT_TYPE_URL => { let domain_msg = MsgConnectionOpenInit::decode_vec(&any_msg.value) - .map_err(|e| RouterError::Decoding(DecodingError::Protobuf(e)))?; + .map_err(DecodingError::Protobuf)?; Ok(MsgEnvelope::Connection(ConnectionMsg::OpenInit(domain_msg))) } CONN_OPEN_TRY_TYPE_URL => { let domain_msg = MsgConnectionOpenTry::decode_vec(&any_msg.value) - .map_err(|e| RouterError::Decoding(DecodingError::Protobuf(e)))?; + .map_err(DecodingError::Protobuf)?; Ok(MsgEnvelope::Connection(ConnectionMsg::OpenTry(domain_msg))) } CONN_OPEN_ACK_TYPE_URL => { let domain_msg = MsgConnectionOpenAck::decode_vec(&any_msg.value) - .map_err(|e| RouterError::Decoding(DecodingError::Protobuf(e)))?; + .map_err(DecodingError::Protobuf)?; Ok(MsgEnvelope::Connection(ConnectionMsg::OpenAck(domain_msg))) } CONN_OPEN_CONFIRM_TYPE_URL => { let domain_msg = MsgConnectionOpenConfirm::decode_vec(&any_msg.value) - .map_err(|e| RouterError::Decoding(DecodingError::Protobuf(e)))?; + .map_err(DecodingError::Protobuf)?; Ok(MsgEnvelope::Connection(ConnectionMsg::OpenConfirm( domain_msg, ))) @@ -93,56 +93,57 @@ impl TryFrom for MsgEnvelope { // ICS04 channel messages CHAN_OPEN_INIT_TYPE_URL => { let domain_msg = MsgChannelOpenInit::decode_vec(&any_msg.value) - .map_err(|e| RouterError::Decoding(DecodingError::Protobuf(e)))?; + .map_err(DecodingError::Protobuf)?; Ok(MsgEnvelope::Channel(ChannelMsg::OpenInit(domain_msg))) } CHAN_OPEN_TRY_TYPE_URL => { let domain_msg = MsgChannelOpenTry::decode_vec(&any_msg.value) - .map_err(|e| RouterError::Decoding(DecodingError::Protobuf(e)))?; + .map_err(DecodingError::Protobuf)?; Ok(MsgEnvelope::Channel(ChannelMsg::OpenTry(domain_msg))) } CHAN_OPEN_ACK_TYPE_URL => { let domain_msg = MsgChannelOpenAck::decode_vec(&any_msg.value) - .map_err(|e| RouterError::Decoding(DecodingError::Protobuf(e)))?; + .map_err(DecodingError::Protobuf)?; Ok(MsgEnvelope::Channel(ChannelMsg::OpenAck(domain_msg))) } CHAN_OPEN_CONFIRM_TYPE_URL => { let domain_msg = MsgChannelOpenConfirm::decode_vec(&any_msg.value) - .map_err(|e| RouterError::Decoding(DecodingError::Protobuf(e)))?; + .map_err(DecodingError::Protobuf)?; Ok(MsgEnvelope::Channel(ChannelMsg::OpenConfirm(domain_msg))) } CHAN_CLOSE_INIT_TYPE_URL => { let domain_msg = MsgChannelCloseInit::decode_vec(&any_msg.value) - .map_err(|e| RouterError::Decoding(DecodingError::Protobuf(e)))?; + .map_err(DecodingError::Protobuf)?; Ok(MsgEnvelope::Channel(ChannelMsg::CloseInit(domain_msg))) } CHAN_CLOSE_CONFIRM_TYPE_URL => { let domain_msg = MsgChannelCloseConfirm::decode_vec(&any_msg.value) - .map_err(|e| RouterError::Decoding(DecodingError::Protobuf(e)))?; + .map_err(DecodingError::Protobuf)?; Ok(MsgEnvelope::Channel(ChannelMsg::CloseConfirm(domain_msg))) } // ICS04 packet messages RECV_PACKET_TYPE_URL => { - let domain_msg = MsgRecvPacket::decode_vec(&any_msg.value) - .map_err(|e| RouterError::Decoding(DecodingError::Protobuf(e)))?; + let domain_msg = + MsgRecvPacket::decode_vec(&any_msg.value).map_err(DecodingError::Protobuf)?; Ok(MsgEnvelope::Packet(PacketMsg::Recv(domain_msg))) } ACKNOWLEDGEMENT_TYPE_URL => { let domain_msg = MsgAcknowledgement::decode_vec(&any_msg.value) - .map_err(|e| RouterError::Decoding(DecodingError::Protobuf(e)))?; + .map_err(DecodingError::Protobuf)?; Ok(MsgEnvelope::Packet(PacketMsg::Ack(domain_msg))) } TIMEOUT_TYPE_URL => { - let domain_msg = MsgTimeout::decode_vec(&any_msg.value) - .map_err(|e| RouterError::Decoding(DecodingError::Protobuf(e)))?; + let domain_msg = + MsgTimeout::decode_vec(&any_msg.value).map_err(DecodingError::Protobuf)?; Ok(MsgEnvelope::Packet(PacketMsg::Timeout(domain_msg))) } TIMEOUT_ON_CLOSE_TYPE_URL => { let domain_msg = MsgTimeoutOnClose::decode_vec(&any_msg.value) - .map_err(|e| RouterError::Decoding(DecodingError::Protobuf(e)))?; + .map_err(DecodingError::Protobuf)?; Ok(MsgEnvelope::Packet(PacketMsg::TimeoutOnClose(domain_msg))) } - _ => Err(RouterError::UnknownMessageTypeUrl(any_msg.type_url)), + + _ => Err(DecodingError::UnknownTypeUrl(any_msg.type_url))?, } } } diff --git a/ibc-core/ics26-routing/types/src/error.rs b/ibc-core/ics26-routing/types/src/error.rs index aab2fa8fd..cb998dd76 100644 --- a/ibc-core/ics26-routing/types/src/error.rs +++ b/ibc-core/ics26-routing/types/src/error.rs @@ -4,14 +4,12 @@ use ibc_core_host_types::identifiers::PortId; use ibc_primitives::prelude::*; /// Error type for the router module. -#[derive(Debug, Display)] +#[derive(Debug, Display, derive_more::From)] pub enum RouterError { /// decoding error: `{0}` Decoding(DecodingError), /// missing module MissingModule, - /// unknown message type URL `{0}` - UnknownMessageTypeUrl(String), /// unknown port `{0}` UnknownPort(PortId), } From 9a776c85e4b87871dcd29285ea33927e1da61f47 Mon Sep 17 00:00:00 2001 From: Sean Chen Date: Thu, 29 Aug 2024 16:00:40 -0500 Subject: [PATCH 27/73] Add derive_more::From on TokenTransferError --- ibc-apps/ics20-transfer/types/src/coin.rs | 5 +++- ibc-apps/ics20-transfer/types/src/denom.rs | 5 +++- ibc-apps/ics20-transfer/types/src/error.rs | 28 +++++++++---------- .../ics20-transfer/types/src/msgs/transfer.rs | 13 ++++----- .../types/src/msgs/transfer.rs | 13 ++++----- 5 files changed, 31 insertions(+), 33 deletions(-) diff --git a/ibc-apps/ics20-transfer/types/src/coin.rs b/ibc-apps/ics20-transfer/types/src/coin.rs index 9470bbdbc..2f091eb84 100644 --- a/ibc-apps/ics20-transfer/types/src/coin.rs +++ b/ibc-apps/ics20-transfer/types/src/coin.rs @@ -76,7 +76,10 @@ where .chars() .all(|x| x.is_alphanumeric() || VALID_DENOM_CHARACTERS.contains(x)) }) - .ok_or_else(|| TokenTransferError::InvalidCoin(coin_str.to_string()))?; + .ok_or_else(|| TokenTransferError::FailedToParseType { + expected: "Coin".to_string(), + actual: coin_str.to_string(), + })?; Ok(Coin { amount: amount.parse()?, diff --git a/ibc-apps/ics20-transfer/types/src/denom.rs b/ibc-apps/ics20-transfer/types/src/denom.rs index cc814280f..b668813a5 100644 --- a/ibc-apps/ics20-transfer/types/src/denom.rs +++ b/ibc-apps/ics20-transfer/types/src/denom.rs @@ -219,7 +219,10 @@ impl FromStr for TracePath { remaining_parts .is_none() .then_some(trace_path) - .ok_or_else(|| TokenTransferError::InvalidTrace(s.to_string())) + .ok_or_else(|| TokenTransferError::FailedToParseType { + expected: "TracePath".to_string(), + actual: s.to_string(), + }) } } diff --git a/ibc-apps/ics20-transfer/types/src/error.rs b/ibc-apps/ics20-transfer/types/src/error.rs index 72a68f4c3..892dcc6ee 100644 --- a/ibc-apps/ics20-transfer/types/src/error.rs +++ b/ibc-apps/ics20-transfer/types/src/error.rs @@ -10,7 +10,7 @@ use ibc_core::host::types::identifiers::{ChannelId, PortId}; use ibc_core::primitives::prelude::*; use uint::FromDecStrErr; -#[derive(Display, Debug)] +#[derive(Display, Debug, derive_more::From)] pub enum TokenTransferError { /// context error: `{0}` ContextError(ContextError), @@ -18,12 +18,8 @@ pub enum TokenTransferError { Decoding(DecodingError), /// identifier error: `{0}` Identifier(IdentifierError), - /// invalid trace: `{0}` - InvalidTrace(String), /// invalid amount: `{0}` InvalidAmount(FromDecStrErr), - /// invalid coin: `{0}` - InvalidCoin(String), /// missing token MissingToken, /// missing destination channel `{channel_id}` on port `{port_id}` @@ -43,6 +39,8 @@ pub enum TokenTransferError { // to a host-relevant error /// failed to parse account ID FailedToParseAccount, + /// failed to parse `{expected}` from `{actual}` + FailedToParseType { expected: String, actual: String }, /// channel cannot be closed UnsupportedClosedChannel, /// empty base denomination @@ -68,17 +66,17 @@ impl From for TokenTransferError { } } -impl From for TokenTransferError { - fn from(e: ContextError) -> Self { - Self::ContextError(e) - } -} +// impl From for TokenTransferError { +// fn from(e: ContextError) -> Self { +// Self::ContextError(e) +// } +// } -impl From for TokenTransferError { - fn from(e: IdentifierError) -> Self { - Self::Identifier(e) - } -} +// impl From for TokenTransferError { +// fn from(e: IdentifierError) -> Self { +// Self::Identifier(e) +// } +// } impl From for StatusValue { fn from(e: TokenTransferError) -> Self { diff --git a/ibc-apps/ics20-transfer/types/src/msgs/transfer.rs b/ibc-apps/ics20-transfer/types/src/msgs/transfer.rs index eefcdbf5d..fcc23863b 100644 --- a/ibc-apps/ics20-transfer/types/src/msgs/transfer.rs +++ b/ibc-apps/ics20-transfer/types/src/msgs/transfer.rs @@ -105,14 +105,11 @@ impl TryFrom for MsgTransfer { fn try_from(raw: Any) -> Result { match raw.type_url.as_str() { - TYPE_URL => MsgTransfer::decode_vec(&raw.value) - .map_err(|e| TokenTransferError::Decoding(DecodingError::Protobuf(e))), - _ => Err(TokenTransferError::Decoding( - DecodingError::MismatchedTypeUrls { - expected: TYPE_URL.to_string(), - actual: raw.type_url, - }, - )), + TYPE_URL => Ok(MsgTransfer::decode_vec(&raw.value).map_err(DecodingError::Protobuf)?), + _ => Err(DecodingError::MismatchedTypeUrls { + expected: TYPE_URL.to_string(), + actual: raw.type_url, + })?, } } } diff --git a/ibc-apps/ics721-nft-transfer/types/src/msgs/transfer.rs b/ibc-apps/ics721-nft-transfer/types/src/msgs/transfer.rs index abd73e681..5b2bfb077 100644 --- a/ibc-apps/ics721-nft-transfer/types/src/msgs/transfer.rs +++ b/ibc-apps/ics721-nft-transfer/types/src/msgs/transfer.rs @@ -123,14 +123,11 @@ impl TryFrom for MsgTransfer { fn try_from(raw: Any) -> Result { match raw.type_url.as_str() { - TYPE_URL => MsgTransfer::decode_vec(&raw.value) - .map_err(|e| NftTransferError::Decoding(DecodingError::Protobuf(e))), - _ => Err(NftTransferError::Decoding( - DecodingError::MismatchedTypeUrls { - expected: TYPE_URL.to_string(), - actual: raw.type_url, - }, - )), + TYPE_URL => Ok(MsgTransfer::decode_vec(&raw.value).map_err(DecodingError::Protobuf)?), + _ => Err(DecodingError::MismatchedTypeUrls { + expected: TYPE_URL.to_string(), + actual: raw.type_url, + })?, } } } From 023595c190555866fd3821b0598fbd2607793b32 Mon Sep 17 00:00:00 2001 From: Sean Chen Date: Thu, 29 Aug 2024 16:04:01 -0500 Subject: [PATCH 28/73] Add derive_more to NftTransferError --- ibc-apps/ics20-transfer/types/src/error.rs | 12 ----------- .../ics721-nft-transfer/types/src/error.rs | 20 +------------------ 2 files changed, 1 insertion(+), 31 deletions(-) diff --git a/ibc-apps/ics20-transfer/types/src/error.rs b/ibc-apps/ics20-transfer/types/src/error.rs index 892dcc6ee..31180b646 100644 --- a/ibc-apps/ics20-transfer/types/src/error.rs +++ b/ibc-apps/ics20-transfer/types/src/error.rs @@ -66,18 +66,6 @@ impl From for TokenTransferError { } } -// impl From for TokenTransferError { -// fn from(e: ContextError) -> Self { -// Self::ContextError(e) -// } -// } - -// impl From for TokenTransferError { -// fn from(e: IdentifierError) -> Self { -// Self::Identifier(e) -// } -// } - impl From for StatusValue { fn from(e: TokenTransferError) -> Self { StatusValue::new(e.to_string()).expect("error message must not be empty") diff --git a/ibc-apps/ics721-nft-transfer/types/src/error.rs b/ibc-apps/ics721-nft-transfer/types/src/error.rs index c04b391b6..6826f4a58 100644 --- a/ibc-apps/ics721-nft-transfer/types/src/error.rs +++ b/ibc-apps/ics721-nft-transfer/types/src/error.rs @@ -10,7 +10,7 @@ use ibc_core::host::types::error::{DecodingError, IdentifierError}; use ibc_core::host::types::identifiers::{ChannelId, PortId}; use ibc_core::primitives::prelude::*; -#[derive(Display, Debug)] +#[derive(Display, Debug, derive_more::From)] pub enum NftTransferError { /// context error: `{0}` ContextError(ContextError), @@ -64,24 +64,6 @@ impl From for NftTransferError { } } -impl From for NftTransferError { - fn from(e: ContextError) -> Self { - Self::ContextError(e) - } -} - -impl From for NftTransferError { - fn from(e: IdentifierError) -> Self { - Self::Identifier(e) - } -} - -impl From for NftTransferError { - fn from(e: DecodingError) -> Self { - Self::Decoding(e) - } -} - impl From for StatusValue { fn from(e: NftTransferError) -> Self { StatusValue::new(e.to_string()).expect("error message must not be empty") From 0341ebd19998ecd85431fd5fd4f4aa82c097bcd8 Mon Sep 17 00:00:00 2001 From: Sean Chen Date: Thu, 29 Aug 2024 16:07:12 -0500 Subject: [PATCH 29/73] Remove tendermint-proto dependency from ibc-primitives --- ibc-primitives/Cargo.toml | 1 - 1 file changed, 1 deletion(-) diff --git a/ibc-primitives/Cargo.toml b/ibc-primitives/Cargo.toml index 1e090acf6..dac541f33 100644 --- a/ibc-primitives/Cargo.toml +++ b/ibc-primitives/Cargo.toml @@ -33,7 +33,6 @@ ibc-proto = { workspace = true } # cosmos dependencies tendermint = { workspace = true } -tendermint-proto = { workspace = true } # parity dependencies parity-scale-codec = { workspace = true, optional = true } From 6be11a0008b17f34044cf25de6f6dac81a99eea0 Mon Sep 17 00:00:00 2001 From: Sean Chen Date: Fri, 30 Aug 2024 09:32:58 -0500 Subject: [PATCH 30/73] Remove StatusError --- .../src/client_state/common.rs | 6 ++--- .../ics02-client/src/handler/create_client.rs | 6 ++--- .../src/handler/recover_client.rs | 6 ++--- .../ics02-client/src/handler/update_client.rs | 3 +-- .../src/handler/upgrade_client.rs | 3 +-- ibc-core/ics02-client/types/src/error.rs | 15 ++++------- ibc-core/ics02-client/types/src/status.rs | 27 ++++++------------- .../src/handler/conn_open_ack.rs | 3 +-- .../src/handler/conn_open_confirm.rs | 4 +-- .../src/handler/conn_open_init.rs | 4 +-- .../src/handler/conn_open_try.rs | 3 +-- .../src/handler/acknowledgement.rs | 4 +-- .../src/handler/chan_close_confirm.rs | 4 +-- .../src/handler/chan_close_init.rs | 4 +-- .../src/handler/chan_open_ack.rs | 4 +-- .../src/handler/chan_open_confirm.rs | 4 +-- .../src/handler/chan_open_init.rs | 4 +-- .../src/handler/chan_open_try.rs | 4 +-- .../ics04-channel/src/handler/recv_packet.rs | 4 +-- .../ics04-channel/src/handler/send_packet.rs | 4 +-- ibc-core/ics04-channel/src/handler/timeout.rs | 4 +-- .../src/handler/timeout_on_close.rs | 4 +-- .../cosmos/src/validate_self_client.rs | 6 ++--- ibc-query/src/error.rs | 10 ------- .../testapp/ibc/clients/mock/client_state.rs | 6 ++--- ibc-testkit/src/testapp/ibc/core/core_ctx.rs | 6 ++--- .../tests/core/ics02_client/create_client.rs | 20 +++++++------- 27 files changed, 52 insertions(+), 120 deletions(-) diff --git a/ibc-clients/ics07-tendermint/src/client_state/common.rs b/ibc-clients/ics07-tendermint/src/client_state/common.rs index 4528447cf..5c573135f 100644 --- a/ibc-clients/ics07-tendermint/src/client_state/common.rs +++ b/ibc-clients/ics07-tendermint/src/client_state/common.rs @@ -4,7 +4,7 @@ use ibc_client_tendermint_types::{client_type as tm_client_type, ClientState as use ibc_core_client::context::client_state::ClientStateCommon; use ibc_core_client::context::consensus_state::ConsensusState; use ibc_core_client::types::error::{ClientError, UpgradeClientError}; -use ibc_core_client::types::{Height, Status, StatusError}; +use ibc_core_client::types::{Height, Status}; use ibc_core_commitment_types::commitment::{ CommitmentPrefix, CommitmentProofBytes, CommitmentRoot, }; @@ -166,9 +166,7 @@ pub fn verify_consensus_state( }; if consensus_state_status(&tm_consensus_state, host_timestamp, trusting_period)?.is_expired() { - return Err(ClientError::ClientStatus(StatusError::UnexpectedStatus( - Status::Expired, - ))); + return Err(ClientError::UnexpectedStatus(Status::Expired)); } Ok(()) diff --git a/ibc-core/ics02-client/src/handler/create_client.rs b/ibc-core/ics02-client/src/handler/create_client.rs index 1663c2cc4..8c7010443 100644 --- a/ibc-core/ics02-client/src/handler/create_client.rs +++ b/ibc-core/ics02-client/src/handler/create_client.rs @@ -4,7 +4,7 @@ use ibc_core_client_context::prelude::*; use ibc_core_client_types::error::ClientError; use ibc_core_client_types::events::CreateClient; use ibc_core_client_types::msgs::MsgCreateClient; -use ibc_core_client_types::{Status, StatusError}; +use ibc_core_client_types::Status; use ibc_core_handler_types::error::ContextError; use ibc_core_handler_types::events::{IbcEvent, MessageEvent}; use ibc_core_host::{ClientStateMut, ClientStateRef, ExecutionContext, ValidationContext}; @@ -36,9 +36,7 @@ where let status = client_state.status(client_val_ctx, &client_id)?; if status.is_frozen() { - return Err( - ClientError::ClientStatus(StatusError::UnexpectedStatus(Status::Frozen)).into(), - ); + return Err(ClientError::UnexpectedStatus(Status::Frozen).into()); }; let host_timestamp = ctx.host_timestamp()?; diff --git a/ibc-core/ics02-client/src/handler/recover_client.rs b/ibc-core/ics02-client/src/handler/recover_client.rs index c48aae2ec..7994edab3 100644 --- a/ibc-core/ics02-client/src/handler/recover_client.rs +++ b/ibc-core/ics02-client/src/handler/recover_client.rs @@ -39,14 +39,12 @@ where substitute_client_state .status(ctx.get_client_validation_context(), &substitute_client_id)? - .verify_is_active() - .map_err(ClientError::ClientStatus)?; // TODO(seanchen1991): Why is this `map_err` necessary? + .verify_is_active()?; // Verify that the subject client is inactive, i.e., that it is either frozen or expired subject_client_state .status(ctx.get_client_validation_context(), &subject_client_id)? - .verify_is_inactive() - .map_err(ClientError::ClientStatus)?; + .verify_is_inactive()?; // Check that the subject client state and substitute client states match, i.e., that // all their respective client state parameters match except for frozen height, latest diff --git a/ibc-core/ics02-client/src/handler/update_client.rs b/ibc-core/ics02-client/src/handler/update_client.rs index d2a18b8b5..66ce95ce1 100644 --- a/ibc-core/ics02-client/src/handler/update_client.rs +++ b/ibc-core/ics02-client/src/handler/update_client.rs @@ -26,8 +26,7 @@ where client_state .status(client_val_ctx, &client_id)? - .verify_is_active() - .map_err(ClientError::ClientStatus)?; + .verify_is_active()?; let client_message = msg.client_message(); diff --git a/ibc-core/ics02-client/src/handler/upgrade_client.rs b/ibc-core/ics02-client/src/handler/upgrade_client.rs index 475e86c1d..7dce4cdaa 100644 --- a/ibc-core/ics02-client/src/handler/upgrade_client.rs +++ b/ibc-core/ics02-client/src/handler/upgrade_client.rs @@ -28,8 +28,7 @@ where // Check if the client is active. old_client_state .status(client_val_ctx, &client_id)? - .verify_is_active() - .map_err(ClientError::ClientStatus)?; + .verify_is_active()?; // Read the latest consensus state from the host chain store. let old_client_cons_state_path = ClientConsensusStatePath::new( diff --git a/ibc-core/ics02-client/types/src/error.rs b/ibc-core/ics02-client/types/src/error.rs index 5c3d0f0e7..b6eaed20d 100644 --- a/ibc-core/ics02-client/types/src/error.rs +++ b/ibc-core/ics02-client/types/src/error.rs @@ -10,7 +10,7 @@ use ibc_primitives::prelude::*; use ibc_primitives::Timestamp; use crate::height::Height; -use crate::StatusError; +use crate::Status; /// Encodes all the possible client errors #[derive(Debug, Display)] @@ -19,8 +19,6 @@ pub enum ClientError { Upgrade(UpgradeClientError), /// decoding error: `{0}` Decoding(DecodingError), - /// client status error: `{0}` - ClientStatus(StatusError), /// invalid header type: `{0}` InvalidHeaderType(String), /// invalid trust threshold: `{numerator}`/`{denominator}` @@ -45,6 +43,8 @@ pub enum ClientError { InvalidAttributeKey(String), /// invalid attribute value: `{0}` InvalidAttributeValue(String), + /// invalid status: `{0}` + InvalidStatus(String), /// missing client state for client: `{0}` MissingClientState(ClientId), /// missing consensus state for client `{client_id}` at height `{height}` @@ -65,6 +65,8 @@ pub enum ClientError { MissingAttributeKey, /// missing attribute value MissingAttributeValue, + /// unexpected status found: `{0}` + UnexpectedStatus(Status), /// client state already exists: `{0}` AlreadyExistingClientState(ClientId), /// mismatched client recovery states @@ -108,18 +110,11 @@ impl From for ClientError { } } -impl From for ClientError { - fn from(e: StatusError) -> Self { - Self::ClientStatus(e) - } -} - #[cfg(feature = "std")] impl std::error::Error for ClientError { fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { match &self { Self::FailedICS23Verification(e) => Some(e), - Self::ClientStatus(e) => Some(e), Self::Decoding(e) => Some(e), _ => None, } diff --git a/ibc-core/ics02-client/types/src/status.rs b/ibc-core/ics02-client/types/src/status.rs index a16d1218d..25f28d3cf 100644 --- a/ibc-core/ics02-client/types/src/status.rs +++ b/ibc-core/ics02-client/types/src/status.rs @@ -1,9 +1,10 @@ use core::fmt::{Debug, Display, Formatter}; use core::str::FromStr; -use displaydoc::Display; use ibc_primitives::prelude::*; +use crate::error::ClientError; + /// `UpdateKind` represents the 2 ways that a client can be updated /// in IBC: either through a `MsgUpdateClient`, or a `MsgSubmitMisbehaviour`. #[derive(Clone, Debug, PartialEq, Eq)] @@ -32,15 +33,6 @@ pub enum Status { Unauthorized, } -/// Encapsulates Status-related errors -#[derive(Debug, Display)] -pub enum StatusError { - /// invalid client status: `{0}` - InvalidStatus(String), - /// unexpected status found: `{0}` - UnexpectedStatus(Status), -} - impl Status { pub fn is_active(&self) -> bool { *self == Status::Active @@ -55,18 +47,18 @@ impl Status { } /// Checks whether the status is active; returns `Err` if not. - pub fn verify_is_active(&self) -> Result<(), StatusError> { + pub fn verify_is_active(&self) -> Result<(), ClientError> { match self { Self::Active => Ok(()), - &status => Err(StatusError::UnexpectedStatus(status)), + &status => Err(ClientError::UnexpectedStatus(status)), } } /// Checks whether the client is either frozen or expired; returns `Err` if not. - pub fn verify_is_inactive(&self) -> Result<(), StatusError> { + pub fn verify_is_inactive(&self) -> Result<(), ClientError> { match self { Self::Frozen | Self::Expired => Ok(()), - &status => Err(StatusError::UnexpectedStatus(status)), + &status => Err(ClientError::UnexpectedStatus(status)), } } } @@ -78,7 +70,7 @@ impl Display for Status { } impl FromStr for Status { - type Err = StatusError; + type Err = ClientError; fn from_str(s: &str) -> Result { match s { @@ -86,10 +78,7 @@ impl FromStr for Status { "FROZEN" => Ok(Status::Frozen), "EXPIRED" => Ok(Status::Expired), "UNAUTHORIZED" => Ok(Status::Unauthorized), - _ => Err(StatusError::InvalidStatus(s.to_string())), + _ => Err(ClientError::InvalidStatus(s.to_string())), } } } - -#[cfg(feature = "std")] -impl std::error::Error for StatusError {} diff --git a/ibc-core/ics03-connection/src/handler/conn_open_ack.rs b/ibc-core/ics03-connection/src/handler/conn_open_ack.rs index 493bb1f8d..91027ff43 100644 --- a/ibc-core/ics03-connection/src/handler/conn_open_ack.rs +++ b/ibc-core/ics03-connection/src/handler/conn_open_ack.rs @@ -67,8 +67,7 @@ where client_state_of_b_on_a .status(client_val_ctx_a, vars.client_id_on_a())? - .verify_is_active() - .map_err(ClientError::ClientStatus)?; + .verify_is_active()?; client_state_of_b_on_a.validate_proof_height(msg.proofs_height_on_b)?; diff --git a/ibc-core/ics03-connection/src/handler/conn_open_confirm.rs b/ibc-core/ics03-connection/src/handler/conn_open_confirm.rs index b622a3037..1987c047f 100644 --- a/ibc-core/ics03-connection/src/handler/conn_open_confirm.rs +++ b/ibc-core/ics03-connection/src/handler/conn_open_confirm.rs @@ -1,7 +1,6 @@ //! Protocol logic specific to processing ICS3 messages of type `MsgConnectionOpenConfirm`. use ibc_core_client::context::prelude::*; -use ibc_core_client::types::error::ClientError; use ibc_core_connection_types::error::ConnectionError; use ibc_core_connection_types::events::OpenConfirm; use ibc_core_connection_types::msgs::MsgConnectionOpenConfirm; @@ -48,8 +47,7 @@ where client_state_of_a_on_b .status(client_val_ctx_b, client_id_on_b)? - .verify_is_active() - .map_err(ClientError::ClientStatus)?; + .verify_is_active()?; client_state_of_a_on_b.validate_proof_height(msg.proof_height_on_a)?; diff --git a/ibc-core/ics03-connection/src/handler/conn_open_init.rs b/ibc-core/ics03-connection/src/handler/conn_open_init.rs index f6196a787..8d4286616 100644 --- a/ibc-core/ics03-connection/src/handler/conn_open_init.rs +++ b/ibc-core/ics03-connection/src/handler/conn_open_init.rs @@ -1,6 +1,5 @@ //! Protocol logic specific to ICS3 messages of type `MsgConnectionOpenInit`. use ibc_core_client::context::prelude::*; -use ibc_core_client::types::error::ClientError; use ibc_core_connection_types::events::OpenInit; use ibc_core_connection_types::msgs::MsgConnectionOpenInit; use ibc_core_connection_types::{ConnectionEnd, Counterparty, State}; @@ -24,8 +23,7 @@ where client_state_of_b_on_a .status(client_val_ctx_a, &msg.client_id_on_a)? - .verify_is_active() - .map_err(ClientError::ClientStatus)?; + .verify_is_active()?; if let Some(version) = msg.version { version.verify_is_supported(&ctx_a.get_compatible_versions())?; diff --git a/ibc-core/ics03-connection/src/handler/conn_open_try.rs b/ibc-core/ics03-connection/src/handler/conn_open_try.rs index 4c86a6261..fbb013824 100644 --- a/ibc-core/ics03-connection/src/handler/conn_open_try.rs +++ b/ibc-core/ics03-connection/src/handler/conn_open_try.rs @@ -67,8 +67,7 @@ where client_state_of_a_on_b .status(client_val_ctx_b, &msg.client_id_on_b)? - .verify_is_active() - .map_err(ClientError::ClientStatus)?; + .verify_is_active()?; client_state_of_a_on_b.validate_proof_height(msg.proofs_height_on_a)?; diff --git a/ibc-core/ics04-channel/src/handler/acknowledgement.rs b/ibc-core/ics04-channel/src/handler/acknowledgement.rs index a0cb98e86..e5f484f2b 100644 --- a/ibc-core/ics04-channel/src/handler/acknowledgement.rs +++ b/ibc-core/ics04-channel/src/handler/acknowledgement.rs @@ -4,7 +4,6 @@ use ibc_core_channel_types::error::{ChannelError, PacketError}; use ibc_core_channel_types::events::AcknowledgePacket; use ibc_core_channel_types::msgs::MsgAcknowledgement; use ibc_core_client::context::prelude::*; -use ibc_core_client::types::error::ClientError; use ibc_core_connection::delay::verify_conn_delay_passed; use ibc_core_connection::types::State as ConnectionState; use ibc_core_handler_types::error::ContextError; @@ -177,8 +176,7 @@ where client_state_of_b_on_a .status(ctx_a.get_client_validation_context(), client_id_on_a)? - .verify_is_active() - .map_err(ClientError::ClientStatus)?; + .verify_is_active()?; client_state_of_b_on_a.validate_proof_height(msg.proof_height_on_b)?; diff --git a/ibc-core/ics04-channel/src/handler/chan_close_confirm.rs b/ibc-core/ics04-channel/src/handler/chan_close_confirm.rs index fb3479864..5b315ecbf 100644 --- a/ibc-core/ics04-channel/src/handler/chan_close_confirm.rs +++ b/ibc-core/ics04-channel/src/handler/chan_close_confirm.rs @@ -5,7 +5,6 @@ use ibc_core_channel_types::error::ChannelError; use ibc_core_channel_types::events::CloseConfirm; use ibc_core_channel_types::msgs::MsgChannelCloseConfirm; use ibc_core_client::context::prelude::*; -use ibc_core_client::types::error::ClientError; use ibc_core_connection::types::State as ConnectionState; use ibc_core_connection_types::error::ConnectionError; use ibc_core_handler_types::error::ContextError; @@ -114,8 +113,7 @@ where client_state_of_a_on_b .status(ctx_b.get_client_validation_context(), client_id_on_b)? - .verify_is_active() - .map_err(ClientError::ClientStatus)?; + .verify_is_active()?; client_state_of_a_on_b.validate_proof_height(msg.proof_height_on_a)?; diff --git a/ibc-core/ics04-channel/src/handler/chan_close_init.rs b/ibc-core/ics04-channel/src/handler/chan_close_init.rs index ba2bd2585..6bdab73f6 100644 --- a/ibc-core/ics04-channel/src/handler/chan_close_init.rs +++ b/ibc-core/ics04-channel/src/handler/chan_close_init.rs @@ -4,7 +4,6 @@ use ibc_core_channel_types::error::ChannelError; use ibc_core_channel_types::events::CloseInit; use ibc_core_channel_types::msgs::MsgChannelCloseInit; use ibc_core_client::context::prelude::*; -use ibc_core_client::types::error::ClientError; use ibc_core_connection::types::State as ConnectionState; use ibc_core_handler_types::error::ContextError; use ibc_core_handler_types::events::{IbcEvent, MessageEvent}; @@ -111,8 +110,7 @@ where let client_state_of_b_on_a = client_val_ctx_a.client_state(client_id_on_a)?; client_state_of_b_on_a .status(ctx_a.get_client_validation_context(), client_id_on_a)? - .verify_is_active() - .map_err(ClientError::ClientStatus)?; + .verify_is_active()?; Ok(()) } diff --git a/ibc-core/ics04-channel/src/handler/chan_open_ack.rs b/ibc-core/ics04-channel/src/handler/chan_open_ack.rs index bc3506652..f6271bcd0 100644 --- a/ibc-core/ics04-channel/src/handler/chan_open_ack.rs +++ b/ibc-core/ics04-channel/src/handler/chan_open_ack.rs @@ -4,7 +4,6 @@ use ibc_core_channel_types::error::ChannelError; use ibc_core_channel_types::events::OpenAck; use ibc_core_channel_types::msgs::MsgChannelOpenAck; use ibc_core_client::context::prelude::*; -use ibc_core_client::types::error::ClientError; use ibc_core_connection::types::State as ConnectionState; use ibc_core_connection_types::error::ConnectionError; use ibc_core_handler_types::error::ContextError; @@ -115,8 +114,7 @@ where client_state_of_b_on_a .status(ctx_a.get_client_validation_context(), client_id_on_a)? - .verify_is_active() - .map_err(ClientError::ClientStatus)?; + .verify_is_active()?; client_state_of_b_on_a.validate_proof_height(msg.proof_height_on_b)?; diff --git a/ibc-core/ics04-channel/src/handler/chan_open_confirm.rs b/ibc-core/ics04-channel/src/handler/chan_open_confirm.rs index 71ad5a00f..2ea7078a4 100644 --- a/ibc-core/ics04-channel/src/handler/chan_open_confirm.rs +++ b/ibc-core/ics04-channel/src/handler/chan_open_confirm.rs @@ -5,7 +5,6 @@ use ibc_core_channel_types::error::ChannelError; use ibc_core_channel_types::events::OpenConfirm; use ibc_core_channel_types::msgs::MsgChannelOpenConfirm; use ibc_core_client::context::prelude::*; -use ibc_core_client::types::error::ClientError; use ibc_core_connection::types::State as ConnectionState; use ibc_core_connection_types::error::ConnectionError; use ibc_core_handler_types::error::ContextError; @@ -119,8 +118,7 @@ where client_state_of_a_on_b .status(ctx_b.get_client_validation_context(), client_id_on_b)? - .verify_is_active() - .map_err(ClientError::ClientStatus)?; + .verify_is_active()?; client_state_of_a_on_b.validate_proof_height(msg.proof_height_on_a)?; diff --git a/ibc-core/ics04-channel/src/handler/chan_open_init.rs b/ibc-core/ics04-channel/src/handler/chan_open_init.rs index 0553b7b1d..58a161d0b 100644 --- a/ibc-core/ics04-channel/src/handler/chan_open_init.rs +++ b/ibc-core/ics04-channel/src/handler/chan_open_init.rs @@ -4,7 +4,6 @@ use ibc_core_channel_types::channel::{ChannelEnd, Counterparty, State}; use ibc_core_channel_types::events::OpenInit; use ibc_core_channel_types::msgs::MsgChannelOpenInit; use ibc_core_client::context::prelude::*; -use ibc_core_client::types::error::ClientError; use ibc_core_handler_types::error::ContextError; use ibc_core_handler_types::events::{IbcEvent, MessageEvent}; use ibc_core_host::types::identifiers::ChannelId; @@ -126,8 +125,7 @@ where client_state_of_b_on_a .status(ctx_a.get_client_validation_context(), client_id_on_a)? - .verify_is_active() - .map_err(ClientError::ClientStatus)?; + .verify_is_active()?; let conn_version = conn_end_on_a.versions(); diff --git a/ibc-core/ics04-channel/src/handler/chan_open_try.rs b/ibc-core/ics04-channel/src/handler/chan_open_try.rs index 738f8d67c..48138ce69 100644 --- a/ibc-core/ics04-channel/src/handler/chan_open_try.rs +++ b/ibc-core/ics04-channel/src/handler/chan_open_try.rs @@ -5,7 +5,6 @@ use ibc_core_channel_types::error::ChannelError; use ibc_core_channel_types::events::OpenTry; use ibc_core_channel_types::msgs::MsgChannelOpenTry; use ibc_core_client::context::prelude::*; -use ibc_core_client::types::error::ClientError; use ibc_core_connection::types::State as ConnectionState; use ibc_core_connection_types::error::ConnectionError; use ibc_core_handler_types::error::ContextError; @@ -141,8 +140,7 @@ where client_state_of_a_on_b .status(ctx_b.get_client_validation_context(), client_id_on_b)? - .verify_is_active() - .map_err(ClientError::ClientStatus)?; + .verify_is_active()?; client_state_of_a_on_b.validate_proof_height(msg.proof_height_on_a)?; diff --git a/ibc-core/ics04-channel/src/handler/recv_packet.rs b/ibc-core/ics04-channel/src/handler/recv_packet.rs index fe7230b20..f3229f493 100644 --- a/ibc-core/ics04-channel/src/handler/recv_packet.rs +++ b/ibc-core/ics04-channel/src/handler/recv_packet.rs @@ -5,7 +5,6 @@ use ibc_core_channel_types::events::{ReceivePacket, WriteAcknowledgement}; use ibc_core_channel_types::msgs::MsgRecvPacket; use ibc_core_channel_types::packet::Receipt; use ibc_core_client::context::prelude::*; -use ibc_core_client::types::error::ClientError; use ibc_core_connection::delay::verify_conn_delay_passed; use ibc_core_connection::types::State as ConnectionState; use ibc_core_handler_types::error::ContextError; @@ -187,8 +186,7 @@ where client_state_of_a_on_b .status(ctx_b.get_client_validation_context(), client_id_on_b)? - .verify_is_active() - .map_err(ClientError::ClientStatus)?; + .verify_is_active()?; client_state_of_a_on_b.validate_proof_height(msg.proof_height_on_a)?; diff --git a/ibc-core/ics04-channel/src/handler/send_packet.rs b/ibc-core/ics04-channel/src/handler/send_packet.rs index 6247197cf..6680bf6fb 100644 --- a/ibc-core/ics04-channel/src/handler/send_packet.rs +++ b/ibc-core/ics04-channel/src/handler/send_packet.rs @@ -4,7 +4,6 @@ use ibc_core_channel_types::error::PacketError; use ibc_core_channel_types::events::SendPacket; use ibc_core_channel_types::packet::Packet; use ibc_core_client::context::prelude::*; -use ibc_core_client::types::error::ClientError; use ibc_core_handler_types::error::ContextError; use ibc_core_handler_types::events::{IbcEvent, MessageEvent}; use ibc_core_host::types::path::{ @@ -60,8 +59,7 @@ pub fn send_packet_validate( client_state_of_b_on_a .status(ctx_a.get_client_validation_context(), client_id_on_a)? - .verify_is_active() - .map_err(ClientError::ClientStatus)?; + .verify_is_active()?; let latest_height_on_a = client_state_of_b_on_a.latest_height(); diff --git a/ibc-core/ics04-channel/src/handler/timeout.rs b/ibc-core/ics04-channel/src/handler/timeout.rs index 325803985..9ce98bc0a 100644 --- a/ibc-core/ics04-channel/src/handler/timeout.rs +++ b/ibc-core/ics04-channel/src/handler/timeout.rs @@ -4,7 +4,6 @@ use ibc_core_channel_types::error::{ChannelError, PacketError}; use ibc_core_channel_types::events::{ChannelClosed, TimeoutPacket}; use ibc_core_channel_types::msgs::{MsgTimeout, MsgTimeoutOnClose}; use ibc_core_client::context::prelude::*; -use ibc_core_client::types::error::ClientError; use ibc_core_connection::delay::verify_conn_delay_passed; use ibc_core_handler_types::error::ContextError; use ibc_core_handler_types::events::{IbcEvent, MessageEvent}; @@ -187,8 +186,7 @@ where client_state_of_b_on_a .status(ctx_a.get_client_validation_context(), client_id_on_a)? - .verify_is_active() - .map_err(ClientError::ClientStatus)?; + .verify_is_active()?; client_state_of_b_on_a.validate_proof_height(msg.proof_height_on_b)?; diff --git a/ibc-core/ics04-channel/src/handler/timeout_on_close.rs b/ibc-core/ics04-channel/src/handler/timeout_on_close.rs index 0d31ae234..c52225f81 100644 --- a/ibc-core/ics04-channel/src/handler/timeout_on_close.rs +++ b/ibc-core/ics04-channel/src/handler/timeout_on_close.rs @@ -3,7 +3,6 @@ use ibc_core_channel_types::commitment::compute_packet_commitment; use ibc_core_channel_types::error::{ChannelError, PacketError}; use ibc_core_channel_types::msgs::MsgTimeoutOnClose; use ibc_core_client::context::prelude::*; -use ibc_core_client::types::error::ClientError; use ibc_core_connection::delay::verify_conn_delay_passed; use ibc_core_connection::types::error::ConnectionError; use ibc_core_handler_types::error::ContextError; @@ -71,8 +70,7 @@ where client_state_of_b_on_a .status(ctx_a.get_client_validation_context(), client_id_on_a)? - .verify_is_active() - .map_err(ClientError::ClientStatus)?; + .verify_is_active()?; client_state_of_b_on_a.validate_proof_height(msg.proof_height_on_b)?; diff --git a/ibc-core/ics24-host/cosmos/src/validate_self_client.rs b/ibc-core/ics24-host/cosmos/src/validate_self_client.rs index 6f72e2937..f6d66994d 100644 --- a/ibc-core/ics24-host/cosmos/src/validate_self_client.rs +++ b/ibc-core/ics24-host/cosmos/src/validate_self_client.rs @@ -2,7 +2,7 @@ use core::time::Duration; use ibc_client_tendermint::types::ClientState as TmClientState; use ibc_core_client_types::error::ClientError; -use ibc_core_client_types::{Height, Status, StatusError}; +use ibc_core_client_types::{Height, Status}; use ibc_core_commitment_types::specs::ProofSpecs; use ibc_core_connection_types::error::ConnectionError; use ibc_core_handler_types::error::ContextError; @@ -25,9 +25,7 @@ pub trait ValidateSelfClientContext { .map_err(ClientError::from)?; if client_state_of_host_on_counterparty.is_frozen() { - return Err( - ClientError::ClientStatus(StatusError::UnexpectedStatus(Status::Frozen)).into(), - ); + return Err(ClientError::UnexpectedStatus(Status::Frozen).into()); } let self_chain_id = self.chain_id(); diff --git a/ibc-query/src/error.rs b/ibc-query/src/error.rs index badea0b59..4c41120eb 100644 --- a/ibc-query/src/error.rs +++ b/ibc-query/src/error.rs @@ -3,7 +3,6 @@ use alloc::string::{String, ToString}; use displaydoc::Display; use ibc::core::channel::types::error::{ChannelError, PacketError}; use ibc::core::client::types::error::ClientError; -use ibc::core::client::types::StatusError; use ibc::core::connection::types::error::ConnectionError; use ibc::core::handler::types::error::ContextError; use ibc::core::host::types::error::IdentifierError; @@ -16,8 +15,6 @@ use tonic::Status; pub enum QueryError { /// context error: `{0}` ContextError(ContextError), - /// client status error: `{0}` - ClientStatus(StatusError), /// identifier error: `{0}` IdentifierError(IdentifierError), /// missing proof: `{0}` @@ -41,7 +38,6 @@ impl From for Status { match e { QueryError::ContextError(ctx_err) => Self::internal(ctx_err.to_string()), QueryError::IdentifierError(id_err) => Self::internal(id_err.to_string()), - QueryError::ClientStatus(status_err) => Self::invalid_argument(status_err.to_string()), QueryError::MissingProof(description) => Self::not_found(description), QueryError::MissingField(description) => Self::invalid_argument(description), } @@ -83,9 +79,3 @@ impl From for QueryError { Self::IdentifierError(e) } } - -impl From for QueryError { - fn from(e: StatusError) -> Self { - Self::ClientStatus(e) - } -} diff --git a/ibc-testkit/src/testapp/ibc/clients/mock/client_state.rs b/ibc-testkit/src/testapp/ibc/clients/mock/client_state.rs index 6f8cd0533..34db638d7 100644 --- a/ibc-testkit/src/testapp/ibc/clients/mock/client_state.rs +++ b/ibc-testkit/src/testapp/ibc/clients/mock/client_state.rs @@ -4,7 +4,7 @@ use core::time::Duration; use ibc::clients::tendermint::client_state::consensus_state_status; use ibc::core::client::context::prelude::*; use ibc::core::client::types::error::{ClientError, UpgradeClientError}; -use ibc::core::client::types::{Height, Status, StatusError}; +use ibc::core::client::types::{Height, Status}; use ibc::core::commitment_types::commitment::{ CommitmentPrefix, CommitmentProofBytes, CommitmentRoot, }; @@ -172,9 +172,7 @@ impl ClientStateCommon for MockClientState { if consensus_state_status(&mock_consensus_state, host_timestamp, self.trusting_period)? .is_expired() { - return Err(ClientError::ClientStatus(StatusError::UnexpectedStatus( - Status::Expired, - ))); + return Err(ClientError::UnexpectedStatus(Status::Expired)); } Ok(()) diff --git a/ibc-testkit/src/testapp/ibc/core/core_ctx.rs b/ibc-testkit/src/testapp/ibc/core/core_ctx.rs index 41333372e..aef595159 100644 --- a/ibc-testkit/src/testapp/ibc/core/core_ctx.rs +++ b/ibc-testkit/src/testapp/ibc/core/core_ctx.rs @@ -11,7 +11,7 @@ use ibc::core::channel::types::error::{ChannelError, PacketError}; use ibc::core::channel::types::packet::{PacketState, Receipt}; use ibc::core::client::context::consensus_state::ConsensusState; use ibc::core::client::types::error::ClientError; -use ibc::core::client::types::{Height, Status, StatusError}; +use ibc::core::client::types::{Height, Status}; use ibc::core::commitment_types::commitment::CommitmentPrefix; use ibc::core::commitment_types::merkle::MerkleProof; use ibc::core::connection::types::error::ConnectionError; @@ -80,9 +80,7 @@ where client_state_of_host_on_counterparty: Self::HostClientState, ) -> Result<(), ContextError> { if client_state_of_host_on_counterparty.is_frozen() { - return Err( - ClientError::ClientStatus(StatusError::UnexpectedStatus(Status::Frozen)).into(), - ); + return Err(ClientError::UnexpectedStatus(Status::Frozen).into()); } let latest_height = self.host_height()?; diff --git a/tests-integration/tests/core/ics02_client/create_client.rs b/tests-integration/tests/core/ics02_client/create_client.rs index 3ab8712a3..c78fef45c 100644 --- a/tests-integration/tests/core/ics02_client/create_client.rs +++ b/tests-integration/tests/core/ics02_client/create_client.rs @@ -13,7 +13,7 @@ use ibc::core::handler::types::msgs::MsgEnvelope; use ibc::core::host::types::identifiers::ClientId; use ibc::core::host::types::path::{ClientConsensusStatePath, NextClientSequencePath}; use ibc::core::host::{ClientStateRef, ValidationContext}; -use ibc_core_client_types::{Status, StatusError}; +use ibc_core_client_types::Status; use ibc_query::core::context::ProvableContext; use ibc_testkit::context::{MockContext, TendermintContext}; use ibc_testkit::fixtures::clients::tendermint::dummy_tm_client_state_from_header; @@ -180,9 +180,9 @@ fn test_create_expired_mock_client() { let fxt = create_client_fixture(Ctx::Default, Msg::ExpiredMockHeader); create_client_validate( &fxt, - Expect::Failure(Some(ContextError::ClientError(ClientError::ClientStatus( - StatusError::UnexpectedStatus(Status::Expired), - )))), + Expect::Failure(Some(ContextError::ClientError( + ClientError::UnexpectedStatus(Status::Expired), + ))), ); } @@ -206,9 +206,9 @@ fn test_create_expired_tm_client() { let fxt = create_client_fixture(Ctx::Default, Msg::ExpiredTendermintHeader); create_client_validate( &fxt, - Expect::Failure(Some(ContextError::ClientError(ClientError::ClientStatus( - StatusError::UnexpectedStatus(Status::Expired), - )))), + Expect::Failure(Some(ContextError::ClientError( + ClientError::UnexpectedStatus(Status::Expired), + ))), ); } @@ -218,9 +218,9 @@ fn test_create_frozen_tm_client() { let fxt = create_client_fixture(Ctx::Default, Msg::FrozenTendermintHeader); create_client_validate( &fxt, - Expect::Failure(Some(ContextError::ClientError(ClientError::ClientStatus( - StatusError::UnexpectedStatus(Status::Frozen), - )))), + Expect::Failure(Some(ContextError::ClientError( + ClientError::UnexpectedStatus(Status::Frozen), + ))), ); } From cc2e5c6bdec4df2efa7556066ae2773dc3b6b8b5 Mon Sep 17 00:00:00 2001 From: Sean Chen Date: Fri, 30 Aug 2024 10:23:31 -0500 Subject: [PATCH 31/73] Remove unnecessary ClientError::Decoding wrappings --- .../ics07-tendermint/types/src/client_state.rs | 4 ++-- .../types/src/consensus_state.rs | 4 ++-- ibc-clients/ics07-tendermint/types/src/error.rs | 11 ++++++++++- ibc-clients/ics07-tendermint/types/src/header.rs | 16 +++++++++++----- .../ics07-tendermint/types/src/misbehaviour.rs | 4 ++-- ibc-clients/ics08-wasm/types/src/client_state.rs | 10 ++++------ .../ics08-wasm/types/src/consensus_state.rs | 4 ++-- ibc-clients/ics08-wasm/types/src/error.rs | 9 ++++++++- ibc-core/ics02-client/types/src/error.rs | 16 ++++++++++++---- .../ics02-client/types/src/msgs/misbehaviour.rs | 8 ++++---- .../types/src/msgs/recover_client.rs | 4 ++-- .../ics02-client/types/src/msgs/update_client.rs | 8 ++++---- .../types/src/msgs/upgrade_client.rs | 2 +- .../cosmos/src/upgrade_proposal/plan.rs | 15 +++++++-------- ibc-core/ics24-host/types/src/error.rs | 4 ++++ .../src/testapp/ibc/clients/mock/client_state.rs | 4 ++-- .../testapp/ibc/clients/mock/consensus_state.rs | 4 ++-- .../src/testapp/ibc/clients/mock/header.rs | 8 ++++---- .../src/testapp/ibc/clients/mock/misbehaviour.rs | 12 ++++++++---- 19 files changed, 91 insertions(+), 56 deletions(-) diff --git a/ibc-clients/ics07-tendermint/types/src/client_state.rs b/ibc-clients/ics07-tendermint/types/src/client_state.rs index 3595a7e4e..a2c5a2360 100644 --- a/ibc-clients/ics07-tendermint/types/src/client_state.rs +++ b/ibc-clients/ics07-tendermint/types/src/client_state.rs @@ -351,10 +351,10 @@ impl TryFrom for ClientState { TENDERMINT_CLIENT_STATE_TYPE_URL => { decode_client_state(&raw.value).map_err(ClientError::Decoding) } - _ => Err(ClientError::Decoding(DecodingError::MismatchedTypeUrls { + _ => Err(DecodingError::MismatchedTypeUrls { expected: TENDERMINT_CLIENT_STATE_TYPE_URL.to_string(), actual: raw.type_url, - })), + })?, } } } diff --git a/ibc-clients/ics07-tendermint/types/src/consensus_state.rs b/ibc-clients/ics07-tendermint/types/src/consensus_state.rs index 3008b756b..f069a812c 100644 --- a/ibc-clients/ics07-tendermint/types/src/consensus_state.rs +++ b/ibc-clients/ics07-tendermint/types/src/consensus_state.rs @@ -117,10 +117,10 @@ impl TryFrom for ConsensusState { TENDERMINT_CONSENSUS_STATE_TYPE_URL => { decode_consensus_state(&raw.value).map_err(ClientError::Decoding) } - _ => Err(ClientError::Decoding(DecodingError::MismatchedTypeUrls { + _ => Err(DecodingError::MismatchedTypeUrls { expected: TENDERMINT_CONSENSUS_STATE_TYPE_URL.to_string(), actual: raw.type_url, - })), + })?, } } } diff --git a/ibc-clients/ics07-tendermint/types/src/error.rs b/ibc-clients/ics07-tendermint/types/src/error.rs index 45f00354e..dde87fa60 100644 --- a/ibc-clients/ics07-tendermint/types/src/error.rs +++ b/ibc-clients/ics07-tendermint/types/src/error.rs @@ -5,7 +5,7 @@ use core::time::Duration; use displaydoc::Display; use ibc_core_client_types::error::ClientError; use ibc_core_commitment_types::error::CommitmentError; -use ibc_core_host_types::error::IdentifierError; +use ibc_core_host_types::error::{DecodingError, IdentifierError}; use ibc_primitives::prelude::*; use ibc_primitives::TimestampError; use tendermint::{Error as TendermintError, Hash}; @@ -16,6 +16,8 @@ use tendermint_light_client_verifier::Verdict; /// The main error type for the Tendermint light client #[derive(Debug, Display)] pub enum TendermintClientError { + /// decoding error: `{0}` + Decoding(DecodingError), /// invalid identifier: `{0}` InvalidIdentifier(IdentifierError), /// invalid client state trust threshold: `{description}` @@ -75,6 +77,7 @@ impl std::error::Error for TendermintClientError { match &self { Self::InvalidIdentifier(e) => Some(e), Self::InvalidRawHeader(e) => Some(e), + Self::Decoding(e) => Some(e), _ => None, } } @@ -100,6 +103,12 @@ impl From for TendermintClientError { } } +impl From for TendermintClientError { + fn from(e: DecodingError) -> Self { + Self::Decoding(e) + } +} + pub trait IntoResult { fn into_result(self) -> Result; } diff --git a/ibc-clients/ics07-tendermint/types/src/header.rs b/ibc-clients/ics07-tendermint/types/src/header.rs index 085bec887..7c33f7fdd 100644 --- a/ibc-clients/ics07-tendermint/types/src/header.rs +++ b/ibc-clients/ics07-tendermint/types/src/header.rs @@ -173,12 +173,16 @@ impl TryFrom for Header { .signed_header .ok_or(TendermintClientError::MissingSignedHeader)? .try_into() - .map_err(TendermintClientError::InvalidRawHeader)?, + .map_err(|e| DecodingError::InvalidRawData { + description: format!("{e:?}"), + })?, validator_set: raw .validator_set .ok_or(TendermintClientError::MissingValidatorSet)? .try_into() - .map_err(TendermintClientError::InvalidRawHeader)?, + .map_err(|e| DecodingError::InvalidRawData { + description: format!("{e:?}"), + })?, trusted_height: raw .trusted_height .and_then(|raw_height| raw_height.try_into().ok()) @@ -187,7 +191,9 @@ impl TryFrom for Header { .trusted_validators .ok_or(TendermintClientError::MissingTrustedNextValidatorSet)? .try_into() - .map_err(TendermintClientError::InvalidRawHeader)?, + .map_err(|e| DecodingError::InvalidRawData { + description: format!("{e:?}"), + })?, }; Ok(header) @@ -206,10 +212,10 @@ impl TryFrom for Header { } match raw.type_url.as_str() { TENDERMINT_HEADER_TYPE_URL => decode_header(&raw.value).map_err(ClientError::Decoding), - _ => Err(ClientError::Decoding(DecodingError::MismatchedTypeUrls { + _ => Err(DecodingError::MismatchedTypeUrls { expected: TENDERMINT_HEADER_TYPE_URL.to_string(), actual: raw.type_url, - })), + })?, } } } diff --git a/ibc-clients/ics07-tendermint/types/src/misbehaviour.rs b/ibc-clients/ics07-tendermint/types/src/misbehaviour.rs index 059b4b4ee..cdea2bf68 100644 --- a/ibc-clients/ics07-tendermint/types/src/misbehaviour.rs +++ b/ibc-clients/ics07-tendermint/types/src/misbehaviour.rs @@ -123,10 +123,10 @@ impl TryFrom for Misbehaviour { TENDERMINT_MISBEHAVIOUR_TYPE_URL => { decode_misbehaviour(&raw.value).map_err(ClientError::Decoding) } - _ => Err(ClientError::Decoding(DecodingError::MismatchedTypeUrls { + _ => Err(DecodingError::MismatchedTypeUrls { expected: TENDERMINT_MISBEHAVIOUR_TYPE_URL.to_string(), actual: raw.type_url, - })), + })?, } } } diff --git a/ibc-clients/ics08-wasm/types/src/client_state.rs b/ibc-clients/ics08-wasm/types/src/client_state.rs index acc2fbecd..7124636ae 100644 --- a/ibc-clients/ics08-wasm/types/src/client_state.rs +++ b/ibc-clients/ics08-wasm/types/src/client_state.rs @@ -79,12 +79,10 @@ impl TryFrom for ClientState { WASM_CLIENT_STATE_TYPE_URL => { decode_client_state(&any.value).map_err(WasmClientError::Decoding) } - _ => Err(WasmClientError::Decoding( - DecodingError::MismatchedTypeUrls { - expected: WASM_CLIENT_STATE_TYPE_URL.to_string(), - actual: any.type_url, - }, - )), + _ => Err(DecodingError::MismatchedTypeUrls { + expected: WASM_CLIENT_STATE_TYPE_URL.to_string(), + actual: any.type_url, + })?, } } } diff --git a/ibc-clients/ics08-wasm/types/src/consensus_state.rs b/ibc-clients/ics08-wasm/types/src/consensus_state.rs index 588455b9b..a1346cb32 100644 --- a/ibc-clients/ics08-wasm/types/src/consensus_state.rs +++ b/ibc-clients/ics08-wasm/types/src/consensus_state.rs @@ -66,10 +66,10 @@ impl TryFrom for ConsensusState { WASM_CONSENSUS_STATE_TYPE_URL => { decode_consensus_state(&any.value).map_err(ClientError::Decoding) } - _ => Err(ClientError::Decoding(DecodingError::MismatchedTypeUrls { + _ => Err(DecodingError::MismatchedTypeUrls { expected: WASM_CONSENSUS_STATE_TYPE_URL.to_string(), actual: any.type_url.to_string(), - })), + })?, } } } diff --git a/ibc-clients/ics08-wasm/types/src/error.rs b/ibc-clients/ics08-wasm/types/src/error.rs index b94a14b53..f7615f802 100644 --- a/ibc-clients/ics08-wasm/types/src/error.rs +++ b/ibc-clients/ics08-wasm/types/src/error.rs @@ -21,7 +21,8 @@ pub enum WasmClientError { impl std::error::Error for WasmClientError { fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { match self { - Self::InvalidIdentifier(err) => Some(err), + Self::InvalidIdentifier(e) => Some(e), + Self::Decoding(e) => Some(e), _ => None, } } @@ -32,3 +33,9 @@ impl From for WasmClientError { Self::InvalidIdentifier(e) } } + +impl From for WasmClientError { + fn from(e: DecodingError) -> Self { + Self::Decoding(e) + } +} diff --git a/ibc-core/ics02-client/types/src/error.rs b/ibc-core/ics02-client/types/src/error.rs index b6eaed20d..5fed54576 100644 --- a/ibc-core/ics02-client/types/src/error.rs +++ b/ibc-core/ics02-client/types/src/error.rs @@ -29,8 +29,6 @@ pub enum ClientError { InvalidConsensusStateType(String), /// invalid update client message InvalidUpdateClientMessage, - /// invalid raw header: `{description}` - InvalidRawHeader { description: String }, /// invalid misbehaviour type: `{0}` InvalidMisbehaviourType(String), /// invalid height; cannot be zero or negative @@ -57,8 +55,6 @@ pub enum ClientError { MissingRawConsensusState, /// missing raw client message MissingRawClientMessage, - /// missing raw misbehaviour - MissingRawMisbehaviour, /// missing local consensus state at `{0}` MissingLocalConsensusState(Height), /// missing attribute key @@ -110,6 +106,12 @@ impl From for ClientError { } } +impl From for ClientError { + fn from(e: DecodingError) -> Self { + Self::Decoding(e) + } +} + #[cfg(feature = "std")] impl std::error::Error for ClientError { fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { @@ -159,6 +161,12 @@ impl From for ClientError { } } +impl From for UpgradeClientError { + fn from(e: DecodingError) -> Self { + Self::Decoding(e) + } +} + #[cfg(feature = "std")] impl std::error::Error for UpgradeClientError { fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { diff --git a/ibc-core/ics02-client/types/src/msgs/misbehaviour.rs b/ibc-core/ics02-client/types/src/msgs/misbehaviour.rs index e5b083196..7215ca534 100644 --- a/ibc-core/ics02-client/types/src/msgs/misbehaviour.rs +++ b/ibc-core/ics02-client/types/src/msgs/misbehaviour.rs @@ -41,15 +41,15 @@ impl TryFrom for MsgSubmitMisbehaviour { type Error = ClientError; fn try_from(raw: RawMsgSubmitMisbehaviour) -> Result { - let raw_misbehaviour = raw - .misbehaviour - .ok_or(ClientError::MissingRawMisbehaviour)?; + let raw_misbehaviour = raw.misbehaviour.ok_or(DecodingError::MissingRawData { + description: "missing raw misbehaviour".to_string(), + })?; Ok(MsgSubmitMisbehaviour { client_id: raw .client_id .parse() - .map_err(|e| ClientError::Decoding(DecodingError::InvalidIdentifier(e)))?, + .map_err(DecodingError::InvalidIdentifier)?, misbehaviour: raw_misbehaviour, signer: raw.signer.into(), }) diff --git a/ibc-core/ics02-client/types/src/msgs/recover_client.rs b/ibc-core/ics02-client/types/src/msgs/recover_client.rs index d71c8d90c..6d78f0ed1 100644 --- a/ibc-core/ics02-client/types/src/msgs/recover_client.rs +++ b/ibc-core/ics02-client/types/src/msgs/recover_client.rs @@ -46,11 +46,11 @@ impl TryFrom for MsgRecoverClient { subject_client_id: raw .subject_client_id .parse() - .map_err(|e| ClientError::Decoding(DecodingError::InvalidIdentifier(e)))?, + .map_err(DecodingError::InvalidIdentifier)?, substitute_client_id: raw .substitute_client_id .parse() - .map_err(|e| ClientError::Decoding(DecodingError::InvalidIdentifier(e)))?, + .map_err(DecodingError::InvalidIdentifier)?, signer: raw.signer.into(), }) } diff --git a/ibc-core/ics02-client/types/src/msgs/update_client.rs b/ibc-core/ics02-client/types/src/msgs/update_client.rs index 26d719fac..0ffa8430a 100644 --- a/ibc-core/ics02-client/types/src/msgs/update_client.rs +++ b/ibc-core/ics02-client/types/src/msgs/update_client.rs @@ -38,10 +38,10 @@ impl TryFrom for MsgUpdateClient { client_id: raw .client_id .parse() - .map_err(|e| ClientError::Decoding(DecodingError::InvalidIdentifier(e)))?, - client_message: raw - .client_message - .ok_or(ClientError::MissingRawClientMessage)?, + .map_err(DecodingError::InvalidIdentifier)?, + client_message: raw.client_message.ok_or(DecodingError::MissingRawData { + description: "missing raw client message".to_string(), + })?, signer: raw.signer.into(), }) } diff --git a/ibc-core/ics02-client/types/src/msgs/upgrade_client.rs b/ibc-core/ics02-client/types/src/msgs/upgrade_client.rs index 1fbff9e7d..4b545e452 100644 --- a/ibc-core/ics02-client/types/src/msgs/upgrade_client.rs +++ b/ibc-core/ics02-client/types/src/msgs/upgrade_client.rs @@ -79,7 +79,7 @@ impl TryFrom for MsgUpgradeClient { Ok(MsgUpgradeClient { client_id: ClientId::from_str(&proto_msg.client_id) - .map_err(|e| ClientError::Decoding(DecodingError::InvalidIdentifier(e)))?, + .map_err(DecodingError::InvalidIdentifier)?, upgraded_client_state: raw_client_state, upgraded_consensus_state: raw_consensus_state, proof_upgrade_client: c_bytes, diff --git a/ibc-core/ics24-host/cosmos/src/upgrade_proposal/plan.rs b/ibc-core/ics24-host/cosmos/src/upgrade_proposal/plan.rs index 0a7251351..48ceaf0e5 100644 --- a/ibc-core/ics24-host/cosmos/src/upgrade_proposal/plan.rs +++ b/ibc-core/ics24-host/cosmos/src/upgrade_proposal/plan.rs @@ -84,14 +84,13 @@ impl TryFrom for Plan { fn try_from(any: Any) -> Result { match any.type_url.as_str() { - TYPE_URL => Protobuf::::decode_vec(&any.value) - .map_err(|e| UpgradeClientError::Decoding(DecodingError::Protobuf(e))), - _ => Err(UpgradeClientError::Decoding( - DecodingError::MismatchedTypeUrls { - expected: TYPE_URL.to_string(), - actual: any.type_url, - }, - )), + TYPE_URL => { + Ok(Protobuf::::decode_vec(&any.value).map_err(DecodingError::Protobuf)?) + } + _ => Err(DecodingError::MismatchedTypeUrls { + expected: TYPE_URL.to_string(), + actual: any.type_url, + })?, } } } diff --git a/ibc-core/ics24-host/types/src/error.rs b/ibc-core/ics24-host/types/src/error.rs index ad0c98b3c..9996f8268 100644 --- a/ibc-core/ics24-host/types/src/error.rs +++ b/ibc-core/ics24-host/types/src/error.rs @@ -39,6 +39,10 @@ pub enum DecodingError { InvalidJson { description: String }, /// invalid identifier error: `{0}` InvalidIdentifier(IdentifierError), + /// invalid raw data: `{description}` + InvalidRawData { description: String }, + /// missing raw data: `{description}` + MissingRawData { description: String }, /// mismatched type URLs: expected `{expected}`, actual `{actual}` MismatchedTypeUrls { expected: String, actual: String }, /// unknown type URL: `{0}` diff --git a/ibc-testkit/src/testapp/ibc/clients/mock/client_state.rs b/ibc-testkit/src/testapp/ibc/clients/mock/client_state.rs index 34db638d7..dff68ecd9 100644 --- a/ibc-testkit/src/testapp/ibc/clients/mock/client_state.rs +++ b/ibc-testkit/src/testapp/ibc/clients/mock/client_state.rs @@ -136,10 +136,10 @@ impl TryFrom for MockClientState { MOCK_CLIENT_STATE_TYPE_URL => { decode_client_state(&raw.value).map_err(ClientError::Decoding) } - _ => Err(ClientError::Decoding(DecodingError::MismatchedTypeUrls { + _ => Err(DecodingError::MismatchedTypeUrls { expected: MOCK_CLIENT_STATE_TYPE_URL.to_string(), actual: raw.type_url, - })), + })?, } } } diff --git a/ibc-testkit/src/testapp/ibc/clients/mock/consensus_state.rs b/ibc-testkit/src/testapp/ibc/clients/mock/consensus_state.rs index e5d7a2ad5..48561f087 100644 --- a/ibc-testkit/src/testapp/ibc/clients/mock/consensus_state.rs +++ b/ibc-testkit/src/testapp/ibc/clients/mock/consensus_state.rs @@ -73,10 +73,10 @@ impl TryFrom for MockConsensusState { MOCK_CONSENSUS_STATE_TYPE_URL => { decode_consensus_state(&raw.value).map_err(ClientError::Decoding) } - _ => Err(ClientError::Decoding(DecodingError::MismatchedTypeUrls { + _ => Err(DecodingError::MismatchedTypeUrls { expected: MOCK_CONSENSUS_STATE_TYPE_URL.to_string(), actual: raw.type_url, - })), + })?, } } } diff --git a/ibc-testkit/src/testapp/ibc/clients/mock/header.rs b/ibc-testkit/src/testapp/ibc/clients/mock/header.rs index a485d2341..9f46592e4 100644 --- a/ibc-testkit/src/testapp/ibc/clients/mock/header.rs +++ b/ibc-testkit/src/testapp/ibc/clients/mock/header.rs @@ -96,12 +96,12 @@ impl TryFrom for MockHeader { fn try_from(raw: Any) -> Result { match raw.type_url.as_str() { - MOCK_HEADER_TYPE_URL => Protobuf::::decode_vec(&raw.value) - .map_err(|e| ClientError::Decoding(DecodingError::Protobuf(e))), - _ => Err(ClientError::Decoding(DecodingError::MismatchedTypeUrls { + MOCK_HEADER_TYPE_URL => Ok(Protobuf::::decode_vec(&raw.value) + .map_err(DecodingError::Protobuf)?), + _ => Err(DecodingError::MismatchedTypeUrls { expected: MOCK_HEADER_TYPE_URL.to_string(), actual: raw.type_url, - })), + })?, } } } diff --git a/ibc-testkit/src/testapp/ibc/clients/mock/misbehaviour.rs b/ibc-testkit/src/testapp/ibc/clients/mock/misbehaviour.rs index 83b07623a..1e0a90091 100644 --- a/ibc-testkit/src/testapp/ibc/clients/mock/misbehaviour.rs +++ b/ibc-testkit/src/testapp/ibc/clients/mock/misbehaviour.rs @@ -27,11 +27,15 @@ impl TryFrom for Misbehaviour { client_id: ClientId::new("07-tendermint", 0).expect("no error"), header1: raw .header1 - .ok_or(ClientError::MissingRawMisbehaviour)? + .ok_or(DecodingError::MissingRawData { + description: "missing header1 in raw misbehaviour".to_string(), + })? .try_into()?, header2: raw .header2 - .ok_or(ClientError::MissingRawMisbehaviour)? + .ok_or(DecodingError::MissingRawData { + description: "missing header2 in raw misbehaviour".to_string(), + })? .try_into()?, }) } @@ -61,10 +65,10 @@ impl TryFrom for Misbehaviour { MOCK_MISBEHAVIOUR_TYPE_URL => { decode_misbehaviour(&raw.value).map_err(ClientError::Decoding) } - _ => Err(ClientError::Decoding(DecodingError::MismatchedTypeUrls { + _ => Err(DecodingError::MismatchedTypeUrls { expected: MOCK_MISBEHAVIOUR_TYPE_URL.to_string(), actual: raw.type_url, - })), + })?, } } } From 43c17eb252e39c3b5f7b02a2abdc1bccff0cd966 Mon Sep 17 00:00:00 2001 From: Sean Chen Date: Fri, 30 Aug 2024 10:32:51 -0500 Subject: [PATCH 32/73] Clean up TendermintClientError --- ibc-clients/ics07-tendermint/types/src/error.rs | 5 +---- ibc-clients/ics07-tendermint/types/src/misbehaviour.rs | 8 ++++---- ibc-testkit/src/testapp/ibc/clients/mock/misbehaviour.rs | 4 ++-- 3 files changed, 7 insertions(+), 10 deletions(-) diff --git a/ibc-clients/ics07-tendermint/types/src/error.rs b/ibc-clients/ics07-tendermint/types/src/error.rs index dde87fa60..3d2d6dfb1 100644 --- a/ibc-clients/ics07-tendermint/types/src/error.rs +++ b/ibc-clients/ics07-tendermint/types/src/error.rs @@ -8,7 +8,7 @@ use ibc_core_commitment_types::error::CommitmentError; use ibc_core_host_types::error::{DecodingError, IdentifierError}; use ibc_primitives::prelude::*; use ibc_primitives::TimestampError; -use tendermint::{Error as TendermintError, Hash}; +use tendermint::Hash; use tendermint_light_client_verifier::errors::VerificationErrorDetail as LightClientErrorDetail; use tendermint_light_client_verifier::operations::VotingPowerTally; use tendermint_light_client_verifier::Verdict; @@ -28,8 +28,6 @@ pub enum TendermintClientError { InvalidProofSpec(CommitmentError), /// invalid raw client state: `{description}` InvalidRawClientState { description: String }, - /// invalid raw header error: `{0}` - InvalidRawHeader(TendermintError), /// invalid raw misbehaviour: `{description}` InvalidRawMisbehaviour { description: String }, /// invalid header timestamp: `{0}` @@ -76,7 +74,6 @@ impl std::error::Error for TendermintClientError { fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { match &self { Self::InvalidIdentifier(e) => Some(e), - Self::InvalidRawHeader(e) => Some(e), Self::Decoding(e) => Some(e), _ => None, } diff --git a/ibc-clients/ics07-tendermint/types/src/misbehaviour.rs b/ibc-clients/ics07-tendermint/types/src/misbehaviour.rs index cdea2bf68..b49f0a328 100644 --- a/ibc-clients/ics07-tendermint/types/src/misbehaviour.rs +++ b/ibc-clients/ics07-tendermint/types/src/misbehaviour.rs @@ -82,15 +82,15 @@ impl TryFrom for Misbehaviour { let header1: Header = raw .header_1 - .ok_or_else(|| TendermintClientError::InvalidRawMisbehaviour { - description: "missing header1".into(), + .ok_or_else(|| DecodingError::MissingRawData { + description: "missing header1 in raw misbehaviour".into(), })? .try_into()?; let header2: Header = raw .header_2 - .ok_or_else(|| TendermintClientError::InvalidRawMisbehaviour { - description: "missing header2".into(), + .ok_or_else(|| DecodingError::MissingRawData { + description: "missing header2 in raw misbehaviour".into(), })? .try_into()?; diff --git a/ibc-testkit/src/testapp/ibc/clients/mock/misbehaviour.rs b/ibc-testkit/src/testapp/ibc/clients/mock/misbehaviour.rs index 1e0a90091..d537e8209 100644 --- a/ibc-testkit/src/testapp/ibc/clients/mock/misbehaviour.rs +++ b/ibc-testkit/src/testapp/ibc/clients/mock/misbehaviour.rs @@ -28,13 +28,13 @@ impl TryFrom for Misbehaviour { header1: raw .header1 .ok_or(DecodingError::MissingRawData { - description: "missing header1 in raw misbehaviour".to_string(), + description: "missing header1 in raw misbehaviour".into(), })? .try_into()?, header2: raw .header2 .ok_or(DecodingError::MissingRawData { - description: "missing header2 in raw misbehaviour".to_string(), + description: "missing header2 in raw misbehaviour".into(), })? .try_into()?, }) From 69133763a048a56169d91d0f04f86cb50827a513 Mon Sep 17 00:00:00 2001 From: Sean Chen Date: Fri, 30 Aug 2024 10:33:40 -0500 Subject: [PATCH 33/73] Regenerate cw-check cargo.lock --- ci/cw-check/Cargo.lock | 1 - 1 file changed, 1 deletion(-) diff --git a/ci/cw-check/Cargo.lock b/ci/cw-check/Cargo.lock index e0be4007f..e80c0a8a3 100644 --- a/ci/cw-check/Cargo.lock +++ b/ci/cw-check/Cargo.lock @@ -1095,7 +1095,6 @@ dependencies = [ "schemars", "serde", "tendermint", - "tendermint-proto", "time", ] From e684b54e8a40681a619f53a92773efbdfa7dd519 Mon Sep 17 00:00:00 2001 From: Sean Chen Date: Fri, 30 Aug 2024 11:43:38 -0500 Subject: [PATCH 34/73] taplo fmt --- ibc-primitives/Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ibc-primitives/Cargo.toml b/ibc-primitives/Cargo.toml index dac541f33..2c56cd6de 100644 --- a/ibc-primitives/Cargo.toml +++ b/ibc-primitives/Cargo.toml @@ -32,7 +32,7 @@ time = { version = ">=0.3.0, <0.3.37", default-features = false } ibc-proto = { workspace = true } # cosmos dependencies -tendermint = { workspace = true } +tendermint = { workspace = true } # parity dependencies parity-scale-codec = { workspace = true, optional = true } From a74351d9ccf796a9c43f2891a642d1b0a0befd02 Mon Sep 17 00:00:00 2001 From: Sean Chen Date: Fri, 30 Aug 2024 13:33:02 -0500 Subject: [PATCH 35/73] Apply PR feedback --- ibc-clients/ics07-tendermint/types/src/client_state.rs | 6 +++++- ibc-core/ics03-connection/src/handler/mod.rs | 4 +--- ibc-core/ics23-commitment/types/src/commitment.rs | 9 +++++++-- 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/ibc-clients/ics07-tendermint/types/src/client_state.rs b/ibc-clients/ics07-tendermint/types/src/client_state.rs index a2c5a2360..ca76e9c32 100644 --- a/ibc-clients/ics07-tendermint/types/src/client_state.rs +++ b/ibc-clients/ics07-tendermint/types/src/client_state.rs @@ -343,7 +343,11 @@ impl TryFrom for ClientState { fn try_from(raw: Any) -> Result { fn decode_client_state(value: &[u8]) -> Result { - let client_state = Protobuf::::decode(value)?; + let client_state = Protobuf::::decode(value).map_err(|e| { + DecodingError::Protobuf { + description: e.to_string(), + } + })?; Ok(client_state) } diff --git a/ibc-core/ics03-connection/src/handler/mod.rs b/ibc-core/ics03-connection/src/handler/mod.rs index 3421ebb16..f780295e4 100644 --- a/ibc-core/ics03-connection/src/handler/mod.rs +++ b/ibc-core/ics03-connection/src/handler/mod.rs @@ -37,9 +37,7 @@ where })?; let any_client_state = ::decode(wasm_client_state.data.as_slice()) - .map_err(|e| { - ContextError::ConnectionError(ConnectionError::Decoding(DecodingError::Prost(e))) - })?; + .map_err(|e| ConnectionError::Decoding(DecodingError::Prost(e)))?; Ok(CS::try_from(any_client_state).map_err(Into::::into)?) } else { diff --git a/ibc-core/ics23-commitment/types/src/commitment.rs b/ibc-core/ics23-commitment/types/src/commitment.rs index f43162668..0d1d34082 100644 --- a/ibc-core/ics23-commitment/types/src/commitment.rs +++ b/ibc-core/ics23-commitment/types/src/commitment.rs @@ -122,8 +122,13 @@ impl<'a> TryFrom<&'a CommitmentProofBytes> for MerkleProof { type Error = CommitmentError; fn try_from(value: &'a CommitmentProofBytes) -> Result { - Protobuf::::decode(value.as_ref()) - .map_err(|e| CommitmentError::Decoding(DecodingError::Protobuf(e))) + Ok( + Protobuf::::decode(value.as_ref()).map_err(|e| { + DecodingError::Protobuf { + description: e.to_string(), + } + })?, + ) } } From 98954a69dc8ee3e4d8cbd7a0fb6df9652108bc4a Mon Sep 17 00:00:00 2001 From: Sean Chen Date: Tue, 3 Sep 2024 11:38:09 -0500 Subject: [PATCH 36/73] Use ibc_proto::Error type instead of tendermint_proto::Error --- Cargo.toml | 2 +- ibc-clients/ics07-tendermint/types/src/client_state.rs | 7 ++----- ibc-core/ics23-commitment/types/src/commitment.rs | 8 +------- ibc-core/ics24-host/types/src/error.rs | 2 +- ibc-primitives/src/lib.rs | 1 + 5 files changed, 6 insertions(+), 14 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 454378242..f38401ab3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -105,7 +105,7 @@ ibc-client-wasm-types = { version = "0.54.0", path = "./ibc-clients/ics08- ibc-app-transfer-types = { version = "0.54.0", path = "./ibc-apps/ics20-transfer/types", default-features = false } ibc-app-nft-transfer-types = { version = "0.54.0", path = "./ibc-apps/ics721-nft-transfer/types", default-features = false } -ibc-proto = { version = "0.47.0", default-features = false } +ibc-proto = { version = "0.47.1", default-features = false } # cosmos dependencies tendermint = { version = "0.38.0", default-features = false } diff --git a/ibc-clients/ics07-tendermint/types/src/client_state.rs b/ibc-clients/ics07-tendermint/types/src/client_state.rs index ca76e9c32..87f588d82 100644 --- a/ibc-clients/ics07-tendermint/types/src/client_state.rs +++ b/ibc-clients/ics07-tendermint/types/src/client_state.rs @@ -343,11 +343,8 @@ impl TryFrom for ClientState { fn try_from(raw: Any) -> Result { fn decode_client_state(value: &[u8]) -> Result { - let client_state = Protobuf::::decode(value).map_err(|e| { - DecodingError::Protobuf { - description: e.to_string(), - } - })?; + let client_state = + Protobuf::::decode(value).map_err(DecodingError::Protobuf)?; Ok(client_state) } diff --git a/ibc-core/ics23-commitment/types/src/commitment.rs b/ibc-core/ics23-commitment/types/src/commitment.rs index 0d1d34082..1f6c94175 100644 --- a/ibc-core/ics23-commitment/types/src/commitment.rs +++ b/ibc-core/ics23-commitment/types/src/commitment.rs @@ -122,13 +122,7 @@ impl<'a> TryFrom<&'a CommitmentProofBytes> for MerkleProof { type Error = CommitmentError; fn try_from(value: &'a CommitmentProofBytes) -> Result { - Ok( - Protobuf::::decode(value.as_ref()).map_err(|e| { - DecodingError::Protobuf { - description: e.to_string(), - } - })?, - ) + Ok(Protobuf::::decode(value.as_ref()).map_err(DecodingError::Protobuf)?) } } diff --git a/ibc-core/ics24-host/types/src/error.rs b/ibc-core/ics24-host/types/src/error.rs index 9996f8268..048392de6 100644 --- a/ibc-core/ics24-host/types/src/error.rs +++ b/ibc-core/ics24-host/types/src/error.rs @@ -5,8 +5,8 @@ use alloc::string::{FromUtf8Error, String}; use base64::DecodeError as Base64Error; use displaydoc::Display; use ibc_primitives::prelude::*; +use ibc_primitives::proto::Error as ProtoError; use prost::DecodeError as ProstError; -use tendermint_proto::Error as ProtoError; /// Errors that arise when parsing identifiers. #[cfg_attr(feature = "serde", derive(serde::Serialize))] diff --git a/ibc-primitives/src/lib.rs b/ibc-primitives/src/lib.rs index 5aa99f4e5..8de7a3d39 100644 --- a/ibc-primitives/src/lib.rs +++ b/ibc-primitives/src/lib.rs @@ -32,5 +32,6 @@ pub mod serializers; pub mod proto { pub use ibc_proto::google::protobuf::{Any, Duration, Timestamp}; + pub use ibc_proto::Error; pub use ibc_proto::Protobuf; } From 60af75446d8b379b7d2c7733db112cb7f78bd863 Mon Sep 17 00:00:00 2001 From: Sean Chen Date: Tue, 3 Sep 2024 11:43:04 -0500 Subject: [PATCH 37/73] Change FailedToParseType fields to make them more clear --- ibc-apps/ics20-transfer/types/src/coin.rs | 4 ++-- ibc-apps/ics20-transfer/types/src/denom.rs | 4 ++-- ibc-apps/ics20-transfer/types/src/error.rs | 7 +++++-- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/ibc-apps/ics20-transfer/types/src/coin.rs b/ibc-apps/ics20-transfer/types/src/coin.rs index 2f091eb84..0846029ad 100644 --- a/ibc-apps/ics20-transfer/types/src/coin.rs +++ b/ibc-apps/ics20-transfer/types/src/coin.rs @@ -77,8 +77,8 @@ where .all(|x| x.is_alphanumeric() || VALID_DENOM_CHARACTERS.contains(x)) }) .ok_or_else(|| TokenTransferError::FailedToParseType { - expected: "Coin".to_string(), - actual: coin_str.to_string(), + desired_type: "Coin".to_string(), + str_repr: coin_str.to_string(), })?; Ok(Coin { diff --git a/ibc-apps/ics20-transfer/types/src/denom.rs b/ibc-apps/ics20-transfer/types/src/denom.rs index b668813a5..42a55bd98 100644 --- a/ibc-apps/ics20-transfer/types/src/denom.rs +++ b/ibc-apps/ics20-transfer/types/src/denom.rs @@ -220,8 +220,8 @@ impl FromStr for TracePath { .is_none() .then_some(trace_path) .ok_or_else(|| TokenTransferError::FailedToParseType { - expected: "TracePath".to_string(), - actual: s.to_string(), + desired_type: "TracePath".to_string(), + str_repr: s.to_string(), }) } } diff --git a/ibc-apps/ics20-transfer/types/src/error.rs b/ibc-apps/ics20-transfer/types/src/error.rs index 31180b646..e89b41e33 100644 --- a/ibc-apps/ics20-transfer/types/src/error.rs +++ b/ibc-apps/ics20-transfer/types/src/error.rs @@ -39,8 +39,11 @@ pub enum TokenTransferError { // to a host-relevant error /// failed to parse account ID FailedToParseAccount, - /// failed to parse `{expected}` from `{actual}` - FailedToParseType { expected: String, actual: String }, + /// failed to parse `{desired_type}` type from string representation `{str_repr}` + FailedToParseType { + desired_type: String, + str_repr: String, + }, /// channel cannot be closed UnsupportedClosedChannel, /// empty base denomination From b449a43485d3d233968b797bd397bfc3525041d1 Mon Sep 17 00:00:00 2001 From: Sean Chen Date: Tue, 3 Sep 2024 14:17:34 -0500 Subject: [PATCH 38/73] Revert InvalidTrace and InvalidCoin TokenTransferError variants --- ibc-apps/ics20-transfer/src/module.rs | 66 ++++++++++++++----- ibc-apps/ics20-transfer/types/src/coin.rs | 5 +- ibc-apps/ics20-transfer/types/src/denom.rs | 5 +- ibc-apps/ics20-transfer/types/src/error.rs | 33 +++++++--- .../types/src/acknowledgement.rs | 7 ++ 5 files changed, 83 insertions(+), 33 deletions(-) diff --git a/ibc-apps/ics20-transfer/src/module.rs b/ibc-apps/ics20-transfer/src/module.rs index 66370f10c..062f34c2d 100644 --- a/ibc-apps/ics20-transfer/src/module.rs +++ b/ibc-apps/ics20-transfer/src/module.rs @@ -7,6 +7,7 @@ use ibc_core::channel::types::channel::{Counterparty, Order}; use ibc_core::channel::types::packet::Packet; use ibc_core::channel::types::Version; use ibc_core::handler::types::error::ContextError; +use ibc_core::host::types::error::DecodingError; use ibc_core::host::types::identifiers::{ChannelId, ConnectionId, PortId}; use ibc_core::primitives::prelude::*; use ibc_core::primitives::Signer; @@ -171,8 +172,12 @@ pub fn on_recv_packet_execute( packet: &Packet, ) -> (ModuleExtras, Acknowledgement) { let Ok(data) = serde_json::from_slice::(&packet.data) else { - let ack = - AcknowledgementStatus::error(TokenTransferError::FailedToDeserializePacketData.into()); + let ack = AcknowledgementStatus::error( + DecodingError::InvalidJson { + description: "failed to deserialize packet data".to_string(), + } + .into(), + ); return (ModuleExtras::empty(), ack.into()); }; @@ -203,11 +208,16 @@ pub fn on_acknowledgement_packet_validate( where Ctx: TokenTransferValidationContext, { - let data = serde_json::from_slice::(&packet.data) - .map_err(|_| TokenTransferError::FailedToDeserializePacketData)?; + let data = serde_json::from_slice::(&packet.data).map_err(|e| { + DecodingError::InvalidJson { + description: format!("failed to deserialize packet data: {e}"), + } + })?; let acknowledgement = serde_json::from_slice::(acknowledgement.as_ref()) - .map_err(|_| TokenTransferError::FailedToDeserializeAck)?; + .map_err(|e| DecodingError::InvalidJson { + description: format!("failed to deserialize acknowledgment status: {e}"), + })?; if !acknowledgement.is_successful() { refund_packet_token_validate(ctx, packet, &data)?; @@ -225,7 +235,10 @@ pub fn on_acknowledgement_packet_execute( let Ok(data) = serde_json::from_slice::(&packet.data) else { return ( ModuleExtras::empty(), - Err(TokenTransferError::FailedToDeserializePacketData), + Err(DecodingError::InvalidJson { + description: "failed to deserialize packet data".to_string(), + } + .into()), ); }; @@ -234,7 +247,10 @@ pub fn on_acknowledgement_packet_execute( else { return ( ModuleExtras::empty(), - Err(TokenTransferError::FailedToDeserializeAck), + Err(DecodingError::InvalidJson { + description: "failed to deserialize acknowledgment status".to_string(), + } + .into()), ); }; @@ -269,8 +285,11 @@ pub fn on_timeout_packet_validate( where Ctx: TokenTransferValidationContext, { - let data = serde_json::from_slice::(&packet.data) - .map_err(|_| TokenTransferError::FailedToDeserializePacketData)?; + let data = serde_json::from_slice::(&packet.data).map_err(|e| { + DecodingError::InvalidJson { + description: format!("failed to deserialize packet data: {e}"), + } + })?; refund_packet_token_validate(ctx, packet, &data)?; @@ -285,7 +304,10 @@ pub fn on_timeout_packet_execute( let Ok(data) = serde_json::from_slice::(&packet.data) else { return ( ModuleExtras::empty(), - Err(TokenTransferError::FailedToDeserializePacketData), + Err(DecodingError::InvalidJson { + description: "failed to deserialize packet data".to_string(), + } + .into()), ); }; @@ -324,7 +346,12 @@ mod test { r#"{"result":"AQ=="}"#, ); ser_json_assert_eq( - AcknowledgementStatus::error(TokenTransferError::FailedToDeserializePacketData.into()), + AcknowledgementStatus::error( + DecodingError::InvalidJson { + description: "failed to deserialize packet data".to_string(), + } + .into(), + ), r#"{"error":"failed to deserialize packet data"}"#, ); } @@ -341,9 +368,13 @@ mod test { #[test] fn test_ack_error_to_vec() { - let ack_error: Vec = - AcknowledgementStatus::error(TokenTransferError::FailedToDeserializePacketData.into()) - .into(); + let ack_error: Vec = AcknowledgementStatus::error( + DecodingError::InvalidJson { + description: "failed to deserialize packet data".to_string(), + } + .into(), + ) + .into(); // Check that it's the same output as ibc-go // Note: this also implicitly checks that the ack bytes are non-empty, @@ -367,7 +398,12 @@ mod test { ); de_json_assert_eq( r#"{"error":"failed to deserialize packet data"}"#, - AcknowledgementStatus::error(TokenTransferError::FailedToDeserializePacketData.into()), + AcknowledgementStatus::error( + DecodingError::InvalidJson { + description: "failed to deserialize packet data".to_string(), + } + .into(), + ), ); assert!(serde_json::from_str::(r#"{"success":"AQ=="}"#).is_err()); diff --git a/ibc-apps/ics20-transfer/types/src/coin.rs b/ibc-apps/ics20-transfer/types/src/coin.rs index 0846029ad..3a8b7387f 100644 --- a/ibc-apps/ics20-transfer/types/src/coin.rs +++ b/ibc-apps/ics20-transfer/types/src/coin.rs @@ -76,10 +76,7 @@ where .chars() .all(|x| x.is_alphanumeric() || VALID_DENOM_CHARACTERS.contains(x)) }) - .ok_or_else(|| TokenTransferError::FailedToParseType { - desired_type: "Coin".to_string(), - str_repr: coin_str.to_string(), - })?; + .ok_or_else(|| TokenTransferError::InvalidCoin(coin_str.to_owned()))?; Ok(Coin { amount: amount.parse()?, diff --git a/ibc-apps/ics20-transfer/types/src/denom.rs b/ibc-apps/ics20-transfer/types/src/denom.rs index 42a55bd98..ce014ee68 100644 --- a/ibc-apps/ics20-transfer/types/src/denom.rs +++ b/ibc-apps/ics20-transfer/types/src/denom.rs @@ -219,10 +219,7 @@ impl FromStr for TracePath { remaining_parts .is_none() .then_some(trace_path) - .ok_or_else(|| TokenTransferError::FailedToParseType { - desired_type: "TracePath".to_string(), - str_repr: s.to_string(), - }) + .ok_or_else(|| TokenTransferError::InvalidTrace(s.to_owned())) } } diff --git a/ibc-apps/ics20-transfer/types/src/error.rs b/ibc-apps/ics20-transfer/types/src/error.rs index e89b41e33..0d421b836 100644 --- a/ibc-apps/ics20-transfer/types/src/error.rs +++ b/ibc-apps/ics20-transfer/types/src/error.rs @@ -10,7 +10,7 @@ use ibc_core::host::types::identifiers::{ChannelId, PortId}; use ibc_core::primitives::prelude::*; use uint::FromDecStrErr; -#[derive(Display, Debug, derive_more::From)] +#[derive(Display, Debug)] pub enum TokenTransferError { /// context error: `{0}` ContextError(ContextError), @@ -20,6 +20,10 @@ pub enum TokenTransferError { Identifier(IdentifierError), /// invalid amount: `{0}` InvalidAmount(FromDecStrErr), + /// invalid coin: `{0}` + InvalidCoin(String), + /// invalid trace: `{0}` + InvalidTrace(String), /// missing token MissingToken, /// missing destination channel `{channel_id}` on port `{port_id}` @@ -31,19 +35,10 @@ pub enum TokenTransferError { MismatchedChannelOrders { expected: Order, actual: Order }, /// mismatched port IDs: expected `{expected}`, actual `{actual}` MismatchedPortIds { expected: PortId, actual: PortId }, - /// failed to deserialize packet data - FailedToDeserializePacketData, - /// failed to deserialize acknowledgement - FailedToDeserializeAck, // TODO(seanchen1991): Used in basecoin; this variant should be moved // to a host-relevant error /// failed to parse account ID FailedToParseAccount, - /// failed to parse `{desired_type}` type from string representation `{str_repr}` - FailedToParseType { - desired_type: String, - str_repr: String, - }, /// channel cannot be closed UnsupportedClosedChannel, /// empty base denomination @@ -69,6 +64,24 @@ impl From for TokenTransferError { } } +impl From for TokenTransferError { + fn from(e: ContextError) -> Self { + Self::ContextError(e) + } +} + +impl From for TokenTransferError { + fn from(e: IdentifierError) -> Self { + Self::Identifier(e) + } +} + +impl From for TokenTransferError { + fn from(e: DecodingError) -> Self { + Self::Decoding(e) + } +} + impl From for StatusValue { fn from(e: TokenTransferError) -> Self { StatusValue::new(e.to_string()).expect("error message must not be empty") diff --git a/ibc-core/ics04-channel/types/src/acknowledgement.rs b/ibc-core/ics04-channel/types/src/acknowledgement.rs index 0e983b0ce..2e19d3358 100644 --- a/ibc-core/ics04-channel/types/src/acknowledgement.rs +++ b/ibc-core/ics04-channel/types/src/acknowledgement.rs @@ -3,6 +3,7 @@ use core::fmt::{Display, Error as FmtError, Formatter}; use derive_more::Into; +use ibc_core_host_types::error::DecodingError; use ibc_primitives::prelude::*; use super::error::PacketError; @@ -139,3 +140,9 @@ impl From for Acknowledgement { .expect("token transfer internal error: ack is never supposed to be empty") } } + +impl From for StatusValue { + fn from(e: DecodingError) -> Self { + StatusValue::new(e.to_string()).expect("error message must not be empty") + } +} From 37cc8963d5d0cc11c5bf488e8af56713d2b8db8f Mon Sep 17 00:00:00 2001 From: Sean Chen Date: Tue, 3 Sep 2024 14:38:32 -0500 Subject: [PATCH 39/73] Remove NftTransferError variants in favor of DecodingError::InvalidJson --- ibc-apps/ics20-transfer/src/module.rs | 6 +- ibc-apps/ics721-nft-transfer/src/module.rs | 72 ++++++++++++++----- .../ics721-nft-transfer/types/src/error.rs | 4 -- 3 files changed, 57 insertions(+), 25 deletions(-) diff --git a/ibc-apps/ics20-transfer/src/module.rs b/ibc-apps/ics20-transfer/src/module.rs index 062f34c2d..e493760e6 100644 --- a/ibc-apps/ics20-transfer/src/module.rs +++ b/ibc-apps/ics20-transfer/src/module.rs @@ -352,7 +352,7 @@ mod test { } .into(), ), - r#"{"error":"failed to deserialize packet data"}"#, + r#"{"error":"invalid JSON data: `failed to deserialize packet data`"}"#, ); } @@ -381,7 +381,7 @@ mod test { // which would make the conversion to `Acknowledgement` panic assert_eq!( ack_error, - br#"{"error":"failed to deserialize packet data"}"# + br#"{"error":"invalid JSON data: `failed to deserialize packet data`"}"# ); } @@ -397,7 +397,7 @@ mod test { AcknowledgementStatus::success(ack_success_b64()), ); de_json_assert_eq( - r#"{"error":"failed to deserialize packet data"}"#, + r#"{"error":"invalid JSON data: `failed to deserialize packet data`"}"#, AcknowledgementStatus::error( DecodingError::InvalidJson { description: "failed to deserialize packet data".to_string(), diff --git a/ibc-apps/ics721-nft-transfer/src/module.rs b/ibc-apps/ics721-nft-transfer/src/module.rs index 5560b686f..8b1ffef0f 100644 --- a/ibc-apps/ics721-nft-transfer/src/module.rs +++ b/ibc-apps/ics721-nft-transfer/src/module.rs @@ -4,6 +4,7 @@ use ibc_core::channel::types::channel::{Counterparty, Order}; use ibc_core::channel::types::packet::Packet; use ibc_core::channel::types::Version; use ibc_core::handler::types::error::ContextError; +use ibc_core::host::types::error::DecodingError; use ibc_core::host::types::identifiers::{ChannelId, ConnectionId, PortId}; use ibc_core::primitives::prelude::*; use ibc_core::primitives::Signer; @@ -172,8 +173,12 @@ pub fn on_recv_packet_execute( packet: &Packet, ) -> (ModuleExtras, Acknowledgement) { let Ok(data) = serde_json::from_slice::(&packet.data) else { - let ack = - AcknowledgementStatus::error(NftTransferError::FailedToDeserializePacketData.into()); + let ack = AcknowledgementStatus::error( + DecodingError::InvalidJson { + description: "failed to deserialize packet data".to_string(), + } + .into(), + ); return (ModuleExtras::empty(), ack.into()); }; @@ -204,11 +209,16 @@ pub fn on_acknowledgement_packet_validate( acknowledgement: &Acknowledgement, _relayer: &Signer, ) -> Result<(), NftTransferError> { - let data = serde_json::from_slice::(&packet.data) - .map_err(|_| NftTransferError::FailedToDeserializePacketData)?; + let data = serde_json::from_slice::(&packet.data).map_err(|e| { + DecodingError::InvalidJson { + description: format!("failed to deserialize packet data: {e}"), + } + })?; let acknowledgement = serde_json::from_slice::(acknowledgement.as_ref()) - .map_err(|_| NftTransferError::FailedToDeserializeAck)?; + .map_err(|e| DecodingError::InvalidJson { + description: format!("failed to deserialize acknowledgment: {e}"), + })?; if !acknowledgement.is_successful() { refund_packet_nft_validate(ctx, packet, &data)?; @@ -226,7 +236,10 @@ pub fn on_acknowledgement_packet_execute( let Ok(data) = serde_json::from_slice::(&packet.data) else { return ( ModuleExtras::empty(), - Err(NftTransferError::FailedToDeserializePacketData), + Err(DecodingError::InvalidJson { + description: "failed to deserialize packet data".to_string(), + } + .into()), ); }; @@ -235,7 +248,10 @@ pub fn on_acknowledgement_packet_execute( else { return ( ModuleExtras::empty(), - Err(NftTransferError::FailedToDeserializeAck), + Err(DecodingError::InvalidJson { + description: "failed to deserialize acknowledgment".to_string(), + } + .into()), ); }; @@ -267,8 +283,11 @@ pub fn on_timeout_packet_validate( packet: &Packet, _relayer: &Signer, ) -> Result<(), NftTransferError> { - let data = serde_json::from_slice::(&packet.data) - .map_err(|_| NftTransferError::FailedToDeserializePacketData)?; + let data = serde_json::from_slice::(&packet.data).map_err(|e| { + DecodingError::InvalidJson { + description: format!("failed to deserialize packet data: {e}"), + } + })?; refund_packet_nft_validate(ctx, packet, &data)?; @@ -283,7 +302,10 @@ pub fn on_timeout_packet_execute( let Ok(data) = serde_json::from_slice::(&packet.data) else { return ( ModuleExtras::empty(), - Err(NftTransferError::FailedToDeserializePacketData), + Err(DecodingError::InvalidJson { + description: "failed to deserialize packet data".to_string(), + } + .into()), ); }; @@ -322,8 +344,13 @@ mod test { r#"{"result":"AQ=="}"#, ); ser_json_assert_eq( - AcknowledgementStatus::error(NftTransferError::FailedToDeserializePacketData.into()), - r#"{"error":"failed to deserialize packet data"}"#, + AcknowledgementStatus::error( + DecodingError::InvalidJson { + description: "failed to deserialize packet data".to_string(), + } + .into(), + ), + r#"{"error":"invalid JSON data: `failed to deserialize packet data`"}"#, ); } @@ -339,16 +366,20 @@ mod test { #[test] fn test_ack_error_to_vec() { - let ack_error: Vec = - AcknowledgementStatus::error(NftTransferError::FailedToDeserializePacketData.into()) - .into(); + let ack_error: Vec = AcknowledgementStatus::error( + DecodingError::InvalidJson { + description: "failed to deserialize packet data".to_string(), + } + .into(), + ) + .into(); // Check that it's the same output as ibc-go // Note: this also implicitly checks that the ack bytes are non-empty, // which would make the conversion to `Acknowledgement` panic assert_eq!( ack_error, - br#"{"error":"failed to deserialize packet data"}"# + br#"{"error":"invalid JSON data: `failed to deserialize packet data`"}"# ); } @@ -364,8 +395,13 @@ mod test { AcknowledgementStatus::success(ack_success_b64()), ); de_json_assert_eq( - r#"{"error":"failed to deserialize packet data"}"#, - AcknowledgementStatus::error(NftTransferError::FailedToDeserializePacketData.into()), + r#"{"error":"invalid JSON data: `failed to deserialize packet data`"}"#, + AcknowledgementStatus::error( + DecodingError::InvalidJson { + description: "failed to deserialize packet data".to_string(), + } + .into(), + ), ); assert!(serde_json::from_str::(r#"{"success":"AQ=="}"#).is_err()); diff --git a/ibc-apps/ics721-nft-transfer/types/src/error.rs b/ibc-apps/ics721-nft-transfer/types/src/error.rs index 6826f4a58..2e7456b5b 100644 --- a/ibc-apps/ics721-nft-transfer/types/src/error.rs +++ b/ibc-apps/ics721-nft-transfer/types/src/error.rs @@ -37,10 +37,6 @@ pub enum NftTransferError { MismatchedChannelOrders { expected: Order, actual: Order }, /// mismatched port IDs: expected `{expected}`, actual `{actual}` MismatchedPortIds { expected: PortId, actual: PortId }, - /// failed to deserialize packet data - FailedToDeserializePacketData, - /// failed to deserialize acknowledgement - FailedToDeserializeAck, /// failed to parse account ID FailedToParseAccount, /// channel cannot be closed From 23dc6d3c4ee1850d47085b01d8203e1b45ae4f9f Mon Sep 17 00:00:00 2001 From: Sean Chen Date: Tue, 3 Sep 2024 14:56:21 -0500 Subject: [PATCH 40/73] cargo fmt --- ibc-clients/ics07-tendermint/src/client_state/common.rs | 5 +---- ibc-core/ics02-client/types/src/error.rs | 2 ++ .../ics24-host/cosmos/src/upgrade_proposal/proposal.rs | 8 ++++---- ibc-primitives/src/lib.rs | 3 +-- 4 files changed, 8 insertions(+), 10 deletions(-) diff --git a/ibc-clients/ics07-tendermint/src/client_state/common.rs b/ibc-clients/ics07-tendermint/src/client_state/common.rs index 5c573135f..ca0a82eec 100644 --- a/ibc-clients/ics07-tendermint/src/client_state/common.rs +++ b/ibc-clients/ics07-tendermint/src/client_state/common.rs @@ -66,10 +66,7 @@ impl ClientStateCommon for ClientState { let upgrade_path = &self.inner().upgrade_path; let (upgrade_path_prefix, upgrade_path) = match upgrade_path.len() { 0 => { - return Err(UpgradeClientError::InvalidUpgradePath { - description: "no upgrade path has been set".to_string(), - } - .into()); + return Err(UpgradeClientError::MissingUpgradePath.into()); } 1 => (CommitmentPrefix::empty(), upgrade_path[0].clone()), 2 => ( diff --git a/ibc-core/ics02-client/types/src/error.rs b/ibc-core/ics02-client/types/src/error.rs index 5fed54576..505ce8322 100644 --- a/ibc-core/ics02-client/types/src/error.rs +++ b/ibc-core/ics02-client/types/src/error.rs @@ -138,6 +138,8 @@ pub enum UpgradeClientError { InvalidUpgradeProposal { description: String }, /// invalid upgrade plan: `{description}` InvalidUpgradePlan { description: String }, + /// missing upgrade path + MissingUpgradePath, /// missing upgraded client state MissingUpgradedClientState, /// missing upgraded consensus state diff --git a/ibc-core/ics24-host/cosmos/src/upgrade_proposal/proposal.rs b/ibc-core/ics24-host/cosmos/src/upgrade_proposal/proposal.rs index 4a72af753..f069e6852 100644 --- a/ibc-core/ics24-host/cosmos/src/upgrade_proposal/proposal.rs +++ b/ibc-core/ics24-host/cosmos/src/upgrade_proposal/proposal.rs @@ -33,13 +33,13 @@ impl TryFrom for UpgradeProposal { fn try_from(raw: RawUpgradeProposal) -> Result { if raw.title.is_empty() { return Err(UpgradeClientError::InvalidUpgradeProposal { - description: "title field cannot be empty".to_string(), + description: "missing title field".to_string(), }); } if raw.description.is_empty() { return Err(UpgradeClientError::InvalidUpgradeProposal { - description: "description field cannot be empty".to_string(), + description: "missing description field".to_string(), }); } @@ -47,13 +47,13 @@ impl TryFrom for UpgradeProposal { plan.try_into()? } else { return Err(UpgradeClientError::InvalidUpgradeProposal { - description: "plan field cannot be empty".to_string(), + description: "missing plan field".to_string(), }); }; let upgraded_client_state = raw.upgraded_client_state.ok_or_else(|| { UpgradeClientError::InvalidUpgradeProposal { - description: "upgraded client state cannot be empty".to_string(), + description: "missing upgraded client state".to_string(), } })?; diff --git a/ibc-primitives/src/lib.rs b/ibc-primitives/src/lib.rs index 8de7a3d39..277c794cd 100644 --- a/ibc-primitives/src/lib.rs +++ b/ibc-primitives/src/lib.rs @@ -32,6 +32,5 @@ pub mod serializers; pub mod proto { pub use ibc_proto::google::protobuf::{Any, Duration, Timestamp}; - pub use ibc_proto::Error; - pub use ibc_proto::Protobuf; + pub use ibc_proto::{Error, Protobuf}; } From 35bb851bbf22cba23b2f8d7b8b8736315bbc8336 Mon Sep 17 00:00:00 2001 From: Sean Chen Date: Tue, 3 Sep 2024 14:57:21 -0500 Subject: [PATCH 41/73] Regenerate cw-check cargo.lock --- ci/cw-check/Cargo.lock | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ci/cw-check/Cargo.lock b/ci/cw-check/Cargo.lock index e80c0a8a3..3a5d9fe84 100644 --- a/ci/cw-check/Cargo.lock +++ b/ci/cw-check/Cargo.lock @@ -1100,9 +1100,9 @@ dependencies = [ [[package]] name = "ibc-proto" -version = "0.47.0" +version = "0.47.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1678333cf68c9094ca66aaf9a271269f1f6bf5c26881161def8bd88cee831a23" +checksum = "c852d22b782d2d793f4a646f968de419be635e02bc8798d5d74a6e44eef27733" dependencies = [ "base64 0.22.1", "bytes", From c3caee19d96e7f5c855c47301bda74b6f12908d0 Mon Sep 17 00:00:00 2001 From: Sean Chen Date: Wed, 4 Sep 2024 09:24:55 -0500 Subject: [PATCH 42/73] Separate out error variants that need to be moved to host-relevant errors --- ibc-apps/ics20-transfer/types/src/error.rs | 9 ++-- ibc-core/ics02-client/types/src/error.rs | 43 ++++++++++++-------- ibc-core/ics03-connection/types/src/error.rs | 10 ++--- ibc-core/ics04-channel/types/src/error.rs | 16 ++++---- ibc-core/ics26-routing/types/src/error.rs | 2 + 5 files changed, 45 insertions(+), 35 deletions(-) diff --git a/ibc-apps/ics20-transfer/types/src/error.rs b/ibc-apps/ics20-transfer/types/src/error.rs index 0d421b836..43150c0cb 100644 --- a/ibc-apps/ics20-transfer/types/src/error.rs +++ b/ibc-apps/ics20-transfer/types/src/error.rs @@ -35,14 +35,15 @@ pub enum TokenTransferError { MismatchedChannelOrders { expected: Order, actual: Order }, /// mismatched port IDs: expected `{expected}`, actual `{actual}` MismatchedPortIds { expected: PortId, actual: PortId }, - // TODO(seanchen1991): Used in basecoin; this variant should be moved - // to a host-relevant error - /// failed to parse account ID - FailedToParseAccount, /// channel cannot be closed UnsupportedClosedChannel, /// empty base denomination EmptyBaseDenom, + + // TODO(seanchen1991): Used in basecoin; this variant should be moved + // to a host-relevant error + /// failed to parse account ID + FailedToParseAccount, } #[cfg(feature = "std")] diff --git a/ibc-core/ics02-client/types/src/error.rs b/ibc-core/ics02-client/types/src/error.rs index 505ce8322..87d5b78ef 100644 --- a/ibc-core/ics02-client/types/src/error.rs +++ b/ibc-core/ics02-client/types/src/error.rs @@ -3,6 +3,8 @@ use core::convert::Infallible; use displaydoc::Display; +use tendermint::Error as TendermintError; + use ibc_core_commitment_types::error::CommitmentError; use ibc_core_host_types::error::DecodingError; use ibc_core_host_types::identifiers::ClientId; @@ -19,8 +21,6 @@ pub enum ClientError { Upgrade(UpgradeClientError), /// decoding error: `{0}` Decoding(DecodingError), - /// invalid header type: `{0}` - InvalidHeaderType(String), /// invalid trust threshold: `{numerator}`/`{denominator}` InvalidTrustThreshold { numerator: u64, denominator: u64 }, /// invalid client state type: `{0}` @@ -43,12 +43,6 @@ pub enum ClientError { InvalidAttributeValue(String), /// invalid status: `{0}` InvalidStatus(String), - /// missing client state for client: `{0}` - MissingClientState(ClientId), - /// missing consensus state for client `{client_id}` at height `{height}` - MissingConsensusState { client_id: ClientId, height: Height }, - /// missing update client metadata for client `{client_id}` at height `{height}` - MissingUpdateMetaData { client_id: ClientId, height: Height }, /// missing raw client state MissingRawClientState, /// missing raw client consensus state @@ -81,7 +75,18 @@ pub enum ClientError { /// client-specific error: `{description}` ClientSpecific { description: String }, - // TODO(seanchen1991): Incorporate these errors into their own variants + // TODO(seanchen1991): Add these to host-relevant errors + /// missing client state for client: `{0}` + MissingClientState(ClientId), + /// missing consensus state for client `{client_id}` at height `{height}` + MissingConsensusState { client_id: ClientId, height: Height }, + /// missing update client metadata for client `{client_id}` at height `{height}` + MissingUpdateMetaData { client_id: ClientId, height: Height }, + /// invalid raw header: `{0}` + InvalidRawHeader(TendermintError), + /// invalid header type: `{0}` + InvalidHeaderType(String), + // TODO(seanchen1991): Incorporate this error into its own variants /// other error: `{description}` Other { description: String }, } @@ -134,12 +139,19 @@ pub enum UpgradeClientError { InvalidUpgradeConsensusStateProof(CommitmentError), /// invalid upgrade path: `{description}` InvalidUpgradePath { description: String }, - /// invalid upgrade proposal: `{description}` - InvalidUpgradeProposal { description: String }, - /// invalid upgrade plan: `{description}` - InvalidUpgradePlan { description: String }, /// missing upgrade path MissingUpgradePath, + /// insufficient upgrade client height `{upgraded_height}`; must be greater than current client height `{client_height}` + InsufficientUpgradeHeight { + upgraded_height: Height, + client_height: Height, + }, + + // TODO(seanchen1991): Move these variants to host-relevant errors + /// invalid upgrade plan: `{description}` + InvalidUpgradePlan { description: String }, + /// invalid upgrade proposal: `{description}` + InvalidUpgradeProposal { description: String }, /// missing upgraded client state MissingUpgradedClientState, /// missing upgraded consensus state @@ -150,11 +162,6 @@ pub enum UpgradeClientError { FailedToStoreUpgradedClientState { description: String }, /// failed to store upgraded consensus state: `{description}` FailedToStoreUpgradedConsensusState { description: String }, - /// insufficient upgrade client height `{upgraded_height}`; must be greater than current client height `{client_height}` - InsufficientUpgradeHeight { - upgraded_height: Height, - client_height: Height, - }, } impl From for ClientError { diff --git a/ibc-core/ics03-connection/types/src/error.rs b/ibc-core/ics03-connection/types/src/error.rs index 7016256b7..d141c6303 100644 --- a/ibc-core/ics03-connection/types/src/error.rs +++ b/ibc-core/ics03-connection/types/src/error.rs @@ -44,9 +44,9 @@ pub enum ConnectionError { MissingProofHeight, /// missing consensus height MissingConsensusHeight, - /// missing connection `{0}` + /// [HostError] missing connection `{0}` MissingConnection(ConnectionId), - /// missing connection counter + /// [HostError] missing connection counter MissingConnectionCounter, /// missing counterparty MissingCounterparty, @@ -73,11 +73,11 @@ pub enum ConnectionError { FailedToVerifyConsensusState(ClientError), /// failed to verify client state: `{0}` FailedToVerifyClientState(ClientError), - /// failed to store connection IDs + /// [HostError] failed to store connection IDs FailedToStoreConnectionIds, - /// failed to store connection end + /// [HostError] failed to store connection end FailedToStoreConnectionEnd, - /// failed to update connection counter + /// [HostError] failed to update connection counter FailedToUpdateConnectionCounter, /// overflowed timestamp: `{0}` OverflowedTimestamp(TimestampError), diff --git a/ibc-core/ics04-channel/types/src/error.rs b/ibc-core/ics04-channel/types/src/error.rs index 56cdadcd5..a44f1975b 100644 --- a/ibc-core/ics04-channel/types/src/error.rs +++ b/ibc-core/ics04-channel/types/src/error.rs @@ -16,8 +16,6 @@ use crate::Version; #[derive(Debug, Display)] pub enum ChannelError { - /// application module error: `{description}` - AppModule { description: String }, /// identifier error: `{0}` InvalidIdentifier(IdentifierError), /// invalid channel id: expected `{expected}`, actual `{actual}` @@ -41,8 +39,6 @@ pub enum ChannelError { MissingCounterparty, /// missing channel end in raw message MissingRawChannelEnd, - /// missing channel counter - MissingCounter, /// unsupported channel upgrade sequence UnsupportedChannelUpgradeSequence, /// unsupported version: expected `{expected}`, actual `{actual}` @@ -62,8 +58,12 @@ pub enum ChannelError { /// failed proof verification: `{0}` FailedProofVerification(ClientError), - // TODO(seanchen1991): These two variants should be encoded by host-relevant error types + // TODO(seanchen1991): These variants should be encoded by host-relevant error types // once those have been defined. + /// application module error: `{description}` + AppModule { description: String }, + /// missing channel counter + MissingCounter, /// failed to update counter: `{description}` FailedToUpdateCounter { description: String }, /// failed to store channel: `{description}` @@ -72,7 +72,7 @@ pub enum ChannelError { #[derive(Debug, Display)] pub enum PacketError { - /// application module error: `{description}` + /// [HostError] application module error: `{description}` AppModule { description: String }, /// channel error: `{0}` Channel(ChannelError), @@ -94,11 +94,11 @@ pub enum PacketError { expected: PacketCommitment, actual: PacketCommitment, }, - /// missing packet receipt for packet `{0}` + /// [HostError] missing packet receipt for packet `{0}` MissingPacketReceipt(Sequence), /// missing proof MissingProof, - /// missing acknowledgment for packet `{0}` + /// [HostError] missing acknowledgment for packet `{0}` MissingPacketAcknowledgment(Sequence), /// missing proof height MissingProofHeight, diff --git a/ibc-core/ics26-routing/types/src/error.rs b/ibc-core/ics26-routing/types/src/error.rs index cb998dd76..8e53c1a86 100644 --- a/ibc-core/ics26-routing/types/src/error.rs +++ b/ibc-core/ics26-routing/types/src/error.rs @@ -10,6 +10,8 @@ pub enum RouterError { Decoding(DecodingError), /// missing module MissingModule, + + // TODO(seanchen1991): This variant needs to be moved to HostError /// unknown port `{0}` UnknownPort(PortId), } From dc915daa1cba3b18bb19a19dc3956f982246c56d Mon Sep 17 00:00:00 2001 From: Sean Chen Date: Wed, 4 Sep 2024 14:08:39 -0500 Subject: [PATCH 43/73] Consolidate TendermintClientError decoding errors --- .../types/src/client_state.rs | 52 ++++++++++++------- .../types/src/consensus_state.rs | 21 ++++---- .../ics07-tendermint/types/src/error.rs | 20 +------ .../ics07-tendermint/types/src/header.rs | 22 +++++--- ibc-core/ics02-client/types/src/error.rs | 17 ++---- .../types/src/msgs/create_client.rs | 11 ++-- .../types/src/msgs/upgrade_client.rs | 18 +++++-- ibc-core/ics24-host/types/src/error.rs | 2 + .../ibc/clients/mock/consensus_state.rs | 4 +- 9 files changed, 89 insertions(+), 78 deletions(-) diff --git a/ibc-clients/ics07-tendermint/types/src/client_state.rs b/ibc-clients/ics07-tendermint/types/src/client_state.rs index 87f588d82..91ab3d944 100644 --- a/ibc-clients/ics07-tendermint/types/src/client_state.rs +++ b/ibc-clients/ics07-tendermint/types/src/client_state.rs @@ -241,48 +241,64 @@ impl TryFrom for ClientState { let chain_id = ChainId::from_str(raw.chain_id.as_str())?; let trust_level = { - let trust_level = raw - .trust_level - .ok_or(TendermintClientError::MissingTrustingPeriod)?; + let trust_level = raw.trust_level.ok_or(DecodingError::MissingRawData { + description: "trust level not set".to_string(), + })?; trust_level .try_into() - .map_err(|e| TendermintClientError::InvalidTrustThreshold { - description: format!("{e}"), + .map_err(|e| DecodingError::InvalidRawData { + description: format!("failed to decoding trust threshold: {e}"), })? }; let trusting_period = raw .trusting_period - .ok_or(TendermintClientError::MissingTrustingPeriod)? + .ok_or(DecodingError::MissingRawData { + description: "trusting period not set".to_string(), + })? .try_into() - .map_err(|_| TendermintClientError::MissingTrustingPeriod)?; + .map_err(|_| DecodingError::InvalidRawData { + description: "failed to decode trusting period".to_string(), + })?; let unbonding_period = raw .unbonding_period - .ok_or(TendermintClientError::MissingUnbondingPeriod)? + .ok_or(DecodingError::MissingRawData { + description: "unbonding period not set".to_string(), + })? .try_into() - .map_err(|_| TendermintClientError::MissingUnbondingPeriod)?; + .map_err(|_| DecodingError::InvalidRawData { + description: "failed to decode unbonding period".to_string(), + })?; let max_clock_drift = raw .max_clock_drift - .ok_or(TendermintClientError::InvalidMaxClockDrift)? + .ok_or(DecodingError::MissingRawData { + description: "max clock drift not set".to_string(), + })? .try_into() - .map_err(|_| TendermintClientError::InvalidMaxClockDrift)?; + .map_err(|_| DecodingError::InvalidRawData { + description: "failed to decode max clock drift".to_string(), + })?; let latest_height = raw .latest_height - .ok_or(TendermintClientError::MissingLatestHeight)? + .ok_or(DecodingError::MissingRawData { + description: "latest height not set".to_string(), + })? .try_into() - .map_err(|_| TendermintClientError::MissingLatestHeight)?; + .map_err(|e| DecodingError::InvalidRawData { + description: format!("failed to decode latest height: {e}"), + })?; // NOTE: In `RawClientState`, a `frozen_height` of `0` means "not // frozen". See: // https://github.com/cosmos/ibc-go/blob/8422d0c4c35ef970539466c5bdec1cd27369bab3/modules/light-clients/07-tendermint/types/client_state.go#L74 - let frozen_height = Height::try_from( - raw.frozen_height - .ok_or(TendermintClientError::MissingFrozenHeight)?, - ) - .ok(); + let frozen_height = + Height::try_from(raw.frozen_height.ok_or(DecodingError::MissingRawData { + description: "frozen height not set".to_string(), + })?) + .ok(); // We use set this deprecated field just so that we can properly convert // it back in its raw form diff --git a/ibc-clients/ics07-tendermint/types/src/consensus_state.rs b/ibc-clients/ics07-tendermint/types/src/consensus_state.rs index f069a812c..40e5837b2 100644 --- a/ibc-clients/ics07-tendermint/types/src/consensus_state.rs +++ b/ibc-clients/ics07-tendermint/types/src/consensus_state.rs @@ -53,27 +53,26 @@ impl TryFrom for ConsensusState { fn try_from(raw: RawConsensusState) -> Result { let proto_root = raw .root - .ok_or(TendermintClientError::InvalidRawClientState { - description: "missing commitment root".into(), + .ok_or(DecodingError::MissingRawData { + description: "no commitment root set".into(), })? .hash; let ibc_proto::google::protobuf::Timestamp { seconds, nanos } = - raw.timestamp - .ok_or(TendermintClientError::InvalidRawClientState { - description: "missing timestamp".into(), - })?; + raw.timestamp.ok_or(DecodingError::MissingRawData { + description: "no timestamp set".into(), + })?; // FIXME: shunts like this are necessary due to // https://github.com/informalsystems/tendermint-rs/issues/1053 let proto_timestamp = tpb::Timestamp { seconds, nanos }; - let timestamp = proto_timestamp.try_into().map_err(|e| { - TendermintClientError::InvalidRawClientState { + let timestamp = proto_timestamp + .try_into() + .map_err(|e| DecodingError::InvalidRawData { description: format!("invalid timestamp: {e}"), - } - })?; + })?; let next_validators_hash = Hash::from_bytes(Algorithm::Sha256, &raw.next_validators_hash) - .map_err(|e| TendermintClientError::InvalidRawClientState { + .map_err(|e| DecodingError::InvalidHash { description: e.to_string(), })?; diff --git a/ibc-clients/ics07-tendermint/types/src/error.rs b/ibc-clients/ics07-tendermint/types/src/error.rs index 3d2d6dfb1..11bf310b7 100644 --- a/ibc-clients/ics07-tendermint/types/src/error.rs +++ b/ibc-clients/ics07-tendermint/types/src/error.rs @@ -26,30 +26,12 @@ pub enum TendermintClientError { InvalidMaxClockDrift, /// invalid client proof specs: `{0}` InvalidProofSpec(CommitmentError), - /// invalid raw client state: `{description}` - InvalidRawClientState { description: String }, /// invalid raw misbehaviour: `{description}` InvalidRawMisbehaviour { description: String }, /// invalid header timestamp: `{0}` InvalidHeaderTimestamp(TimestampError), /// invalid header height: `{0}` InvalidHeaderHeight(u64), - /// missing signed header - MissingSignedHeader, - /// missing validator set - MissingValidatorSet, - /// missing trusted next validator set - MissingTrustedNextValidatorSet, - /// missing trusted height - MissingTrustedHeight, - /// missing trusting period - MissingTrustingPeriod, - /// missing unbonding period - MissingUnbondingPeriod, - /// missing the latest height - MissingLatestHeight, - /// missing frozen height - MissingFrozenHeight, /// mismatched revision heights: expected `{expected}`, actual `{actual}` MismatchedRevisionHeights { expected: u64, actual: u64 }, /// mismatched header chain ids: expected `{expected}`, actual `{actual}` @@ -80,6 +62,8 @@ impl std::error::Error for TendermintClientError { } } +// TODO(seanchen1991): Should this impl be deprecated in favor of a +// From for TendermintClientError impl? impl From for ClientError { fn from(e: TendermintClientError) -> Self { Self::ClientSpecific { diff --git a/ibc-clients/ics07-tendermint/types/src/header.rs b/ibc-clients/ics07-tendermint/types/src/header.rs index 7c33f7fdd..aaadfde07 100644 --- a/ibc-clients/ics07-tendermint/types/src/header.rs +++ b/ibc-clients/ics07-tendermint/types/src/header.rs @@ -171,28 +171,36 @@ impl TryFrom for Header { let header = Self { signed_header: raw .signed_header - .ok_or(TendermintClientError::MissingSignedHeader)? + .ok_or(DecodingError::MissingRawData { + description: "signed header not set".to_string(), + })? .try_into() .map_err(|e| DecodingError::InvalidRawData { - description: format!("{e:?}"), + description: format!("failed to decode signed header: {e:?}"), })?, validator_set: raw .validator_set - .ok_or(TendermintClientError::MissingValidatorSet)? + .ok_or(DecodingError::MissingRawData { + description: "validator set not set".to_string(), + })? .try_into() .map_err(|e| DecodingError::InvalidRawData { - description: format!("{e:?}"), + description: format!("failed to decode validator set: {e:?}"), })?, trusted_height: raw .trusted_height .and_then(|raw_height| raw_height.try_into().ok()) - .ok_or(TendermintClientError::MissingTrustedHeight)?, + .ok_or(DecodingError::MissingRawData { + description: "trusted height not set".to_string(), + })?, trusted_next_validator_set: raw .trusted_validators - .ok_or(TendermintClientError::MissingTrustedNextValidatorSet)? + .ok_or(DecodingError::MissingRawData { + description: "trusted next validator set not set".to_string(), + })? .try_into() .map_err(|e| DecodingError::InvalidRawData { - description: format!("{e:?}"), + description: format!("failed to decode trusted next validator set: {e:?}"), })?, }; diff --git a/ibc-core/ics02-client/types/src/error.rs b/ibc-core/ics02-client/types/src/error.rs index 87d5b78ef..eb283e2b4 100644 --- a/ibc-core/ics02-client/types/src/error.rs +++ b/ibc-core/ics02-client/types/src/error.rs @@ -25,12 +25,8 @@ pub enum ClientError { InvalidTrustThreshold { numerator: u64, denominator: u64 }, /// invalid client state type: `{0}` InvalidClientStateType(String), - /// invalid client consensus state type: `{0}` - InvalidConsensusStateType(String), /// invalid update client message InvalidUpdateClientMessage, - /// invalid misbehaviour type: `{0}` - InvalidMisbehaviourType(String), /// invalid height; cannot be zero or negative InvalidHeight, /// invalid proof height; expected `{actual}` >= `{expected}` @@ -43,12 +39,6 @@ pub enum ClientError { InvalidAttributeValue(String), /// invalid status: `{0}` InvalidStatus(String), - /// missing raw client state - MissingRawClientState, - /// missing raw client consensus state - MissingRawConsensusState, - /// missing raw client message - MissingRawClientMessage, /// missing local consensus state at `{0}` MissingLocalConsensusState(Height), /// missing attribute key @@ -134,7 +124,7 @@ pub enum UpgradeClientError { /// decoding error: `{0}` Decoding(DecodingError), /// invalid proof for the upgraded client state: `{0}` - InvalidUpgradeClientProof(CommitmentError), + InvalidUpgradeClientStateProof(CommitmentError), /// invalid proof for the upgraded consensus state: `{0}` InvalidUpgradeConsensusStateProof(CommitmentError), /// invalid upgrade path: `{description}` @@ -180,9 +170,8 @@ impl From for UpgradeClientError { impl std::error::Error for UpgradeClientError { fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { match &self { - Self::InvalidUpgradeClientProof(e) | Self::InvalidUpgradeConsensusStateProof(e) => { - Some(e) - } + Self::InvalidUpgradeClientStateProof(e) + | Self::InvalidUpgradeConsensusStateProof(e) => Some(e), _ => None, } } diff --git a/ibc-core/ics02-client/types/src/msgs/create_client.rs b/ibc-core/ics02-client/types/src/msgs/create_client.rs index fe6944b3d..72a035c9e 100644 --- a/ibc-core/ics02-client/types/src/msgs/create_client.rs +++ b/ibc-core/ics02-client/types/src/msgs/create_client.rs @@ -1,5 +1,6 @@ //! Definition of domain type message `MsgCreateClient`. +use ibc_core_host_types::error::DecodingError; use ibc_primitives::prelude::*; use ibc_primitives::Signer; use ibc_proto::google::protobuf::Any; @@ -39,11 +40,13 @@ impl TryFrom for MsgCreateClient { type Error = ClientError; fn try_from(raw: RawMsgCreateClient) -> Result { - let raw_client_state = raw.client_state.ok_or(ClientError::MissingRawClientState)?; + let raw_client_state = raw.client_state.ok_or(DecodingError::MissingRawData { + description: "no raw client state set".to_string(), + })?; - let raw_consensus_state = raw - .consensus_state - .ok_or(ClientError::MissingRawConsensusState)?; + let raw_consensus_state = raw.consensus_state.ok_or(DecodingError::MissingRawData { + description: "no raw consensus state set".to_string(), + })?; Ok(MsgCreateClient::new( raw_client_state, diff --git a/ibc-core/ics02-client/types/src/msgs/upgrade_client.rs b/ibc-core/ics02-client/types/src/msgs/upgrade_client.rs index 4b545e452..b1d2964d1 100644 --- a/ibc-core/ics02-client/types/src/msgs/upgrade_client.rs +++ b/ibc-core/ics02-client/types/src/msgs/upgrade_client.rs @@ -60,16 +60,24 @@ impl TryFrom for MsgUpgradeClient { fn try_from(proto_msg: RawMsgUpgradeClient) -> Result { let raw_client_state = proto_msg .client_state - .ok_or(ClientError::MissingRawClientState)?; + .ok_or(DecodingError::MissingRawData { + description: "no raw client state set".to_string(), + })?; - let raw_consensus_state = proto_msg - .consensus_state - .ok_or(ClientError::MissingRawConsensusState)?; + let raw_consensus_state = + proto_msg + .consensus_state + .ok_or(DecodingError::MissingRawData { + description: "no raw consensus state set".to_string(), + })?; let c_bytes = CommitmentProofBytes::try_from(proto_msg.proof_upgrade_client).map_err(|_| { - UpgradeClientError::InvalidUpgradeClientProof(CommitmentError::EmptyMerkleProof) + UpgradeClientError::InvalidUpgradeClientStateProof( + CommitmentError::EmptyMerkleProof, + ) })?; + let cs_bytes = CommitmentProofBytes::try_from(proto_msg.proof_upgrade_consensus_state) .map_err(|_| { UpgradeClientError::InvalidUpgradeConsensusStateProof( diff --git a/ibc-core/ics24-host/types/src/error.rs b/ibc-core/ics24-host/types/src/error.rs index 048392de6..bf1d8a129 100644 --- a/ibc-core/ics24-host/types/src/error.rs +++ b/ibc-core/ics24-host/types/src/error.rs @@ -35,6 +35,8 @@ pub enum DecodingError { Protobuf(ProtoError), /// prost decoding error: `{0}` Prost(ProstError), + /// invalid hash bytes: `{description}` + InvalidHash { description: String }, /// invalid JSON data: `{description}` InvalidJson { description: String }, /// invalid identifier error: `{0}` diff --git a/ibc-testkit/src/testapp/ibc/clients/mock/consensus_state.rs b/ibc-testkit/src/testapp/ibc/clients/mock/consensus_state.rs index 48561f087..66d53d595 100644 --- a/ibc-testkit/src/testapp/ibc/clients/mock/consensus_state.rs +++ b/ibc-testkit/src/testapp/ibc/clients/mock/consensus_state.rs @@ -42,7 +42,9 @@ impl TryFrom for MockConsensusState { type Error = ClientError; fn try_from(raw: RawMockConsensusState) -> Result { - let raw_header = raw.header.ok_or(ClientError::MissingRawConsensusState)?; + let raw_header = raw.header.ok_or(DecodingError::MissingRawData { + description: "no raw header set".to_string(), + })?; Ok(Self { header: raw_header.try_into()?, From e74f4bf6aa1582ed75c1e43eba6cb3f341e6ce8f Mon Sep 17 00:00:00 2001 From: Sean Chen Date: Wed, 4 Sep 2024 14:56:48 -0500 Subject: [PATCH 44/73] Consolidate Connection and Packet decoding errors --- .../ics721-nft-transfer/types/src/packet.rs | 4 +- .../ics02-client/src/handler/create_client.rs | 2 +- ibc-core/ics02-client/types/src/error.rs | 2 +- .../types/src/acknowledgement.rs | 4 +- ibc-core/ics04-channel/types/src/error.rs | 58 +++++++++++-------- .../types/src/events/packet_attributes.rs | 6 +- .../types/src/msgs/acknowledgement.rs | 18 ++++-- .../types/src/msgs/chan_open_ack.rs | 14 +++-- .../types/src/msgs/chan_open_init.rs | 5 +- .../types/src/msgs/chan_open_try.rs | 10 ++-- .../types/src/msgs/recv_packet.rs | 18 ++++-- .../ics04-channel/types/src/msgs/timeout.rs | 18 ++++-- .../types/src/msgs/timeout_on_close.rs | 27 +++++---- ibc-core/ics04-channel/types/src/packet.rs | 9 ++- ibc-core/ics24-host/types/src/error.rs | 7 ++- 15 files changed, 126 insertions(+), 76 deletions(-) diff --git a/ibc-apps/ics721-nft-transfer/types/src/packet.rs b/ibc-apps/ics721-nft-transfer/types/src/packet.rs index a0bd962fe..6a8813d07 100644 --- a/ibc-apps/ics721-nft-transfer/types/src/packet.rs +++ b/ibc-apps/ics721-nft-transfer/types/src/packet.rs @@ -130,7 +130,7 @@ impl TryFrom for PacketData { let decoded = BASE64_STANDARD .decode(raw_pkt_data.class_data) .map_err(DecodingError::Base64)?; - let data_str = String::from_utf8(decoded).map_err(DecodingError::Utf8)?; + let data_str = String::from_utf8(decoded).map_err(DecodingError::StringUtf8)?; Some(data_str.parse()?) }; @@ -144,7 +144,7 @@ impl TryFrom for PacketData { let decoded = BASE64_STANDARD .decode(data) .map_err(DecodingError::Base64)?; - let data_str = String::from_utf8(decoded).map_err(DecodingError::Utf8)?; + let data_str = String::from_utf8(decoded).map_err(DecodingError::StringUtf8)?; data_str.parse() }) .collect(); diff --git a/ibc-core/ics02-client/src/handler/create_client.rs b/ibc-core/ics02-client/src/handler/create_client.rs index 8c7010443..47f5bab4a 100644 --- a/ibc-core/ics02-client/src/handler/create_client.rs +++ b/ibc-core/ics02-client/src/handler/create_client.rs @@ -44,7 +44,7 @@ where client_state.verify_consensus_state(consensus_state, &host_timestamp)?; if client_val_ctx.client_state(&client_id).is_ok() { - return Err(ClientError::AlreadyExistingClientState(client_id).into()); + return Err(ClientError::DuplicateClientState(client_id).into()); }; Ok(()) diff --git a/ibc-core/ics02-client/types/src/error.rs b/ibc-core/ics02-client/types/src/error.rs index eb283e2b4..f6000ac47 100644 --- a/ibc-core/ics02-client/types/src/error.rs +++ b/ibc-core/ics02-client/types/src/error.rs @@ -48,7 +48,7 @@ pub enum ClientError { /// unexpected status found: `{0}` UnexpectedStatus(Status), /// client state already exists: `{0}` - AlreadyExistingClientState(ClientId), + DuplicateClientState(ClientId), /// mismatched client recovery states MismatchedClientRecoveryStates, /// client recovery heights not allowed: expected substitute client height `{substitute_height}` > subject client height `{subject_height}` diff --git a/ibc-core/ics04-channel/types/src/acknowledgement.rs b/ibc-core/ics04-channel/types/src/acknowledgement.rs index 2e19d3358..fbd0ffdd5 100644 --- a/ibc-core/ics04-channel/types/src/acknowledgement.rs +++ b/ibc-core/ics04-channel/types/src/acknowledgement.rs @@ -46,7 +46,9 @@ impl TryFrom> for Acknowledgement { fn try_from(bytes: Vec) -> Result { if bytes.is_empty() { - Err(PacketError::EmptyAcknowledgment) + Err(DecodingError::MissingRawData { + description: "acknowledgment not set".to_string(), + })? } else { Ok(Self(bytes)) } diff --git a/ibc-core/ics04-channel/types/src/error.rs b/ibc-core/ics04-channel/types/src/error.rs index a44f1975b..93a67b134 100644 --- a/ibc-core/ics04-channel/types/src/error.rs +++ b/ibc-core/ics04-channel/types/src/error.rs @@ -3,7 +3,7 @@ use displaydoc::Display; use ibc_core_client_types::error::ClientError; use ibc_core_client_types::Height; -use ibc_core_host_types::error::IdentifierError; +use ibc_core_host_types::error::{DecodingError, IdentifierError}; use ibc_core_host_types::identifiers::{ChannelId, PortId, Sequence}; use ibc_primitives::prelude::*; use ibc_primitives::{Timestamp, TimestampError}; @@ -16,6 +16,8 @@ use crate::Version; #[derive(Debug, Display)] pub enum ChannelError { + /// decoding error: `{0}` + Decoding(DecodingError), /// identifier error: `{0}` InvalidIdentifier(IdentifierError), /// invalid channel id: expected `{expected}`, actual `{actual}` @@ -37,8 +39,6 @@ pub enum ChannelError { MissingProofHeight, /// missing counterparty MissingCounterparty, - /// missing channel end in raw message - MissingRawChannelEnd, /// unsupported channel upgrade sequence UnsupportedChannelUpgradeSequence, /// unsupported version: expected `{expected}`, actual `{actual}` @@ -48,8 +48,6 @@ pub enum ChannelError { port_id: PortId, channel_id: ChannelId, }, - /// packet data bytes must be valid UTF-8 - NonUtf8PacketData, /// failed packet verification for packet with sequence `{sequence}`: `{client_error}` FailedPacketVerification { sequence: Sequence, @@ -72,10 +70,10 @@ pub enum ChannelError { #[derive(Debug, Display)] pub enum PacketError { - /// [HostError] application module error: `{description}` - AppModule { description: String }, /// channel error: `{0}` Channel(ChannelError), + /// decoding error: `{0}` + Decoding(DecodingError), /// insufficient packet timeout height: should have `{timeout_height}` > `{chain_height}` InsufficientPacketHeight { chain_height: Height, @@ -94,14 +92,6 @@ pub enum PacketError { expected: PacketCommitment, actual: PacketCommitment, }, - /// [HostError] missing packet receipt for packet `{0}` - MissingPacketReceipt(Sequence), - /// missing proof - MissingProof, - /// [HostError] missing acknowledgment for packet `{0}` - MissingPacketAcknowledgment(Sequence), - /// missing proof height - MissingProofHeight, /// missing timeout MissingTimeout, /// invalid timeout height: `{0}` @@ -110,12 +100,8 @@ pub enum PacketError { InvalidTimeoutTimestamp(TimestampError), /// invalid identifier: `{0}` InvalidIdentifier(IdentifierError), - /// empty acknowledgment not allowed - EmptyAcknowledgment, /// empty acknowledgment status not allowed EmptyAcknowledgmentStatus, - /// packet data bytes cannot be empty - EmptyPacketData, /// packet acknowledgment for sequence `{0}` already exists DuplicateAcknowledgment(Sequence), /// packet sequence cannot be 0 @@ -129,23 +115,43 @@ pub enum PacketError { }, /// implementation-specific error ImplementationSpecific, + + // TODO(seanchen1991): Move these variants to host-relevant error types + /// application module error: `{description}` + AppModule { description: String }, + /// missing acknowledgment for packet `{0}` + MissingPacketAcknowledgment(Sequence), + /// missing packet receipt for packet `{0}` + MissingPacketReceipt(Sequence), } impl From for ChannelError { - fn from(err: IdentifierError) -> Self { - Self::InvalidIdentifier(err) + fn from(e: IdentifierError) -> Self { + Self::InvalidIdentifier(e) } } impl From for PacketError { - fn from(err: IdentifierError) -> Self { - Self::InvalidIdentifier(err) + fn from(e: IdentifierError) -> Self { + Self::InvalidIdentifier(e) + } +} + +impl From for ChannelError { + fn from(e: DecodingError) -> Self { + Self::Decoding(e) + } +} + +impl From for PacketError { + fn from(e: DecodingError) -> Self { + Self::Decoding(e) } } impl From for PacketError { - fn from(err: TimestampError) -> Self { - Self::InvalidTimeoutTimestamp(err) + fn from(e: TimestampError) -> Self { + Self::InvalidTimeoutTimestamp(e) } } @@ -154,6 +160,7 @@ impl std::error::Error for PacketError { fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { match &self { Self::Channel(e) => Some(e), + Self::Decoding(e) => Some(e), Self::InvalidIdentifier(e) => Some(e), _ => None, } @@ -165,6 +172,7 @@ impl std::error::Error for ChannelError { fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { match &self { Self::InvalidIdentifier(e) => Some(e), + Self::Decoding(e) => Some(e), Self::FailedPacketVerification { client_error: e, .. } => Some(e), diff --git a/ibc-core/ics04-channel/types/src/events/packet_attributes.rs b/ibc-core/ics04-channel/types/src/events/packet_attributes.rs index a15a31220..35fb84a7f 100644 --- a/ibc-core/ics04-channel/types/src/events/packet_attributes.rs +++ b/ibc-core/ics04-channel/types/src/events/packet_attributes.rs @@ -4,6 +4,7 @@ use core::str; use derive_more::From; +use ibc_core_host_types::error::DecodingError; use ibc_core_host_types::identifiers::{ChannelId, ConnectionId, PortId, Sequence}; use ibc_primitives::prelude::*; use subtle_encoding::hex; @@ -53,7 +54,7 @@ impl TryFrom for Vec { let tags = vec![ ( PKT_DATA_ATTRIBUTE_KEY, - str::from_utf8(&attr.packet_data).map_err(|_| ChannelError::NonUtf8PacketData)?, + str::from_utf8(&attr.packet_data).map_err(DecodingError::StrUtf8)?, ) .into(), ( @@ -322,8 +323,7 @@ impl TryFrom for Vec { // 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(|_| ChannelError::NonUtf8PacketData)?, + str::from_utf8(attr.acknowledgement.as_bytes()).map_err(DecodingError::StrUtf8)?, ) .into(), ( diff --git a/ibc-core/ics04-channel/types/src/msgs/acknowledgement.rs b/ibc-core/ics04-channel/types/src/msgs/acknowledgement.rs index 2446395d7..b9f7d119e 100644 --- a/ibc-core/ics04-channel/types/src/msgs/acknowledgement.rs +++ b/ibc-core/ics04-channel/types/src/msgs/acknowledgement.rs @@ -1,5 +1,6 @@ use ibc_core_client_types::Height; use ibc_core_commitment_types::commitment::CommitmentProofBytes; +use ibc_core_host_types::error::DecodingError; use ibc_primitives::prelude::*; use ibc_primitives::Signer; use ibc_proto::ibc::core::channel::v1::MsgAcknowledgement as RawMsgAcknowledgement; @@ -39,17 +40,22 @@ impl TryFrom for MsgAcknowledgement { Ok(MsgAcknowledgement { packet: raw_msg .packet - .ok_or(PacketError::EmptyPacketData)? + .ok_or(DecodingError::MissingRawData { + description: "packet data not set".to_string(), + })? .try_into()?, acknowledgement: raw_msg.acknowledgement.try_into()?, - proof_acked_on_b: raw_msg - .proof_acked - .try_into() - .map_err(|_| PacketError::MissingProof)?, + proof_acked_on_b: raw_msg.proof_acked.try_into().map_err(|e| { + DecodingError::InvalidRawData { + description: format!("failed to decode proof: {e}"), + } + })?, proof_height_on_b: raw_msg .proof_height .and_then(|raw_height| raw_height.try_into().ok()) - .ok_or(PacketError::MissingProofHeight)?, + .ok_or(DecodingError::InvalidRawData { + description: "failed to decode proof height".to_string(), + })?, signer: raw_msg.signer.into(), }) } diff --git a/ibc-core/ics04-channel/types/src/msgs/chan_open_ack.rs b/ibc-core/ics04-channel/types/src/msgs/chan_open_ack.rs index 8634eb3e8..cb13fe9cb 100644 --- a/ibc-core/ics04-channel/types/src/msgs/chan_open_ack.rs +++ b/ibc-core/ics04-channel/types/src/msgs/chan_open_ack.rs @@ -1,5 +1,6 @@ use ibc_core_client_types::Height; use ibc_core_commitment_types::commitment::CommitmentProofBytes; +use ibc_core_host_types::error::DecodingError; use ibc_core_host_types::identifiers::{ChannelId, PortId}; use ibc_primitives::prelude::*; use ibc_primitives::Signer; @@ -41,14 +42,17 @@ impl TryFrom for MsgChannelOpenAck { chan_id_on_a: raw_msg.channel_id.parse()?, chan_id_on_b: raw_msg.counterparty_channel_id.parse()?, version_on_b: raw_msg.counterparty_version.into(), - proof_chan_end_on_b: raw_msg - .proof_try - .try_into() - .map_err(|_| ChannelError::MissingProof)?, + proof_chan_end_on_b: raw_msg.proof_try.try_into().map_err(|e| { + DecodingError::InvalidRawData { + description: format!("failed to decode proof: {e}"), + } + })?, proof_height_on_b: raw_msg .proof_height .and_then(|raw_height| raw_height.try_into().ok()) - .ok_or(ChannelError::MissingProofHeight)?, + .ok_or(DecodingError::MissingRawData { + description: "proof height not set".to_string(), + })?, signer: raw_msg.signer.into(), }) } diff --git a/ibc-core/ics04-channel/types/src/msgs/chan_open_init.rs b/ibc-core/ics04-channel/types/src/msgs/chan_open_init.rs index afac87752..c264ddabe 100644 --- a/ibc-core/ics04-channel/types/src/msgs/chan_open_init.rs +++ b/ibc-core/ics04-channel/types/src/msgs/chan_open_init.rs @@ -1,3 +1,4 @@ +use ibc_core_host_types::error::DecodingError; use ibc_core_host_types::identifiers::{ConnectionId, PortId}; use ibc_primitives::prelude::*; use ibc_primitives::Signer; @@ -47,7 +48,9 @@ impl TryFrom for MsgChannelOpenInit { fn try_from(raw_msg: RawMsgChannelOpenInit) -> Result { let chan_end_on_a: ChannelEnd = raw_msg .channel - .ok_or(ChannelError::MissingRawChannelEnd)? + .ok_or(DecodingError::MissingRawData { + description: "channel end not set".to_string(), + })? .try_into()?; chan_end_on_a.verify_state_matches(&State::Init)?; chan_end_on_a.counterparty().verify_empty_channel_id()?; diff --git a/ibc-core/ics04-channel/types/src/msgs/chan_open_try.rs b/ibc-core/ics04-channel/types/src/msgs/chan_open_try.rs index 8d85d1fa3..77e5afd89 100644 --- a/ibc-core/ics04-channel/types/src/msgs/chan_open_try.rs +++ b/ibc-core/ics04-channel/types/src/msgs/chan_open_try.rs @@ -1,5 +1,6 @@ use ibc_core_client_types::Height; use ibc_core_commitment_types::commitment::CommitmentProofBytes; +use ibc_core_host_types::error::DecodingError; use ibc_core_host_types::identifiers::{ChannelId, ConnectionId, PortId}; use ibc_primitives::prelude::*; use ibc_primitives::Signer; @@ -55,17 +56,16 @@ impl TryFrom for MsgChannelOpenTry { fn try_from(raw_msg: RawMsgChannelOpenTry) -> Result { let chan_end_on_b: ChannelEnd = raw_msg .channel - .ok_or(ChannelError::MissingRawChannelEnd)? + .ok_or(DecodingError::MissingRawData { + description: "channel end not set".to_string(), + })? .try_into()?; chan_end_on_b.verify_state_matches(&State::TryOpen)?; #[allow(deprecated)] if !raw_msg.previous_channel_id.is_empty() { - return Err(ChannelError::InvalidChannelId { - expected: "previous channel id must be empty. It has been deprecated as crossing hellos are no longer supported".to_string(), - actual: raw_msg.previous_channel_id, - }); + return Err(DecodingError::InvalidRawData { description: "previous channel id must be empty. It has been deprecated as crossing hellos are no longer supported".to_string() })?; } #[allow(deprecated)] diff --git a/ibc-core/ics04-channel/types/src/msgs/recv_packet.rs b/ibc-core/ics04-channel/types/src/msgs/recv_packet.rs index 53e4a6716..030449b72 100644 --- a/ibc-core/ics04-channel/types/src/msgs/recv_packet.rs +++ b/ibc-core/ics04-channel/types/src/msgs/recv_packet.rs @@ -1,5 +1,6 @@ use ibc_core_client_types::Height; use ibc_core_commitment_types::commitment::CommitmentProofBytes; +use ibc_core_host_types::error::DecodingError; use ibc_primitives::prelude::*; use ibc_primitives::Signer; use ibc_proto::ibc::core::channel::v1::MsgRecvPacket as RawMsgRecvPacket; @@ -39,16 +40,21 @@ impl TryFrom for MsgRecvPacket { Ok(MsgRecvPacket { packet: raw_msg .packet - .ok_or(PacketError::EmptyPacketData)? + .ok_or(DecodingError::MissingRawData { + description: "packet data not set".to_string(), + })? .try_into()?, - proof_commitment_on_a: raw_msg - .proof_commitment - .try_into() - .map_err(|_| PacketError::MissingProof)?, + proof_commitment_on_a: raw_msg.proof_commitment.try_into().map_err(|e| { + DecodingError::InvalidRawData { + description: format!("failed to decode proof: {e}"), + } + })?, proof_height_on_a: raw_msg .proof_height .and_then(|raw_height| raw_height.try_into().ok()) - .ok_or(PacketError::MissingProofHeight)?, + .ok_or(DecodingError::InvalidRawData { + description: "failed to decode proof height".to_string(), + })?, signer: raw_msg.signer.into(), }) } diff --git a/ibc-core/ics04-channel/types/src/msgs/timeout.rs b/ibc-core/ics04-channel/types/src/msgs/timeout.rs index 657e8233e..aaa24bd05 100644 --- a/ibc-core/ics04-channel/types/src/msgs/timeout.rs +++ b/ibc-core/ics04-channel/types/src/msgs/timeout.rs @@ -1,5 +1,6 @@ use ibc_core_client_types::Height; use ibc_core_commitment_types::commitment::CommitmentProofBytes; +use ibc_core_host_types::error::DecodingError; use ibc_core_host_types::identifiers::Sequence; use ibc_primitives::prelude::*; use ibc_primitives::Signer; @@ -41,17 +42,22 @@ impl TryFrom for MsgTimeout { Ok(MsgTimeout { packet: raw_msg .packet - .ok_or(PacketError::EmptyPacketData)? + .ok_or(DecodingError::MissingRawData { + description: "packet data not set".to_string(), + })? .try_into()?, next_seq_recv_on_b: Sequence::from(raw_msg.next_sequence_recv), - proof_unreceived_on_b: raw_msg - .proof_unreceived - .try_into() - .map_err(|_| PacketError::MissingProof)?, + proof_unreceived_on_b: raw_msg.proof_unreceived.try_into().map_err(|e| { + DecodingError::InvalidRawData { + description: format!("failed to decode proof: {e}"), + } + })?, proof_height_on_b: raw_msg .proof_height .and_then(|raw_height| raw_height.try_into().ok()) - .ok_or(PacketError::MissingProofHeight)?, + .ok_or(DecodingError::MissingRawData { + description: "proof height not set".to_string(), + })?, signer: raw_msg.signer.into(), }) } diff --git a/ibc-core/ics04-channel/types/src/msgs/timeout_on_close.rs b/ibc-core/ics04-channel/types/src/msgs/timeout_on_close.rs index 670205716..fd1142a7c 100644 --- a/ibc-core/ics04-channel/types/src/msgs/timeout_on_close.rs +++ b/ibc-core/ics04-channel/types/src/msgs/timeout_on_close.rs @@ -1,5 +1,6 @@ use ibc_core_client_types::Height; use ibc_core_commitment_types::commitment::CommitmentProofBytes; +use ibc_core_host_types::error::DecodingError; use ibc_core_host_types::identifiers::Sequence; use ibc_primitives::prelude::*; use ibc_primitives::Signer; @@ -48,21 +49,27 @@ impl TryFrom for MsgTimeoutOnClose { Ok(MsgTimeoutOnClose { packet: raw_msg .packet - .ok_or(PacketError::EmptyPacketData)? + .ok_or(DecodingError::MissingRawData { + description: "packet data not set".to_string(), + })? .try_into()?, next_seq_recv_on_b: Sequence::from(raw_msg.next_sequence_recv), - proof_unreceived_on_b: raw_msg - .proof_unreceived - .try_into() - .map_err(|_| PacketError::MissingProof)?, - proof_close_on_b: raw_msg - .proof_close - .try_into() - .map_err(|_| PacketError::MissingProof)?, + proof_unreceived_on_b: raw_msg.proof_unreceived.try_into().map_err(|e| { + DecodingError::InvalidRawData { + description: format!("failed to decode proof: {e}"), + } + })?, + proof_close_on_b: raw_msg.proof_close.try_into().map_err(|e| { + DecodingError::InvalidRawData { + description: format!("failed to decode proof: {e}"), + } + })?, proof_height_on_b: raw_msg .proof_height .and_then(|raw_height| raw_height.try_into().ok()) - .ok_or(PacketError::MissingProofHeight)?, + .ok_or(DecodingError::InvalidRawData { + description: "failed to decode proof height".to_string(), + })?, signer: raw_msg.signer.into(), }) } diff --git a/ibc-core/ics04-channel/types/src/packet.rs b/ibc-core/ics04-channel/types/src/packet.rs index dfd6f0358..e1be45ef3 100644 --- a/ibc-core/ics04-channel/types/src/packet.rs +++ b/ibc-core/ics04-channel/types/src/packet.rs @@ -1,5 +1,6 @@ //! Defines the packet type use ibc_core_client_types::Height; +use ibc_core_host_types::error::DecodingError; use ibc_core_host_types::identifiers::{ChannelId, PortId, Sequence}; use ibc_primitives::prelude::*; use ibc_primitives::Timestamp; @@ -172,7 +173,9 @@ impl TryFrom for Packet { } if raw_pkt.data.is_empty() { - return Err(PacketError::EmptyPacketData); + return Err(DecodingError::MissingRawData { + description: "packet data is not set".to_string(), + })?; } // Note: ibc-go currently (July 2022) incorrectly treats the timeout @@ -282,7 +285,9 @@ impl TryFrom for PacketState { } if raw_pkt.data.is_empty() { - return Err(PacketError::EmptyPacketData); + return Err(DecodingError::MissingRawData { + description: "packet data not set".to_string(), + })?; } Ok(PacketState { diff --git a/ibc-core/ics24-host/types/src/error.rs b/ibc-core/ics24-host/types/src/error.rs index bf1d8a129..5a89f9ab8 100644 --- a/ibc-core/ics24-host/types/src/error.rs +++ b/ibc-core/ics24-host/types/src/error.rs @@ -1,6 +1,7 @@ //! Foundational error types that are applicable across multiple ibc-rs workspaces. use alloc::string::{FromUtf8Error, String}; +use core::str::Utf8Error; use base64::DecodeError as Base64Error; use displaydoc::Display; @@ -29,8 +30,10 @@ pub enum IdentifierError { pub enum DecodingError { /// base64 decoding error: `{0}` Base64(Base64Error), - /// utf-8 decoding error: `{0}` - Utf8(FromUtf8Error), + /// utf-8 String decoding error: `{0}` + StringUtf8(FromUtf8Error), + /// utf-8 str decoding error: `{0}` + StrUtf8(Utf8Error), /// protobuf decoding error: `{0}` Protobuf(ProtoError), /// prost decoding error: `{0}` From a814a3e4ffcc8cadec740fd376f1e90b523de9fb Mon Sep 17 00:00:00 2001 From: Sean Chen Date: Wed, 4 Sep 2024 15:05:40 -0500 Subject: [PATCH 45/73] Remove WasmClientError --- .../ics08-wasm/types/src/client_state.rs | 17 ++++---- ibc-clients/ics08-wasm/types/src/error.rs | 41 ------------------- ibc-clients/ics08-wasm/types/src/lib.rs | 1 - .../types/src/msgs/migrate_contract.rs | 7 ++-- 4 files changed, 13 insertions(+), 53 deletions(-) delete mode 100644 ibc-clients/ics08-wasm/types/src/error.rs diff --git a/ibc-clients/ics08-wasm/types/src/client_state.rs b/ibc-clients/ics08-wasm/types/src/client_state.rs index 7124636ae..b7506267a 100644 --- a/ibc-clients/ics08-wasm/types/src/client_state.rs +++ b/ibc-clients/ics08-wasm/types/src/client_state.rs @@ -6,7 +6,6 @@ use ibc_primitives::prelude::*; use ibc_primitives::proto::{Any, Protobuf}; use ibc_proto::ibc::lightclients::wasm::v1::ClientState as RawClientState; -use crate::error::WasmClientError; #[cfg(feature = "serde")] use crate::serializer::Base64; use crate::Bytes; @@ -39,14 +38,18 @@ impl From for RawClientState { } impl TryFrom for ClientState { - type Error = WasmClientError; + type Error = DecodingError; fn try_from(raw: RawClientState) -> Result { let latest_height = raw .latest_height - .ok_or(WasmClientError::MissingLatestHeight)? + .ok_or(DecodingError::MissingRawData { + description: "latest height not set".to_string(), + })? .try_into() - .map_err(|_| WasmClientError::InvalidLatestHeight)?; + .map_err(|e| DecodingError::InvalidRawData { + description: format!("failed to decode latest height: {e}"), + })?; Ok(Self { data: raw.data, checksum: raw.checksum, @@ -67,7 +70,7 @@ impl From for Any { } impl TryFrom for ClientState { - type Error = WasmClientError; + type Error = DecodingError; fn try_from(any: Any) -> Result { fn decode_client_state(value: &[u8]) -> Result { @@ -76,9 +79,7 @@ impl TryFrom for ClientState { } match any.type_url.as_str() { - WASM_CLIENT_STATE_TYPE_URL => { - decode_client_state(&any.value).map_err(WasmClientError::Decoding) - } + WASM_CLIENT_STATE_TYPE_URL => decode_client_state(&any.value), _ => Err(DecodingError::MismatchedTypeUrls { expected: WASM_CLIENT_STATE_TYPE_URL.to_string(), actual: any.type_url, diff --git a/ibc-clients/ics08-wasm/types/src/error.rs b/ibc-clients/ics08-wasm/types/src/error.rs deleted file mode 100644 index f7615f802..000000000 --- a/ibc-clients/ics08-wasm/types/src/error.rs +++ /dev/null @@ -1,41 +0,0 @@ -//! Defines the error type for the ICS-08 Wasm light client. - -use displaydoc::Display; -use ibc_core_host_types::error::{DecodingError, IdentifierError}; -use ibc_primitives::prelude::*; - -/// The main error type -#[derive(Debug, Display)] -pub enum WasmClientError { - /// decoding error: `{0}` - Decoding(DecodingError), - /// invalid identifier: `{0}` - InvalidIdentifier(IdentifierError), - /// invalid client state latest height - InvalidLatestHeight, - /// missing latest height - MissingLatestHeight, -} - -#[cfg(feature = "std")] -impl std::error::Error for WasmClientError { - fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { - match self { - Self::InvalidIdentifier(e) => Some(e), - Self::Decoding(e) => Some(e), - _ => None, - } - } -} - -impl From for WasmClientError { - fn from(e: IdentifierError) -> Self { - Self::InvalidIdentifier(e) - } -} - -impl From for WasmClientError { - fn from(e: DecodingError) -> Self { - Self::Decoding(e) - } -} diff --git a/ibc-clients/ics08-wasm/types/src/lib.rs b/ibc-clients/ics08-wasm/types/src/lib.rs index 169eb3b30..3a88d0431 100644 --- a/ibc-clients/ics08-wasm/types/src/lib.rs +++ b/ibc-clients/ics08-wasm/types/src/lib.rs @@ -15,7 +15,6 @@ pub mod client_message; pub mod client_state; pub mod consensus_state; -pub mod error; pub mod msgs; #[cfg(feature = "serde")] diff --git a/ibc-clients/ics08-wasm/types/src/msgs/migrate_contract.rs b/ibc-clients/ics08-wasm/types/src/msgs/migrate_contract.rs index cd0bd9d3d..c00d36080 100644 --- a/ibc-clients/ics08-wasm/types/src/msgs/migrate_contract.rs +++ b/ibc-clients/ics08-wasm/types/src/msgs/migrate_contract.rs @@ -1,12 +1,12 @@ use core::str::FromStr; +use ibc_core_host_types::error::DecodingError; use ibc_core_host_types::identifiers::ClientId; use ibc_primitives::prelude::*; use ibc_primitives::Signer; use ibc_proto::ibc::lightclients::wasm::v1::MsgMigrateContract as RawMsgMigrateContract; use ibc_proto::Protobuf; -use crate::error::WasmClientError; use crate::Bytes; pub const MIGRATE_CONTRACT_TYPE_URL: &str = "/ibc.lightclients.wasm.v1.MsgMigrateContract"; @@ -34,12 +34,13 @@ impl From for RawMsgMigrateContract { } impl TryFrom for MsgMigrateContract { - type Error = WasmClientError; + type Error = DecodingError; fn try_from(value: RawMsgMigrateContract) -> Result { Ok(Self { signer: Signer::from(value.signer), - client_id: ClientId::from_str(&value.client_id)?, + client_id: ClientId::from_str(&value.client_id) + .map_err(DecodingError::InvalidIdentifier)?, checksum: value.checksum, msg: value.msg, }) From 810a5ad75c7212c426ed4a7f8083f4804e74a949 Mon Sep 17 00:00:00 2001 From: Sean Chen Date: Wed, 4 Sep 2024 15:12:43 -0500 Subject: [PATCH 46/73] Consolidate Identifier variant naming --- ibc-clients/ics07-tendermint/types/src/error.rs | 8 ++++---- .../ics08-wasm/types/src/msgs/migrate_contract.rs | 3 +-- ibc-core/ics02-client/types/src/error.rs | 3 +-- .../ics02-client/types/src/msgs/misbehaviour.rs | 7 ++----- .../ics02-client/types/src/msgs/recover_client.rs | 4 ++-- .../ics02-client/types/src/msgs/update_client.rs | 7 ++----- .../ics02-client/types/src/msgs/upgrade_client.rs | 2 +- ibc-core/ics03-connection/types/src/connection.rs | 11 ++++------- ibc-core/ics03-connection/types/src/error.rs | 4 ++-- .../types/src/msgs/conn_open_ack.rs | 4 ++-- .../types/src/msgs/conn_open_confirm.rs | 2 +- .../types/src/msgs/conn_open_init.rs | 5 +---- .../types/src/msgs/conn_open_try.rs | 5 +---- ibc-core/ics04-channel/types/src/error.rs | 14 +++++++------- ibc-core/ics24-host/types/src/error.rs | 4 ++-- 15 files changed, 33 insertions(+), 50 deletions(-) diff --git a/ibc-clients/ics07-tendermint/types/src/error.rs b/ibc-clients/ics07-tendermint/types/src/error.rs index 11bf310b7..f09c74748 100644 --- a/ibc-clients/ics07-tendermint/types/src/error.rs +++ b/ibc-clients/ics07-tendermint/types/src/error.rs @@ -18,8 +18,8 @@ use tendermint_light_client_verifier::Verdict; pub enum TendermintClientError { /// decoding error: `{0}` Decoding(DecodingError), - /// invalid identifier: `{0}` - InvalidIdentifier(IdentifierError), + /// identifier error: `{0}` + Identifier(IdentifierError), /// invalid client state trust threshold: `{description}` InvalidTrustThreshold { description: String }, /// invalid clock drift; must be greater than 0 @@ -55,7 +55,7 @@ pub enum TendermintClientError { impl std::error::Error for TendermintClientError { fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { match &self { - Self::InvalidIdentifier(e) => Some(e), + Self::Identifier(e) => Some(e), Self::Decoding(e) => Some(e), _ => None, } @@ -74,7 +74,7 @@ impl From for ClientError { impl From for TendermintClientError { fn from(e: IdentifierError) -> Self { - Self::InvalidIdentifier(e) + Self::Identifier(e) } } diff --git a/ibc-clients/ics08-wasm/types/src/msgs/migrate_contract.rs b/ibc-clients/ics08-wasm/types/src/msgs/migrate_contract.rs index c00d36080..6a8e860e3 100644 --- a/ibc-clients/ics08-wasm/types/src/msgs/migrate_contract.rs +++ b/ibc-clients/ics08-wasm/types/src/msgs/migrate_contract.rs @@ -39,8 +39,7 @@ impl TryFrom for MsgMigrateContract { fn try_from(value: RawMsgMigrateContract) -> Result { Ok(Self { signer: Signer::from(value.signer), - client_id: ClientId::from_str(&value.client_id) - .map_err(DecodingError::InvalidIdentifier)?, + client_id: ClientId::from_str(&value.client_id).map_err(DecodingError::Identifier)?, checksum: value.checksum, msg: value.msg, }) diff --git a/ibc-core/ics02-client/types/src/error.rs b/ibc-core/ics02-client/types/src/error.rs index f6000ac47..26aeb03dd 100644 --- a/ibc-core/ics02-client/types/src/error.rs +++ b/ibc-core/ics02-client/types/src/error.rs @@ -3,13 +3,12 @@ use core::convert::Infallible; use displaydoc::Display; -use tendermint::Error as TendermintError; - use ibc_core_commitment_types::error::CommitmentError; use ibc_core_host_types::error::DecodingError; use ibc_core_host_types::identifiers::ClientId; use ibc_primitives::prelude::*; use ibc_primitives::Timestamp; +use tendermint::Error as TendermintError; use crate::height::Height; use crate::Status; diff --git a/ibc-core/ics02-client/types/src/msgs/misbehaviour.rs b/ibc-core/ics02-client/types/src/msgs/misbehaviour.rs index 7215ca534..dac0eb62e 100644 --- a/ibc-core/ics02-client/types/src/msgs/misbehaviour.rs +++ b/ibc-core/ics02-client/types/src/msgs/misbehaviour.rs @@ -42,14 +42,11 @@ impl TryFrom for MsgSubmitMisbehaviour { fn try_from(raw: RawMsgSubmitMisbehaviour) -> Result { let raw_misbehaviour = raw.misbehaviour.ok_or(DecodingError::MissingRawData { - description: "missing raw misbehaviour".to_string(), + description: "misbehaviour not set".to_string(), })?; Ok(MsgSubmitMisbehaviour { - client_id: raw - .client_id - .parse() - .map_err(DecodingError::InvalidIdentifier)?, + client_id: raw.client_id.parse().map_err(DecodingError::Identifier)?, misbehaviour: raw_misbehaviour, signer: raw.signer.into(), }) diff --git a/ibc-core/ics02-client/types/src/msgs/recover_client.rs b/ibc-core/ics02-client/types/src/msgs/recover_client.rs index 6d78f0ed1..e9b79c78f 100644 --- a/ibc-core/ics02-client/types/src/msgs/recover_client.rs +++ b/ibc-core/ics02-client/types/src/msgs/recover_client.rs @@ -46,11 +46,11 @@ impl TryFrom for MsgRecoverClient { subject_client_id: raw .subject_client_id .parse() - .map_err(DecodingError::InvalidIdentifier)?, + .map_err(DecodingError::Identifier)?, substitute_client_id: raw .substitute_client_id .parse() - .map_err(DecodingError::InvalidIdentifier)?, + .map_err(DecodingError::Identifier)?, signer: raw.signer.into(), }) } diff --git a/ibc-core/ics02-client/types/src/msgs/update_client.rs b/ibc-core/ics02-client/types/src/msgs/update_client.rs index 0ffa8430a..5c5518884 100644 --- a/ibc-core/ics02-client/types/src/msgs/update_client.rs +++ b/ibc-core/ics02-client/types/src/msgs/update_client.rs @@ -35,12 +35,9 @@ impl TryFrom for MsgUpdateClient { fn try_from(raw: RawMsgUpdateClient) -> Result { Ok(MsgUpdateClient { - client_id: raw - .client_id - .parse() - .map_err(DecodingError::InvalidIdentifier)?, + client_id: raw.client_id.parse().map_err(DecodingError::Identifier)?, client_message: raw.client_message.ok_or(DecodingError::MissingRawData { - description: "missing raw client message".to_string(), + description: "client message not set".to_string(), })?, signer: raw.signer.into(), }) diff --git a/ibc-core/ics02-client/types/src/msgs/upgrade_client.rs b/ibc-core/ics02-client/types/src/msgs/upgrade_client.rs index b1d2964d1..8bcf63956 100644 --- a/ibc-core/ics02-client/types/src/msgs/upgrade_client.rs +++ b/ibc-core/ics02-client/types/src/msgs/upgrade_client.rs @@ -87,7 +87,7 @@ impl TryFrom for MsgUpgradeClient { Ok(MsgUpgradeClient { client_id: ClientId::from_str(&proto_msg.client_id) - .map_err(DecodingError::InvalidIdentifier)?, + .map_err(DecodingError::Identifier)?, upgraded_client_state: raw_client_state, upgraded_consensus_state: raw_consensus_state, proof_upgrade_client: c_bytes, diff --git a/ibc-core/ics03-connection/types/src/connection.rs b/ibc-core/ics03-connection/types/src/connection.rs index 2602c456d..8af322e41 100644 --- a/ibc-core/ics03-connection/types/src/connection.rs +++ b/ibc-core/ics03-connection/types/src/connection.rs @@ -67,10 +67,7 @@ impl TryFrom for IdentifiedConnectionEnd { }; Ok(IdentifiedConnectionEnd { - connection_id: value - .id - .parse() - .map_err(ConnectionError::InvalidIdentifier)?, + connection_id: value.id.parse().map_err(ConnectionError::Identifier)?, connection_end: raw_connection_end.try_into()?, }) } @@ -214,7 +211,7 @@ impl TryFrom for ConnectionEnd { value .client_id .parse() - .map_err(ConnectionError::InvalidIdentifier)?, + .map_err(ConnectionError::Identifier)?, value .counterparty .ok_or(ConnectionError::MissingCounterparty)? @@ -378,14 +375,14 @@ impl TryFrom for Counterparty { raw_counterparty .connection_id .parse() - .map_err(ConnectionError::InvalidIdentifier)?, + .map_err(ConnectionError::Identifier)?, ) }; Ok(Counterparty::new( raw_counterparty .client_id .parse() - .map_err(ConnectionError::InvalidIdentifier)?, + .map_err(ConnectionError::Identifier)?, connection_id, raw_counterparty .prefix diff --git a/ibc-core/ics03-connection/types/src/error.rs b/ibc-core/ics03-connection/types/src/error.rs index d141c6303..fa6d49ad1 100644 --- a/ibc-core/ics03-connection/types/src/error.rs +++ b/ibc-core/ics03-connection/types/src/error.rs @@ -14,8 +14,8 @@ use crate::version::Version; pub enum ConnectionError { /// decoding error: `{0}` Decoding(DecodingError), - /// invalid identifier: `{0}` - InvalidIdentifier(IdentifierError), + /// identifier error: `{0}` + Identifier(IdentifierError), /// invalid state for initializing new ConnectionEnd; expected `Init` connection state and a single version InvalidStateForConnectionEndInit, /// invalid connection proof diff --git a/ibc-core/ics03-connection/types/src/msgs/conn_open_ack.rs b/ibc-core/ics03-connection/types/src/msgs/conn_open_ack.rs index dc3056b2a..611102f8b 100644 --- a/ibc-core/ics03-connection/types/src/msgs/conn_open_ack.rs +++ b/ibc-core/ics03-connection/types/src/msgs/conn_open_ack.rs @@ -54,11 +54,11 @@ impl TryFrom for MsgConnectionOpenAck { conn_id_on_a: msg .connection_id .parse() - .map_err(ConnectionError::InvalidIdentifier)?, + .map_err(ConnectionError::Identifier)?, conn_id_on_b: msg .counterparty_connection_id .parse() - .map_err(ConnectionError::InvalidIdentifier)?, + .map_err(ConnectionError::Identifier)?, client_state_of_a_on_b: msg .client_state .ok_or(ConnectionError::MissingClientState)?, diff --git a/ibc-core/ics03-connection/types/src/msgs/conn_open_confirm.rs b/ibc-core/ics03-connection/types/src/msgs/conn_open_confirm.rs index e18821d57..3f534a2d6 100644 --- a/ibc-core/ics03-connection/types/src/msgs/conn_open_confirm.rs +++ b/ibc-core/ics03-connection/types/src/msgs/conn_open_confirm.rs @@ -38,7 +38,7 @@ impl TryFrom for MsgConnectionOpenConfirm { conn_id_on_b: msg .connection_id .parse() - .map_err(ConnectionError::InvalidIdentifier)?, + .map_err(ConnectionError::Identifier)?, proof_conn_end_on_a: msg .proof_ack .try_into() diff --git a/ibc-core/ics03-connection/types/src/msgs/conn_open_init.rs b/ibc-core/ics03-connection/types/src/msgs/conn_open_init.rs index 7d9affcfd..eed8736a3 100644 --- a/ibc-core/ics03-connection/types/src/msgs/conn_open_init.rs +++ b/ibc-core/ics03-connection/types/src/msgs/conn_open_init.rs @@ -95,10 +95,7 @@ impl TryFrom for MsgConnectionOpenInit { counterparty.verify_empty_connection_id()?; Ok(Self { - client_id_on_a: msg - .client_id - .parse() - .map_err(ConnectionError::InvalidIdentifier)?, + client_id_on_a: msg.client_id.parse().map_err(ConnectionError::Identifier)?, counterparty, version: msg.version.map(TryInto::try_into).transpose()?, delay_period: Duration::from_nanos(msg.delay_period), diff --git a/ibc-core/ics03-connection/types/src/msgs/conn_open_try.rs b/ibc-core/ics03-connection/types/src/msgs/conn_open_try.rs index 6686b806a..0c9e884ea 100644 --- a/ibc-core/ics03-connection/types/src/msgs/conn_open_try.rs +++ b/ibc-core/ics03-connection/types/src/msgs/conn_open_try.rs @@ -162,10 +162,7 @@ impl TryFrom for MsgConnectionOpenTry { #[allow(deprecated)] Ok(Self { previous_connection_id: msg.previous_connection_id, - client_id_on_b: msg - .client_id - .parse() - .map_err(ConnectionError::InvalidIdentifier)?, + client_id_on_b: msg.client_id.parse().map_err(ConnectionError::Identifier)?, client_state_of_b_on_a: msg .client_state .ok_or(ConnectionError::MissingClientState)?, diff --git a/ibc-core/ics04-channel/types/src/error.rs b/ibc-core/ics04-channel/types/src/error.rs index 93a67b134..abf150b13 100644 --- a/ibc-core/ics04-channel/types/src/error.rs +++ b/ibc-core/ics04-channel/types/src/error.rs @@ -19,7 +19,7 @@ pub enum ChannelError { /// decoding error: `{0}` Decoding(DecodingError), /// identifier error: `{0}` - InvalidIdentifier(IdentifierError), + Identifier(IdentifierError), /// invalid channel id: expected `{expected}`, actual `{actual}` InvalidChannelId { expected: String, actual: String }, /// invalid channel state: expected `{expected}`, actual `{actual}` @@ -98,8 +98,8 @@ pub enum PacketError { InvalidTimeoutHeight(ClientError), /// invalid timeout timestamp: `{0}` InvalidTimeoutTimestamp(TimestampError), - /// invalid identifier: `{0}` - InvalidIdentifier(IdentifierError), + /// identifier error: `{0}` + Identifier(IdentifierError), /// empty acknowledgment status not allowed EmptyAcknowledgmentStatus, /// packet acknowledgment for sequence `{0}` already exists @@ -127,13 +127,13 @@ pub enum PacketError { impl From for ChannelError { fn from(e: IdentifierError) -> Self { - Self::InvalidIdentifier(e) + Self::Identifier(e) } } impl From for PacketError { fn from(e: IdentifierError) -> Self { - Self::InvalidIdentifier(e) + Self::Identifier(e) } } @@ -161,7 +161,7 @@ impl std::error::Error for PacketError { match &self { Self::Channel(e) => Some(e), Self::Decoding(e) => Some(e), - Self::InvalidIdentifier(e) => Some(e), + Self::Identifier(e) => Some(e), _ => None, } } @@ -171,7 +171,7 @@ impl std::error::Error for PacketError { impl std::error::Error for ChannelError { fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { match &self { - Self::InvalidIdentifier(e) => Some(e), + Self::Identifier(e) => Some(e), Self::Decoding(e) => Some(e), Self::FailedPacketVerification { client_error: e, .. diff --git a/ibc-core/ics24-host/types/src/error.rs b/ibc-core/ics24-host/types/src/error.rs index 5a89f9ab8..fefc02871 100644 --- a/ibc-core/ics24-host/types/src/error.rs +++ b/ibc-core/ics24-host/types/src/error.rs @@ -28,6 +28,8 @@ pub enum IdentifierError { /// Errors that result in decoding failures #[derive(Debug, Display)] pub enum DecodingError { + /// identifier error: `{0}` + Identifier(IdentifierError), /// base64 decoding error: `{0}` Base64(Base64Error), /// utf-8 String decoding error: `{0}` @@ -42,8 +44,6 @@ pub enum DecodingError { InvalidHash { description: String }, /// invalid JSON data: `{description}` InvalidJson { description: String }, - /// invalid identifier error: `{0}` - InvalidIdentifier(IdentifierError), /// invalid raw data: `{description}` InvalidRawData { description: String }, /// missing raw data: `{description}` From a307051c6430622a4e0db67f32c3e2bee284c599 Mon Sep 17 00:00:00 2001 From: Sean Chen Date: Wed, 4 Sep 2024 16:44:32 -0500 Subject: [PATCH 47/73] Remove HostError annotations in doc comments --- ibc-core/ics03-connection/types/src/error.rs | 26 +++++--- .../types/src/msgs/conn_open_try.rs | 62 +++++++++++-------- 2 files changed, 54 insertions(+), 34 deletions(-) diff --git a/ibc-core/ics03-connection/types/src/error.rs b/ibc-core/ics03-connection/types/src/error.rs index fa6d49ad1..f7ef3426e 100644 --- a/ibc-core/ics03-connection/types/src/error.rs +++ b/ibc-core/ics03-connection/types/src/error.rs @@ -44,10 +44,6 @@ pub enum ConnectionError { MissingProofHeight, /// missing consensus height MissingConsensusHeight, - /// [HostError] missing connection `{0}` - MissingConnection(ConnectionId), - /// [HostError] missing connection counter - MissingConnectionCounter, /// missing counterparty MissingCounterparty, /// missing client state @@ -73,14 +69,26 @@ pub enum ConnectionError { FailedToVerifyConsensusState(ClientError), /// failed to verify client state: `{0}` FailedToVerifyClientState(ClientError), - /// [HostError] failed to store connection IDs + /// overflowed timestamp: `{0}` + OverflowedTimestamp(TimestampError), + + // TODO(seanchen1991): Move these variants to host-relevant error types + /// missing connection `{0}` + MissingConnection(ConnectionId), + /// missing connection counter + MissingConnectionCounter, + /// failed to store connection IDs FailedToStoreConnectionIds, - /// [HostError] failed to store connection end + /// failed to store connection end FailedToStoreConnectionEnd, - /// [HostError] failed to update connection counter + /// failed to update connection counter FailedToUpdateConnectionCounter, - /// overflowed timestamp: `{0}` - OverflowedTimestamp(TimestampError), +} + +impl From for ConnectionError { + fn from(e: DecodingError) -> Self { + Self::Decoding(e) + } } #[cfg(feature = "std")] diff --git a/ibc-core/ics03-connection/types/src/msgs/conn_open_try.rs b/ibc-core/ics03-connection/types/src/msgs/conn_open_try.rs index 0c9e884ea..2bc0526aa 100644 --- a/ibc-core/ics03-connection/types/src/msgs/conn_open_try.rs +++ b/ibc-core/ics03-connection/types/src/msgs/conn_open_try.rs @@ -2,6 +2,7 @@ use core::time::Duration; use ibc_core_client_types::Height; use ibc_core_commitment_types::commitment::CommitmentProofBytes; +use ibc_core_host_types::error::DecodingError; use ibc_core_host_types::identifiers::ClientId; use ibc_primitives::prelude::*; use ibc_primitives::Signer; @@ -154,7 +155,9 @@ impl TryFrom for MsgConnectionOpenTry { .collect::, _>>()?; if counterparty_versions.is_empty() { - return Err(ConnectionError::EmptyVersions); + return Err(DecodingError::MissingRawData { + description: "connection versions not set".to_string(), + })?; } // We set the deprecated `previous_connection_id` field so that we can @@ -162,45 +165,54 @@ impl TryFrom for MsgConnectionOpenTry { #[allow(deprecated)] Ok(Self { previous_connection_id: msg.previous_connection_id, - client_id_on_b: msg.client_id.parse().map_err(ConnectionError::Identifier)?, - client_state_of_b_on_a: msg - .client_state - .ok_or(ConnectionError::MissingClientState)?, + client_id_on_b: msg.client_id.parse().map_err(DecodingError::Identifier)?, + client_state_of_b_on_a: msg.client_state.ok_or(DecodingError::MissingRawData { + description: "client state not set".to_string(), + })?, counterparty: msg .counterparty - .ok_or(ConnectionError::MissingCounterparty)? + .ok_or(DecodingError::MissingRawData { + description: "counterparty not set".to_string(), + })? .try_into()?, versions_on_a: counterparty_versions, - proof_conn_end_on_a: msg - .proof_init - .try_into() - .map_err(|_| ConnectionError::InvalidProof)?, - proof_client_state_of_b_on_a: msg - .proof_client - .try_into() - .map_err(|_| ConnectionError::InvalidProof)?, - proof_consensus_state_of_b_on_a: msg - .proof_consensus - .try_into() - .map_err(|_| ConnectionError::InvalidProof)?, + proof_conn_end_on_a: msg.proof_init.try_into().map_err(|e| { + DecodingError::InvalidRawData { + description: format!("failed to decode connection end proof: {e}"), + } + })?, + proof_client_state_of_b_on_a: msg.proof_client.try_into().map_err(|e| { + DecodingError::InvalidRawData { + description: format!("failed to decode client state proof: {e}"), + } + })?, + proof_consensus_state_of_b_on_a: msg.proof_consensus.try_into().map_err(|e| { + DecodingError::InvalidRawData { + description: format!("failed to decode consensus state proof: {e}"), + } + })?, proofs_height_on_a: msg .proof_height .and_then(|raw_height| raw_height.try_into().ok()) - .ok_or(ConnectionError::MissingProofHeight)?, + .ok_or(DecodingError::InvalidRawData { + description: "failed to decode proof height".to_string(), + })?, consensus_height_of_b_on_a: msg .consensus_height .and_then(|raw_height| raw_height.try_into().ok()) - .ok_or(ConnectionError::MissingConsensusHeight)?, + .ok_or(DecodingError::InvalidRawData { + description: "failed to decode consensus height".to_string(), + })?, delay_period: Duration::from_nanos(msg.delay_period), signer: msg.signer.into(), proof_consensus_state_of_b: if msg.host_consensus_state_proof.is_empty() { None } else { - Some( - msg.host_consensus_state_proof - .try_into() - .map_err(|_| ConnectionError::InvalidProof)?, - ) + Some(msg.host_consensus_state_proof.try_into().map_err(|e| { + DecodingError::InvalidRawData { + description: format!("failed to decode consensus state proof: {e}"), + } + })?) }, }) } From eb4e612bea3497c6a1219fcad3da231cd4cc475b Mon Sep 17 00:00:00 2001 From: Sean Chen Date: Thu, 5 Sep 2024 09:07:43 -0500 Subject: [PATCH 48/73] Consolidate CommitmentError variants --- .../types/src/msgs/upgrade_client.rs | 8 +++--- .../ics23-commitment/types/src/commitment.rs | 4 ++- ibc-core/ics23-commitment/types/src/error.rs | 6 ----- ibc-core/ics23-commitment/types/src/specs.rs | 25 ++++++++++++------- 4 files changed, 23 insertions(+), 20 deletions(-) diff --git a/ibc-core/ics02-client/types/src/msgs/upgrade_client.rs b/ibc-core/ics02-client/types/src/msgs/upgrade_client.rs index 8bcf63956..72251e3d7 100644 --- a/ibc-core/ics02-client/types/src/msgs/upgrade_client.rs +++ b/ibc-core/ics02-client/types/src/msgs/upgrade_client.rs @@ -61,27 +61,27 @@ impl TryFrom for MsgUpgradeClient { let raw_client_state = proto_msg .client_state .ok_or(DecodingError::MissingRawData { - description: "no raw client state set".to_string(), + description: "client state not set".to_string(), })?; let raw_consensus_state = proto_msg .consensus_state .ok_or(DecodingError::MissingRawData { - description: "no raw consensus state set".to_string(), + description: "consensus state not set".to_string(), })?; let c_bytes = CommitmentProofBytes::try_from(proto_msg.proof_upgrade_client).map_err(|_| { UpgradeClientError::InvalidUpgradeClientStateProof( - CommitmentError::EmptyMerkleProof, + CommitmentError::InvalidMerkleProof, ) })?; let cs_bytes = CommitmentProofBytes::try_from(proto_msg.proof_upgrade_consensus_state) .map_err(|_| { UpgradeClientError::InvalidUpgradeConsensusStateProof( - CommitmentError::EmptyMerkleProof, + CommitmentError::InvalidMerkleProof, ) })?; diff --git a/ibc-core/ics23-commitment/types/src/commitment.rs b/ibc-core/ics23-commitment/types/src/commitment.rs index 1f6c94175..88df28c54 100644 --- a/ibc-core/ics23-commitment/types/src/commitment.rs +++ b/ibc-core/ics23-commitment/types/src/commitment.rs @@ -95,7 +95,9 @@ impl TryFrom> for CommitmentProofBytes { fn try_from(bytes: Vec) -> Result { if bytes.is_empty() { - Err(Self::Error::EmptyMerkleProof) + Err(DecodingError::InvalidRawData { + description: "empty commitment proof bytes".to_string(), + })? } else { Ok(Self { bytes }) } diff --git a/ibc-core/ics23-commitment/types/src/error.rs b/ibc-core/ics23-commitment/types/src/error.rs index 511aa3fb9..3b6d09927 100644 --- a/ibc-core/ics23-commitment/types/src/error.rs +++ b/ibc-core/ics23-commitment/types/src/error.rs @@ -22,18 +22,12 @@ pub enum CommitmentError { EmptyProofSpecs, /// mismatched number of proofs: expected `{expected}`, actual `{actual}` MismatchedNumberOfProofs { expected: usize, actual: usize }, - /// mismatched proofs: expected `{expected}`, actual `{actual}` - MismatchedProofs { expected: String, actual: String }, /// invalid range: [`{min}`, `{max}`] InvalidRange { min: i32, max: i32 }, /// invalid merkle proof InvalidMerkleProof, /// invalid child size: `{0}` InvalidChildSize(i32), - /// invalid hash operation: `{0}` - InvalidHashOp(i32), - /// invalid length operation: `{0}` - InvalidLengthOp(i32), /// failed to verify membership FailedToVerifyMembership, } diff --git a/ibc-core/ics23-commitment/types/src/specs.rs b/ibc-core/ics23-commitment/types/src/specs.rs index a37abf6cc..8b4f934a9 100644 --- a/ibc-core/ics23-commitment/types/src/specs.rs +++ b/ibc-core/ics23-commitment/types/src/specs.rs @@ -1,5 +1,6 @@ //! Defines proof specs, which encode the structure of proofs +use ibc_core_host_types::error::DecodingError; use ibc_primitives::prelude::*; use ibc_proto::ics23::{InnerSpec as RawInnerSpec, LeafOp as RawLeafOp, ProofSpec as RawProofSpec}; use ics23::{HashOp, LengthOp}; @@ -129,16 +130,21 @@ struct LeafOp(RawLeafOp); impl TryFrom for LeafOp { type Error = CommitmentError; - fn try_from(leaf_op: RawLeafOp) -> Result { - let _ = HashOp::try_from(leaf_op.hash) - .map_err(|_| CommitmentError::InvalidHashOp(leaf_op.hash))?; - let _ = HashOp::try_from(leaf_op.prehash_key) - .map_err(|_| CommitmentError::InvalidHashOp(leaf_op.prehash_key))?; - let _ = HashOp::try_from(leaf_op.prehash_value) - .map_err(|_| CommitmentError::InvalidHashOp(leaf_op.prehash_value))?; - let _ = LengthOp::try_from(leaf_op.length) - .map_err(|_| CommitmentError::InvalidLengthOp(leaf_op.length))?; + fn try_from(leaf_op: RawLeafOp) -> Result { + let _ = HashOp::try_from(leaf_op.hash).map_err(|e| DecodingError::InvalidHash { + description: format!("hash op {0} is invalid: {e}", leaf_op.hash), + })?; + let _ = HashOp::try_from(leaf_op.prehash_key).map_err(|e| DecodingError::InvalidHash { + description: format!("hash op {0} is invalid: {e}", leaf_op.prehash_key), + })?; + let _ = + HashOp::try_from(leaf_op.prehash_value).map_err(|e| DecodingError::InvalidHash { + description: format!("hash op {0} is invalid: {e}", leaf_op.prehash_value), + })?; + let _ = LengthOp::try_from(leaf_op.length).map_err(|e| DecodingError::InvalidHash { + description: format!("length op {0} is invalid: {e}", leaf_op.length), + })?; Ok(Self(leaf_op)) } } @@ -155,6 +161,7 @@ struct InnerSpec(RawInnerSpec); impl TryFrom for InnerSpec { type Error = CommitmentError; + fn try_from(inner_spec: RawInnerSpec) -> Result { if inner_spec.child_size <= 0 { return Err(CommitmentError::InvalidChildSize(inner_spec.child_size)); From a59e0de2dff19b72776875043fff0a17f382fe6a Mon Sep 17 00:00:00 2001 From: Sean Chen Date: Thu, 5 Sep 2024 09:48:50 -0500 Subject: [PATCH 49/73] Consolidate ConnectionError variants --- .../ics03-connection/types/src/connection.rs | 10 +++- ibc-core/ics03-connection/types/src/error.rs | 14 ----- .../types/src/msgs/conn_open_ack.rs | 60 +++++++++++-------- .../types/src/msgs/conn_open_confirm.rs | 16 +++-- .../ics03-connection/types/src/version.rs | 6 +- 5 files changed, 58 insertions(+), 48 deletions(-) diff --git a/ibc-core/ics03-connection/types/src/connection.rs b/ibc-core/ics03-connection/types/src/connection.rs index 8af322e41..901cf4f5c 100644 --- a/ibc-core/ics03-connection/types/src/connection.rs +++ b/ibc-core/ics03-connection/types/src/connection.rs @@ -4,6 +4,7 @@ use core::fmt::{Display, Error as FmtError, Formatter}; use core::time::Duration; use ibc_core_commitment_types::commitment::CommitmentPrefix; +use ibc_core_host_types::error::DecodingError; use ibc_core_host_types::identifiers::{ClientId, ConnectionId}; use ibc_primitives::prelude::*; use ibc_proto::ibc::core::connection::v1::{ @@ -195,15 +196,20 @@ impl Protobuf for ConnectionEnd {} impl TryFrom for ConnectionEnd { type Error = ConnectionError; + fn try_from(value: RawConnectionEnd) -> Result { let state = value.state.try_into()?; if value.client_id.is_empty() { - return Err(ConnectionError::EmptyProtoConnectionEnd); + return Err(DecodingError::MissingRawData { + description: "connection end is empty".to_string(), + })?; } if value.versions.is_empty() { - return Err(ConnectionError::EmptyVersions); + return Err(DecodingError::MissingRawData { + description: "connection versions is empty".to_string(), + })?; } Self::new( diff --git a/ibc-core/ics03-connection/types/src/error.rs b/ibc-core/ics03-connection/types/src/error.rs index f7ef3426e..d80c0d6a0 100644 --- a/ibc-core/ics03-connection/types/src/error.rs +++ b/ibc-core/ics03-connection/types/src/error.rs @@ -18,18 +18,12 @@ pub enum ConnectionError { Identifier(IdentifierError), /// invalid state for initializing new ConnectionEnd; expected `Init` connection state and a single version InvalidStateForConnectionEndInit, - /// invalid connection proof - InvalidProof, /// invalid counterparty InvalidCounterparty, /// invalid client state: `{description}` InvalidClientState { description: String }, /// mismatched connection states: expected `{expected}`, actual `{actual}` MismatchedConnectionStates { expected: String, actual: String }, - /// empty proto connection end; failed to construct ConnectionEnd domain object - EmptyProtoConnectionEnd, - /// empty supported versions - EmptyVersions, /// empty supported features EmptyFeatures, /// unsupported version \"`{0}`\" @@ -40,14 +34,8 @@ pub enum ConnectionError { MissingCommonVersion, /// missing common features MissingCommonFeatures, - /// missing proof height - MissingProofHeight, - /// missing consensus height - MissingConsensusHeight, /// missing counterparty MissingCounterparty, - /// missing client state - MissingClientState, /// insufficient consensus height `{current_height}` for host chain; needs to meet counterparty's height `{target_height}` InsufficientConsensusHeight { target_height: Height, @@ -98,8 +86,6 @@ impl std::error::Error for ConnectionError { Self::FailedToVerifyConnectionState(e) | Self::FailedToVerifyConsensusState(e) | Self::FailedToVerifyClientState(e) => Some(e), - // Self::InvalidIdentifier(e) => Some(e), - // Self::OverflowedTimestamp(e) => Some(e), _ => None, } } diff --git a/ibc-core/ics03-connection/types/src/msgs/conn_open_ack.rs b/ibc-core/ics03-connection/types/src/msgs/conn_open_ack.rs index 611102f8b..e0675b3ca 100644 --- a/ibc-core/ics03-connection/types/src/msgs/conn_open_ack.rs +++ b/ibc-core/ics03-connection/types/src/msgs/conn_open_ack.rs @@ -1,5 +1,6 @@ use ibc_core_client_types::Height; use ibc_core_commitment_types::commitment::CommitmentProofBytes; +use ibc_core_host_types::error::DecodingError; use ibc_core_host_types::identifiers::ConnectionId; use ibc_primitives::prelude::*; use ibc_primitives::Signer; @@ -54,47 +55,56 @@ impl TryFrom for MsgConnectionOpenAck { conn_id_on_a: msg .connection_id .parse() - .map_err(ConnectionError::Identifier)?, + .map_err(DecodingError::Identifier)?, conn_id_on_b: msg .counterparty_connection_id .parse() - .map_err(ConnectionError::Identifier)?, - client_state_of_a_on_b: msg - .client_state - .ok_or(ConnectionError::MissingClientState)?, + .map_err(DecodingError::Identifier)?, + client_state_of_a_on_b: msg.client_state.ok_or(DecodingError::MissingRawData { + description: "client state not set".to_string(), + })?, version: msg .version - .ok_or(ConnectionError::EmptyVersions)? + .ok_or(DecodingError::MissingRawData { + description: "connection version not set".to_string(), + })? .try_into()?, - proof_conn_end_on_b: msg - .proof_try - .try_into() - .map_err(|_| ConnectionError::InvalidProof)?, - proof_client_state_of_a_on_b: msg - .proof_client - .try_into() - .map_err(|_| ConnectionError::InvalidProof)?, - proof_consensus_state_of_a_on_b: msg - .proof_consensus - .try_into() - .map_err(|_| ConnectionError::InvalidProof)?, + proof_conn_end_on_b: msg.proof_try.try_into().map_err(|e| { + DecodingError::InvalidRawData { + description: format!("failed to decode connection end proof: {e}"), + } + })?, + proof_client_state_of_a_on_b: msg.proof_client.try_into().map_err(|e| { + DecodingError::InvalidRawData { + description: format!("failed to decode client state proof: {e}"), + } + })?, + proof_consensus_state_of_a_on_b: msg.proof_consensus.try_into().map_err(|e| { + DecodingError::InvalidRawData { + description: format!("failed to decode consensus state proof: {e}"), + } + })?, proofs_height_on_b: msg .proof_height .and_then(|raw_height| raw_height.try_into().ok()) - .ok_or(ConnectionError::MissingProofHeight)?, + .ok_or(DecodingError::MissingRawData { + description: "proof height not set".to_string(), + })?, consensus_height_of_a_on_b: msg .consensus_height .and_then(|raw_height| raw_height.try_into().ok()) - .ok_or(ConnectionError::MissingConsensusHeight)?, + .ok_or(DecodingError::MissingRawData { + description: "consensus height not set".to_string(), + })?, signer: msg.signer.into(), proof_consensus_state_of_a: if msg.host_consensus_state_proof.is_empty() { None } else { - Some( - msg.host_consensus_state_proof - .try_into() - .map_err(|_| ConnectionError::InvalidProof)?, - ) + Some(msg.host_consensus_state_proof.try_into().map_err(|e| { + DecodingError::InvalidRawData { + description: format!("failed to decode host consensus state proof: {e}"), + } + })?) }, }) } diff --git a/ibc-core/ics03-connection/types/src/msgs/conn_open_confirm.rs b/ibc-core/ics03-connection/types/src/msgs/conn_open_confirm.rs index 3f534a2d6..0157b9bb7 100644 --- a/ibc-core/ics03-connection/types/src/msgs/conn_open_confirm.rs +++ b/ibc-core/ics03-connection/types/src/msgs/conn_open_confirm.rs @@ -1,5 +1,6 @@ use ibc_core_client_types::Height; use ibc_core_commitment_types::commitment::CommitmentProofBytes; +use ibc_core_host_types::error::DecodingError; use ibc_core_host_types::identifiers::ConnectionId; use ibc_primitives::prelude::*; use ibc_primitives::Signer; @@ -38,15 +39,18 @@ impl TryFrom for MsgConnectionOpenConfirm { conn_id_on_b: msg .connection_id .parse() - .map_err(ConnectionError::Identifier)?, - proof_conn_end_on_a: msg - .proof_ack - .try_into() - .map_err(|_| ConnectionError::InvalidProof)?, + .map_err(DecodingError::Identifier)?, + proof_conn_end_on_a: msg.proof_ack.try_into().map_err(|e| { + DecodingError::InvalidRawData { + description: format!("failed to decode connection end proof: {e}"), + } + })?, proof_height_on_a: msg .proof_height .and_then(|raw_height| raw_height.try_into().ok()) - .ok_or(ConnectionError::MissingProofHeight)?, + .ok_or(DecodingError::InvalidRawData { + description: "failed to decode proof height".to_string(), + })?, signer: msg.signer.into(), }) } diff --git a/ibc-core/ics03-connection/types/src/version.rs b/ibc-core/ics03-connection/types/src/version.rs index aa6f5316a..ac8f9d975 100644 --- a/ibc-core/ics03-connection/types/src/version.rs +++ b/ibc-core/ics03-connection/types/src/version.rs @@ -2,6 +2,7 @@ use core::fmt::Display; +use ibc_core_host_types::error::DecodingError; use ibc_primitives::prelude::*; use ibc_primitives::utils::PrettySlice; use ibc_proto::ibc::core::connection::v1::Version as RawVersion; @@ -72,9 +73,12 @@ impl Protobuf for Version {} impl TryFrom for Version { type Error = ConnectionError; + fn try_from(value: RawVersion) -> Result { if value.identifier.trim().is_empty() { - return Err(ConnectionError::EmptyVersions); + return Err(DecodingError::MissingRawData { + description: "version is empty".to_string(), + })?; } for feature in value.features.iter() { if feature.trim().is_empty() { From a324e760a5b2f04947c111ff48fdd19f4fdde82f Mon Sep 17 00:00:00 2001 From: Sean Chen Date: Thu, 5 Sep 2024 10:19:53 -0500 Subject: [PATCH 50/73] Revert some CommitmentError variants --- ibc-core/ics23-commitment/types/src/error.rs | 4 ++++ ibc-core/ics23-commitment/types/src/specs.rs | 23 ++++++++------------ 2 files changed, 13 insertions(+), 14 deletions(-) diff --git a/ibc-core/ics23-commitment/types/src/error.rs b/ibc-core/ics23-commitment/types/src/error.rs index 3b6d09927..c367a0817 100644 --- a/ibc-core/ics23-commitment/types/src/error.rs +++ b/ibc-core/ics23-commitment/types/src/error.rs @@ -28,6 +28,10 @@ pub enum CommitmentError { InvalidMerkleProof, /// invalid child size: `{0}` InvalidChildSize(i32), + /// invalid hash operation: `{0}` + InvalidHashOp(i32), + /// invalid length operation: `{0}` + InvalidLengthOp(i32), /// failed to verify membership FailedToVerifyMembership, } diff --git a/ibc-core/ics23-commitment/types/src/specs.rs b/ibc-core/ics23-commitment/types/src/specs.rs index 8b4f934a9..d163c6bf8 100644 --- a/ibc-core/ics23-commitment/types/src/specs.rs +++ b/ibc-core/ics23-commitment/types/src/specs.rs @@ -1,6 +1,5 @@ //! Defines proof specs, which encode the structure of proofs -use ibc_core_host_types::error::DecodingError; use ibc_primitives::prelude::*; use ibc_proto::ics23::{InnerSpec as RawInnerSpec, LeafOp as RawLeafOp, ProofSpec as RawProofSpec}; use ics23::{HashOp, LengthOp}; @@ -132,19 +131,15 @@ impl TryFrom for LeafOp { type Error = CommitmentError; fn try_from(leaf_op: RawLeafOp) -> Result { - let _ = HashOp::try_from(leaf_op.hash).map_err(|e| DecodingError::InvalidHash { - description: format!("hash op {0} is invalid: {e}", leaf_op.hash), - })?; - let _ = HashOp::try_from(leaf_op.prehash_key).map_err(|e| DecodingError::InvalidHash { - description: format!("hash op {0} is invalid: {e}", leaf_op.prehash_key), - })?; - let _ = - HashOp::try_from(leaf_op.prehash_value).map_err(|e| DecodingError::InvalidHash { - description: format!("hash op {0} is invalid: {e}", leaf_op.prehash_value), - })?; - let _ = LengthOp::try_from(leaf_op.length).map_err(|e| DecodingError::InvalidHash { - description: format!("length op {0} is invalid: {e}", leaf_op.length), - })?; + let _ = HashOp::try_from(leaf_op.hash) + .map_err(|_| CommitmentError::InvalidHashOp(leaf_op.hash))?; + let _ = HashOp::try_from(leaf_op.prehash_key) + .map_err(|_| CommitmentError::InvalidHashOp(leaf_op.prehash_key))?; + let _ = HashOp::try_from(leaf_op.prehash_value) + .map_err(|_| CommitmentError::InvalidHashOp(leaf_op.prehash_value))?; + let _ = LengthOp::try_from(leaf_op.length) + .map_err(|_| CommitmentError::InvalidLengthOp(leaf_op.length))?; + Ok(Self(leaf_op)) } } From 5b37bd53f4959b6fe5f45786f4eccdc751f21fa8 Mon Sep 17 00:00:00 2001 From: Sean Chen Date: Thu, 5 Sep 2024 13:28:09 -0500 Subject: [PATCH 51/73] Change TryFrom for MsgEnvelope Error type to DecodingError --- ibc-core/ics25-handler/types/src/msgs.rs | 57 ++++++++---------------- 1 file changed, 19 insertions(+), 38 deletions(-) diff --git a/ibc-core/ics25-handler/types/src/msgs.rs b/ibc-core/ics25-handler/types/src/msgs.rs index b2a34c773..a47a9b702 100644 --- a/ibc-core/ics25-handler/types/src/msgs.rs +++ b/ibc-core/ics25-handler/types/src/msgs.rs @@ -18,7 +18,6 @@ use ibc_core_connection_types::msgs::{ CONN_OPEN_INIT_TYPE_URL, CONN_OPEN_TRY_TYPE_URL, }; use ibc_core_host_types::error::DecodingError; -use ibc_core_router_types::error::RouterError; use ibc_primitives::prelude::*; use ibc_proto::google::protobuf::Any; use ibc_proto::Protobuf; @@ -39,52 +38,44 @@ pub enum MsgEnvelope { #[allow(deprecated)] impl TryFrom for MsgEnvelope { - type Error = RouterError; + type Error = DecodingError; fn try_from(any_msg: Any) -> Result { match any_msg.type_url.as_str() { // ICS2 messages CREATE_CLIENT_TYPE_URL => { // Pop out the message and then wrap it in the corresponding type. - let domain_msg = - MsgCreateClient::decode_vec(&any_msg.value).map_err(DecodingError::Protobuf)?; + let domain_msg = MsgCreateClient::decode_vec(&any_msg.value)?; Ok(MsgEnvelope::Client(ClientMsg::CreateClient(domain_msg))) } UPDATE_CLIENT_TYPE_URL => { - let domain_msg = - MsgUpdateClient::decode_vec(&any_msg.value).map_err(DecodingError::Protobuf)?; + let domain_msg = MsgUpdateClient::decode_vec(&any_msg.value)?; Ok(MsgEnvelope::Client(ClientMsg::UpdateClient(domain_msg))) } UPGRADE_CLIENT_TYPE_URL => { - let domain_msg = MsgUpgradeClient::decode_vec(&any_msg.value) - .map_err(DecodingError::Protobuf)?; + let domain_msg = MsgUpgradeClient::decode_vec(&any_msg.value)?; Ok(MsgEnvelope::Client(ClientMsg::UpgradeClient(domain_msg))) } SUBMIT_MISBEHAVIOUR_TYPE_URL => { - let domain_msg = MsgSubmitMisbehaviour::decode_vec(&any_msg.value) - .map_err(DecodingError::Protobuf)?; + let domain_msg = MsgSubmitMisbehaviour::decode_vec(&any_msg.value)?; Ok(MsgEnvelope::Client(ClientMsg::Misbehaviour(domain_msg))) } // ICS03 CONN_OPEN_INIT_TYPE_URL => { - let domain_msg = MsgConnectionOpenInit::decode_vec(&any_msg.value) - .map_err(DecodingError::Protobuf)?; + let domain_msg = MsgConnectionOpenInit::decode_vec(&any_msg.value)?; Ok(MsgEnvelope::Connection(ConnectionMsg::OpenInit(domain_msg))) } CONN_OPEN_TRY_TYPE_URL => { - let domain_msg = MsgConnectionOpenTry::decode_vec(&any_msg.value) - .map_err(DecodingError::Protobuf)?; + let domain_msg = MsgConnectionOpenTry::decode_vec(&any_msg.value)?; Ok(MsgEnvelope::Connection(ConnectionMsg::OpenTry(domain_msg))) } CONN_OPEN_ACK_TYPE_URL => { - let domain_msg = MsgConnectionOpenAck::decode_vec(&any_msg.value) - .map_err(DecodingError::Protobuf)?; + let domain_msg = MsgConnectionOpenAck::decode_vec(&any_msg.value)?; Ok(MsgEnvelope::Connection(ConnectionMsg::OpenAck(domain_msg))) } CONN_OPEN_CONFIRM_TYPE_URL => { - let domain_msg = MsgConnectionOpenConfirm::decode_vec(&any_msg.value) - .map_err(DecodingError::Protobuf)?; + let domain_msg = MsgConnectionOpenConfirm::decode_vec(&any_msg.value)?; Ok(MsgEnvelope::Connection(ConnectionMsg::OpenConfirm( domain_msg, ))) @@ -92,54 +83,44 @@ impl TryFrom for MsgEnvelope { // ICS04 channel messages CHAN_OPEN_INIT_TYPE_URL => { - let domain_msg = MsgChannelOpenInit::decode_vec(&any_msg.value) - .map_err(DecodingError::Protobuf)?; + let domain_msg = MsgChannelOpenInit::decode_vec(&any_msg.value)?; Ok(MsgEnvelope::Channel(ChannelMsg::OpenInit(domain_msg))) } CHAN_OPEN_TRY_TYPE_URL => { - let domain_msg = MsgChannelOpenTry::decode_vec(&any_msg.value) - .map_err(DecodingError::Protobuf)?; + let domain_msg = MsgChannelOpenTry::decode_vec(&any_msg.value)?; Ok(MsgEnvelope::Channel(ChannelMsg::OpenTry(domain_msg))) } CHAN_OPEN_ACK_TYPE_URL => { - let domain_msg = MsgChannelOpenAck::decode_vec(&any_msg.value) - .map_err(DecodingError::Protobuf)?; + let domain_msg = MsgChannelOpenAck::decode_vec(&any_msg.value)?; Ok(MsgEnvelope::Channel(ChannelMsg::OpenAck(domain_msg))) } CHAN_OPEN_CONFIRM_TYPE_URL => { - let domain_msg = MsgChannelOpenConfirm::decode_vec(&any_msg.value) - .map_err(DecodingError::Protobuf)?; + let domain_msg = MsgChannelOpenConfirm::decode_vec(&any_msg.value)?; Ok(MsgEnvelope::Channel(ChannelMsg::OpenConfirm(domain_msg))) } CHAN_CLOSE_INIT_TYPE_URL => { - let domain_msg = MsgChannelCloseInit::decode_vec(&any_msg.value) - .map_err(DecodingError::Protobuf)?; + let domain_msg = MsgChannelCloseInit::decode_vec(&any_msg.value)?; Ok(MsgEnvelope::Channel(ChannelMsg::CloseInit(domain_msg))) } CHAN_CLOSE_CONFIRM_TYPE_URL => { - let domain_msg = MsgChannelCloseConfirm::decode_vec(&any_msg.value) - .map_err(DecodingError::Protobuf)?; + let domain_msg = MsgChannelCloseConfirm::decode_vec(&any_msg.value)?; Ok(MsgEnvelope::Channel(ChannelMsg::CloseConfirm(domain_msg))) } // ICS04 packet messages RECV_PACKET_TYPE_URL => { - let domain_msg = - MsgRecvPacket::decode_vec(&any_msg.value).map_err(DecodingError::Protobuf)?; + let domain_msg = MsgRecvPacket::decode_vec(&any_msg.value)?; Ok(MsgEnvelope::Packet(PacketMsg::Recv(domain_msg))) } ACKNOWLEDGEMENT_TYPE_URL => { - let domain_msg = MsgAcknowledgement::decode_vec(&any_msg.value) - .map_err(DecodingError::Protobuf)?; + let domain_msg = MsgAcknowledgement::decode_vec(&any_msg.value)?; Ok(MsgEnvelope::Packet(PacketMsg::Ack(domain_msg))) } TIMEOUT_TYPE_URL => { - let domain_msg = - MsgTimeout::decode_vec(&any_msg.value).map_err(DecodingError::Protobuf)?; + let domain_msg = MsgTimeout::decode_vec(&any_msg.value)?; Ok(MsgEnvelope::Packet(PacketMsg::Timeout(domain_msg))) } TIMEOUT_ON_CLOSE_TYPE_URL => { - let domain_msg = MsgTimeoutOnClose::decode_vec(&any_msg.value) - .map_err(DecodingError::Protobuf)?; + let domain_msg = MsgTimeoutOnClose::decode_vec(&any_msg.value)?; Ok(MsgEnvelope::Packet(PacketMsg::TimeoutOnClose(domain_msg))) } From bd0e5cf3b2b032a16991e3b2c37dd7a1526149ca Mon Sep 17 00:00:00 2001 From: Sean Chen Date: Fri, 6 Sep 2024 09:36:24 -0500 Subject: [PATCH 52/73] Remove ConnectionError::Identifier variant in favor of DecodingError::Identifier --- .../ics03-connection/types/src/connection.rs | 19 ++++++++++--------- ibc-core/ics03-connection/types/src/error.rs | 4 +--- .../types/src/msgs/conn_open_init.rs | 7 +++++-- 3 files changed, 16 insertions(+), 14 deletions(-) diff --git a/ibc-core/ics03-connection/types/src/connection.rs b/ibc-core/ics03-connection/types/src/connection.rs index 901cf4f5c..b9f64b48c 100644 --- a/ibc-core/ics03-connection/types/src/connection.rs +++ b/ibc-core/ics03-connection/types/src/connection.rs @@ -68,7 +68,7 @@ impl TryFrom for IdentifiedConnectionEnd { }; Ok(IdentifiedConnectionEnd { - connection_id: value.id.parse().map_err(ConnectionError::Identifier)?, + connection_id: value.id.parse().map_err(DecodingError::Identifier)?, connection_end: raw_connection_end.try_into()?, }) } @@ -214,13 +214,12 @@ impl TryFrom for ConnectionEnd { Self::new( state, - value - .client_id - .parse() - .map_err(ConnectionError::Identifier)?, + value.client_id.parse().map_err(DecodingError::Identifier)?, value .counterparty - .ok_or(ConnectionError::MissingCounterparty)? + .ok_or(DecodingError::MissingRawData { + description: "counterparty not set".to_string(), + })? .try_into()?, value .versions @@ -381,18 +380,20 @@ impl TryFrom for Counterparty { raw_counterparty .connection_id .parse() - .map_err(ConnectionError::Identifier)?, + .map_err(DecodingError::Identifier)?, ) }; Ok(Counterparty::new( raw_counterparty .client_id .parse() - .map_err(ConnectionError::Identifier)?, + .map_err(DecodingError::Identifier)?, connection_id, raw_counterparty .prefix - .ok_or(ConnectionError::MissingCounterparty)? + .ok_or(DecodingError::MissingRawData { + description: "counterparty prefix not set".to_string(), + })? .key_prefix .into(), )) diff --git a/ibc-core/ics03-connection/types/src/error.rs b/ibc-core/ics03-connection/types/src/error.rs index d80c0d6a0..d06c64b35 100644 --- a/ibc-core/ics03-connection/types/src/error.rs +++ b/ibc-core/ics03-connection/types/src/error.rs @@ -3,7 +3,7 @@ use displaydoc::Display; use ibc_core_client_types::error::ClientError; use ibc_core_client_types::Height; -use ibc_core_host_types::error::{DecodingError, IdentifierError}; +use ibc_core_host_types::error::DecodingError; use ibc_core_host_types::identifiers::ConnectionId; use ibc_primitives::prelude::*; use ibc_primitives::{Timestamp, TimestampError}; @@ -14,8 +14,6 @@ use crate::version::Version; pub enum ConnectionError { /// decoding error: `{0}` Decoding(DecodingError), - /// identifier error: `{0}` - Identifier(IdentifierError), /// invalid state for initializing new ConnectionEnd; expected `Init` connection state and a single version InvalidStateForConnectionEndInit, /// invalid counterparty diff --git a/ibc-core/ics03-connection/types/src/msgs/conn_open_init.rs b/ibc-core/ics03-connection/types/src/msgs/conn_open_init.rs index eed8736a3..cd7a0e620 100644 --- a/ibc-core/ics03-connection/types/src/msgs/conn_open_init.rs +++ b/ibc-core/ics03-connection/types/src/msgs/conn_open_init.rs @@ -1,5 +1,6 @@ use core::time::Duration; +use ibc_core_host_types::error::DecodingError; use ibc_core_host_types::identifiers::ClientId; use ibc_primitives::prelude::*; use ibc_primitives::Signer; @@ -89,13 +90,15 @@ impl TryFrom for MsgConnectionOpenInit { fn try_from(msg: RawMsgConnectionOpenInit) -> Result { let counterparty: Counterparty = msg .counterparty - .ok_or(ConnectionError::MissingCounterparty)? + .ok_or(DecodingError::MissingRawData { + description: "counterparty not set".to_string(), + })? .try_into()?; counterparty.verify_empty_connection_id()?; Ok(Self { - client_id_on_a: msg.client_id.parse().map_err(ConnectionError::Identifier)?, + client_id_on_a: msg.client_id.parse().map_err(DecodingError::Identifier)?, counterparty, version: msg.version.map(TryInto::try_into).transpose()?, delay_period: Duration::from_nanos(msg.delay_period), From fba4f7b4493ab3cde004425cd7deb3203ac25d68 Mon Sep 17 00:00:00 2001 From: Sean Chen Date: Fri, 6 Sep 2024 09:38:17 -0500 Subject: [PATCH 53/73] Remove ChannelError::Identifier variant in favor of DecodingError::Identifier --- ibc-core/ics04-channel/types/src/error.rs | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/ibc-core/ics04-channel/types/src/error.rs b/ibc-core/ics04-channel/types/src/error.rs index abf150b13..6a7af2e88 100644 --- a/ibc-core/ics04-channel/types/src/error.rs +++ b/ibc-core/ics04-channel/types/src/error.rs @@ -18,8 +18,6 @@ use crate::Version; pub enum ChannelError { /// decoding error: `{0}` Decoding(DecodingError), - /// identifier error: `{0}` - Identifier(IdentifierError), /// invalid channel id: expected `{expected}`, actual `{actual}` InvalidChannelId { expected: String, actual: String }, /// invalid channel state: expected `{expected}`, actual `{actual}` @@ -127,7 +125,7 @@ pub enum PacketError { impl From for ChannelError { fn from(e: IdentifierError) -> Self { - Self::Identifier(e) + Self::Decoding(DecodingError::Identifier(e)) } } @@ -171,7 +169,6 @@ impl std::error::Error for PacketError { impl std::error::Error for ChannelError { fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { match &self { - Self::Identifier(e) => Some(e), Self::Decoding(e) => Some(e), Self::FailedPacketVerification { client_error: e, .. From c309dd2605fd800c4029d41317072c0013f08167 Mon Sep 17 00:00:00 2001 From: Sean Chen Date: Fri, 6 Sep 2024 09:48:34 -0500 Subject: [PATCH 54/73] Remove PacketError::Identifier variant in favor of DecodingError::Identifier --- ibc-core/ics04-channel/types/src/error.rs | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/ibc-core/ics04-channel/types/src/error.rs b/ibc-core/ics04-channel/types/src/error.rs index 6a7af2e88..4e0551e66 100644 --- a/ibc-core/ics04-channel/types/src/error.rs +++ b/ibc-core/ics04-channel/types/src/error.rs @@ -96,8 +96,6 @@ pub enum PacketError { InvalidTimeoutHeight(ClientError), /// invalid timeout timestamp: `{0}` InvalidTimeoutTimestamp(TimestampError), - /// identifier error: `{0}` - Identifier(IdentifierError), /// empty acknowledgment status not allowed EmptyAcknowledgmentStatus, /// packet acknowledgment for sequence `{0}` already exists @@ -111,8 +109,6 @@ pub enum PacketError { timeout_timestamp: TimeoutTimestamp, chain_timestamp: Timestamp, }, - /// implementation-specific error - ImplementationSpecific, // TODO(seanchen1991): Move these variants to host-relevant error types /// application module error: `{description}` @@ -121,6 +117,8 @@ pub enum PacketError { MissingPacketAcknowledgment(Sequence), /// missing packet receipt for packet `{0}` MissingPacketReceipt(Sequence), + /// implementation-specific error + ImplementationSpecific, } impl From for ChannelError { @@ -131,7 +129,7 @@ impl From for ChannelError { impl From for PacketError { fn from(e: IdentifierError) -> Self { - Self::Identifier(e) + Self::Decoding(DecodingError::Identifier(e)) } } @@ -159,7 +157,6 @@ impl std::error::Error for PacketError { match &self { Self::Channel(e) => Some(e), Self::Decoding(e) => Some(e), - Self::Identifier(e) => Some(e), _ => None, } } From 9f26de70d855f7714479a71aa1846b9c032a99f7 Mon Sep 17 00:00:00 2001 From: Sean Chen Date: Fri, 6 Sep 2024 10:06:20 -0500 Subject: [PATCH 55/73] Revert TokenTransferError FailedToDeserializeAck and FailedToDeserializePacketData --- ibc-apps/ics20-transfer/src/module.rs | 21 +++++---------------- ibc-apps/ics20-transfer/types/src/error.rs | 4 ++++ 2 files changed, 9 insertions(+), 16 deletions(-) diff --git a/ibc-apps/ics20-transfer/src/module.rs b/ibc-apps/ics20-transfer/src/module.rs index e493760e6..520404c18 100644 --- a/ibc-apps/ics20-transfer/src/module.rs +++ b/ibc-apps/ics20-transfer/src/module.rs @@ -208,16 +208,11 @@ pub fn on_acknowledgement_packet_validate( where Ctx: TokenTransferValidationContext, { - let data = serde_json::from_slice::(&packet.data).map_err(|e| { - DecodingError::InvalidJson { - description: format!("failed to deserialize packet data: {e}"), - } - })?; + let data = serde_json::from_slice::(&packet.data) + .map_err(|_| TokenTransferError::FailedToDeserializePacketData)?; let acknowledgement = serde_json::from_slice::(acknowledgement.as_ref()) - .map_err(|e| DecodingError::InvalidJson { - description: format!("failed to deserialize acknowledgment status: {e}"), - })?; + .map_err(|_| TokenTransferError::FailedToDeserializeAck)?; if !acknowledgement.is_successful() { refund_packet_token_validate(ctx, packet, &data)?; @@ -235,10 +230,7 @@ pub fn on_acknowledgement_packet_execute( let Ok(data) = serde_json::from_slice::(&packet.data) else { return ( ModuleExtras::empty(), - Err(DecodingError::InvalidJson { - description: "failed to deserialize packet data".to_string(), - } - .into()), + Err(TokenTransferError::FailedToDeserializePacketData), ); }; @@ -247,10 +239,7 @@ pub fn on_acknowledgement_packet_execute( else { return ( ModuleExtras::empty(), - Err(DecodingError::InvalidJson { - description: "failed to deserialize acknowledgment status".to_string(), - } - .into()), + Err(TokenTransferError::FailedToDeserializeAck), ); }; diff --git a/ibc-apps/ics20-transfer/types/src/error.rs b/ibc-apps/ics20-transfer/types/src/error.rs index 43150c0cb..da26a2f8b 100644 --- a/ibc-apps/ics20-transfer/types/src/error.rs +++ b/ibc-apps/ics20-transfer/types/src/error.rs @@ -39,6 +39,10 @@ pub enum TokenTransferError { UnsupportedClosedChannel, /// empty base denomination EmptyBaseDenom, + /// failed to deserialize packet data + FailedToDeserializePacketData, + /// failed to deserialize acknowledgement + FailedToDeserializeAck, // TODO(seanchen1991): Used in basecoin; this variant should be moved // to a host-relevant error From 99c6c9e13819a7f1f816ad3a03feacfafac95a31 Mon Sep 17 00:00:00 2001 From: Sean Chen Date: Fri, 6 Sep 2024 10:14:51 -0500 Subject: [PATCH 56/73] Revert NftTransferError FailedToDeserializeAck and FailedToDeserializePacketData --- ibc-apps/ics721-nft-transfer/src/module.rs | 21 +++++-------------- .../ics721-nft-transfer/types/src/error.rs | 4 ++++ 2 files changed, 9 insertions(+), 16 deletions(-) diff --git a/ibc-apps/ics721-nft-transfer/src/module.rs b/ibc-apps/ics721-nft-transfer/src/module.rs index 8b1ffef0f..e0f3a4346 100644 --- a/ibc-apps/ics721-nft-transfer/src/module.rs +++ b/ibc-apps/ics721-nft-transfer/src/module.rs @@ -209,16 +209,11 @@ pub fn on_acknowledgement_packet_validate( acknowledgement: &Acknowledgement, _relayer: &Signer, ) -> Result<(), NftTransferError> { - let data = serde_json::from_slice::(&packet.data).map_err(|e| { - DecodingError::InvalidJson { - description: format!("failed to deserialize packet data: {e}"), - } - })?; + let data = serde_json::from_slice::(&packet.data) + .map_err(|_| NftTransferError::FailedToDeserializePacketData)?; let acknowledgement = serde_json::from_slice::(acknowledgement.as_ref()) - .map_err(|e| DecodingError::InvalidJson { - description: format!("failed to deserialize acknowledgment: {e}"), - })?; + .map_err(|__| NftTransferError::FailedToDeserializeAck)?; if !acknowledgement.is_successful() { refund_packet_nft_validate(ctx, packet, &data)?; @@ -236,10 +231,7 @@ pub fn on_acknowledgement_packet_execute( let Ok(data) = serde_json::from_slice::(&packet.data) else { return ( ModuleExtras::empty(), - Err(DecodingError::InvalidJson { - description: "failed to deserialize packet data".to_string(), - } - .into()), + Err(NftTransferError::FailedToDeserializePacketData), ); }; @@ -248,10 +240,7 @@ pub fn on_acknowledgement_packet_execute( else { return ( ModuleExtras::empty(), - Err(DecodingError::InvalidJson { - description: "failed to deserialize acknowledgment".to_string(), - } - .into()), + Err(NftTransferError::FailedToDeserializeAck), ); }; diff --git a/ibc-apps/ics721-nft-transfer/types/src/error.rs b/ibc-apps/ics721-nft-transfer/types/src/error.rs index 2e7456b5b..6826f4a58 100644 --- a/ibc-apps/ics721-nft-transfer/types/src/error.rs +++ b/ibc-apps/ics721-nft-transfer/types/src/error.rs @@ -37,6 +37,10 @@ pub enum NftTransferError { MismatchedChannelOrders { expected: Order, actual: Order }, /// mismatched port IDs: expected `{expected}`, actual `{actual}` MismatchedPortIds { expected: PortId, actual: PortId }, + /// failed to deserialize packet data + FailedToDeserializePacketData, + /// failed to deserialize acknowledgement + FailedToDeserializeAck, /// failed to parse account ID FailedToParseAccount, /// channel cannot be closed From 1106e5f383bbd9e221e7e7e1b79b073119fcc39f Mon Sep 17 00:00:00 2001 From: Sean Chen Date: Fri, 6 Sep 2024 10:22:37 -0500 Subject: [PATCH 57/73] Revert ics20 and ics721 on_recv_packet_execute impls --- ibc-apps/ics20-transfer/src/module.rs | 8 ++------ ibc-apps/ics721-nft-transfer/src/module.rs | 8 ++------ 2 files changed, 4 insertions(+), 12 deletions(-) diff --git a/ibc-apps/ics20-transfer/src/module.rs b/ibc-apps/ics20-transfer/src/module.rs index 520404c18..e6c82a2a3 100644 --- a/ibc-apps/ics20-transfer/src/module.rs +++ b/ibc-apps/ics20-transfer/src/module.rs @@ -172,12 +172,8 @@ pub fn on_recv_packet_execute( packet: &Packet, ) -> (ModuleExtras, Acknowledgement) { let Ok(data) = serde_json::from_slice::(&packet.data) else { - let ack = AcknowledgementStatus::error( - DecodingError::InvalidJson { - description: "failed to deserialize packet data".to_string(), - } - .into(), - ); + let ack = + AcknowledgementStatus::error(TokenTransferError::FailedToDeserializePacketData.into()); return (ModuleExtras::empty(), ack.into()); }; diff --git a/ibc-apps/ics721-nft-transfer/src/module.rs b/ibc-apps/ics721-nft-transfer/src/module.rs index e0f3a4346..30269c8ba 100644 --- a/ibc-apps/ics721-nft-transfer/src/module.rs +++ b/ibc-apps/ics721-nft-transfer/src/module.rs @@ -173,12 +173,8 @@ pub fn on_recv_packet_execute( packet: &Packet, ) -> (ModuleExtras, Acknowledgement) { let Ok(data) = serde_json::from_slice::(&packet.data) else { - let ack = AcknowledgementStatus::error( - DecodingError::InvalidJson { - description: "failed to deserialize packet data".to_string(), - } - .into(), - ); + let ack = + AcknowledgementStatus::error(NftTransferError::FailedToDeserializePacketData.into()); return (ModuleExtras::empty(), ack.into()); }; From 03a6d0102fe254321b8f05fb1330da970398c7f9 Mon Sep 17 00:00:00 2001 From: Sean Chen Date: Fri, 6 Sep 2024 10:29:43 -0500 Subject: [PATCH 58/73] Remove additional Identifier error variants --- ibc-apps/ics20-transfer/types/src/error.rs | 5 +---- ibc-clients/ics07-tendermint/types/src/error.rs | 5 +---- 2 files changed, 2 insertions(+), 8 deletions(-) diff --git a/ibc-apps/ics20-transfer/types/src/error.rs b/ibc-apps/ics20-transfer/types/src/error.rs index da26a2f8b..15efb347f 100644 --- a/ibc-apps/ics20-transfer/types/src/error.rs +++ b/ibc-apps/ics20-transfer/types/src/error.rs @@ -16,8 +16,6 @@ pub enum TokenTransferError { ContextError(ContextError), /// decoding error: `{0}` Decoding(DecodingError), - /// identifier error: `{0}` - Identifier(IdentifierError), /// invalid amount: `{0}` InvalidAmount(FromDecStrErr), /// invalid coin: `{0}` @@ -55,7 +53,6 @@ impl std::error::Error for TokenTransferError { fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { match &self { Self::ContextError(e) => Some(e), - Self::Identifier(e) => Some(e), Self::InvalidAmount(e) => Some(e), Self::Decoding(e) => Some(e), _ => None, @@ -77,7 +74,7 @@ impl From for TokenTransferError { impl From for TokenTransferError { fn from(e: IdentifierError) -> Self { - Self::Identifier(e) + Self::Decoding(DecodingError::Identifier(e)) } } diff --git a/ibc-clients/ics07-tendermint/types/src/error.rs b/ibc-clients/ics07-tendermint/types/src/error.rs index f09c74748..3252fdcf8 100644 --- a/ibc-clients/ics07-tendermint/types/src/error.rs +++ b/ibc-clients/ics07-tendermint/types/src/error.rs @@ -18,8 +18,6 @@ use tendermint_light_client_verifier::Verdict; pub enum TendermintClientError { /// decoding error: `{0}` Decoding(DecodingError), - /// identifier error: `{0}` - Identifier(IdentifierError), /// invalid client state trust threshold: `{description}` InvalidTrustThreshold { description: String }, /// invalid clock drift; must be greater than 0 @@ -55,7 +53,6 @@ pub enum TendermintClientError { impl std::error::Error for TendermintClientError { fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { match &self { - Self::Identifier(e) => Some(e), Self::Decoding(e) => Some(e), _ => None, } @@ -74,7 +71,7 @@ impl From for ClientError { impl From for TendermintClientError { fn from(e: IdentifierError) -> Self { - Self::Identifier(e) + Self::Decoding(DecodingError::Identifier(e)) } } From 47562b49f604f4aa306a4c67557881dda5ef2816 Mon Sep 17 00:00:00 2001 From: Sean Chen Date: Fri, 6 Sep 2024 10:49:12 -0500 Subject: [PATCH 59/73] Add TendermintClientError::InsufficientMisbehaviourHeaderHeight variant --- .../ics07-tendermint/types/src/error.rs | 5 +++-- .../ics07-tendermint/types/src/misbehaviour.rs | 18 +++++++++--------- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/ibc-clients/ics07-tendermint/types/src/error.rs b/ibc-clients/ics07-tendermint/types/src/error.rs index 3252fdcf8..2090797d7 100644 --- a/ibc-clients/ics07-tendermint/types/src/error.rs +++ b/ibc-clients/ics07-tendermint/types/src/error.rs @@ -4,6 +4,7 @@ use core::time::Duration; use displaydoc::Display; use ibc_core_client_types::error::ClientError; +use ibc_core_client_types::Height; use ibc_core_commitment_types::error::CommitmentError; use ibc_core_host_types::error::{DecodingError, IdentifierError}; use ibc_primitives::prelude::*; @@ -24,8 +25,6 @@ pub enum TendermintClientError { InvalidMaxClockDrift, /// invalid client proof specs: `{0}` InvalidProofSpec(CommitmentError), - /// invalid raw misbehaviour: `{description}` - InvalidRawMisbehaviour { description: String }, /// invalid header timestamp: `{0}` InvalidHeaderTimestamp(TimestampError), /// invalid header height: `{0}` @@ -47,6 +46,8 @@ pub enum TendermintClientError { duration_since_consensus_state: Duration, trusting_period: Duration, }, + /// insufficient misbehaviour header height: header1 height `{height_1}` shoul be >= header2 height `{height_2}` + InsufficientMisbehaviourHeaderHeight { height_1: Height, height_2: Height }, } #[cfg(feature = "std")] diff --git a/ibc-clients/ics07-tendermint/types/src/misbehaviour.rs b/ibc-clients/ics07-tendermint/types/src/misbehaviour.rs index b49f0a328..17de928e7 100644 --- a/ibc-clients/ics07-tendermint/types/src/misbehaviour.rs +++ b/ibc-clients/ics07-tendermint/types/src/misbehaviour.rs @@ -53,19 +53,19 @@ impl Misbehaviour { if self.header1.signed_header.header.chain_id != self.header2.signed_header.header.chain_id { - return Err(TendermintClientError::InvalidRawMisbehaviour { - description: "headers must have identical chain_ids".to_owned(), + return Err(TendermintClientError::MismatchedHeaderChainIds { + expected: self.header1.signed_header.header.chain_id.to_string(), + actual: self.header2.signed_header.header.chain_id.to_string(), }); } if self.header1.height() < self.header2.height() { - return Err(TendermintClientError::InvalidRawMisbehaviour { - description: format!( - "header1 height is less than header2 height ({} < {})", - self.header1.height(), - self.header2.height() - ), - }); + return Err( + TendermintClientError::InsufficientMisbehaviourHeaderHeight { + height_1: self.header1.height(), + height_2: self.header2.height(), + }, + ); } Ok(()) From b7eb7873b9e63ffb04063d83736761c25ce6dbfd Mon Sep 17 00:00:00 2001 From: Sean Chen Date: Fri, 6 Sep 2024 11:01:22 -0500 Subject: [PATCH 60/73] Implement From for ClientError and ConnectionError --- .../types/src/msgs/migrate_contract.rs | 2 +- ibc-core/ics02-client/types/src/error.rs | 10 ++++++++++ .../ics02-client/types/src/msgs/misbehaviour.rs | 2 +- .../types/src/msgs/recover_client.rs | 11 ++--------- .../ics02-client/types/src/msgs/update_client.rs | 2 +- .../types/src/msgs/upgrade_client.rs | 3 +-- .../ics03-connection/types/src/connection.rs | 16 ++++------------ ibc-core/ics03-connection/types/src/error.rs | 8 +++++++- .../types/src/msgs/conn_open_ack.rs | 10 ++-------- .../types/src/msgs/conn_open_confirm.rs | 5 +---- .../types/src/msgs/conn_open_init.rs | 2 +- .../types/src/msgs/conn_open_try.rs | 2 +- 12 files changed, 32 insertions(+), 41 deletions(-) diff --git a/ibc-clients/ics08-wasm/types/src/msgs/migrate_contract.rs b/ibc-clients/ics08-wasm/types/src/msgs/migrate_contract.rs index 6a8e860e3..3f7bc6a93 100644 --- a/ibc-clients/ics08-wasm/types/src/msgs/migrate_contract.rs +++ b/ibc-clients/ics08-wasm/types/src/msgs/migrate_contract.rs @@ -39,7 +39,7 @@ impl TryFrom for MsgMigrateContract { fn try_from(value: RawMsgMigrateContract) -> Result { Ok(Self { signer: Signer::from(value.signer), - client_id: ClientId::from_str(&value.client_id).map_err(DecodingError::Identifier)?, + client_id: ClientId::from_str(&value.client_id)?, checksum: value.checksum, msg: value.msg, }) diff --git a/ibc-core/ics02-client/types/src/error.rs b/ibc-core/ics02-client/types/src/error.rs index 26aeb03dd..9c5d23b5f 100644 --- a/ibc-core/ics02-client/types/src/error.rs +++ b/ibc-core/ics02-client/types/src/error.rs @@ -5,6 +5,7 @@ use core::convert::Infallible; use displaydoc::Display; use ibc_core_commitment_types::error::CommitmentError; use ibc_core_host_types::error::DecodingError; +use ibc_core_host_types::error::IdentifierError; use ibc_core_host_types::identifiers::ClientId; use ibc_primitives::prelude::*; use ibc_primitives::Timestamp; @@ -20,6 +21,8 @@ pub enum ClientError { Upgrade(UpgradeClientError), /// decoding error: `{0}` Decoding(DecodingError), + /// identifier error: `{0}` + Identifier(IdentifierError), /// invalid trust threshold: `{numerator}`/`{denominator}` InvalidTrustThreshold { numerator: u64, denominator: u64 }, /// invalid client state type: `{0}` @@ -106,11 +109,18 @@ impl From for ClientError { } } +impl From for ClientError { + fn from(e: IdentifierError) -> Self { + Self::Identifier(e) + } +} + #[cfg(feature = "std")] impl std::error::Error for ClientError { fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { match &self { Self::FailedICS23Verification(e) => Some(e), + Self::Identifier(e) => Some(e), Self::Decoding(e) => Some(e), _ => None, } diff --git a/ibc-core/ics02-client/types/src/msgs/misbehaviour.rs b/ibc-core/ics02-client/types/src/msgs/misbehaviour.rs index dac0eb62e..dd627ae02 100644 --- a/ibc-core/ics02-client/types/src/msgs/misbehaviour.rs +++ b/ibc-core/ics02-client/types/src/msgs/misbehaviour.rs @@ -46,7 +46,7 @@ impl TryFrom for MsgSubmitMisbehaviour { })?; Ok(MsgSubmitMisbehaviour { - client_id: raw.client_id.parse().map_err(DecodingError::Identifier)?, + client_id: raw.client_id.parse()?, misbehaviour: raw_misbehaviour, signer: raw.signer.into(), }) diff --git a/ibc-core/ics02-client/types/src/msgs/recover_client.rs b/ibc-core/ics02-client/types/src/msgs/recover_client.rs index e9b79c78f..df371e63a 100644 --- a/ibc-core/ics02-client/types/src/msgs/recover_client.rs +++ b/ibc-core/ics02-client/types/src/msgs/recover_client.rs @@ -1,6 +1,5 @@ //! Definition of domain type message `MsgRecoverClient`. -use ibc_core_host_types::error::DecodingError; use ibc_core_host_types::identifiers::ClientId; use ibc_primitives::prelude::*; use ibc_primitives::Signer; @@ -43,14 +42,8 @@ impl TryFrom for MsgRecoverClient { fn try_from(raw: RawMsgRecoverClient) -> Result { Ok(MsgRecoverClient { - subject_client_id: raw - .subject_client_id - .parse() - .map_err(DecodingError::Identifier)?, - substitute_client_id: raw - .substitute_client_id - .parse() - .map_err(DecodingError::Identifier)?, + subject_client_id: raw.subject_client_id.parse()?, + substitute_client_id: raw.substitute_client_id.parse()?, signer: raw.signer.into(), }) } diff --git a/ibc-core/ics02-client/types/src/msgs/update_client.rs b/ibc-core/ics02-client/types/src/msgs/update_client.rs index 5c5518884..fc99faf9a 100644 --- a/ibc-core/ics02-client/types/src/msgs/update_client.rs +++ b/ibc-core/ics02-client/types/src/msgs/update_client.rs @@ -35,7 +35,7 @@ impl TryFrom for MsgUpdateClient { fn try_from(raw: RawMsgUpdateClient) -> Result { Ok(MsgUpdateClient { - client_id: raw.client_id.parse().map_err(DecodingError::Identifier)?, + client_id: raw.client_id.parse()?, client_message: raw.client_message.ok_or(DecodingError::MissingRawData { description: "client message not set".to_string(), })?, diff --git a/ibc-core/ics02-client/types/src/msgs/upgrade_client.rs b/ibc-core/ics02-client/types/src/msgs/upgrade_client.rs index 72251e3d7..de1941b00 100644 --- a/ibc-core/ics02-client/types/src/msgs/upgrade_client.rs +++ b/ibc-core/ics02-client/types/src/msgs/upgrade_client.rs @@ -86,8 +86,7 @@ impl TryFrom for MsgUpgradeClient { })?; Ok(MsgUpgradeClient { - client_id: ClientId::from_str(&proto_msg.client_id) - .map_err(DecodingError::Identifier)?, + client_id: ClientId::from_str(&proto_msg.client_id)?, upgraded_client_state: raw_client_state, upgraded_consensus_state: raw_consensus_state, proof_upgrade_client: c_bytes, diff --git a/ibc-core/ics03-connection/types/src/connection.rs b/ibc-core/ics03-connection/types/src/connection.rs index b9f64b48c..4ffd8002b 100644 --- a/ibc-core/ics03-connection/types/src/connection.rs +++ b/ibc-core/ics03-connection/types/src/connection.rs @@ -68,7 +68,7 @@ impl TryFrom for IdentifiedConnectionEnd { }; Ok(IdentifiedConnectionEnd { - connection_id: value.id.parse().map_err(DecodingError::Identifier)?, + connection_id: value.id.parse()?, connection_end: raw_connection_end.try_into()?, }) } @@ -214,7 +214,7 @@ impl TryFrom for ConnectionEnd { Self::new( state, - value.client_id.parse().map_err(DecodingError::Identifier)?, + value.client_id.parse()?, value .counterparty .ok_or(DecodingError::MissingRawData { @@ -376,18 +376,10 @@ impl TryFrom for Counterparty { let connection_id: Option = if raw_counterparty.connection_id.is_empty() { None } else { - Some( - raw_counterparty - .connection_id - .parse() - .map_err(DecodingError::Identifier)?, - ) + Some(raw_counterparty.connection_id.parse()?) }; Ok(Counterparty::new( - raw_counterparty - .client_id - .parse() - .map_err(DecodingError::Identifier)?, + raw_counterparty.client_id.parse()?, connection_id, raw_counterparty .prefix diff --git a/ibc-core/ics03-connection/types/src/error.rs b/ibc-core/ics03-connection/types/src/error.rs index d06c64b35..7a4342c74 100644 --- a/ibc-core/ics03-connection/types/src/error.rs +++ b/ibc-core/ics03-connection/types/src/error.rs @@ -3,7 +3,7 @@ use displaydoc::Display; use ibc_core_client_types::error::ClientError; use ibc_core_client_types::Height; -use ibc_core_host_types::error::DecodingError; +use ibc_core_host_types::error::{DecodingError, IdentifierError}; use ibc_core_host_types::identifiers::ConnectionId; use ibc_primitives::prelude::*; use ibc_primitives::{Timestamp, TimestampError}; @@ -77,6 +77,12 @@ impl From for ConnectionError { } } +impl From for ConnectionError { + fn from(e: IdentifierError) -> Self { + Self::Decoding(DecodingError::Identifier(e)) + } +} + #[cfg(feature = "std")] impl std::error::Error for ConnectionError { fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { diff --git a/ibc-core/ics03-connection/types/src/msgs/conn_open_ack.rs b/ibc-core/ics03-connection/types/src/msgs/conn_open_ack.rs index e0675b3ca..39cd8e712 100644 --- a/ibc-core/ics03-connection/types/src/msgs/conn_open_ack.rs +++ b/ibc-core/ics03-connection/types/src/msgs/conn_open_ack.rs @@ -52,14 +52,8 @@ impl TryFrom for MsgConnectionOpenAck { fn try_from(msg: RawMsgConnectionOpenAck) -> Result { Ok(Self { - conn_id_on_a: msg - .connection_id - .parse() - .map_err(DecodingError::Identifier)?, - conn_id_on_b: msg - .counterparty_connection_id - .parse() - .map_err(DecodingError::Identifier)?, + conn_id_on_a: msg.connection_id.parse()?, + conn_id_on_b: msg.counterparty_connection_id.parse()?, client_state_of_a_on_b: msg.client_state.ok_or(DecodingError::MissingRawData { description: "client state not set".to_string(), })?, diff --git a/ibc-core/ics03-connection/types/src/msgs/conn_open_confirm.rs b/ibc-core/ics03-connection/types/src/msgs/conn_open_confirm.rs index 0157b9bb7..982e8f15c 100644 --- a/ibc-core/ics03-connection/types/src/msgs/conn_open_confirm.rs +++ b/ibc-core/ics03-connection/types/src/msgs/conn_open_confirm.rs @@ -36,10 +36,7 @@ impl TryFrom for MsgConnectionOpenConfirm { fn try_from(msg: RawMsgConnectionOpenConfirm) -> Result { Ok(Self { - conn_id_on_b: msg - .connection_id - .parse() - .map_err(DecodingError::Identifier)?, + conn_id_on_b: msg.connection_id.parse()?, proof_conn_end_on_a: msg.proof_ack.try_into().map_err(|e| { DecodingError::InvalidRawData { description: format!("failed to decode connection end proof: {e}"), diff --git a/ibc-core/ics03-connection/types/src/msgs/conn_open_init.rs b/ibc-core/ics03-connection/types/src/msgs/conn_open_init.rs index cd7a0e620..672f419da 100644 --- a/ibc-core/ics03-connection/types/src/msgs/conn_open_init.rs +++ b/ibc-core/ics03-connection/types/src/msgs/conn_open_init.rs @@ -98,7 +98,7 @@ impl TryFrom for MsgConnectionOpenInit { counterparty.verify_empty_connection_id()?; Ok(Self { - client_id_on_a: msg.client_id.parse().map_err(DecodingError::Identifier)?, + client_id_on_a: msg.client_id.parse()?, counterparty, version: msg.version.map(TryInto::try_into).transpose()?, delay_period: Duration::from_nanos(msg.delay_period), diff --git a/ibc-core/ics03-connection/types/src/msgs/conn_open_try.rs b/ibc-core/ics03-connection/types/src/msgs/conn_open_try.rs index 2bc0526aa..5714784c4 100644 --- a/ibc-core/ics03-connection/types/src/msgs/conn_open_try.rs +++ b/ibc-core/ics03-connection/types/src/msgs/conn_open_try.rs @@ -165,7 +165,7 @@ impl TryFrom for MsgConnectionOpenTry { #[allow(deprecated)] Ok(Self { previous_connection_id: msg.previous_connection_id, - client_id_on_b: msg.client_id.parse().map_err(DecodingError::Identifier)?, + client_id_on_b: msg.client_id.parse()?, client_state_of_b_on_a: msg.client_state.ok_or(DecodingError::MissingRawData { description: "client state not set".to_string(), })?, From 73a186e1e1c8940ad2adc21a2084b7d1acda35df Mon Sep 17 00:00:00 2001 From: Sean Chen Date: Fri, 6 Sep 2024 11:04:07 -0500 Subject: [PATCH 61/73] Incorporate PR feedback --- ibc-core/ics02-client/types/src/msgs/upgrade_client.rs | 2 +- ibc-core/ics23-commitment/types/src/commitment.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/ibc-core/ics02-client/types/src/msgs/upgrade_client.rs b/ibc-core/ics02-client/types/src/msgs/upgrade_client.rs index de1941b00..90bc14837 100644 --- a/ibc-core/ics02-client/types/src/msgs/upgrade_client.rs +++ b/ibc-core/ics02-client/types/src/msgs/upgrade_client.rs @@ -81,7 +81,7 @@ impl TryFrom for MsgUpgradeClient { let cs_bytes = CommitmentProofBytes::try_from(proto_msg.proof_upgrade_consensus_state) .map_err(|_| { UpgradeClientError::InvalidUpgradeConsensusStateProof( - CommitmentError::InvalidMerkleProof, + CommitmentError::EmptyMerkleProof, ) })?; diff --git a/ibc-core/ics23-commitment/types/src/commitment.rs b/ibc-core/ics23-commitment/types/src/commitment.rs index 88df28c54..004c09152 100644 --- a/ibc-core/ics23-commitment/types/src/commitment.rs +++ b/ibc-core/ics23-commitment/types/src/commitment.rs @@ -95,7 +95,7 @@ impl TryFrom> for CommitmentProofBytes { fn try_from(bytes: Vec) -> Result { if bytes.is_empty() { - Err(DecodingError::InvalidRawData { + Err(DecodingError::MissingRawData { description: "empty commitment proof bytes".to_string(), })? } else { From 2804e7a1caab3fdc139109ac25cb4c46604ba78d Mon Sep 17 00:00:00 2001 From: Sean Chen Date: Fri, 6 Sep 2024 11:25:31 -0500 Subject: [PATCH 62/73] Change TryFrom for ConsensusState error to DecodingError --- ibc-clients/ics07-tendermint/types/src/consensus_state.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ibc-clients/ics07-tendermint/types/src/consensus_state.rs b/ibc-clients/ics07-tendermint/types/src/consensus_state.rs index 40e5837b2..a5360811d 100644 --- a/ibc-clients/ics07-tendermint/types/src/consensus_state.rs +++ b/ibc-clients/ics07-tendermint/types/src/consensus_state.rs @@ -48,7 +48,7 @@ impl ConsensusState { impl Protobuf for ConsensusState {} impl TryFrom for ConsensusState { - type Error = TendermintClientError; + type Error = DecodingError; fn try_from(raw: RawConsensusState) -> Result { let proto_root = raw From 39988c0ec7b8523ce6e522c63f61590023eddd7e Mon Sep 17 00:00:00 2001 From: Sean Chen Date: Fri, 6 Sep 2024 11:35:10 -0500 Subject: [PATCH 63/73] Remove RouterError::Decoding variant --- ibc-clients/ics07-tendermint/types/src/consensus_state.rs | 1 - ibc-core/ics26-routing/types/src/error.rs | 4 +--- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/ibc-clients/ics07-tendermint/types/src/consensus_state.rs b/ibc-clients/ics07-tendermint/types/src/consensus_state.rs index a5360811d..723da3497 100644 --- a/ibc-clients/ics07-tendermint/types/src/consensus_state.rs +++ b/ibc-clients/ics07-tendermint/types/src/consensus_state.rs @@ -12,7 +12,6 @@ use tendermint::time::Time; use tendermint::Hash; use tendermint_proto::google::protobuf as tpb; -use crate::error::TendermintClientError; use crate::header::Header; pub const TENDERMINT_CONSENSUS_STATE_TYPE_URL: &str = diff --git a/ibc-core/ics26-routing/types/src/error.rs b/ibc-core/ics26-routing/types/src/error.rs index 8e53c1a86..edfeb8a83 100644 --- a/ibc-core/ics26-routing/types/src/error.rs +++ b/ibc-core/ics26-routing/types/src/error.rs @@ -1,13 +1,11 @@ use displaydoc::Display; -use ibc_core_host_types::error::DecodingError; + use ibc_core_host_types::identifiers::PortId; use ibc_primitives::prelude::*; /// Error type for the router module. #[derive(Debug, Display, derive_more::From)] pub enum RouterError { - /// decoding error: `{0}` - Decoding(DecodingError), /// missing module MissingModule, From 5c5dcbec12771f280c9c1224a92a04c7cc6af416 Mon Sep 17 00:00:00 2001 From: Sean Chen Date: Fri, 6 Sep 2024 11:44:17 -0500 Subject: [PATCH 64/73] Revert AcknowledgementStatus tests --- ibc-apps/ics20-transfer/src/module.rs | 30 +++++-------------- ibc-apps/ics721-nft-transfer/src/module.rs | 30 +++++-------------- .../types/src/acknowledgement.rs | 6 ---- ibc-core/ics24-host/types/src/error.rs | 6 ++++ 4 files changed, 22 insertions(+), 50 deletions(-) diff --git a/ibc-apps/ics20-transfer/src/module.rs b/ibc-apps/ics20-transfer/src/module.rs index e6c82a2a3..9c025a427 100644 --- a/ibc-apps/ics20-transfer/src/module.rs +++ b/ibc-apps/ics20-transfer/src/module.rs @@ -331,13 +331,8 @@ mod test { r#"{"result":"AQ=="}"#, ); ser_json_assert_eq( - AcknowledgementStatus::error( - DecodingError::InvalidJson { - description: "failed to deserialize packet data".to_string(), - } - .into(), - ), - r#"{"error":"invalid JSON data: `failed to deserialize packet data`"}"#, + AcknowledgementStatus::error(TokenTransferError::FailedToDeserializePacketData.into()), + r#"{"error":"failed to deserialize packet data"}"#, ); } @@ -353,20 +348,16 @@ mod test { #[test] fn test_ack_error_to_vec() { - let ack_error: Vec = AcknowledgementStatus::error( - DecodingError::InvalidJson { - description: "failed to deserialize packet data".to_string(), - } - .into(), - ) - .into(); + let ack_error: Vec = + AcknowledgementStatus::error(TokenTransferError::FailedToDeserializePacketData.into()) + .into(); // Check that it's the same output as ibc-go // Note: this also implicitly checks that the ack bytes are non-empty, // which would make the conversion to `Acknowledgement` panic assert_eq!( ack_error, - br#"{"error":"invalid JSON data: `failed to deserialize packet data`"}"# + br#"{"error":"failed to deserialize packet data"}"# ); } @@ -382,13 +373,8 @@ mod test { AcknowledgementStatus::success(ack_success_b64()), ); de_json_assert_eq( - r#"{"error":"invalid JSON data: `failed to deserialize packet data`"}"#, - AcknowledgementStatus::error( - DecodingError::InvalidJson { - description: "failed to deserialize packet data".to_string(), - } - .into(), - ), + r#"{"error":"failed to deserialize packet data"}"#, + AcknowledgementStatus::error(TokenTransferError::FailedToDeserializeAck.into()), ); assert!(serde_json::from_str::(r#"{"success":"AQ=="}"#).is_err()); diff --git a/ibc-apps/ics721-nft-transfer/src/module.rs b/ibc-apps/ics721-nft-transfer/src/module.rs index 30269c8ba..8f22fae36 100644 --- a/ibc-apps/ics721-nft-transfer/src/module.rs +++ b/ibc-apps/ics721-nft-transfer/src/module.rs @@ -329,13 +329,8 @@ mod test { r#"{"result":"AQ=="}"#, ); ser_json_assert_eq( - AcknowledgementStatus::error( - DecodingError::InvalidJson { - description: "failed to deserialize packet data".to_string(), - } - .into(), - ), - r#"{"error":"invalid JSON data: `failed to deserialize packet data`"}"#, + AcknowledgementStatus::error(NftTransferError::FailedToDeserializePacketData.into()), + r#"{"error":"failed to deserialize packet data"}"#, ); } @@ -351,20 +346,16 @@ mod test { #[test] fn test_ack_error_to_vec() { - let ack_error: Vec = AcknowledgementStatus::error( - DecodingError::InvalidJson { - description: "failed to deserialize packet data".to_string(), - } - .into(), - ) - .into(); + let ack_error: Vec = + AcknowledgementStatus::error(NftTransferError::FailedToDeserializePacketData.into()) + .into(); // Check that it's the same output as ibc-go // Note: this also implicitly checks that the ack bytes are non-empty, // which would make the conversion to `Acknowledgement` panic assert_eq!( ack_error, - br#"{"error":"invalid JSON data: `failed to deserialize packet data`"}"# + br#"{"error":"failed to deserialize packet data"}"# ); } @@ -380,13 +371,8 @@ mod test { AcknowledgementStatus::success(ack_success_b64()), ); de_json_assert_eq( - r#"{"error":"invalid JSON data: `failed to deserialize packet data`"}"#, - AcknowledgementStatus::error( - DecodingError::InvalidJson { - description: "failed to deserialize packet data".to_string(), - } - .into(), - ), + r#"{"error":"failed to deserialize packet data"}"#, + AcknowledgementStatus::error(NftTransferError::FailedToDeserializePacketData.into()), ); assert!(serde_json::from_str::(r#"{"success":"AQ=="}"#).is_err()); diff --git a/ibc-core/ics04-channel/types/src/acknowledgement.rs b/ibc-core/ics04-channel/types/src/acknowledgement.rs index fbd0ffdd5..c061f2be5 100644 --- a/ibc-core/ics04-channel/types/src/acknowledgement.rs +++ b/ibc-core/ics04-channel/types/src/acknowledgement.rs @@ -142,9 +142,3 @@ impl From for Acknowledgement { .expect("token transfer internal error: ack is never supposed to be empty") } } - -impl From for StatusValue { - fn from(e: DecodingError) -> Self { - StatusValue::new(e.to_string()).expect("error message must not be empty") - } -} diff --git a/ibc-core/ics24-host/types/src/error.rs b/ibc-core/ics24-host/types/src/error.rs index fefc02871..2356d7363 100644 --- a/ibc-core/ics24-host/types/src/error.rs +++ b/ibc-core/ics24-host/types/src/error.rs @@ -60,6 +60,12 @@ impl From for DecodingError { } } +impl From for DecodingError { + fn from(e: IdentifierError) -> Self { + Self::Identifier(e) + } +} + #[cfg(feature = "std")] impl std::error::Error for IdentifierError {} From 9e51a6d550db0fd0496167fdf824a08993be2cef Mon Sep 17 00:00:00 2001 From: Sean Chen Date: Fri, 6 Sep 2024 13:30:37 -0500 Subject: [PATCH 65/73] Cargo fmt --- ibc-core/ics02-client/types/src/error.rs | 3 +-- ibc-core/ics26-routing/types/src/error.rs | 1 - 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/ibc-core/ics02-client/types/src/error.rs b/ibc-core/ics02-client/types/src/error.rs index 9c5d23b5f..dda5be0eb 100644 --- a/ibc-core/ics02-client/types/src/error.rs +++ b/ibc-core/ics02-client/types/src/error.rs @@ -4,8 +4,7 @@ use core::convert::Infallible; use displaydoc::Display; use ibc_core_commitment_types::error::CommitmentError; -use ibc_core_host_types::error::DecodingError; -use ibc_core_host_types::error::IdentifierError; +use ibc_core_host_types::error::{DecodingError, IdentifierError}; use ibc_core_host_types::identifiers::ClientId; use ibc_primitives::prelude::*; use ibc_primitives::Timestamp; diff --git a/ibc-core/ics26-routing/types/src/error.rs b/ibc-core/ics26-routing/types/src/error.rs index edfeb8a83..97650e147 100644 --- a/ibc-core/ics26-routing/types/src/error.rs +++ b/ibc-core/ics26-routing/types/src/error.rs @@ -1,5 +1,4 @@ use displaydoc::Display; - use ibc_core_host_types::identifiers::PortId; use ibc_primitives::prelude::*; From 4a2a8e792e9f688821e1dc37b7a83db171bccec7 Mon Sep 17 00:00:00 2001 From: Sean Chen Date: Fri, 6 Sep 2024 13:32:26 -0500 Subject: [PATCH 66/73] Fix test_ack_de --- ibc-apps/ics721-nft-transfer/src/module.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ibc-apps/ics721-nft-transfer/src/module.rs b/ibc-apps/ics721-nft-transfer/src/module.rs index 8f22fae36..574a28de5 100644 --- a/ibc-apps/ics721-nft-transfer/src/module.rs +++ b/ibc-apps/ics721-nft-transfer/src/module.rs @@ -371,7 +371,7 @@ mod test { AcknowledgementStatus::success(ack_success_b64()), ); de_json_assert_eq( - r#"{"error":"failed to deserialize packet data"}"#, + r#"{"error":"failed to deserialize acknowledgement"}"#, AcknowledgementStatus::error(NftTransferError::FailedToDeserializePacketData.into()), ); From 6fd057cca8e69fc245a4346c284ce08407d470f8 Mon Sep 17 00:00:00 2001 From: Sean Chen Date: Fri, 6 Sep 2024 13:41:17 -0500 Subject: [PATCH 67/73] Fix typo in doc comment --- ibc-clients/ics07-tendermint/types/src/error.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ibc-clients/ics07-tendermint/types/src/error.rs b/ibc-clients/ics07-tendermint/types/src/error.rs index 2090797d7..eb4c2c67d 100644 --- a/ibc-clients/ics07-tendermint/types/src/error.rs +++ b/ibc-clients/ics07-tendermint/types/src/error.rs @@ -46,7 +46,7 @@ pub enum TendermintClientError { duration_since_consensus_state: Duration, trusting_period: Duration, }, - /// insufficient misbehaviour header height: header1 height `{height_1}` shoul be >= header2 height `{height_2}` + /// insufficient misbehaviour header height: header1 height `{height_1}` should be >= header2 height `{height_2}` InsufficientMisbehaviourHeaderHeight { height_1: Height, height_2: Height }, } From 8f9193c0228177e127baa14cddccc31e4d46ead1 Mon Sep 17 00:00:00 2001 From: Sean Chen Date: Fri, 6 Sep 2024 13:51:20 -0500 Subject: [PATCH 68/73] Fix test_ack_de --- ibc-apps/ics721-nft-transfer/src/module.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ibc-apps/ics721-nft-transfer/src/module.rs b/ibc-apps/ics721-nft-transfer/src/module.rs index 574a28de5..a6df81b61 100644 --- a/ibc-apps/ics721-nft-transfer/src/module.rs +++ b/ibc-apps/ics721-nft-transfer/src/module.rs @@ -372,7 +372,7 @@ mod test { ); de_json_assert_eq( r#"{"error":"failed to deserialize acknowledgement"}"#, - AcknowledgementStatus::error(NftTransferError::FailedToDeserializePacketData.into()), + AcknowledgementStatus::error(NftTransferError::FailedToDeserializeAck.into()), ); assert!(serde_json::from_str::(r#"{"success":"AQ=="}"#).is_err()); From 4fd2432c8873da73d673d39e1a837c26a74af167 Mon Sep 17 00:00:00 2001 From: Sean Chen Date: Fri, 6 Sep 2024 13:55:25 -0500 Subject: [PATCH 69/73] Fix test_ack_de --- ibc-apps/ics20-transfer/src/module.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ibc-apps/ics20-transfer/src/module.rs b/ibc-apps/ics20-transfer/src/module.rs index 9c025a427..5958184c7 100644 --- a/ibc-apps/ics20-transfer/src/module.rs +++ b/ibc-apps/ics20-transfer/src/module.rs @@ -374,7 +374,7 @@ mod test { ); de_json_assert_eq( r#"{"error":"failed to deserialize packet data"}"#, - AcknowledgementStatus::error(TokenTransferError::FailedToDeserializeAck.into()), + AcknowledgementStatus::error(TokenTransferError::FailedToDeserializePacketData.into()), ); assert!(serde_json::from_str::(r#"{"success":"AQ=="}"#).is_err()); From ad5268cd4fa41a9beccec0df7ce105a95cc4ccb9 Mon Sep 17 00:00:00 2001 From: Farhad Shabani Date: Mon, 9 Sep 2024 09:31:05 -0700 Subject: [PATCH 70/73] fix: revert nft721 on module errors --- ibc-apps/ics721-nft-transfer/src/module.rs | 19 ++++++------------- .../ics721-nft-transfer/types/src/error.rs | 4 ++-- 2 files changed, 8 insertions(+), 15 deletions(-) diff --git a/ibc-apps/ics721-nft-transfer/src/module.rs b/ibc-apps/ics721-nft-transfer/src/module.rs index a6df81b61..5560b686f 100644 --- a/ibc-apps/ics721-nft-transfer/src/module.rs +++ b/ibc-apps/ics721-nft-transfer/src/module.rs @@ -4,7 +4,6 @@ use ibc_core::channel::types::channel::{Counterparty, Order}; use ibc_core::channel::types::packet::Packet; use ibc_core::channel::types::Version; use ibc_core::handler::types::error::ContextError; -use ibc_core::host::types::error::DecodingError; use ibc_core::host::types::identifiers::{ChannelId, ConnectionId, PortId}; use ibc_core::primitives::prelude::*; use ibc_core::primitives::Signer; @@ -209,7 +208,7 @@ pub fn on_acknowledgement_packet_validate( .map_err(|_| NftTransferError::FailedToDeserializePacketData)?; let acknowledgement = serde_json::from_slice::(acknowledgement.as_ref()) - .map_err(|__| NftTransferError::FailedToDeserializeAck)?; + .map_err(|_| NftTransferError::FailedToDeserializeAck)?; if !acknowledgement.is_successful() { refund_packet_nft_validate(ctx, packet, &data)?; @@ -268,11 +267,8 @@ pub fn on_timeout_packet_validate( packet: &Packet, _relayer: &Signer, ) -> Result<(), NftTransferError> { - let data = serde_json::from_slice::(&packet.data).map_err(|e| { - DecodingError::InvalidJson { - description: format!("failed to deserialize packet data: {e}"), - } - })?; + let data = serde_json::from_slice::(&packet.data) + .map_err(|_| NftTransferError::FailedToDeserializePacketData)?; refund_packet_nft_validate(ctx, packet, &data)?; @@ -287,10 +283,7 @@ pub fn on_timeout_packet_execute( let Ok(data) = serde_json::from_slice::(&packet.data) else { return ( ModuleExtras::empty(), - Err(DecodingError::InvalidJson { - description: "failed to deserialize packet data".to_string(), - } - .into()), + Err(NftTransferError::FailedToDeserializePacketData), ); }; @@ -371,8 +364,8 @@ mod test { AcknowledgementStatus::success(ack_success_b64()), ); de_json_assert_eq( - r#"{"error":"failed to deserialize acknowledgement"}"#, - AcknowledgementStatus::error(NftTransferError::FailedToDeserializeAck.into()), + r#"{"error":"failed to deserialize packet data"}"#, + AcknowledgementStatus::error(NftTransferError::FailedToDeserializePacketData.into()), ); assert!(serde_json::from_str::(r#"{"success":"AQ=="}"#).is_err()); diff --git a/ibc-apps/ics721-nft-transfer/types/src/error.rs b/ibc-apps/ics721-nft-transfer/types/src/error.rs index 6826f4a58..3e0fcc1dd 100644 --- a/ibc-apps/ics721-nft-transfer/types/src/error.rs +++ b/ibc-apps/ics721-nft-transfer/types/src/error.rs @@ -65,7 +65,7 @@ impl From for NftTransferError { } impl From for StatusValue { - fn from(e: NftTransferError) -> Self { - StatusValue::new(e.to_string()).expect("error message must not be empty") + fn from(err: NftTransferError) -> Self { + StatusValue::new(err.to_string()).expect("error message must not be empty") } } From 04c7ad1e154d82040044615c5a1056697dcfc53f Mon Sep 17 00:00:00 2001 From: Farhad Shabani Date: Mon, 9 Sep 2024 09:35:06 -0700 Subject: [PATCH 71/73] fix: remove Identifier variant from few more enums --- ibc-apps/ics721-nft-transfer/types/src/error.rs | 8 ++++++-- ibc-core/ics02-client/types/src/error.rs | 5 +---- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/ibc-apps/ics721-nft-transfer/types/src/error.rs b/ibc-apps/ics721-nft-transfer/types/src/error.rs index 3e0fcc1dd..39d6463fb 100644 --- a/ibc-apps/ics721-nft-transfer/types/src/error.rs +++ b/ibc-apps/ics721-nft-transfer/types/src/error.rs @@ -16,8 +16,6 @@ pub enum NftTransferError { ContextError(ContextError), /// decoding error: `{0}` Decoding(DecodingError), - /// identifier error: `{0}` - Identifier(IdentifierError), /// invalid trace: `{0}` InvalidTrace(String), /// invalid URI error: `{0}` @@ -58,6 +56,12 @@ impl std::error::Error for NftTransferError { } } +impl From for NftTransferError { + fn from(e: IdentifierError) -> Self { + Self::Decoding(DecodingError::Identifier(e)) + } +} + impl From for NftTransferError { fn from(e: Infallible) -> Self { match e {} diff --git a/ibc-core/ics02-client/types/src/error.rs b/ibc-core/ics02-client/types/src/error.rs index dda5be0eb..06f0cfb53 100644 --- a/ibc-core/ics02-client/types/src/error.rs +++ b/ibc-core/ics02-client/types/src/error.rs @@ -20,8 +20,6 @@ pub enum ClientError { Upgrade(UpgradeClientError), /// decoding error: `{0}` Decoding(DecodingError), - /// identifier error: `{0}` - Identifier(IdentifierError), /// invalid trust threshold: `{numerator}`/`{denominator}` InvalidTrustThreshold { numerator: u64, denominator: u64 }, /// invalid client state type: `{0}` @@ -110,7 +108,7 @@ impl From for ClientError { impl From for ClientError { fn from(e: IdentifierError) -> Self { - Self::Identifier(e) + Self::Decoding(DecodingError::Identifier(e)) } } @@ -119,7 +117,6 @@ impl std::error::Error for ClientError { fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { match &self { Self::FailedICS23Verification(e) => Some(e), - Self::Identifier(e) => Some(e), Self::Decoding(e) => Some(e), _ => None, } From 51cb3a4cb63dc5020b05561c24a7be953d5e3a0f Mon Sep 17 00:00:00 2001 From: Farhad Shabani Date: Mon, 9 Sep 2024 13:05:08 -0700 Subject: [PATCH 72/73] fix: remove unused tendermint-proto dep --- ibc-core/ics24-host/types/Cargo.toml | 3 --- 1 file changed, 3 deletions(-) diff --git a/ibc-core/ics24-host/types/Cargo.toml b/ibc-core/ics24-host/types/Cargo.toml index fa69e483f..e4953c720 100644 --- a/ibc-core/ics24-host/types/Cargo.toml +++ b/ibc-core/ics24-host/types/Cargo.toml @@ -35,9 +35,6 @@ ibc-primitives = { workspace = true } parity-scale-codec = { workspace = true, optional = true } scale-info = { workspace = true, optional = true } -# cosmos dependencies -tendermint-proto = { workspace = true } - [dev-dependencies] rstest = { workspace = true } serde-json = { workspace = true } From 96cc7bb7b7f40ae556df15e57bac3231f3255bf5 Mon Sep 17 00:00:00 2001 From: Farhad Shabani Date: Mon, 9 Sep 2024 13:09:15 -0700 Subject: [PATCH 73/73] chore: update Cargo.lock --- ci/cw-check/Cargo.lock | 1 - ci/no-std-check/Cargo.lock | 87 ++++++++++++++++++++------------------ 2 files changed, 45 insertions(+), 43 deletions(-) diff --git a/ci/cw-check/Cargo.lock b/ci/cw-check/Cargo.lock index 3a5d9fe84..89ffc3d40 100644 --- a/ci/cw-check/Cargo.lock +++ b/ci/cw-check/Cargo.lock @@ -1040,7 +1040,6 @@ dependencies = [ "scale-info", "schemars", "serde", - "tendermint-proto", ] [[package]] diff --git a/ci/no-std-check/Cargo.lock b/ci/no-std-check/Cargo.lock index 01ea501f8..be243bc1b 100644 --- a/ci/no-std-check/Cargo.lock +++ b/ci/no-std-check/Cargo.lock @@ -1170,7 +1170,7 @@ dependencies = [ [[package]] name = "ibc" -version = "0.53.0" +version = "0.54.0" dependencies = [ "ibc-apps", "ibc-clients", @@ -1182,7 +1182,7 @@ dependencies = [ [[package]] name = "ibc-app-transfer" -version = "0.53.0" +version = "0.54.0" dependencies = [ "ibc-app-transfer-types", "ibc-core", @@ -1191,7 +1191,7 @@ dependencies = [ [[package]] name = "ibc-app-transfer-types" -version = "0.53.0" +version = "0.54.0" dependencies = [ "derive_more", "displaydoc", @@ -1204,14 +1204,14 @@ dependencies = [ [[package]] name = "ibc-apps" -version = "0.53.0" +version = "0.54.0" dependencies = [ "ibc-app-transfer", ] [[package]] name = "ibc-client-tendermint" -version = "0.53.0" +version = "0.54.0" dependencies = [ "derive_more", "ibc-client-tendermint-types", @@ -1227,7 +1227,7 @@ dependencies = [ [[package]] name = "ibc-client-tendermint-types" -version = "0.53.0" +version = "0.54.0" dependencies = [ "displaydoc", "ibc-core-client-types", @@ -1243,7 +1243,7 @@ dependencies = [ [[package]] name = "ibc-client-wasm-types" -version = "0.53.0" +version = "0.54.0" dependencies = [ "base64 0.22.1", "displaydoc", @@ -1256,7 +1256,7 @@ dependencies = [ [[package]] name = "ibc-clients" -version = "0.53.0" +version = "0.54.0" dependencies = [ "ibc-client-tendermint", "ibc-client-wasm-types", @@ -1264,7 +1264,7 @@ dependencies = [ [[package]] name = "ibc-core" -version = "0.53.0" +version = "0.54.0" dependencies = [ "ibc-core-channel", "ibc-core-client", @@ -1279,12 +1279,13 @@ dependencies = [ [[package]] name = "ibc-core-channel" -version = "0.53.0" +version = "0.54.0" dependencies = [ "ibc-core-channel-types", "ibc-core-client", "ibc-core-commitment-types", "ibc-core-connection", + "ibc-core-connection-types", "ibc-core-handler-types", "ibc-core-host", "ibc-core-router", @@ -1293,7 +1294,7 @@ dependencies = [ [[package]] name = "ibc-core-channel-types" -version = "0.53.0" +version = "0.54.0" dependencies = [ "derive_more", "displaydoc", @@ -1311,7 +1312,7 @@ dependencies = [ [[package]] name = "ibc-core-client" -version = "0.53.0" +version = "0.54.0" dependencies = [ "ibc-core-client-context", "ibc-core-client-types", @@ -1323,7 +1324,7 @@ dependencies = [ [[package]] name = "ibc-core-client-context" -version = "0.53.0" +version = "0.54.0" dependencies = [ "derive_more", "displaydoc", @@ -1338,7 +1339,7 @@ dependencies = [ [[package]] name = "ibc-core-client-types" -version = "0.53.0" +version = "0.54.0" dependencies = [ "derive_more", "displaydoc", @@ -1353,7 +1354,7 @@ dependencies = [ [[package]] name = "ibc-core-commitment-types" -version = "0.53.0" +version = "0.54.0" dependencies = [ "derive_more", "displaydoc", @@ -1367,7 +1368,7 @@ dependencies = [ [[package]] name = "ibc-core-connection" -version = "0.53.0" +version = "0.54.0" dependencies = [ "ibc-core-client", "ibc-core-connection-types", @@ -1378,7 +1379,7 @@ dependencies = [ [[package]] name = "ibc-core-connection-types" -version = "0.53.0" +version = "0.54.0" dependencies = [ "derive_more", "displaydoc", @@ -1394,7 +1395,7 @@ dependencies = [ [[package]] name = "ibc-core-handler" -version = "0.53.0" +version = "0.54.0" dependencies = [ "ibc-core-channel", "ibc-core-client", @@ -1408,7 +1409,7 @@ dependencies = [ [[package]] name = "ibc-core-handler-types" -version = "0.53.0" +version = "0.54.0" dependencies = [ "derive_more", "displaydoc", @@ -1427,7 +1428,7 @@ dependencies = [ [[package]] name = "ibc-core-host" -version = "0.53.0" +version = "0.54.0" dependencies = [ "derive_more", "displaydoc", @@ -1444,7 +1445,7 @@ dependencies = [ [[package]] name = "ibc-core-host-cosmos" -version = "0.53.0" +version = "0.54.0" dependencies = [ "derive_more", "displaydoc", @@ -1466,17 +1467,19 @@ dependencies = [ [[package]] name = "ibc-core-host-types" -version = "0.53.0" +version = "0.54.0" dependencies = [ + "base64 0.22.1", "derive_more", "displaydoc", "ibc-primitives", + "prost", "serde", ] [[package]] name = "ibc-core-router" -version = "0.53.0" +version = "0.54.0" dependencies = [ "derive_more", "displaydoc", @@ -1489,7 +1492,7 @@ dependencies = [ [[package]] name = "ibc-core-router-types" -version = "0.53.0" +version = "0.54.0" dependencies = [ "derive_more", "displaydoc", @@ -1503,7 +1506,7 @@ dependencies = [ [[package]] name = "ibc-derive" -version = "0.7.0" +version = "0.8.0" dependencies = [ "proc-macro2", "quote", @@ -1512,7 +1515,7 @@ dependencies = [ [[package]] name = "ibc-primitives" -version = "0.53.0" +version = "0.54.0" dependencies = [ "derive_more", "displaydoc", @@ -1525,9 +1528,9 @@ dependencies = [ [[package]] name = "ibc-proto" -version = "0.46.0" +version = "0.47.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6cb09e0b52b8a16e98ce98845e7c15b018440f3c56defa12fa44782cd66bab65" +checksum = "c852d22b782d2d793f4a646f968de419be635e02bc8798d5d74a6e44eef27733" dependencies = [ "base64 0.22.1", "borsh", @@ -1545,9 +1548,9 @@ dependencies = [ [[package]] name = "ics23" -version = "0.11.1" +version = "0.12.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dc3b8be84e7285c73b88effdc3294b552277d6b0ec728ee016c861b7b9a2c19c" +checksum = "73b17f1a5bd7d12ad30a21445cfa5f52fd7651cb3243ba866f9916b1ec112f12" dependencies = [ "anyhow", "blake2", @@ -2130,9 +2133,9 @@ dependencies = [ [[package]] name = "prost" -version = "0.12.6" +version = "0.13.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "deb1435c188b76130da55f17a466d252ff7b1418b2ad3e037d127b94e3411f29" +checksum = "3b2ecbe40f08db5c006b5764a2645f7f3f141ce756412ac9e1dd6087e6d32995" dependencies = [ "bytes", "prost-derive", @@ -2140,9 +2143,9 @@ dependencies = [ [[package]] name = "prost-derive" -version = "0.12.6" +version = "0.13.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "81bddcdb20abf9501610992b6759a4c888aef7d1a7247ef75e2404275ac24af1" +checksum = "acf0c195eebb4af52c752bec4f52f645da98b6e92077a04110c7f349477ae5ac" dependencies = [ "anyhow", "itertools 0.12.1", @@ -2153,9 +2156,9 @@ dependencies = [ [[package]] name = "prost-types" -version = "0.12.6" +version = "0.13.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9091c90b0a32608e984ff2fa4091273cbdd755d54935c51d520887f4a1dbd5b0" +checksum = "60caa6738c7369b940c3d49246a8d1749323674c65cb13010134f5c9bad5b519" dependencies = [ "prost", ] @@ -3034,9 +3037,9 @@ checksum = "55937e1799185b12863d447f42597ed69d9928686b8d88a1df17376a097d8369" [[package]] name = "tendermint" -version = "0.37.0" +version = "0.38.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "954496fbc9716eb4446cdd6d00c071a3e2f22578d62aa03b40c7e5b4fda3ed42" +checksum = "505d9d6ffeb83b1de47c307c6e0d2dff56c6256989299010ad03cd80a8491e97" dependencies = [ "bytes", "digest 0.10.7", @@ -3063,9 +3066,9 @@ dependencies = [ [[package]] name = "tendermint-light-client-verifier" -version = "0.37.0" +version = "0.38.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3848090df4502a09ee27cb1a00f1835e1111c8993b22c5e1e41ffb7f6f09d57e" +checksum = "7a2674adbf0dc51aa0c8eaf8462c7d6692ec79502713e50ed5432a442002be90" dependencies = [ "derive_more", "flex-error", @@ -3076,9 +3079,9 @@ dependencies = [ [[package]] name = "tendermint-proto" -version = "0.37.0" +version = "0.38.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dc87024548c7f3da479885201e3da20ef29e85a3b13d04606b380ac4c7120d87" +checksum = "8ed14abe3b0502a3afe21ca74ca5cdd6c7e8d326d982c26f98a394445eb31d6e" dependencies = [ "bytes", "flex-error",