Skip to content

Commit

Permalink
fix storage mutation for aggregate node rewards
Browse files Browse the repository at this point in the history
  • Loading branch information
Raid5594 committed Jul 13, 2023
1 parent 63f5e4c commit 655061d
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions pallets/ddc-staking/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ pub mod pallet {
#[pallet::storage]
#[pallet::getter(fn rewards)]
pub type Rewards<T: Config> =
StorageMap<_, Blake2_128Concat, T::AccountId, BalanceOf<T>>;
StorageMap<_, Blake2_128Concat, T::AccountId, BalanceOf<T>, ValueQuery>;

/// The current era index.
///
Expand Down Expand Up @@ -824,11 +824,10 @@ pub mod pallet {
reward,
ExistenceRequirement::AllowDeath,
)?; // ToDo: all success or noop
let mut total_rewards: BalanceOf<T> = Self::rewards(&stash).unwrap();
total_rewards += reward;
log::info!("Total rewards to be inserted: {:?}", total_rewards.clone());

<Rewards<T>>::insert(&stash, total_rewards);
Rewards::<T>::mutate(&stash, |current_balance| {
*current_balance += reward;
});
log::info!("Total rewards to be inserted: {:?}", Self::rewards(&stash));
}
Self::deposit_event(Event::<T>::PayoutNodes(era, era_reward_points.clone() ,price_per_byte));
log::info!("Payout event executed");
Expand Down

0 comments on commit 655061d

Please sign in to comment.