Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix benchmarks before using it in Polkadot/Kusama/Rococo runtimes #1309

Merged
merged 1 commit into from
Feb 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion bin/millau/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -860,7 +860,7 @@ impl_runtime_apis! {
fn prepare_outbound_message(
params: MessageParams<Self::AccountId>,
) -> (rialto_messages::ToRialtoMessagePayload, Balance) {
prepare_outbound_message::<WithRialtoMessageBridge>(params)
(prepare_outbound_message::<WithRialtoMessageBridge>(params), Self::message_fee())
}

fn prepare_message_proof(
Expand Down
7 changes: 3 additions & 4 deletions bin/runtime-common/src/messages_benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,22 +46,21 @@ use sp_version::RuntimeVersion;
/// Prepare outbound message for the `send_message` call.
pub fn prepare_outbound_message<B>(
params: MessageParams<AccountIdOf<ThisChain<B>>>,
) -> (FromThisChainMessagePayload<B>, BalanceOf<ThisChain<B>>)
) -> FromThisChainMessagePayload<B>
where
B: MessageBridge,
BalanceOf<ThisChain<B>>: From<u64>,
{
let message_payload = vec![0; params.size as usize];
let dispatch_origin = bp_message_dispatch::CallOrigin::SourceAccount(params.sender_account);

let message = FromThisChainMessagePayload::<B> {
FromThisChainMessagePayload::<B> {
spec_version: 0,
weight: params.size as _,
origin: dispatch_origin,
call: message_payload,
dispatch_fee_payment: DispatchFeePayment::AtSourceChain,
};
(message, pallet_bridge_messages::benchmarking::MESSAGE_FEE.into())
}
}

/// Prepare proof of messages for the `receive_messages_proof` call.
Expand Down
23 changes: 17 additions & 6 deletions modules/messages/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,6 @@ use frame_support::{traits::Get, weights::Weight};
use frame_system::RawOrigin;
use sp_std::{collections::vec_deque::VecDeque, convert::TryInto, ops::RangeInclusive, prelude::*};

/// Fee paid by submitter for single message delivery.
pub const MESSAGE_FEE: u64 = 100_000_000_000;

const SEED: u32 = 0;

/// Pallet we're benchmarking here.
Expand Down Expand Up @@ -103,6 +100,10 @@ pub trait Config<I: 'static>: crate::Config<I> {
fn account_balance(account: &Self::AccountId) -> Self::OutboundMessageFee;
/// Create given account and give it enough balance for test purposes.
fn endow_account(account: &Self::AccountId);
/// Fee paid by submitter for single message delivery.
fn message_fee() -> Self::OutboundMessageFee {
100_000_000_000_000.into()
}
/// Prepare message to send over lane.
fn prepare_outbound_message(
params: MessageParams<Self::AccountId>,
Expand Down Expand Up @@ -138,8 +139,10 @@ benchmarks_instance_pallet! {
// added.
send_minimal_message_worst_case {
let lane_id = T::bench_lane_id();
let relayers_fund_id = crate::relayer_fund_account_id::<T::AccountId, T::AccountIdConverter>();
let sender = account("sender", 0, SEED);
T::endow_account(&sender);
T::endow_account(&relayers_fund_id);

// 'send' messages that are to be pruned when our message is sent
for _nonce in 1..=T::MaxMessagesToPruneAtOnce::get() {
Expand Down Expand Up @@ -169,8 +172,10 @@ benchmarks_instance_pallet! {
// `(send_16_kb_message_worst_case - send_1_kb_message_worst_case) / 15`.
send_1_kb_message_worst_case {
let lane_id = T::bench_lane_id();
let relayers_fund_id = crate::relayer_fund_account_id::<T::AccountId, T::AccountIdConverter>();
let sender = account("sender", 0, SEED);
T::endow_account(&sender);
T::endow_account(&relayers_fund_id);

// 'send' messages that are to be pruned when our message is sent
for _nonce in 1..=T::MaxMessagesToPruneAtOnce::get() {
Expand Down Expand Up @@ -206,8 +211,10 @@ benchmarks_instance_pallet! {
// `(send_16_kb_message_worst_case - send_1_kb_message_worst_case) / 15`.
send_16_kb_message_worst_case {
let lane_id = T::bench_lane_id();
let relayers_fund_id = crate::relayer_fund_account_id::<T::AccountId, T::AccountIdConverter>();
let sender = account("sender", 0, SEED);
T::endow_account(&sender);
T::endow_account(&relayers_fund_id);

// 'send' messages that are to be pruned when our message is sent
for _nonce in 1..=T::MaxMessagesToPruneAtOnce::get() {
Expand Down Expand Up @@ -239,8 +246,10 @@ benchmarks_instance_pallet! {
//
// Result of this benchmark is directly used by weight formula of the call.
maximal_increase_message_fee {
let relayers_fund_id = crate::relayer_fund_account_id::<T::AccountId, T::AccountIdConverter>();
let sender = account("sender", 42, SEED);
T::endow_account(&sender);
T::endow_account(&relayers_fund_id);

let additional_fee = T::account_balance(&sender);
let lane_id = T::bench_lane_id();
Expand All @@ -258,8 +267,10 @@ benchmarks_instance_pallet! {
increase_message_fee {
let i in 0..T::maximal_message_size().try_into().unwrap_or_default();

let relayers_fund_id = crate::relayer_fund_account_id::<T::AccountId, T::AccountIdConverter>();
let sender = account("sender", 42, SEED);
T::endow_account(&sender);
T::endow_account(&relayers_fund_id);

let additional_fee = T::account_balance(&sender);
let lane_id = T::bench_lane_id();
Expand Down Expand Up @@ -506,7 +517,7 @@ benchmarks_instance_pallet! {
verify {
assert_eq!(
T::account_balance(&relayer_id),
relayer_balance + MESSAGE_FEE.into(),
relayer_balance + T::message_fee(),
);
}

Expand Down Expand Up @@ -600,12 +611,12 @@ benchmarks_instance_pallet! {

fn send_regular_message<T: Config<I>, I: 'static>() {
let mut outbound_lane = outbound_lane::<T, I>(T::bench_lane_id());
outbound_lane.send_message(MessageData { payload: vec![], fee: MESSAGE_FEE.into() });
outbound_lane.send_message(MessageData { payload: vec![], fee: T::message_fee() });
}

fn send_regular_message_with_payload<T: Config<I>, I: 'static>(payload: Vec<u8>) {
let mut outbound_lane = outbound_lane::<T, I>(T::bench_lane_id());
outbound_lane.send_message(MessageData { payload, fee: MESSAGE_FEE.into() });
outbound_lane.send_message(MessageData { payload, fee: T::message_fee() });
}

fn confirm_message_delivery<T: Config<I>, I: 'static>(nonce: MessageNonce) {
Expand Down