mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-30 23:21:02 +00:00
send_message weight now depends on message size (#603)
* `send_message` weight now depends on message size * fix tests * Update modules/message-lane/src/benchmarking.rs Co-authored-by: Hernando Castano <HCastano@users.noreply.github.com> * Update modules/message-lane/src/benchmarking.rs Co-authored-by: Hernando Castano <HCastano@users.noreply.github.com> Co-authored-by: Hernando Castano <HCastano@users.noreply.github.com>
This commit is contained in:
committed by
Bastian Köcher
parent
de3037853b
commit
820407ee98
@@ -813,6 +813,8 @@ impl_runtime_apis! {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
use crate::millau_messages::{ToMillauMessagePayload, WithMillauMessageBridge};
|
||||||
|
use bridge_runtime_common::messages;
|
||||||
use pallet_message_lane::benchmarking::{
|
use pallet_message_lane::benchmarking::{
|
||||||
Module as MessageLaneBench,
|
Module as MessageLaneBench,
|
||||||
Config as MessageLaneConfig,
|
Config as MessageLaneConfig,
|
||||||
@@ -822,6 +824,10 @@ impl_runtime_apis! {
|
|||||||
};
|
};
|
||||||
|
|
||||||
impl MessageLaneConfig<WithMillauMessageLaneInstance> for Runtime {
|
impl MessageLaneConfig<WithMillauMessageLaneInstance> for Runtime {
|
||||||
|
fn maximal_message_size() -> u32 {
|
||||||
|
messages::source::maximal_message_size::<WithMillauMessageBridge>()
|
||||||
|
}
|
||||||
|
|
||||||
fn bridged_relayer_id() -> Self::InboundRelayer {
|
fn bridged_relayer_id() -> Self::InboundRelayer {
|
||||||
Default::default()
|
Default::default()
|
||||||
}
|
}
|
||||||
@@ -840,24 +846,14 @@ impl_runtime_apis! {
|
|||||||
fn prepare_outbound_message(
|
fn prepare_outbound_message(
|
||||||
params: MessageLaneMessageParams<Self::AccountId>,
|
params: MessageLaneMessageParams<Self::AccountId>,
|
||||||
) -> (millau_messages::ToMillauMessagePayload, Balance) {
|
) -> (millau_messages::ToMillauMessagePayload, Balance) {
|
||||||
use crate::millau_messages::{ToMillauMessagePayload, WithMillauMessageBridge};
|
let message_payload = vec![0; params.size as usize];
|
||||||
use bridge_runtime_common::messages;
|
|
||||||
use pallet_message_lane::benchmarking::WORST_MESSAGE_SIZE_FACTOR;
|
|
||||||
|
|
||||||
let max_message_size = messages::source::maximal_message_size::<WithMillauMessageBridge>();
|
|
||||||
let message_size = match params.size_factor {
|
|
||||||
0 => 1,
|
|
||||||
factor => max_message_size / WORST_MESSAGE_SIZE_FACTOR
|
|
||||||
* sp_std::cmp::min(factor, WORST_MESSAGE_SIZE_FACTOR),
|
|
||||||
};
|
|
||||||
let message_payload = vec![0; message_size as usize];
|
|
||||||
let dispatch_origin = pallet_bridge_call_dispatch::CallOrigin::SourceAccount(
|
let dispatch_origin = pallet_bridge_call_dispatch::CallOrigin::SourceAccount(
|
||||||
params.sender_account,
|
params.sender_account,
|
||||||
);
|
);
|
||||||
|
|
||||||
let message = ToMillauMessagePayload {
|
let message = ToMillauMessagePayload {
|
||||||
spec_version: 0,
|
spec_version: 0,
|
||||||
weight: message_size as _,
|
weight: params.size as _,
|
||||||
origin: dispatch_origin,
|
origin: dispatch_origin,
|
||||||
call: message_payload,
|
call: message_payload,
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -25,7 +25,7 @@
|
|||||||
#![warn(missing_docs)]
|
#![warn(missing_docs)]
|
||||||
|
|
||||||
use bp_message_dispatch::{MessageDispatch, Weight};
|
use bp_message_dispatch::{MessageDispatch, Weight};
|
||||||
use bp_runtime::{derive_account_id, InstanceId, SourceAccount};
|
use bp_runtime::{derive_account_id, InstanceId, Size, SourceAccount};
|
||||||
use codec::{Decode, Encode};
|
use codec::{Decode, Encode};
|
||||||
use frame_support::{
|
use frame_support::{
|
||||||
decl_event, decl_module, decl_storage,
|
decl_event, decl_module, decl_storage,
|
||||||
@@ -104,6 +104,14 @@ pub struct MessagePayload<SourceChainAccountId, TargetChainAccountPublic, Target
|
|||||||
pub call: Call,
|
pub call: Call,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl<SourceChainAccountId, TargetChainAccountPublic, TargetChainSignature> Size
|
||||||
|
for MessagePayload<SourceChainAccountId, TargetChainAccountPublic, TargetChainSignature, Vec<u8>>
|
||||||
|
{
|
||||||
|
fn size_hint(&self) -> u32 {
|
||||||
|
self.call.len() as _
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// The module configuration trait.
|
/// The module configuration trait.
|
||||||
pub trait Config<I = DefaultInstance>: frame_system::Config {
|
pub trait Config<I = DefaultInstance>: frame_system::Config {
|
||||||
/// The overarching event type.
|
/// The overarching event type.
|
||||||
|
|||||||
@@ -27,8 +27,6 @@ use frame_support::{traits::Get, weights::Weight};
|
|||||||
use frame_system::RawOrigin;
|
use frame_system::RawOrigin;
|
||||||
use sp_std::{collections::btree_map::BTreeMap, convert::TryInto, ops::RangeInclusive, prelude::*};
|
use sp_std::{collections::btree_map::BTreeMap, convert::TryInto, ops::RangeInclusive, prelude::*};
|
||||||
|
|
||||||
/// Message crafted with this size factor should be the largest possible message.
|
|
||||||
pub const WORST_MESSAGE_SIZE_FACTOR: u32 = 1000;
|
|
||||||
/// Fee paid by submitter for single message delivery.
|
/// Fee paid by submitter for single message delivery.
|
||||||
const MESSAGE_FEE: u32 = 1_000_000;
|
const MESSAGE_FEE: u32 = 1_000_000;
|
||||||
|
|
||||||
@@ -39,10 +37,8 @@ pub struct Module<T: Config<I>, I: crate::Instance>(crate::Module<T, I>);
|
|||||||
|
|
||||||
/// Benchmark-specific message parameters.
|
/// Benchmark-specific message parameters.
|
||||||
pub struct MessageParams<ThisAccountId> {
|
pub struct MessageParams<ThisAccountId> {
|
||||||
/// Size factor of the message payload. Message payload grows with every factor
|
/// Size of the message payload.
|
||||||
/// increment. Zero is the smallest possible message and the `WORST_MESSAGE_SIZE_FACTOR` is
|
pub size: u32,
|
||||||
/// largest possible message.
|
|
||||||
pub size_factor: u32,
|
|
||||||
/// Message sender account.
|
/// Message sender account.
|
||||||
pub sender_account: ThisAccountId,
|
pub sender_account: ThisAccountId,
|
||||||
}
|
}
|
||||||
@@ -67,6 +63,8 @@ pub struct MessageDeliveryProofParams<ThisChainAccountId> {
|
|||||||
|
|
||||||
/// Trait that must be implemented by runtime.
|
/// Trait that must be implemented by runtime.
|
||||||
pub trait Config<I: Instance>: crate::Config<I> {
|
pub trait Config<I: Instance>: crate::Config<I> {
|
||||||
|
/// Get maximal size of the message payload.
|
||||||
|
fn maximal_message_size() -> u32;
|
||||||
/// Return id of relayer account at the bridged chain.
|
/// Return id of relayer account at the bridged chain.
|
||||||
fn bridged_relayer_id() -> Self::InboundRelayer;
|
fn bridged_relayer_id() -> Self::InboundRelayer;
|
||||||
/// Return balance of given account.
|
/// Return balance of given account.
|
||||||
@@ -101,10 +99,12 @@ benchmarks_instance! {
|
|||||||
// * outbound lane already has state, so it needs to be read and decoded;
|
// * outbound lane already has state, so it needs to be read and decoded;
|
||||||
// * relayers fund account does not exists (in practice it needs to exist in production environment);
|
// * relayers fund account does not exists (in practice it needs to exist in production environment);
|
||||||
// * maximal number of messages is being pruned during the call;
|
// * maximal number of messages is being pruned during the call;
|
||||||
// * message size is maximal for the target chain.
|
// * message size is minimal for the target chain.
|
||||||
//
|
//
|
||||||
// Results of this benchmark may be directly used in the `send_message`.
|
// Result of this benchmark is used as a base weight for `send_message` call. Then the 'message weight'
|
||||||
send_message_worst_case {
|
// (estimated using `send_half_maximal_message_worst_case` and `send_maximal_message_worst_case`) is
|
||||||
|
// added.
|
||||||
|
send_minimal_message_worst_case {
|
||||||
let lane_id = bench_lane_id();
|
let lane_id = bench_lane_id();
|
||||||
let sender = account("sender", 0, SEED);
|
let sender = account("sender", 0, SEED);
|
||||||
T::endow_account(&sender);
|
T::endow_account(&sender);
|
||||||
@@ -116,7 +116,81 @@ benchmarks_instance! {
|
|||||||
confirm_message_delivery::<T, I>(T::MaxMessagesToPruneAtOnce::get());
|
confirm_message_delivery::<T, I>(T::MaxMessagesToPruneAtOnce::get());
|
||||||
|
|
||||||
let (payload, fee) = T::prepare_outbound_message(MessageParams {
|
let (payload, fee) = T::prepare_outbound_message(MessageParams {
|
||||||
size_factor: WORST_MESSAGE_SIZE_FACTOR,
|
size: 0,
|
||||||
|
sender_account: sender.clone(),
|
||||||
|
});
|
||||||
|
}: send_message(RawOrigin::Signed(sender), lane_id, payload, fee)
|
||||||
|
verify {
|
||||||
|
assert_eq!(
|
||||||
|
crate::Module::<T, I>::outbound_latest_generated_nonce(bench_lane_id()),
|
||||||
|
T::MaxMessagesToPruneAtOnce::get() + 1,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Benchmark `send_message` extrinsic with the worst possible conditions:
|
||||||
|
// * outbound lane already has state, so it needs to be read and decoded;
|
||||||
|
// * relayers fund account does not exists (in practice it needs to exist in production environment);
|
||||||
|
// * maximal number of messages is being pruned during the call;
|
||||||
|
// * message size is 1KB.
|
||||||
|
//
|
||||||
|
// With single KB of message size, the weight of the call is increased (roughly) by
|
||||||
|
// `(send_16_kb_message_worst_case - send_1_kb_message_worst_case) / 15`.
|
||||||
|
send_1_kb_message_worst_case {
|
||||||
|
let lane_id = bench_lane_id();
|
||||||
|
let sender = account("sender", 0, SEED);
|
||||||
|
T::endow_account(&sender);
|
||||||
|
|
||||||
|
// 'send' messages that are to be pruned when our message is sent
|
||||||
|
for _nonce in 1..=T::MaxMessagesToPruneAtOnce::get() {
|
||||||
|
send_regular_message::<T, I>();
|
||||||
|
}
|
||||||
|
confirm_message_delivery::<T, I>(T::MaxMessagesToPruneAtOnce::get());
|
||||||
|
|
||||||
|
let size = 1024;
|
||||||
|
assert!(
|
||||||
|
T::maximal_message_size() > size,
|
||||||
|
"This benchmark can only be used with runtime that accepts 1KB messages",
|
||||||
|
);
|
||||||
|
|
||||||
|
let (payload, fee) = T::prepare_outbound_message(MessageParams {
|
||||||
|
size,
|
||||||
|
sender_account: sender.clone(),
|
||||||
|
});
|
||||||
|
}: send_message(RawOrigin::Signed(sender), lane_id, payload, fee)
|
||||||
|
verify {
|
||||||
|
assert_eq!(
|
||||||
|
crate::Module::<T, I>::outbound_latest_generated_nonce(bench_lane_id()),
|
||||||
|
T::MaxMessagesToPruneAtOnce::get() + 1,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Benchmark `send_message` extrinsic with the worst possible conditions:
|
||||||
|
// * outbound lane already has state, so it needs to be read and decoded;
|
||||||
|
// * relayers fund account does not exists (in practice it needs to exist in production environment);
|
||||||
|
// * maximal number of messages is being pruned during the call;
|
||||||
|
// * message size is 16KB.
|
||||||
|
//
|
||||||
|
// With single KB of message size, the weight of the call is increased (roughly) by
|
||||||
|
// `(send_16_kb_message_worst_case - send_1_kb_message_worst_case) / 15`.
|
||||||
|
send_16_kb_message_worst_case {
|
||||||
|
let lane_id = bench_lane_id();
|
||||||
|
let sender = account("sender", 0, SEED);
|
||||||
|
T::endow_account(&sender);
|
||||||
|
|
||||||
|
// 'send' messages that are to be pruned when our message is sent
|
||||||
|
for _nonce in 1..=T::MaxMessagesToPruneAtOnce::get() {
|
||||||
|
send_regular_message::<T, I>();
|
||||||
|
}
|
||||||
|
confirm_message_delivery::<T, I>(T::MaxMessagesToPruneAtOnce::get());
|
||||||
|
|
||||||
|
let size = 16 * 1024;
|
||||||
|
assert!(
|
||||||
|
T::maximal_message_size() > size,
|
||||||
|
"This benchmark can only be used with runtime that accepts 16KB messages",
|
||||||
|
);
|
||||||
|
|
||||||
|
let (payload, fee) = T::prepare_outbound_message(MessageParams {
|
||||||
|
size,
|
||||||
sender_account: sender.clone(),
|
sender_account: sender.clone(),
|
||||||
});
|
});
|
||||||
}: send_message(RawOrigin::Signed(sender), lane_id, payload, fee)
|
}: send_message(RawOrigin::Signed(sender), lane_id, payload, fee)
|
||||||
@@ -340,6 +414,38 @@ benchmarks_instance! {
|
|||||||
// Benchmarks for manual checks.
|
// Benchmarks for manual checks.
|
||||||
//
|
//
|
||||||
|
|
||||||
|
// Benchmark `send_message` extrinsic with following conditions:
|
||||||
|
// * outbound lane already has state, so it needs to be read and decoded;
|
||||||
|
// * relayers fund account does not exists (in practice it needs to exist in production environment);
|
||||||
|
// * maximal number of messages is being pruned during the call;
|
||||||
|
// * message size varies from minimal to maximal for the target chain.
|
||||||
|
//
|
||||||
|
// Results of this benchmark may be used to check how message size affects `send_message` performance.
|
||||||
|
send_messages_of_various_lengths {
|
||||||
|
let i in 0..T::maximal_message_size().try_into().unwrap_or_default();
|
||||||
|
|
||||||
|
let lane_id = bench_lane_id();
|
||||||
|
let sender = account("sender", 0, SEED);
|
||||||
|
T::endow_account(&sender);
|
||||||
|
|
||||||
|
// 'send' messages that are to be pruned when our message is sent
|
||||||
|
for _nonce in 1..=T::MaxMessagesToPruneAtOnce::get() {
|
||||||
|
send_regular_message::<T, I>();
|
||||||
|
}
|
||||||
|
confirm_message_delivery::<T, I>(T::MaxMessagesToPruneAtOnce::get());
|
||||||
|
|
||||||
|
let (payload, fee) = T::prepare_outbound_message(MessageParams {
|
||||||
|
size: i as _,
|
||||||
|
sender_account: sender.clone(),
|
||||||
|
});
|
||||||
|
}: send_message(RawOrigin::Signed(sender), lane_id, payload, fee)
|
||||||
|
verify {
|
||||||
|
assert_eq!(
|
||||||
|
crate::Module::<T, I>::outbound_latest_generated_nonce(bench_lane_id()),
|
||||||
|
T::MaxMessagesToPruneAtOnce::get() + 1,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
// Benchmark `receive_messages_proof` extrinsic with multiple minimal-weight messages and following conditions:
|
// Benchmark `receive_messages_proof` extrinsic with multiple minimal-weight messages and following conditions:
|
||||||
// * proof does not include outbound lane state proof;
|
// * proof does not include outbound lane state proof;
|
||||||
// * inbound lane already has state, so it needs to be read and decoded;
|
// * inbound lane already has state, so it needs to be read and decoded;
|
||||||
|
|||||||
@@ -39,7 +39,6 @@ pub use crate::weights_ext::{ensure_weights_are_correct, WeightInfoExt};
|
|||||||
|
|
||||||
use crate::inbound_lane::{InboundLane, InboundLaneStorage};
|
use crate::inbound_lane::{InboundLane, InboundLaneStorage};
|
||||||
use crate::outbound_lane::{OutboundLane, OutboundLaneStorage};
|
use crate::outbound_lane::{OutboundLane, OutboundLaneStorage};
|
||||||
use crate::weights::WeightInfo;
|
|
||||||
|
|
||||||
use bp_message_lane::{
|
use bp_message_lane::{
|
||||||
source_chain::{LaneMessageVerifier, MessageDeliveryAndDispatchPayment, TargetHeaderChain},
|
source_chain::{LaneMessageVerifier, MessageDeliveryAndDispatchPayment, TargetHeaderChain},
|
||||||
@@ -47,6 +46,7 @@ use bp_message_lane::{
|
|||||||
total_unrewarded_messages, InboundLaneData, LaneId, MessageData, MessageKey, MessageNonce, MessagePayload,
|
total_unrewarded_messages, InboundLaneData, LaneId, MessageData, MessageKey, MessageNonce, MessagePayload,
|
||||||
OutboundLaneData, UnrewardedRelayersState,
|
OutboundLaneData, UnrewardedRelayersState,
|
||||||
};
|
};
|
||||||
|
use bp_runtime::Size;
|
||||||
use codec::{Decode, Encode};
|
use codec::{Decode, Encode};
|
||||||
use frame_support::{
|
use frame_support::{
|
||||||
decl_error, decl_event, decl_module, decl_storage, ensure,
|
decl_error, decl_event, decl_module, decl_storage, ensure,
|
||||||
@@ -104,7 +104,7 @@ pub trait Config<I = DefaultInstance>: frame_system::Config {
|
|||||||
type MaxUnconfirmedMessagesAtInboundLane: Get<MessageNonce>;
|
type MaxUnconfirmedMessagesAtInboundLane: Get<MessageNonce>;
|
||||||
|
|
||||||
/// Payload type of outbound messages. This payload is dispatched on the bridged chain.
|
/// Payload type of outbound messages. This payload is dispatched on the bridged chain.
|
||||||
type OutboundPayload: Parameter;
|
type OutboundPayload: Parameter + Size;
|
||||||
/// Message fee type of outbound messages. This fee is paid on this chain.
|
/// Message fee type of outbound messages. This fee is paid on this chain.
|
||||||
type OutboundMessageFee: From<u32> + Parameter + SaturatingAdd + Zero;
|
type OutboundMessageFee: From<u32> + Parameter + SaturatingAdd + Zero;
|
||||||
|
|
||||||
@@ -261,10 +261,9 @@ decl_module! {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Send message over lane.
|
/// Send message over lane.
|
||||||
///
|
#[weight = T::WeightInfo::send_message_overhead()
|
||||||
/// The weight of the call assumes that the largest possible message is sent in
|
.saturating_add(T::WeightInfo::send_message_size_overhead(Size::size_hint(payload)))
|
||||||
/// worst possible environment.
|
]
|
||||||
#[weight = T::WeightInfo::send_message_worst_case()]
|
|
||||||
pub fn send_message(
|
pub fn send_message(
|
||||||
origin,
|
origin,
|
||||||
lane_id: LaneId,
|
lane_id: LaneId,
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ use bp_message_lane::{
|
|||||||
target_chain::{DispatchMessage, MessageDispatch, ProvedLaneMessages, ProvedMessages, SourceHeaderChain},
|
target_chain::{DispatchMessage, MessageDispatch, ProvedLaneMessages, ProvedMessages, SourceHeaderChain},
|
||||||
InboundLaneData, LaneId, Message, MessageData, MessageKey, MessageNonce,
|
InboundLaneData, LaneId, Message, MessageData, MessageKey, MessageNonce,
|
||||||
};
|
};
|
||||||
|
use bp_runtime::Size;
|
||||||
use codec::{Decode, Encode};
|
use codec::{Decode, Encode};
|
||||||
use frame_support::{impl_outer_event, impl_outer_origin, parameter_types, weights::Weight};
|
use frame_support::{impl_outer_event, impl_outer_origin, parameter_types, weights::Weight};
|
||||||
use sp_core::H256;
|
use sp_core::H256;
|
||||||
@@ -32,7 +33,8 @@ use sp_runtime::{
|
|||||||
use std::collections::BTreeMap;
|
use std::collections::BTreeMap;
|
||||||
|
|
||||||
pub type AccountId = u64;
|
pub type AccountId = u64;
|
||||||
pub type TestPayload = (u64, Weight);
|
#[derive(Decode, Encode, Clone, Debug, PartialEq, Eq)]
|
||||||
|
pub struct TestPayload(pub u64, pub Weight);
|
||||||
pub type TestMessageFee = u64;
|
pub type TestMessageFee = u64;
|
||||||
pub type TestRelayer = u64;
|
pub type TestRelayer = u64;
|
||||||
|
|
||||||
@@ -123,6 +125,12 @@ impl Config for TestRuntime {
|
|||||||
type MessageDispatch = TestMessageDispatch;
|
type MessageDispatch = TestMessageDispatch;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Size for TestPayload {
|
||||||
|
fn size_hint(&self) -> u32 {
|
||||||
|
16
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Account id of test relayer.
|
/// Account id of test relayer.
|
||||||
pub const TEST_RELAYER_A: AccountId = 100;
|
pub const TEST_RELAYER_A: AccountId = 100;
|
||||||
|
|
||||||
@@ -139,10 +147,10 @@ pub const TEST_ERROR: &str = "Test error";
|
|||||||
pub const TEST_LANE_ID: LaneId = [0, 0, 0, 1];
|
pub const TEST_LANE_ID: LaneId = [0, 0, 0, 1];
|
||||||
|
|
||||||
/// Regular message payload.
|
/// Regular message payload.
|
||||||
pub const REGULAR_PAYLOAD: TestPayload = (0, 50);
|
pub const REGULAR_PAYLOAD: TestPayload = TestPayload(0, 50);
|
||||||
|
|
||||||
/// Payload that is rejected by `TestTargetHeaderChain`.
|
/// Payload that is rejected by `TestTargetHeaderChain`.
|
||||||
pub const PAYLOAD_REJECTED_BY_TARGET_CHAIN: TestPayload = (1, 50);
|
pub const PAYLOAD_REJECTED_BY_TARGET_CHAIN: TestPayload = TestPayload(1, 50);
|
||||||
|
|
||||||
/// Vec of proved messages, grouped by lane.
|
/// Vec of proved messages, grouped by lane.
|
||||||
pub type MessagesByLaneVec = Vec<(LaneId, ProvedLaneMessages<Message<TestMessageFee>>)>;
|
pub type MessagesByLaneVec = Vec<(LaneId, ProvedLaneMessages<Message<TestMessageFee>>)>;
|
||||||
|
|||||||
@@ -17,7 +17,7 @@
|
|||||||
//! Autogenerated weights for pallet_message_lane
|
//! Autogenerated weights for pallet_message_lane
|
||||||
//!
|
//!
|
||||||
//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 2.0.0
|
//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 2.0.0
|
||||||
//! DATE: 2020-12-22, STEPS: [50, ], REPEAT: 20
|
//! DATE: 2020-12-28, STEPS: [50, ], REPEAT: 20
|
||||||
//! LOW RANGE: [], HIGH RANGE: []
|
//! LOW RANGE: [], HIGH RANGE: []
|
||||||
//! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled
|
//! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled
|
||||||
//! CHAIN: Some("local"), DB CACHE: 128
|
//! CHAIN: Some("local"), DB CACHE: 128
|
||||||
@@ -48,13 +48,16 @@ use sp_std::marker::PhantomData;
|
|||||||
|
|
||||||
/// Weight functions needed for pallet_message_lane.
|
/// Weight functions needed for pallet_message_lane.
|
||||||
pub trait WeightInfo {
|
pub trait WeightInfo {
|
||||||
fn send_message_worst_case() -> Weight;
|
fn send_minimal_message_worst_case() -> Weight;
|
||||||
|
fn send_1_kb_message_worst_case() -> Weight;
|
||||||
|
fn send_16_kb_message_worst_case() -> Weight;
|
||||||
fn receive_single_message_proof() -> Weight;
|
fn receive_single_message_proof() -> Weight;
|
||||||
fn receive_two_messages_proof() -> Weight;
|
fn receive_two_messages_proof() -> Weight;
|
||||||
fn receive_single_message_proof_with_outbound_lane_state() -> Weight;
|
fn receive_single_message_proof_with_outbound_lane_state() -> Weight;
|
||||||
fn receive_delivery_proof_for_single_message() -> Weight;
|
fn receive_delivery_proof_for_single_message() -> Weight;
|
||||||
fn receive_delivery_proof_for_two_messages_by_single_relayer() -> Weight;
|
fn receive_delivery_proof_for_two_messages_by_single_relayer() -> Weight;
|
||||||
fn receive_delivery_proof_for_two_messages_by_two_relayers() -> Weight;
|
fn receive_delivery_proof_for_two_messages_by_two_relayers() -> Weight;
|
||||||
|
fn send_messages_of_various_lengths(i: u32) -> Weight;
|
||||||
fn receive_multiple_messages_proof(i: u32) -> Weight;
|
fn receive_multiple_messages_proof(i: u32) -> Weight;
|
||||||
fn receive_multiple_messages_proof_with_outbound_lane_state(i: u32) -> Weight;
|
fn receive_multiple_messages_proof_with_outbound_lane_state(i: u32) -> Weight;
|
||||||
fn receive_delivery_proof_for_multiple_messages_by_single_relayer(i: u32) -> Weight;
|
fn receive_delivery_proof_for_multiple_messages_by_single_relayer(i: u32) -> Weight;
|
||||||
@@ -64,63 +67,79 @@ pub trait WeightInfo {
|
|||||||
/// Weights for pallet_message_lane using the Rialto node and recommended hardware.
|
/// Weights for pallet_message_lane using the Rialto node and recommended hardware.
|
||||||
pub struct RialtoWeight<T>(PhantomData<T>);
|
pub struct RialtoWeight<T>(PhantomData<T>);
|
||||||
impl<T: frame_system::Config> WeightInfo for RialtoWeight<T> {
|
impl<T: frame_system::Config> WeightInfo for RialtoWeight<T> {
|
||||||
fn send_message_worst_case() -> Weight {
|
fn send_minimal_message_worst_case() -> Weight {
|
||||||
(4_289_189_000 as Weight)
|
(249_486_000 as Weight)
|
||||||
|
.saturating_add(T::DbWeight::get().reads(4 as Weight))
|
||||||
|
.saturating_add(T::DbWeight::get().writes(12 as Weight))
|
||||||
|
}
|
||||||
|
fn send_1_kb_message_worst_case() -> Weight {
|
||||||
|
(257_454_000 as Weight)
|
||||||
|
.saturating_add(T::DbWeight::get().reads(4 as Weight))
|
||||||
|
.saturating_add(T::DbWeight::get().writes(12 as Weight))
|
||||||
|
}
|
||||||
|
fn send_16_kb_message_worst_case() -> Weight {
|
||||||
|
(344_817_000 as Weight)
|
||||||
.saturating_add(T::DbWeight::get().reads(4 as Weight))
|
.saturating_add(T::DbWeight::get().reads(4 as Weight))
|
||||||
.saturating_add(T::DbWeight::get().writes(12 as Weight))
|
.saturating_add(T::DbWeight::get().writes(12 as Weight))
|
||||||
}
|
}
|
||||||
fn receive_single_message_proof() -> Weight {
|
fn receive_single_message_proof() -> Weight {
|
||||||
(186_909_000 as Weight)
|
(197_341_000 as Weight)
|
||||||
.saturating_add(T::DbWeight::get().reads(3 as Weight))
|
.saturating_add(T::DbWeight::get().reads(3 as Weight))
|
||||||
.saturating_add(T::DbWeight::get().writes(1 as Weight))
|
.saturating_add(T::DbWeight::get().writes(1 as Weight))
|
||||||
}
|
}
|
||||||
fn receive_two_messages_proof() -> Weight {
|
fn receive_two_messages_proof() -> Weight {
|
||||||
(339_281_000 as Weight)
|
(341_056_000 as Weight)
|
||||||
.saturating_add(T::DbWeight::get().reads(3 as Weight))
|
.saturating_add(T::DbWeight::get().reads(3 as Weight))
|
||||||
.saturating_add(T::DbWeight::get().writes(1 as Weight))
|
.saturating_add(T::DbWeight::get().writes(1 as Weight))
|
||||||
}
|
}
|
||||||
fn receive_single_message_proof_with_outbound_lane_state() -> Weight {
|
fn receive_single_message_proof_with_outbound_lane_state() -> Weight {
|
||||||
(215_607_000 as Weight)
|
(227_735_000 as Weight)
|
||||||
.saturating_add(T::DbWeight::get().reads(3 as Weight))
|
.saturating_add(T::DbWeight::get().reads(3 as Weight))
|
||||||
.saturating_add(T::DbWeight::get().writes(1 as Weight))
|
.saturating_add(T::DbWeight::get().writes(1 as Weight))
|
||||||
}
|
}
|
||||||
fn receive_delivery_proof_for_single_message() -> Weight {
|
fn receive_delivery_proof_for_single_message() -> Weight {
|
||||||
(202_085_000 as Weight)
|
(208_305_000 as Weight)
|
||||||
.saturating_add(T::DbWeight::get().reads(6 as Weight))
|
.saturating_add(T::DbWeight::get().reads(6 as Weight))
|
||||||
.saturating_add(T::DbWeight::get().writes(3 as Weight))
|
.saturating_add(T::DbWeight::get().writes(3 as Weight))
|
||||||
}
|
}
|
||||||
fn receive_delivery_proof_for_two_messages_by_single_relayer() -> Weight {
|
fn receive_delivery_proof_for_two_messages_by_single_relayer() -> Weight {
|
||||||
(213_142_000 as Weight)
|
(239_511_000 as Weight)
|
||||||
.saturating_add(T::DbWeight::get().reads(7 as Weight))
|
.saturating_add(T::DbWeight::get().reads(7 as Weight))
|
||||||
.saturating_add(T::DbWeight::get().writes(3 as Weight))
|
.saturating_add(T::DbWeight::get().writes(3 as Weight))
|
||||||
}
|
}
|
||||||
fn receive_delivery_proof_for_two_messages_by_two_relayers() -> Weight {
|
fn receive_delivery_proof_for_two_messages_by_two_relayers() -> Weight {
|
||||||
(300_159_000 as Weight)
|
(341_307_000 as Weight)
|
||||||
.saturating_add(T::DbWeight::get().reads(8 as Weight))
|
.saturating_add(T::DbWeight::get().reads(8 as Weight))
|
||||||
.saturating_add(T::DbWeight::get().writes(4 as Weight))
|
.saturating_add(T::DbWeight::get().writes(4 as Weight))
|
||||||
}
|
}
|
||||||
|
fn send_messages_of_various_lengths(i: u32) -> Weight {
|
||||||
|
(206_352_000 as Weight)
|
||||||
|
.saturating_add((5_000 as Weight).saturating_mul(i as Weight))
|
||||||
|
.saturating_add(T::DbWeight::get().reads(4 as Weight))
|
||||||
|
.saturating_add(T::DbWeight::get().writes(12 as Weight))
|
||||||
|
}
|
||||||
fn receive_multiple_messages_proof(i: u32) -> Weight {
|
fn receive_multiple_messages_proof(i: u32) -> Weight {
|
||||||
(0 as Weight)
|
(0 as Weight)
|
||||||
.saturating_add((150_558_000 as Weight).saturating_mul(i as Weight))
|
.saturating_add((157_613_000 as Weight).saturating_mul(i as Weight))
|
||||||
.saturating_add(T::DbWeight::get().reads(3 as Weight))
|
.saturating_add(T::DbWeight::get().reads(3 as Weight))
|
||||||
.saturating_add(T::DbWeight::get().writes(1 as Weight))
|
.saturating_add(T::DbWeight::get().writes(1 as Weight))
|
||||||
}
|
}
|
||||||
fn receive_multiple_messages_proof_with_outbound_lane_state(i: u32) -> Weight {
|
fn receive_multiple_messages_proof_with_outbound_lane_state(i: u32) -> Weight {
|
||||||
(0 as Weight)
|
(0 as Weight)
|
||||||
.saturating_add((204_949_000 as Weight).saturating_mul(i as Weight))
|
.saturating_add((166_416_000 as Weight).saturating_mul(i as Weight))
|
||||||
.saturating_add(T::DbWeight::get().reads(3 as Weight))
|
.saturating_add(T::DbWeight::get().reads(3 as Weight))
|
||||||
.saturating_add(T::DbWeight::get().writes(1 as Weight))
|
.saturating_add(T::DbWeight::get().writes(1 as Weight))
|
||||||
}
|
}
|
||||||
fn receive_delivery_proof_for_multiple_messages_by_single_relayer(i: u32) -> Weight {
|
fn receive_delivery_proof_for_multiple_messages_by_single_relayer(i: u32) -> Weight {
|
||||||
(79_087_000 as Weight)
|
(107_561_000 as Weight)
|
||||||
.saturating_add((12_889_000 as Weight).saturating_mul(i as Weight))
|
.saturating_add((12_218_000 as Weight).saturating_mul(i as Weight))
|
||||||
.saturating_add(T::DbWeight::get().reads(5 as Weight))
|
.saturating_add(T::DbWeight::get().reads(5 as Weight))
|
||||||
.saturating_add(T::DbWeight::get().reads((1 as Weight).saturating_mul(i as Weight)))
|
.saturating_add(T::DbWeight::get().reads((1 as Weight).saturating_mul(i as Weight)))
|
||||||
.saturating_add(T::DbWeight::get().writes(3 as Weight))
|
.saturating_add(T::DbWeight::get().writes(3 as Weight))
|
||||||
}
|
}
|
||||||
fn receive_delivery_proof_for_multiple_messages_by_multiple_relayers(i: u32) -> Weight {
|
fn receive_delivery_proof_for_multiple_messages_by_multiple_relayers(i: u32) -> Weight {
|
||||||
(131_794_000 as Weight)
|
(124_619_000 as Weight)
|
||||||
.saturating_add((108_620_000 as Weight).saturating_mul(i as Weight))
|
.saturating_add((104_750_000 as Weight).saturating_mul(i as Weight))
|
||||||
.saturating_add(T::DbWeight::get().reads(4 as Weight))
|
.saturating_add(T::DbWeight::get().reads(4 as Weight))
|
||||||
.saturating_add(T::DbWeight::get().reads((2 as Weight).saturating_mul(i as Weight)))
|
.saturating_add(T::DbWeight::get().reads((2 as Weight).saturating_mul(i as Weight)))
|
||||||
.saturating_add(T::DbWeight::get().writes(2 as Weight))
|
.saturating_add(T::DbWeight::get().writes(2 as Weight))
|
||||||
@@ -130,63 +149,79 @@ impl<T: frame_system::Config> WeightInfo for RialtoWeight<T> {
|
|||||||
|
|
||||||
// For backwards compatibility and tests
|
// For backwards compatibility and tests
|
||||||
impl WeightInfo for () {
|
impl WeightInfo for () {
|
||||||
fn send_message_worst_case() -> Weight {
|
fn send_minimal_message_worst_case() -> Weight {
|
||||||
(4_289_189_000 as Weight)
|
(249_486_000 as Weight)
|
||||||
|
.saturating_add(RocksDbWeight::get().reads(4 as Weight))
|
||||||
|
.saturating_add(RocksDbWeight::get().writes(12 as Weight))
|
||||||
|
}
|
||||||
|
fn send_1_kb_message_worst_case() -> Weight {
|
||||||
|
(257_454_000 as Weight)
|
||||||
|
.saturating_add(RocksDbWeight::get().reads(4 as Weight))
|
||||||
|
.saturating_add(RocksDbWeight::get().writes(12 as Weight))
|
||||||
|
}
|
||||||
|
fn send_16_kb_message_worst_case() -> Weight {
|
||||||
|
(344_817_000 as Weight)
|
||||||
.saturating_add(RocksDbWeight::get().reads(4 as Weight))
|
.saturating_add(RocksDbWeight::get().reads(4 as Weight))
|
||||||
.saturating_add(RocksDbWeight::get().writes(12 as Weight))
|
.saturating_add(RocksDbWeight::get().writes(12 as Weight))
|
||||||
}
|
}
|
||||||
fn receive_single_message_proof() -> Weight {
|
fn receive_single_message_proof() -> Weight {
|
||||||
(186_909_000 as Weight)
|
(197_341_000 as Weight)
|
||||||
.saturating_add(RocksDbWeight::get().reads(3 as Weight))
|
.saturating_add(RocksDbWeight::get().reads(3 as Weight))
|
||||||
.saturating_add(RocksDbWeight::get().writes(1 as Weight))
|
.saturating_add(RocksDbWeight::get().writes(1 as Weight))
|
||||||
}
|
}
|
||||||
fn receive_two_messages_proof() -> Weight {
|
fn receive_two_messages_proof() -> Weight {
|
||||||
(339_281_000 as Weight)
|
(341_056_000 as Weight)
|
||||||
.saturating_add(RocksDbWeight::get().reads(3 as Weight))
|
.saturating_add(RocksDbWeight::get().reads(3 as Weight))
|
||||||
.saturating_add(RocksDbWeight::get().writes(1 as Weight))
|
.saturating_add(RocksDbWeight::get().writes(1 as Weight))
|
||||||
}
|
}
|
||||||
fn receive_single_message_proof_with_outbound_lane_state() -> Weight {
|
fn receive_single_message_proof_with_outbound_lane_state() -> Weight {
|
||||||
(215_607_000 as Weight)
|
(227_735_000 as Weight)
|
||||||
.saturating_add(RocksDbWeight::get().reads(3 as Weight))
|
.saturating_add(RocksDbWeight::get().reads(3 as Weight))
|
||||||
.saturating_add(RocksDbWeight::get().writes(1 as Weight))
|
.saturating_add(RocksDbWeight::get().writes(1 as Weight))
|
||||||
}
|
}
|
||||||
fn receive_delivery_proof_for_single_message() -> Weight {
|
fn receive_delivery_proof_for_single_message() -> Weight {
|
||||||
(202_085_000 as Weight)
|
(208_305_000 as Weight)
|
||||||
.saturating_add(RocksDbWeight::get().reads(6 as Weight))
|
.saturating_add(RocksDbWeight::get().reads(6 as Weight))
|
||||||
.saturating_add(RocksDbWeight::get().writes(3 as Weight))
|
.saturating_add(RocksDbWeight::get().writes(3 as Weight))
|
||||||
}
|
}
|
||||||
fn receive_delivery_proof_for_two_messages_by_single_relayer() -> Weight {
|
fn receive_delivery_proof_for_two_messages_by_single_relayer() -> Weight {
|
||||||
(213_142_000 as Weight)
|
(239_511_000 as Weight)
|
||||||
.saturating_add(RocksDbWeight::get().reads(7 as Weight))
|
.saturating_add(RocksDbWeight::get().reads(7 as Weight))
|
||||||
.saturating_add(RocksDbWeight::get().writes(3 as Weight))
|
.saturating_add(RocksDbWeight::get().writes(3 as Weight))
|
||||||
}
|
}
|
||||||
fn receive_delivery_proof_for_two_messages_by_two_relayers() -> Weight {
|
fn receive_delivery_proof_for_two_messages_by_two_relayers() -> Weight {
|
||||||
(300_159_000 as Weight)
|
(341_307_000 as Weight)
|
||||||
.saturating_add(RocksDbWeight::get().reads(8 as Weight))
|
.saturating_add(RocksDbWeight::get().reads(8 as Weight))
|
||||||
.saturating_add(RocksDbWeight::get().writes(4 as Weight))
|
.saturating_add(RocksDbWeight::get().writes(4 as Weight))
|
||||||
}
|
}
|
||||||
|
fn send_messages_of_various_lengths(i: u32) -> Weight {
|
||||||
|
(206_352_000 as Weight)
|
||||||
|
.saturating_add((5_000 as Weight).saturating_mul(i as Weight))
|
||||||
|
.saturating_add(RocksDbWeight::get().reads(4 as Weight))
|
||||||
|
.saturating_add(RocksDbWeight::get().writes(12 as Weight))
|
||||||
|
}
|
||||||
fn receive_multiple_messages_proof(i: u32) -> Weight {
|
fn receive_multiple_messages_proof(i: u32) -> Weight {
|
||||||
(0 as Weight)
|
(0 as Weight)
|
||||||
.saturating_add((150_558_000 as Weight).saturating_mul(i as Weight))
|
.saturating_add((157_613_000 as Weight).saturating_mul(i as Weight))
|
||||||
.saturating_add(RocksDbWeight::get().reads(3 as Weight))
|
.saturating_add(RocksDbWeight::get().reads(3 as Weight))
|
||||||
.saturating_add(RocksDbWeight::get().writes(1 as Weight))
|
.saturating_add(RocksDbWeight::get().writes(1 as Weight))
|
||||||
}
|
}
|
||||||
fn receive_multiple_messages_proof_with_outbound_lane_state(i: u32) -> Weight {
|
fn receive_multiple_messages_proof_with_outbound_lane_state(i: u32) -> Weight {
|
||||||
(0 as Weight)
|
(0 as Weight)
|
||||||
.saturating_add((204_949_000 as Weight).saturating_mul(i as Weight))
|
.saturating_add((166_416_000 as Weight).saturating_mul(i as Weight))
|
||||||
.saturating_add(RocksDbWeight::get().reads(3 as Weight))
|
.saturating_add(RocksDbWeight::get().reads(3 as Weight))
|
||||||
.saturating_add(RocksDbWeight::get().writes(1 as Weight))
|
.saturating_add(RocksDbWeight::get().writes(1 as Weight))
|
||||||
}
|
}
|
||||||
fn receive_delivery_proof_for_multiple_messages_by_single_relayer(i: u32) -> Weight {
|
fn receive_delivery_proof_for_multiple_messages_by_single_relayer(i: u32) -> Weight {
|
||||||
(79_087_000 as Weight)
|
(107_561_000 as Weight)
|
||||||
.saturating_add((12_889_000 as Weight).saturating_mul(i as Weight))
|
.saturating_add((12_218_000 as Weight).saturating_mul(i as Weight))
|
||||||
.saturating_add(RocksDbWeight::get().reads(5 as Weight))
|
.saturating_add(RocksDbWeight::get().reads(5 as Weight))
|
||||||
.saturating_add(RocksDbWeight::get().reads((1 as Weight).saturating_mul(i as Weight)))
|
.saturating_add(RocksDbWeight::get().reads((1 as Weight).saturating_mul(i as Weight)))
|
||||||
.saturating_add(RocksDbWeight::get().writes(3 as Weight))
|
.saturating_add(RocksDbWeight::get().writes(3 as Weight))
|
||||||
}
|
}
|
||||||
fn receive_delivery_proof_for_multiple_messages_by_multiple_relayers(i: u32) -> Weight {
|
fn receive_delivery_proof_for_multiple_messages_by_multiple_relayers(i: u32) -> Weight {
|
||||||
(131_794_000 as Weight)
|
(124_619_000 as Weight)
|
||||||
.saturating_add((108_620_000 as Weight).saturating_mul(i as Weight))
|
.saturating_add((104_750_000 as Weight).saturating_mul(i as Weight))
|
||||||
.saturating_add(RocksDbWeight::get().reads(4 as Weight))
|
.saturating_add(RocksDbWeight::get().reads(4 as Weight))
|
||||||
.saturating_add(RocksDbWeight::get().reads((2 as Weight).saturating_mul(i as Weight)))
|
.saturating_add(RocksDbWeight::get().reads((2 as Weight).saturating_mul(i as Weight)))
|
||||||
.saturating_add(RocksDbWeight::get().writes(2 as Weight))
|
.saturating_add(RocksDbWeight::get().writes(2 as Weight))
|
||||||
|
|||||||
@@ -23,7 +23,8 @@ use frame_support::weights::Weight;
|
|||||||
|
|
||||||
/// Ensure that weights from `WeightInfoExt` implementation are looking correct.
|
/// Ensure that weights from `WeightInfoExt` implementation are looking correct.
|
||||||
pub fn ensure_weights_are_correct<W: WeightInfoExt>() {
|
pub fn ensure_weights_are_correct<W: WeightInfoExt>() {
|
||||||
assert_ne!(W::send_message_worst_case(), 0);
|
assert_ne!(W::send_message_overhead(), 0);
|
||||||
|
assert_ne!(W::send_message_size_overhead(0), 0);
|
||||||
|
|
||||||
assert_ne!(W::receive_messages_proof_overhead(), 0);
|
assert_ne!(W::receive_messages_proof_overhead(), 0);
|
||||||
assert_ne!(W::receive_messages_proof_messages_overhead(1), 0);
|
assert_ne!(W::receive_messages_proof_messages_overhead(1), 0);
|
||||||
@@ -36,6 +37,18 @@ pub fn ensure_weights_are_correct<W: WeightInfoExt>() {
|
|||||||
|
|
||||||
/// Extended weight info.
|
/// Extended weight info.
|
||||||
pub trait WeightInfoExt: WeightInfo {
|
pub trait WeightInfoExt: WeightInfo {
|
||||||
|
/// Returns weight of message send transaction (`send_message`).
|
||||||
|
fn send_message_overhead() -> Weight {
|
||||||
|
Self::send_minimal_message_worst_case()
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Returns weight that needs to be accounted when message of given size is sent (`send_message`).
|
||||||
|
fn send_message_size_overhead(message_size: u32) -> Weight {
|
||||||
|
let message_size_in_kb = (1024u64 + message_size as u64) / 1024;
|
||||||
|
let single_kb_weight = (Self::send_16_kb_message_worst_case() - Self::send_1_kb_message_worst_case()) / 15;
|
||||||
|
message_size_in_kb * single_kb_weight
|
||||||
|
}
|
||||||
|
|
||||||
/// Returns weight overhead of message delivery transaction (`receive_messages_proof`).
|
/// Returns weight overhead of message delivery transaction (`receive_messages_proof`).
|
||||||
fn receive_messages_proof_overhead() -> Weight {
|
fn receive_messages_proof_overhead() -> Weight {
|
||||||
let weight_of_two_messages_and_two_tx_overheads = Self::receive_single_message_proof().saturating_mul(2);
|
let weight_of_two_messages_and_two_tx_overheads = Self::receive_single_message_proof().saturating_mul(2);
|
||||||
|
|||||||
@@ -95,3 +95,12 @@ where
|
|||||||
pub fn derive_relayer_fund_account_id(bridge_id: InstanceId) -> H256 {
|
pub fn derive_relayer_fund_account_id(bridge_id: InstanceId) -> H256 {
|
||||||
("relayer-fund-account", bridge_id).using_encoded(blake2_256).into()
|
("relayer-fund-account", bridge_id).using_encoded(blake2_256).into()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Anything that has size.
|
||||||
|
pub trait Size {
|
||||||
|
/// Return approximate size of this object (in bytes).
|
||||||
|
///
|
||||||
|
/// This function should be lightweight. The result should not necessary be absolutely
|
||||||
|
/// accurate.
|
||||||
|
fn size_hint(&self) -> u32;
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user