diff --git a/bridges/bin/millau/runtime/src/lib.rs b/bridges/bin/millau/runtime/src/lib.rs index 095250a55861a..49cd16834bb76 100644 --- a/bridges/bin/millau/runtime/src/lib.rs +++ b/bridges/bin/millau/runtime/src/lib.rs @@ -494,8 +494,6 @@ impl pallet_bridge_messages::Config for Runtime { Runtime, WithRialtoMessagesInstance, >; - type OnMessageAccepted = (); - type OnDeliveryConfirmed = (); type SourceHeaderChain = crate::rialto_messages::Rialto; type MessageDispatch = crate::rialto_messages::FromRialtoMessageDispatch; @@ -526,8 +524,6 @@ impl pallet_bridge_messages::Config for Run Runtime, WithRialtoParachainMessagesInstance, >; - type OnMessageAccepted = (); - type OnDeliveryConfirmed = (); type SourceHeaderChain = crate::rialto_parachain_messages::RialtoParachain; type MessageDispatch = crate::rialto_parachain_messages::FromRialtoParachainMessageDispatch; diff --git a/bridges/bin/millau/runtime/src/rialto_messages.rs b/bridges/bin/millau/runtime/src/rialto_messages.rs index c0868298a3276..5d7b189db2af9 100644 --- a/bridges/bin/millau/runtime/src/rialto_messages.rs +++ b/bridges/bin/millau/runtime/src/rialto_messages.rs @@ -177,7 +177,7 @@ impl SourceHeaderChain for Rialto { #[cfg(test)] mod tests { use super::*; - use crate::{DbWeight, Runtime, WithRialtoMessagesInstance}; + use crate::{Runtime, WithRialtoMessagesInstance}; use bp_runtime::Chain; use bridge_runtime_common::{ @@ -218,7 +218,6 @@ mod tests { max_incoming_inbound_lane_data_proof_size, bp_millau::MAX_UNREWARDED_RELAYERS_IN_CONFIRMATION_TX, bp_millau::MAX_UNCONFIRMED_MESSAGES_IN_CONFIRMATION_TX, - DbWeight::get(), ); } diff --git a/bridges/bin/rialto-parachain/runtime/src/lib.rs b/bridges/bin/rialto-parachain/runtime/src/lib.rs index c5b9e50d067c0..7487e68f8f953 100644 --- a/bridges/bin/rialto-parachain/runtime/src/lib.rs +++ b/bridges/bin/rialto-parachain/runtime/src/lib.rs @@ -579,8 +579,6 @@ impl pallet_bridge_messages::Config for Runtime { Runtime, WithMillauMessagesInstance, >; - type OnMessageAccepted = (); - type OnDeliveryConfirmed = (); type SourceHeaderChain = crate::millau_messages::Millau; type MessageDispatch = crate::millau_messages::FromMillauMessageDispatch; diff --git a/bridges/bin/rialto/runtime/src/lib.rs b/bridges/bin/rialto/runtime/src/lib.rs index 3ce0b650dc5f1..378a471325d66 100644 --- a/bridges/bin/rialto/runtime/src/lib.rs +++ b/bridges/bin/rialto/runtime/src/lib.rs @@ -467,8 +467,6 @@ impl pallet_bridge_messages::Config for Runtime { Runtime, WithMillauMessagesInstance, >; - type OnMessageAccepted = (); - type OnDeliveryConfirmed = (); type SourceHeaderChain = crate::millau_messages::Millau; type MessageDispatch = crate::millau_messages::FromMillauMessageDispatch; diff --git a/bridges/bin/rialto/runtime/src/millau_messages.rs b/bridges/bin/rialto/runtime/src/millau_messages.rs index 9eb6c82f3678d..98030ac3ee52e 100644 --- a/bridges/bin/rialto/runtime/src/millau_messages.rs +++ b/bridges/bin/rialto/runtime/src/millau_messages.rs @@ -175,7 +175,7 @@ impl SourceHeaderChain for Millau { #[cfg(test)] mod tests { use super::*; - use crate::{DbWeight, MillauGrandpaInstance, Runtime, WithMillauMessagesInstance}; + use crate::{MillauGrandpaInstance, Runtime, WithMillauMessagesInstance}; use bp_runtime::Chain; use bridge_runtime_common::{ assert_complete_bridge_types, @@ -214,7 +214,6 @@ mod tests { max_incoming_inbound_lane_data_proof_size, bp_rialto::MAX_UNREWARDED_RELAYERS_IN_CONFIRMATION_TX, bp_rialto::MAX_UNCONFIRMED_MESSAGES_IN_CONFIRMATION_TX, - DbWeight::get(), ); } diff --git a/bridges/modules/messages/src/lib.rs b/bridges/modules/messages/src/lib.rs index d6a5ffe453c0b..8324aa75bc833 100644 --- a/bridges/modules/messages/src/lib.rs +++ b/bridges/modules/messages/src/lib.rs @@ -52,8 +52,8 @@ use crate::{ use bp_messages::{ source_chain::{ - LaneMessageVerifier, MessageDeliveryAndDispatchPayment, OnDeliveryConfirmed, - OnMessageAccepted, RelayersRewards, SendMessageArtifacts, TargetHeaderChain, + LaneMessageVerifier, MessageDeliveryAndDispatchPayment, RelayersRewards, + SendMessageArtifacts, TargetHeaderChain, }, target_chain::{ DispatchMessage, MessageDispatch, ProvedLaneMessages, ProvedMessages, SourceHeaderChain, @@ -65,7 +65,6 @@ use bp_messages::{ use bp_runtime::{BasicOperatingMode, ChainId, OwnedBridgeModule, Size}; use codec::{Decode, Encode, MaxEncodedLen}; use frame_support::{dispatch::PostDispatchInfo, ensure, fail, traits::Get}; -use num_traits::Zero; use sp_std::{ cell::RefCell, collections::vec_deque::VecDeque, marker::PhantomData, ops::RangeInclusive, prelude::*, @@ -159,10 +158,6 @@ pub mod pallet { Self::RuntimeOrigin, Self::AccountId, >; - /// Handler for accepted messages. - type OnMessageAccepted: OnMessageAccepted; - /// Handler for delivered messages. - type OnDeliveryConfirmed: OnDeliveryConfirmed; // Types that are used by inbound_lane (on target chain). @@ -362,33 +357,14 @@ pub mod pallet { #[pallet::weight(T::WeightInfo::receive_messages_delivery_proof_weight( proof, relayers_state, - T::DbWeight::get(), ))] pub fn receive_messages_delivery_proof( origin: OriginFor, proof: MessagesDeliveryProofOf, relayers_state: UnrewardedRelayersState, - ) -> DispatchResultWithPostInfo { + ) -> DispatchResult { Self::ensure_not_halted().map_err(Error::::BridgeModule)?; - // why do we need to know the weight of this (`receive_messages_delivery_proof`) call? - // Because we may want to return some funds for messages that are not processed by the - // delivery callback, or if their actual processing weight is less than accounted by - // weight formula. So to refund relayer, we need to: - // - // ActualWeight = DeclaredWeight - UnspentCallbackWeight - // - // The DeclaredWeight is exactly what's computed here. Unfortunately it is impossible - // to get pre-computed value (and it has been already computed by the executive). - let single_message_callback_overhead = - T::WeightInfo::single_message_callback_overhead(T::DbWeight::get()); - let declared_weight = T::WeightInfo::receive_messages_delivery_proof_weight( - &proof, - &relayers_state, - T::DbWeight::get(), - ); - let mut actual_weight = declared_weight; - let confirmation_relayer = ensure_signed(origin)?; let (lane_id, lane_data) = T::TargetHeaderChain::verify_messages_delivery_proof(proof) .map_err(|err| { @@ -453,39 +429,6 @@ pub mod pallet { }; if let Some(confirmed_messages) = confirmed_messages { - // handle messages delivery confirmation - let preliminary_callback_overhead = - single_message_callback_overhead.saturating_mul(relayers_state.total_messages); - let actual_callback_weight = - T::OnDeliveryConfirmed::on_messages_delivered(&lane_id, &confirmed_messages); - match preliminary_callback_overhead.checked_sub(&actual_callback_weight) { - Some(difference) if difference.is_zero() => (), - Some(difference) => { - log::trace!( - target: LOG_TARGET, - "T::OnDeliveryConfirmed callback has spent less weight than expected. Refunding: \ - {} - {} = {}", - preliminary_callback_overhead, - actual_callback_weight, - difference, - ); - actual_weight = actual_weight.saturating_sub(difference); - }, - None => { - debug_assert!( - false, - "T::OnDeliveryConfirmed callback consumed too much weight." - ); - log::error!( - target: LOG_TARGET, - "T::OnDeliveryConfirmed callback has spent more weight that it is allowed to: \ - {} vs {}", - preliminary_callback_overhead, - actual_callback_weight, - ); - }, - } - // emit 'delivered' event let received_range = confirmed_messages.begin..=confirmed_messages.end; Self::deposit_event(Event::MessagesDelivered { @@ -509,7 +452,7 @@ pub mod pallet { lane_id, ); - Ok(PostDispatchInfo { actual_weight: Some(actual_weight), pays_fee: Pays::Yes }) + Ok(()) } } @@ -710,38 +653,6 @@ fn send_message, I: 'static>( ); let nonce = lane.send_message(encoded_payload); - // Guaranteed to be called outside only when the message is accepted. - // We assume that the maximum weight call back used is `single_message_callback_overhead`, so do - // not perform complex db operation in callback. If you want to, put these magic logic in - // outside pallet and control the weight there. - let single_message_callback_overhead = - T::WeightInfo::single_message_callback_overhead(T::DbWeight::get()); - let actual_callback_weight = T::OnMessageAccepted::on_messages_accepted(&lane_id, &nonce); - match single_message_callback_overhead.checked_sub(&actual_callback_weight) { - Some(difference) if difference.is_zero() => (), - Some(difference) => { - log::trace!( - target: LOG_TARGET, - "T::OnMessageAccepted callback has spent less weight than expected. Refunding: \ - {} - {} = {}", - single_message_callback_overhead, - actual_callback_weight, - difference, - ); - actual_weight = actual_weight.saturating_sub(difference); - }, - None => { - debug_assert!(false, "T::OnMessageAccepted callback consumed too much weight."); - log::error!( - target: LOG_TARGET, - "T::OnMessageAccepted callback has spent more weight that it is allowed to: \ - {} vs {}", - single_message_callback_overhead, - actual_callback_weight, - ); - }, - } - // message sender pays for pruning at most `MaxMessagesToPruneAtOnce` messages // the cost of pruning every message is roughly single db write // => lets refund sender if less than `MaxMessagesToPruneAtOnce` messages pruned @@ -942,8 +853,7 @@ mod tests { use crate::mock::{ message, message_payload, run_test, unrewarded_relayer, RuntimeEvent as TestEvent, RuntimeOrigin, TestMessageDeliveryAndDispatchPayment, TestMessagesDeliveryProof, - TestMessagesProof, TestOnDeliveryConfirmed1, TestOnDeliveryConfirmed2, - TestOnMessageAccepted, TestRuntime, MAX_OUTBOUND_PAYLOAD_SIZE, + TestMessagesProof, TestRuntime, MAX_OUTBOUND_PAYLOAD_SIZE, PAYLOAD_REJECTED_BY_TARGET_CHAIN, REGULAR_PAYLOAD, TEST_LANE_ID, TEST_RELAYER_A, TEST_RELAYER_B, }; @@ -1674,12 +1584,9 @@ mod tests { TEST_LANE_ID, InboundLaneData { last_confirmed_nonce: 0, - relayers: vec![UnrewardedRelayer { - relayer: 0, - messages: delivered_message_3.clone(), - }] - .into_iter() - .collect(), + relayers: vec![UnrewardedRelayer { relayer: 0, messages: delivered_message_3 }] + .into_iter() + .collect(), }, )); @@ -1705,82 +1612,6 @@ mod tests { ..Default::default() }, )); - - // ensure that both callbacks have been called twice: for 1+2, then for 3 - TestOnDeliveryConfirmed1::ensure_called(&TEST_LANE_ID, &delivered_messages_1_and_2); - TestOnDeliveryConfirmed1::ensure_called(&TEST_LANE_ID, &delivered_message_3); - TestOnDeliveryConfirmed2::ensure_called(&TEST_LANE_ID, &delivered_messages_1_and_2); - TestOnDeliveryConfirmed2::ensure_called(&TEST_LANE_ID, &delivered_message_3); - }); - } - - fn confirm_3_messages_delivery() -> (Weight, Weight) { - send_regular_message(); - send_regular_message(); - send_regular_message(); - - let proof = TestMessagesDeliveryProof(Ok(( - TEST_LANE_ID, - InboundLaneData { - last_confirmed_nonce: 0, - relayers: vec![unrewarded_relayer(1, 3, TEST_RELAYER_A)].into_iter().collect(), - }, - ))); - let relayers_state = UnrewardedRelayersState { - unrewarded_relayer_entries: 1, - total_messages: 3, - last_delivered_nonce: 3, - ..Default::default() - }; - let pre_dispatch_weight = - ::WeightInfo::receive_messages_delivery_proof_weight( - &proof, - &relayers_state, - crate::mock::DbWeight::get(), - ); - let post_dispatch_weight = Pallet::::receive_messages_delivery_proof( - RuntimeOrigin::signed(1), - proof, - relayers_state, - ) - .expect("confirmation has failed") - .actual_weight - .expect("receive_messages_delivery_proof always returns Some"); - (pre_dispatch_weight, post_dispatch_weight) - } - - #[test] - fn receive_messages_delivery_proof_refunds_zero_weight() { - run_test(|| { - let (pre_dispatch_weight, post_dispatch_weight) = confirm_3_messages_delivery(); - assert_eq!(pre_dispatch_weight, post_dispatch_weight); - }); - } - - #[test] - fn receive_messages_delivery_proof_refunds_non_zero_weight() { - run_test(|| { - TestOnDeliveryConfirmed1::set_consumed_weight_per_message( - crate::mock::DbWeight::get().writes(1), - ); - - let (pre_dispatch_weight, post_dispatch_weight) = confirm_3_messages_delivery(); - assert_eq!( - pre_dispatch_weight.saturating_sub(post_dispatch_weight), - crate::mock::DbWeight::get().reads(1) * 3 - ); - }); - } - - #[test] - #[should_panic] - #[cfg(debug_assertions)] - fn receive_messages_panics_in_debug_mode_if_callback_is_wrong() { - run_test(|| { - TestOnDeliveryConfirmed1::set_consumed_weight_per_message( - crate::mock::DbWeight::get().reads_writes(2, 2), - ); - confirm_3_messages_delivery() }); } @@ -1811,26 +1642,6 @@ mod tests { }); } - #[test] - fn message_accepted_callbacks_are_called() { - run_test(|| { - send_regular_message(); - TestOnMessageAccepted::ensure_called(&TEST_LANE_ID, &1); - }); - } - - #[test] - #[should_panic] - #[cfg(debug_assertions)] - fn message_accepted_panics_in_debug_mode_if_callback_is_wrong() { - run_test(|| { - TestOnMessageAccepted::set_consumed_weight_per_message( - crate::mock::DbWeight::get().reads_writes(2, 2), - ); - send_regular_message(); - }); - } - #[test] fn storage_keys_computed_properly() { assert_eq!( diff --git a/bridges/modules/messages/src/mock.rs b/bridges/modules/messages/src/mock.rs index afda37ba8be7b..5d58883d0a6f9 100644 --- a/bridges/modules/messages/src/mock.rs +++ b/bridges/modules/messages/src/mock.rs @@ -21,10 +21,7 @@ use crate::{calc_relayers_rewards, Config}; use bitvec::prelude::*; use bp_messages::{ - source_chain::{ - LaneMessageVerifier, MessageDeliveryAndDispatchPayment, OnDeliveryConfirmed, - OnMessageAccepted, TargetHeaderChain, - }, + source_chain::{LaneMessageVerifier, MessageDeliveryAndDispatchPayment, TargetHeaderChain}, target_chain::{ DispatchMessage, DispatchMessageData, MessageDispatch, ProvedLaneMessages, ProvedMessages, SourceHeaderChain, @@ -162,8 +159,6 @@ impl Config for TestRuntime { type TargetHeaderChain = TestTargetHeaderChain; type LaneMessageVerifier = TestLaneMessageVerifier; type MessageDeliveryAndDispatchPayment = TestMessageDeliveryAndDispatchPayment; - type OnMessageAccepted = TestOnMessageAccepted; - type OnDeliveryConfirmed = (TestOnDeliveryConfirmed1, TestOnDeliveryConfirmed2); type SourceHeaderChain = TestSourceHeaderChain; type MessageDispatch = TestMessageDispatch; @@ -321,88 +316,6 @@ impl MessageDeliveryAndDispatchPayment } } -#[derive(Debug)] -pub struct TestOnMessageAccepted; - -impl TestOnMessageAccepted { - /// Verify that the callback has been called when the message is accepted. - pub fn ensure_called(lane: &LaneId, message: &MessageNonce) { - let key = (b"TestOnMessageAccepted", lane, message).encode(); - assert_eq!(frame_support::storage::unhashed::get(&key), Some(true)); - } - - /// Set consumed weight returned by the callback. - pub fn set_consumed_weight_per_message(weight: Weight) { - frame_support::storage::unhashed::put(b"TestOnMessageAccepted_Weight", &weight); - } - - /// Get consumed weight returned by the callback. - pub fn get_consumed_weight_per_message() -> Option { - frame_support::storage::unhashed::get(b"TestOnMessageAccepted_Weight") - } -} - -impl OnMessageAccepted for TestOnMessageAccepted { - fn on_messages_accepted(lane: &LaneId, message: &MessageNonce) -> Weight { - let key = (b"TestOnMessageAccepted", lane, message).encode(); - frame_support::storage::unhashed::put(&key, &true); - Self::get_consumed_weight_per_message() - .unwrap_or_else(|| DbWeight::get().reads_writes(1, 1)) - } -} - -/// First on-messages-delivered callback. -#[derive(Debug)] -pub struct TestOnDeliveryConfirmed1; - -impl TestOnDeliveryConfirmed1 { - /// Verify that the callback has been called with given delivered messages. - pub fn ensure_called(lane: &LaneId, messages: &DeliveredMessages) { - let key = (b"TestOnDeliveryConfirmed1", lane, messages).encode(); - assert_eq!(frame_support::storage::unhashed::get(&key), Some(true)); - } - - /// Set consumed weight returned by the callback. - pub fn set_consumed_weight_per_message(weight: Weight) { - frame_support::storage::unhashed::put(b"TestOnDeliveryConfirmed1_Weight", &weight); - } - - /// Get consumed weight returned by the callback. - pub fn get_consumed_weight_per_message() -> Option { - frame_support::storage::unhashed::get(b"TestOnDeliveryConfirmed1_Weight") - } -} - -impl OnDeliveryConfirmed for TestOnDeliveryConfirmed1 { - fn on_messages_delivered(lane: &LaneId, messages: &DeliveredMessages) -> Weight { - let key = (b"TestOnDeliveryConfirmed1", lane, messages).encode(); - frame_support::storage::unhashed::put(&key, &true); - Self::get_consumed_weight_per_message() - .unwrap_or_else(|| DbWeight::get().reads_writes(1, 1)) - .saturating_mul(messages.total_messages()) - } -} - -/// Second on-messages-delivered callback. -#[derive(Debug)] -pub struct TestOnDeliveryConfirmed2; - -impl TestOnDeliveryConfirmed2 { - /// Verify that the callback has been called with given delivered messages. - pub fn ensure_called(lane: &LaneId, messages: &DeliveredMessages) { - let key = (b"TestOnDeliveryConfirmed2", lane, messages).encode(); - assert_eq!(frame_support::storage::unhashed::get(&key), Some(true)); - } -} - -impl OnDeliveryConfirmed for TestOnDeliveryConfirmed2 { - fn on_messages_delivered(lane: &LaneId, messages: &DeliveredMessages) -> Weight { - let key = (b"TestOnDeliveryConfirmed2", lane, messages).encode(); - frame_support::storage::unhashed::put(&key, &true); - Weight::from_ref_time(0) - } -} - /// Source header chain that is used in tests. #[derive(Debug)] pub struct TestSourceHeaderChain; diff --git a/bridges/modules/messages/src/weights_ext.rs b/bridges/modules/messages/src/weights_ext.rs index 5ad86c817dcee..1604832c0790a 100644 --- a/bridges/modules/messages/src/weights_ext.rs +++ b/bridges/modules/messages/src/weights_ext.rs @@ -20,7 +20,7 @@ use crate::weights::WeightInfo; use bp_messages::{MessageNonce, UnrewardedRelayersState}; use bp_runtime::{PreComputedSize, Size}; -use frame_support::weights::{RuntimeDbWeight, Weight}; +use frame_support::weights::Weight; /// Size of the message being delivered in benchmarks. pub const EXPECTED_DEFAULT_MESSAGE_LENGTH: u32 = 128; @@ -88,7 +88,6 @@ pub fn ensure_able_to_receive_confirmation( max_inbound_lane_data_proof_size_from_peer_chain: u32, max_unrewarded_relayer_entries_at_peer_inbound_lane: MessageNonce, max_unconfirmed_messages_at_inbound_lane: MessageNonce, - db_weight: RuntimeDbWeight, ) { // verify that we're able to receive confirmation of maximal-size let max_confirmation_transaction_size = @@ -110,7 +109,6 @@ pub fn ensure_able_to_receive_confirmation( total_messages: max_unconfirmed_messages_at_inbound_lane, ..Default::default() }, - db_weight, ); assert!( max_confirmation_transaction_dispatch_weight.all_lte(max_extrinsic_weight), @@ -166,7 +164,6 @@ pub trait WeightInfoExt: WeightInfo { fn receive_messages_delivery_proof_weight( proof: &impl Size, relayers_state: &UnrewardedRelayersState, - db_weight: RuntimeDbWeight, ) -> Weight { // basic components of extrinsic weight let transaction_overhead = Self::receive_messages_delivery_proof_overhead(); @@ -183,16 +180,10 @@ pub trait WeightInfoExt: WeightInfo { actual_proof_size.saturating_sub(expected_proof_size), ); - // and cost of calling `OnDeliveryConfirmed::on_messages_delivered()` for every confirmed - // message - let callback_overhead = Self::single_message_callback_overhead(db_weight) - .saturating_mul(relayers_state.total_messages); - transaction_overhead .saturating_add(messages_overhead) .saturating_add(relayers_overhead) .saturating_add(proof_size_overhead) - .saturating_add(callback_overhead) } // Functions that are used by extrinsics weights formulas. @@ -283,15 +274,6 @@ pub trait WeightInfoExt: WeightInfo { Self::receive_single_message_proof() .saturating_sub(Self::receive_single_prepaid_message_proof()) } - - /// Returns pre-dispatch weight of single callback call. - /// - /// When benchmarking the weight please take into consideration both the `OnMessageAccepted` and - /// `OnDeliveryConfirmed` callbacks. The method should return the greater of the two, because - /// it's used to estimate the weight in both contexts. - fn single_message_callback_overhead(db_weight: RuntimeDbWeight) -> Weight { - db_weight.reads_writes(1, 1) - } } impl WeightInfoExt for () { diff --git a/bridges/modules/relayers/src/mock.rs b/bridges/modules/relayers/src/mock.rs index f2ae936ae8c9b..acb709407dca1 100644 --- a/bridges/modules/relayers/src/mock.rs +++ b/bridges/modules/relayers/src/mock.rs @@ -110,8 +110,6 @@ impl pallet_bridge_messages::Config for TestRuntime { type TargetHeaderChain = ForbidOutboundMessages; type LaneMessageVerifier = ForbidOutboundMessages; type MessageDeliveryAndDispatchPayment = (); - type OnMessageAccepted = (); - type OnDeliveryConfirmed = (); type SourceHeaderChain = ForbidInboundMessages; type MessageDispatch = ForbidInboundMessages; diff --git a/bridges/primitives/messages/src/source_chain.rs b/bridges/primitives/messages/src/source_chain.rs index 6a22ececf8efc..1cac449ee63ea 100644 --- a/bridges/primitives/messages/src/source_chain.rs +++ b/bridges/primitives/messages/src/source_chain.rs @@ -16,7 +16,7 @@ //! Primitives of messages module, that are used on the source chain. -use crate::{DeliveredMessages, InboundLaneData, LaneId, MessageNonce, OutboundLaneData}; +use crate::{InboundLaneData, LaneId, MessageNonce, OutboundLaneData}; use crate::UnrewardedRelayer; use bp_runtime::Size; @@ -165,49 +165,6 @@ impl MessagesBridge for NoopMessag } } -/// Handler for messages delivery confirmation. -pub trait OnDeliveryConfirmed { - /// Called when we receive confirmation that our messages have been delivered to the - /// target chain. The confirmation also has single bit dispatch result for every - /// confirmed message (see `DeliveredMessages` for details). Guaranteed to be called - /// only when at least one message is delivered. - /// - /// Should return total weight consumed by the call. - /// - /// NOTE: messages pallet assumes that maximal weight that may be spent on processing - /// single message is single DB read + single DB write. So this function shall never - /// return weight that is larger than total number of messages * (db read + db write). - /// If your pallet needs more time for processing single message, please do it - /// from `on_initialize` call(s) of the next block(s). - fn on_messages_delivered(_lane: &LaneId, _messages: &DeliveredMessages) -> Weight; -} - -#[allow(clippy::let_and_return)] -#[impl_trait_for_tuples::impl_for_tuples(30)] -impl OnDeliveryConfirmed for Tuple { - fn on_messages_delivered(lane: &LaneId, messages: &DeliveredMessages) -> Weight { - let mut total_weight = Weight::zero(); - for_tuples!( - #( - total_weight = total_weight.saturating_add(Tuple::on_messages_delivered(lane, messages)); - )* - ); - total_weight - } -} - -/// Handler for messages have been accepted -pub trait OnMessageAccepted { - /// Called when a message has been accepted by message pallet. - fn on_messages_accepted(lane: &LaneId, message: &MessageNonce) -> Weight; -} - -impl OnMessageAccepted for () { - fn on_messages_accepted(_lane: &LaneId, _message: &MessageNonce) -> Weight { - Weight::zero() - } -} - /// Structure that may be used in place of `TargetHeaderChain`, `LaneMessageVerifier` and /// `MessageDeliveryAndDispatchPayment` on chains, where outbound messages are forbidden. pub struct ForbidOutboundMessages;