Skip to content

Commit

Permalink
fixed benchmarks of relayers pallet (paritytech#1700)
Browse files Browse the repository at this point in the history
  • Loading branch information
svyatonik authored Dec 5, 2022
1 parent fdda918 commit 6bceef3
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 7 deletions.
23 changes: 21 additions & 2 deletions bridges/bin/millau/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -969,13 +969,14 @@ impl_runtime_apis! {

use pallet_bridge_messages::benchmarking::Pallet as MessagesBench;
use pallet_bridge_parachains::benchmarking::Pallet as ParachainsBench;
use pallet_bridge_relayers::benchmarking::Pallet as RelayersBench;

let mut list = Vec::<BenchmarkList>::new();

list_benchmark!(list, extra, pallet_bridge_messages, MessagesBench::<Runtime, WithRialtoMessagesInstance>);
list_benchmark!(list, extra, pallet_bridge_grandpa, BridgeRialtoGrandpa);
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();

Expand Down Expand Up @@ -1014,6 +1015,10 @@ impl_runtime_apis! {
Pallet as ParachainsBench,
Config as ParachainsConfig,
};
use pallet_bridge_relayers::benchmarking::{
Pallet as RelayersBench,
Config as RelayersConfig,
};
use rialto_messages::WithRialtoMessageBridge;

impl MessagesConfig<WithRialtoMessagesInstance> for Runtime {
Expand Down Expand Up @@ -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!(
params,
batches,
Expand All @@ -1081,7 +1100,7 @@ impl_runtime_apis! {
pallet_bridge_parachains,
ParachainsBench::<Runtime, WithRialtoParachainsInstance>
);
add_benchmark!(params, batches, pallet_bridge_relayers, BridgeRelayers);
add_benchmark!(params, batches, pallet_bridge_relayers, RelayersBench::<Runtime>);

Ok(batches)
}
Expand Down
14 changes: 13 additions & 1 deletion bridges/modules/relayers/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,24 @@ use frame_system::RawOrigin;
/// Reward amount that is (hopefully) is larger than existential deposit across all chains.
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! {
// Benchmark `claim_rewards` call.
claim_rewards {
let lane = [0, 0, 0, 0];
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)
verify {
// we can't check anything here, because `PaymentProcedure` is responsible for
Expand Down
3 changes: 2 additions & 1 deletion bridges/modules/relayers/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ use weights::WeightInfo;
pub use pallet::*;
pub use payment_adapter::MessageDeliveryAndDispatchPaymentAdapter;

mod benchmarking;
pub mod benchmarking;

mod mock;
mod payment_adapter;

Expand Down
6 changes: 3 additions & 3 deletions bridges/modules/relayers/src/weights.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
//! Autogenerated weights for `pallet_bridge_relayers`
//!
//! 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: []
//! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled
//! CHAIN: Some("dev"), DB CACHE: 1024
Expand Down Expand Up @@ -59,7 +59,7 @@ pub trait WeightInfo {
pub struct BridgeWeight<T>(PhantomData<T>);
impl<T: frame_system::Config> WeightInfo for BridgeWeight<T> {
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().writes(2 as u64))
}
Expand All @@ -68,7 +68,7 @@ impl<T: frame_system::Config> WeightInfo for BridgeWeight<T> {
// For backwards compatibility and tests
impl WeightInfo for () {
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().writes(2 as u64))
}
Expand Down

0 comments on commit 6bceef3

Please sign in to comment.