Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce provider traits for HasRuntime #74

Merged
merged 3 commits into from
Dec 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 7 additions & 11 deletions crates/cosmos-integration-tests/src/contexts/bootstrap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +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_runtime::types::error::TokioRuntimeError;
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;
Expand Down Expand Up @@ -63,6 +63,8 @@ delegate_components!(
ErrorRaiserComponent,
]:
HandleErrorsWithEyre,
RuntimeTypeComponent:
ProvideTokioRuntimeType,
ChainConfigTypeComponent: ProvideCosmosChainConfigType,
GenesisConfigTypeComponent: ProvideCosmosGenesisConfigType,
WalletConfigGeneratorComponent: GenerateStandardWalletConfig,
Expand Down Expand Up @@ -92,15 +94,9 @@ impl ChainFromBootstrapParamsBuilder<CosmosStdBootstrapContext> for CosmosStdBoo
}
}

impl HasRuntime for CosmosStdBootstrapContext {
type Runtime = TokioRuntimeContext;

fn runtime(&self) -> &TokioRuntimeContext {
&self.runtime
}

fn runtime_error(e: TokioRuntimeError) -> Error {
e.into()
impl ProvideRuntime<CosmosStdBootstrapContext> for CosmosStdBootstrapComponents {
fn runtime(bootstrap: &CosmosStdBootstrapContext) -> &TokioRuntimeContext {
&bootstrap.runtime
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -71,6 +73,8 @@ delegate_components!(
[
ErrorTypeComponent,
ErrorRaiserComponent,
RuntimeTypeComponent,
RuntimeComponent,
ChainTypeComponent,
GenesisConfigTypeComponent,
ChainConfigTypeComponent,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -50,6 +52,8 @@ delegate_components!(
[
ErrorTypeComponent,
ErrorRaiserComponent,
RuntimeTypeComponent,
RuntimeComponent,
ChainIdGeneratorComponent,
ChainHomeDirInitializerComponent,
ChainDataInitializerComponent,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ where
+ CanInitChainConfig
+ CanStartChainFullNode
+ CanBuildChainFromBootstrapParameters,
Runtime: HasFilePathType + HasChildProcessType,
Runtime: HasFilePathType + HasChildProcessType + HasErrorType,
Chain: HasChainIdType + HasWalletType,
{
async fn bootstrap_chain(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ where
],
)
.await
.map_err(Bootstrap::runtime_error)?;
.map_err(Bootstrap::raise_error)?;

Ok(())
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ where
],
)
.await
.map_err(Bootstrap::runtime_error)?;
.map_err(Bootstrap::raise_error)?;

Ok(())
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ where
+ CanInitWallet
+ CanAddGenesisAccount
+ CanAddGenesisValidator,
Runtime: HasFilePathType,
Runtime: HasFilePathType + HasErrorType,
Chain: HasChainIdType + HasWalletType + HasAmountType + HasAddressType,
{
async fn add_wallet_to_genesis(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ where
],
)
.await
.map_err(Bootstrap::runtime_error)?;
.map_err(Bootstrap::raise_error)?;

Ok(())
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ where
],
)
.await
.map_err(Bootstrap::runtime_error)?;
.map_err(Bootstrap::raise_error)?;

Ok(())
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -51,7 +51,7 @@ where
],
)
.await
.map_err(Bootstrap::runtime_error)?;
.map_err(Bootstrap::raise_error)?;

Ok(())
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ where
],
)
.await
.map_err(Bootstrap::runtime_error)?;
.map_err(Bootstrap::raise_error)?;

Ok(())
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ impl<Bootstrap, Runtime, Chain> ChainHomeDirInitializer<Bootstrap> for CreateCha
where
Bootstrap:
HasChainType<Chain = Chain> + HasRuntime<Runtime = Runtime> + HasErrorType + HasTestDir,
Runtime: HasFilePathType,
Runtime: HasFilePathType + HasErrorType,
Chain: HasChainIdType,
Chain::ChainId: Display,
Runtime::FilePath: AsRef<Path>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ where
],
)
.await
.map_err(Bootstrap::runtime_error)?;
.map_err(Bootstrap::raise_error)?;

