Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 0 additions & 14 deletions frame/reward/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,14 +96,6 @@ pub mod pallet {
type WeightInfo: WeightInfo;
}

// #[pallet::hooks]
// impl<T: Config> Hooks<BlockNumberFor<T>> for Pallet<T> {
// fn on_runtime_upgrade() -> frame_support::weights::Weight {
// migrate_to_v1::<T>()
// }

// }

/// The era reward which are distributed among the validator and nominator
#[pallet::storage]
#[pallet::getter(fn total_rewards)]
Expand All @@ -122,12 +114,6 @@ pub mod pallet {
pub type ValidatorRewardAccounts<T: Config> =
StorageMap<_, Blake2_128Concat, T::AccountId, T::Balance, ValueQuery>;

/// Specifics regarding the rewards distributed within the designated era of the nominator
#[pallet::storage]
#[pallet::getter(fn nominator_reward_accounts)]
pub type NominatorRewardAccounts<T: Config> =
StorageMap<_, Blake2_128Concat, T::AccountId, T::Balance, ValueQuery>;

/// Storage that tracks the rewards earned by nominators for each validator
#[pallet::storage]
#[pallet::getter(fn nominator_earning_accounts)]
Expand Down
21 changes: 1 addition & 20 deletions frame/reward/src/migration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,24 +23,7 @@ pub mod v1 {
);

if onchain_version == 0 {
let mut count = 0;
for (nominator_id, balance) in NominatorRewardAccounts::<T>::iter() {
if let Some(nominations) =
pallet_staking::Nominators::<T>::get(nominator_id.clone())
{
if let Some(validator) = nominations.targets.first() {
NominatorEarningsAccount::<T>::mutate(
validator,
nominator_id.clone(),
|earlier_reward| {
*earlier_reward += balance;
},
)
}
NominatorRewardAccounts::<T>::remove(nominator_id.clone());
}
count += 1;
}
let count = 0;
StorageVersion::new(1).put::<Pallet<T>>();
log!(Level::Info, "reward v1 applied successfully");
T::DbWeight::get().reads_writes((count as u64) + 1, (count as u64) + 1)
Expand All @@ -61,8 +44,6 @@ pub mod v1 {
let prev_count_old_storage: u32 = Decode::decode(&mut prev_count.as_slice()).expect(
"the state parameter should be something that was generated by pre_upgrade",
);
let post_count_old_storage = NominatorRewardAccounts::<T>::iter().count() as u32;
ensure!(post_count_old_storage == 0, "count should be 0 in NominatorRewardAccounts");

// compare old storage key length (NominatorRewardAccounts) and new storage key length
// (NominatorEarningsAccount)
Expand Down