Skip to content

Commit

Permalink
Remove redundant storage item
Browse files Browse the repository at this point in the history
  • Loading branch information
Dinonard committed Dec 20, 2023
1 parent 0bd6338 commit b853cc9
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 36 deletions.
1 change: 0 additions & 1 deletion pallets/dapp-staking-v3/src/benchmarking/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,6 @@ pub(super) fn initial_config<T: Config>() {

StaticTierParams::<T>::put(tier_params);
TierConfig::<T>::put(init_tier_config.clone());
NextTierConfig::<T>::put(init_tier_config);
}

/// Maximum number of contracts that 'makes sense' - considers both contract number limit & number of slots.
Expand Down
12 changes: 1 addition & 11 deletions pallets/dapp-staking-v3/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -431,11 +431,6 @@ pub mod pallet {
pub type StaticTierParams<T: Config> =
StorageValue<_, TierParameters<T::NumberOfTiers>, ValueQuery>;

/// Tier configuration to be used during the newly started period
#[pallet::storage]
pub type NextTierConfig<T: Config> =
StorageValue<_, TiersConfiguration<T::NumberOfTiers>, ValueQuery>;

/// Tier configuration user for current & preceding eras.
#[pallet::storage]
pub type TierConfig<T: Config> =
Expand Down Expand Up @@ -518,7 +513,6 @@ pub mod pallet {
ActiveProtocolState::<T>::put(protocol_state);
StaticTierParams::<T>::put(tier_params);
TierConfig::<T>::put(tier_config.clone());
NextTierConfig::<T>::put(tier_config);
}
}

Expand Down Expand Up @@ -1739,10 +1733,6 @@ pub mod pallet {

era_info.migrate_to_next_era(Some(protocol_state.subperiod()));

// Update tier configuration to be used when calculating rewards for the upcoming eras
let next_tier_config = NextTierConfig::<T>::take();
TierConfig::<T>::put(next_tier_config);

consumed_weight
.saturating_accrue(T::WeightInfo::on_initialize_voting_to_build_and_earn());

Expand Down Expand Up @@ -1813,7 +1803,7 @@ pub mod pallet {
let average_price = T::NativePriceProvider::average_price();
let new_tier_config =
TierConfig::<T>::get().calculate_new(average_price, &tier_params);
NextTierConfig::<T>::put(new_tier_config);
TierConfig::<T>::put(new_tier_config);

consumed_weight.saturating_accrue(
T::WeightInfo::on_initialize_build_and_earn_to_voting(),
Expand Down
1 change: 0 additions & 1 deletion pallets/dapp-staking-v3/src/test/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,6 @@ impl ExtBuilder {

pallet_dapp_staking::StaticTierParams::<Test>::put(tier_params);
pallet_dapp_staking::TierConfig::<Test>::put(init_tier_config.clone());
pallet_dapp_staking::NextTierConfig::<Test>::put(init_tier_config);

DappStaking::on_initialize(System::block_number());
});
Expand Down
27 changes: 4 additions & 23 deletions pallets/dapp-staking-v3/src/test/testing_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use crate::types::*;
use crate::{
pallet::Config, ActiveProtocolState, ContractStake, CurrentEraInfo, DAppId, DAppTiers,
EraRewards, Event, FreezeReason, HistoryCleanupMarker, IntegratedDApps, Ledger, NextDAppId,
NextTierConfig, PeriodEnd, PeriodEndInfo, StakerInfo, TierConfig,
PeriodEnd, PeriodEndInfo, StakerInfo,
};

use frame_support::{
Expand Down Expand Up @@ -57,8 +57,6 @@ pub(crate) struct MemorySnapshot {
era_rewards: HashMap<EraNumber, EraRewardSpan<<Test as Config>::EraRewardSpanLength>>,
period_end: HashMap<PeriodNumber, PeriodEndInfo>,
dapp_tiers: HashMap<EraNumber, DAppTierRewardsFor<Test>>,
tier_config: TiersConfiguration<<Test as Config>::NumberOfTiers>,
next_tier_config: TiersConfiguration<<Test as Config>::NumberOfTiers>,
}

impl MemorySnapshot {
Expand All @@ -77,8 +75,6 @@ impl MemorySnapshot {
era_rewards: EraRewards::<Test>::iter().collect(),
period_end: PeriodEnd::<Test>::iter().collect(),
dapp_tiers: DAppTiers::<Test>::iter().collect(),
tier_config: TierConfig::<Test>::get(),
next_tier_config: NextTierConfig::<Test>::get(),
}
}

Expand Down Expand Up @@ -1272,22 +1268,7 @@ pub(crate) fn assert_block_bump(pre_snapshot: &MemorySnapshot) {
);
}

// 3. Verify tier config
match pre_protoc_state.subperiod() {
Subperiod::Voting => {
assert!(!NextTierConfig::<Test>::exists());
assert_eq!(post_snapshot.tier_config, pre_snapshot.next_tier_config);
}
Subperiod::BuildAndEarn if is_new_subperiod => {
assert!(NextTierConfig::<Test>::exists());
assert_eq!(post_snapshot.tier_config, pre_snapshot.tier_config);
}
_ => {
assert_eq!(post_snapshot.tier_config, pre_snapshot.tier_config);
}
}

// 4. Verify era reward
// 3. Verify era reward
let era_span_index = DappStaking::era_reward_span_index(pre_protoc_state.era);
let maybe_pre_era_reward_span = pre_snapshot.era_rewards.get(&era_span_index);
let post_era_reward_span = post_snapshot
Expand Down Expand Up @@ -1318,7 +1299,7 @@ pub(crate) fn assert_block_bump(pre_snapshot: &MemorySnapshot) {
"Total staked amount must be equal to total amount staked at the end of the era."
);

// 5. Verify period end
// 4. Verify period end
if is_new_subperiod && pre_protoc_state.subperiod() == Subperiod::BuildAndEarn {
let period_end_info = post_snapshot.period_end[&pre_protoc_state.period_number()];
assert_eq!(
Expand All @@ -1329,7 +1310,7 @@ pub(crate) fn assert_block_bump(pre_snapshot: &MemorySnapshot) {
);
}

// 6. Verify event(s)
// 5. Verify event(s)
if is_new_subperiod {
let events = dapp_staking_events();
assert!(
Expand Down

0 comments on commit b853cc9

Please sign in to comment.