Skip to content

Commit

Permalink
Use component delegation pattern for core relayer components (#3539)
Browse files Browse the repository at this point in the history
* Define ForwardComponent to auto forward component with less macros

* Forward IBC message sender components

* Auto derive from HasComponent for both provider and consumer traits.

* Use new component pattern for chain status and consensus state querier

* Use new component pattern for all other components

* Remove HasComponents trait

* Add forward_components! macro to forward multiple components at once

* Reorder macro arguments and rename forward_component to delegate_component

* Rename HasComponent to DelegateComponent

* Separate out component graphs for each context

* Remove generic Mode argument from AutoRelayer

* Delegate event relayer component

* Rearrange modules

* Turn CreateClient into a component

* Remove unused traits

* Use component delegation for PacketClearer

* Do not retry failed tests in CI

* Use component delegation for chain builder

* Use component delegation for RelayBuilder

* Use component delegation for RelayFromChainsBuilder

* Use component delegation for RelayWithBatchBuilder

* Rearrange modules

* Rearrange birelay traits

* Use component delegation for BiRelayBuilder

* Allow delegate_components! to match without trailing comma

* Use component delegation for BiRelayFromRelayBuilder

* Fix CI
  • Loading branch information
soareschen authored Aug 15, 2023
1 parent bf1407d commit 9579ec6
Show file tree
Hide file tree
Showing 125 changed files with 1,568 additions and 1,381 deletions.
12 changes: 2 additions & 10 deletions .github/workflows/integration.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -100,17 +100,13 @@ jobs:
command: test
args: -p ibc-integration-test --no-fail-fast --no-run
- name: run integration tests
uses: nick-fields/retry@v2
env:
RUST_LOG: info,ibc_relayer_runtime=trace
RUST_BACKTRACE: 1
NO_COLOR_LOG: 1
CHAIN_COMMAND_PATHS: ${{ matrix.chain.command }}
ACCOUNT_PREFIXES: ${{ matrix.chain.account_prefix }}
with:
max_attempts: 2
timeout_minutes: 90
command: |
run: |
nix shell .#python .#${{ matrix.chain.package }} -c cargo \
test -p ibc-integration-test --no-fail-fast -- \
--nocapture --test-threads=2
Expand Down Expand Up @@ -180,17 +176,13 @@ jobs:
command: test
args: -p ibc-integration-test --no-fail-fast --no-run
- name: run integration tests
uses: nick-fields/retry@v2
env:
RUST_LOG: info,ibc_relayer_runtime=trace
RUST_BACKTRACE: 1
NO_COLOR_LOG: 1
CHAIN_COMMAND_PATHS: ${{ matrix.chain.command }}
ACCOUNT_PREFIXES: ${{ matrix.chain.account_prefix }}
with:
max_attempts: 3
timeout_minutes: 45
command: |
run: |
nix shell .#python .#${{ matrix.chain.package }} -c cargo \
test -p ibc-integration-test --no-fail-fast -- \
--nocapture --test-threads=2
Expand Down
6 changes: 3 additions & 3 deletions Cargo.lock

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

6 changes: 3 additions & 3 deletions crates/relayer-all-in-one/src/all_for_one/birelay.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use ibc_relayer_components::logger::traits::level::HasLoggerWithBaseLevels;
use ibc_relayer_components::relay::traits::auto_relayer::{BiRelayMode, CanAutoRelay};
use ibc_relayer_components::relay::traits::auto_relayer::CanAutoRelay;
use ibc_relayer_components::relay::traits::two_way::HasTwoWayRelay;

use crate::all_for_one::relay::AfoRelay;
Expand All @@ -8,7 +8,7 @@ use crate::all_for_one::runtime::HasAfoRuntime;
pub trait AfoBiRelay:
HasAfoRuntime
+ HasLoggerWithBaseLevels
+ CanAutoRelay<BiRelayMode>
+ CanAutoRelay
+ HasTwoWayRelay<RelayAToB = Self::AfoRelayAToB, RelayBToA = Self::AfoRelayBToA>
{
type AfoRelayAToB: AfoRelay;
Expand All @@ -26,7 +26,7 @@ where
BiRelay: Clone
+ HasAfoRuntime
+ HasLoggerWithBaseLevels
+ CanAutoRelay<BiRelayMode>
+ CanAutoRelay
+ HasTwoWayRelay<RelayAToB = RelayAToB, RelayBToA = RelayBToA>,
{
type AfoRelayAToB = RelayAToB;
Expand Down
3 changes: 2 additions & 1 deletion crates/relayer-all-in-one/src/all_for_one/builder.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use async_trait::async_trait;
use ibc_relayer_components::builder::traits::birelay::{CanBuildBiRelay, HasBiRelayType};
use ibc_relayer_components::builder::traits::birelay::build::CanBuildBiRelay;
use ibc_relayer_components::builder::traits::birelay::types::HasBiRelayType;
use ibc_relayer_components::builder::types::aliases::{ChainIdA, ChainIdB, ClientIdA, ClientIdB};
use ibc_relayer_components::core::traits::error::HasErrorType;

Expand Down
16 changes: 8 additions & 8 deletions crates/relayer-all-in-one/src/all_for_one/relay.rs
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
use ibc_relayer_components::chain::types::aliases::{IncomingPacket, OutgoingPacket};
use ibc_relayer_components::logger::traits::level::HasLoggerWithBaseLevels;
use ibc_relayer_components::relay::impls::client::create::CanCreateClient;
use ibc_relayer_components::relay::traits::auto_relayer::{CanAutoRelay, RelayMode};
use ibc_relayer_components::relay::traits::auto_relayer::CanAutoRelay;
use ibc_relayer_components::relay::traits::chains::HasRelayChains;
use ibc_relayer_components::relay::traits::channel::open_handshake::CanRelayChannelOpenHandshake;
use ibc_relayer_components::relay::traits::channel::open_init::CanInitChannel;
use ibc_relayer_components::relay::traits::clear_packet::CanClearPackets;
use ibc_relayer_components::relay::traits::connection::open_handshake::CanRelayConnectionOpenHandshake;
use ibc_relayer_components::relay::traits::connection::open_init::CanInitConnection;
use ibc_relayer_components::relay::traits::create_client::CanCreateClient;
use ibc_relayer_components::relay::traits::event_relayer::CanRelayEvent;
use ibc_relayer_components::relay::traits::ibc_message_sender::{CanSendIbcMessages, MainSink};
use ibc_relayer_components::relay::traits::messages::update_client::CanBuildUpdateClientMessage;
use ibc_relayer_components::relay::traits::packet::HasRelayPacket;
use ibc_relayer_components::relay::traits::packet_clear::CanClearReceivePackets;
use ibc_relayer_components::relay::traits::packet_filter::CanFilterPackets;
use ibc_relayer_components::relay::traits::packet_relayer::CanRelayPacket;
use ibc_relayer_components::relay::traits::packet_relayers::ack_packet::CanRelayAckPacket;
use ibc_relayer_components::relay::traits::packet_relayers::receive_packet::CanRelayReceivePacket;
use ibc_relayer_components::relay::traits::packet_relayers::timeout_unordered_packet::CanRelayTimeoutUnorderedPacket;
use ibc_relayer_components::relay::traits::target::{DestinationTarget, SourceTarget};
use ibc_relayer_components::relay::traits::update_client::CanBuildUpdateClientMessage;
use ibc_relayer_components_extra::relay::components::packet_relayers::retry::SupportsPacketRetry;

use crate::all_for_one::chain::AfoChain;
Expand All @@ -37,7 +37,7 @@ pub trait AfoRelay:
+ CanSendIbcMessages<MainSink, DestinationTarget>
+ CanRelayEvent<SourceTarget>
+ CanRelayEvent<DestinationTarget>
+ CanAutoRelay<RelayMode>
+ CanAutoRelay
+ CanFilterPackets
+ CanRelayReceivePacket
+ CanRelayPacket
Expand All @@ -50,7 +50,7 @@ pub trait AfoRelay:
+ CanInitChannel
+ CanRelayChannelOpenHandshake
+ SupportsPacketRetry
+ CanClearReceivePackets
+ CanClearPackets
{
type AfoSrcChain: AfoChain<Self::AfoDstChain>;

Expand All @@ -76,7 +76,7 @@ where
+ CanSendIbcMessages<MainSink, DestinationTarget>
+ CanRelayEvent<SourceTarget>
+ CanRelayEvent<DestinationTarget>
+ CanAutoRelay<RelayMode>
+ CanAutoRelay
+ CanFilterPackets
+ CanRelayReceivePacket
+ CanRelayPacket
Expand All @@ -89,7 +89,7 @@ where
+ CanInitChannel
+ CanRelayChannelOpenHandshake
+ SupportsPacketRetry
+ CanClearReceivePackets,
+ CanClearPackets,
{
type AfoSrcChain = SrcChain;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
use async_trait::async_trait;
use ibc_relayer_components::core::traits::component::HasComponents;
use ibc_relayer_components::core::traits::component::DelegateComponent;
use ibc_relayer_components::core::traits::sync::Async;
use ibc_relayer_components_extra::components::extra::ExtraComponents;
use ibc_relayer_components_extra::components::extra::birelay::ExtraBiRelayComponents;

use crate::one_for_all::types::birelay::OfaBiRelayWrapper;
use crate::one_for_all::types::component::OfaComponents;

#[async_trait]
impl<BiRelay> HasComponents for OfaBiRelayWrapper<BiRelay>
impl<BiRelay, Name> DelegateComponent<Name> for OfaBiRelayWrapper<BiRelay>
where
BiRelay: Async,
{
type Components = ExtraComponents<OfaComponents>;
type Delegate = ExtraBiRelayComponents<OfaComponents>;
}
47 changes: 10 additions & 37 deletions crates/relayer-all-in-one/src/one_for_all/impls/builder/birelay.rs
Original file line number Diff line number Diff line change
@@ -1,53 +1,26 @@
use async_trait::async_trait;
use ibc_relayer_components::builder::impls::birelay::BuildBiRelayFromRelays;
use ibc_relayer_components::builder::traits::birelay::{
BiRelayBuilder, CanBuildBiRelay, CanBuildBiRelayFromRelays,
};
use ibc_relayer_components::builder::traits::birelay::from_relays::BiRelayFromRelayBuilder;

use crate::one_for_all::traits::builder::{
ChainIdA, ChainIdB, ClientIdA, ClientIdB, OfaBuilder, RelayAToB, RelayBToA,
};
use crate::one_for_all::traits::builder::{OfaBuilder, RelayAToB, RelayBToA};
use crate::one_for_all::types::birelay::OfaBiRelayWrapper;
use crate::one_for_all::types::builder::OfaBuilderWrapper;
use crate::one_for_all::types::component::OfaComponents;
use crate::one_for_all::types::relay::OfaRelayWrapper;
use crate::std_prelude::*;

#[async_trait]
impl<Builder> CanBuildBiRelayFromRelays for OfaBuilderWrapper<Builder>
impl<Build> BiRelayFromRelayBuilder<OfaBuilderWrapper<Build>> for OfaComponents
where
Builder: OfaBuilder,
Build: OfaBuilder,
{
async fn build_birelay_from_relays(
&self,
relay_a_to_b: OfaRelayWrapper<RelayAToB<Builder>>,
relay_b_to_a: OfaRelayWrapper<RelayBToA<Builder>>,
) -> Result<OfaBiRelayWrapper<Builder::BiRelay>, Builder::Error> {
build: &OfaBuilderWrapper<Build>,
relay_a_to_b: OfaRelayWrapper<RelayAToB<Build>>,
relay_b_to_a: OfaRelayWrapper<RelayBToA<Build>>,
) -> Result<OfaBiRelayWrapper<Build::BiRelay>, Build::Error> {
let birelay =
OfaBuilder::build_birelay(self.builder.as_ref(), relay_a_to_b, relay_b_to_a).await?;
OfaBuilder::build_birelay(build.builder.as_ref(), relay_a_to_b, relay_b_to_a).await?;

Ok(OfaBiRelayWrapper::new(birelay))
}
}

#[async_trait]
impl<Builder> CanBuildBiRelay for OfaBuilderWrapper<Builder>
where
Builder: OfaBuilder,
{
async fn build_birelay(
&self,
chain_id_a: &ChainIdA<Builder>,
chain_id_b: &ChainIdB<Builder>,
client_id_a: &ClientIdA<Builder>,
client_id_b: &ClientIdB<Builder>,
) -> Result<Self::BiRelay, Self::Error> {
BuildBiRelayFromRelays::build_birelay(
self,
chain_id_a,
chain_id_b,
client_id_a,
client_id_b,
)
.await
}
}
40 changes: 4 additions & 36 deletions crates/relayer-all-in-one/src/one_for_all/impls/builder/chain.rs
Original file line number Diff line number Diff line change
@@ -1,23 +1,20 @@
use async_trait::async_trait;
use ibc_relayer_components::builder::impls::cache::BuildWithCache;
use ibc_relayer_components::builder::traits::chain::{CanBuildChain, ChainBuilder};
use ibc_relayer_components::builder::traits::chain::ChainBuilder;
use ibc_relayer_components::builder::traits::target::chain::{ChainATarget, ChainBTarget};

use crate::one_for_all::traits::builder::{ChainA, ChainB, ChainIdA, ChainIdB, OfaBuilder};
use crate::one_for_all::types::builder::OfaBuilderWrapper;
use crate::one_for_all::types::chain::OfaChainWrapper;
use crate::one_for_all::types::component::OfaComponents;
use crate::std_prelude::*;

pub struct BuildChainFromOfa;

#[async_trait]
impl<Builder> ChainBuilder<OfaBuilderWrapper<Builder>, ChainATarget> for BuildChainFromOfa
impl<Builder> ChainBuilder<OfaBuilderWrapper<Builder>, ChainATarget> for OfaComponents
where
Builder: OfaBuilder,
{
async fn build_chain(
builder: &OfaBuilderWrapper<Builder>,
_target: ChainATarget,
chain_id: &ChainIdA<Builder>,
) -> Result<OfaChainWrapper<ChainA<Builder>>, Builder::Error> {
let chain = builder.builder.build_chain_a(chain_id).await?;
Expand All @@ -27,45 +24,16 @@ where
}

#[async_trait]
impl<Builder> ChainBuilder<OfaBuilderWrapper<Builder>, ChainBTarget> for BuildChainFromOfa
impl<Builder> ChainBuilder<OfaBuilderWrapper<Builder>, ChainBTarget> for OfaComponents
where
Builder: OfaBuilder,
{
async fn build_chain(
builder: &OfaBuilderWrapper<Builder>,
_target: ChainBTarget,
chain_id: &ChainIdB<Builder>,
) -> Result<OfaChainWrapper<ChainB<Builder>>, Builder::Error> {
let chain = builder.builder.build_chain_b(chain_id).await?;

Ok(OfaChainWrapper::new(chain))
}
}

#[async_trait]
impl<Builder> CanBuildChain<ChainATarget> for OfaBuilderWrapper<Builder>
where
Builder: OfaBuilder,
{
async fn build_chain(
&self,
target: ChainATarget,
chain_id: &ChainIdA<Builder>,
) -> Result<OfaChainWrapper<ChainA<Builder>>, Self::Error> {
<BuildWithCache<BuildChainFromOfa>>::build_chain(self, target, chain_id).await
}
}

#[async_trait]
impl<Builder> CanBuildChain<ChainBTarget> for OfaBuilderWrapper<Builder>
where
Builder: OfaBuilder,
{
async fn build_chain(
&self,
target: ChainBTarget,
chain_id: &ChainIdB<Builder>,
) -> Result<OfaChainWrapper<ChainB<Builder>>, Self::Error> {
<BuildWithCache<BuildChainFromOfa>>::build_chain(self, target, chain_id).await
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
use ibc_relayer_components::core::traits::component::DelegateComponent;
use ibc_relayer_components_extra::components::extra::build::ExtraBuildComponents;

use crate::one_for_all::traits::builder::OfaBuilder;
use crate::one_for_all::types::builder::OfaBuilderWrapper;
use crate::one_for_all::types::component::OfaComponents;

impl<Build, Name> DelegateComponent<Name> for OfaBuilderWrapper<Build>
where
Build: OfaBuilder,
{
type Delegate = ExtraBuildComponents<OfaComponents>;
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ pub mod batch;
pub mod birelay;
pub mod cache;
pub mod chain;
pub mod component;
pub mod error;
pub mod logger;
pub mod relay;
Expand Down
Loading

0 comments on commit 9579ec6

Please sign in to comment.