mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-31 13:21:01 +00:00
Message lane benchmarks: start (#554)
* message lane benchmarks: start * finish send_message_worst_case benchmark * fix compilation * removed redundant bench param
This commit is contained in:
committed by
Bastian Köcher
parent
2944f997d1
commit
f57b7e9de0
@@ -0,0 +1,92 @@
|
||||
// Copyright 2019-2020 Parity Technologies (UK) Ltd.
|
||||
// This file is part of Parity Bridges Common.
|
||||
|
||||
// Parity Bridges Common is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
|
||||
// Parity Bridges Common is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Parity Bridges Common. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
//! Message lane pallet benchmarking.
|
||||
|
||||
use crate::{Call, Instance};
|
||||
|
||||
use bp_message_lane::{LaneId, MessageData, MessageNonce};
|
||||
use frame_benchmarking::{account, benchmarks_instance};
|
||||
use frame_support::traits::Get;
|
||||
use frame_system::RawOrigin;
|
||||
use num_traits::Zero;
|
||||
use sp_std::prelude::*;
|
||||
|
||||
/// Message crafted with this size factor should be the largest possible message.
|
||||
pub const WORST_MESSAGE_SIZE_FACTOR: u32 = 1000;
|
||||
|
||||
const SEED: u32 = 0;
|
||||
|
||||
/// Module we're benchmarking here.
|
||||
pub struct Module<T: Trait<I>, I: crate::Instance>(crate::Module<T, I>);
|
||||
|
||||
/// Benchmark-specific message parameters.
|
||||
pub struct MessageParams {
|
||||
/// Size factor of the message payload. Message payload grows with every factor
|
||||
/// increment. Zero is the smallest possible message and the `WORST_MESSAGE_SIZE_FACTOR` is
|
||||
/// largest possible message.
|
||||
pub size_factor: u32,
|
||||
}
|
||||
|
||||
/// Trait that must be implemented by runtime.
|
||||
pub trait Trait<I: Instance>: crate::Trait<I> {
|
||||
/// Create given account and give it enough balance for test purposes.
|
||||
fn endow_account(account: &Self::AccountId);
|
||||
/// Prepare message to send over lane.
|
||||
fn prepare_message(params: MessageParams) -> (Self::OutboundPayload, Self::OutboundMessageFee);
|
||||
}
|
||||
|
||||
benchmarks_instance! {
|
||||
_ { }
|
||||
|
||||
// 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 maximal for the target chain.
|
||||
send_message_worst_case {
|
||||
let i in 1..100;
|
||||
|
||||
let lane_id = bench_lane_id();
|
||||
let sender = account("sender", i, 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_message(MessageParams { size_factor: WORST_MESSAGE_SIZE_FACTOR });
|
||||
}: send_message(RawOrigin::Signed(sender), lane_id, payload, fee)
|
||||
}
|
||||
|
||||
fn bench_lane_id() -> LaneId {
|
||||
*b"test"
|
||||
}
|
||||
|
||||
fn send_regular_message<T: Trait<I>, I: Instance>() {
|
||||
let mut outbound_lane = crate::outbound_lane::<T, I>(bench_lane_id());
|
||||
outbound_lane.send_message(MessageData {
|
||||
payload: vec![],
|
||||
fee: Zero::zero(),
|
||||
});
|
||||
}
|
||||
|
||||
fn confirm_message_delivery<T: Trait<I>, I: Instance>(nonce: MessageNonce) {
|
||||
let mut outbound_lane = crate::outbound_lane::<T, I>(bench_lane_id());
|
||||
assert!(outbound_lane.confirm_delivery(nonce).is_some());
|
||||
}
|
||||
@@ -45,6 +45,7 @@ use frame_support::{
|
||||
Parameter, StorageMap,
|
||||
};
|
||||
use frame_system::{ensure_signed, RawOrigin};
|
||||
use num_traits::Zero;
|
||||
use sp_runtime::{traits::BadOrigin, DispatchResult};
|
||||
use sp_std::{cell::RefCell, marker::PhantomData, prelude::*};
|
||||
|
||||
@@ -53,6 +54,9 @@ mod outbound_lane;
|
||||
|
||||
pub mod instant_payments;
|
||||
|
||||
#[cfg(feature = "runtime-benchmarks")]
|
||||
pub mod benchmarking;
|
||||
|
||||
#[cfg(test)]
|
||||
mod mock;
|
||||
|
||||
@@ -71,9 +75,8 @@ pub trait Trait<I = DefaultInstance>: frame_system::Trait {
|
||||
/// They overarching event type.
|
||||
type Event: From<Event<Self, I>> + Into<<Self as frame_system::Trait>::Event>;
|
||||
/// Maximal number of messages that may be pruned during maintenance. Maintenance occurs
|
||||
/// whenever outbound lane is updated - i.e. when new message is sent, or receival is
|
||||
/// confirmed. The reason is that if you want to use lane, you should be ready to pay
|
||||
/// for it.
|
||||
/// whenever new message is sent. The reason is that if you want to use lane, you should
|
||||
/// be ready to pay for its maintenance.
|
||||
type MaxMessagesToPruneAtOnce: Get<MessageNonce>;
|
||||
/// Maximal number of unrewarded relayer entries at inbound lane. Unrewarded means that the
|
||||
/// relayer has delivered messages, but either confirmations haven't been delivered back to the
|
||||
@@ -99,7 +102,7 @@ pub trait Trait<I = DefaultInstance>: frame_system::Trait {
|
||||
/// Payload type of outbound messages. This payload is dispatched on the bridged chain.
|
||||
type OutboundPayload: Parameter;
|
||||
/// Message fee type of outbound messages. This fee is paid on this chain.
|
||||
type OutboundMessageFee: Parameter;
|
||||
type OutboundMessageFee: Parameter + Zero;
|
||||
|
||||
/// Payload type of inbound messages. This payload is dispatched on this chain.
|
||||
type InboundPayload: Decode;
|
||||
|
||||
Reference in New Issue
Block a user