Skip to content

Commit

Permalink
Merge branch 'main' into luca_joss/remove-ibc-relayer-dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
ljoss17 committed Dec 12, 2024
2 parents 392ef4a + 0b03530 commit 30f6ef2
Show file tree
Hide file tree
Showing 62 changed files with 696 additions and 277 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,27 @@ use alloc::vec::Vec;

use cgp::core::component::UseDelegate;
use cgp::prelude::*;
use hermes_chain_type_components::traits::types::counterparty::CanUseCounterparty;
use hermes_chain_type_components::traits::types::ibc::client_id::HasClientIdType;
use hermes_chain_type_components::traits::types::message::HasMessageType;

use crate::traits::types::update_client::HasUpdateClientPayloadType;
use crate::traits::types::update_client::{HasUpdateClientPayloadType, UpdateClientPayloadOf};

#[cgp_component {
provider: UpdateClientMessageBuilder,
context: Chain,
}]
#[async_trait]
pub trait CanBuildUpdateClientMessage<Counterparty>:
HasClientIdType<Counterparty> + HasMessageType + HasErrorType
where
Counterparty: HasUpdateClientPayloadType<Self>,
HasClientIdType<Counterparty>
+ CanUseCounterparty<Counterparty, Counterparty: HasUpdateClientPayloadType<Self>>
+ HasMessageType
+ HasErrorType
{
async fn build_update_client_message(
&self,
client_id: &Self::ClientId,
payload: Counterparty::UpdateClientPayload,
payload: UpdateClientPayloadOf<Counterparty, Self>,
) -> Result<Vec<Self::Message>, Self::Error>;
}

Expand Down
21 changes: 14 additions & 7 deletions crates/chain/chain-components/src/traits/packet/fields.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
use cgp::prelude::*;
use hermes_chain_type_components::traits::types::counterparty::CanUseCounterparty;
use hermes_chain_type_components::traits::types::height::HasHeightType;
use hermes_chain_type_components::traits::types::ibc::channel_id::HasChannelIdType;
use hermes_chain_type_components::traits::types::ibc::packet::HasOutgoingPacketType;
use hermes_chain_type_components::traits::types::ibc::port_id::HasPortIdType;
use hermes_chain_type_components::traits::types::ibc::sequence::HasSequenceType;
use hermes_chain_type_components::traits::types::timeout::HasTimeoutType;
use hermes_chain_type_components::traits::types::timeout::{HasTimeoutType, TimeoutOf};

use crate::types::aliases::{ChannelIdOf, HeightOf, PortIdOf};

#[cgp_component {
provider: OutgoingPacketFieldsReader,
Expand All @@ -15,24 +18,28 @@ pub trait CanReadOutgoingPacketFields<Counterparty>:
+ HasChannelIdType<Counterparty>
+ HasPortIdType<Counterparty>
+ HasSequenceType<Counterparty>
where
Counterparty: HasHeightType + HasTimeoutType + HasChannelIdType<Self> + HasPortIdType<Self>,
+ CanUseCounterparty<
Counterparty,
Counterparty: HasHeightType + HasTimeoutType + HasChannelIdType<Self> + HasPortIdType<Self>,
>
{
fn outgoing_packet_src_channel_id(packet: &Self::OutgoingPacket) -> &Self::ChannelId;

fn outgoing_packet_dst_channel_id(packet: &Self::OutgoingPacket) -> &Counterparty::ChannelId;
fn outgoing_packet_dst_channel_id(
packet: &Self::OutgoingPacket,
) -> &ChannelIdOf<Counterparty, Self>;

fn outgoing_packet_src_port(packet: &Self::OutgoingPacket) -> &Self::PortId;

fn outgoing_packet_dst_port(packet: &Self::OutgoingPacket) -> &Counterparty::PortId;
fn outgoing_packet_dst_port(packet: &Self::OutgoingPacket) -> &PortIdOf<Counterparty, Self>;

fn outgoing_packet_sequence(packet: &Self::OutgoingPacket) -> &Self::Sequence;

fn outgoing_packet_timeout_height(
packet: &Self::OutgoingPacket,
) -> Option<Counterparty::Height>;
) -> Option<HeightOf<Counterparty>>;

fn outgoing_packet_timeout_timestamp(
packet: &Self::OutgoingPacket,
) -> Option<Counterparty::Timeout>;
) -> Option<TimeoutOf<Counterparty>>;
}
32 changes: 32 additions & 0 deletions crates/chain/chain-components/src/traits/packet/filter.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
use cgp::prelude::*;
use hermes_chain_type_components::traits::types::ibc::packet::{
HasIncomingPacketType, HasOutgoingPacketType,
};

#[cgp_component {
context: Chain,
provider: OutgoingPacketFilter,
}]
#[async_trait]
pub trait CanFilterOutgoingPacket<Counterparty>:
HasOutgoingPacketType<Counterparty> + HasErrorType
{
async fn should_relay_outgoing_packet(
&self,
packet: &Self::OutgoingPacket,
) -> Result<bool, Self::Error>;
}

