Skip to content

Commit

Permalink
fix benchmarks before using it in Polkadot/Kusama/Rococo runtimes (pa…
Browse files Browse the repository at this point in the history
  • Loading branch information
svyatonik authored and serban300 committed Apr 9, 2024
1 parent 1f50cd5 commit 6ff6583
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 11 deletions.
2 changes: 1 addition & 1 deletion bridges/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 bridges/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 bridges/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

0 comments on commit 6ff6583

Please sign in to comment.