Skip to content

Commit

Permalink
migration fully tested
Browse files Browse the repository at this point in the history
  • Loading branch information
ipapandinas committed Feb 17, 2025
1 parent dfb0a75 commit 7df699a
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
11 changes: 6 additions & 5 deletions pallets/dapp-staking/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2719,11 +2719,12 @@ pub mod pallet {
))
} else {
// Enable maintenance mode on the first run
// ActiveProtocolState::<T>::mutate(|state| {
// state.maintenance = true;
// });
// log::warn!("Maintenance mode enabled.");
// consumed_weight.saturating_add(T::DbWeight::get().reads_writes(1, 1));
// Likely to be already set in the runtime upgrade migration
ActiveProtocolState::<T>::mutate(|state| {
state.maintenance = true;
});
log::warn!("Maintenance mode enabled.");
consumed_weight.saturating_add(T::DbWeight::get().reads_writes(1, 2));
StakerInfo::<T>::iter()
};

Expand Down
12 changes: 12 additions & 0 deletions pallets/dapp-staking/src/migration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,10 @@ mod v9 {
"Out of {} already existing stakers are expected to have their bonus updated.",
v8::StakerInfo::<T>::iter().count(),
);
assert!(
!ActiveProtocolState::<T>::get().maintenance,
"Maintenance mode must be disabled before the runtime upgrade."
);
Ok(Vec::new())
}

Expand All @@ -125,11 +129,19 @@ mod v9 {
Pallet::<T>::on_chain_storage_version() >= 9,
"dapp-staking::migration::v9: wrong storage version"
);
assert!(
!ActiveProtocolState::<T>::get().maintenance,
"Maintenance mode must be disabled after the successful runtime upgrade."
);

let new_default_bonus_status = *crate::types::BonusStatusWrapperFor::<T>::default();
for (_, _, staking_info) in StakerInfo::<T>::iter() {
assert_eq!(staking_info.bonus_status, new_default_bonus_status);
}
log::info!(
target: LOG_TARGET,
"All entries updated to new_default_bonus_status {}", new_default_bonus_status,
);

Ok(())
}
Expand Down

0 comments on commit 7df699a

Please sign in to comment.