Skip to content

Commit

Permalink
Finished benchmarks
Browse files Browse the repository at this point in the history
  • Loading branch information
Dinonard committed Jan 16, 2024
1 parent 2051546 commit 2674d57
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
13 changes: 12 additions & 1 deletion pallets/dapp-staking-v3/src/benchmarking/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -840,6 +840,12 @@ mod benchmarks {
// Register & stake contracts, just so we don't have empty stakes.
prepare_contracts_for_tier_assignment::<T>(max_number_of_contracts::<T>());

// Force advance enough periods into the future so we can ensure that history
// cleanup marker will be updated on the next period change.
let period_before_expiry_starts =
ActiveProtocolState::<T>::get().period_number() + T::RewardRetentionInPeriods::get();
force_advance_to_period::<T>(period_before_expiry_starts);

// Advance to build&earn subperiod
force_advance_to_next_subperiod::<T>();
let snapshot_state = ActiveProtocolState::<T>::get();
Expand All @@ -853,7 +859,7 @@ mod benchmarks {
);
run_to_block::<T>(ActiveProtocolState::<T>::get().next_era_start - 1);

// Some sanity checks, we should still be in the build&earn subperiod, and in the first period.
// Some sanity checks, we should still be in the build&earn subperiod, and in the same period as when snapshot was taken.
assert_eq!(
ActiveProtocolState::<T>::get().subperiod(),
Subperiod::BuildAndEarn
Expand All @@ -867,6 +873,8 @@ mod benchmarks {
DappStaking::<T>::on_finalize(new_era_start_block - 1);
System::<T>::set_block_number(new_era_start_block);

let pre_cleanup_marker = HistoryCleanupMarker::<T>::get();

#[block]
{
DappStaking::<T>::era_and_period_handler(new_era_start_block, TierAssignment::Dummy);
Expand All @@ -880,6 +888,9 @@ mod benchmarks {
ActiveProtocolState::<T>::get().period_number(),
snapshot_state.period_number() + 1,
);
assert!(
HistoryCleanupMarker::<T>::get().oldest_valid_era > pre_cleanup_marker.oldest_valid_era
);
}

#[benchmark]
Expand Down
8 changes: 8 additions & 0 deletions pallets/dapp-staking-v3/src/benchmarking/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,14 @@ pub(super) fn force_advance_to_next_period<T: Config>() {
}
}

/// Advance to the specified period, using the `force` approach.
pub(super) fn force_advance_to_period<T: Config>(period: PeriodNumber) {
assert!(period >= ActiveProtocolState::<T>::get().period_number());
while ActiveProtocolState::<T>::get().period_number() < period {
force_advance_to_next_subperiod::<T>();
}
}

/// Use the `force` approach to advance to the next subperiod immediately in the next block.
pub(super) fn force_advance_to_next_subperiod<T: Config>() {
assert_ok!(DappStaking::<T>::force(
Expand Down

0 comments on commit 2674d57

Please sign in to comment.