From c3e809f0e5b9916f7c4bc66261310f5a26b692a9 Mon Sep 17 00:00:00 2001 From: Svyatoslav Nikolsky Date: Wed, 17 Feb 2021 15:09:02 +0300 Subject: [PATCH] ForbidOutboundMessages and ForbidInboundMessages (#735) --- .../message-lane/src/source_chain.rs | 56 +++++++++++++++++++ .../message-lane/src/target_chain.rs | 29 ++++++++++ bridges/primitives/runtime/src/lib.rs | 6 ++ 3 files changed, 91 insertions(+) diff --git a/bridges/primitives/message-lane/src/source_chain.rs b/bridges/primitives/message-lane/src/source_chain.rs index 1bb0d591586f9..d0dc36bb69352 100644 --- a/bridges/primitives/message-lane/src/source_chain.rs +++ b/bridges/primitives/message-lane/src/source_chain.rs @@ -134,3 +134,59 @@ pub trait MessageDeliveryAndDispatchPayment { 0 } } + +/// Structure that may be used in place of `TargetHeaderChain`, `LaneMessageVerifier` and +/// `MessageDeliveryAndDispatchPayment` on chains, where outbound messages are forbidden. +pub struct ForbidOutboundMessages; + +/// Error message that is used in `ForbidOutboundMessages` implementation. +const ALL_OUTBOUND_MESSAGES_REJECTED: &str = "This chain is configured to reject all outbound messages"; + +impl TargetHeaderChain for ForbidOutboundMessages { + type Error = &'static str; + + type MessagesDeliveryProof = (); + + fn verify_message(_payload: &Payload) -> Result<(), Self::Error> { + Err(ALL_OUTBOUND_MESSAGES_REJECTED) + } + + fn verify_messages_delivery_proof( + _proof: Self::MessagesDeliveryProof, + ) -> Result<(LaneId, InboundLaneData), Self::Error> { + Err(ALL_OUTBOUND_MESSAGES_REJECTED) + } +} + +impl LaneMessageVerifier for ForbidOutboundMessages { + type Error = &'static str; + + fn verify_message( + _submitter: &Sender, + _delivery_and_dispatch_fee: &Fee, + _lane: &LaneId, + _outbound_data: &OutboundLaneData, + _payload: &Payload, + ) -> Result<(), Self::Error> { + Err(ALL_OUTBOUND_MESSAGES_REJECTED) + } +} + +impl MessageDeliveryAndDispatchPayment for ForbidOutboundMessages { + type Error = &'static str; + + fn pay_delivery_and_dispatch_fee( + _submitter: &Sender, + _fee: &Balance, + _relayer_fund_account: &AccountId, + ) -> Result<(), Self::Error> { + Err(ALL_OUTBOUND_MESSAGES_REJECTED) + } + + fn pay_relayers_rewards( + _confirmation_relayer: &AccountId, + _relayers_rewards: RelayersRewards, + _relayer_fund_account: &AccountId, + ) { + } +} diff --git a/bridges/primitives/message-lane/src/target_chain.rs b/bridges/primitives/message-lane/src/target_chain.rs index 825fe67c54915..765ce64f63b39 100644 --- a/bridges/primitives/message-lane/src/target_chain.rs +++ b/bridges/primitives/message-lane/src/target_chain.rs @@ -129,3 +129,32 @@ impl From> for DispatchMessageDat } } } + +/// Structure that may be used in place of `SourceHeaderChain` and `MessageDispatch` on chains, +/// where inbound messages are forbidden. +pub struct ForbidInboundMessages; + +/// Error message that is used in `ForbidOutboundMessages` implementation. +const ALL_INBOUND_MESSAGES_REJECTED: &str = "This chain is configured to reject all inbound messages"; + +impl SourceHeaderChain for ForbidInboundMessages { + type Error = &'static str; + type MessagesProof = (); + + fn verify_messages_proof( + _proof: Self::MessagesProof, + _messages_count: u32, + ) -> Result>, Self::Error> { + Err(ALL_INBOUND_MESSAGES_REJECTED) + } +} + +impl MessageDispatch for ForbidInboundMessages { + type DispatchPayload = (); + + fn dispatch_weight(_message: &DispatchMessage) -> Weight { + Weight::MAX + } + + fn dispatch(_message: DispatchMessage) {} +} diff --git a/bridges/primitives/runtime/src/lib.rs b/bridges/primitives/runtime/src/lib.rs index 058c510c1b526..6612e26c37dca 100644 --- a/bridges/primitives/runtime/src/lib.rs +++ b/bridges/primitives/runtime/src/lib.rs @@ -112,6 +112,12 @@ pub trait Size { fn size_hint(&self) -> u32; } +impl Size for () { + fn size_hint(&self) -> u32 { + 0 + } +} + /// Pre-computed size. pub struct PreComputedSize(pub usize);