-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Perform packet filter on chain context instead of on relay context (#497
) * Rename CanFilterPackets to CanFilterRelayPackets * Add back HasIncomingPacketType alias * Add HasRelayPacketType * Use HasRelayPacketType in CanFilterRelayPacket * Implement OutgoingPacketFilter for FilterPacketWithConfig * Add HasCounterparty and CanUseCounterparty helper * Implement IncomingPacketFilter for FilterPacketWithConfig * Add packet_filter field to CosmosChain * Implement CanFilterPacket for CosmosChain * Simplify trait bounds of counterparty * Add FilterRelayPacketWithChains * Remove packet_filter field from CosmosRelay * Use FilterRelayPacketWithChains in WasmRelayer * Remove relay impl of FilterPacketWithConfig * Simplify delegation of extra relay components * Implement RelayPacketFilter in DefaultRelayComponents * Rename default/extra-RelayComponents to -RelayPreset
- Loading branch information
1 parent
01813c1
commit be7d07f
Showing
46 changed files
with
372 additions
and
228 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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>; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
crates/chain/chain-type-components/src/traits/types/counterparty.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 40 additions & 16 deletions
56
crates/cosmos/cosmos-chain-components/src/impls/relay/packet_filter.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,55 @@ | ||
use core::marker::PhantomData; | ||
|
||
use cgp::prelude::HasField; | ||
use cgp::core::Async; | ||
use cgp::prelude::{HasErrorType, HasField}; | ||
use hermes_relayer_components::chain::traits::packet::fields::CanReadOutgoingPacketFields; | ||
use hermes_relayer_components::chain::traits::packet::filter::{ | ||
IncomingPacketFilter, OutgoingPacketFilter, | ||
}; | ||
use hermes_relayer_components::chain::traits::types::ibc::{HasChannelIdType, HasPortIdType}; | ||
use hermes_relayer_components::relay::traits::chains::{HasRelayChainTypes, PacketOf}; | ||
use hermes_relayer_components::relay::traits::packet_filter::PacketFilter; | ||
use ibc::core::host::types::identifiers::{ChannelId, PortId}; | ||
|
||
use crate::types::messages::packet::packet_filter::PacketFilterConfig; | ||
|
||
pub struct FilterPacketWithConfig<Tag>(pub PhantomData<Tag>); | ||
|
||
impl<Relay, Tag, SrcChain, DstChain> PacketFilter<Relay> for FilterPacketWithConfig<Tag> | ||
impl<Chain, Counterparty, Tag> OutgoingPacketFilter<Chain, Counterparty> | ||
for FilterPacketWithConfig<Tag> | ||
where | ||
Relay: HasRelayChainTypes<SrcChain = SrcChain, DstChain = DstChain> | ||
+ HasField<Tag, Value = PacketFilterConfig>, | ||
SrcChain: CanReadOutgoingPacketFields<DstChain> | ||
+ HasPortIdType<DstChain, PortId = PortId> | ||
+ HasChannelIdType<DstChain, ChannelId = ChannelId>, | ||
Chain: CanReadOutgoingPacketFields<Counterparty> | ||
+ HasPortIdType<Counterparty, PortId = PortId> | ||
+ HasChannelIdType<Counterparty, ChannelId = ChannelId> | ||
+ HasField<Tag, Value = PacketFilterConfig> | ||
+ HasErrorType, | ||
{ | ||
async fn should_relay_packet( | ||
relay: &Relay, | ||
packet: &PacketOf<Relay>, | ||
) -> Result<bool, Relay::Error> { | ||
Ok(relay.get_field(PhantomData).is_allowed( | ||
SrcChain::outgoing_packet_src_port(packet), | ||
SrcChain::outgoing_packet_src_channel_id(packet), | ||
async fn should_relay_outgoing_packet( | ||
chain: &Chain, | ||
packet: &Chain::OutgoingPacket, | ||
) -> Result<bool, Chain::Error> { | ||
Ok(chain.get_field(PhantomData).is_allowed( | ||
Chain::outgoing_packet_src_port(packet), | ||
Chain::outgoing_packet_src_channel_id(packet), | ||
)) | ||
} | ||
} | ||
|
||
impl<Chain, Counterparty, Tag> IncomingPacketFilter<Chain, Counterparty> | ||
for FilterPacketWithConfig<Tag> | ||
where | ||
Chain: Async | ||
+ HasField<Tag, Value = PacketFilterConfig> | ||
+ HasPortIdType<Counterparty, PortId = PortId> | ||
+ HasChannelIdType<Counterparty, ChannelId = ChannelId> | ||
+ HasErrorType, | ||
Counterparty: CanReadOutgoingPacketFields<Chain>, | ||
{ | ||
async fn should_relay_incoming_packet( | ||
chain: &Chain, | ||
packet: &Counterparty::OutgoingPacket, | ||
) -> Result<bool, Chain::Error> { | ||
Ok(chain.get_field(PhantomData).is_allowed( | ||
Counterparty::outgoing_packet_dst_port(packet), | ||
Counterparty::outgoing_packet_dst_channel_id(packet), | ||
)) | ||
} | ||
} |
Oops, something went wrong.