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

Fixed benchmarks of relayers pallet #1700

Merged
merged 1 commit into from
Dec 5, 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
23 changes: 21 additions & 2 deletions 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 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 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 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