Skip to content

Commit

Permalink
Remove Async bounds in component traits and macros (#402)
Browse files Browse the repository at this point in the history
* Remove Async bounds in component traits and macros

* Reformat imports

* Use back main branch
  • Loading branch information
soareschen authored Aug 8, 2024
1 parent 659e5bb commit 668e550
Show file tree
Hide file tree
Showing 24 changed files with 54 additions and 42 deletions.
26 changes: 13 additions & 13 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use cgp_core::error::CanRaiseError;
use cgp_core::Async;
use hermes_encoding_components::traits::convert::CanConvert;
use hermes_encoding_components::traits::has_encoding::HasDefaultEncoding;
use hermes_relayer_components::chain::traits::message_builders::create_client::CreateClientMessageBuilder;
Expand All @@ -23,7 +24,8 @@ where
+ CanRaiseError<Encoding::Error>,
Counterparty: HasCreateClientPayloadType<Chain, CreateClientPayload = CosmosCreateClientPayload>
+ HasDefaultEncoding<Encoding = Encoding>,
Encoding: CanConvert<TendermintClientState, Any> + CanConvert<TendermintConsensusState, Any>,
Encoding:
Async + CanConvert<TendermintClientState, Any> + CanConvert<TendermintConsensusState, Any>,
{
async fn build_create_client_message(
_chain: &Chain,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use alloc::collections::BTreeMap;
use alloc::sync::Arc;
use ibc_relayer::config::{ChainConfig, Config};
use std::path::PathBuf;

use cgp_core::error::{ErrorRaiserComponent, ErrorTypeComponent};
Expand Down Expand Up @@ -41,6 +40,7 @@ use hermes_test_components::chain_driver::traits::proposal::vote::ProposalVoterC
use hermes_test_components::chain_driver::traits::types::chain::{ChainGetter, ProvideChainType};
use hermes_wasm_test_components::components::WasmChainDriverComponents;
use hermes_wasm_test_components::traits::chain_driver::upload_client_code::WasmClientCodeUploaderComponent;
use ibc_relayer::config::{ChainConfig, Config};
use tokio::process::Child;
use tokio::sync::Mutex;
use toml::{to_string_pretty, Value};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use alloc::collections::BTreeMap;
use alloc::sync::Arc;
use std::path::PathBuf;
use tokio::sync::Mutex;

use cgp_core::error::CanRaiseError;
use hermes_cosmos_relayer::contexts::chain::CosmosChain;
Expand All @@ -21,6 +20,7 @@ use hermes_runtime_components::traits::runtime::HasRuntimeType;
use hermes_test_components::chain_driver::traits::types::chain::HasChainType;
use hermes_test_components::driver::traits::types::chain_driver::HasChainDriverType;
use tokio::process::Child;
use tokio::sync::Mutex;

use crate::contexts::chain_driver::CosmosChainDriver;
use crate::traits::bootstrap::build_chain::CanBuildChainWithNodeConfig;
Expand Down
2 changes: 1 addition & 1 deletion crates/cosmos/cosmos-relayer/src/impls/error.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
use alloc::string::FromUtf8Error;
use core::convert::Infallible;
use core::num::ParseIntError;
use hermes_any_counterparty::impls::encoding::consensus_state::UnknownConsensusStateType;

use cgp_core::error::{DelegateErrorRaiser, ErrorRaiser, ErrorRaiserComponent, ErrorTypeComponent};
use cgp_core::prelude::*;
use eyre::Report;
use hermes_any_counterparty::impls::encoding::client_state::UnknownClientStateType;
use hermes_any_counterparty::impls::encoding::consensus_state::UnknownConsensusStateType;
use hermes_cosmos_chain_components::impls::queries::abci::AbciQueryError;
use hermes_cosmos_chain_components::impls::transaction::submit_tx::BroadcastTxError;
use hermes_error::handlers::debug::DebugError;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,6 @@ where
+ RelayWithBatchBuilder<Build, 0, 1>
+ RelayWithBatchBuilder<Build, 1, 0>
+ ProvideErrorType<Build>,
BaseComponents: ChainBuilder<Build, 0> + ChainBuilder<Build, 1>,
BaseComponents: Async + ChainBuilder<Build, 0> + ChainBuilder<Build, 1>,
{
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use cgp_core::prelude::{async_trait, HasErrorType};
use cgp_core::Async;

use crate::build::impls::bootstrap::relay::CanBootstrapRelay;
use crate::build::traits::builders::birelay_builder::CanBuildBiRelay;
Expand Down Expand Up @@ -41,17 +42,20 @@ pub trait CanBootstrapBiRelay<const A: usize, const B: usize>:

impl<Build, ChainA, ChainB, const A: usize, const B: usize> CanBootstrapBiRelay<A, B> for Build
where
Build: HasBiRelayTypeAt<A, B>
Build: Async
+ HasBiRelayTypeAt<A, B>
+ HasChainTypeAt<A, Chain = ChainA>
+ HasChainTypeAt<B, Chain = ChainB>
+ CanBuildBiRelay<A, B>
+ CanBootstrapRelay<A, B>,
ChainA: HasChainIdType
ChainA: Async
+ HasChainIdType
+ HasCreateClientPayloadOptionsType<ChainB>
+ HasCreateClientMessageOptionsType<ChainB>
+ HasIbcChainTypes<ChainB>
+ HasErrorType,
ChainB: HasChainIdType
ChainB: Async
+ HasChainIdType
+ HasCreateClientPayloadOptionsType<ChainA>
+ HasCreateClientMessageOptionsType<ChainA>
+ HasIbcChainTypes<ChainA>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use alloc::vec::Vec;

use cgp_core::error::CanRaiseError;
use cgp_core::Async;
use hermes_encoding_components::traits::convert::CanConvert;
use hermes_encoding_components::traits::has_encoding::HasDefaultEncoding;

Expand All @@ -17,7 +18,7 @@ impl<Chain, Counterparty, Encoding> ClientStateQuerier<Chain, Counterparty>
where
Chain: CanQueryRawClientState<Counterparty> + CanRaiseError<Encoding::Error>,
Counterparty: HasClientStateType<Chain> + HasDefaultEncoding<Encoding = Encoding>,
Encoding: CanConvert<Chain::RawClientState, Counterparty::ClientState>,
Encoding: Async + CanConvert<Chain::RawClientState, Counterparty::ClientState>,
{
async fn query_client_state(
chain: &Chain,
Expand All @@ -39,7 +40,7 @@ impl<Chain, Counterparty, Encoding> ClientStateWithProofsQuerier<Chain, Counterp
where
Chain: CanQueryRawClientStateWithProofs<Counterparty> + CanRaiseError<Encoding::Error>,
Counterparty: HasClientStateType<Chain> + HasDefaultEncoding<Encoding = Encoding>,
Encoding: CanConvert<Chain::RawClientState, Counterparty::ClientState>,
Encoding: Async + CanConvert<Chain::RawClientState, Counterparty::ClientState>,
{
async fn query_client_state_with_proofs(
chain: &Chain,
Expand All @@ -63,7 +64,7 @@ impl<Chain, Counterparty, Encoding> AllClientStatesQuerier<Chain, Counterparty>
where
Chain: CanQueryAllRawClientStates<Counterparty>,
Counterparty: HasClientStateType<Chain> + HasDefaultEncoding<Encoding = Encoding>,
Encoding: CanConvert<Chain::RawClientState, Counterparty::ClientState>,
Encoding: Async + CanConvert<Chain::RawClientState, Counterparty::ClientState>,
{
async fn query_all_client_states(
chain: &Chain,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use cgp_core::error::CanRaiseError;
use cgp_core::Async;
use hermes_encoding_components::traits::convert::CanConvert;
use hermes_encoding_components::traits::has_encoding::HasDefaultEncoding;

Expand All @@ -17,7 +18,7 @@ where
Chain: CanQueryRawConsensusState<Counterparty> + CanRaiseError<Encoding::Error>,
Counterparty:
HasConsensusStateType<Chain> + HasDefaultEncoding<Encoding = Encoding> + HasHeightType,
Encoding: CanConvert<Chain::RawConsensusState, Counterparty::ConsensusState>,
Encoding: Async + CanConvert<Chain::RawConsensusState, Counterparty::ConsensusState>,
{
async fn query_consensus_state(
chain: &Chain,
Expand All @@ -43,7 +44,7 @@ where
Chain: CanQueryRawConsensusStateWithProofs<Counterparty> + CanRaiseError<Encoding::Error>,
Counterparty:
HasConsensusStateType<Chain> + HasDefaultEncoding<Encoding = Encoding> + HasHeightType,
Encoding: CanConvert<Chain::RawConsensusState, Counterparty::ConsensusState>,
Encoding: Async + CanConvert<Chain::RawConsensusState, Counterparty::ConsensusState>,
{
async fn query_consensus_state_with_proofs(
chain: &Chain,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ pub trait UseDefaultBuildComponents: CanBuildBiRelay<0, 1> {}

impl<Build, Components, BaseComponents> UseDefaultBuildComponents for Build
where
Build: HasBiRelayTypeAt<0, 1>
Build: Async
+ HasBiRelayTypeAt<0, 1>
+ HasRelayCache<0, 1>
+ HasRelayCache<1, 0>
+ HasChainCache<0>
Expand All @@ -49,6 +50,6 @@ where
+ RelayFromChainsBuilder<Build, 0, 1>
+ RelayFromChainsBuilder<Build, 1, 0>
+ ProvideErrorType<Build>,
BaseComponents: ChainBuilder<Build, 0> + ChainBuilder<Build, 1>,
BaseComponents: Async + ChainBuilder<Build, 0> + ChainBuilder<Build, 1>,
{
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use crate::multi::traits::relay_at::{HasRelayTypeAt, RelayAt};

#[derive_component(BiRelayTypeAtComponent, ProvideBiRelayTypeAt<Setup>)]
pub trait HasBiRelayTypeAt<const A: usize, const B: usize>:
HasRelayTypeAt<A, B> + HasRelayTypeAt<B, A>
Async + HasRelayTypeAt<A, B> + HasRelayTypeAt<B, A>
{
type BiRelay: HasChainTypeAt<A, Chain = ChainAt<Self, A>>
+ HasChainTypeAt<B, Chain = ChainAt<Self, B>>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ use crate::relay::traits::chains::HasRelayChains;

#[derive_component(RelayTypeAtComponent, ProvideRelayTypeAt<Context>)]
pub trait HasRelayTypeAt<const SRC: usize, const DST: usize>:
HasChainTypeAt<SRC, Chain: HasIbcChainTypes<ChainAt<Self, DST>>>
Async
+ HasChainTypeAt<SRC, Chain: HasIbcChainTypes<ChainAt<Self, DST>>>
+ HasChainTypeAt<DST, Chain: HasIbcChainTypes<ChainAt<Self, SRC>>>
{
type Relay: HasRelayChains<SrcChain = ChainAt<Self, SRC>, DstChain = ChainAt<Self, DST>>;
Expand Down
3 changes: 2 additions & 1 deletion crates/relayer/relayer-components/src/relay/impls/fields.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ impl<
> ProvideRelayChains<Relay>
for ProvideRelayFields<SrcChainField, DstChainField, SrcClientIdField, DstClientIdField>
where
Relay: HasErrorType
Relay: Async
+ HasErrorType
+ HasField<SrcChainField, Field = SrcChain>
+ HasField<DstChainField, Field = DstChain>
+ HasField<SrcClientIdField, Field = SrcChain::ClientId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ use crate::chain::types::aliases::ClientIdOf;
only a single channel or connection.
*/
#[derive_component(RelayChainsComponent, ProvideRelayChains<Relay>)]
pub trait HasRelayChains: HasErrorType {
pub trait HasRelayChains: Async + HasErrorType {
type Packet: Async;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ where

impl<Runtime, Components> HasUnboundedChannelType for Runtime
where
Runtime: HasComponents<Components = Components>,
Runtime: Async + HasComponents<Components = Components>,
Components: UnboundedChannelTypeProvider<Runtime> + ProvideChannelType<Runtime>,
{
fn from_unbounded_sender<T>(sender: Arc<Mutex<mpsc::UnboundedSender<T>>>) -> Self::Sender<T>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ pub trait HasBoxedStreamType: HasStreamType {

impl<Runtime, Components> HasBoxedStreamType for Runtime
where
Runtime: HasComponents<Components = Components>,
Runtime: Async + HasComponents<Components = Components>,
Components: BoxedStreamTypeProvider<Runtime>,
{
fn to_boxed_stream<Item>(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ use cgp_core::prelude::*;
#[derive_component(TcpPortReserverComponent, TcpPortReserver<Runtime>)]
/// Allocate a TCP port that the full node process use for listening
#[async_trait]
pub trait CanReserveTcpPort: HasErrorType {
pub trait CanReserveTcpPort: Async + HasErrorType {
async fn reserve_tcp_port(&self) -> Result<u16, Self::Error>;
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,8 @@ pub use hermes_runtime_components::traits::fs::file_path::FilePathTypeComponent;
pub use hermes_runtime_components::traits::fs::read_file::FileAsStringReaderComponent;
pub use hermes_runtime_components::traits::fs::write_file::StringToFileWriterComponent;
pub use hermes_runtime_components::traits::mutex::MutexComponent;
pub use hermes_runtime_components::traits::os::child_process::ChildProcessWaiterComponent;
pub use hermes_runtime_components::traits::os::child_process::{
ChildProcessStarterComponent, ChildProcessTypeComponent,
ChildProcessStarterComponent, ChildProcessTypeComponent, ChildProcessWaiterComponent,
};
pub use hermes_runtime_components::traits::os::exec_command::{
CommandExecutorComponent, CommandWithEnvsExecutorComponent,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ pub struct TokioReserveTcpPort;

impl<Runtime> TcpPortReserver<Runtime> for TokioReserveTcpPort
where
Runtime: CanRaiseError<IoError>,
Runtime: Async + CanRaiseError<IoError>,
{
async fn reserve_tcp_port(_runtime: &Runtime) -> Result<u16, Runtime::Error> {
// TODO: abort if failed to find a free port after X tries
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ where

impl<Runtime, Components> HasUnboundedChannelType for Runtime
where
Runtime: HasComponents<Components = Components>,
Runtime: Async + HasComponents<Components = Components>,
Components: UnboundedChannelTypeProvider<Runtime> + ProvideChannelType<Runtime>,
{
fn from_unbounded_sender<T>(sender: mpsc::UnboundedSender<T>) -> Self::Sender<T>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use alloc::string::String;

use cgp_core::prelude::*;

#[derive_component(ConfigUpdaterComponent, ConfigUpdater<ChainDriver>)]
Expand Down
Loading

0 comments on commit 668e550

Please sign in to comment.