From fcdd873b996285818cc14308a6cbe7dc9e6d4a55 Mon Sep 17 00:00:00 2001 From: Soares Chen Date: Mon, 18 Dec 2023 17:04:19 +0100 Subject: [PATCH 1/3] Add ErrorRaiser constraint to HasRuntime trait --- .../bootstrap/impls/chain/bootstrap_chain.rs | 2 +- .../impls/genesis/add_genesis_wallet.rs | 2 +- .../initializers/create_chain_home_dir.rs | 2 +- .../src/build/components/relay/batch.rs | 5 +- .../src/build/traits/cache.rs | 6 ++- .../components/relay_with_batch_builder.rs | 7 ++- .../src/build/components/chain/cache.rs | 1 + .../src/build/components/relay/cache.rs | 1 + .../src/build/traits/cache.rs | 9 ++-- .../src/components/default/closures/build.rs | 2 + .../relay/components/auto_relayers/event.rs | 4 +- .../src/runtime/traits/mutex.rs | 13 ----- .../src/runtime/traits/runtime.rs | 4 +- .../relayer-cosmos-mock/src/impls/birelay.rs | 13 ++++- crates/relayer-cosmos-mock/src/impls/chain.rs | 10 +++- crates/relayer-cosmos-mock/src/impls/relay.rs | 13 ++++- .../src/impls/birelay/components.rs | 8 +++ .../relayer-cosmos/src/impls/birelay/types.rs | 11 +--- .../src/impls/build/components.rs | 8 +++ .../relayer-cosmos/src/impls/build/types.rs | 6 --- .../src/impls/chain/component.rs | 8 +++ .../relayer-cosmos/src/impls/chain/error.rs | 34 ------------- crates/relayer-cosmos/src/impls/chain/mod.rs | 1 - .../relayer-cosmos/src/impls/chain/types.rs | 10 +--- crates/relayer-cosmos/src/impls/error.rs | 51 +++++++++++++++++++ crates/relayer-cosmos/src/impls/mod.rs | 1 + .../src/impls/relay/component.rs | 8 +++ .../relayer-cosmos/src/impls/relay/types.rs | 11 +--- .../src/impls/transaction/component.rs | 8 ++- .../src/impls/transaction/types.rs | 6 --- .../src/relayer_mock/base/impls/chain.rs | 16 ++++-- .../src/relayer_mock/base/impls/error.rs | 22 ++++++++ .../src/relayer_mock/base/impls/mod.rs | 1 + .../src/relayer_mock/base/impls/relay.rs | 15 ++++-- .../src/impls/chain/types.rs | 11 +++- .../src/impls/relay/error.rs | 4 +- .../src/impls/relay/types.rs | 11 +++- crates/relayer-solomachine/src/types/error.rs | 1 - 38 files changed, 222 insertions(+), 124 deletions(-) delete mode 100644 crates/relayer-cosmos/src/impls/chain/error.rs create mode 100644 crates/relayer-cosmos/src/impls/error.rs create mode 100644 crates/relayer-mock/src/relayer_mock/base/impls/error.rs diff --git a/crates/cosmos-test-components/src/bootstrap/impls/chain/bootstrap_chain.rs b/crates/cosmos-test-components/src/bootstrap/impls/chain/bootstrap_chain.rs index 4558a8337..02b0219aa 100644 --- a/crates/cosmos-test-components/src/bootstrap/impls/chain/bootstrap_chain.rs +++ b/crates/cosmos-test-components/src/bootstrap/impls/chain/bootstrap_chain.rs @@ -36,7 +36,7 @@ where + CanInitChainConfig + CanStartChainFullNode + CanBuildChainFromBootstrapParameters, - Runtime: HasFilePathType + HasChildProcessType, + Runtime: HasFilePathType + HasChildProcessType + HasErrorType, Chain: HasChainIdType + HasWalletType, { async fn bootstrap_chain( diff --git a/crates/cosmos-test-components/src/bootstrap/impls/genesis/add_genesis_wallet.rs b/crates/cosmos-test-components/src/bootstrap/impls/genesis/add_genesis_wallet.rs index 548c0faef..a166c2eb5 100644 --- a/crates/cosmos-test-components/src/bootstrap/impls/genesis/add_genesis_wallet.rs +++ b/crates/cosmos-test-components/src/bootstrap/impls/genesis/add_genesis_wallet.rs @@ -25,7 +25,7 @@ where + CanInitWallet + CanAddGenesisAccount + CanAddGenesisValidator, - Runtime: HasFilePathType, + Runtime: HasFilePathType + HasErrorType, Chain: HasChainIdType + HasWalletType + HasAmountType + HasAddressType, { async fn add_wallet_to_genesis( diff --git a/crates/cosmos-test-components/src/bootstrap/impls/initializers/create_chain_home_dir.rs b/crates/cosmos-test-components/src/bootstrap/impls/initializers/create_chain_home_dir.rs index fcfba4726..96a76d97c 100644 --- a/crates/cosmos-test-components/src/bootstrap/impls/initializers/create_chain_home_dir.rs +++ b/crates/cosmos-test-components/src/bootstrap/impls/initializers/create_chain_home_dir.rs @@ -20,7 +20,7 @@ impl ChainHomeDirInitializer for CreateCha where Bootstrap: HasChainType + HasRuntime + HasErrorType + HasTestDir, - Runtime: HasFilePathType, + Runtime: HasFilePathType + HasErrorType, Chain: HasChainIdType, Chain::ChainId: Display, Runtime::FilePath: AsRef, diff --git a/crates/relayer-components-extra/src/build/components/relay/batch.rs b/crates/relayer-components-extra/src/build/components/relay/batch.rs index d1e450b1a..0088d302f 100644 --- a/crates/relayer-components-extra/src/build/components/relay/batch.rs +++ b/crates/relayer-components-extra/src/build/components/relay/batch.rs @@ -11,7 +11,7 @@ use ibc_relayer_components::chain::traits::types::chain_id::HasChainId; use ibc_relayer_components::chain::traits::types::ibc::HasIbcChainTypes; use ibc_relayer_components::relay::traits::chains::HasRelayChains; use ibc_relayer_components::relay::traits::target::{DestinationTarget, SourceTarget}; -use ibc_relayer_components::runtime::traits::mutex::{HasMutex, HasRuntimeWithMutex}; +use ibc_relayer_components::runtime::traits::mutex::HasMutex; use ibc_relayer_components::runtime::traits::runtime::HasRuntime; use crate::batch::traits::config::HasBatchConfig; @@ -138,12 +138,13 @@ where #[async_trait] impl CanBuildBatchChannel for Build where - Build: HasBiRelayType + HasRuntimeWithMutex + HasErrorType, + Build: HasBiRelayType + HasRuntime + HasErrorType, Target: ChainBuildTarget, Chain: HasIbcChainTypes + HasRuntime, Counterparty: HasIbcChainTypes, Runtime: CanCreateChannels + HasChannelOnceTypes + CanCloneSender, Build: HasBatchSenderCache>, + Build::Runtime: HasMutex, Chain::ChainId: Ord + Clone, Counterparty::ChainId: Ord + Clone, Chain::ClientId: Ord + Clone, diff --git a/crates/relayer-components-extra/src/build/traits/cache.rs b/crates/relayer-components-extra/src/build/traits/cache.rs index 6bbed17d6..58d75d050 100644 --- a/crates/relayer-components-extra/src/build/traits/cache.rs +++ b/crates/relayer-components-extra/src/build/traits/cache.rs @@ -6,7 +6,8 @@ use ibc_relayer_components::build::traits::target::chain::ChainBuildTarget; use ibc_relayer_components::build::types::aliases::{ CounterpartyChainId, CounterpartyClientId, TargetChain, TargetChainId, TargetClientId, }; -use ibc_relayer_components::runtime::traits::mutex::HasRuntimeWithMutex; +use ibc_relayer_components::runtime::traits::mutex::HasMutex; +use ibc_relayer_components::runtime::traits::runtime::HasRuntime; use ibc_relayer_components::runtime::types::aliases::Mutex; use crate::batch::traits::channel::HasMessageBatchSenderType; @@ -25,9 +26,10 @@ pub trait HasBatchSenderCacheType: Async { impl HasBatchSenderCacheType for Target where Error: Async, - Build: HasBiRelayType + HasRuntimeWithMutex, + Build: HasBiRelayType + HasRuntime, Target: ChainBuildTarget, Target::TargetChain: HasMessageBatchSenderType, + Build::Runtime: HasMutex, { type BatchSenderCache = Mutex< Build, diff --git a/crates/relayer-components-extra/src/build/traits/components/relay_with_batch_builder.rs b/crates/relayer-components-extra/src/build/traits/components/relay_with_batch_builder.rs index 74aaf456b..05073fba8 100644 --- a/crates/relayer-components-extra/src/build/traits/components/relay_with_batch_builder.rs +++ b/crates/relayer-components-extra/src/build/traits/components/relay_with_batch_builder.rs @@ -4,7 +4,7 @@ use ibc_relayer_components::build::traits::target::relay::RelayBuildTarget; use ibc_relayer_components::build::types::aliases::{ TargetDstChain, TargetDstClientId, TargetRelay, TargetSrcChain, TargetSrcClientId, }; -use ibc_relayer_components::runtime::traits::mutex::HasRuntimeWithMutex; +use ibc_relayer_components::runtime::traits::runtime::HasRuntime; use crate::batch::traits::channel::HasMessageBatchSenderTypes; use crate::std_prelude::*; @@ -61,8 +61,7 @@ where } #[async_trait] -pub trait CanBuildRelayWithBatch: - HasBiRelayType + HasRuntimeWithMutex + HasErrorType +pub trait CanBuildRelayWithBatch: HasBiRelayType + HasRuntime + HasErrorType where Target: RelayBuildTarget, Target::TargetRelay: HasMessageBatchSenderTypes, @@ -82,7 +81,7 @@ where #[async_trait] impl CanBuildRelayWithBatch for Build where - Build: HasBiRelayType + HasRuntimeWithMutex + HasErrorType + HasComponents, + Build: HasBiRelayType + HasRuntime + HasErrorType + HasComponents, Target: RelayBuildTarget, Target::TargetRelay: HasMessageBatchSenderTypes, Build::Components: RelayWithBatchBuilder, diff --git a/crates/relayer-components/src/build/components/chain/cache.rs b/crates/relayer-components/src/build/components/chain/cache.rs index 99fbbdbb2..27eba4c4f 100644 --- a/crates/relayer-components/src/build/components/chain/cache.rs +++ b/crates/relayer-components/src/build/components/chain/cache.rs @@ -19,6 +19,7 @@ where Build: HasChainCache + HasErrorType, InBuilder: ChainBuilder, Target: ChainBuildTarget, + Build::Runtime: HasMutex, { async fn build_chain( build: &Build, diff --git a/crates/relayer-components/src/build/components/relay/cache.rs b/crates/relayer-components/src/build/components/relay/cache.rs index 3b32fd41f..bed772982 100644 --- a/crates/relayer-components/src/build/components/relay/cache.rs +++ b/crates/relayer-components/src/build/components/relay/cache.rs @@ -24,6 +24,7 @@ where Build: HasRelayCache + HasErrorType, InBuilder: RelayBuilder, Target: RelayBuildTarget, + Build::Runtime: HasMutex, { async fn build_relay( build: &Build, diff --git a/crates/relayer-components/src/build/traits/cache.rs b/crates/relayer-components/src/build/traits/cache.rs index 440ee28aa..0d5dd110e 100644 --- a/crates/relayer-components/src/build/traits/cache.rs +++ b/crates/relayer-components/src/build/traits/cache.rs @@ -2,18 +2,21 @@ use crate::build::traits::birelay::HasBiRelayType; use crate::build::traits::target::chain::ChainBuildTarget; use crate::build::traits::target::relay::RelayBuildTarget; use crate::build::types::aliases::{TargetChainCache, TargetRelayCache}; -use crate::runtime::traits::mutex::HasRuntimeWithMutex; +use crate::runtime::traits::mutex::HasMutex; +use crate::runtime::traits::runtime::HasRuntime; -pub trait HasChainCache: HasBiRelayType + HasRuntimeWithMutex +pub trait HasChainCache: HasBiRelayType + HasRuntime where Target: ChainBuildTarget, + Self::Runtime: HasMutex, { fn chain_cache(&self) -> &TargetChainCache; } -pub trait HasRelayCache: HasBiRelayType + HasRuntimeWithMutex +pub trait HasRelayCache: HasBiRelayType + HasRuntime where Target: RelayBuildTarget, + Self::Runtime: HasMutex, { fn relay_cache(&self) -> &TargetRelayCache; } diff --git a/crates/relayer-components/src/components/default/closures/build.rs b/crates/relayer-components/src/components/default/closures/build.rs index 303ad2759..d2d472e54 100644 --- a/crates/relayer-components/src/components/default/closures/build.rs +++ b/crates/relayer-components/src/components/default/closures/build.rs @@ -13,6 +13,7 @@ use crate::chain::traits::types::ibc::HasIbcChainTypes; use crate::components::default::build::DefaultBuildComponents; use crate::relay::traits::chains::HasRelayChains; use crate::relay::traits::two_way::{HasTwoChainTypes, HasTwoWayRelay}; +use crate::runtime::traits::mutex::HasMutex; pub trait UseDefaultBuilderComponents: CanBuildBiRelay where @@ -41,6 +42,7 @@ where ChainB::ChainId: Ord + Clone, ChainA::ClientId: Ord + Clone, ChainB::ClientId: Ord + Clone, + Build::Runtime: HasMutex, BaseComponents: BiRelayFromRelayBuilder + RelayFromChainsBuilder + RelayFromChainsBuilder diff --git a/crates/relayer-components/src/relay/components/auto_relayers/event.rs b/crates/relayer-components/src/relay/components/auto_relayers/event.rs index 5e8af0c0e..64130e290 100644 --- a/crates/relayer-components/src/relay/components/auto_relayers/event.rs +++ b/crates/relayer-components/src/relay/components/auto_relayers/event.rs @@ -1,6 +1,6 @@ use core::marker::PhantomData; -use cgp_core::async_trait; +use cgp_core::{async_trait, HasErrorType}; use crate::chain::traits::event_subscription::HasEventSubscription; use crate::chain::traits::types::event::HasEventType; @@ -52,7 +52,7 @@ where Relay: CanRelayEvent + HasRuntime + Clone, Target: ChainTarget, Target::TargetChain: HasEventSubscription, - Runtime: HasSubscriptionType + CanMapStream + CanRunConcurrentTasks, + Runtime: HasSubscriptionType + CanMapStream + CanRunConcurrentTasks + HasErrorType, { async fn auto_relay(relay: &Relay, _target: Target) -> Result<(), Relay::Error> { let subscription = Target::target_chain(relay).event_subscription(); diff --git a/crates/relayer-components/src/runtime/traits/mutex.rs b/crates/relayer-components/src/runtime/traits/mutex.rs index 220428921..3b3c0a380 100644 --- a/crates/relayer-components/src/runtime/traits/mutex.rs +++ b/crates/relayer-components/src/runtime/traits/mutex.rs @@ -2,7 +2,6 @@ use core::ops::DerefMut; use cgp_core::{async_trait, Async}; -use crate::runtime::traits::runtime::HasRuntime; use crate::std_prelude::*; #[async_trait] @@ -15,15 +14,3 @@ pub trait HasMutex: Async { async fn acquire_mutex<'a, T: Async>(mutex: &'a Self::Mutex) -> Self::MutexGuard<'a, T>; } - -pub trait HasRuntimeWithMutex: HasRuntime { - type RuntimeWithMutex: HasMutex; -} - -impl HasRuntimeWithMutex for Context -where - Context: HasRuntime, - Context::Runtime: HasMutex, -{ - type RuntimeWithMutex = Context::Runtime; -} diff --git a/crates/relayer-components/src/runtime/traits/runtime.rs b/crates/relayer-components/src/runtime/traits/runtime.rs index c310da792..72172e45e 100644 --- a/crates/relayer-components/src/runtime/traits/runtime.rs +++ b/crates/relayer-components/src/runtime/traits/runtime.rs @@ -1,6 +1,6 @@ -use cgp_core::HasErrorType; +use cgp_core::{CanRaiseError, HasErrorType}; -pub trait HasRuntime: HasErrorType { +pub trait HasRuntime: HasErrorType + CanRaiseError<::Error> { type Runtime: HasErrorType; fn runtime(&self) -> &Self::Runtime; diff --git a/crates/relayer-cosmos-mock/src/impls/birelay.rs b/crates/relayer-cosmos-mock/src/impls/birelay.rs index a2ccd7aff..e1ca7594f 100644 --- a/crates/relayer-cosmos-mock/src/impls/birelay.rs +++ b/crates/relayer-cosmos-mock/src/impls/birelay.rs @@ -1,8 +1,9 @@ -use cgp_core::HasErrorType; +use cgp_core::{CanRaiseError, HasErrorType}; use ibc_relayer_components::relay::traits::two_way::{ HasTwoChainTypes, HasTwoWayRelay, HasTwoWayRelayTypes, }; use ibc_relayer_components::runtime::traits::runtime::HasRuntime; +use ibc_relayer_runtime::types::error::TokioRuntimeError; use ibc_relayer_runtime::types::runtime::TokioRuntimeContext; use crate::contexts::birelay::MockCosmosBiRelay; @@ -35,6 +36,16 @@ where } } +impl CanRaiseError for MockCosmosBiRelay +where + SrcChain: BasecoinEndpoint, + DstChain: BasecoinEndpoint, +{ + fn raise_error(e: TokioRuntimeError) -> Self::Error { + Error::source(e) + } +} + impl HasTwoChainTypes for MockCosmosBiRelay where ChainA: BasecoinEndpoint, diff --git a/crates/relayer-cosmos-mock/src/impls/chain.rs b/crates/relayer-cosmos-mock/src/impls/chain.rs index 32f724930..d7089fae0 100644 --- a/crates/relayer-cosmos-mock/src/impls/chain.rs +++ b/crates/relayer-cosmos-mock/src/impls/chain.rs @@ -3,7 +3,7 @@ use std::time::Duration; use async_trait::async_trait; use basecoin_app::modules::ibc::AnyConsensusState; -use cgp_core::{HasComponents, ProvideErrorType}; +use cgp_core::{ErrorRaiser, HasComponents, ProvideErrorType}; use ibc::clients::ics07_tendermint::client_state::{AllowUpdate, ClientState as TmClientState}; use ibc::clients::ics07_tendermint::consensus_state::ConsensusState as TmConsensusState; use ibc::clients::ics07_tendermint::header::Header; @@ -104,6 +104,14 @@ impl HasRuntime for MockCosmosContext { } } +impl ErrorRaiser, TokioRuntimeError> + for MockCosmosChainComponents +{ + fn raise_error(e: TokioRuntimeError) -> Error { + Error::source(e) + } +} + impl ChainIdTypeProvider> for MockCosmosChainComponents { diff --git a/crates/relayer-cosmos-mock/src/impls/relay.rs b/crates/relayer-cosmos-mock/src/impls/relay.rs index af0519c29..e909de018 100644 --- a/crates/relayer-cosmos-mock/src/impls/relay.rs +++ b/crates/relayer-cosmos-mock/src/impls/relay.rs @@ -2,7 +2,7 @@ use alloc::boxed::Box; use alloc::vec::Vec; use async_trait::async_trait; -use cgp_core::{DelegateComponent, HasComponents, ProvideErrorType}; +use cgp_core::{DelegateComponent, ErrorRaiser, HasComponents, ProvideErrorType}; use ibc::clients::ics07_tendermint::client_type; use ibc::clients::ics07_tendermint::header::Header; use ibc::core::ics02_client::msgs::update_client::MsgUpdateClient; @@ -76,6 +76,17 @@ where } } +impl ErrorRaiser, TokioRuntimeError> + for MockCosmosRelayComponents +where + SrcChain: BasecoinEndpoint, + DstChain: BasecoinEndpoint, +{ + fn raise_error(e: TokioRuntimeError) -> Error { + Error::source(e) + } +} + impl HasRelayChains for MockCosmosRelay where SrcChain: BasecoinEndpoint, diff --git a/crates/relayer-cosmos/src/impls/birelay/components.rs b/crates/relayer-cosmos/src/impls/birelay/components.rs index 26029dd29..b071b640a 100644 --- a/crates/relayer-cosmos/src/impls/birelay/components.rs +++ b/crates/relayer-cosmos/src/impls/birelay/components.rs @@ -1,4 +1,6 @@ use cgp_core::prelude::*; +use cgp_core::ErrorRaiserComponent; +use cgp_core::ErrorTypeComponent; use ibc_relayer_components::logger::traits::has_logger::{ LoggerFieldComponent, LoggerTypeComponent, }; @@ -6,6 +8,7 @@ use ibc_relayer_components_extra::components::extra::birelay::ExtraBiRelayCompon use ibc_relayer_runtime::impls::logger::components::ProvideTracingLogger; use crate::contexts::birelay::CosmosBiRelay; +use crate::impls::error::HandleCosmosError; pub struct CosmosBiRelayComponents; @@ -19,6 +22,11 @@ where delegate_components!( CosmosBiRelayComponents; + [ + ErrorTypeComponent, + ErrorRaiserComponent, + ]: + HandleCosmosError, [ LoggerTypeComponent, LoggerFieldComponent, diff --git a/crates/relayer-cosmos/src/impls/birelay/types.rs b/crates/relayer-cosmos/src/impls/birelay/types.rs index f48a3e9bd..9169e76dc 100644 --- a/crates/relayer-cosmos/src/impls/birelay/types.rs +++ b/crates/relayer-cosmos/src/impls/birelay/types.rs @@ -1,4 +1,4 @@ -use cgp_core::{Async, ProvideErrorType}; +use cgp_core::Async; use ibc_relayer::chain::handle::ChainHandle; use ibc_relayer_components::relay::traits::two_way::{ HasTwoChainTypes, HasTwoWayRelay, HasTwoWayRelayTypes, @@ -10,7 +10,6 @@ use ibc_relayer_runtime::types::runtime::TokioRuntimeContext; use crate::contexts::birelay::CosmosBiRelay; use crate::contexts::chain::CosmosChain; use crate::contexts::relay::CosmosRelay; -use crate::impls::birelay::components::CosmosBiRelayComponents; use crate::types::error::{BaseError, Error}; impl HasTwoChainTypes for CosmosBiRelay @@ -51,14 +50,6 @@ where } } -impl ProvideErrorType> for CosmosBiRelayComponents -where - ChainA: Async, - ChainB: Async, -{ - type Error = Error; -} - impl HasRuntime for CosmosBiRelay where ChainA: Async, diff --git a/crates/relayer-cosmos/src/impls/build/components.rs b/crates/relayer-cosmos/src/impls/build/components.rs index 3be4a057c..ec2a0c933 100644 --- a/crates/relayer-cosmos/src/impls/build/components.rs +++ b/crates/relayer-cosmos/src/impls/build/components.rs @@ -1,4 +1,6 @@ use cgp_core::prelude::*; +use cgp_core::ErrorRaiserComponent; +use cgp_core::ErrorTypeComponent; use ibc_relayer_components::logger::traits::has_logger::{ LoggerFieldComponent, LoggerTypeComponent, }; @@ -6,6 +8,7 @@ use ibc_relayer_components_extra::components::extra::build::ExtraBuildComponents use ibc_relayer_runtime::impls::logger::components::ProvideTracingLogger; use crate::contexts::builder::CosmosBuilder; +use crate::impls::error::HandleCosmosError; pub struct CosmosBuildComponents; @@ -15,6 +18,11 @@ impl HasComponents for CosmosBuilder { delegate_components!( CosmosBuildComponents; + [ + ErrorTypeComponent, + ErrorRaiserComponent, + ]: + HandleCosmosError, [ LoggerTypeComponent, LoggerFieldComponent, diff --git a/crates/relayer-cosmos/src/impls/build/types.rs b/crates/relayer-cosmos/src/impls/build/types.rs index a818655fa..20f96f3de 100644 --- a/crates/relayer-cosmos/src/impls/build/types.rs +++ b/crates/relayer-cosmos/src/impls/build/types.rs @@ -1,4 +1,3 @@ -use cgp_core::ProvideErrorType; use ibc_relayer::chain::handle::BaseChainHandle; use ibc_relayer_components::build::traits::birelay::HasBiRelayType; use ibc_relayer_components::runtime::traits::runtime::HasRuntime; @@ -7,7 +6,6 @@ use ibc_relayer_runtime::types::runtime::TokioRuntimeContext; use crate::contexts::birelay::CosmosBiRelay; use crate::contexts::builder::CosmosBuilder; -use crate::impls::build::components::CosmosBuildComponents; use crate::types::error::{BaseError, Error}; impl HasBiRelayType for CosmosBuilder { @@ -18,10 +16,6 @@ impl HasBiRelayType for CosmosBuilder { } } -impl ProvideErrorType for CosmosBuildComponents { - type Error = Error; -} - impl HasRuntime for CosmosBuilder { type Runtime = TokioRuntimeContext; diff --git a/crates/relayer-cosmos/src/impls/chain/component.rs b/crates/relayer-cosmos/src/impls/chain/component.rs index b9dd0338c..0930a293e 100644 --- a/crates/relayer-cosmos/src/impls/chain/component.rs +++ b/crates/relayer-cosmos/src/impls/chain/component.rs @@ -1,4 +1,6 @@ use cgp_core::prelude::*; +use cgp_core::ErrorRaiserComponent; +use cgp_core::ErrorTypeComponent; use cosmos_client_components::components::ack_packet_message::BuildCosmosAckPacketMessage; use cosmos_client_components::components::ack_packet_payload::BuildCosmosAckPacketPayload; use cosmos_client_components::components::channel_handshake_message::BuildCosmosChannelHandshakeMessage; @@ -75,6 +77,7 @@ use crate::impls::chain::components::connection_handshake_message::DelegateCosmo use crate::impls::chain::components::create_client_message::DelegateCosmosCreateClientMessageBuilder; use crate::impls::chain::components::query_client_state::DelegateCosmosClientStateQuerier; use crate::impls::chain::components::query_consensus_state::DelegateCosmosConsensusStateQuerier; +use crate::impls::error::HandleCosmosError; pub struct CosmosChainComponents; @@ -95,6 +98,11 @@ where delegate_components!( CosmosChainComponents; + [ + ErrorTypeComponent, + ErrorRaiserComponent, + ]: + HandleCosmosError, [ HeightTypeProviderComponent, TimestampTypeProviderComponent, diff --git a/crates/relayer-cosmos/src/impls/chain/error.rs b/crates/relayer-cosmos/src/impls/chain/error.rs deleted file mode 100644 index 1ee636473..000000000 --- a/crates/relayer-cosmos/src/impls/chain/error.rs +++ /dev/null @@ -1,34 +0,0 @@ -use cgp_core::{Async, ErrorRaiser}; -use ibc_relayer::error::Error as RelayerError; -use ibc_relayer::supervisor::Error as SupervisorError; - -use crate::contexts::chain::CosmosChain; -use crate::impls::chain::component::CosmosChainComponents; -use crate::types::error::{BaseError, Error}; - -impl ErrorRaiser, RelayerError> for CosmosChainComponents -where - Chain: Async, -{ - fn raise_error(err: RelayerError) -> Error { - BaseError::relayer(err).into() - } -} - -impl ErrorRaiser, SupervisorError> for CosmosChainComponents -where - Chain: Async, -{ - fn raise_error(err: SupervisorError) -> Error { - BaseError::supervisor(err).into() - } -} - -impl ErrorRaiser, eyre::Report> for CosmosChainComponents -where - Chain: Async, -{ - fn raise_error(err: eyre::Report) -> Error { - BaseError::generic(err).into() - } -} diff --git a/crates/relayer-cosmos/src/impls/chain/mod.rs b/crates/relayer-cosmos/src/impls/chain/mod.rs index 41fea3973..9a4753987 100644 --- a/crates/relayer-cosmos/src/impls/chain/mod.rs +++ b/crates/relayer-cosmos/src/impls/chain/mod.rs @@ -1,6 +1,5 @@ pub mod component; pub mod components; -pub mod error; pub mod events; pub mod ext; pub mod fields; diff --git a/crates/relayer-cosmos/src/impls/chain/types.rs b/crates/relayer-cosmos/src/impls/chain/types.rs index e4a090e9f..b36c5bf33 100644 --- a/crates/relayer-cosmos/src/impls/chain/types.rs +++ b/crates/relayer-cosmos/src/impls/chain/types.rs @@ -1,4 +1,4 @@ -use cgp_core::{Async, ProvideErrorType}; +use cgp_core::Async; use cosmos_client_components::types::channel::CosmosInitChannelOptions; use cosmos_client_components::types::connection::CosmosInitConnectionOptions; use cosmos_client_components::types::payloads::channel::{ @@ -39,17 +39,9 @@ use ibc_relayer_runtime::types::error::TokioRuntimeError; use ibc_relayer_runtime::types::runtime::TokioRuntimeContext; use crate::contexts::chain::CosmosChain; -use crate::impls::chain::component::CosmosChainComponents; use crate::types::error::{BaseError, Error}; use crate::types::telemetry::CosmosTelemetry; -impl ProvideErrorType> for CosmosChainComponents -where - Chain: Async, -{ - type Error = Error; -} - impl HasRuntime for CosmosChain where Chain: Async, diff --git a/crates/relayer-cosmos/src/impls/error.rs b/crates/relayer-cosmos/src/impls/error.rs new file mode 100644 index 000000000..357a8b56b --- /dev/null +++ b/crates/relayer-cosmos/src/impls/error.rs @@ -0,0 +1,51 @@ +use cgp_core::{Async, ErrorRaiser, HasErrorType, ProvideErrorType}; +use ibc_relayer::error::Error as RelayerError; +use ibc_relayer::supervisor::Error as SupervisorError; +use ibc_relayer_runtime::types::error::TokioRuntimeError; + +use crate::types::error::{BaseError, Error}; + +pub struct HandleCosmosError; + +impl ProvideErrorType for HandleCosmosError +where + Context: Async, +{ + type Error = Error; +} + +impl ErrorRaiser for HandleCosmosError +where + Context: HasErrorType, +{ + fn raise_error(e: TokioRuntimeError) -> Error { + BaseError::tokio(e).into() + } +} + +impl ErrorRaiser for HandleCosmosError +where + Context: HasErrorType, +{ + fn raise_error(err: RelayerError) -> Error { + BaseError::relayer(err).into() + } +} + +impl ErrorRaiser for HandleCosmosError +where + Context: HasErrorType, +{ + fn raise_error(err: SupervisorError) -> Error { + BaseError::supervisor(err).into() + } +} + +impl ErrorRaiser for HandleCosmosError +where + Context: HasErrorType, +{ + fn raise_error(err: eyre::Report) -> Error { + BaseError::generic(err).into() + } +} diff --git a/crates/relayer-cosmos/src/impls/mod.rs b/crates/relayer-cosmos/src/impls/mod.rs index 51b7544f8..c6c785de4 100644 --- a/crates/relayer-cosmos/src/impls/mod.rs +++ b/crates/relayer-cosmos/src/impls/mod.rs @@ -1,6 +1,7 @@ pub mod birelay; pub mod build; pub mod chain; +pub mod error; pub mod relay; pub mod subscription; pub mod telemetry; diff --git a/crates/relayer-cosmos/src/impls/relay/component.rs b/crates/relayer-cosmos/src/impls/relay/component.rs index 57dcb0f50..15b55d12b 100644 --- a/crates/relayer-cosmos/src/impls/relay/component.rs +++ b/crates/relayer-cosmos/src/impls/relay/component.rs @@ -1,4 +1,6 @@ use cgp_core::prelude::*; +use cgp_core::ErrorRaiserComponent; +use cgp_core::ErrorTypeComponent; use ibc_relayer::chain::handle::ChainHandle; use ibc_relayer_components::logger::traits::has_logger::{ LoggerFieldComponent, LoggerTypeComponent, @@ -8,11 +10,17 @@ use ibc_relayer_components_extra::components::extra::relay::ExtraRelayComponents use ibc_relayer_runtime::impls::logger::components::ProvideTracingLogger; use crate::contexts::relay::CosmosRelay; +use crate::impls::error::HandleCosmosError; pub struct CosmosRelayComponents; delegate_components!( CosmosRelayComponents; + [ + ErrorTypeComponent, + ErrorRaiserComponent, + ]: + HandleCosmosError, [ LoggerTypeComponent, LoggerFieldComponent, diff --git a/crates/relayer-cosmos/src/impls/relay/types.rs b/crates/relayer-cosmos/src/impls/relay/types.rs index c2af128fb..0bbe4030d 100644 --- a/crates/relayer-cosmos/src/impls/relay/types.rs +++ b/crates/relayer-cosmos/src/impls/relay/types.rs @@ -1,4 +1,4 @@ -use cgp_core::{Async, ProvideErrorType}; +use cgp_core::Async; use ibc_relayer::chain::handle::ChainHandle; use ibc_relayer_components::relay::traits::chains::HasRelayChains; use ibc_relayer_components::runtime::traits::runtime::HasRuntime; @@ -9,7 +9,6 @@ use ibc_relayer_types::core::ics24_host::identifier::ClientId; use crate::contexts::chain::CosmosChain; use crate::contexts::relay::CosmosRelay; -use crate::impls::relay::component::CosmosRelayComponents; use crate::types::error::{BaseError, Error}; impl HasRelayChains for CosmosRelay @@ -48,14 +47,6 @@ where } } -impl ProvideErrorType> for CosmosRelayComponents -where - SrcChain: Async, - DstChain: Async, -{ - type Error = Error; -} - impl HasRuntime for CosmosRelay where SrcChain: Async, diff --git a/crates/relayer-cosmos/src/impls/transaction/component.rs b/crates/relayer-cosmos/src/impls/transaction/component.rs index 8b09c120d..84f698e02 100644 --- a/crates/relayer-cosmos/src/impls/transaction/component.rs +++ b/crates/relayer-cosmos/src/impls/transaction/component.rs @@ -1,4 +1,4 @@ -use cgp_core::{delegate_components, HasComponents}; +use cgp_core::{delegate_components, ErrorRaiserComponent, ErrorTypeComponent, HasComponents}; use cosmos_client_components::components::types::chain::ProvideCosmosChainTypes; use ibc_relayer_components::chain::traits::types::chain_id::ChainIdTypeProviderComponent; use ibc_relayer_components::chain::traits::types::event::EventTypeProviderComponent; @@ -10,6 +10,7 @@ use ibc_relayer_components_extra::components::extra::transaction::ExtraTxCompone use ibc_relayer_runtime::impls::logger::components::ProvideTracingLogger; use crate::contexts::transaction::CosmosTxContext; +use crate::impls::error::HandleCosmosError; pub struct CosmosTxComponents; @@ -19,6 +20,11 @@ impl HasComponents for CosmosTxContext { delegate_components!( CosmosTxComponents; + [ + ErrorTypeComponent, + ErrorRaiserComponent, + ]: + HandleCosmosError, [ ChainIdTypeProviderComponent, MessageTypeProviderComponent, diff --git a/crates/relayer-cosmos/src/impls/transaction/types.rs b/crates/relayer-cosmos/src/impls/transaction/types.rs index 16c4603fe..43e74a017 100644 --- a/crates/relayer-cosmos/src/impls/transaction/types.rs +++ b/crates/relayer-cosmos/src/impls/transaction/types.rs @@ -1,4 +1,3 @@ -use cgp_core::ProvideErrorType; use futures::lock::MutexGuard; use ibc_proto::cosmos::tx::v1beta1::{Fee, TxRaw}; use ibc_relayer::chain::cosmos::types::account::Account; @@ -14,13 +13,8 @@ use tendermint::Hash as TxHash; use tendermint_rpc::endpoint::tx::Response as TxResponse; use crate::contexts::transaction::CosmosTxContext; -use crate::impls::transaction::component::CosmosTxComponents; use crate::types::error::{BaseError, Error}; -impl ProvideErrorType for CosmosTxComponents { - type Error = Error; -} - impl HasRuntime for CosmosTxContext { type Runtime = TokioRuntimeContext; diff --git a/crates/relayer-mock/src/relayer_mock/base/impls/chain.rs b/crates/relayer-mock/src/relayer_mock/base/impls/chain.rs index 6a5111262..2a930d986 100644 --- a/crates/relayer-mock/src/relayer_mock/base/impls/chain.rs +++ b/crates/relayer-mock/src/relayer_mock/base/impls/chain.rs @@ -9,7 +9,9 @@ //! * The ChainStatus is a ConsensusState with a Height and a Timestamp. use async_trait::async_trait; -use cgp_core::{HasComponents, ProvideErrorType}; +use cgp_core::prelude::*; +use cgp_core::ErrorRaiserComponent; +use cgp_core::ErrorTypeComponent; use eyre::eyre; use ibc_relayer_components::chain::traits::components::ack_packet_message_builder::AckPacketMessageBuilder; use ibc_relayer_components::chain::traits::components::ack_packet_payload_builder::AckPacketPayloadBuilder; @@ -53,6 +55,7 @@ use ibc_relayer_runtime::types::error::TokioRuntimeError; use ibc_relayer_runtime::types::log::value::LogValue; use crate::relayer_mock::base::error::{BaseError, Error}; +use crate::relayer_mock::base::impls::error::HandleMockError; use crate::relayer_mock::base::types::aliases::{ ChainStatus, ChannelId, ClientId, ConsensusState, MockTimestamp, PortId, Sequence, }; @@ -69,9 +72,14 @@ impl HasComponents for MockChainContext { type Components = MockChainComponents; } -impl ProvideErrorType for MockChainComponents { - type Error = Error; -} +delegate_components!( + MockChainComponents; + [ + ErrorTypeComponent, + ErrorRaiserComponent, + ]: + HandleMockError, +); impl HasRuntime for MockChainContext { type Runtime = MockRuntimeContext; diff --git a/crates/relayer-mock/src/relayer_mock/base/impls/error.rs b/crates/relayer-mock/src/relayer_mock/base/impls/error.rs new file mode 100644 index 000000000..7996adfb7 --- /dev/null +++ b/crates/relayer-mock/src/relayer_mock/base/impls/error.rs @@ -0,0 +1,22 @@ +use cgp_core::{Async, ErrorRaiser, HasErrorType, ProvideErrorType}; +use ibc_relayer_runtime::types::error::TokioRuntimeError; + +use crate::relayer_mock::base::error::{BaseError, Error}; + +pub struct HandleMockError; + +impl ProvideErrorType for HandleMockError +where + Context: Async, +{ + type Error = Error; +} + +impl ErrorRaiser for HandleMockError +where + Context: HasErrorType, +{ + fn raise_error(e: TokioRuntimeError) -> Error { + BaseError::tokio(e).into() + } +} diff --git a/crates/relayer-mock/src/relayer_mock/base/impls/mod.rs b/crates/relayer-mock/src/relayer_mock/base/impls/mod.rs index d8d5e5ef6..8448980e2 100644 --- a/crates/relayer-mock/src/relayer_mock/base/impls/mod.rs +++ b/crates/relayer-mock/src/relayer_mock/base/impls/mod.rs @@ -1,2 +1,3 @@ pub mod chain; +pub mod error; pub mod relay; diff --git a/crates/relayer-mock/src/relayer_mock/base/impls/relay.rs b/crates/relayer-mock/src/relayer_mock/base/impls/relay.rs index 455614672..d77d0eaef 100644 --- a/crates/relayer-mock/src/relayer_mock/base/impls/relay.rs +++ b/crates/relayer-mock/src/relayer_mock/base/impls/relay.rs @@ -1,10 +1,11 @@ use alloc::boxed::Box; use alloc::string::ToString; use alloc::vec::Vec; +use cgp_core::{ErrorRaiserComponent, ErrorTypeComponent}; use std::vec; use async_trait::async_trait; -use cgp_core::{HasComponents, ProvideErrorType}; +use cgp_core::prelude::*; use ibc_relayer_components::relay::traits::chains::HasRelayChains; use ibc_relayer_components::relay::traits::components::update_client_message_builder::UpdateClientMessageBuilder; use ibc_relayer_components::relay::traits::packet_lock::HasPacketLock; @@ -13,6 +14,7 @@ use ibc_relayer_components::runtime::traits::runtime::HasRuntime; use ibc_relayer_runtime::types::error::TokioRuntimeError; use crate::relayer_mock::base::error::{BaseError, Error}; +use crate::relayer_mock::base::impls::error::HandleMockError; use crate::relayer_mock::base::types::aliases::ClientId; use crate::relayer_mock::base::types::height::Height as MockHeight; use crate::relayer_mock::base::types::message::Message as MockMessage; @@ -26,9 +28,14 @@ impl HasComponents for MockRelayContext { type Components = MockRelayComponents; } -impl ProvideErrorType for MockRelayComponents { - type Error = Error; -} +delegate_components!( + MockRelayComponents; + [ + ErrorTypeComponent, + ErrorRaiserComponent, + ]: + HandleMockError, +); impl HasRuntime for MockRelayContext { type Runtime = MockRuntimeContext; diff --git a/crates/relayer-solomachine/src/impls/chain/types.rs b/crates/relayer-solomachine/src/impls/chain/types.rs index 8ab10de16..40aadccb2 100644 --- a/crates/relayer-solomachine/src/impls/chain/types.rs +++ b/crates/relayer-solomachine/src/impls/chain/types.rs @@ -1,4 +1,4 @@ -use cgp_core::{Async, ProvideErrorType}; +use cgp_core::{Async, ErrorRaiser, ProvideErrorType}; use ibc_relayer_components::chain::traits::types::channel::{ HasChannelHandshakePayloads, HasInitChannelOptionsType, }; @@ -51,6 +51,15 @@ where type Error = Chain::Error; } +impl ErrorRaiser, TokioRuntimeError> for SolomachineChainComponents +where + Chain: Solomachine, +{ + fn raise_error(e: TokioRuntimeError) -> Chain::Error { + Chain::runtime_error(e) + } +} + impl HasRuntime for SolomachineChain where Chain: Solomachine, diff --git a/crates/relayer-solomachine/src/impls/relay/error.rs b/crates/relayer-solomachine/src/impls/relay/error.rs index ce547ff40..c97b81a24 100644 --- a/crates/relayer-solomachine/src/impls/relay/error.rs +++ b/crates/relayer-solomachine/src/impls/relay/error.rs @@ -15,7 +15,7 @@ where fn missing_create_client_event_error( src_chain: &Self::SrcChain, dst_chain: &Self::DstChain, - ) -> Self::Error { + ) -> Error { BaseError::generic(eyre!("missing CreateClient event when creating client from chain {} with counterparty chain {}", src_chain.chain_id(), dst_chain.chain_id(), @@ -30,7 +30,7 @@ where fn missing_create_client_event_error( dst_chain: &Self::DstChain, src_chain: &Self::SrcChain, - ) -> Self::Error { + ) -> Error { BaseError::generic(eyre!("missing CreateClient event when creating client from chain {} with counterparty chain {}", dst_chain.chain_id(), src_chain.chain_id(), diff --git a/crates/relayer-solomachine/src/impls/relay/types.rs b/crates/relayer-solomachine/src/impls/relay/types.rs index 227048b36..a78d9def3 100644 --- a/crates/relayer-solomachine/src/impls/relay/types.rs +++ b/crates/relayer-solomachine/src/impls/relay/types.rs @@ -1,4 +1,4 @@ -use cgp_core::{Async, ProvideErrorType}; +use cgp_core::{Async, ErrorRaiser, ProvideErrorType}; use ibc_relayer::chain::handle::BaseChainHandle; use ibc_relayer_components::relay::traits::chains::HasRelayChains; use ibc_relayer_components::runtime::traits::runtime::HasRuntime; @@ -22,6 +22,15 @@ where type Error = Error; } +impl ErrorRaiser, TokioRuntimeError> for SolomachineRelayComponents +where + Chain: Async, +{ + fn raise_error(e: TokioRuntimeError) -> Error { + BaseError::tokio(e).into() + } +} + impl HasRuntime for SolomachineRelay where Chain: Async, diff --git a/crates/relayer-solomachine/src/types/error.rs b/crates/relayer-solomachine/src/types/error.rs index 911074ced..3e2012621 100644 --- a/crates/relayer-solomachine/src/types/error.rs +++ b/crates/relayer-solomachine/src/types/error.rs @@ -18,7 +18,6 @@ define_error! { [ TraceError ] | _ | { "cosmos chain error" }, - Encode [ TraceError ] | _ | { "protobuf encode error" }, From ef1371c8586232432ffb2ba9215bfcacda243c4a Mon Sep 17 00:00:00 2001 From: Soares Chen Date: Mon, 18 Dec 2023 21:22:43 +0100 Subject: [PATCH 2/3] Remove HasRuntime::runtime_error method --- .../src/contexts/bootstrap.rs | 5 ----- .../src/bootstrap/impls/chain/start_chain.rs | 2 +- .../bootstrap/impls/genesis/add_genesis_account.rs | 2 +- .../bootstrap/impls/genesis/add_genesis_validator.rs | 2 +- .../src/bootstrap/impls/genesis/collect_gentxs.rs | 2 +- .../impls/genesis_legacy/add_genesis_account.rs | 2 +- .../impls/genesis_legacy/add_genesis_validator.rs | 6 +++--- .../bootstrap/impls/genesis_legacy/collect_gentxs.rs | 2 +- .../bootstrap/impls/initializers/init_chain_data.rs | 2 +- .../src/bootstrap/impls/initializers/init_wallet.rs | 4 ++-- .../impls/initializers/update_chain_config.rs | 12 ++++++------ .../impls/initializers/update_genesis_config.rs | 4 ++-- .../src/batch/components/message_sender.rs | 4 ++-- .../relayer-components/src/runtime/traits/runtime.rs | 2 -- crates/relayer-cosmos-mock/src/impls/birelay.rs | 4 ---- crates/relayer-cosmos-mock/src/impls/chain.rs | 4 ---- crates/relayer-cosmos-mock/src/impls/relay.rs | 4 ---- crates/relayer-cosmos/src/impls/birelay/types.rs | 7 +------ crates/relayer-cosmos/src/impls/build/types.rs | 7 +------ crates/relayer-cosmos/src/impls/chain/types.rs | 6 ------ crates/relayer-cosmos/src/impls/relay/types.rs | 7 +------ crates/relayer-cosmos/src/impls/transaction/types.rs | 6 ------ .../src/relayer_mock/base/impls/chain.rs | 5 ----- .../src/relayer_mock/base/impls/relay.rs | 7 +------ crates/relayer-solomachine/src/impls/chain/types.rs | 4 ---- crates/relayer-solomachine/src/impls/relay/types.rs | 4 ---- 26 files changed, 26 insertions(+), 90 deletions(-) diff --git a/crates/cosmos-integration-tests/src/contexts/bootstrap.rs b/crates/cosmos-integration-tests/src/contexts/bootstrap.rs index 1d6c43f82..dc3b4462f 100644 --- a/crates/cosmos-integration-tests/src/contexts/bootstrap.rs +++ b/crates/cosmos-integration-tests/src/contexts/bootstrap.rs @@ -16,7 +16,6 @@ use cosmos_test_components::chain::types::denom::Denom; use cosmos_test_components::chain::types::wallet::CosmosTestWallet; use eyre::Error; use ibc_relayer_components::runtime::traits::runtime::HasRuntime; -use ibc_relayer_runtime::types::error::TokioRuntimeError; use ibc_relayer_runtime::types::runtime::TokioRuntimeContext; use ibc_relayer_types::core::ics24_host::identifier::ChainId; use ibc_test_components::bootstrap::traits::types::chain::ProvideChainType; @@ -98,10 +97,6 @@ impl HasRuntime for CosmosStdBootstrapContext { fn runtime(&self) -> &TokioRuntimeContext { &self.runtime } - - fn runtime_error(e: TokioRuntimeError) -> Error { - e.into() - } } impl TestDirGetter for CosmosStdBootstrapComponents { diff --git a/crates/cosmos-test-components/src/bootstrap/impls/chain/start_chain.rs b/crates/cosmos-test-components/src/bootstrap/impls/chain/start_chain.rs index a3a365785..7be175f56 100644 --- a/crates/cosmos-test-components/src/bootstrap/impls/chain/start_chain.rs +++ b/crates/cosmos-test-components/src/bootstrap/impls/chain/start_chain.rs @@ -42,7 +42,7 @@ where .runtime() .start_child_process(chain_command, &args, Some(&stdout_path), Some(&stderr_path)) .await - .map_err(Bootstrap::runtime_error)?; + .map_err(Bootstrap::raise_error)?; Ok(child_process) } diff --git a/crates/cosmos-test-components/src/bootstrap/impls/genesis/add_genesis_account.rs b/crates/cosmos-test-components/src/bootstrap/impls/genesis/add_genesis_account.rs index 42c8cea8e..302479361 100644 --- a/crates/cosmos-test-components/src/bootstrap/impls/genesis/add_genesis_account.rs +++ b/crates/cosmos-test-components/src/bootstrap/impls/genesis/add_genesis_account.rs @@ -48,7 +48,7 @@ where ], ) .await - .map_err(Bootstrap::runtime_error)?; + .map_err(Bootstrap::raise_error)?; Ok(()) } diff --git a/crates/cosmos-test-components/src/bootstrap/impls/genesis/add_genesis_validator.rs b/crates/cosmos-test-components/src/bootstrap/impls/genesis/add_genesis_validator.rs index f00e4dee7..efdd35cce 100644 --- a/crates/cosmos-test-components/src/bootstrap/impls/genesis/add_genesis_validator.rs +++ b/crates/cosmos-test-components/src/bootstrap/impls/genesis/add_genesis_validator.rs @@ -51,7 +51,7 @@ where ], ) .await - .map_err(Bootstrap::runtime_error)?; + .map_err(Bootstrap::raise_error)?; Ok(()) } diff --git a/crates/cosmos-test-components/src/bootstrap/impls/genesis/collect_gentxs.rs b/crates/cosmos-test-components/src/bootstrap/impls/genesis/collect_gentxs.rs index f34b7167f..1c91f78b8 100644 --- a/crates/cosmos-test-components/src/bootstrap/impls/genesis/collect_gentxs.rs +++ b/crates/cosmos-test-components/src/bootstrap/impls/genesis/collect_gentxs.rs @@ -30,7 +30,7 @@ where ], ) .await - .map_err(Bootstrap::runtime_error)?; + .map_err(Bootstrap::raise_error)?; Ok(()) } diff --git a/crates/cosmos-test-components/src/bootstrap/impls/genesis_legacy/add_genesis_account.rs b/crates/cosmos-test-components/src/bootstrap/impls/genesis_legacy/add_genesis_account.rs index 13070c64e..c34813832 100644 --- a/crates/cosmos-test-components/src/bootstrap/impls/genesis_legacy/add_genesis_account.rs +++ b/crates/cosmos-test-components/src/bootstrap/impls/genesis_legacy/add_genesis_account.rs @@ -48,7 +48,7 @@ where ], ) .await - .map_err(Bootstrap::runtime_error)?; + .map_err(Bootstrap::raise_error)?; Ok(()) } diff --git a/crates/cosmos-test-components/src/bootstrap/impls/genesis_legacy/add_genesis_validator.rs b/crates/cosmos-test-components/src/bootstrap/impls/genesis_legacy/add_genesis_validator.rs index d6dd7f539..21b1c6d79 100644 --- a/crates/cosmos-test-components/src/bootstrap/impls/genesis_legacy/add_genesis_validator.rs +++ b/crates/cosmos-test-components/src/bootstrap/impls/genesis_legacy/add_genesis_validator.rs @@ -3,11 +3,11 @@ use ibc_relayer_components::chain::traits::types::chain_id::HasChainIdType; use ibc_relayer_components::runtime::traits::runtime::HasRuntime; use ibc_test_components::bootstrap::traits::types::chain::HasChainType; use ibc_test_components::chain::traits::types::amount::HasAmountType; +use ibc_test_components::runtime::traits::exec_command::CanExecCommand; +use ibc_test_components::runtime::traits::types::file_path::HasFilePathType; use crate::bootstrap::traits::fields::chain_command_path::HasChainCommandPath; use crate::bootstrap::traits::genesis::add_genesis_validator::GenesisValidatorAdder; -use ibc_test_components::runtime::traits::exec_command::CanExecCommand; -use ibc_test_components::runtime::traits::types::file_path::HasFilePathType; /** Implementation for adding genesis validator to legacy Cosmos chains @@ -51,7 +51,7 @@ where ], ) .await - .map_err(Bootstrap::runtime_error)?; + .map_err(Bootstrap::raise_error)?; Ok(()) } diff --git a/crates/cosmos-test-components/src/bootstrap/impls/genesis_legacy/collect_gentxs.rs b/crates/cosmos-test-components/src/bootstrap/impls/genesis_legacy/collect_gentxs.rs index 560804663..b1c992337 100644 --- a/crates/cosmos-test-components/src/bootstrap/impls/genesis_legacy/collect_gentxs.rs +++ b/crates/cosmos-test-components/src/bootstrap/impls/genesis_legacy/collect_gentxs.rs @@ -29,7 +29,7 @@ where ], ) .await - .map_err(Bootstrap::runtime_error)?; + .map_err(Bootstrap::raise_error)?; Ok(()) } diff --git a/crates/cosmos-test-components/src/bootstrap/impls/initializers/init_chain_data.rs b/crates/cosmos-test-components/src/bootstrap/impls/initializers/init_chain_data.rs index df491c07b..6e32c5951 100644 --- a/crates/cosmos-test-components/src/bootstrap/impls/initializers/init_chain_data.rs +++ b/crates/cosmos-test-components/src/bootstrap/impls/initializers/init_chain_data.rs @@ -39,7 +39,7 @@ where ], ) .await - .map_err(Bootstrap::runtime_error)?; + .map_err(Bootstrap::raise_error)?; Ok(()) } diff --git a/crates/cosmos-test-components/src/bootstrap/impls/initializers/init_wallet.rs b/crates/cosmos-test-components/src/bootstrap/impls/initializers/init_wallet.rs index dcfed2d01..f4e3f00a5 100644 --- a/crates/cosmos-test-components/src/bootstrap/impls/initializers/init_wallet.rs +++ b/crates/cosmos-test-components/src/bootstrap/impls/initializers/init_wallet.rs @@ -50,7 +50,7 @@ where ], ) .await - .map_err(Bootstrap::runtime_error)? + .map_err(Bootstrap::raise_error)? .stderr; let json_val: json::Value = json::from_str(&seed_content).map_err(Report::from)?; @@ -72,7 +72,7 @@ where .runtime() .write_string_to_file(&seed_path, &seed_content) .await - .map_err(Bootstrap::runtime_error)?; + .map_err(Bootstrap::raise_error)?; let hd_path = bootstrap.wallet_hd_path(); diff --git a/crates/cosmos-test-components/src/bootstrap/impls/initializers/update_chain_config.rs b/crates/cosmos-test-components/src/bootstrap/impls/initializers/update_chain_config.rs index 7bef9fbfe..a25ae25c1 100644 --- a/crates/cosmos-test-components/src/bootstrap/impls/initializers/update_chain_config.rs +++ b/crates/cosmos-test-components/src/bootstrap/impls/initializers/update_chain_config.rs @@ -35,19 +35,19 @@ where let rpc_port = runtime .reserve_tcp_port() .await - .map_err(Bootstrap::runtime_error)?; + .map_err(Bootstrap::raise_error)?; let p2p_port = runtime .reserve_tcp_port() .await - .map_err(Bootstrap::runtime_error)?; + .map_err(Bootstrap::raise_error)?; let pprof_port = runtime .reserve_tcp_port() .await - .map_err(Bootstrap::runtime_error)?; + .map_err(Bootstrap::raise_error)?; let grpc_port = runtime .reserve_tcp_port() .await - .map_err(Bootstrap::runtime_error)?; + .map_err(Bootstrap::raise_error)?; let comet_config = { let mut comet_config = { @@ -59,7 +59,7 @@ where let comet_config_string = runtime .read_file_as_string(&comet_config_path) .await - .map_err(Bootstrap::runtime_error)?; + .map_err(Bootstrap::raise_error)?; toml::from_str(&comet_config_string).map_err(Report::from)? }; @@ -88,7 +88,7 @@ where let sdk_config_string = runtime .read_file_as_string(&sdk_config_path) .await - .map_err(Bootstrap::runtime_error)?; + .map_err(Bootstrap::raise_error)?; toml::from_str(&sdk_config_string).map_err(Report::from)? }; diff --git a/crates/cosmos-test-components/src/bootstrap/impls/initializers/update_genesis_config.rs b/crates/cosmos-test-components/src/bootstrap/impls/initializers/update_genesis_config.rs index cb5607588..1a3fbb778 100644 --- a/crates/cosmos-test-components/src/bootstrap/impls/initializers/update_genesis_config.rs +++ b/crates/cosmos-test-components/src/bootstrap/impls/initializers/update_genesis_config.rs @@ -40,7 +40,7 @@ where let config_string = runtime .read_file_as_string(&genesis_file_path) .await - .map_err(Bootstrap::runtime_error)?; + .map_err(Bootstrap::raise_error)?; let mut config_json: Value = serde_json::from_str(&config_string).map_err(Report::from)?; @@ -52,7 +52,7 @@ where runtime .write_string_to_file(&genesis_file_path, &modified_config_string) .await - .map_err(Bootstrap::runtime_error)?; + .map_err(Bootstrap::raise_error)?; // TODO: generate random denom diff --git a/crates/relayer-components-extra/src/batch/components/message_sender.rs b/crates/relayer-components-extra/src/batch/components/message_sender.rs index 628382f8e..a59909fa9 100644 --- a/crates/relayer-components-extra/src/batch/components/message_sender.rs +++ b/crates/relayer-components-extra/src/batch/components/message_sender.rs @@ -37,12 +37,12 @@ where let message_sender = context.get_batch_sender(); Runtime::send(message_sender, (messages, result_sender)) - .map_err(TargetChain::runtime_error) + .map_err(TargetChain::raise_error) .map_err(Target::target_chain_error)?; let events = Runtime::receive_once(result_receiver) .await - .map_err(TargetChain::runtime_error) + .map_err(TargetChain::raise_error) .map_err(Target::target_chain_error)??; Ok(events) diff --git a/crates/relayer-components/src/runtime/traits/runtime.rs b/crates/relayer-components/src/runtime/traits/runtime.rs index 72172e45e..d3246afbf 100644 --- a/crates/relayer-components/src/runtime/traits/runtime.rs +++ b/crates/relayer-components/src/runtime/traits/runtime.rs @@ -4,6 +4,4 @@ pub trait HasRuntime: HasErrorType + CanRaiseError< &Self::Runtime; - - fn runtime_error(e: ::Error) -> Self::Error; } diff --git a/crates/relayer-cosmos-mock/src/impls/birelay.rs b/crates/relayer-cosmos-mock/src/impls/birelay.rs index e1ca7594f..76c9e437e 100644 --- a/crates/relayer-cosmos-mock/src/impls/birelay.rs +++ b/crates/relayer-cosmos-mock/src/impls/birelay.rs @@ -30,10 +30,6 @@ where fn runtime(&self) -> &Self::Runtime { &self.runtime } - - fn runtime_error(e: ::Error) -> Self::Error { - Error::source(e) - } } impl CanRaiseError for MockCosmosBiRelay diff --git a/crates/relayer-cosmos-mock/src/impls/chain.rs b/crates/relayer-cosmos-mock/src/impls/chain.rs index d7089fae0..35eab3873 100644 --- a/crates/relayer-cosmos-mock/src/impls/chain.rs +++ b/crates/relayer-cosmos-mock/src/impls/chain.rs @@ -98,10 +98,6 @@ impl HasRuntime for MockCosmosContext { fn runtime(&self) -> &Self::Runtime { &self.runtime } - - fn runtime_error(e: TokioRuntimeError) -> Error { - Error::source(e) - } } impl ErrorRaiser, TokioRuntimeError> diff --git a/crates/relayer-cosmos-mock/src/impls/relay.rs b/crates/relayer-cosmos-mock/src/impls/relay.rs index e909de018..40fb2c931 100644 --- a/crates/relayer-cosmos-mock/src/impls/relay.rs +++ b/crates/relayer-cosmos-mock/src/impls/relay.rs @@ -70,10 +70,6 @@ where fn runtime(&self) -> &Self::Runtime { &self.runtime } - - fn runtime_error(e: TokioRuntimeError) -> Error { - Error::source(e) - } } impl ErrorRaiser, TokioRuntimeError> diff --git a/crates/relayer-cosmos/src/impls/birelay/types.rs b/crates/relayer-cosmos/src/impls/birelay/types.rs index 9169e76dc..9171157fc 100644 --- a/crates/relayer-cosmos/src/impls/birelay/types.rs +++ b/crates/relayer-cosmos/src/impls/birelay/types.rs @@ -4,13 +4,12 @@ use ibc_relayer_components::relay::traits::two_way::{ HasTwoChainTypes, HasTwoWayRelay, HasTwoWayRelayTypes, }; use ibc_relayer_components::runtime::traits::runtime::HasRuntime; -use ibc_relayer_runtime::types::error::TokioRuntimeError; use ibc_relayer_runtime::types::runtime::TokioRuntimeContext; use crate::contexts::birelay::CosmosBiRelay; use crate::contexts::chain::CosmosChain; use crate::contexts::relay::CosmosRelay; -use crate::types::error::{BaseError, Error}; +use crate::types::error::Error; impl HasTwoChainTypes for CosmosBiRelay where @@ -60,8 +59,4 @@ where fn runtime(&self) -> &TokioRuntimeContext { &self.runtime } - - fn runtime_error(e: TokioRuntimeError) -> Error { - BaseError::tokio(e).into() - } } diff --git a/crates/relayer-cosmos/src/impls/build/types.rs b/crates/relayer-cosmos/src/impls/build/types.rs index 20f96f3de..fd3640423 100644 --- a/crates/relayer-cosmos/src/impls/build/types.rs +++ b/crates/relayer-cosmos/src/impls/build/types.rs @@ -1,12 +1,11 @@ use ibc_relayer::chain::handle::BaseChainHandle; use ibc_relayer_components::build::traits::birelay::HasBiRelayType; use ibc_relayer_components::runtime::traits::runtime::HasRuntime; -use ibc_relayer_runtime::types::error::TokioRuntimeError; use ibc_relayer_runtime::types::runtime::TokioRuntimeContext; use crate::contexts::birelay::CosmosBiRelay; use crate::contexts::builder::CosmosBuilder; -use crate::types::error::{BaseError, Error}; +use crate::types::error::Error; impl HasBiRelayType for CosmosBuilder { type BiRelay = CosmosBiRelay; @@ -22,8 +21,4 @@ impl HasRuntime for CosmosBuilder { fn runtime(&self) -> &TokioRuntimeContext { &self.runtime } - - fn runtime_error(e: TokioRuntimeError) -> Error { - BaseError::tokio(e).into() - } } diff --git a/crates/relayer-cosmos/src/impls/chain/types.rs b/crates/relayer-cosmos/src/impls/chain/types.rs index b36c5bf33..22e872ae7 100644 --- a/crates/relayer-cosmos/src/impls/chain/types.rs +++ b/crates/relayer-cosmos/src/impls/chain/types.rs @@ -35,11 +35,9 @@ use ibc_relayer_components::chain::traits::types::packets::timeout::HasTimeoutUn use ibc_relayer_components::chain::traits::types::update_client::HasUpdateClientPayload; use ibc_relayer_components::runtime::traits::runtime::HasRuntime; use ibc_relayer_components_extra::telemetry::traits::telemetry::HasTelemetry; -use ibc_relayer_runtime::types::error::TokioRuntimeError; use ibc_relayer_runtime::types::runtime::TokioRuntimeContext; use crate::contexts::chain::CosmosChain; -use crate::types::error::{BaseError, Error}; use crate::types::telemetry::CosmosTelemetry; impl HasRuntime for CosmosChain @@ -51,10 +49,6 @@ where fn runtime(&self) -> &TokioRuntimeContext { &self.runtime } - - fn runtime_error(e: TokioRuntimeError) -> Error { - BaseError::tokio(e).into() - } } impl HasTelemetry for CosmosChain diff --git a/crates/relayer-cosmos/src/impls/relay/types.rs b/crates/relayer-cosmos/src/impls/relay/types.rs index 0bbe4030d..d3adddc3b 100644 --- a/crates/relayer-cosmos/src/impls/relay/types.rs +++ b/crates/relayer-cosmos/src/impls/relay/types.rs @@ -2,14 +2,13 @@ use cgp_core::Async; use ibc_relayer::chain::handle::ChainHandle; use ibc_relayer_components::relay::traits::chains::HasRelayChains; use ibc_relayer_components::runtime::traits::runtime::HasRuntime; -use ibc_relayer_runtime::types::error::TokioRuntimeError; use ibc_relayer_runtime::types::runtime::TokioRuntimeContext; use ibc_relayer_types::core::ics04_channel::packet::Packet; use ibc_relayer_types::core::ics24_host::identifier::ClientId; use crate::contexts::chain::CosmosChain; use crate::contexts::relay::CosmosRelay; -use crate::types::error::{BaseError, Error}; +use crate::types::error::Error; impl HasRelayChains for CosmosRelay where @@ -57,8 +56,4 @@ where fn runtime(&self) -> &TokioRuntimeContext { &self.runtime } - - fn runtime_error(e: TokioRuntimeError) -> Error { - BaseError::tokio(e).into() - } } diff --git a/crates/relayer-cosmos/src/impls/transaction/types.rs b/crates/relayer-cosmos/src/impls/transaction/types.rs index 43e74a017..56e35396f 100644 --- a/crates/relayer-cosmos/src/impls/transaction/types.rs +++ b/crates/relayer-cosmos/src/impls/transaction/types.rs @@ -6,14 +6,12 @@ use ibc_relayer::keyring::Secp256k1KeyPair; use ibc_relayer_components::runtime::traits::runtime::HasRuntime; use ibc_relayer_components::transaction::traits::nonce::guard::HasNonceGuard; use ibc_relayer_components::transaction::traits::types::{HasNonceType, HasSignerType, HasTxTypes}; -use ibc_relayer_runtime::types::error::TokioRuntimeError; use ibc_relayer_runtime::types::runtime::TokioRuntimeContext; use prost::Message; use tendermint::Hash as TxHash; use tendermint_rpc::endpoint::tx::Response as TxResponse; use crate::contexts::transaction::CosmosTxContext; -use crate::types::error::{BaseError, Error}; impl HasRuntime for CosmosTxContext { type Runtime = TokioRuntimeContext; @@ -21,10 +19,6 @@ impl HasRuntime for CosmosTxContext { fn runtime(&self) -> &TokioRuntimeContext { &self.runtime } - - fn runtime_error(e: TokioRuntimeError) -> Error { - BaseError::tokio(e).into() - } } impl HasSignerType for CosmosTxContext { diff --git a/crates/relayer-mock/src/relayer_mock/base/impls/chain.rs b/crates/relayer-mock/src/relayer_mock/base/impls/chain.rs index 2a930d986..29558015d 100644 --- a/crates/relayer-mock/src/relayer_mock/base/impls/chain.rs +++ b/crates/relayer-mock/src/relayer_mock/base/impls/chain.rs @@ -51,7 +51,6 @@ use ibc_relayer_components::chain::traits::types::packets::timeout::HasTimeoutUn use ibc_relayer_components::chain::traits::types::status::ChainStatusTypeProvider; use ibc_relayer_components::chain::traits::types::timestamp::TimestampTypeProvider; use ibc_relayer_components::runtime::traits::runtime::HasRuntime; -use ibc_relayer_runtime::types::error::TokioRuntimeError; use ibc_relayer_runtime::types::log::value::LogValue; use crate::relayer_mock::base::error::{BaseError, Error}; @@ -87,10 +86,6 @@ impl HasRuntime for MockChainContext { fn runtime(&self) -> &Self::Runtime { &self.runtime } - - fn runtime_error(e: TokioRuntimeError) -> Error { - BaseError::tokio(e).into() - } } impl HeightTypeProvider for MockChainComponents { diff --git a/crates/relayer-mock/src/relayer_mock/base/impls/relay.rs b/crates/relayer-mock/src/relayer_mock/base/impls/relay.rs index d77d0eaef..0dc452aac 100644 --- a/crates/relayer-mock/src/relayer_mock/base/impls/relay.rs +++ b/crates/relayer-mock/src/relayer_mock/base/impls/relay.rs @@ -11,9 +11,8 @@ use ibc_relayer_components::relay::traits::components::update_client_message_bui use ibc_relayer_components::relay::traits::packet_lock::HasPacketLock; use ibc_relayer_components::relay::traits::target::{DestinationTarget, SourceTarget}; use ibc_relayer_components::runtime::traits::runtime::HasRuntime; -use ibc_relayer_runtime::types::error::TokioRuntimeError; -use crate::relayer_mock::base::error::{BaseError, Error}; +use crate::relayer_mock::base::error::Error; use crate::relayer_mock::base::impls::error::HandleMockError; use crate::relayer_mock::base::types::aliases::ClientId; use crate::relayer_mock::base::types::height::Height as MockHeight; @@ -43,10 +42,6 @@ impl HasRuntime for MockRelayContext { fn runtime(&self) -> &Self::Runtime { &self.runtime } - - fn runtime_error(e: TokioRuntimeError) -> Error { - BaseError::tokio(e).into() - } } impl HasRelayChains for MockRelayContext { diff --git a/crates/relayer-solomachine/src/impls/chain/types.rs b/crates/relayer-solomachine/src/impls/chain/types.rs index 40aadccb2..1601286a5 100644 --- a/crates/relayer-solomachine/src/impls/chain/types.rs +++ b/crates/relayer-solomachine/src/impls/chain/types.rs @@ -69,10 +69,6 @@ where fn runtime(&self) -> &TokioRuntimeContext { self.chain.runtime() } - - fn runtime_error(e: TokioRuntimeError) -> Chain::Error { - Chain::runtime_error(e) - } } impl HasClientStateType for SolomachineChain diff --git a/crates/relayer-solomachine/src/impls/relay/types.rs b/crates/relayer-solomachine/src/impls/relay/types.rs index a78d9def3..f0c4cca67 100644 --- a/crates/relayer-solomachine/src/impls/relay/types.rs +++ b/crates/relayer-solomachine/src/impls/relay/types.rs @@ -40,10 +40,6 @@ where fn runtime(&self) -> &Self::Runtime { todo!() } - - fn runtime_error(_e: TokioRuntimeError) -> Self::Error { - todo!() - } } impl HasRelayChains for SolomachineRelay From 1dc6f133393fd4ef33eac152ae932c52052e5917 Mon Sep 17 00:00:00 2001 From: Soares Chen Date: Mon, 18 Dec 2023 21:59:37 +0100 Subject: [PATCH 3/3] Introduce provider traits ProvideRuntimeType and ProvideRuntime --- .../src/contexts/bootstrap.rs | 13 +++++++------ .../src/bootstrap/components/cosmos_sdk.rs | 4 ++++ .../src/bootstrap/components/cosmos_sdk_legacy.rs | 4 ++++ .../src/batch/traits/channel.rs | 3 ++- .../src/components/extra/birelay.rs | 4 ++++ .../src/components/extra/build.rs | 4 ++++ .../src/components/extra/chain.rs | 4 ++++ .../src/components/extra/closures/batch.rs | 9 +++++---- .../components/extra/closures/relay/auto_relayer.rs | 6 +++--- .../src/components/extra/relay.rs | 4 ++++ .../src/components/extra/transaction.rs | 3 +++ .../relayer-components/src/build/types/aliases.rs | 5 +++-- .../src/components/default/birelay.rs | 4 ++++ .../src/components/default/build.rs | 4 ++++ .../src/components/default/chain.rs | 4 ++++ .../default/closures/relay/auto_relayer.rs | 6 +++--- .../src/components/default/relay.rs | 4 ++++ .../src/components/default/transaction.rs | 4 ++++ .../src/runtime/traits/runtime.rs | 11 +++++++++-- .../relayer-components/src/runtime/types/aliases.rs | 4 ++-- crates/relayer-cosmos-mock/src/components/chain.rs | 4 ++++ crates/relayer-cosmos-mock/src/components/relay.rs | 4 ++++ crates/relayer-cosmos-mock/src/impls/birelay.rs | 10 ++++++++-- crates/relayer-cosmos-mock/src/impls/chain.rs | 12 ++++++------ crates/relayer-cosmos-mock/src/impls/relay.rs | 11 +++++------ .../relayer-cosmos/src/impls/birelay/components.rs | 4 ++++ crates/relayer-cosmos/src/impls/birelay/types.rs | 11 +++++------ crates/relayer-cosmos/src/impls/build/components.rs | 4 ++++ crates/relayer-cosmos/src/impls/build/types.rs | 11 +++++------ crates/relayer-cosmos/src/impls/chain/component.rs | 4 ++++ crates/relayer-cosmos/src/impls/chain/types.rs | 11 +++++------ crates/relayer-cosmos/src/impls/relay/component.rs | 4 ++++ crates/relayer-cosmos/src/impls/relay/types.rs | 11 +++++------ .../src/impls/transaction/component.rs | 4 ++++ .../relayer-cosmos/src/impls/transaction/types.rs | 11 +++++------ .../src/relayer_mock/base/impls/chain.rs | 11 +++++++---- .../src/relayer_mock/base/impls/relay.rs | 10 ++++++---- crates/relayer-runtime/src/impls/mod.rs | 1 + crates/relayer-runtime/src/impls/types/mod.rs | 1 + crates/relayer-runtime/src/impls/types/runtime.rs | 13 +++++++++++++ .../src/impls/chain/component.rs | 4 ++++ crates/relayer-solomachine/src/impls/chain/types.rs | 10 ++++------ .../src/impls/relay/component.rs | 10 +++++++++- crates/relayer-solomachine/src/impls/relay/types.rs | 10 ++++------ 44 files changed, 202 insertions(+), 88 deletions(-) create mode 100644 crates/relayer-runtime/src/impls/types/mod.rs create mode 100644 crates/relayer-runtime/src/impls/types/runtime.rs diff --git a/crates/cosmos-integration-tests/src/contexts/bootstrap.rs b/crates/cosmos-integration-tests/src/contexts/bootstrap.rs index dc3b4462f..933b9e3ee 100644 --- a/crates/cosmos-integration-tests/src/contexts/bootstrap.rs +++ b/crates/cosmos-integration-tests/src/contexts/bootstrap.rs @@ -15,7 +15,8 @@ use cosmos_test_components::bootstrap::types::genesis_config::CosmosGenesisConfi use cosmos_test_components::chain::types::denom::Denom; use cosmos_test_components::chain::types::wallet::CosmosTestWallet; use eyre::Error; -use ibc_relayer_components::runtime::traits::runtime::HasRuntime; +use ibc_relayer_components::runtime::traits::runtime::{ProvideRuntime, RuntimeTypeComponent}; +use ibc_relayer_runtime::impls::types::runtime::ProvideTokioRuntimeType; use ibc_relayer_runtime::types::runtime::TokioRuntimeContext; use ibc_relayer_types::core::ics24_host::identifier::ChainId; use ibc_test_components::bootstrap::traits::types::chain::ProvideChainType; @@ -62,6 +63,8 @@ delegate_components!( ErrorRaiserComponent, ]: HandleErrorsWithEyre, + RuntimeTypeComponent: + ProvideTokioRuntimeType, ChainConfigTypeComponent: ProvideCosmosChainConfigType, GenesisConfigTypeComponent: ProvideCosmosGenesisConfigType, WalletConfigGeneratorComponent: GenerateStandardWalletConfig, @@ -91,11 +94,9 @@ impl ChainFromBootstrapParamsBuilder for CosmosStdBoo } } -impl HasRuntime for CosmosStdBootstrapContext { - type Runtime = TokioRuntimeContext; - - fn runtime(&self) -> &TokioRuntimeContext { - &self.runtime +impl ProvideRuntime for CosmosStdBootstrapComponents { + fn runtime(bootstrap: &CosmosStdBootstrapContext) -> &TokioRuntimeContext { + &bootstrap.runtime } } diff --git a/crates/cosmos-test-components/src/bootstrap/components/cosmos_sdk.rs b/crates/cosmos-test-components/src/bootstrap/components/cosmos_sdk.rs index 646cab5cc..ddbaa1402 100644 --- a/crates/cosmos-test-components/src/bootstrap/components/cosmos_sdk.rs +++ b/crates/cosmos-test-components/src/bootstrap/components/cosmos_sdk.rs @@ -3,6 +3,8 @@ use core::marker::PhantomData; use cgp_core::prelude::*; use cgp_core::ErrorRaiserComponent; use cgp_core::ErrorTypeComponent; +use ibc_relayer_components::runtime::traits::runtime::RuntimeComponent; +use ibc_relayer_components::runtime::traits::runtime::RuntimeTypeComponent; use ibc_test_components::bootstrap::traits::chain::ChainBootstrapperComponent; use ibc_test_components::bootstrap::traits::types::chain::ChainTypeComponent; @@ -71,6 +73,8 @@ delegate_components!( [ ErrorTypeComponent, ErrorRaiserComponent, + RuntimeTypeComponent, + RuntimeComponent, ChainTypeComponent, GenesisConfigTypeComponent, ChainConfigTypeComponent, diff --git a/crates/cosmos-test-components/src/bootstrap/components/cosmos_sdk_legacy.rs b/crates/cosmos-test-components/src/bootstrap/components/cosmos_sdk_legacy.rs index 8d792a2b5..ab692bffc 100644 --- a/crates/cosmos-test-components/src/bootstrap/components/cosmos_sdk_legacy.rs +++ b/crates/cosmos-test-components/src/bootstrap/components/cosmos_sdk_legacy.rs @@ -3,6 +3,8 @@ use core::marker::PhantomData; use cgp_core::prelude::*; use cgp_core::ErrorRaiserComponent; use cgp_core::ErrorTypeComponent; +use ibc_relayer_components::runtime::traits::runtime::RuntimeComponent; +use ibc_relayer_components::runtime::traits::runtime::RuntimeTypeComponent; use ibc_test_components::bootstrap::traits::chain::ChainBootstrapperComponent; use ibc_test_components::bootstrap::traits::types::chain::ChainTypeComponent; @@ -50,6 +52,8 @@ delegate_components!( [ ErrorTypeComponent, ErrorRaiserComponent, + RuntimeTypeComponent, + RuntimeComponent, ChainIdGeneratorComponent, ChainHomeDirInitializerComponent, ChainDataInitializerComponent, diff --git a/crates/relayer-components-extra/src/batch/traits/channel.rs b/crates/relayer-components-extra/src/batch/traits/channel.rs index b90b71331..cd69a661b 100644 --- a/crates/relayer-components-extra/src/batch/traits/channel.rs +++ b/crates/relayer-components-extra/src/batch/traits/channel.rs @@ -3,6 +3,7 @@ use ibc_relayer_components::chain::traits::types::chain::HasChainTypes; use ibc_relayer_components::relay::traits::chains::HasRelayChains; use ibc_relayer_components::relay::traits::target::ChainTarget; use ibc_relayer_components::runtime::traits::runtime::HasRuntime; +use ibc_relayer_components::runtime::types::aliases::Runtime; use crate::batch::types::aliases::MessageBatchSender; use crate::runtime::traits::channel::HasChannelTypes; @@ -12,7 +13,7 @@ pub trait HasMessageBatchSender: HasRelayChains where Target: ChainTarget, Target::TargetChain: HasRuntime, - ::Runtime: HasChannelTypes + HasChannelOnceTypes, + Runtime: HasChannelTypes + HasChannelOnceTypes, { fn get_batch_sender(&self) -> &MessageBatchSender; } diff --git a/crates/relayer-components-extra/src/components/extra/birelay.rs b/crates/relayer-components-extra/src/components/extra/birelay.rs index dd1ff836b..08b587752 100644 --- a/crates/relayer-components-extra/src/components/extra/birelay.rs +++ b/crates/relayer-components-extra/src/components/extra/birelay.rs @@ -8,6 +8,8 @@ use ibc_relayer_components::components::default::birelay::DefaultBiRelayComponen use ibc_relayer_components::logger::traits::has_logger::{ LoggerFieldComponent, LoggerTypeComponent, }; +use ibc_relayer_components::runtime::traits::runtime::RuntimeComponent; +use ibc_relayer_components::runtime::traits::runtime::RuntimeTypeComponent; pub struct ExtraBiRelayComponents(pub PhantomData); @@ -16,6 +18,8 @@ delegate_components!( [ ErrorTypeComponent, ErrorRaiserComponent, + RuntimeTypeComponent, + RuntimeComponent, RunnerComponent, LoggerTypeComponent, LoggerFieldComponent, diff --git a/crates/relayer-components-extra/src/components/extra/build.rs b/crates/relayer-components-extra/src/components/extra/build.rs index 6e0d4de27..783228250 100644 --- a/crates/relayer-components-extra/src/components/extra/build.rs +++ b/crates/relayer-components-extra/src/components/extra/build.rs @@ -12,6 +12,8 @@ use ibc_relayer_components::components::default::build::DefaultBuildComponents; use ibc_relayer_components::logger::traits::has_logger::{ LoggerFieldComponent, LoggerTypeComponent, }; +use ibc_relayer_components::runtime::traits::runtime::RuntimeComponent; +use ibc_relayer_components::runtime::traits::runtime::RuntimeTypeComponent; use crate::build::components::relay::batch::BuildRelayWithBatchWorker; use crate::build::traits::components::relay_with_batch_builder::RelayWithBatchBuilderComponent; @@ -25,6 +27,8 @@ delegate_components!( [ ErrorTypeComponent, ErrorRaiserComponent, + RuntimeTypeComponent, + RuntimeComponent, LoggerFieldComponent, LoggerTypeComponent, ChainBuilderComponent, diff --git a/crates/relayer-components-extra/src/components/extra/chain.rs b/crates/relayer-components-extra/src/components/extra/chain.rs index 73ab31e78..614da1854 100644 --- a/crates/relayer-components-extra/src/components/extra/chain.rs +++ b/crates/relayer-components-extra/src/components/extra/chain.rs @@ -47,6 +47,8 @@ use ibc_relayer_components::components::default::chain::DefaultChainComponents; use ibc_relayer_components::logger::traits::has_logger::{ LoggerFieldComponent, LoggerTypeComponent, }; +use ibc_relayer_components::runtime::traits::runtime::RuntimeComponent; +use ibc_relayer_components::runtime::traits::runtime::RuntimeTypeComponent; use crate::telemetry::components::consensus_state::ConsensusStateTelemetryQuerier; use crate::telemetry::components::status::ChainStatusTelemetryQuerier; @@ -62,6 +64,8 @@ delegate_components!( [ ErrorTypeComponent, ErrorRaiserComponent, + RuntimeTypeComponent, + RuntimeComponent, HeightTypeProviderComponent, TimestampTypeProviderComponent, ChainIdTypeProviderComponent, diff --git a/crates/relayer-components-extra/src/components/extra/closures/batch.rs b/crates/relayer-components-extra/src/components/extra/closures/batch.rs index 00b489ee3..2fc999d82 100644 --- a/crates/relayer-components-extra/src/components/extra/closures/batch.rs +++ b/crates/relayer-components-extra/src/components/extra/closures/batch.rs @@ -10,6 +10,7 @@ use ibc_relayer_components::runtime::traits::mutex::HasMutex; use ibc_relayer_components::runtime::traits::runtime::HasRuntime; use ibc_relayer_components::runtime::traits::sleep::CanSleep; use ibc_relayer_components::runtime::traits::time::HasTime; +use ibc_relayer_components::runtime::types::aliases::Runtime; use crate::batch::types::sink::BatchWorkerSink; use crate::batch::worker::CanSpawnBatchMessageWorker; @@ -21,8 +22,8 @@ pub trait CanUseBatchMessageWorkerSpawner: UseBatchMessageWorkerSpawner where Self::SrcChain: HasRuntime, Self::DstChain: HasRuntime, - ::Runtime: HasChannelTypes + HasChannelOnceTypes, - ::Runtime: HasChannelTypes + HasChannelOnceTypes, + Runtime: HasChannelTypes + HasChannelOnceTypes, + Runtime: HasChannelTypes + HasChannelOnceTypes, { } @@ -31,8 +32,8 @@ pub trait UseBatchMessageWorkerSpawner: where Self::SrcChain: HasRuntime, Self::DstChain: HasRuntime, - ::Runtime: HasChannelTypes + HasChannelOnceTypes, - ::Runtime: HasChannelTypes + HasChannelOnceTypes, + Runtime: HasChannelTypes + HasChannelOnceTypes, + Runtime: HasChannelTypes + HasChannelOnceTypes, { } diff --git a/crates/relayer-components-extra/src/components/extra/closures/relay/auto_relayer.rs b/crates/relayer-components-extra/src/components/extra/closures/relay/auto_relayer.rs index 13550891b..5cfd3bbcd 100644 --- a/crates/relayer-components-extra/src/components/extra/closures/relay/auto_relayer.rs +++ b/crates/relayer-components-extra/src/components/extra/closures/relay/auto_relayer.rs @@ -5,7 +5,7 @@ use ibc_relayer_components::chain::traits::types::chain_id::HasChainId; use ibc_relayer_components::logger::traits::has_logger::{HasLogger, HasLoggerType}; use ibc_relayer_components::logger::traits::level::HasBaseLogLevels; use ibc_relayer_components::relay::traits::chains::HasRelayChains; -use ibc_relayer_components::runtime::traits::runtime::HasRuntime; +use ibc_relayer_components::runtime::traits::runtime::{HasRuntime, HasRuntimeType}; use ibc_relayer_components::runtime::traits::stream::CanMapStream; use ibc_relayer_components::runtime::traits::subscription::HasSubscriptionType; use ibc_relayer_components::runtime::traits::task::CanRunConcurrentTasks; @@ -38,9 +38,9 @@ where + HasEventSubscription, Relay::Runtime: CanSpawnTask + CanRunConcurrentTasks, Relay::Logger: HasBaseLogLevels, - ::Runtime: + ::Runtime: HasSubscriptionType + CanRunConcurrentTasks + CanMapStream, - ::Runtime: + ::Runtime: HasSubscriptionType + CanRunConcurrentTasks + CanMapStream, BaseRelayComponents: Async, { diff --git a/crates/relayer-components-extra/src/components/extra/relay.rs b/crates/relayer-components-extra/src/components/extra/relay.rs index bded97024..d888b3823 100644 --- a/crates/relayer-components-extra/src/components/extra/relay.rs +++ b/crates/relayer-components-extra/src/components/extra/relay.rs @@ -36,6 +36,8 @@ use ibc_relayer_components::relay::traits::connection::open_confirm::ConnectionO use ibc_relayer_components::relay::traits::connection::open_handshake::ConnectionOpenHandshakeRelayerComponent; use ibc_relayer_components::relay::traits::connection::open_init::ConnectionInitializerComponent; use ibc_relayer_components::relay::traits::connection::open_try::ConnectionOpenTryRelayerComponent; +use ibc_relayer_components::runtime::traits::runtime::RuntimeComponent; +use ibc_relayer_components::runtime::traits::runtime::RuntimeTypeComponent; use crate::batch::components::message_sender::SendMessagesToBatchWorker; use crate::batch::types::sink::BatchWorkerSink; @@ -53,6 +55,8 @@ delegate_components!( [ ErrorTypeComponent, ErrorRaiserComponent, + RuntimeTypeComponent, + RuntimeComponent, LoggerTypeComponent, LoggerFieldComponent, UpdateClientMessageBuilderComponent, diff --git a/crates/relayer-components-extra/src/components/extra/transaction.rs b/crates/relayer-components-extra/src/components/extra/transaction.rs index c4899d6c0..ca9dd5293 100644 --- a/crates/relayer-components-extra/src/components/extra/transaction.rs +++ b/crates/relayer-components-extra/src/components/extra/transaction.rs @@ -11,6 +11,7 @@ use ibc_relayer_components::components::default::transaction::DefaultTxComponent use ibc_relayer_components::logger::traits::has_logger::{ LoggerFieldComponent, LoggerTypeComponent, }; +use ibc_relayer_components::runtime::traits::runtime::{RuntimeComponent, RuntimeTypeComponent}; use ibc_relayer_components::transaction::traits::components::nonce_allocater::NonceAllocatorComponent; use ibc_relayer_components::transaction::traits::components::nonce_querier::NonceQuerierComponent; use ibc_relayer_components::transaction::traits::components::send_messages_with_signer::MessagesWithSignerSenderComponent; @@ -28,6 +29,8 @@ delegate_components!( [ ErrorTypeComponent, ErrorRaiserComponent, + RuntimeTypeComponent, + RuntimeComponent, LoggerTypeComponent, LoggerFieldComponent, ChainIdTypeProviderComponent, diff --git a/crates/relayer-components/src/build/types/aliases.rs b/crates/relayer-components/src/build/types/aliases.rs index 568a14bad..503ab28d3 100644 --- a/crates/relayer-components/src/build/types/aliases.rs +++ b/crates/relayer-components/src/build/types/aliases.rs @@ -9,7 +9,7 @@ use crate::chain::traits::types::chain_id::HasChainIdType; use crate::chain::traits::types::ibc::HasIbcChainTypes; use crate::relay::traits::chains::HasRelayChains; use crate::relay::traits::two_way::{HasTwoChainTypes, HasTwoWayRelayTypes}; -use crate::runtime::traits::runtime::HasRuntime; +use crate::runtime::traits::runtime::HasRuntimeType; use crate::runtime::types::aliases::Mutex; pub type BiRelay = ::BiRelay; @@ -64,7 +64,8 @@ pub type RelayBToACache = Mutex< pub type TargetChain = >::TargetChain; -pub type TargetChainRuntime = as HasRuntime>::Runtime; +pub type TargetChainRuntime = + as HasRuntimeType>::Runtime; pub type TargetChainId = as HasChainIdType>::ChainId; diff --git a/crates/relayer-components/src/components/default/birelay.rs b/crates/relayer-components/src/components/default/birelay.rs index 6474d886f..70b2baff2 100644 --- a/crates/relayer-components/src/components/default/birelay.rs +++ b/crates/relayer-components/src/components/default/birelay.rs @@ -7,6 +7,8 @@ use cgp_core::RunnerComponent; use crate::logger::traits::has_logger::{LoggerFieldComponent, LoggerTypeComponent}; use crate::relay::components::auto_relayers::both_ways::RelayBothWays; +use crate::runtime::traits::runtime::RuntimeComponent; +use crate::runtime::traits::runtime::RuntimeTypeComponent; pub struct DefaultBiRelayComponents(pub PhantomData); @@ -16,6 +18,8 @@ delegate_components!( [ ErrorTypeComponent, ErrorRaiserComponent, + RuntimeTypeComponent, + RuntimeComponent, LoggerTypeComponent, LoggerFieldComponent, ]: diff --git a/crates/relayer-components/src/components/default/build.rs b/crates/relayer-components/src/components/default/build.rs index 4ba289b0a..f9a4044a8 100644 --- a/crates/relayer-components/src/components/default/build.rs +++ b/crates/relayer-components/src/components/default/build.rs @@ -14,6 +14,8 @@ use crate::build::traits::components::chain_builder::ChainBuilderComponent; use crate::build::traits::components::relay_builder::RelayBuilderComponent; use crate::build::traits::components::relay_from_chains_builder::RelayFromChainsBuilderComponent; use crate::logger::traits::has_logger::{LoggerFieldComponent, LoggerTypeComponent}; +use crate::runtime::traits::runtime::RuntimeComponent; +use crate::runtime::traits::runtime::RuntimeTypeComponent; pub struct DefaultBuildComponents(pub PhantomData); @@ -25,6 +27,8 @@ delegate_components!( [ ErrorTypeComponent, ErrorRaiserComponent, + RuntimeTypeComponent, + RuntimeComponent, LoggerFieldComponent, LoggerTypeComponent, RelayFromChainsBuilderComponent, diff --git a/crates/relayer-components/src/components/default/chain.rs b/crates/relayer-components/src/components/default/chain.rs index 93e0cfb90..693063889 100644 --- a/crates/relayer-components/src/components/default/chain.rs +++ b/crates/relayer-components/src/components/default/chain.rs @@ -43,6 +43,8 @@ use crate::chain::traits::types::packet::IbcPacketTypesProviderComponent; use crate::chain::traits::types::status::ChainStatusTypeProviderComponent; use crate::chain::traits::types::timestamp::TimestampTypeProviderComponent; use crate::logger::traits::has_logger::{LoggerFieldComponent, LoggerTypeComponent}; +use crate::runtime::traits::runtime::RuntimeComponent; +use crate::runtime::traits::runtime::RuntimeTypeComponent; pub struct DefaultChainComponents(pub PhantomData); delegate_components!( @@ -50,6 +52,8 @@ delegate_components!( [ ErrorTypeComponent, ErrorRaiserComponent, + RuntimeTypeComponent, + RuntimeComponent, HeightTypeProviderComponent, TimestampTypeProviderComponent, ChainIdTypeProviderComponent, diff --git a/crates/relayer-components/src/components/default/closures/relay/auto_relayer.rs b/crates/relayer-components/src/components/default/closures/relay/auto_relayer.rs index 98f10649f..52446644f 100644 --- a/crates/relayer-components/src/components/default/closures/relay/auto_relayer.rs +++ b/crates/relayer-components/src/components/default/closures/relay/auto_relayer.rs @@ -4,7 +4,7 @@ use crate::chain::traits::event_subscription::HasEventSubscription; use crate::components::default::closures::relay::event_relayer::UseDefaultEventRelayer; use crate::components::default::relay::DefaultRelayComponents; use crate::relay::traits::chains::HasRelayChains; -use crate::runtime::traits::runtime::HasRuntime; +use crate::runtime::traits::runtime::{HasRuntime, HasRuntimeType}; use crate::runtime::traits::stream::CanMapStream; use crate::runtime::traits::subscription::HasSubscriptionType; use crate::runtime::traits::task::CanRunConcurrentTasks; @@ -23,9 +23,9 @@ where Relay::SrcChain: HasEventSubscription, Relay::DstChain: HasEventSubscription, Relay::Runtime: CanRunConcurrentTasks, - ::Runtime: + ::Runtime: HasSubscriptionType + CanRunConcurrentTasks + CanMapStream, - ::Runtime: + ::Runtime: HasSubscriptionType + CanRunConcurrentTasks + CanMapStream, BaseRelayComponents: Async, { diff --git a/crates/relayer-components/src/components/default/relay.rs b/crates/relayer-components/src/components/default/relay.rs index 687b7c6eb..7295c702e 100644 --- a/crates/relayer-components/src/components/default/relay.rs +++ b/crates/relayer-components/src/components/default/relay.rs @@ -55,6 +55,8 @@ use crate::relay::traits::connection::open_confirm::ConnectionOpenConfirmRelayer use crate::relay::traits::connection::open_handshake::ConnectionOpenHandshakeRelayerComponent; use crate::relay::traits::connection::open_init::ConnectionInitializerComponent; use crate::relay::traits::connection::open_try::ConnectionOpenTryRelayerComponent; +use crate::runtime::traits::runtime::RuntimeComponent; +use crate::runtime::traits::runtime::RuntimeTypeComponent; pub struct DefaultRelayComponents(pub PhantomData); @@ -84,6 +86,8 @@ delegate_components!( [ ErrorTypeComponent, ErrorRaiserComponent, + RuntimeTypeComponent, + RuntimeComponent, LoggerTypeComponent, LoggerFieldComponent, PacketFilterComponent, diff --git a/crates/relayer-components/src/components/default/transaction.rs b/crates/relayer-components/src/components/default/transaction.rs index 7c5cea9fe..aa0499d8f 100644 --- a/crates/relayer-components/src/components/default/transaction.rs +++ b/crates/relayer-components/src/components/default/transaction.rs @@ -9,6 +9,8 @@ use crate::chain::traits::types::chain_id::{ChainIdGetterComponent, ChainIdTypeP use crate::chain::traits::types::event::EventTypeProviderComponent; use crate::chain::traits::types::message::MessageTypeProviderComponent; use crate::logger::traits::has_logger::{LoggerFieldComponent, LoggerTypeComponent}; +use crate::runtime::traits::runtime::RuntimeComponent; +use crate::runtime::traits::runtime::RuntimeTypeComponent; use crate::transaction::components::allocate_nonce_and_send_messages::AllocateNonceAndSendMessages; use crate::transaction::components::allocate_nonce_with_mutex::AllocateNonceWithMutex; use crate::transaction::components::estimate_fees_and_send_tx::EstimateFeesAndSendTx; @@ -36,6 +38,8 @@ delegate_components!( [ ErrorTypeComponent, ErrorRaiserComponent, + RuntimeTypeComponent, + RuntimeComponent, LoggerTypeComponent, LoggerFieldComponent, ChainIdTypeProviderComponent, diff --git a/crates/relayer-components/src/runtime/traits/runtime.rs b/crates/relayer-components/src/runtime/traits/runtime.rs index d3246afbf..1d00fe8f7 100644 --- a/crates/relayer-components/src/runtime/traits/runtime.rs +++ b/crates/relayer-components/src/runtime/traits/runtime.rs @@ -1,7 +1,14 @@ -use cgp_core::{CanRaiseError, HasErrorType}; +use cgp_core::prelude::*; +use cgp_core::CanRaiseError; -pub trait HasRuntime: HasErrorType + CanRaiseError<::Error> { +#[derive_component(RuntimeTypeComponent, ProvideRuntimeType)] +pub trait HasRuntimeType: Async { type Runtime: HasErrorType; +} +#[derive_component(RuntimeComponent, ProvideRuntime)] +pub trait HasRuntime: + HasRuntimeType + CanRaiseError<::Error> +{ fn runtime(&self) -> &Self::Runtime; } diff --git a/crates/relayer-components/src/runtime/types/aliases.rs b/crates/relayer-components/src/runtime/types/aliases.rs index 46c76964b..6d75d8cd0 100644 --- a/crates/relayer-components/src/runtime/types/aliases.rs +++ b/crates/relayer-components/src/runtime/types/aliases.rs @@ -1,6 +1,6 @@ use crate::runtime::traits::mutex::HasMutex; -use crate::runtime::traits::runtime::HasRuntime; +use crate::runtime::traits::runtime::HasRuntimeType; -pub type Runtime = ::Runtime; +pub type Runtime = ::Runtime; pub type Mutex = as HasMutex>::Mutex; diff --git a/crates/relayer-cosmos-mock/src/components/chain.rs b/crates/relayer-cosmos-mock/src/components/chain.rs index dfbd8d3a6..e6d753bb4 100644 --- a/crates/relayer-cosmos-mock/src/components/chain.rs +++ b/crates/relayer-cosmos-mock/src/components/chain.rs @@ -2,7 +2,9 @@ use cgp_core::prelude::*; use ibc_relayer_components::logger::traits::has_logger::{ LoggerFieldComponent, LoggerTypeComponent, }; +use ibc_relayer_components::runtime::traits::runtime::RuntimeTypeComponent; use ibc_relayer_runtime::impls::logger::components::ProvideTracingLogger; +use ibc_relayer_runtime::impls::types::runtime::ProvideTokioRuntimeType; pub struct MockCosmosChainComponents; @@ -13,4 +15,6 @@ delegate_components!( LoggerFieldComponent, ]: ProvideTracingLogger, + RuntimeTypeComponent: + ProvideTokioRuntimeType, ); diff --git a/crates/relayer-cosmos-mock/src/components/relay.rs b/crates/relayer-cosmos-mock/src/components/relay.rs index 63118d8ae..510415fbb 100644 --- a/crates/relayer-cosmos-mock/src/components/relay.rs +++ b/crates/relayer-cosmos-mock/src/components/relay.rs @@ -17,7 +17,9 @@ use ibc_relayer_components::relay::traits::components::packet_relayers::receive_ use ibc_relayer_components::relay::traits::components::packet_relayers::timeout_unordered_packet::TimeoutUnorderedPacketRelayerComponent; use ibc_relayer_components::relay::traits::components::update_client_message_builder::UpdateClientMessageBuilderComponent; use cgp_core::delegate_components; +use ibc_relayer_components::runtime::traits::runtime::RuntimeTypeComponent; use ibc_relayer_runtime::impls::logger::components::ProvideTracingLogger; +use ibc_relayer_runtime::impls::types::runtime::ProvideTokioRuntimeType; use crate::impls::relay::MockCosmosBuildUpdateClientMessage; @@ -38,6 +40,8 @@ delegate_components!( TimeoutUnorderedPacketRelayerComponent: BaseTimeoutUnorderedPacketRelayer, PacketFilterComponent: AllowAll, + RuntimeTypeComponent: + ProvideTokioRuntimeType, [ LoggerTypeComponent, LoggerFieldComponent, diff --git a/crates/relayer-cosmos-mock/src/impls/birelay.rs b/crates/relayer-cosmos-mock/src/impls/birelay.rs index 76c9e437e..37bc5d8e7 100644 --- a/crates/relayer-cosmos-mock/src/impls/birelay.rs +++ b/crates/relayer-cosmos-mock/src/impls/birelay.rs @@ -2,7 +2,7 @@ use cgp_core::{CanRaiseError, HasErrorType}; use ibc_relayer_components::relay::traits::two_way::{ HasTwoChainTypes, HasTwoWayRelay, HasTwoWayRelayTypes, }; -use ibc_relayer_components::runtime::traits::runtime::HasRuntime; +use ibc_relayer_components::runtime::traits::runtime::{HasRuntime, HasRuntimeType}; use ibc_relayer_runtime::types::error::TokioRuntimeError; use ibc_relayer_runtime::types::runtime::TokioRuntimeContext; @@ -20,13 +20,19 @@ where type Error = Error; } -impl HasRuntime for MockCosmosBiRelay +impl HasRuntimeType for MockCosmosBiRelay where SrcChain: BasecoinEndpoint, DstChain: BasecoinEndpoint, { type Runtime = TokioRuntimeContext; +} +impl HasRuntime for MockCosmosBiRelay +where + SrcChain: BasecoinEndpoint, + DstChain: BasecoinEndpoint, +{ fn runtime(&self) -> &Self::Runtime { &self.runtime } diff --git a/crates/relayer-cosmos-mock/src/impls/chain.rs b/crates/relayer-cosmos-mock/src/impls/chain.rs index 35eab3873..abed4a785 100644 --- a/crates/relayer-cosmos-mock/src/impls/chain.rs +++ b/crates/relayer-cosmos-mock/src/impls/chain.rs @@ -70,7 +70,7 @@ use ibc_relayer_components::chain::traits::types::status::ChainStatusTypeProvide use ibc_relayer_components::chain::traits::types::timestamp::TimestampTypeProvider; use ibc_relayer_components::chain::traits::types::update_client::HasUpdateClientPayload; use ibc_relayer_components::components::default::chain::DefaultChainComponents; -use ibc_relayer_components::runtime::traits::runtime::HasRuntime; +use ibc_relayer_components::runtime::traits::runtime::ProvideRuntime; use ibc_relayer_runtime::types::error::TokioRuntimeError; use ibc_relayer_runtime::types::log::value::LogValue; use ibc_relayer_runtime::types::runtime::TokioRuntimeContext; @@ -92,11 +92,11 @@ impl ProvideErrorType> type Error = Error; } -impl HasRuntime for MockCosmosContext { - type Runtime = TokioRuntimeContext; - - fn runtime(&self) -> &Self::Runtime { - &self.runtime +impl ProvideRuntime> + for MockCosmosChainComponents +{ + fn runtime(chain: &MockCosmosContext) -> &TokioRuntimeContext { + &chain.runtime } } diff --git a/crates/relayer-cosmos-mock/src/impls/relay.rs b/crates/relayer-cosmos-mock/src/impls/relay.rs index 40fb2c931..5e2555d01 100644 --- a/crates/relayer-cosmos-mock/src/impls/relay.rs +++ b/crates/relayer-cosmos-mock/src/impls/relay.rs @@ -17,7 +17,7 @@ use ibc_relayer_components::relay::traits::chains::HasRelayChains; use ibc_relayer_components::relay::traits::components::update_client_message_builder::UpdateClientMessageBuilder; use ibc_relayer_components::relay::traits::packet_lock::HasPacketLock; use ibc_relayer_components::relay::traits::target::{DestinationTarget, SourceTarget}; -use ibc_relayer_components::runtime::traits::runtime::HasRuntime; +use ibc_relayer_components::runtime::traits::runtime::ProvideRuntime; use ibc_relayer_runtime::types::error::TokioRuntimeError; use ibc_relayer_runtime::types::runtime::TokioRuntimeContext; @@ -60,15 +60,14 @@ where type Error = Error; } -impl HasRuntime for MockCosmosRelay +impl ProvideRuntime> + for MockCosmosRelayComponents where SrcChain: BasecoinEndpoint, DstChain: BasecoinEndpoint, { - type Runtime = TokioRuntimeContext; - - fn runtime(&self) -> &Self::Runtime { - &self.runtime + fn runtime(relay: &MockCosmosRelay) -> &TokioRuntimeContext { + &relay.runtime } } diff --git a/crates/relayer-cosmos/src/impls/birelay/components.rs b/crates/relayer-cosmos/src/impls/birelay/components.rs index b071b640a..c470eb5a6 100644 --- a/crates/relayer-cosmos/src/impls/birelay/components.rs +++ b/crates/relayer-cosmos/src/impls/birelay/components.rs @@ -4,8 +4,10 @@ use cgp_core::ErrorTypeComponent; use ibc_relayer_components::logger::traits::has_logger::{ LoggerFieldComponent, LoggerTypeComponent, }; +use ibc_relayer_components::runtime::traits::runtime::RuntimeTypeComponent; use ibc_relayer_components_extra::components::extra::birelay::ExtraBiRelayComponents; use ibc_relayer_runtime::impls::logger::components::ProvideTracingLogger; +use ibc_relayer_runtime::impls::types::runtime::ProvideTokioRuntimeType; use crate::contexts::birelay::CosmosBiRelay; use crate::impls::error::HandleCosmosError; @@ -27,6 +29,8 @@ delegate_components!( ErrorRaiserComponent, ]: HandleCosmosError, + RuntimeTypeComponent: + ProvideTokioRuntimeType, [ LoggerTypeComponent, LoggerFieldComponent, diff --git a/crates/relayer-cosmos/src/impls/birelay/types.rs b/crates/relayer-cosmos/src/impls/birelay/types.rs index 9171157fc..7508ae8e1 100644 --- a/crates/relayer-cosmos/src/impls/birelay/types.rs +++ b/crates/relayer-cosmos/src/impls/birelay/types.rs @@ -3,12 +3,13 @@ use ibc_relayer::chain::handle::ChainHandle; use ibc_relayer_components::relay::traits::two_way::{ HasTwoChainTypes, HasTwoWayRelay, HasTwoWayRelayTypes, }; -use ibc_relayer_components::runtime::traits::runtime::HasRuntime; +use ibc_relayer_components::runtime::traits::runtime::ProvideRuntime; use ibc_relayer_runtime::types::runtime::TokioRuntimeContext; use crate::contexts::birelay::CosmosBiRelay; use crate::contexts::chain::CosmosChain; use crate::contexts::relay::CosmosRelay; +use crate::impls::birelay::components::CosmosBiRelayComponents; use crate::types::error::Error; impl HasTwoChainTypes for CosmosBiRelay @@ -49,14 +50,12 @@ where } } -impl HasRuntime for CosmosBiRelay +impl ProvideRuntime> for CosmosBiRelayComponents where ChainA: Async, ChainB: Async, { - type Runtime = TokioRuntimeContext; - - fn runtime(&self) -> &TokioRuntimeContext { - &self.runtime + fn runtime(birelay: &CosmosBiRelay) -> &TokioRuntimeContext { + &birelay.runtime } } diff --git a/crates/relayer-cosmos/src/impls/build/components.rs b/crates/relayer-cosmos/src/impls/build/components.rs index ec2a0c933..0ebf179e0 100644 --- a/crates/relayer-cosmos/src/impls/build/components.rs +++ b/crates/relayer-cosmos/src/impls/build/components.rs @@ -4,8 +4,10 @@ use cgp_core::ErrorTypeComponent; use ibc_relayer_components::logger::traits::has_logger::{ LoggerFieldComponent, LoggerTypeComponent, }; +use ibc_relayer_components::runtime::traits::runtime::RuntimeTypeComponent; use ibc_relayer_components_extra::components::extra::build::ExtraBuildComponents; use ibc_relayer_runtime::impls::logger::components::ProvideTracingLogger; +use ibc_relayer_runtime::impls::types::runtime::ProvideTokioRuntimeType; use crate::contexts::builder::CosmosBuilder; use crate::impls::error::HandleCosmosError; @@ -23,6 +25,8 @@ delegate_components!( ErrorRaiserComponent, ]: HandleCosmosError, + RuntimeTypeComponent: + ProvideTokioRuntimeType, [ LoggerTypeComponent, LoggerFieldComponent, diff --git a/crates/relayer-cosmos/src/impls/build/types.rs b/crates/relayer-cosmos/src/impls/build/types.rs index fd3640423..65de6e018 100644 --- a/crates/relayer-cosmos/src/impls/build/types.rs +++ b/crates/relayer-cosmos/src/impls/build/types.rs @@ -1,10 +1,11 @@ use ibc_relayer::chain::handle::BaseChainHandle; use ibc_relayer_components::build::traits::birelay::HasBiRelayType; -use ibc_relayer_components::runtime::traits::runtime::HasRuntime; +use ibc_relayer_components::runtime::traits::runtime::ProvideRuntime; use ibc_relayer_runtime::types::runtime::TokioRuntimeContext; use crate::contexts::birelay::CosmosBiRelay; use crate::contexts::builder::CosmosBuilder; +use crate::impls::build::components::CosmosBuildComponents; use crate::types::error::Error; impl HasBiRelayType for CosmosBuilder { @@ -15,10 +16,8 @@ impl HasBiRelayType for CosmosBuilder { } } -impl HasRuntime for CosmosBuilder { - type Runtime = TokioRuntimeContext; - - fn runtime(&self) -> &TokioRuntimeContext { - &self.runtime +impl ProvideRuntime for CosmosBuildComponents { + fn runtime(build: &CosmosBuilder) -> &TokioRuntimeContext { + &build.runtime } } diff --git a/crates/relayer-cosmos/src/impls/chain/component.rs b/crates/relayer-cosmos/src/impls/chain/component.rs index 0930a293e..a43324f5a 100644 --- a/crates/relayer-cosmos/src/impls/chain/component.rs +++ b/crates/relayer-cosmos/src/impls/chain/component.rs @@ -68,9 +68,11 @@ use ibc_relayer_components::chain::traits::types::timestamp::TimestampTypeProvid use ibc_relayer_components::logger::traits::has_logger::{ LoggerFieldComponent, LoggerTypeComponent, }; +use ibc_relayer_components::runtime::traits::runtime::RuntimeTypeComponent; use ibc_relayer_components_extra::components::extra::chain::ExtraChainComponents; use ibc_relayer_components_extra::components::extra::closures::chain::all::CanUseExtraChainComponents; use ibc_relayer_runtime::impls::logger::components::ProvideTracingLogger; +use ibc_relayer_runtime::impls::types::runtime::ProvideTokioRuntimeType; use crate::contexts::chain::CosmosChain; use crate::impls::chain::components::connection_handshake_message::DelegateCosmosConnectionHandshakeBuilder; @@ -103,6 +105,8 @@ delegate_components!( ErrorRaiserComponent, ]: HandleCosmosError, + RuntimeTypeComponent: + ProvideTokioRuntimeType, [ HeightTypeProviderComponent, TimestampTypeProviderComponent, diff --git a/crates/relayer-cosmos/src/impls/chain/types.rs b/crates/relayer-cosmos/src/impls/chain/types.rs index 22e872ae7..638b15d5e 100644 --- a/crates/relayer-cosmos/src/impls/chain/types.rs +++ b/crates/relayer-cosmos/src/impls/chain/types.rs @@ -33,21 +33,20 @@ use ibc_relayer_components::chain::traits::types::packets::ack::HasAckPacketPayl use ibc_relayer_components::chain::traits::types::packets::receive::HasReceivePacketPayload; use ibc_relayer_components::chain::traits::types::packets::timeout::HasTimeoutUnorderedPacketPayload; use ibc_relayer_components::chain::traits::types::update_client::HasUpdateClientPayload; -use ibc_relayer_components::runtime::traits::runtime::HasRuntime; +use ibc_relayer_components::runtime::traits::runtime::ProvideRuntime; use ibc_relayer_components_extra::telemetry::traits::telemetry::HasTelemetry; use ibc_relayer_runtime::types::runtime::TokioRuntimeContext; use crate::contexts::chain::CosmosChain; +use crate::impls::chain::component::CosmosChainComponents; use crate::types::telemetry::CosmosTelemetry; -impl HasRuntime for CosmosChain +impl ProvideRuntime> for CosmosChainComponents where Chain: Async, { - type Runtime = TokioRuntimeContext; - - fn runtime(&self) -> &TokioRuntimeContext { - &self.runtime + fn runtime(chain: &CosmosChain) -> &TokioRuntimeContext { + &chain.runtime } } diff --git a/crates/relayer-cosmos/src/impls/relay/component.rs b/crates/relayer-cosmos/src/impls/relay/component.rs index 15b55d12b..4cacda13f 100644 --- a/crates/relayer-cosmos/src/impls/relay/component.rs +++ b/crates/relayer-cosmos/src/impls/relay/component.rs @@ -5,9 +5,11 @@ use ibc_relayer::chain::handle::ChainHandle; use ibc_relayer_components::logger::traits::has_logger::{ LoggerFieldComponent, LoggerTypeComponent, }; +use ibc_relayer_components::runtime::traits::runtime::RuntimeTypeComponent; use ibc_relayer_components_extra::components::extra::closures::relay::auto_relayer::CanUseExtraAutoRelayer; use ibc_relayer_components_extra::components::extra::relay::ExtraRelayComponents; use ibc_relayer_runtime::impls::logger::components::ProvideTracingLogger; +use ibc_relayer_runtime::impls::types::runtime::ProvideTokioRuntimeType; use crate::contexts::relay::CosmosRelay; use crate::impls::error::HandleCosmosError; @@ -21,6 +23,8 @@ delegate_components!( ErrorRaiserComponent, ]: HandleCosmosError, + RuntimeTypeComponent: + ProvideTokioRuntimeType, [ LoggerTypeComponent, LoggerFieldComponent, diff --git a/crates/relayer-cosmos/src/impls/relay/types.rs b/crates/relayer-cosmos/src/impls/relay/types.rs index d3adddc3b..62a6207b9 100644 --- a/crates/relayer-cosmos/src/impls/relay/types.rs +++ b/crates/relayer-cosmos/src/impls/relay/types.rs @@ -1,13 +1,14 @@ use cgp_core::Async; use ibc_relayer::chain::handle::ChainHandle; use ibc_relayer_components::relay::traits::chains::HasRelayChains; -use ibc_relayer_components::runtime::traits::runtime::HasRuntime; +use ibc_relayer_components::runtime::traits::runtime::ProvideRuntime; use ibc_relayer_runtime::types::runtime::TokioRuntimeContext; use ibc_relayer_types::core::ics04_channel::packet::Packet; use ibc_relayer_types::core::ics24_host::identifier::ClientId; use crate::contexts::chain::CosmosChain; use crate::contexts::relay::CosmosRelay; +use crate::impls::relay::component::CosmosRelayComponents; use crate::types::error::Error; impl HasRelayChains for CosmosRelay @@ -46,14 +47,12 @@ where } } -impl HasRuntime for CosmosRelay +impl ProvideRuntime> for CosmosRelayComponents where SrcChain: Async, DstChain: Async, { - type Runtime = TokioRuntimeContext; - - fn runtime(&self) -> &TokioRuntimeContext { - &self.runtime + fn runtime(relay: &CosmosRelay) -> &TokioRuntimeContext { + &relay.runtime } } diff --git a/crates/relayer-cosmos/src/impls/transaction/component.rs b/crates/relayer-cosmos/src/impls/transaction/component.rs index 84f698e02..d108783ea 100644 --- a/crates/relayer-cosmos/src/impls/transaction/component.rs +++ b/crates/relayer-cosmos/src/impls/transaction/component.rs @@ -6,8 +6,10 @@ use ibc_relayer_components::chain::traits::types::message::MessageTypeProviderCo use ibc_relayer_components::logger::traits::has_logger::{ LoggerFieldComponent, LoggerTypeComponent, }; +use ibc_relayer_components::runtime::traits::runtime::RuntimeTypeComponent; use ibc_relayer_components_extra::components::extra::transaction::ExtraTxComponents; use ibc_relayer_runtime::impls::logger::components::ProvideTracingLogger; +use ibc_relayer_runtime::impls::types::runtime::ProvideTokioRuntimeType; use crate::contexts::transaction::CosmosTxContext; use crate::impls::error::HandleCosmosError; @@ -25,6 +27,8 @@ delegate_components!( ErrorRaiserComponent, ]: HandleCosmosError, + RuntimeTypeComponent: + ProvideTokioRuntimeType, [ ChainIdTypeProviderComponent, MessageTypeProviderComponent, diff --git a/crates/relayer-cosmos/src/impls/transaction/types.rs b/crates/relayer-cosmos/src/impls/transaction/types.rs index 56e35396f..f664d79df 100644 --- a/crates/relayer-cosmos/src/impls/transaction/types.rs +++ b/crates/relayer-cosmos/src/impls/transaction/types.rs @@ -3,7 +3,7 @@ use ibc_proto::cosmos::tx::v1beta1::{Fee, TxRaw}; use ibc_relayer::chain::cosmos::types::account::Account; use ibc_relayer::chain::cosmos::types::tx::SignedTx; use ibc_relayer::keyring::Secp256k1KeyPair; -use ibc_relayer_components::runtime::traits::runtime::HasRuntime; +use ibc_relayer_components::runtime::traits::runtime::ProvideRuntime; use ibc_relayer_components::transaction::traits::nonce::guard::HasNonceGuard; use ibc_relayer_components::transaction::traits::types::{HasNonceType, HasSignerType, HasTxTypes}; use ibc_relayer_runtime::types::runtime::TokioRuntimeContext; @@ -12,12 +12,11 @@ use tendermint::Hash as TxHash; use tendermint_rpc::endpoint::tx::Response as TxResponse; use crate::contexts::transaction::CosmosTxContext; +use crate::impls::transaction::component::CosmosTxComponents; -impl HasRuntime for CosmosTxContext { - type Runtime = TokioRuntimeContext; - - fn runtime(&self) -> &TokioRuntimeContext { - &self.runtime +impl ProvideRuntime for CosmosTxComponents { + fn runtime(chain: &CosmosTxContext) -> &TokioRuntimeContext { + &chain.runtime } } diff --git a/crates/relayer-mock/src/relayer_mock/base/impls/chain.rs b/crates/relayer-mock/src/relayer_mock/base/impls/chain.rs index 29558015d..5ee6fa9d9 100644 --- a/crates/relayer-mock/src/relayer_mock/base/impls/chain.rs +++ b/crates/relayer-mock/src/relayer_mock/base/impls/chain.rs @@ -50,7 +50,8 @@ use ibc_relayer_components::chain::traits::types::packets::receive::HasReceivePa use ibc_relayer_components::chain::traits::types::packets::timeout::HasTimeoutUnorderedPacketPayload; use ibc_relayer_components::chain::traits::types::status::ChainStatusTypeProvider; use ibc_relayer_components::chain::traits::types::timestamp::TimestampTypeProvider; -use ibc_relayer_components::runtime::traits::runtime::HasRuntime; +use ibc_relayer_components::runtime::traits::runtime::ProvideRuntime; +use ibc_relayer_components::runtime::traits::runtime::ProvideRuntimeType; use ibc_relayer_runtime::types::log::value::LogValue; use crate::relayer_mock::base::error::{BaseError, Error}; @@ -80,11 +81,13 @@ delegate_components!( HandleMockError, ); -impl HasRuntime for MockChainContext { +impl ProvideRuntimeType for MockChainComponents { type Runtime = MockRuntimeContext; +} - fn runtime(&self) -> &Self::Runtime { - &self.runtime +impl ProvideRuntime for MockChainComponents { + fn runtime(chain: &MockChainContext) -> &MockRuntimeContext { + &chain.runtime } } diff --git a/crates/relayer-mock/src/relayer_mock/base/impls/relay.rs b/crates/relayer-mock/src/relayer_mock/base/impls/relay.rs index 0dc452aac..03a6b44eb 100644 --- a/crates/relayer-mock/src/relayer_mock/base/impls/relay.rs +++ b/crates/relayer-mock/src/relayer_mock/base/impls/relay.rs @@ -10,7 +10,7 @@ use ibc_relayer_components::relay::traits::chains::HasRelayChains; use ibc_relayer_components::relay::traits::components::update_client_message_builder::UpdateClientMessageBuilder; use ibc_relayer_components::relay::traits::packet_lock::HasPacketLock; use ibc_relayer_components::relay::traits::target::{DestinationTarget, SourceTarget}; -use ibc_relayer_components::runtime::traits::runtime::HasRuntime; +use ibc_relayer_components::runtime::traits::runtime::{ProvideRuntime, ProvideRuntimeType}; use crate::relayer_mock::base::error::Error; use crate::relayer_mock::base::impls::error::HandleMockError; @@ -36,11 +36,13 @@ delegate_components!( HandleMockError, ); -impl HasRuntime for MockRelayContext { +impl ProvideRuntimeType for MockRelayComponents { type Runtime = MockRuntimeContext; +} - fn runtime(&self) -> &Self::Runtime { - &self.runtime +impl ProvideRuntime for MockRelayComponents { + fn runtime(relay: &MockRelayContext) -> &MockRuntimeContext { + &relay.runtime } } diff --git a/crates/relayer-runtime/src/impls/mod.rs b/crates/relayer-runtime/src/impls/mod.rs index 0984e2c7c..d23564f31 100644 --- a/crates/relayer-runtime/src/impls/mod.rs +++ b/crates/relayer-runtime/src/impls/mod.rs @@ -1,3 +1,4 @@ pub mod logger; pub mod runtime; pub mod task; +pub mod types; diff --git a/crates/relayer-runtime/src/impls/types/mod.rs b/crates/relayer-runtime/src/impls/types/mod.rs new file mode 100644 index 000000000..ea62c4145 --- /dev/null +++ b/crates/relayer-runtime/src/impls/types/mod.rs @@ -0,0 +1 @@ +pub mod runtime; diff --git a/crates/relayer-runtime/src/impls/types/runtime.rs b/crates/relayer-runtime/src/impls/types/runtime.rs new file mode 100644 index 000000000..815811e55 --- /dev/null +++ b/crates/relayer-runtime/src/impls/types/runtime.rs @@ -0,0 +1,13 @@ +use cgp_core::Async; +use ibc_relayer_components::runtime::traits::runtime::ProvideRuntimeType; + +use crate::types::runtime::TokioRuntimeContext; + +pub struct ProvideTokioRuntimeType; + +impl ProvideRuntimeType for ProvideTokioRuntimeType +where + Context: Async, +{ + type Runtime = TokioRuntimeContext; +} diff --git a/crates/relayer-solomachine/src/impls/chain/component.rs b/crates/relayer-solomachine/src/impls/chain/component.rs index 5efde4412..2e6a3f553 100644 --- a/crates/relayer-solomachine/src/impls/chain/component.rs +++ b/crates/relayer-solomachine/src/impls/chain/component.rs @@ -27,7 +27,9 @@ use ibc_relayer_components::components::default::chain::DefaultChainComponents; use ibc_relayer_components::logger::traits::has_logger::{ LoggerFieldComponent, LoggerTypeComponent, }; +use ibc_relayer_components::runtime::traits::runtime::RuntimeTypeComponent; use ibc_relayer_runtime::impls::logger::components::ProvideTracingLogger; +use ibc_relayer_runtime::impls::types::runtime::ProvideTokioRuntimeType; use crate::impls::chain::solomachine_components::channel_handshake_message::BuildCosmosToSolomachineChannelHandshakeMessage; use crate::impls::chain::solomachine_components::channel_handshake_payload::BuildSolomachineChannelHandshakePayloads; @@ -55,6 +57,8 @@ where delegate_components!( SolomachineChainComponents; + RuntimeTypeComponent: + ProvideTokioRuntimeType, [ HeightTypeProviderComponent, TimestampTypeProviderComponent, diff --git a/crates/relayer-solomachine/src/impls/chain/types.rs b/crates/relayer-solomachine/src/impls/chain/types.rs index 1601286a5..e97913163 100644 --- a/crates/relayer-solomachine/src/impls/chain/types.rs +++ b/crates/relayer-solomachine/src/impls/chain/types.rs @@ -15,7 +15,7 @@ use ibc_relayer_components::chain::traits::types::packets::ack::HasAckPacketPayl use ibc_relayer_components::chain::traits::types::packets::receive::HasReceivePacketPayload; use ibc_relayer_components::chain::traits::types::packets::timeout::HasTimeoutUnorderedPacketPayload; use ibc_relayer_components::chain::traits::types::update_client::HasUpdateClientPayload; -use ibc_relayer_components::runtime::traits::runtime::HasRuntime; +use ibc_relayer_components::runtime::traits::runtime::ProvideRuntime; use ibc_relayer_runtime::types::error::TokioRuntimeError; use ibc_relayer_runtime::types::runtime::TokioRuntimeContext; use ibc_relayer_types::core::ics24_host::identifier::{ClientId, ConnectionId}; @@ -60,14 +60,12 @@ where } } -impl HasRuntime for SolomachineChain +impl ProvideRuntime> for SolomachineChainComponents where Chain: Solomachine, { - type Runtime = TokioRuntimeContext; - - fn runtime(&self) -> &TokioRuntimeContext { - self.chain.runtime() + fn runtime(chain: &SolomachineChain) -> &TokioRuntimeContext { + chain.chain.runtime() } } diff --git a/crates/relayer-solomachine/src/impls/relay/component.rs b/crates/relayer-solomachine/src/impls/relay/component.rs index 0770dd401..81c70cdb7 100644 --- a/crates/relayer-solomachine/src/impls/relay/component.rs +++ b/crates/relayer-solomachine/src/impls/relay/component.rs @@ -1,5 +1,7 @@ -use cgp_core::{Async, HasComponents}; +use cgp_core::prelude::*; use ibc_relayer_components::components::default::relay::DefaultRelayComponents; +use ibc_relayer_components::runtime::traits::runtime::RuntimeTypeComponent; +use ibc_relayer_runtime::impls::types::runtime::ProvideTokioRuntimeType; use crate::context::relay::SolomachineRelay; @@ -11,3 +13,9 @@ where { type Components = DefaultRelayComponents; } + +delegate_components!( + SolomachineRelayComponents; + RuntimeTypeComponent: + ProvideTokioRuntimeType, +); diff --git a/crates/relayer-solomachine/src/impls/relay/types.rs b/crates/relayer-solomachine/src/impls/relay/types.rs index f0c4cca67..1919040ac 100644 --- a/crates/relayer-solomachine/src/impls/relay/types.rs +++ b/crates/relayer-solomachine/src/impls/relay/types.rs @@ -1,7 +1,7 @@ use cgp_core::{Async, ErrorRaiser, ProvideErrorType}; use ibc_relayer::chain::handle::BaseChainHandle; use ibc_relayer_components::relay::traits::chains::HasRelayChains; -use ibc_relayer_components::runtime::traits::runtime::HasRuntime; +use ibc_relayer_components::runtime::traits::runtime::ProvideRuntime; use ibc_relayer_cosmos::contexts::chain::CosmosChain; use ibc_relayer_cosmos::types::error::Error as CosmosError; use ibc_relayer_runtime::types::error::TokioRuntimeError; @@ -31,14 +31,12 @@ where } } -impl HasRuntime for SolomachineRelay +impl ProvideRuntime> for SolomachineRelayComponents where Chain: Async, { - type Runtime = TokioRuntimeContext; - - fn runtime(&self) -> &Self::Runtime { - todo!() + fn runtime(relay: &SolomachineRelay) -> &TokioRuntimeContext { + &relay.runtime } }