From 3a359acb83fffa0a614f2cb16079d1acb24854b5 Mon Sep 17 00:00:00 2001 From: Svyatoslav Nikolsky Date: Fri, 4 Feb 2022 12:48:56 +0300 Subject: [PATCH] fix benchmarks before using it in Polkadot/Kusama/Rococo runtimes (#1309) --- bridges/bin/millau/runtime/src/lib.rs | 2 +- .../src/messages_benchmarking.rs | 7 +++--- bridges/modules/messages/src/benchmarking.rs | 23 ++++++++++++++----- 3 files changed, 21 insertions(+), 11 deletions(-) diff --git a/bridges/bin/millau/runtime/src/lib.rs b/bridges/bin/millau/runtime/src/lib.rs index e0c3903621709..67ac2abfe8391 100644 --- a/bridges/bin/millau/runtime/src/lib.rs +++ b/bridges/bin/millau/runtime/src/lib.rs @@ -860,7 +860,7 @@ impl_runtime_apis! { fn prepare_outbound_message( params: MessageParams, ) -> (rialto_messages::ToRialtoMessagePayload, Balance) { - prepare_outbound_message::(params) + (prepare_outbound_message::(params), Self::message_fee()) } fn prepare_message_proof( diff --git a/bridges/bin/runtime-common/src/messages_benchmarking.rs b/bridges/bin/runtime-common/src/messages_benchmarking.rs index 12c270d8666fd..b55442855c953 100644 --- a/bridges/bin/runtime-common/src/messages_benchmarking.rs +++ b/bridges/bin/runtime-common/src/messages_benchmarking.rs @@ -46,7 +46,7 @@ use sp_version::RuntimeVersion; /// Prepare outbound message for the `send_message` call. pub fn prepare_outbound_message( params: MessageParams>>, -) -> (FromThisChainMessagePayload, BalanceOf>) +) -> FromThisChainMessagePayload where B: MessageBridge, BalanceOf>: From, @@ -54,14 +54,13 @@ where let message_payload = vec![0; params.size as usize]; let dispatch_origin = bp_message_dispatch::CallOrigin::SourceAccount(params.sender_account); - let message = FromThisChainMessagePayload:: { + FromThisChainMessagePayload:: { 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. diff --git a/bridges/modules/messages/src/benchmarking.rs b/bridges/modules/messages/src/benchmarking.rs index 288ef4b2e8187..c0ad31460b693 100644 --- a/bridges/modules/messages/src/benchmarking.rs +++ b/bridges/modules/messages/src/benchmarking.rs @@ -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. @@ -103,6 +100,10 @@ pub trait Config: crate::Config { 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, @@ -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::(); 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() { @@ -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::(); 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() { @@ -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::(); 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() { @@ -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::(); 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(); @@ -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::(); 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(); @@ -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(), ); } @@ -600,12 +611,12 @@ benchmarks_instance_pallet! { fn send_regular_message, I: 'static>() { let mut outbound_lane = outbound_lane::(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, I: 'static>(payload: Vec) { let mut outbound_lane = outbound_lane::(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, I: 'static>(nonce: MessageNonce) {