fixed benchmarks of relayers pallet (#1700)

This commit is contained in:
Svyatoslav Nikolsky
2022-12-05 13:36:11 +03:00
committed by Bastian Köcher
parent 66dfd2dcae
commit b94bd8d46b
4 changed files with 39 additions and 7 deletions
+21 -2
View File
@@ -969,13 +969,14 @@ impl_runtime_apis! {
use pallet_bridge_messages::benchmarking::Pallet as MessagesBench; use pallet_bridge_messages::benchmarking::Pallet as MessagesBench;
use pallet_bridge_parachains::benchmarking::Pallet as ParachainsBench; use pallet_bridge_parachains::benchmarking::Pallet as ParachainsBench;
use pallet_bridge_relayers::benchmarking::Pallet as RelayersBench;
let mut list = Vec::<BenchmarkList>::new(); let mut list = Vec::<BenchmarkList>::new();
list_benchmark!(list, extra, pallet_bridge_messages, MessagesBench::<Runtime, WithRialtoMessagesInstance>); list_benchmark!(list, extra, pallet_bridge_messages, MessagesBench::<Runtime, WithRialtoMessagesInstance>);
list_benchmark!(list, extra, pallet_bridge_grandpa, BridgeRialtoGrandpa); list_benchmark!(list, extra, pallet_bridge_grandpa, BridgeRialtoGrandpa);
list_benchmark!(list, extra, pallet_bridge_parachains, ParachainsBench::<Runtime, WithRialtoMessagesInstance>); list_benchmark!(list, extra, pallet_bridge_parachains, ParachainsBench::<Runtime, WithRialtoMessagesInstance>);
list_benchmark!(list, extra, pallet_bridge_relayers, BridgeRelayers); list_benchmark!(list, extra, pallet_bridge_relayers, RelayersBench::<Runtime>);
let storage_info = AllPalletsWithSystem::storage_info(); let storage_info = AllPalletsWithSystem::storage_info();
@@ -1014,6 +1015,10 @@ impl_runtime_apis! {
Pallet as ParachainsBench, Pallet as ParachainsBench,
Config as ParachainsConfig, Config as ParachainsConfig,
}; };
use pallet_bridge_relayers::benchmarking::{
Pallet as RelayersBench,
Config as RelayersConfig,
};
use rialto_messages::WithRialtoMessageBridge; use rialto_messages::WithRialtoMessageBridge;
impl MessagesConfig<WithRialtoMessagesInstance> for Runtime { impl MessagesConfig<WithRialtoMessagesInstance> for Runtime {
@@ -1068,6 +1073,20 @@ impl_runtime_apis! {
} }
} }
impl RelayersConfig for Runtime {
fn prepare_environment(
lane: bp_messages::LaneId,
reward: Balance,
) {
use frame_support::traits::fungible::Mutate;
let lane_rewards_account = bp_relayers::PayLaneRewardFromAccount::<
Balances,
AccountId
>::lane_rewards_account(lane);
Balances::mint_into(&lane_rewards_account, reward).unwrap();
}
}
add_benchmark!( add_benchmark!(
params, params,
batches, batches,
@@ -1081,7 +1100,7 @@ impl_runtime_apis! {
pallet_bridge_parachains, pallet_bridge_parachains,
ParachainsBench::<Runtime, WithRialtoParachainsInstance> ParachainsBench::<Runtime, WithRialtoParachainsInstance>
); );
add_benchmark!(params, batches, pallet_bridge_relayers, BridgeRelayers); add_benchmark!(params, batches, pallet_bridge_relayers, RelayersBench::<Runtime>);
Ok(batches) Ok(batches)
} }
+13 -1
View File
@@ -26,12 +26,24 @@ use frame_system::RawOrigin;
/// Reward amount that is (hopefully) is larger than existential deposit across all chains. /// Reward amount that is (hopefully) is larger than existential deposit across all chains.
const REWARD_AMOUNT: u32 = u32::MAX; const REWARD_AMOUNT: u32 = u32::MAX;
/// Pallet we're benchmarking here.
pub struct Pallet<T: Config>(crate::Pallet<T>);
/// Trait that must be implemented by runtime.
pub trait Config: crate::Config {
/// Prepare environment for paying given reward for serving given lane.
fn prepare_environment(lane: LaneId, reward: Self::Reward);
}
benchmarks! { benchmarks! {
// Benchmark `claim_rewards` call. // Benchmark `claim_rewards` call.
claim_rewards { claim_rewards {
let lane = [0, 0, 0, 0]; let lane = [0, 0, 0, 0];
let relayer: T::AccountId = whitelisted_caller(); let relayer: T::AccountId = whitelisted_caller();
RelayerRewards::<T>::insert(&relayer, lane, T::Reward::from(REWARD_AMOUNT)); let reward = T::Reward::from(REWARD_AMOUNT);
T::prepare_environment(lane, reward);
RelayerRewards::<T>::insert(&relayer, lane, reward);
}: _(RawOrigin::Signed(relayer), lane) }: _(RawOrigin::Signed(relayer), lane)
verify { verify {
// we can't check anything here, because `PaymentProcedure` is responsible for // we can't check anything here, because `PaymentProcedure` is responsible for
+2 -1
View File
@@ -30,7 +30,8 @@ use weights::WeightInfo;
pub use pallet::*; pub use pallet::*;
pub use payment_adapter::MessageDeliveryAndDispatchPaymentAdapter; pub use payment_adapter::MessageDeliveryAndDispatchPaymentAdapter;
mod benchmarking; pub mod benchmarking;
mod mock; mod mock;
mod payment_adapter; mod payment_adapter;
+3 -3
View File
@@ -17,7 +17,7 @@
//! Autogenerated weights for `pallet_bridge_relayers` //! Autogenerated weights for `pallet_bridge_relayers`
//! //!
//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev
//! DATE: 2022-11-17, STEPS: 50, REPEAT: 20 //! DATE: 2022-12-05, 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("dev"), DB CACHE: 1024 //! CHAIN: Some("dev"), DB CACHE: 1024
@@ -59,7 +59,7 @@ pub trait WeightInfo {
pub struct BridgeWeight<T>(PhantomData<T>); pub struct BridgeWeight<T>(PhantomData<T>);
impl<T: frame_system::Config> WeightInfo for BridgeWeight<T> { impl<T: frame_system::Config> WeightInfo for BridgeWeight<T> {
fn claim_rewards() -> Weight { fn claim_rewards() -> Weight {
Weight::from_ref_time(59_334_000 as u64) Weight::from_ref_time(64_065_000 as u64)
.saturating_add(T::DbWeight::get().reads(2 as u64)) .saturating_add(T::DbWeight::get().reads(2 as u64))
.saturating_add(T::DbWeight::get().writes(2 as u64)) .saturating_add(T::DbWeight::get().writes(2 as u64))
} }
@@ -68,7 +68,7 @@ impl<T: frame_system::Config> WeightInfo for BridgeWeight<T> {
// For backwards compatibility and tests // For backwards compatibility and tests
impl WeightInfo for () { impl WeightInfo for () {
fn claim_rewards() -> Weight { fn claim_rewards() -> Weight {
Weight::from_ref_time(59_334_000 as u64) Weight::from_ref_time(64_065_000 as u64)
.saturating_add(RocksDbWeight::get().reads(2 as u64)) .saturating_add(RocksDbWeight::get().reads(2 as u64))
.saturating_add(RocksDbWeight::get().writes(2 as u64)) .saturating_add(RocksDbWeight::get().writes(2 as u64))
} }