Skip to content

Commit

Permalink
update benchmarks and related weights
Browse files Browse the repository at this point in the history
  • Loading branch information
shannonwells committed Apr 25, 2024
1 parent a6db4de commit 0b5d184
Show file tree
Hide file tree
Showing 4 changed files with 133 additions and 47 deletions.
36 changes: 29 additions & 7 deletions pallets/capacity/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,24 @@ pub fn set_up_epoch<T: Config>(current_block: BlockNumberFor<T>, current_epoch:
CurrentEpochInfo::<T>::set(EpochInfo { epoch_start });
}

pub fn set_era_and_reward_pool_at_block<T: Config>(
era_index: T::RewardEra,
started_at: BlockNumberFor<T>,
total_staked_token: BalanceOf<T>,
) {
let era_info: RewardEraInfo<T::RewardEra, BlockNumberFor<T>> =
RewardEraInfo { era_index, started_at };
let total_reward_pool: BalanceOf<T> =
T::MinimumStakingAmount::get().saturating_add(1_100u32.into());
CurrentEraInfo::<T>::set(era_info);
let pool_info: RewardPoolInfo<BalanceOf<T>> = RewardPoolInfo {
total_staked_token,
total_reward_pool,
unclaimed_balance: total_reward_pool,
};
StakingRewardPool::<T>::insert(era_index, pool_info);
}

