From 5abfea843d0227cb38890da5dfb5539e332223fd Mon Sep 17 00:00:00 2001 From: Branislav Kontur Date: Mon, 21 Nov 2022 14:32:27 +0100 Subject: [PATCH 1/3] Added event `MessagesReceived` for better visibility on receiving side --- modules/messages/src/inbound_lane.rs | 6 +- modules/messages/src/lib.rs | 68 ++++++++++++++++++---- primitives/messages/src/lib.rs | 44 ++++++++++++++ scripts/send-message-from-millau-rialto.sh | 8 +-- scripts/send-message-from-rialto-millau.sh | 8 +-- 5 files changed, 106 insertions(+), 28 deletions(-) diff --git a/modules/messages/src/inbound_lane.rs b/modules/messages/src/inbound_lane.rs index ba4483e608c..ddd67fb0ecc 100644 --- a/modules/messages/src/inbound_lane.rs +++ b/modules/messages/src/inbound_lane.rs @@ -181,12 +181,12 @@ impl InboundLane { } /// Receive new message. - pub fn receive_message, AccountId>( + pub fn receive_message, AccountId>( &mut self, relayer_at_bridged_chain: &S::Relayer, relayer_at_this_chain: &AccountId, nonce: MessageNonce, - message_data: DispatchMessageData, + message_data: DispatchMessageData, ) -> ReceivalResult { let mut data = self.storage.data(); let is_correct_message = nonce == data.last_delivered_nonce() + 1; @@ -206,7 +206,7 @@ impl InboundLane { } // then, dispatch message - let dispatch_result = P::dispatch( + let dispatch_result = Dispatch::dispatch( relayer_at_this_chain, DispatchMessage { key: MessageKey { lane_id: self.storage.id(), nonce }, diff --git a/modules/messages/src/lib.rs b/modules/messages/src/lib.rs index e2e3bef4855..de382c794b1 100644 --- a/modules/messages/src/lib.rs +++ b/modules/messages/src/lib.rs @@ -91,6 +91,7 @@ pub const LOG_TARGET: &str = "runtime::bridge-messages"; #[frame_support::pallet] pub mod pallet { use super::*; + use bp_messages::{NotDispatchedReason, ReceivedMessageResult, ReceivedMessages}; use frame_support::pallet_prelude::*; use frame_system::pallet_prelude::*; @@ -298,6 +299,7 @@ pub mod pallet { // dispatch messages and (optionally) update lane(s) state(s) let mut total_messages = 0; let mut valid_messages = 0; + let mut messages_received_status = Vec::with_capacity(messages.len()); let mut dispatch_weight_left = dispatch_weight; for (lane_id, lane_data) in messages { let mut lane = inbound_lane::(lane_id); @@ -314,24 +316,41 @@ pub mod pallet { } } + let mut lane_messages_received_status = + Vec::with_capacity(lane_data.messages.len()); + let mut is_lane_processing_stopped_no_weight_left = false; + for mut message in lane_data.messages { debug_assert_eq!(message.key.lane_id, lane_id); + total_messages += 1; + + if is_lane_processing_stopped_no_weight_left { + lane_messages_received_status.push(( + message.key.nonce, + NotDispatchedReason::NotEnoughWeightForLane.into(), + )); + continue + } // ensure that relayer has declared enough weight for dispatching next message // on this lane. We can't dispatch lane messages out-of-order, so if declared // weight is not enough, let's move to next lane - let dispatch_weight = T::MessageDispatch::dispatch_weight(&mut message); - if dispatch_weight.any_gt(dispatch_weight_left) { + let message_dispatch_weight = T::MessageDispatch::dispatch_weight(&mut message); + if message_dispatch_weight.any_gt(dispatch_weight_left) { log::trace!( target: LOG_TARGET, "Cannot dispatch any more messages on lane {:?}. Weight: declared={}, left={}", lane_id, - dispatch_weight, + message_dispatch_weight, dispatch_weight_left, ); - break + lane_messages_received_status.push(( + message.key.nonce, + NotDispatchedReason::NotEnoughWeightForLane.into(), + )); + is_lane_processing_stopped_no_weight_left = true; + continue } - total_messages += 1; let receival_result = lane.receive_message::( &relayer_id_at_bridged_chain, @@ -349,18 +368,38 @@ pub mod pallet { let (unspent_weight, refund_pay_dispatch_fee) = match receival_result { ReceivalResult::Dispatched(dispatch_result) => { valid_messages += 1; + lane_messages_received_status + .push((message.key.nonce, ReceivedMessageResult::Dispatched)); ( dispatch_result.unspent_weight, !dispatch_result.dispatch_fee_paid_during_dispatch, ) }, - ReceivalResult::InvalidNonce | - ReceivalResult::TooManyUnrewardedRelayers | - ReceivalResult::TooManyUnconfirmedMessages => (dispatch_weight, true), + ReceivalResult::InvalidNonce => { + lane_messages_received_status.push(( + message.key.nonce, + NotDispatchedReason::InvalidNonce.into(), + )); + (message_dispatch_weight, true) + }, + ReceivalResult::TooManyUnrewardedRelayers => { + lane_messages_received_status.push(( + message.key.nonce, + NotDispatchedReason::TooManyUnrewardedRelayers.into(), + )); + (message_dispatch_weight, true) + }, + ReceivalResult::TooManyUnconfirmedMessages => { + lane_messages_received_status.push(( + message.key.nonce, + NotDispatchedReason::TooManyUnconfirmedMessages.into(), + )); + (message_dispatch_weight, true) + }, }; - let unspent_weight = unspent_weight.min(dispatch_weight); - dispatch_weight_left -= dispatch_weight - unspent_weight; + let unspent_weight = unspent_weight.min(message_dispatch_weight); + dispatch_weight_left -= message_dispatch_weight - unspent_weight; actual_weight = actual_weight.saturating_sub(unspent_weight).saturating_sub( // delivery call weight formula assumes that the fee is paid at // this (target) chain. If the message is prepaid at the source @@ -372,9 +411,12 @@ pub mod pallet { }, ); } + + messages_received_status + .push(ReceivedMessages::new(lane_id, lane_messages_received_status)); } - log::trace!( + log::debug!( target: LOG_TARGET, "Received messages: total={}, valid={}. Weight used: {}/{}", total_messages, @@ -383,6 +425,8 @@ pub mod pallet { declared_weight, ); + Self::deposit_event(Event::MessagesReceived(messages_received_status)); + Ok(PostDispatchInfo { actual_weight: Some(actual_weight), pays_fee: Pays::Yes }) } @@ -494,6 +538,8 @@ pub mod pallet { pub enum Event, I: 'static = ()> { /// Message has been accepted and is waiting to be delivered. MessageAccepted { lane_id: LaneId, nonce: MessageNonce }, + /// Messages have been received from the bridged chain. + MessagesReceived(Vec>), /// Messages in the inclusive range have been delivered to the bridged chain. MessagesDelivered { lane_id: LaneId, messages: DeliveredMessages }, } diff --git a/primitives/messages/src/lib.rs b/primitives/messages/src/lib.rs index f535a40a9db..4e6094a5db0 100644 --- a/primitives/messages/src/lib.rs +++ b/primitives/messages/src/lib.rs @@ -218,6 +218,50 @@ pub struct UnrewardedRelayer { pub messages: DeliveredMessages, } +/// Received messages with their dispatch result. +#[derive(Clone, Default, Encode, Decode, RuntimeDebug, PartialEq, Eq, TypeInfo)] +pub struct ReceivedMessages { + pub lane: LaneId, + pub receive_results: Vec<(MessageNonce, Result)>, +} + +impl ReceivedMessages { + pub fn new(lane: LaneId, receive_results: Vec<(MessageNonce, Result)>) -> Self { + ReceivedMessages { lane, receive_results } + } +} + +/// Result of single message receival. +#[derive(RuntimeDebug, Encode, Decode, PartialEq, Eq, Clone, TypeInfo)] +pub enum ReceivedMessageResult { + /// Message has been received and dispatched. Note that we don't care whether dispatch has + /// been successful or not - in both case message falls into this category. + /// + /// The message dispatch result is also returned. + Dispatched, + /// Reason why messages was not dispatched + NotDispatched(NotDispatchedReason), +} + +/// Result of single message receival. +#[derive(RuntimeDebug, Encode, Decode, PartialEq, Eq, Clone, TypeInfo)] +pub enum NotDispatchedReason { + /// Message has invalid nonce and lane has rejected to accept this message. + InvalidNonce, + /// There are too many unrewarded relayer entries at the lane. + TooManyUnrewardedRelayers, + /// There are too many unconfirmed messages at the lane. + TooManyUnconfirmedMessages, + /// There are too many unconfirmed messages at the lane. + NotEnoughWeightForLane, +} + +impl From for ReceivedMessageResult { + fn from(value: NotDispatchedReason) -> Self { + ReceivedMessageResult::NotDispatched(value) + } +} + /// Delivered messages with their dispatch result. #[derive(Clone, Default, Encode, Decode, RuntimeDebug, PartialEq, Eq, TypeInfo)] pub struct DeliveredMessages { diff --git a/scripts/send-message-from-millau-rialto.sh b/scripts/send-message-from-millau-rialto.sh index d14b08021ee..bcb9f418ea8 100755 --- a/scripts/send-message-from-millau-rialto.sh +++ b/scripts/send-message-from-millau-rialto.sh @@ -15,10 +15,7 @@ case "$1" in --source-host localhost \ --source-port $MILLAU_PORT \ --source-signer //Alice \ - --target-signer //Bob \ - --lane 00000000 \ - --origin Target \ - remark \ + raw 020419ac ;; transfer) RUST_LOG=runtime=trace,substrate-relay=trace,bridge=trace \ @@ -26,9 +23,6 @@ case "$1" in --source-host localhost \ --source-port $MILLAU_PORT \ --source-signer //Alice \ - --target-signer //Bob \ - --lane 00000000 \ - --origin Target \ transfer \ --amount 100000000000000 \ --recipient 5DZvVvd1udr61vL7Xks17TFQ4fi9NiagYLaBobnbPCP14ewA \ diff --git a/scripts/send-message-from-rialto-millau.sh b/scripts/send-message-from-rialto-millau.sh index 10582aa6b3a..76a531073a9 100755 --- a/scripts/send-message-from-rialto-millau.sh +++ b/scripts/send-message-from-rialto-millau.sh @@ -14,21 +14,15 @@ case "$1" in ./target/debug/substrate-relay send-message rialto-to-millau \ --source-host localhost \ --source-port $RIALTO_PORT \ - --target-signer //Alice \ --source-signer //Bob \ - --lane 00000000 \ - --origin Target \ - remark \ + raw 020419ac ;; transfer) RUST_LOG=runtime=trace,substrate-relay=trace,bridge=trace \ ./target/debug/substrate-relay send-message rialto-to-millau \ --source-host localhost \ --source-port $RIALTO_PORT \ - --target-signer //Alice \ --source-signer //Bob \ - --lane 00000000 \ - --origin Target \ transfer \ --amount 100000000000000 \ --recipient 5DZvVvd1udr61vL7Xks17TFQ4fi9NiagYLaBobnbPCP14ewA \ From 464eb299438a95bad115d7334f18599480983228 Mon Sep 17 00:00:00 2001 From: Branislav Kontur Date: Mon, 21 Nov 2022 15:30:07 +0100 Subject: [PATCH 2/3] Fixes/comments from PR --- modules/messages/src/inbound_lane.rs | 17 ++++++++- modules/messages/src/lib.rs | 44 ++++++---------------- primitives/messages/src/lib.rs | 16 ++++++-- scripts/send-message-from-millau-rialto.sh | 2 + scripts/send-message-from-rialto-millau.sh | 2 + 5 files changed, 44 insertions(+), 37 deletions(-) diff --git a/modules/messages/src/inbound_lane.rs b/modules/messages/src/inbound_lane.rs index ddd67fb0ecc..02c86702282 100644 --- a/modules/messages/src/inbound_lane.rs +++ b/modules/messages/src/inbound_lane.rs @@ -20,8 +20,8 @@ use crate::Config; use bp_messages::{ target_chain::{DispatchMessage, DispatchMessageData, MessageDispatch}, - DeliveredMessages, InboundLaneData, LaneId, MessageKey, MessageNonce, OutboundLaneData, - UnrewardedRelayer, + DeliveredMessages, InboundLaneData, LaneId, MessageKey, MessageNonce, NotDispatchedReason, + OutboundLaneData, ReceivedMessageResult, UnrewardedRelayer, }; use bp_runtime::messages::MessageDispatchResult; use codec::{Decode, Encode, EncodeLike, MaxEncodedLen}; @@ -124,6 +124,19 @@ pub enum ReceivalResult { TooManyUnconfirmedMessages, } +impl From for ReceivedMessageResult { + fn from(value: ReceivalResult) -> Self { + match value { + ReceivalResult::Dispatched(_) => ReceivedMessageResult::Dispatched, + ReceivalResult::InvalidNonce => NotDispatchedReason::InvalidNonce.into(), + ReceivalResult::TooManyUnrewardedRelayers => + NotDispatchedReason::TooManyUnrewardedRelayers.into(), + ReceivalResult::TooManyUnconfirmedMessages => + NotDispatchedReason::TooManyUnconfirmedMessages.into(), + } + } +} + /// Inbound messages lane. pub struct InboundLane { storage: S, diff --git a/modules/messages/src/lib.rs b/modules/messages/src/lib.rs index de382c794b1..fd0cd452acc 100644 --- a/modules/messages/src/lib.rs +++ b/modules/messages/src/lib.rs @@ -91,7 +91,7 @@ pub const LOG_TARGET: &str = "runtime::bridge-messages"; #[frame_support::pallet] pub mod pallet { use super::*; - use bp_messages::{NotDispatchedReason, ReceivedMessageResult, ReceivedMessages}; + use bp_messages::{ReceivedMessageResult, ReceivedMessages}; use frame_support::pallet_prelude::*; use frame_system::pallet_prelude::*; @@ -317,7 +317,7 @@ pub mod pallet { } let mut lane_messages_received_status = - Vec::with_capacity(lane_data.messages.len()); + ReceivedMessages::new(lane_id, Vec::with_capacity(lane_data.messages.len())); let mut is_lane_processing_stopped_no_weight_left = false; for mut message in lane_data.messages { @@ -325,10 +325,8 @@ pub mod pallet { total_messages += 1; if is_lane_processing_stopped_no_weight_left { - lane_messages_received_status.push(( - message.key.nonce, - NotDispatchedReason::NotEnoughWeightForLane.into(), - )); + lane_messages_received_status + .push_skipped_for_not_enough_weight(message.key.nonce); continue } @@ -344,10 +342,8 @@ pub mod pallet { message_dispatch_weight, dispatch_weight_left, ); - lane_messages_received_status.push(( - message.key.nonce, - NotDispatchedReason::NotEnoughWeightForLane.into(), - )); + lane_messages_received_status + .push_skipped_for_not_enough_weight(message.key.nonce); is_lane_processing_stopped_no_weight_left = true; continue } @@ -369,31 +365,16 @@ pub mod pallet { ReceivalResult::Dispatched(dispatch_result) => { valid_messages += 1; lane_messages_received_status - .push((message.key.nonce, ReceivedMessageResult::Dispatched)); + .push(message.key.nonce, ReceivedMessageResult::Dispatched); ( dispatch_result.unspent_weight, !dispatch_result.dispatch_fee_paid_during_dispatch, ) }, - ReceivalResult::InvalidNonce => { - lane_messages_received_status.push(( - message.key.nonce, - NotDispatchedReason::InvalidNonce.into(), - )); - (message_dispatch_weight, true) - }, - ReceivalResult::TooManyUnrewardedRelayers => { - lane_messages_received_status.push(( - message.key.nonce, - NotDispatchedReason::TooManyUnrewardedRelayers.into(), - )); - (message_dispatch_weight, true) - }, - ReceivalResult::TooManyUnconfirmedMessages => { - lane_messages_received_status.push(( - message.key.nonce, - NotDispatchedReason::TooManyUnconfirmedMessages.into(), - )); + rr @ ReceivalResult::InvalidNonce | + rr @ ReceivalResult::TooManyUnrewardedRelayers | + rr @ ReceivalResult::TooManyUnconfirmedMessages => { + lane_messages_received_status.push(message.key.nonce, rr.into()); (message_dispatch_weight, true) }, }; @@ -412,8 +393,7 @@ pub mod pallet { ); } - messages_received_status - .push(ReceivedMessages::new(lane_id, lane_messages_received_status)); + messages_received_status.push(lane_messages_received_status); } log::debug!( diff --git a/primitives/messages/src/lib.rs b/primitives/messages/src/lib.rs index 4e6094a5db0..2a78371eead 100644 --- a/primitives/messages/src/lib.rs +++ b/primitives/messages/src/lib.rs @@ -221,13 +221,25 @@ pub struct UnrewardedRelayer { /// Received messages with their dispatch result. #[derive(Clone, Default, Encode, Decode, RuntimeDebug, PartialEq, Eq, TypeInfo)] pub struct ReceivedMessages { + /// Id of the lane which is receiving messages. pub lane: LaneId, + /// Result of messages which we tried to dispatch pub receive_results: Vec<(MessageNonce, Result)>, + /// Messages which were skipped and never dispatched + pub skipped_for_not_enough_weight: Vec, } impl ReceivedMessages { pub fn new(lane: LaneId, receive_results: Vec<(MessageNonce, Result)>) -> Self { - ReceivedMessages { lane, receive_results } + ReceivedMessages { lane, receive_results, skipped_for_not_enough_weight: Vec::new() } + } + + pub fn push(&mut self, message: MessageNonce, result: Result) { + self.receive_results.push((message, result)); + } + + pub fn push_skipped_for_not_enough_weight(&mut self, message: MessageNonce) { + self.skipped_for_not_enough_weight.push(message); } } @@ -252,8 +264,6 @@ pub enum NotDispatchedReason { TooManyUnrewardedRelayers, /// There are too many unconfirmed messages at the lane. TooManyUnconfirmedMessages, - /// There are too many unconfirmed messages at the lane. - NotEnoughWeightForLane, } impl From for ReceivedMessageResult { diff --git a/scripts/send-message-from-millau-rialto.sh b/scripts/send-message-from-millau-rialto.sh index bcb9f418ea8..539ca5fc06c 100755 --- a/scripts/send-message-from-millau-rialto.sh +++ b/scripts/send-message-from-millau-rialto.sh @@ -6,6 +6,8 @@ # we have (to make sure the message relays are running), but remove the message # generator service. From there you may submit messages manually using this script. +# TODO: Fix demeo scripts https://github.com/paritytech/parity-bridges-common/issues/1406 + MILLAU_PORT="${RIALTO_PORT:-9945}" case "$1" in diff --git a/scripts/send-message-from-rialto-millau.sh b/scripts/send-message-from-rialto-millau.sh index 76a531073a9..923f588ea47 100755 --- a/scripts/send-message-from-rialto-millau.sh +++ b/scripts/send-message-from-rialto-millau.sh @@ -6,6 +6,8 @@ # we have (to make sure the message relays are running), but remove the message # generator service. From there you may submit messages manually using this script. +# TODO: Fix demeo scripts https://github.com/paritytech/parity-bridges-common/issues/1406 + RIALTO_PORT="${RIALTO_PORT:-9944}" case "$1" in From d0f290b07cbf85e02de2834c4e549ce7649b358d Mon Sep 17 00:00:00 2001 From: Branislav Kontur Date: Mon, 21 Nov 2022 16:15:17 +0100 Subject: [PATCH 3/3] Final cleanup --- modules/messages/src/inbound_lane.rs | 34 ++-------------------------- modules/messages/src/lib.rs | 20 +++++++--------- primitives/messages/src/lib.rs | 18 +++------------ 3 files changed, 13 insertions(+), 59 deletions(-) diff --git a/modules/messages/src/inbound_lane.rs b/modules/messages/src/inbound_lane.rs index 02c86702282..aa2a9682668 100644 --- a/modules/messages/src/inbound_lane.rs +++ b/modules/messages/src/inbound_lane.rs @@ -20,10 +20,9 @@ use crate::Config; use bp_messages::{ target_chain::{DispatchMessage, DispatchMessageData, MessageDispatch}, - DeliveredMessages, InboundLaneData, LaneId, MessageKey, MessageNonce, NotDispatchedReason, - OutboundLaneData, ReceivedMessageResult, UnrewardedRelayer, + DeliveredMessages, InboundLaneData, LaneId, MessageKey, MessageNonce, OutboundLaneData, + ReceivalResult, UnrewardedRelayer, }; -use bp_runtime::messages::MessageDispatchResult; use codec::{Decode, Encode, EncodeLike, MaxEncodedLen}; use frame_support::{traits::Get, RuntimeDebug}; use scale_info::{Type, TypeInfo}; @@ -108,35 +107,6 @@ impl, I: 'static> MaxEncodedLen for StoredInboundLaneData { } } -/// Result of single message receival. -#[derive(RuntimeDebug, PartialEq, Eq)] -pub enum ReceivalResult { - /// Message has been received and dispatched. Note that we don't care whether dispatch has - /// been successful or not - in both case message falls into this category. - /// - /// The message dispatch result is also returned. - Dispatched(MessageDispatchResult), - /// Message has invalid nonce and lane has rejected to accept this message. - InvalidNonce, - /// There are too many unrewarded relayer entries at the lane. - TooManyUnrewardedRelayers, - /// There are too many unconfirmed messages at the lane. - TooManyUnconfirmedMessages, -} - -impl From for ReceivedMessageResult { - fn from(value: ReceivalResult) -> Self { - match value { - ReceivalResult::Dispatched(_) => ReceivedMessageResult::Dispatched, - ReceivalResult::InvalidNonce => NotDispatchedReason::InvalidNonce.into(), - ReceivalResult::TooManyUnrewardedRelayers => - NotDispatchedReason::TooManyUnrewardedRelayers.into(), - ReceivalResult::TooManyUnconfirmedMessages => - NotDispatchedReason::TooManyUnconfirmedMessages.into(), - } - } -} - /// Inbound messages lane. pub struct InboundLane { storage: S, diff --git a/modules/messages/src/lib.rs b/modules/messages/src/lib.rs index fd0cd452acc..b7e7f72f5fa 100644 --- a/modules/messages/src/lib.rs +++ b/modules/messages/src/lib.rs @@ -46,7 +46,7 @@ pub use weights_ext::{ }; use crate::{ - inbound_lane::{InboundLane, InboundLaneStorage, ReceivalResult}, + inbound_lane::{InboundLane, InboundLaneStorage}, outbound_lane::{OutboundLane, OutboundLaneStorage, ReceivalConfirmationResult}, }; @@ -91,7 +91,7 @@ pub const LOG_TARGET: &str = "runtime::bridge-messages"; #[frame_support::pallet] pub mod pallet { use super::*; - use bp_messages::{ReceivedMessageResult, ReceivedMessages}; + use bp_messages::{ReceivalResult, ReceivedMessages}; use frame_support::pallet_prelude::*; use frame_system::pallet_prelude::*; @@ -361,23 +361,19 @@ pub mod pallet { // losing funds for messages dispatch. But keep in mind that relayer pays base // delivery transaction cost anyway. And base cost covers everything except // dispatch, so we have a balance here. - let (unspent_weight, refund_pay_dispatch_fee) = match receival_result { + let (unspent_weight, refund_pay_dispatch_fee) = match &receival_result { ReceivalResult::Dispatched(dispatch_result) => { valid_messages += 1; - lane_messages_received_status - .push(message.key.nonce, ReceivedMessageResult::Dispatched); ( dispatch_result.unspent_weight, !dispatch_result.dispatch_fee_paid_during_dispatch, ) }, - rr @ ReceivalResult::InvalidNonce | - rr @ ReceivalResult::TooManyUnrewardedRelayers | - rr @ ReceivalResult::TooManyUnconfirmedMessages => { - lane_messages_received_status.push(message.key.nonce, rr.into()); - (message_dispatch_weight, true) - }, + ReceivalResult::InvalidNonce | + ReceivalResult::TooManyUnrewardedRelayers | + ReceivalResult::TooManyUnconfirmedMessages => (message_dispatch_weight, true), }; + lane_messages_received_status.push(message.key.nonce, receival_result); let unspent_weight = unspent_weight.min(message_dispatch_weight); dispatch_weight_left -= message_dispatch_weight - unspent_weight; @@ -519,7 +515,7 @@ pub mod pallet { /// Message has been accepted and is waiting to be delivered. MessageAccepted { lane_id: LaneId, nonce: MessageNonce }, /// Messages have been received from the bridged chain. - MessagesReceived(Vec>), + MessagesReceived(Vec>), /// Messages in the inclusive range have been delivered to the bridged chain. MessagesDelivered { lane_id: LaneId, messages: DeliveredMessages }, } diff --git a/primitives/messages/src/lib.rs b/primitives/messages/src/lib.rs index 2a78371eead..d8164479598 100644 --- a/primitives/messages/src/lib.rs +++ b/primitives/messages/src/lib.rs @@ -32,6 +32,7 @@ pub mod storage_keys; pub mod target_chain; // Weight is reexported to avoid additional frame-support dependencies in related crates. +use bp_runtime::messages::MessageDispatchResult; pub use frame_support::weights::Weight; /// Messages pallet operating mode. @@ -245,19 +246,12 @@ impl ReceivedMessages { /// Result of single message receival. #[derive(RuntimeDebug, Encode, Decode, PartialEq, Eq, Clone, TypeInfo)] -pub enum ReceivedMessageResult { +pub enum ReceivalResult { /// Message has been received and dispatched. Note that we don't care whether dispatch has /// been successful or not - in both case message falls into this category. /// /// The message dispatch result is also returned. - Dispatched, - /// Reason why messages was not dispatched - NotDispatched(NotDispatchedReason), -} - -/// Result of single message receival. -#[derive(RuntimeDebug, Encode, Decode, PartialEq, Eq, Clone, TypeInfo)] -pub enum NotDispatchedReason { + Dispatched(MessageDispatchResult), /// Message has invalid nonce and lane has rejected to accept this message. InvalidNonce, /// There are too many unrewarded relayer entries at the lane. @@ -266,12 +260,6 @@ pub enum NotDispatchedReason { TooManyUnconfirmedMessages, } -impl From for ReceivedMessageResult { - fn from(value: NotDispatchedReason) -> Self { - ReceivedMessageResult::NotDispatched(value) - } -} - /// Delivered messages with their dispatch result. #[derive(Clone, Default, Encode, Decode, RuntimeDebug, PartialEq, Eq, TypeInfo)] pub struct DeliveredMessages {