Ok(())
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)?;
Expand All @@ -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();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand All @@ -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)?
};
Expand Down Expand Up @@ -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)?
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)?;

Expand All @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
3 changes: 2 additions & 1 deletion crates/relayer-components-extra/src/batch/traits/channel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -12,7 +13,7 @@ pub trait HasMessageBatchSender<Target>: HasRelayChains
where
Target: ChainTarget<Self>,
Target::TargetChain: HasRuntime,
<Target::TargetChain as HasRuntime>::Runtime: HasChannelTypes + HasChannelOnceTypes,
Runtime<Target::TargetChain>: HasChannelTypes + HasChannelOnceTypes,
{
fn get_batch_sender(&self) -> &MessageBatchSender<Target::TargetChain, Self::Error>;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -138,12 +138,13 @@ where
#[async_trait]
impl<Build, Target, Chain, Counterparty, Runtime> CanBuildBatchChannel<Target> for Build
where
Build: HasBiRelayType + HasRuntimeWithMutex + HasErrorType,
Build: HasBiRelayType + HasRuntime + HasErrorType,
Target: ChainBuildTarget<Build, TargetChain = Chain, CounterpartyChain = Counterparty>,
Chain: HasIbcChainTypes<Counterparty> + HasRuntime<Runtime = Runtime>,
Counterparty: HasIbcChainTypes<Chain>,
Runtime: CanCreateChannels + HasChannelOnceTypes + CanCloneSender,
Build: HasBatchSenderCache<Target, RelayError<Build>>,
Build::Runtime: HasMutex,
Chain::ChainId: Ord + Clone,
Counterparty::ChainId: Ord + Clone,
Chain::ClientId: Ord + Clone,
Expand Down
6 changes: 4 additions & 2 deletions crates/relayer-components-extra/src/build/traits/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -25,9 +26,10 @@ pub trait HasBatchSenderCacheType<Build, Error>: Async {
impl<Target, Build, Error> HasBatchSenderCacheType<Build, Error> for Target
where
Error: Async,
Build: HasBiRelayType + HasRuntimeWithMutex,
Build: HasBiRelayType + HasRuntime,
Target: ChainBuildTarget<Build>,
Target::TargetChain: HasMessageBatchSenderType<Error>,
Build::Runtime: HasMutex,
{
type BatchSenderCache = Mutex<
Build,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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::*;
Expand Down Expand Up @@ -61,8 +61,7 @@ where
}

#[async_trait]
pub trait CanBuildRelayWithBatch<Target>:
HasBiRelayType + HasRuntimeWithMutex + HasErrorType
pub trait CanBuildRelayWithBatch<Target>: HasBiRelayType + HasRuntime + HasErrorType
where
Target: RelayBuildTarget<Self>,
Target::TargetRelay: HasMessageBatchSenderTypes,
Expand All @@ -82,7 +81,7 @@ where
#[async_trait]
impl<Build, Target> CanBuildRelayWithBatch<Target> for Build
where
Build: HasBiRelayType + HasRuntimeWithMutex + HasErrorType + HasComponents,
Build: HasBiRelayType + HasRuntime + HasErrorType + HasComponents,
Target: RelayBuildTarget<Build>,
Target::TargetRelay: HasMessageBatchSenderTypes,
Build::Components: RelayWithBatchBuilder<Build, Target>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<BaseComponents>(pub PhantomData<BaseComponents>);

Expand All @@ -16,6 +18,8 @@ delegate_components!(
[
ErrorTypeComponent,
ErrorRaiserComponent,
RuntimeTypeComponent,
RuntimeComponent,
RunnerComponent,
LoggerTypeComponent,
LoggerFieldComponent,
Expand Down
Loading
Loading