Skip to content

Commit

Permalink
Minor refactoring for BiRelay components (#533)
Browse files Browse the repository at this point in the history
* Remove HasRelayTypeAt trait bound for CanBuildBiRelay

* Remove HasIbcChainTypes bound in RunStartRelayerCommand

* Simplify CosmosBiRelay implementation

* Add generic params to BiRelayTypeAtComponent

* Remove cosmos-nix Cachix store
  • Loading branch information
soareschen authored Jan 31, 2025
1 parent 61b94d9 commit b432c9e
Show file tree
Hide file tree
Showing 8 changed files with 31 additions and 41 deletions.
3 changes: 0 additions & 3 deletions .github/workflows/integration-tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ jobs:
- uses: cachix/cachix-action@v15
with:
name: hermes-sdk
extraPullNames: cosmos-nix
authToken: ${{ secrets.CACHIX_AUTH_TOKEN }}
- uses: actions-rs/toolchain@v1
with:
Expand Down Expand Up @@ -57,7 +56,6 @@ jobs:
- uses: cachix/cachix-action@v15
with:
name: hermes-sdk
extraPullNames: cosmos-nix
authToken: ${{ secrets.CACHIX_AUTH_TOKEN }}
- uses: actions-rs/toolchain@v1
with:
Expand Down Expand Up @@ -86,7 +84,6 @@ jobs:
- uses: cachix/cachix-action@v15
with:
name: hermes-sdk
extraPullNames: cosmos-nix
authToken: ${{ secrets.CACHIX_AUTH_TOKEN }}
- uses: actions-rs/toolchain@v1
with:
Expand Down
7 changes: 4 additions & 3 deletions crates/cli/cli-components/src/impls/commands/start.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ use hermes_logging_components::traits::has_logger::HasLogger;
use hermes_logging_components::traits::logger::CanLog;
use hermes_logging_components::types::level::LevelInfo;
use hermes_relayer_components::build::traits::builders::birelay_builder::CanBuildBiRelay;
use hermes_relayer_components::chain::traits::types::ibc::HasIbcChainTypes;
use hermes_relayer_components::chain::traits::types::chain_id::HasChainIdType;
use hermes_relayer_components::chain::traits::types::ibc::HasClientIdType;
use hermes_relayer_components::multi::traits::chain_at::HasChainTypeAt;

use crate::traits::build::CanLoadBuilder;
Expand Down Expand Up @@ -75,8 +76,8 @@ where
+ HasChainTypeAt<Index<0>, Chain = ChainA>
+ HasChainTypeAt<Index<1>, Chain = ChainB>,
BiRelay: CanRun,
ChainA: HasIbcChainTypes<ChainB>,
ChainB: HasIbcChainTypes<ChainA>,
ChainA: HasChainIdType + HasClientIdType<ChainB>,
ChainB: HasChainIdType + HasClientIdType<ChainA>,
{
async fn run_command(app: &App, args: &Args) -> Result<App::Output, App::Error> {
let logger = app.logger();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ delegate_components! {
RelayTypeAtComponent<Index<0>, Index<1>>,
RelayTypeAtComponent<Index<1>, Index<0>>,
]: WithType<CosmosRelay>,
BiRelayTypeAtComponent: WithType<CosmosBiRelay>,
BiRelayTypeAtComponent<Index<0>, Index<1>>: WithType<CosmosBiRelay>,
BinaryChannelDriverBuilderComponent: BuildCosmosBinaryChannelDriver,
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ delegate_components! {
ChainDriverTypeAtComponent,
RelayTypeAtComponent<Index<0>, Index<1>>,
RelayTypeAtComponent<Index<1>, Index<0>>,
BiRelayTypeAtComponent,
BiRelayTypeAtComponent<Index<0>, Index<1>>,
RelayDriverTypeAtComponent,
]:
ProvideCosmosTestTypes,
Expand Down
48 changes: 21 additions & 27 deletions crates/cosmos/cosmos-relayer/src/contexts/birelay.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
use cgp::core::error::{ErrorRaiserComponent, ErrorTypeComponent};
use cgp::core::field::{Index, WithField};
use cgp::core::types::WithType;
use cgp::extra::run::CanRun;
use cgp::prelude::*;
use hermes_relayer_components::birelay::traits::two_way::TwoWayRelayGetter;
use hermes_relayer_components::components::default::birelay::*;
use hermes_relayer_components::multi::traits::chain_at::ProvideChainTypeAt;
use hermes_relayer_components::multi::traits::relay_at::ProvideRelayTypeAt;
use hermes_relayer_components::components::default::birelay::{
DefaultBiRelayComponents, IsDefaultBiRelayComponents,
};
use hermes_relayer_components::multi::traits::chain_at::ChainTypeAtComponent;
use hermes_relayer_components::multi::traits::relay_at::RelayTypeAtComponent;
use hermes_runtime::types::runtime::HermesRuntime;
use hermes_runtime_components::traits::runtime::{RuntimeGetterComponent, RuntimeTypeComponent};

Expand All @@ -26,14 +29,11 @@ impl HasComponents for CosmosBiRelay {
type Components = CosmosBiRelayComponents;
}

with_default_bi_relay_components! {
| Components | {
delegate_components! {
CosmosBiRelayComponents {
Components: DefaultBiRelayComponents,
}
}
}
impl<Component> DelegateComponent<Component> for CosmosBiRelayComponents
where
Self: IsDefaultBiRelayComponents<Component>,
{
type Delegate = DefaultBiRelayComponents;
}

delegate_components! {
Expand All @@ -45,6 +45,12 @@ delegate_components! {
HandleCosmosError,
RuntimeTypeComponent: WithType<HermesRuntime>,
RuntimeGetterComponent: WithField<symbol!("runtime")>,
ChainTypeAtComponent<Index<0>>: WithType<CosmosChain>,
ChainTypeAtComponent<Index<1>>: WithType<CosmosChain>,
[
RelayTypeAtComponent<Index<0>, Index<1>>,
RelayTypeAtComponent<Index<1>, Index<0>>,
]: WithType<CosmosRelay>,
}
}

Expand All @@ -62,22 +68,6 @@ impl CosmosBiRelay {
}
}

impl ProvideChainTypeAt<CosmosBiRelay, Index<0>> for CosmosBiRelayComponents {
type Chain = CosmosChain;
}

impl ProvideChainTypeAt<CosmosBiRelay, Index<1>> for CosmosBiRelayComponents {
type Chain = CosmosChain;
}

impl ProvideRelayTypeAt<CosmosBiRelay, Index<0>, Index<1>> for CosmosBiRelayComponents {
type Relay = CosmosRelay;
}

impl ProvideRelayTypeAt<CosmosBiRelay, Index<1>, Index<0>> for CosmosBiRelayComponents {
type Relay = CosmosRelay;
}

impl TwoWayRelayGetter<CosmosBiRelay> for CosmosBiRelayComponents {
fn relay_a_to_b(birelay: &CosmosBiRelay) -> &CosmosRelay {
&birelay.relay_a_to_b
Expand All @@ -87,3 +77,7 @@ impl TwoWayRelayGetter<CosmosBiRelay> for CosmosBiRelayComponents {
&birelay.relay_b_to_a
}
}

pub trait CanUseCosmosBiRelay: CanRun {}

impl CanUseCosmosBiRelay for CosmosBiRelay {}
2 changes: 1 addition & 1 deletion crates/cosmos/cosmos-relayer/src/contexts/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ delegate_components! {
HandleCosmosError,
RuntimeTypeComponent: WithType<HermesRuntime>,
RuntimeGetterComponent: WithField<symbol!("runtime")>,
BiRelayTypeAtComponent:
BiRelayTypeAtComponent<Index<0>, Index<1>>:
WithType<CosmosBiRelay>,
[
ChainTypeAtComponent<Index<0>>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use hermes_chain_components::traits::types::ibc::HasClientIdType;
use crate::chain::traits::types::chain_id::HasChainIdType;
use crate::multi::traits::birelay_at::HasBiRelayTypeAt;
use crate::multi::traits::chain_at::{ChainAt, ChainIdAt, HasChainTypeAt};
use crate::multi::traits::relay_at::{ClientIdAt, HasRelayTypeAt};
use crate::multi::traits::relay_at::ClientIdAt;

#[cgp_component {
provider: BiRelayBuilder,
Expand All @@ -15,8 +15,6 @@ pub trait CanBuildBiRelay<A, B>:
HasBiRelayTypeAt<A, B>
+ HasChainTypeAt<A, Chain: HasChainIdType + HasClientIdType<ChainAt<Self, B>>>
+ HasChainTypeAt<B, Chain: HasChainIdType + HasClientIdType<ChainAt<Self, A>>>
+ HasRelayTypeAt<A, B>
+ HasRelayTypeAt<B, A>
+ HasAsyncErrorType
where
ChainAt<Self, A>: HasClientIdType<ChainAt<Self, B>>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use cgp::core::types::ProvideType;
use cgp::prelude::*;

#[cgp_component {
name: BiRelayTypeAtComponent,
name: BiRelayTypeAtComponent<TagA, TagB>,
provider: ProvideBiRelayTypeAt,
context: Setup,
}]
Expand All @@ -17,7 +17,7 @@ impl<Context, TagA, TagB, Provider, BiRelay> ProvideBiRelayTypeAt<Context, TagA,
for WithProvider<Provider>
where
Context: Async,
Provider: ProvideType<Context, BiRelayTypeAtComponent, Type = BiRelay>,
Provider: ProvideType<Context, BiRelayTypeAtComponent<TagA, TagB>, Type = BiRelay>,
BiRelay: Async,
{
type BiRelay = BiRelay;
Expand Down

0 comments on commit b432c9e

Please sign in to comment.