diff --git a/pallets/dapp-staking-v3/src/benchmarking/mod.rs b/pallets/dapp-staking-v3/src/benchmarking/mod.rs index ad8d21d034..238c3e3a20 100644 --- a/pallets/dapp-staking-v3/src/benchmarking/mod.rs +++ b/pallets/dapp-staking-v3/src/benchmarking/mod.rs @@ -840,6 +840,12 @@ mod benchmarks { // Register & stake contracts, just so we don't have empty stakes. prepare_contracts_for_tier_assignment::(max_number_of_contracts::()); + // 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::::get().period_number() + T::RewardRetentionInPeriods::get(); + force_advance_to_period::(period_before_expiry_starts); + // Advance to build&earn subperiod force_advance_to_next_subperiod::(); let snapshot_state = ActiveProtocolState::::get(); @@ -853,7 +859,7 @@ mod benchmarks { ); run_to_block::(ActiveProtocolState::::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::::get().subperiod(), Subperiod::BuildAndEarn @@ -867,6 +873,8 @@ mod benchmarks { DappStaking::::on_finalize(new_era_start_block - 1); System::::set_block_number(new_era_start_block); + let pre_cleanup_marker = HistoryCleanupMarker::::get(); + #[block] { DappStaking::::era_and_period_handler(new_era_start_block, TierAssignment::Dummy); @@ -880,6 +888,9 @@ mod benchmarks { ActiveProtocolState::::get().period_number(), snapshot_state.period_number() + 1, ); + assert!( + HistoryCleanupMarker::::get().oldest_valid_era > pre_cleanup_marker.oldest_valid_era + ); } #[benchmark] diff --git a/pallets/dapp-staking-v3/src/benchmarking/utils.rs b/pallets/dapp-staking-v3/src/benchmarking/utils.rs index 5226a8d61e..81a788da4b 100644 --- a/pallets/dapp-staking-v3/src/benchmarking/utils.rs +++ b/pallets/dapp-staking-v3/src/benchmarking/utils.rs @@ -91,6 +91,14 @@ pub(super) fn force_advance_to_next_period() { } } +/// Advance to the specified period, using the `force` approach. +pub(super) fn force_advance_to_period(period: PeriodNumber) { + assert!(period >= ActiveProtocolState::::get().period_number()); + while ActiveProtocolState::::get().period_number() < period { + force_advance_to_next_subperiod::(); + } +} + /// Use the `force` approach to advance to the next subperiod immediately in the next block. pub(super) fn force_advance_to_next_subperiod() { assert_ok!(DappStaking::::force(