Skip to content

Commit

Permalink
ForbidOutboundMessages and ForbidInboundMessages (paritytech#735)
Browse files Browse the repository at this point in the history
  • Loading branch information
svyatonik authored and serban300 committed Apr 10, 2024
1 parent 3c55eb4 commit c3e809f
Show file tree
Hide file tree
Showing 3 changed files with 91 additions and 0 deletions.
56 changes: 56 additions & 0 deletions bridges/primitives/message-lane/src/source_chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,3 +134,59 @@ pub trait MessageDeliveryAndDispatchPayment<AccountId, Balance> {
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<Payload, AccountId> TargetHeaderChain<Payload, AccountId> 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<AccountId>), Self::Error> {
Err(ALL_OUTBOUND_MESSAGES_REJECTED)
}
}

impl<Submitter, Payload, Fee> LaneMessageVerifier<Submitter, Payload, Fee> for ForbidOutboundMessages {
type Error = &'static str;

fn verify_message(
_submitter: &Sender<Submitter>,
_delivery_and_dispatch_fee: &Fee,
_lane: &LaneId,
_outbound_data: &OutboundLaneData,
_payload: &Payload,
) -> Result<(), Self::Error> {
Err(ALL_OUTBOUND_MESSAGES_REJECTED)
}
}

impl<AccountId, Balance> MessageDeliveryAndDispatchPayment<AccountId, Balance> for ForbidOutboundMessages {
type Error = &'static str;

fn pay_delivery_and_dispatch_fee(
_submitter: &Sender<AccountId>,
_fee: &Balance,
_relayer_fund_account: &AccountId,
) -> Result<(), Self::Error> {
Err(ALL_OUTBOUND_MESSAGES_REJECTED)
}

fn pay_relayers_rewards(
_confirmation_relayer: &AccountId,
_relayers_rewards: RelayersRewards<AccountId, Balance>,
_relayer_fund_account: &AccountId,
) {
}
}
29 changes: 29 additions & 0 deletions bridges/primitives/message-lane/src/target_chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,3 +129,32 @@ impl<DispatchPayload: Decode, Fee> From<MessageData<Fee>> 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<Fee> SourceHeaderChain<Fee> for ForbidInboundMessages {
type Error = &'static str;
type MessagesProof = ();

fn verify_messages_proof(
_proof: Self::MessagesProof,
_messages_count: u32,
) -> Result<ProvedMessages<Message<Fee>>, Self::Error> {
Err(ALL_INBOUND_MESSAGES_REJECTED)
}
}

impl<Fee> MessageDispatch<Fee> for ForbidInboundMessages {
type DispatchPayload = ();

fn dispatch_weight(_message: &DispatchMessage<Self::DispatchPayload, Fee>) -> Weight {
Weight::MAX
}

fn dispatch(_message: DispatchMessage<Self::DispatchPayload, Fee>) {}
}
6 changes: 6 additions & 0 deletions bridges/primitives/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down

0 comments on commit c3e809f

Please sign in to comment.