mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-31 13:21:01 +00:00
Benchmarks for new relayers pallet calls (#2040)
* slash relayer balance for invalid transactions * require some gap before unstake is possible * more clippy * log priority boost * add issue ref to TODO * fix typo * is_message_delivery_call -> is_receive_messages_proof_call * moved is_receive_messages_proof_call above * only slash relayers for priority transactions * benchmarks for new relayers pallet calls * generated weights * regenerated weights afer master merge * actually use weights
This commit is contained in:
committed by
Bastian Köcher
parent
f7cc060d9b
commit
1f738f1389
@@ -1108,16 +1108,20 @@ impl_runtime_apis! {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl RelayersConfig for Runtime {
|
impl RelayersConfig for Runtime {
|
||||||
fn prepare_environment(
|
fn prepare_rewards_account(
|
||||||
account_params: RewardsAccountParams,
|
account_params: RewardsAccountParams,
|
||||||
reward: Balance,
|
reward: Balance,
|
||||||
) {
|
) {
|
||||||
use frame_support::traits::fungible::Mutate;
|
|
||||||
let rewards_account = bp_relayers::PayRewardFromAccount::<
|
let rewards_account = bp_relayers::PayRewardFromAccount::<
|
||||||
Balances,
|
Balances,
|
||||||
AccountId
|
AccountId
|
||||||
>::rewards_account(account_params);
|
>::rewards_account(account_params);
|
||||||
Balances::mint_into(&rewards_account, reward).unwrap();
|
Self::deposit_account(rewards_account, reward);
|
||||||
|
}
|
||||||
|
|
||||||
|
fn deposit_account(account: AccountId, balance: Balance) {
|
||||||
|
use frame_support::traits::fungible::Mutate;
|
||||||
|
Balances::mint_into(&account, balance.saturating_add(ExistentialDeposit::get())).unwrap();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -24,6 +24,7 @@ use bp_messages::LaneId;
|
|||||||
use bp_relayers::RewardsAccountOwner;
|
use bp_relayers::RewardsAccountOwner;
|
||||||
use frame_benchmarking::{benchmarks, whitelisted_caller};
|
use frame_benchmarking::{benchmarks, whitelisted_caller};
|
||||||
use frame_system::RawOrigin;
|
use frame_system::RawOrigin;
|
||||||
|
use sp_runtime::traits::One;
|
||||||
|
|
||||||
/// 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;
|
||||||
@@ -34,7 +35,9 @@ pub struct Pallet<T: Config>(crate::Pallet<T>);
|
|||||||
/// Trait that must be implemented by runtime.
|
/// Trait that must be implemented by runtime.
|
||||||
pub trait Config: crate::Config {
|
pub trait Config: crate::Config {
|
||||||
/// Prepare environment for paying given reward for serving given lane.
|
/// Prepare environment for paying given reward for serving given lane.
|
||||||
fn prepare_environment(account_params: RewardsAccountParams, reward: Self::Reward);
|
fn prepare_rewards_account(account_params: RewardsAccountParams, reward: Self::Reward);
|
||||||
|
/// Give enough balance to given account.
|
||||||
|
fn deposit_account(account: Self::AccountId, balance: Self::Reward);
|
||||||
}
|
}
|
||||||
|
|
||||||
benchmarks! {
|
benchmarks! {
|
||||||
@@ -46,7 +49,7 @@ benchmarks! {
|
|||||||
let relayer: T::AccountId = whitelisted_caller();
|
let relayer: T::AccountId = whitelisted_caller();
|
||||||
let reward = T::Reward::from(REWARD_AMOUNT);
|
let reward = T::Reward::from(REWARD_AMOUNT);
|
||||||
|
|
||||||
T::prepare_environment(account_params, reward);
|
T::prepare_rewards_account(account_params, reward);
|
||||||
RelayerRewards::<T>::insert(&relayer, account_params, reward);
|
RelayerRewards::<T>::insert(&relayer, account_params, reward);
|
||||||
}: _(RawOrigin::Signed(relayer), account_params)
|
}: _(RawOrigin::Signed(relayer), account_params)
|
||||||
verify {
|
verify {
|
||||||
@@ -55,5 +58,35 @@ benchmarks! {
|
|||||||
// also completed successfully
|
// also completed successfully
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Benchmark `register` call.
|
||||||
|
register {
|
||||||
|
let relayer: T::AccountId = whitelisted_caller();
|
||||||
|
let valid_till = frame_system::Pallet::<T>::block_number()
|
||||||
|
.saturating_add(crate::Pallet::<T>::required_registration_lease())
|
||||||
|
.saturating_add(One::one())
|
||||||
|
.saturating_add(One::one());
|
||||||
|
|
||||||
|
T::deposit_account(relayer.clone(), crate::Pallet::<T>::required_stake());
|
||||||
|
}: _(RawOrigin::Signed(relayer.clone()), valid_till)
|
||||||
|
verify {
|
||||||
|
assert!(crate::Pallet::<T>::is_registration_active(&relayer));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Benchmark `deregister` call.
|
||||||
|
deregister {
|
||||||
|
let relayer: T::AccountId = whitelisted_caller();
|
||||||
|
let valid_till = frame_system::Pallet::<T>::block_number()
|
||||||
|
.saturating_add(crate::Pallet::<T>::required_registration_lease())
|
||||||
|
.saturating_add(One::one())
|
||||||
|
.saturating_add(One::one());
|
||||||
|
T::deposit_account(relayer.clone(), crate::Pallet::<T>::required_stake());
|
||||||
|
crate::Pallet::<T>::register(RawOrigin::Signed(relayer.clone()).into(), valid_till).unwrap();
|
||||||
|
|
||||||
|
frame_system::Pallet::<T>::set_block_number(valid_till.saturating_add(One::one()));
|
||||||
|
}: _(RawOrigin::Signed(relayer.clone()))
|
||||||
|
verify {
|
||||||
|
assert!(!crate::Pallet::<T>::is_registration_active(&relayer));
|
||||||
|
}
|
||||||
|
|
||||||
impl_benchmark_test_suite!(Pallet, crate::mock::new_test_ext(), crate::mock::TestRuntime)
|
impl_benchmark_test_suite!(Pallet, crate::mock::new_test_ext(), crate::mock::TestRuntime)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -114,7 +114,7 @@ pub mod pallet {
|
|||||||
///
|
///
|
||||||
/// Registration allows relayer to get priority boost for its message delivery transactions.
|
/// Registration allows relayer to get priority boost for its message delivery transactions.
|
||||||
#[pallet::call_index(1)]
|
#[pallet::call_index(1)]
|
||||||
#[pallet::weight(Weight::zero())] // TODO: https://github.com/paritytech/parity-bridges-common/issues/2033
|
#[pallet::weight(T::WeightInfo::register())]
|
||||||
pub fn register(origin: OriginFor<T>, valid_till: T::BlockNumber) -> DispatchResult {
|
pub fn register(origin: OriginFor<T>, valid_till: T::BlockNumber) -> DispatchResult {
|
||||||
let relayer = ensure_signed(origin)?;
|
let relayer = ensure_signed(origin)?;
|
||||||
|
|
||||||
@@ -175,7 +175,7 @@ pub mod pallet {
|
|||||||
/// After this call, message delivery transactions of the relayer won't get any priority
|
/// After this call, message delivery transactions of the relayer won't get any priority
|
||||||
/// boost.
|
/// boost.
|
||||||
#[pallet::call_index(2)]
|
#[pallet::call_index(2)]
|
||||||
#[pallet::weight(Weight::zero())] // TODO: https://github.com/paritytech/parity-bridges-common/issues/2033
|
#[pallet::weight(T::WeightInfo::deregister())]
|
||||||
pub fn deregister(origin: OriginFor<T>) -> DispatchResult {
|
pub fn deregister(origin: OriginFor<T>) -> DispatchResult {
|
||||||
let relayer = ensure_signed(origin)?;
|
let relayer = ensure_signed(origin)?;
|
||||||
|
|
||||||
@@ -326,7 +326,7 @@ pub mod pallet {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Return required registration lease.
|
/// Return required registration lease.
|
||||||
fn required_registration_lease() -> T::BlockNumber {
|
pub(crate) fn required_registration_lease() -> T::BlockNumber {
|
||||||
<T::StakeAndSlash as StakeAndSlash<
|
<T::StakeAndSlash as StakeAndSlash<
|
||||||
T::AccountId,
|
T::AccountId,
|
||||||
T::BlockNumber,
|
T::BlockNumber,
|
||||||
@@ -335,7 +335,7 @@ pub mod pallet {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Return required stake.
|
/// Return required stake.
|
||||||
fn required_stake() -> T::Reward {
|
pub(crate) fn required_stake() -> T::Reward {
|
||||||
<T::StakeAndSlash as StakeAndSlash<
|
<T::StakeAndSlash as StakeAndSlash<
|
||||||
T::AccountId,
|
T::AccountId,
|
||||||
T::BlockNumber,
|
T::BlockNumber,
|
||||||
|
|||||||
@@ -118,13 +118,16 @@ impl pallet_bridge_relayers::Config for TestRuntime {
|
|||||||
|
|
||||||
#[cfg(feature = "runtime-benchmarks")]
|
#[cfg(feature = "runtime-benchmarks")]
|
||||||
impl pallet_bridge_relayers::benchmarking::Config for TestRuntime {
|
impl pallet_bridge_relayers::benchmarking::Config for TestRuntime {
|
||||||
fn prepare_environment(account_params: RewardsAccountParams, reward: Balance) {
|
fn prepare_rewards_account(account_params: RewardsAccountParams, reward: Balance) {
|
||||||
use frame_support::traits::fungible::Mutate;
|
|
||||||
let rewards_account =
|
let rewards_account =
|
||||||
bp_relayers::PayRewardFromAccount::<Balances, AccountId>::rewards_account(
|
bp_relayers::PayRewardFromAccount::<Balances, AccountId>::rewards_account(
|
||||||
account_params,
|
account_params,
|
||||||
);
|
);
|
||||||
Balances::mint_into(&rewards_account, reward).unwrap();
|
Self::deposit_account(rewards_account, reward);
|
||||||
|
}
|
||||||
|
|
||||||
|
fn deposit_account(account: Self::AccountId, balance: Self::Reward) {
|
||||||
|
Balances::mint_into(&account, balance.saturating_add(ExistentialDeposit::get())).unwrap();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -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: 2023-03-02, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]`
|
//! DATE: 2023-04-17, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]`
|
||||||
//! WORST CASE MAP SIZE: `1000000`
|
//! WORST CASE MAP SIZE: `1000000`
|
||||||
//! HOSTNAME: `covid`, CPU: `11th Gen Intel(R) Core(TM) i7-11800H @ 2.30GHz`
|
//! HOSTNAME: `covid`, CPU: `11th Gen Intel(R) Core(TM) i7-11800H @ 2.30GHz`
|
||||||
//! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: Some("dev"), DB CACHE: 1024
|
//! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: Some("dev"), DB CACHE: 1024
|
||||||
@@ -51,6 +51,8 @@ use sp_std::marker::PhantomData;
|
|||||||
/// Weight functions needed for pallet_bridge_relayers.
|
/// Weight functions needed for pallet_bridge_relayers.
|
||||||
pub trait WeightInfo {
|
pub trait WeightInfo {
|
||||||
fn claim_rewards() -> Weight;
|
fn claim_rewards() -> Weight;
|
||||||
|
fn register() -> Weight;
|
||||||
|
fn deregister() -> Weight;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Weights for `pallet_bridge_relayers` that are generated using one of the Bridge testnets.
|
/// Weights for `pallet_bridge_relayers` that are generated using one of the Bridge testnets.
|
||||||
@@ -63,16 +65,57 @@ impl<T: frame_system::Config> WeightInfo for BridgeWeight<T> {
|
|||||||
/// Proof: BridgeRelayers RelayerRewards (max_values: None, max_size: Some(65), added: 2540,
|
/// Proof: BridgeRelayers RelayerRewards (max_values: None, max_size: Some(65), added: 2540,
|
||||||
/// mode: MaxEncodedLen)
|
/// mode: MaxEncodedLen)
|
||||||
///
|
///
|
||||||
|
/// Storage: Balances TotalIssuance (r:1 w:0)
|
||||||
|
///
|
||||||
|
/// Proof: Balances TotalIssuance (max_values: Some(1), max_size: Some(8), added: 503, mode:
|
||||||
|
/// MaxEncodedLen)
|
||||||
|
///
|
||||||
/// Storage: System Account (r:1 w:1)
|
/// Storage: System Account (r:1 w:1)
|
||||||
///
|
///
|
||||||
/// Proof: System Account (max_values: None, max_size: Some(96), added: 2571, mode:
|
/// Proof: System Account (max_values: None, max_size: Some(104), added: 2579, mode:
|
||||||
/// MaxEncodedLen)
|
/// MaxEncodedLen)
|
||||||
fn claim_rewards() -> Weight {
|
fn claim_rewards() -> Weight {
|
||||||
// Proof Size summary in bytes:
|
// Proof Size summary in bytes:
|
||||||
// Measured: `275`
|
// Measured: `294`
|
||||||
// Estimated: `5111`
|
// Estimated: `8592`
|
||||||
// Minimum execution time: 48_639 nanoseconds.
|
// Minimum execution time: 75_307 nanoseconds.
|
||||||
Weight::from_parts(49_600_000, 5111)
|
Weight::from_parts(76_564_000, 8592)
|
||||||
|
.saturating_add(T::DbWeight::get().reads(3_u64))
|
||||||
|
.saturating_add(T::DbWeight::get().writes(2_u64))
|
||||||
|
}
|
||||||
|
/// Storage: BridgeRelayers RegisteredRelayers (r:1 w:1)
|
||||||
|
///
|
||||||
|
/// Proof: BridgeRelayers RegisteredRelayers (max_values: None, max_size: Some(64), added: 2539,
|
||||||
|
/// mode: MaxEncodedLen)
|
||||||
|
///
|
||||||
|
/// Storage: Balances Reserves (r:1 w:1)
|
||||||
|
///
|
||||||
|
/// Proof: Balances Reserves (max_values: None, max_size: Some(849), added: 3324, mode:
|
||||||
|
/// MaxEncodedLen)
|
||||||
|
fn register() -> Weight {
|
||||||
|
// Proof Size summary in bytes:
|
||||||
|
// Measured: `87`
|
||||||
|
// Estimated: `7843`
|
||||||
|
// Minimum execution time: 38_270 nanoseconds.
|
||||||
|
Weight::from_parts(39_191_000, 7843)
|
||||||
|
.saturating_add(T::DbWeight::get().reads(2_u64))
|
||||||
|
.saturating_add(T::DbWeight::get().writes(2_u64))
|
||||||
|
}
|
||||||
|
/// Storage: BridgeRelayers RegisteredRelayers (r:1 w:1)
|
||||||
|
///
|
||||||
|
/// Proof: BridgeRelayers RegisteredRelayers (max_values: None, max_size: Some(64), added: 2539,
|
||||||
|
/// mode: MaxEncodedLen)
|
||||||
|
///
|
||||||
|
/// Storage: Balances Reserves (r:1 w:1)
|
||||||
|
///
|
||||||
|
/// Proof: Balances Reserves (max_values: None, max_size: Some(849), added: 3324, mode:
|
||||||
|
/// MaxEncodedLen)
|
||||||
|
fn deregister() -> Weight {
|
||||||
|
// Proof Size summary in bytes:
|
||||||
|
// Measured: `264`
|
||||||
|
// Estimated: `7843`
|
||||||
|
// Minimum execution time: 43_028 nanoseconds.
|
||||||
|
Weight::from_parts(44_098_000, 7843)
|
||||||
.saturating_add(T::DbWeight::get().reads(2_u64))
|
.saturating_add(T::DbWeight::get().reads(2_u64))
|
||||||
.saturating_add(T::DbWeight::get().writes(2_u64))
|
.saturating_add(T::DbWeight::get().writes(2_u64))
|
||||||
}
|
}
|
||||||
@@ -85,16 +128,57 @@ impl WeightInfo for () {
|
|||||||
/// Proof: BridgeRelayers RelayerRewards (max_values: None, max_size: Some(65), added: 2540,
|
/// Proof: BridgeRelayers RelayerRewards (max_values: None, max_size: Some(65), added: 2540,
|
||||||
/// mode: MaxEncodedLen)
|
/// mode: MaxEncodedLen)
|
||||||
///
|
///
|
||||||
|
/// Storage: Balances TotalIssuance (r:1 w:0)
|
||||||
|
///
|
||||||
|
/// Proof: Balances TotalIssuance (max_values: Some(1), max_size: Some(8), added: 503, mode:
|
||||||
|
/// MaxEncodedLen)
|
||||||
|
///
|
||||||
/// Storage: System Account (r:1 w:1)
|
/// Storage: System Account (r:1 w:1)
|
||||||
///
|
///
|
||||||
/// Proof: System Account (max_values: None, max_size: Some(96), added: 2571, mode:
|
/// Proof: System Account (max_values: None, max_size: Some(104), added: 2579, mode:
|
||||||
/// MaxEncodedLen)
|
/// MaxEncodedLen)
|
||||||
fn claim_rewards() -> Weight {
|
fn claim_rewards() -> Weight {
|
||||||
// Proof Size summary in bytes:
|
// Proof Size summary in bytes:
|
||||||
// Measured: `275`
|
// Measured: `294`
|
||||||
// Estimated: `5111`
|
// Estimated: `8592`
|
||||||
// Minimum execution time: 48_639 nanoseconds.
|
// Minimum execution time: 75_307 nanoseconds.
|
||||||
Weight::from_parts(49_600_000, 5111)
|
Weight::from_parts(76_564_000, 8592)
|
||||||
|
.saturating_add(RocksDbWeight::get().reads(3_u64))
|
||||||
|
.saturating_add(RocksDbWeight::get().writes(2_u64))
|
||||||
|
}
|
||||||
|
/// Storage: BridgeRelayers RegisteredRelayers (r:1 w:1)
|
||||||
|
///
|
||||||
|
/// Proof: BridgeRelayers RegisteredRelayers (max_values: None, max_size: Some(64), added: 2539,
|
||||||
|
/// mode: MaxEncodedLen)
|
||||||
|
///
|
||||||
|
/// Storage: Balances Reserves (r:1 w:1)
|
||||||
|
///
|
||||||
|
/// Proof: Balances Reserves (max_values: None, max_size: Some(849), added: 3324, mode:
|
||||||
|
/// MaxEncodedLen)
|
||||||
|
fn register() -> Weight {
|
||||||
|
// Proof Size summary in bytes:
|
||||||
|
// Measured: `87`
|
||||||
|
// Estimated: `7843`
|
||||||
|
// Minimum execution time: 38_270 nanoseconds.
|
||||||
|
Weight::from_parts(39_191_000, 7843)
|
||||||
|
.saturating_add(RocksDbWeight::get().reads(2_u64))
|
||||||
|
.saturating_add(RocksDbWeight::get().writes(2_u64))
|
||||||
|
}
|
||||||
|
/// Storage: BridgeRelayers RegisteredRelayers (r:1 w:1)
|
||||||
|
///
|
||||||
|
/// Proof: BridgeRelayers RegisteredRelayers (max_values: None, max_size: Some(64), added: 2539,
|
||||||
|
/// mode: MaxEncodedLen)
|
||||||
|
///
|
||||||
|
/// Storage: Balances Reserves (r:1 w:1)
|
||||||
|
///
|
||||||
|
/// Proof: Balances Reserves (max_values: None, max_size: Some(849), added: 3324, mode:
|
||||||
|
/// MaxEncodedLen)
|
||||||
|
fn deregister() -> Weight {
|
||||||
|
// Proof Size summary in bytes:
|
||||||
|
// Measured: `264`
|
||||||
|
// Estimated: `7843`
|
||||||
|
// Minimum execution time: 43_028 nanoseconds.
|
||||||
|
Weight::from_parts(44_098_000, 7843)
|
||||||
.saturating_add(RocksDbWeight::get().reads(2_u64))
|
.saturating_add(RocksDbWeight::get().reads(2_u64))
|
||||||
.saturating_add(RocksDbWeight::get().writes(2_u64))
|
.saturating_add(RocksDbWeight::get().writes(2_u64))
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user