From f87bd5db108d2b56be52e52e9e1b4106c1aae14c Mon Sep 17 00:00:00 2001 From: kayandra <5002506+kayandra@users.noreply.github.com> Date: Sat, 18 Jan 2025 16:59:58 +0100 Subject: [PATCH 1/7] refactor(voyager): support multiple IBC interfaces in ensure_ibc_interface --- cosmwasm/ucs00-pingpong/src/ibc.rs | 8 +++++--- lib/voyager-message/src/module.rs | 14 ++++++++++---- voyager/modules/client/ethereum/src/main.rs | 2 +- voyager/modules/client/movement/src/main.rs | 2 +- .../client/state-lens/ics23-ics23/src/main.rs | 2 +- .../client/state-lens/ics23-mpt/src/main.rs | 3 +-- 6 files changed, 19 insertions(+), 12 deletions(-) diff --git a/cosmwasm/ucs00-pingpong/src/ibc.rs b/cosmwasm/ucs00-pingpong/src/ibc.rs index 3b8ee51ee8..83e98082ab 100644 --- a/cosmwasm/ucs00-pingpong/src/ibc.rs +++ b/cosmwasm/ucs00-pingpong/src/ibc.rs @@ -1,7 +1,9 @@ +#[cfg(not(feature = "library"))] +use cosmwasm_std::entry_point; use cosmwasm_std::{ - attr, entry_point, DepsMut, Env, IbcBasicResponse, IbcChannel, IbcChannelCloseMsg, - IbcChannelConnectMsg, IbcChannelOpenMsg, IbcOrder, IbcPacket, IbcPacketAckMsg, - IbcPacketReceiveMsg, IbcPacketTimeoutMsg, IbcReceiveResponse, Reply, Response, StdError, + attr, DepsMut, Env, IbcBasicResponse, IbcChannel, IbcChannelCloseMsg, IbcChannelConnectMsg, + IbcChannelOpenMsg, IbcOrder, IbcPacket, IbcPacketAckMsg, IbcPacketReceiveMsg, + IbcPacketTimeoutMsg, IbcReceiveResponse, Reply, Response, StdError, }; use crate::{msg::UCS00PingPong, state::CONFIG, ContractError}; diff --git a/lib/voyager-message/src/module.rs b/lib/voyager-message/src/module.rs index c6978e29e1..f4c338d6ed 100644 --- a/lib/voyager-message/src/module.rs +++ b/lib/voyager-message/src/module.rs @@ -176,12 +176,18 @@ impl ClientModuleInfo { pub fn ensure_ibc_interface( &self, - ibc_interface: impl AsRef, + expected_interfaces: Vec>, ) -> Result<(), UnexpectedIbcInterfaceError> { - if ibc_interface.as_ref() != self.ibc_interface.as_str() { + if !expected_interfaces + .iter() + .any(|expected| expected.as_ref() == self.ibc_interface.as_str()) + { Err(UnexpectedIbcInterfaceError { expected: self.ibc_interface.clone(), - found: ibc_interface.as_ref().to_owned(), + found: expected_interfaces + .iter() + .map(|s| s.as_ref().to_string()) + .collect(), }) } else { Ok(()) @@ -272,7 +278,7 @@ pub struct UnexpectedClientTypeError { #[error("invalid IBC interface: this module provides functionality for IBC interface `{expected}`, but the config specifies `{found}`")] pub struct UnexpectedIbcInterfaceError { pub expected: IbcInterface, - pub found: String, + pub found: Vec, } #[derive(Debug, Clone, thiserror::Error)] diff --git a/voyager/modules/client/ethereum/src/main.rs b/voyager/modules/client/ethereum/src/main.rs index 906e2ec03c..aa4d1f5bdf 100644 --- a/voyager/modules/client/ethereum/src/main.rs +++ b/voyager/modules/client/ethereum/src/main.rs @@ -47,7 +47,7 @@ impl ClientModule for Module { async fn new(config: Self::Config, info: ClientModuleInfo) -> Result { info.ensure_client_type(ClientType::ETHEREUM)?; info.ensure_consensus_type(ConsensusType::ETHEREUM)?; - info.ensure_ibc_interface(IbcInterface::IBC_COSMWASM)?; + info.ensure_ibc_interface(vec![IbcInterface::IBC_COSMWASM])?; Ok(Self { chain_spec: config.chain_spec, diff --git a/voyager/modules/client/movement/src/main.rs b/voyager/modules/client/movement/src/main.rs index 70aa31beef..939e032e5b 100644 --- a/voyager/modules/client/movement/src/main.rs +++ b/voyager/modules/client/movement/src/main.rs @@ -46,7 +46,7 @@ impl ClientModule for Module { async fn new(Config {}: Self::Config, info: ClientModuleInfo) -> Result { info.ensure_client_type(ClientType::MOVEMENT)?; info.ensure_consensus_type(ConsensusType::MOVEMENT)?; - info.ensure_ibc_interface(IbcInterface::IBC_COSMWASM)?; + info.ensure_ibc_interface(vec![IbcInterface::IBC_COSMWASM])?; Ok(Module {}) } diff --git a/voyager/modules/client/state-lens/ics23-ics23/src/main.rs b/voyager/modules/client/state-lens/ics23-ics23/src/main.rs index b2aa8b9510..e0f3f34b0d 100644 --- a/voyager/modules/client/state-lens/ics23-ics23/src/main.rs +++ b/voyager/modules/client/state-lens/ics23-ics23/src/main.rs @@ -46,7 +46,7 @@ impl ClientModule for Module { async fn new(_: Self::Config, info: ClientModuleInfo) -> Result { info.ensure_client_type(ClientType::STATE_LENS_ICS23_ICS23)?; info.ensure_consensus_type(ConsensusType::TENDERMINT)?; - info.ensure_ibc_interface(IbcInterface::IBC_SOLIDITY)?; + info.ensure_ibc_interface(vec![IbcInterface::IBC_COSMWASM])?; Ok(Self {}) } } diff --git a/voyager/modules/client/state-lens/ics23-mpt/src/main.rs b/voyager/modules/client/state-lens/ics23-mpt/src/main.rs index b7197ed781..ac3a425dc4 100644 --- a/voyager/modules/client/state-lens/ics23-mpt/src/main.rs +++ b/voyager/modules/client/state-lens/ics23-mpt/src/main.rs @@ -81,8 +81,7 @@ impl ClientModule for Module { async fn new(_: Self::Config, info: ClientModuleInfo) -> Result { info.ensure_client_type(ClientType::STATE_LENS_ICS23_MPT)?; info.ensure_consensus_type(ConsensusType::ETHEREUM)?; - info.ensure_ibc_interface(IbcInterface::IBC_SOLIDITY) - .or(info.ensure_ibc_interface(IbcInterface::IBC_COSMWASM))?; + info.ensure_ibc_interface(vec![IbcInterface::IBC_SOLIDITY, IbcInterface::IBC_COSMWASM])?; Ok(Self { ibc_interface: SupportedIbcInterface::try_from(info.ibc_interface.to_string())?, From 75e683dc46a5592b451cd0e220abeb9e93806f09 Mon Sep 17 00:00:00 2001 From: kayandra <5002506+kayandra@users.noreply.github.com> Date: Tue, 28 Jan 2025 06:34:34 +0100 Subject: [PATCH 2/7] refactor(voyager): use IntoInterator for ensure_ibc_interface --- lib/voyager-message/src/module.rs | 11 ++++++----- voyager/modules/client/ethereum/src/main.rs | 2 +- voyager/modules/client/movement/src/main.rs | 2 +- .../modules/client/state-lens/ics23-ics23/src/main.rs | 2 +- .../modules/client/state-lens/ics23-mpt/src/main.rs | 2 +- 5 files changed, 10 insertions(+), 9 deletions(-) diff --git a/lib/voyager-message/src/module.rs b/lib/voyager-message/src/module.rs index f4c338d6ed..86799da79c 100644 --- a/lib/voyager-message/src/module.rs +++ b/lib/voyager-message/src/module.rs @@ -176,20 +176,21 @@ impl ClientModuleInfo { pub fn ensure_ibc_interface( &self, - expected_interfaces: Vec>, + expected_interfaces: impl IntoIterator>, ) -> Result<(), UnexpectedIbcInterfaceError> { if !expected_interfaces - .iter() + .into_iter() .any(|expected| expected.as_ref() == self.ibc_interface.as_str()) { Err(UnexpectedIbcInterfaceError { - expected: self.ibc_interface.clone(), - found: expected_interfaces - .iter() + expected: expected_interfaces + .into_iter() .map(|s| s.as_ref().to_string()) .collect(), + found: self.ibc_interface.clone(), }) } else { + // If a match is found, return Ok Ok(()) } } diff --git a/voyager/modules/client/ethereum/src/main.rs b/voyager/modules/client/ethereum/src/main.rs index aa4d1f5bdf..42bbfcb7d5 100644 --- a/voyager/modules/client/ethereum/src/main.rs +++ b/voyager/modules/client/ethereum/src/main.rs @@ -47,7 +47,7 @@ impl ClientModule for Module { async fn new(config: Self::Config, info: ClientModuleInfo) -> Result { info.ensure_client_type(ClientType::ETHEREUM)?; info.ensure_consensus_type(ConsensusType::ETHEREUM)?; - info.ensure_ibc_interface(vec![IbcInterface::IBC_COSMWASM])?; + info.ensure_ibc_interface([IbcInterface::IBC_COSMWASM])?; Ok(Self { chain_spec: config.chain_spec, diff --git a/voyager/modules/client/movement/src/main.rs b/voyager/modules/client/movement/src/main.rs index 939e032e5b..a9fab90cdd 100644 --- a/voyager/modules/client/movement/src/main.rs +++ b/voyager/modules/client/movement/src/main.rs @@ -46,7 +46,7 @@ impl ClientModule for Module { async fn new(Config {}: Self::Config, info: ClientModuleInfo) -> Result { info.ensure_client_type(ClientType::MOVEMENT)?; info.ensure_consensus_type(ConsensusType::MOVEMENT)?; - info.ensure_ibc_interface(vec![IbcInterface::IBC_COSMWASM])?; + info.ensure_ibc_interface([IbcInterface::IBC_COSMWASM])?; Ok(Module {}) } diff --git a/voyager/modules/client/state-lens/ics23-ics23/src/main.rs b/voyager/modules/client/state-lens/ics23-ics23/src/main.rs index e0f3f34b0d..24ce075b41 100644 --- a/voyager/modules/client/state-lens/ics23-ics23/src/main.rs +++ b/voyager/modules/client/state-lens/ics23-ics23/src/main.rs @@ -46,7 +46,7 @@ impl ClientModule for Module { async fn new(_: Self::Config, info: ClientModuleInfo) -> Result { info.ensure_client_type(ClientType::STATE_LENS_ICS23_ICS23)?; info.ensure_consensus_type(ConsensusType::TENDERMINT)?; - info.ensure_ibc_interface(vec![IbcInterface::IBC_COSMWASM])?; + info.ensure_ibc_interface([IbcInterface::IBC_COSMWASM])?; Ok(Self {}) } } diff --git a/voyager/modules/client/state-lens/ics23-mpt/src/main.rs b/voyager/modules/client/state-lens/ics23-mpt/src/main.rs index ac3a425dc4..0d1dec531c 100644 --- a/voyager/modules/client/state-lens/ics23-mpt/src/main.rs +++ b/voyager/modules/client/state-lens/ics23-mpt/src/main.rs @@ -81,7 +81,7 @@ impl ClientModule for Module { async fn new(_: Self::Config, info: ClientModuleInfo) -> Result { info.ensure_client_type(ClientType::STATE_LENS_ICS23_MPT)?; info.ensure_consensus_type(ConsensusType::ETHEREUM)?; - info.ensure_ibc_interface(vec![IbcInterface::IBC_SOLIDITY, IbcInterface::IBC_COSMWASM])?; + info.ensure_ibc_interface([IbcInterface::IBC_SOLIDITY, IbcInterface::IBC_COSMWASM])?; Ok(Self { ibc_interface: SupportedIbcInterface::try_from(info.ibc_interface.to_string())?, From a11faa5c3594be593b21711c54331b342ac57296 Mon Sep 17 00:00:00 2001 From: kayandra <5002506+kayandra@users.noreply.github.com> Date: Tue, 28 Jan 2025 06:40:11 +0100 Subject: [PATCH 3/7] fix(voyager): add IBC_MOVE_APTOS to expected types --- voyager/modules/client/state-lens/ics23-mpt/src/main.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/voyager/modules/client/state-lens/ics23-mpt/src/main.rs b/voyager/modules/client/state-lens/ics23-mpt/src/main.rs index 0d1dec531c..16dc337adb 100644 --- a/voyager/modules/client/state-lens/ics23-mpt/src/main.rs +++ b/voyager/modules/client/state-lens/ics23-mpt/src/main.rs @@ -81,7 +81,11 @@ impl ClientModule for Module { async fn new(_: Self::Config, info: ClientModuleInfo) -> Result { info.ensure_client_type(ClientType::STATE_LENS_ICS23_MPT)?; info.ensure_consensus_type(ConsensusType::ETHEREUM)?; - info.ensure_ibc_interface([IbcInterface::IBC_SOLIDITY, IbcInterface::IBC_COSMWASM])?; + info.ensure_ibc_interface([ + IbcInterface::IBC_SOLIDITY, + IbcInterface::IBC_COSMWASM, + IbcInterface::IBC_MOVE_APTOS, + ])?; Ok(Self { ibc_interface: SupportedIbcInterface::try_from(info.ibc_interface.to_string())?, From 00aa3acd48cb14ba4895a7e718ec80bb12627e08 Mon Sep 17 00:00:00 2001 From: kayandra <5002506+kayandra@users.noreply.github.com> Date: Tue, 28 Jan 2025 06:57:45 +0100 Subject: [PATCH 4/7] fix(voyager): satisfy the borrow checker --- lib/voyager-message/src/module.rs | 23 ++++++++++--------- .../client/state-lens/ics23-smt/src/main.rs | 3 +-- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/lib/voyager-message/src/module.rs b/lib/voyager-message/src/module.rs index 8e9b405556..f7e41dcc8d 100644 --- a/lib/voyager-message/src/module.rs +++ b/lib/voyager-message/src/module.rs @@ -178,19 +178,20 @@ impl ClientModuleInfo { &self, expected_interfaces: impl IntoIterator>, ) -> Result<(), UnexpectedIbcInterfaceError> { - if !expected_interfaces + let expected_interfaces: Vec = expected_interfaces .into_iter() - .any(|expected| expected.as_ref() == self.ibc_interface.as_str()) + .map(|s| s.as_ref().to_string()) + .collect(); + + if !expected_interfaces + .iter() + .any(|expected| expected == self.ibc_interface.as_str()) { Err(UnexpectedIbcInterfaceError { - expected: expected_interfaces - .into_iter() - .map(|s| s.as_ref().to_string()) - .collect(), - found: self.ibc_interface.clone(), + expected: expected_interfaces, + found: self.ibc_interface.to_string(), }) } else { - // If a match is found, return Ok Ok(()) } } @@ -276,10 +277,10 @@ pub struct UnexpectedClientTypeError { } #[derive(Debug, Clone, thiserror::Error)] -#[error("invalid IBC interface: this module provides functionality for IBC interface `{expected}`, but the config specifies `{found}`")] +#[error("invalid IBC interface: this module provides functionality for IBC interfaces `{expected:?}`, but the config specifies `{found}`")] pub struct UnexpectedIbcInterfaceError { - pub expected: IbcInterface, - pub found: Vec, + pub expected: Vec, + pub found: String, } #[derive(Debug, Clone, thiserror::Error)] diff --git a/voyager/modules/client/state-lens/ics23-smt/src/main.rs b/voyager/modules/client/state-lens/ics23-smt/src/main.rs index ff0323d305..381a091315 100644 --- a/voyager/modules/client/state-lens/ics23-smt/src/main.rs +++ b/voyager/modules/client/state-lens/ics23-smt/src/main.rs @@ -81,8 +81,7 @@ impl ClientModule for Module { async fn new(_: Self::Config, info: ClientModuleInfo) -> Result { info.ensure_client_type(ClientType::STATE_LENS_ICS23_SMT)?; info.ensure_consensus_type(ConsensusType::MOVEMENT)?; - info.ensure_ibc_interface(IbcInterface::IBC_SOLIDITY) - .or(info.ensure_ibc_interface(IbcInterface::IBC_COSMWASM))?; + info.ensure_ibc_interface([IbcInterface::IBC_SOLIDITY, IbcInterface::IBC_COSMWASM])?; Ok(Self { ibc_interface: SupportedIbcInterface::try_from(info.ibc_interface.to_string())?, From 712703f7b537cd978db557639c6599c6b5e6797f Mon Sep 17 00:00:00 2001 From: kayandra <5002506+kayandra@users.noreply.github.com> Date: Tue, 28 Jan 2025 18:08:38 +0100 Subject: [PATCH 5/7] chore(voyager): comma separated UnexpectedClientTypeError expected --- lib/voyager-message/src/module.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/voyager-message/src/module.rs b/lib/voyager-message/src/module.rs index f7e41dcc8d..3e2ce959c0 100644 --- a/lib/voyager-message/src/module.rs +++ b/lib/voyager-message/src/module.rs @@ -188,7 +188,7 @@ impl ClientModuleInfo { .any(|expected| expected == self.ibc_interface.as_str()) { Err(UnexpectedIbcInterfaceError { - expected: expected_interfaces, + expected: expected_interfaces.join(","), found: self.ibc_interface.to_string(), }) } else { @@ -277,9 +277,9 @@ pub struct UnexpectedClientTypeError { } #[derive(Debug, Clone, thiserror::Error)] -#[error("invalid IBC interface: this module provides functionality for IBC interfaces `{expected:?}`, but the config specifies `{found}`")] +#[error("invalid IBC interface: this module provides functionality for IBC interfaces `{expected}`, but the config specifies `{found}`")] pub struct UnexpectedIbcInterfaceError { - pub expected: Vec, + pub expected: String, pub found: String, } From b50f591fc814af8c4e801dc92f5da653e9fa2aea Mon Sep 17 00:00:00 2001 From: kayandra <5002506+kayandra@users.noreply.github.com> Date: Thu, 30 Jan 2025 11:21:06 +0100 Subject: [PATCH 6/7] refactor: cleanup ensure_ibc_interface --- lib/voyager-message/src/module.rs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/voyager-message/src/module.rs b/lib/voyager-message/src/module.rs index 3e2ce959c0..2fbcf8b096 100644 --- a/lib/voyager-message/src/module.rs +++ b/lib/voyager-message/src/module.rs @@ -176,19 +176,19 @@ impl ClientModuleInfo { pub fn ensure_ibc_interface( &self, - expected_interfaces: impl IntoIterator>, + expected_interfaces: impl IntoIterator, ) -> Result<(), UnexpectedIbcInterfaceError> { - let expected_interfaces: Vec = expected_interfaces + let expected_interfaces: Vec = expected_interfaces .into_iter() - .map(|s| s.as_ref().to_string()) + .map(IbcInterface::new) .collect(); if !expected_interfaces .iter() - .any(|expected| expected == self.ibc_interface.as_str()) + .any(|e| e.as_str() == self.ibc_interface.as_str()) { Err(UnexpectedIbcInterfaceError { - expected: expected_interfaces.join(","), + expected: expected_interfaces, found: self.ibc_interface.to_string(), }) } else { @@ -277,9 +277,9 @@ pub struct UnexpectedClientTypeError { } #[derive(Debug, Clone, thiserror::Error)] -#[error("invalid IBC interface: this module provides functionality for IBC interfaces `{expected}`, but the config specifies `{found}`")] +#[error("invalid IBC interface: this module provides functionality for IBC interfaces `{expected}`, but the config specifies `{found}`", expected = expected.into_iter().map(|x| x.as_str()).collect::>().join(","))] pub struct UnexpectedIbcInterfaceError { - pub expected: String, + pub expected: Vec, pub found: String, } From e7c74b92666991587f4fa190dadc7b28d270a479 Mon Sep 17 00:00:00 2001 From: kayandra <5002506+kayandra@users.noreply.github.com> Date: Thu, 30 Jan 2025 12:12:38 +0100 Subject: [PATCH 7/7] fix(voyager): fix broken types --- lib/voyager-message/src/module.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/voyager-message/src/module.rs b/lib/voyager-message/src/module.rs index 2fbcf8b096..fbba9c3e79 100644 --- a/lib/voyager-message/src/module.rs +++ b/lib/voyager-message/src/module.rs @@ -277,7 +277,7 @@ pub struct UnexpectedClientTypeError { } #[derive(Debug, Clone, thiserror::Error)] -#[error("invalid IBC interface: this module provides functionality for IBC interfaces `{expected}`, but the config specifies `{found}`", expected = expected.into_iter().map(|x| x.as_str()).collect::>().join(","))] +#[error("invalid IBC interface: this module provides functionality for IBC interfaces `{expected}`, but the config specifies `{found}`", expected = expected.iter().map(|x| x.as_str()).collect::>().join(","))] pub struct UnexpectedIbcInterfaceError { pub expected: Vec, pub found: String,