#[cgp_component {
context: Chain,
provider: IncomingPacketFilter,
}]
#[async_trait]
pub trait CanFilterIncomingPacket<Counterparty>:
HasIncomingPacketType<Counterparty> + HasErrorType
{
async fn should_relay_incoming_packet(
&self,
packet: &Self::IncomingPacket,
) -> Result<bool, Self::Error>;
}
1 change: 1 addition & 0 deletions crates/chain/chain-components/src/traits/packet/mod.rs
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
pub mod fields;
pub mod filter;
pub mod from_write_ack;
11 changes: 7 additions & 4 deletions crates/chain/chain-components/src/traits/queries/client_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@ use core::marker::PhantomData;

use cgp::core::component::UseDelegate;
use cgp::prelude::*;
use hermes_chain_type_components::traits::types::counterparty::CanUseCounterparty;
use hermes_chain_type_components::traits::types::height::HasHeightType;
use hermes_chain_type_components::traits::types::ibc::client_id::HasClientIdType;
use hermes_chain_type_components::traits::types::ibc::client_state::ClientStateOf;

use crate::traits::queries::chain_status::CanQueryChainStatus;
use crate::traits::types::client_state::{HasClientStateType, HasRawClientStateType};
Expand All @@ -17,16 +19,17 @@ use crate::traits::types::proof::HasCommitmentProofType;
}]
#[async_trait]
pub trait CanQueryClientState<Counterparty>:
HasClientIdType<Counterparty> + HasHeightType + HasErrorType
where
Counterparty: HasClientStateType<Self>,
HasClientIdType<Counterparty>
+ CanUseCounterparty<Counterparty, Counterparty: HasClientStateType<Self>>
+ HasHeightType
+ HasErrorType
{
async fn query_client_state(
&self,
tag: PhantomData<Counterparty>,
client_id: &Self::ClientId,
height: &Self::Height,
) -> Result<Counterparty::ClientState, Self::Error>;
) -> Result<ClientStateOf<Counterparty, Self>, Self::Error>;
}

#[cgp_component {
Expand Down
24 changes: 14 additions & 10 deletions crates/chain/chain-components/src/traits/queries/consensus_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,34 @@ use core::marker::PhantomData;

use cgp::core::component::UseDelegate;
use cgp::prelude::*;
use hermes_chain_type_components::traits::types::counterparty::CanUseCounterparty;
use hermes_chain_type_components::traits::types::ibc::client_id::HasClientIdType;
use hermes_chain_type_components::traits::types::ibc::consensus_state::ConsensusStateOf;

use super::chain_status::CanQueryChainStatus;
use crate::traits::types::consensus_state::{HasConsensusStateType, HasRawConsensusStateType};
use crate::traits::types::height::HasHeightType;
use crate::traits::types::proof::HasCommitmentProofType;
use crate::types::aliases::HeightOf;

#[cgp_component {
provider: ConsensusStateQuerier,
context: Chain,
}]
#[async_trait]
pub trait CanQueryConsensusState<Counterparty>:
HasClientIdType<Counterparty> + HasHeightType + HasErrorType
where
Counterparty: HasConsensusStateType<Self> + HasHeightType,
HasClientIdType<Counterparty>
+ CanUseCounterparty<Counterparty, Counterparty: HasConsensusStateType<Self> + HasHeightType>
+ HasHeightType
+ HasErrorType
{
async fn query_consensus_state(
&self,
tag: PhantomData<Counterparty>,
client_id: &Self::ClientId,
consensus_height: &Counterparty::Height,
consensus_height: &HeightOf<Counterparty>,
query_height: &Self::Height,
) -> Result<Counterparty::ConsensusState, Self::Error>;
) -> Result<ConsensusStateOf<Counterparty, Self>, Self::Error>;
}

#[cgp_component {
Expand Down Expand Up @@ -89,16 +93,16 @@ where

#[async_trait]
pub trait CanQueryConsensusStateWithLatestHeight<Counterparty>:
HasClientIdType<Counterparty> + HasErrorType
where
Counterparty: HasConsensusStateType<Self> + HasHeightType,
HasClientIdType<Counterparty>
+ CanUseCounterparty<Counterparty, Counterparty: HasConsensusStateType<Self> + HasHeightType>
+ HasErrorType
{
async fn query_consensus_state_with_latest_height(
&self,
tag: PhantomData<Counterparty>,
client_id: &Self::ClientId,
consensus_height: &Counterparty::Height,
) -> Result<Counterparty::ConsensusState, Self::Error>;
consensus_height: &HeightOf<Counterparty>,
) -> Result<ConsensusStateOf<Counterparty, Self>, Self::Error>;
}

impl<Chain, Counterparty> CanQueryConsensusStateWithLatestHeight<Counterparty> for Chain
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ pub trait HasUpdateClientPayloadType<Counterparty>: Async {
type UpdateClientPayload: Async;
}

pub type UpdateClientPayloadOf<Chain, Counterparty> =
<Chain as HasUpdateClientPayloadType<Counterparty>>::UpdateClientPayload;

