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

Refactor chain component graph #59

Merged
merged 19 commits into from
Oct 5, 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
12 changes: 6 additions & 6 deletions Cargo.lock

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

20 changes: 10 additions & 10 deletions crates/relayer-all-in-one/src/all_for_one/chain.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
use ibc_relayer_components::chain::traits::client::create::HasCreateClientOptions;
use ibc_relayer_components::chain::traits::components::chain_status_querier::CanQueryChainStatus;
use ibc_relayer_components::chain::traits::components::consensus_state_querier::CanQueryConsensusState;
use ibc_relayer_components::chain::traits::components::packet_commitments_querier::CanQueryPacketCommitments;
use ibc_relayer_components::chain::traits::components::packet_fields_reader::CanReadPacketFields;
use ibc_relayer_components::chain::traits::queries::packet_commitments::CanQueryPacketCommitments;
use ibc_relayer_components::chain::traits::queries::received_packet::CanQueryReceivedPacket;
use ibc_relayer_components::chain::traits::queries::send_packet::CanQuerySendPacketsFromSequences;
use ibc_relayer_components::chain::traits::queries::unreceived_packets::CanQueryUnreceivedPacketSequences;
use ibc_relayer_components::chain::traits::components::received_packet_querier::CanQueryReceivedPacket;
use ibc_relayer_components::chain::traits::components::send_packets_querier::CanQuerySendPackets;
use ibc_relayer_components::chain::traits::components::unreceived_packet_sequences_querier::CanQueryUnreceivedPacketSequences;
use ibc_relayer_components::chain::traits::types::chain::HasChainTypes;
use ibc_relayer_components::chain::traits::types::channel::{
HasChannelHandshakePayloads, HasInitChannelOptionsType,
Expand All @@ -14,8 +13,9 @@ use ibc_relayer_components::chain::traits::types::connection::{
HasConnectionHandshakePayloads, HasInitConnectionOptionsType,
};
use ibc_relayer_components::chain::traits::types::consensus_state::HasConsensusStateType;
use ibc_relayer_components::chain::traits::types::create_client::HasCreateClientOptions;
use ibc_relayer_components::chain::traits::types::ibc::HasIbcChainTypes;
use ibc_relayer_components::chain::traits::types::ibc_events::write_ack::HasWriteAcknowledgementEvent;
use ibc_relayer_components::chain::traits::types::ibc_events::write_ack::HasWriteAckEvent;
use ibc_relayer_components::chain::traits::types::packet::HasIbcPacketTypes;
use ibc_relayer_components::logger::traits::level::HasLoggerWithBaseLevels;
use ibc_relayer_components_extra::telemetry::traits::telemetry::HasTelemetry;
Expand All @@ -31,13 +31,13 @@ pub trait AfoChain<Counterparty>:
+ CanQueryChainStatus
+ HasIbcChainTypes<Counterparty>
+ CanReadPacketFields<Counterparty>
+ HasWriteAcknowledgementEvent<Counterparty>
+ HasWriteAckEvent<Counterparty>
+ HasConsensusStateType<Counterparty>
+ CanQueryConsensusState<Counterparty>
+ CanQueryReceivedPacket<Counterparty>
+ CanQueryPacketCommitments<Counterparty>
+ CanQueryUnreceivedPacketSequences<Counterparty>
+ CanQuerySendPacketsFromSequences<Counterparty>
+ CanQuerySendPackets<Counterparty>
+ HasCreateClientOptions<Counterparty>
+ HasInitConnectionOptionsType<Counterparty>
+ HasConnectionHandshakePayloads<Counterparty>
Expand Down Expand Up @@ -71,13 +71,13 @@ where
+ HasChainTypes
+ CanQueryChainStatus
+ CanReadPacketFields<Counterparty>
+ HasWriteAcknowledgementEvent<Counterparty>
+ HasWriteAckEvent<Counterparty>
+ HasConsensusStateType<Counterparty>
+ CanQueryConsensusState<Counterparty>
+ CanQueryReceivedPacket<Counterparty>
+ CanQueryPacketCommitments<Counterparty>
+ CanQueryUnreceivedPacketSequences<Counterparty>
+ CanQuerySendPacketsFromSequences<Counterparty>
+ CanQuerySendPackets<Counterparty>
+ HasCreateClientOptions<Counterparty>
+ HasInitConnectionOptionsType<Counterparty>
+ HasConnectionHandshakePayloads<Counterparty>
Expand Down
103 changes: 56 additions & 47 deletions crates/relayer-all-in-one/src/one_for_all/impls/chain/channel.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use cgp_core::async_trait;
use ibc_relayer_components::chain::traits::message_builders::channel::{
CanBuildChannelHandshakeMessages, CanBuildChannelHandshakePayloads,
};
use ibc_relayer_components::chain::traits::components::channel_handshake_message_builder::ChannelHandshakeMessageBuilder;
use ibc_relayer_components::chain::traits::components::channel_handshake_payload_builder::ChannelHandshakePayloadBuilder;
use ibc_relayer_components::chain::traits::types::channel::{
HasChannelHandshakePayloads, HasInitChannelOptionsType,
};
Expand All @@ -11,6 +10,7 @@ use ibc_relayer_components::chain::traits::types::ibc_events::channel::{

use crate::one_for_all::traits::chain::{OfaChainTypes, OfaIbcChain};
use crate::one_for_all::types::chain::OfaChainWrapper;
use crate::one_for_all::types::component::OfaComponents;
use crate::std_prelude::*;

impl<Chain, Counterparty> HasChannelHandshakePayloads<OfaChainWrapper<Counterparty>>
Expand Down Expand Up @@ -76,75 +76,82 @@ where
}

#[async_trait]
impl<Chain, Counterparty> CanBuildChannelHandshakePayloads<OfaChainWrapper<Counterparty>>
for OfaChainWrapper<Chain>
impl<Chain, Counterparty>
ChannelHandshakePayloadBuilder<OfaChainWrapper<Chain>, OfaChainWrapper<Counterparty>>
for OfaComponents
where
Chain: OfaIbcChain<Counterparty>,
Counterparty: OfaChainTypes,
{
async fn build_channel_open_try_payload(
&self,
client_state: &Self::ClientState,
height: &Self::Height,
port_id: &Self::PortId,
channel_id: &Self::ChannelId,
) -> Result<Self::ChannelOpenTryPayload, Self::Error> {
self.chain
chain: &OfaChainWrapper<Chain>,
client_state: &Chain::ClientState,
height: &Chain::Height,
port_id: &Chain::PortId,
channel_id: &Chain::ChannelId,
) -> Result<Chain::ChannelOpenTryPayload, Chain::Error> {
chain
.chain
.build_channel_open_try_payload(client_state, height, port_id, channel_id)
.await
}

async fn build_channel_open_ack_payload(
&self,
client_state: &Self::ClientState,
height: &Self::Height,
port_id: &Self::PortId,
channel_id: &Self::ChannelId,
) -> Result<Self::ChannelOpenAckPayload, Self::Error> {
self.chain
chain: &OfaChainWrapper<Chain>,
client_state: &Chain::ClientState,
height: &Chain::Height,
port_id: &Chain::PortId,
channel_id: &Chain::ChannelId,
) -> Result<Chain::ChannelOpenAckPayload, Chain::Error> {
chain
.chain
.build_channel_open_ack_payload(client_state, height, port_id, channel_id)
.await
}

async fn build_channel_open_confirm_payload(
&self,
client_state: &Self::ClientState,
height: &Self::Height,
port_id: &Self::PortId,
channel_id: &Self::ChannelId,
) -> Result<Self::ChannelOpenConfirmPayload, Self::Error> {
self.chain
chain: &OfaChainWrapper<Chain>,
client_state: &Chain::ClientState,
height: &Chain::Height,
port_id: &Chain::PortId,
channel_id: &Chain::ChannelId,
) -> Result<Chain::ChannelOpenConfirmPayload, Chain::Error> {
chain
.chain
.build_channel_open_confirm_payload(client_state, height, port_id, channel_id)
.await
}
}

#[async_trait]
impl<Chain, Counterparty> CanBuildChannelHandshakeMessages<OfaChainWrapper<Counterparty>>
for OfaChainWrapper<Chain>
impl<Chain, Counterparty>
ChannelHandshakeMessageBuilder<OfaChainWrapper<Chain>, OfaChainWrapper<Counterparty>>
for OfaComponents
where
Chain: OfaIbcChain<Counterparty>,
Counterparty: OfaChainTypes,
{
async fn build_channel_open_init_message(
&self,
port_id: &Self::PortId,
chain: &OfaChainWrapper<Chain>,
port_id: &Chain::PortId,
counterparty_port_id: &Counterparty::PortId,
init_channel_options: &Self::InitChannelOptions,
) -> Result<Self::Message, Self::Error> {
self.chain
init_channel_options: &Chain::InitChannelOptions,
) -> Result<Chain::Message, Chain::Error> {
chain
.chain
.build_channel_open_init_message(port_id, counterparty_port_id, init_channel_options)
.await
}

async fn build_channel_open_try_message(
&self,
dst_port_id: &Self::PortId,
chain: &OfaChainWrapper<Chain>,
dst_port_id: &Chain::PortId,
src_port_id: &Counterparty::PortId,
src_channel_id: &Counterparty::ChannelId,
counterparty_payload: Counterparty::ChannelOpenTryPayload,
) -> Result<Self::Message, Self::Error> {
self.chain
) -> Result<Chain::Message, Chain::Error> {
chain
.chain
.build_channel_open_try_message(
dst_port_id,
src_port_id,
Expand All @@ -155,13 +162,14 @@ where
}

async fn build_channel_open_ack_message(
&self,
port_id: &Self::PortId,
channel_id: &Self::ChannelId,
chain: &OfaChainWrapper<Chain>,
port_id: &Chain::PortId,
channel_id: &Chain::ChannelId,
counterparty_channel_id: &Counterparty::ChannelId,
counterparty_payload: Counterparty::ChannelOpenAckPayload,
) -> Result<Self::Message, Self::Error> {
self.chain
) -> Result<Chain::Message, Chain::Error> {
chain
.chain
.build_channel_open_ack_message(
port_id,
channel_id,
Expand All @@ -172,12 +180,13 @@ where
}

async fn build_channel_open_confirm_message(
&self,
port_id: &Self::PortId,
channel_id: &Self::ChannelId,
chain: &OfaChainWrapper<Chain>,
port_id: &Chain::PortId,
channel_id: &Chain::ChannelId,
counterparty_payload: Counterparty::ChannelOpenConfirmPayload,
) -> Result<Self::Message, Self::Error> {
self.chain
) -> Result<Chain::Message, Chain::Error> {
chain
.chain
.build_channel_open_confirm_message(port_id, channel_id, counterparty_payload)
.await
}
Expand Down
Loading
Loading