Skip to content
71 changes: 2 additions & 69 deletions pallets/dapp-staking/src/benchmarking/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use super::{Pallet as DappStaking, *};
use astar_primitives::Balance;
use frame_benchmarking::v2::*;

use frame_support::{assert_ok, migrations::SteppedMigration, weights::WeightMeter};
use frame_support::assert_ok;
use frame_system::{Pallet as System, RawOrigin};
use sp_std::prelude::*;

Expand Down Expand Up @@ -999,7 +999,7 @@ mod benchmarks {
let snapshot_state = ActiveProtocolState::<T>::get();

// Advance over to the last era of the subperiod, and then again to the last block of that era.
advance_to_era::<T>(
force_advance_to_era::<T>(
ActiveProtocolState::<T>::get()
.period_info
.next_subperiod_start_era
Expand Down Expand Up @@ -1180,73 +1180,6 @@ mod benchmarks {
);
}

/// Benchmark a single step of mbm migration.
#[benchmark]
fn step() {
let alice: T::AccountId = account("alice", 0, 1);

Ledger::<T>::set(
&alice,
AccountLedger {
locked: 1000,
unlocking: vec![
UnlockingChunk {
amount: 100,
unlock_block: 5,
},
UnlockingChunk {
amount: 100,
unlock_block: 20,
},
]
.try_into()
.unwrap(),
staked: Default::default(),
staked_future: None,
contract_stake_count: 0,
},
);
CurrentEraInfo::<T>::put(EraInfo {
total_locked: 1000,
unlocking: 200,
current_stake_amount: Default::default(),
next_stake_amount: Default::default(),
});

System::<T>::set_block_number(10u32.into());
let mut meter = WeightMeter::new();

#[block]
{
crate::migration::LazyMigration::<T, weights::SubstrateWeight<T>>::step(
None, &mut meter,
)
.unwrap();
}

assert_eq!(
Ledger::<T>::get(&alice),
AccountLedger {
locked: 1000,
unlocking: vec![
UnlockingChunk {
amount: 100,
unlock_block: 5, // already unlocked
},
UnlockingChunk {
amount: 100,
unlock_block: 30, // double remaining blocks
},
]
.try_into()
.unwrap(),
staked: Default::default(),
staked_future: None,
contract_stake_count: 0,
}
);
}

#[benchmark]
fn set_static_tier_params() {
initial_config::<T>();
Expand Down
49 changes: 23 additions & 26 deletions pallets/dapp-staking/src/benchmarking/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,10 @@

use super::{Pallet as DappStaking, *};

use astar_primitives::{dapp_staking::STANDARD_TIER_SLOTS_ARGS, Balance};
use astar_primitives::{dapp_staking::FIXED_TIER_SLOTS_ARGS, Balance};

use frame_system::Pallet as System;
use sp_arithmetic::Permill;

/// Run to the specified block number.
/// Function assumes first block has been initialized.
Expand All @@ -42,7 +43,7 @@ pub(super) fn run_for_blocks<T: Config>(n: BlockNumberFor<T>) {
/// Advance blocks until the specified era has been reached.
///
/// Function has no effect if era is already passed.
pub(super) fn advance_to_era<T: Config>(era: EraNumber) {
pub(super) fn _advance_to_era<T: Config>(era: EraNumber) {
assert!(era >= ActiveProtocolState::<T>::get().era);
while ActiveProtocolState::<T>::get().era < era {
run_for_blocks::<T>(One::one());
Expand All @@ -65,7 +66,7 @@ pub(super) fn force_advance_to_era<T: Config>(era: EraNumber) {

/// Advance blocks until next era has been reached.
pub(super) fn _advance_to_next_era<T: Config>() {
advance_to_era::<T>(ActiveProtocolState::<T>::get().era + 1);
_advance_to_era::<T>(ActiveProtocolState::<T>::get().era + 1);
}

/// Advance to next era, in the next block using the `force` approach.
Expand Down Expand Up @@ -115,7 +116,7 @@ pub(super) const UNIT: Balance = 1_000_000_000_000_000_000;
pub(super) const MIN_TIER_THRESHOLD: Balance = 10 * UNIT;

/// Number of slots in the tier system.
pub(super) const NUMBER_OF_SLOTS: u32 = 100;
pub(super) const NUMBER_OF_SLOTS: u32 = 16;

/// Random seed.
pub(super) const SEED: u32 = 9000;
Expand Down Expand Up @@ -163,41 +164,37 @@ pub(super) fn initial_config<T: Config>() {
pub(super) fn init_tier_settings<T: Config>() {
let tier_params = TierParameters::<T::NumberOfTiers> {
reward_portion: BoundedVec::try_from(vec![
Permill::from_percent(40),
Permill::from_percent(0),
Permill::from_percent(70),
Permill::from_percent(30),
Permill::from_percent(20),
Permill::from_percent(10),
Permill::from_percent(0),
])
.unwrap(),
slot_distribution: BoundedVec::try_from(vec![
Permill::from_percent(10),
Permill::from_percent(20),
Permill::from_percent(30),
Permill::from_percent(40),
Permill::from_percent(0),
Permill::from_parts(375_000), // 37.5%
Permill::from_parts(625_000), // 62.5%
Permill::from_percent(0),
])
.unwrap(),
tier_thresholds: BoundedVec::try_from(vec![
TierThreshold::DynamicPercentage {
percentage: Perbill::from_parts(11_112_000), // 1.1112%
minimum_required_percentage: Perbill::from_parts(8_889_000), // 0.8889%
maximum_possible_percentage: Perbill::from_percent(100),
TierThreshold::FixedPercentage {
required_percentage: Perbill::from_parts(23_200_000), // 2.32%
},
TierThreshold::DynamicPercentage {
percentage: Perbill::from_parts(5_556_000), // 0.5556%
minimum_required_percentage: Perbill::from_parts(4_400_000), // 0.44%
maximum_possible_percentage: Perbill::from_percent(100),
TierThreshold::FixedPercentage {
required_percentage: Perbill::from_parts(9_300_000), // 0.93%
},
TierThreshold::DynamicPercentage {
percentage: Perbill::from_parts(2_223_000), // 0.2223%
minimum_required_percentage: Perbill::from_parts(2_223_000), // 0.2223%
maximum_possible_percentage: Perbill::from_percent(100),
TierThreshold::FixedPercentage {
required_percentage: Perbill::from_parts(3_500_000), // 0.35%
},
// Tier 3: unreachable dummy
TierThreshold::FixedPercentage {
required_percentage: Perbill::from_parts(1_667_000), // 0.1667%
required_percentage: Perbill::from_parts(0), // 0%
},
])
.unwrap(),
slot_number_args: STANDARD_TIER_SLOTS_ARGS,
slot_number_args: FIXED_TIER_SLOTS_ARGS,
tier_rank_multipliers: BoundedVec::try_from(vec![0, 24_000, 46_700, 0]).unwrap(),
};

let total_issuance = 1000 * MIN_TIER_THRESHOLD;
Expand All @@ -212,7 +209,7 @@ pub(super) fn init_tier_settings<T: Config>() {
// Init tier config, based on the initial params
let init_tier_config =
TiersConfiguration::<T::NumberOfTiers, T::TierSlots, T::BaseNativeCurrencyPrice> {
slots_per_tier: BoundedVec::try_from(vec![10, 20, 30, 40]).unwrap(),
slots_per_tier: BoundedVec::try_from(vec![0, 6, 10, 0]).unwrap(),
reward_portion: tier_params.reward_portion.clone(),
tier_thresholds,
_phantom: Default::default(),
Expand Down
Loading
Loading