impl<Chain, Counterparty, Components, Delegate> ProvideUpdateClientPayloadType<Chain, Counterparty>
for UseDelegate<Components>
where
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
pub trait HasCounterparty<Counterparty> {
type Counterparty;
}

impl<Chain, Counterparty> HasCounterparty<Counterparty> for Chain {
type Counterparty = Counterparty;
}

pub trait CanUseCounterparty<Counterparty>:
HasCounterparty<Counterparty, Counterparty = Counterparty>
{
}

impl<Chain, Counterparty> CanUseCounterparty<Counterparty> for Chain {}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ pub trait HasClientStateType<Counterparty>: Async {
type ClientState: Async;
}

pub type ClientStateOf<Chain, Counterparty> =
<Chain as HasClientStateType<Counterparty>>::ClientState;

impl<Chain, Counterparty, Components, Delegate> ProvideClientStateType<Chain, Counterparty>
for UseDelegate<Components>
where
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ pub trait HasConsensusStateType<Counterparty>: Async {
type ConsensusState: Async;
}

pub type ConsensusStateOf<Chain, Counterparty> =
<Chain as HasConsensusStateType<Counterparty>>::ConsensusState;

impl<Chain, Counterparty, Components, Delegate> ProvideConsensusStateType<Chain, Counterparty>
for UseDelegate<Components>
where
Expand Down
21 changes: 21 additions & 0 deletions crates/chain/chain-type-components/src/traits/types/ibc/packet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

use cgp::prelude::*;

use crate::traits::types::counterparty::CanUseCounterparty;

#[cgp_component {
name: OutgoingPacketTypeComponent,
provider: ProvideOutgoingPacketType,
Expand All @@ -18,3 +20,22 @@ pub trait HasOutgoingPacketType<Counterparty>: Async {
*/
type OutgoingPacket: Async;
}

pub trait HasIncomingPacketType<Counterparty>:
Sized
+ Async
+ CanUseCounterparty<
Counterparty,
Counterparty: HasOutgoingPacketType<Self, OutgoingPacket = Self::IncomingPacket>,
>
{
type IncomingPacket: Async;
}

impl<Chain, Counterparty> HasIncomingPacketType<Counterparty> for Chain
where
Chain: Async,
Counterparty: HasOutgoingPacketType<Chain>,
{
type IncomingPacket = Counterparty::OutgoingPacket;
}
1 change: 1 addition & 0 deletions crates/chain/chain-type-components/src/traits/types/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ pub mod amount;
pub mod chain_id;
pub mod commitment_prefix;
pub mod commitment_proof;
pub mod counterparty;
pub mod denom;
pub mod event;
pub mod height;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,5 @@ pub trait HasTimeoutType: HasTimeType {

fn has_timed_out(time: &Self::Time, timeout: &Self::Timeout) -> bool;
}

pub type TimeoutOf<Chain> = <Chain as HasTimeoutType>::Timeout;
10 changes: 9 additions & 1 deletion crates/cosmos/cosmos-chain-components/src/components/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ pub use hermes_relayer_components::chain::traits::message_builders::receive_pack
pub use hermes_relayer_components::chain::traits::message_builders::timeout_unordered_packet::TimeoutUnorderedPacketMessageBuilderComponent;
pub use hermes_relayer_components::chain::traits::message_builders::update_client::UpdateClientMessageBuilderComponent;
pub use hermes_relayer_components::chain::traits::packet::fields::OutgoingPacketFieldsReaderComponent;
pub use hermes_relayer_components::chain::traits::packet::filter::{
IncomingPacketFilterComponent, OutgoingPacketFilterComponent,
};
pub use hermes_relayer_components::chain::traits::packet::from_write_ack::PacketFromWriteAckBuilderComponent;
pub use hermes_relayer_components::chain::traits::payload_builders::ack_packet::AckPacketPayloadBuilderComponent;
pub use hermes_relayer_components::chain::traits::payload_builders::channel_handshake::{
Expand Down Expand Up @@ -163,6 +166,7 @@ use crate::impls::queries::send_packets::QuerySendPacketsConcurrently;
use crate::impls::queries::unreceived_acks::QueryUnreceivedCosmosAcksSequences;
use crate::impls::queries::unreceived_packet::QueryUnreceivedCosmosPacketSequences;
use crate::impls::queries::write_ack_event::QueryCosmosWriteAckEvent;
use crate::impls::relay::packet_filter::FilterPacketWithConfig;
use crate::impls::types::chain::ProvideCosmosChainTypes;
use crate::impls::types::client_state::ProvideAnyRawClientState;
use crate::impls::types::consensus_state::ProvideAnyRawConsensusState;
Expand Down Expand Up @@ -332,7 +336,11 @@ cgp_preset! {
ChannelEndWithProofsQuerierComponent,
]:
QueryCosmosChannelEndFromAbci,

[
OutgoingPacketFilterComponent,
IncomingPacketFilterComponent,
]:
FilterPacketWithConfig<symbol!("packet_filter")>,
[
ClientStateTypeComponent,
ClientStateFieldsComponent,
Expand Down
Loading

0 comments on commit 30f6ef2

Please sign in to comment.