Skip to content

Commit

Permalink
minor cleanups
Browse files Browse the repository at this point in the history
  • Loading branch information
ipapandinas committed Feb 18, 2025
1 parent f371a77 commit 662bc6a
Showing 1 changed file with 14 additions and 16 deletions.
30 changes: 14 additions & 16 deletions pallets/dapp-staking/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2707,29 +2707,29 @@ pub mod pallet {
/// If no progress is made, `Err(_)` is returned.
pub fn do_update(weight_limit: Weight) -> Result<Weight, Weight> {
// Find out if update is still in progress
let init_bonus_update_state = ActiveBonusUpdateState::<T>::get();
let mut bonus_update_state = ActiveBonusUpdateState::<T>::get();
let mut consumed_weight = T::DbWeight::get().reads(1);

if init_bonus_update_state == BonusUpdateStateFor::<T>::Finished {
if bonus_update_state == BonusUpdateStateFor::<T>::Finished {
log::trace!(
target: LOG_TARGET,
"Update has finished, skipping any action."
);
return Err(consumed_weight);
}

let mut bonus_update_state = init_bonus_update_state.clone();
let mut entries_updated = 0u32;

let mut iter =
if let BonusUpdateStateFor::<T>::InProgress(last_key_pair) = &bonus_update_state {
StakerInfo::<T>::iter_from(StakerInfo::<T>::hashed_key_for(
last_key_pair.0.clone(),
last_key_pair.1.clone(),
))
} else {
StakerInfo::<T>::iter()
};
let mut iter = if let BonusUpdateStateFor::<T>::InProgress((account, contract)) =
&bonus_update_state
{
StakerInfo::<T>::iter_from(StakerInfo::<T>::hashed_key_for(
account.clone(),
contract.clone(),
))
} else {
StakerInfo::<T>::iter()
};

let weight_margin = Self::update_weight_margin();
while weight_limit
Expand All @@ -2750,10 +2750,8 @@ pub mod pallet {
}
}

if bonus_update_state != init_bonus_update_state {
consumed_weight.saturating_accrue(T::DbWeight::get().writes(1));
ActiveBonusUpdateState::<T>::put(bonus_update_state.clone());
}
consumed_weight.saturating_accrue(T::DbWeight::get().writes(1));
ActiveBonusUpdateState::<T>::put(bonus_update_state.clone());

if bonus_update_state == crate::types::BonusUpdateStateFor::<T>::Finished {
consumed_weight.saturating_accrue(T::DbWeight::get().reads_writes(1, 2));
Expand Down

0 comments on commit 662bc6a

Please sign in to comment.