// caller stakes the given amount to the given target
pub fn setup_provider_stake<T: Config>(
caller: &T::AccountId,
Expand Down Expand Up @@ -79,6 +97,7 @@ benchmarks! {
let target = 1;
let staking_type = MaximumCapacity;

set_era_and_reward_pool_at_block::<T>(1u32.into(), 1u32.into(), 1_000u32.into());
register_provider::<T>(target, "Foo");

}: _ (RawOrigin::Signed(caller.clone()), target, amount)
Expand Down Expand Up @@ -119,6 +138,7 @@ benchmarks! {
let target = 1;
let block_number = 4u32;

set_era_and_reward_pool_at_block::<T>(1u32.into(), 1u32.into(), 1_000u32.into());
setup_provider_stake::<T>(&caller, &target, staking_amount);
fill_unlock_chunks::<T>(&caller, T::MaxUnlockingChunks::get() - 1);
}: _ (RawOrigin::Signed(caller.clone()), target, unstaking_amount.into())
Expand All @@ -144,16 +164,17 @@ benchmarks! {
let from_msa = 33;
let to_msa = 34;
// amount in addition to minimum
let from_msa_amount = 32u32;
let to_msa_amount = 1u32;
let from_msa_amount: BalanceOf<T> = T::MinimumStakingAmount::get().saturating_add(31u32.into());
let to_msa_amount: BalanceOf<T> = T::MinimumStakingAmount::get().saturating_add(1u32.into());

set_era_and_reward_pool_at_block::<T>(1u32.into(), 1u32.into(), 1_000u32.into());
register_provider::<T>(from_msa, "frommsa");
register_provider::<T>(to_msa, "tomsa");
setup_provider_stake::<T>(&caller, &from_msa, from_msa_amount.into());
setup_provider_stake::<T>(&caller, &to_msa, to_msa_amount.into());
let restake_amount = 11u32;
setup_provider_stake::<T>(&caller, &from_msa, from_msa_amount);
setup_provider_stake::<T>(&caller, &to_msa, to_msa_amount);
let restake_amount: BalanceOf<T> = from_msa_amount.saturating_sub(10u32.into());

}: _ (RawOrigin::Signed(caller.clone(), ), from_msa, to_msa, restake_amount.into())
}: _ (RawOrigin::Signed(caller.clone(), ), from_msa, to_msa, restake_amount)
verify {
assert_last_event::<T>(Event::<T>::StakingTargetChanged {
account: caller,
Expand All @@ -165,10 +186,11 @@ benchmarks! {

provider_boost {
let caller: T::AccountId = create_funded_account::<T>("boostaccount", SEED, 260u32);
let boost_amount: BalanceOf<T> = 200u32.into(); // enough for 1 Cap boosted
let boost_amount: BalanceOf<T> = T::MinimumStakingAmount::get().saturating_add(1u32.into());
let capacity: BalanceOf<T> = Capacity::<T>::capacity_generated(<T>::RewardsProvider::capacity_boost(boost_amount));
let target = 1;

set_era_and_reward_pool_at_block::<T>(1u32.into(), 1u32.into(), 1_000u32.into());
register_provider::<T>(target, "Foo");

}: _ (RawOrigin::Signed(caller.clone()), target, boost_amount)
Expand Down
2 changes: 1 addition & 1 deletion pallets/capacity/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -541,7 +541,7 @@ pub mod pallet {
/// - [`Error::InvalidTarget`] if `to` does not belong to a registered Provider.
/// - [`Error::MaxRetargetsExceeded`] if origin has reached the maximimum number of retargets for the current RewardEra.
#[pallet::call_index(4)]
#[pallet::weight(T::WeightInfo::unstake())]
#[pallet::weight(T::WeightInfo::change_staking_target())]
pub fn change_staking_target(
origin: OriginFor<T>,
from: MessageSourceId,
Expand Down
1 change: 1 addition & 0 deletions pallets/capacity/src/tests/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ impl StakingRewardsProvider<Test> for TestStakingRewardsProvider {
type RewardEra = TestRewardEra;
type Hash = Hash; // use what's in common_primitives::node

// To reflect new economic model behavior of having a constant RewardPool amount.
fn reward_pool_size(_total_staked: BalanceOf<Test>) -> BalanceOf<Test> {
10_000u64.into()
}
Expand Down
141 changes: 102 additions & 39 deletions pallets/capacity/src/weights.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@
//! Autogenerated weights for pallet_capacity
//!
//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev
//! DATE: 2024-03-06, STEPS: `20`, REPEAT: `10`, LOW RANGE: `[]`, HIGH RANGE: `[]`
//! DATE: 2024-04-25, STEPS: `20`, REPEAT: `10`, LOW RANGE: `[]`, HIGH RANGE: `[]`
//! WORST CASE MAP SIZE: `1000000`
//! HOSTNAME: `benchmark-runner-wc6w8-pv9rm`, CPU: `Intel(R) Xeon(R) Platinum 8375C CPU @ 2.90GHz`
//! HOSTNAME: `UL-Mac`, CPU: `<UNKNOWN>`
//! EXECUTION: , WASM-EXECUTION: Compiled, CHAIN: Some("frequency-bench"), DB CACHE: 1024

// Executed Command:
Expand Down Expand Up @@ -55,7 +55,6 @@ pub trait WeightInfo {
fn unstake() -> Weight;
fn set_epoch_length() -> Weight;
fn change_staking_target() -> Weight;

fn provider_boost() -> Weight;
}

Expand All @@ -80,8 +79,8 @@ impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> {
// Proof Size summary in bytes:
// Measured: `174`
// Estimated: `6249`
// Minimum execution time: 39_050_000 picoseconds.
Weight::from_parts(39_836_000, 6249)
// Minimum execution time: 30_000_000 picoseconds.
Weight::from_parts(31_000_000, 6249)
.saturating_add(T::DbWeight::get().reads(7_u64))
.saturating_add(T::DbWeight::get().writes(4_u64))
}
Expand Down Expand Up @@ -117,6 +116,8 @@ impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> {
}
/// Storage: `Capacity::StakingAccountLedger` (r:1 w:1)
/// Proof: `Capacity::StakingAccountLedger` (`max_values`: None, `max_size`: Some(57), added: 2532, mode: `MaxEncodedLen`)
/// Storage: `Capacity::StakingRewardPool` (r:1 w:1)
/// Proof: `Capacity::StakingRewardPool` (`max_values`: None, `max_size`: Some(60), added: 2535, mode: `MaxEncodedLen`)
/// Storage: `Capacity::UnstakeUnlocks` (r:1 w:1)
/// Proof: `Capacity::UnstakeUnlocks` (`max_values`: None, `max_size`: Some(121), added: 2596, mode: `MaxEncodedLen`)
/// Storage: `Capacity::StakingTargetLedger` (r:1 w:1)
Expand All @@ -125,36 +126,66 @@ impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> {
/// Proof: `Capacity::CapacityLedger` (`max_values`: None, `max_size`: Some(68), added: 2543, mode: `MaxEncodedLen`)
fn unstake() -> Weight {
// Proof Size summary in bytes:
// Measured: `271`
// Measured: `343`
// Estimated: `5071`
// Minimum execution time: 26_198_000 picoseconds.
Weight::from_parts(26_644_000, 5071)
.saturating_add(T::DbWeight::get().reads(4_u64))
.saturating_add(T::DbWeight::get().writes(4_u64))
// Minimum execution time: 23_000_000 picoseconds.
Weight::from_parts(24_000_000, 5071)
.saturating_add(T::DbWeight::get().reads(5_u64))
.saturating_add(T::DbWeight::get().writes(5_u64))
}
/// Storage: `Capacity::EpochLength` (r:0 w:1)
/// Proof: `Capacity::EpochLength` (`max_values`: Some(1), `max_size`: Some(4), added: 499, mode: `MaxEncodedLen`)
fn set_epoch_length() -> Weight {
// Proof Size summary in bytes:
// Measured: `0`
// Estimated: `0`
// Minimum execution time: 6_361_000 picoseconds.
Weight::from_parts(6_550_000, 0)
// Minimum execution time: 5_000_000 picoseconds.
Weight::from_parts(5_000_000, 0)
.saturating_add(T::DbWeight::get().writes(1_u64))
}

/// Storage:
/// Proof:
/// Storage: `Capacity::Retargets` (r:1 w:1)
/// Proof: `Capacity::Retargets` (`max_values`: None, `max_size`: Some(48), added: 2523, mode: `MaxEncodedLen`)
/// Storage: `Msa::ProviderToRegistryEntry` (r:1 w:0)
/// Proof: `Msa::ProviderToRegistryEntry` (`max_values`: None, `max_size`: Some(33), added: 2508, mode: `MaxEncodedLen`)
/// Storage: `Capacity::StakingAccountLedger` (r:1 w:0)
/// Proof: `Capacity::StakingAccountLedger` (`max_values`: None, `max_size`: Some(57), added: 2532, mode: `MaxEncodedLen`)
/// Storage: `Capacity::StakingTargetLedger` (r:2 w:2)
/// Proof: `Capacity::StakingTargetLedger` (`max_values`: None, `max_size`: Some(88), added: 2563, mode: `MaxEncodedLen`)
/// Storage: `Capacity::CapacityLedger` (r:2 w:2)
/// Proof: `Capacity::CapacityLedger` (`max_values`: None, `max_size`: Some(68), added: 2543, mode: `MaxEncodedLen`)
fn change_staking_target() -> Weight {
Weight::from_parts(1_000_000, 0)
.saturating_add(T::DbWeight::get().writes(1_u64))
// Proof Size summary in bytes:
// Measured: `315`
// Estimated: `7601`
// Minimum execution time: 24_000_000 picoseconds.
Weight::from_parts(25_000_000, 7601)
.saturating_add(T::DbWeight::get().reads(7_u64))
.saturating_add(T::DbWeight::get().writes(5_u64))
}

/// Storage:
/// Proof:
/// Storage: `Msa::ProviderToRegistryEntry` (r:1 w:0)
/// Proof: `Msa::ProviderToRegistryEntry` (`max_values`: None, `max_size`: Some(33), added: 2508, mode: `MaxEncodedLen`)
/// Storage: `Capacity::StakingAccountLedger` (r:1 w:1)
/// Proof: `Capacity::StakingAccountLedger` (`max_values`: None, `max_size`: Some(57), added: 2532, mode: `MaxEncodedLen`)
/// Storage: `Capacity::StakingTargetLedger` (r:1 w:1)
/// Proof: `Capacity::StakingTargetLedger` (`max_values`: None, `max_size`: Some(88), added: 2563, mode: `MaxEncodedLen`)
/// Storage: `Capacity::CapacityLedger` (r:1 w:1)
/// Proof: `Capacity::CapacityLedger` (`max_values`: None, `max_size`: Some(68), added: 2543, mode: `MaxEncodedLen`)
/// Storage: `Capacity::StakingRewardPool` (r:1 w:1)
/// Proof: `Capacity::StakingRewardPool` (`max_values`: None, `max_size`: Some(60), added: 2535, mode: `MaxEncodedLen`)
/// Storage: `Capacity::UnstakeUnlocks` (r:1 w:0)
/// Proof: `Capacity::UnstakeUnlocks` (`max_values`: None, `max_size`: Some(121), added: 2596, mode: `MaxEncodedLen`)
/// Storage: `Balances::Freezes` (r:1 w:1)
/// Proof: `Balances::Freezes` (`max_values`: None, `max_size`: Some(85), added: 2560, mode: `MaxEncodedLen`)
/// Storage: `Balances::Locks` (r:1 w:0)
/// Proof: `Balances::Locks` (`max_values`: None, `max_size`: Some(1299), added: 3774, mode: `MaxEncodedLen`)
fn provider_boost() -> Weight {
Weight::from_parts(1_000_000, 0)
.saturating_add(T::DbWeight::get().writes(1_u64))
// Proof Size summary in bytes:
// Measured: `247`
// Estimated: `6249`
// Minimum execution time: 34_000_000 picoseconds.
Weight::from_parts(35_000_000, 6249)
.saturating_add(T::DbWeight::get().reads(8_u64))
.saturating_add(T::DbWeight::get().writes(5_u64))
}
}

Expand Down Expand Up @@ -215,6 +246,8 @@ impl WeightInfo for () {
}
/// Storage: `Capacity::StakingAccountLedger` (r:1 w:1)
/// Proof: `Capacity::StakingAccountLedger` (`max_values`: None, `max_size`: Some(57), added: 2532, mode: `MaxEncodedLen`)
/// Storage: `Capacity::StakingRewardPool` (r:1 w:1)
/// Proof: `Capacity::StakingRewardPool` (`max_values`: None, `max_size`: Some(60), added: 2535, mode: `MaxEncodedLen`)
/// Storage: `Capacity::UnstakeUnlocks` (r:1 w:1)
/// Proof: `Capacity::UnstakeUnlocks` (`max_values`: None, `max_size`: Some(121), added: 2596, mode: `MaxEncodedLen`)
/// Storage: `Capacity::StakingTargetLedger` (r:1 w:1)
Expand All @@ -223,35 +256,65 @@ impl WeightInfo for () {
/// Proof: `Capacity::CapacityLedger` (`max_values`: None, `max_size`: Some(68), added: 2543, mode: `MaxEncodedLen`)
fn unstake() -> Weight {
// Proof Size summary in bytes:
// Measured: `271`
// Measured: `343`
// Estimated: `5071`
// Minimum execution time: 26_198_000 picoseconds.
Weight::from_parts(26_644_000, 5071)
.saturating_add(RocksDbWeight::get().reads(4_u64))
.saturating_add(RocksDbWeight::get().writes(4_u64))
// Minimum execution time: 23_000_000 picoseconds.
Weight::from_parts(24_000_000, 5071)
.saturating_add(RocksDbWeight::get().reads(5_u64))
.saturating_add(RocksDbWeight::get().writes(5_u64))
}
/// Storage: `Capacity::EpochLength` (r:0 w:1)
/// Proof: `Capacity::EpochLength` (`max_values`: Some(1), `max_size`: Some(4), added: 499, mode: `MaxEncodedLen`)
fn set_epoch_length() -> Weight {
// Proof Size summary in bytes:
// Measured: `0`
// Estimated: `0`
// Minimum execution time: 6_361_000 picoseconds.
Weight::from_parts(6_550_000, 0)
// Minimum execution time: 5_000_000 picoseconds.
Weight::from_parts(5_000_000, 0)
.saturating_add(RocksDbWeight::get().writes(1_u64))
}

/// Storage:
/// Proof:
/// Storage: `Capacity::Retargets` (r:1 w:1)
/// Proof: `Capacity::Retargets` (`max_values`: None, `max_size`: Some(48), added: 2523, mode: `MaxEncodedLen`)
/// Storage: `Msa::ProviderToRegistryEntry` (r:1 w:0)
/// Proof: `Msa::ProviderToRegistryEntry` (`max_values`: None, `max_size`: Some(33), added: 2508, mode: `MaxEncodedLen`)
/// Storage: `Capacity::StakingAccountLedger` (r:1 w:0)
/// Proof: `Capacity::StakingAccountLedger` (`max_values`: None, `max_size`: Some(57), added: 2532, mode: `MaxEncodedLen`)
/// Storage: `Capacity::StakingTargetLedger` (r:2 w:2)
/// Proof: `Capacity::StakingTargetLedger` (`max_values`: None, `max_size`: Some(88), added: 2563, mode: `MaxEncodedLen`)
/// Storage: `Capacity::CapacityLedger` (r:2 w:2)
/// Proof: `Capacity::CapacityLedger` (`max_values`: None, `max_size`: Some(68), added: 2543, mode: `MaxEncodedLen`)
fn change_staking_target() -> Weight {
Weight::from_parts(1_000_000, 0)
.saturating_add(RocksDbWeight::get().writes(1_u64))
// Proof Size summary in bytes:
// Measured: `315`
// Estimated: `7601`
// Minimum execution time: 24_000_000 picoseconds.
Weight::from_parts(25_000_000, 7601)
.saturating_add(RocksDbWeight::get().reads(7_u64))
.saturating_add(RocksDbWeight::get().writes(5_u64))
}

/// Storage:
/// Proof:
/// Storage: `Msa::ProviderToRegistryEntry` (r:1 w:0)
/// Proof: `Msa::ProviderToRegistryEntry` (`max_values`: None, `max_size`: Some(33), added: 2508, mode: `MaxEncodedLen`)
/// Storage: `Capacity::StakingAccountLedger` (r:1 w:1)
/// Proof: `Capacity::StakingAccountLedger` (`max_values`: None, `max_size`: Some(57), added: 2532, mode: `MaxEncodedLen`)
/// Storage: `Capacity::StakingTargetLedger` (r:1 w:1)
/// Proof: `Capacity::StakingTargetLedger` (`max_values`: None, `max_size`: Some(88), added: 2563, mode: `MaxEncodedLen`)
/// Storage: `Capacity::CapacityLedger` (r:1 w:1)
/// Proof: `Capacity::CapacityLedger` (`max_values`: None, `max_size`: Some(68), added: 2543, mode: `MaxEncodedLen`)
/// Storage: `Capacity::StakingRewardPool` (r:1 w:1)
/// Proof: `Capacity::StakingRewardPool` (`max_values`: None, `max_size`: Some(60), added: 2535, mode: `MaxEncodedLen`)
/// Storage: `Capacity::UnstakeUnlocks` (r:1 w:0)
/// Proof: `Capacity::UnstakeUnlocks` (`max_values`: None, `max_size`: Some(121), added: 2596, mode: `MaxEncodedLen`)
/// Storage: `Balances::Freezes` (r:1 w:1)
/// Proof: `Balances::Freezes` (`max_values`: None, `max_size`: Some(85), added: 2560, mode: `MaxEncodedLen`)
/// Storage: `Balances::Locks` (r:1 w:0)
/// Proof: `Balances::Locks` (`max_values`: None, `max_size`: Some(1299), added: 3774, mode: `MaxEncodedLen`)
fn provider_boost() -> Weight {
Weight::from_parts(1_000_000, 0)
.saturating_add(RocksDbWeight::get().writes(1_u64))
// Proof Size summary in bytes:
// Measured: `247`
// Estimated: `6249`
// Minimum execution time: 34_000_000 picoseconds.
Weight::from_parts(35_000_000, 6249)
.saturating_add(RocksDbWeight::get().reads(8_u64))
.saturating_add(RocksDbWeight::get().writes(5_u64))
}
}

0 comments on commit 0b5d184

Please sign in to comment.