Message lane weight formulas (#596)

* weight formulas for message-lane calls

* extracted WeightInfoExt into separate file
This commit is contained in:
Svyatoslav Nikolsky
2020-12-24 11:29:33 +03:00
committed by Bastian Köcher
parent a6c3de51d3
commit 8e8e89511f
3 changed files with 129 additions and 14 deletions
+29 -14
View File
@@ -26,9 +26,17 @@
//! Once message is sent, its progress can be tracked by looking at module events.
//! The assigned nonce is reported using `MessageAccepted` event. When message is
//! delivered to the the bridged chain, it is reported using `MessagesDelivered` event.
//!
//! **IMPORTANT NOTE**: after generating weights (custom `WeighInfo` implementation) for
//! your runtime (where this module is plugged to), please add test for these weights.
//! The test should call the `ensure_weights_are_correct` function from this module.
//! If this test fails with your weights, then either weights are computed incorrectly,
//! or some benchmarks assumptions are broken for your runtime.
#![cfg_attr(not(feature = "std"), no_std)]
pub use crate::weights_ext::{ensure_weights_are_correct, WeightInfoExt};
use crate::inbound_lane::{InboundLane, InboundLaneStorage};
use crate::outbound_lane::{OutboundLane, OutboundLaneStorage};
use crate::weights::WeightInfo;
@@ -53,6 +61,7 @@ use sp_std::{cell::RefCell, marker::PhantomData, prelude::*};
mod inbound_lane;
mod outbound_lane;
mod weights_ext;
pub mod instant_payments;
pub mod weights;
@@ -63,14 +72,6 @@ pub mod benchmarking;
#[cfg(test)]
mod mock;
// TODO: update me (https://github.com/paritytech/parity-bridges-common/issues/78)
/// Weight of message delivery without any code that is touching messages.
const DELIVERY_OVERHEAD_WEIGHT: Weight = 0;
// TODO: update me (https://github.com/paritytech/parity-bridges-common/issues/78)
/// Single-message delivery weight. This shall not include message dispatch weight and
/// any delivery transaction code that is not specific to this message.
const SINGLE_MESSAGE_DELIVERY_WEIGHT: Weight = 0;
/// The module configuration trait
pub trait Config<I = DefaultInstance>: frame_system::Config {
// General types
@@ -78,7 +79,7 @@ pub trait Config<I = DefaultInstance>: frame_system::Config {
/// They overarching event type.
type Event: From<Event<Self, I>> + Into<<Self as frame_system::Config>::Event>;
/// Benchmarks results from runtime we're plugged into.
type WeightInfo: WeightInfo;
type WeightInfo: WeightInfoExt;
/// Maximal number of messages that may be pruned during maintenance. Maintenance occurs
/// whenever new message is sent. The reason is that if you want to use lane, you should
/// be ready to pay for its maintenance.
@@ -252,7 +253,10 @@ decl_module! {
}
/// Send message over lane.
#[weight = 0] // TODO: update me (https://github.com/paritytech/parity-bridges-common/issues/78)
///
/// The weight of the call assumes that the largest possible message is sent in
/// worst possible environment.
#[weight = T::WeightInfo::send_message_worst_case()]
pub fn send_message(
origin,
lane_id: LaneId,
@@ -327,9 +331,13 @@ decl_module! {
}
/// Receive messages proof from bridged chain.
#[weight = messages_count
.saturating_mul(SINGLE_MESSAGE_DELIVERY_WEIGHT)
.saturating_add(DELIVERY_OVERHEAD_WEIGHT)
///
/// The weight of the call assumes that the transaction always brings outbound lane
/// state update. Because of that, the submitter (relayer) has no benefit of not including
/// this data in the transaction, so reward confirmations lags should be minimal.
#[weight = T::WeightInfo::receive_messages_proof_overhead()
.saturating_add(T::WeightInfo::receive_messages_proof_outbound_lane_state_overhead())
.saturating_add(T::WeightInfo::receive_messages_proof_messages_overhead(*messages_count))
.saturating_add(*dispatch_weight)
]
pub fn receive_messages_proof(
@@ -414,7 +422,14 @@ decl_module! {
}
/// Receive messages delivery proof from bridged chain.
#[weight = 0] // TODO: update me (https://github.com/paritytech/parity-bridges-common/issues/78)
#[weight = T::WeightInfo::receive_messages_delivery_proof_overhead()
.saturating_add(T::WeightInfo::receive_messages_delivery_proof_messages_overhead(
relayers_state.total_messages
))
.saturating_add(T::WeightInfo::receive_messages_delivery_proof_relayers_overhead(
relayers_state.unrewarded_relayer_entries
))
]
pub fn receive_messages_delivery_proof(
origin,
proof: MessagesDeliveryProofOf<T, I>,