Remove all stale on_runtime_upgrade hooks in the runtime (#10650)

* Remove all stale on_runtime_upgrade hooks in the runtime

* add docs

* cleanup

* fix warn

* fix more warnings

* fix offence test

* overwrite the damn UItest
This commit is contained in:
Kian Paimani
2022-01-19 20:58:47 +01:00
committed by GitHub
parent c8c46fea96
commit 1344e43d2d
11 changed files with 28 additions and 80 deletions
+2 -24
View File
@@ -45,13 +45,14 @@
#![cfg_attr(not(feature = "std"), no_std)]
mod benchmarking;
mod migrations;
#[cfg(test)]
mod mock;
#[cfg(test)]
mod tests;
mod vesting_info;
pub mod migrations;
pub mod weights;
use codec::{Decode, Encode, MaxEncodedLen};
@@ -179,29 +180,6 @@ pub mod pallet {
#[pallet::hooks]
impl<T: Config> Hooks<BlockNumberFor<T>> for Pallet<T> {
#[cfg(feature = "try-runtime")]
fn pre_upgrade() -> Result<(), &'static str> {
if StorageVersion::<T>::get() == Releases::V0 {
migrations::v1::pre_migrate::<T>()
} else {
Ok(())
}
}
fn on_runtime_upgrade() -> Weight {
if StorageVersion::<T>::get() == Releases::V0 {
StorageVersion::<T>::put(Releases::V1);
migrations::v1::migrate::<T>().saturating_add(T::DbWeight::get().reads_writes(1, 1))
} else {
T::DbWeight::get().reads(1)
}
}
#[cfg(feature = "try-runtime")]
fn post_upgrade() -> Result<(), &'static str> {
migrations::v1::post_migrate::<T>()
}
fn integrity_test() {
assert!(T::MAX_VESTING_SCHEDULES > 0, "`MaxVestingSchedules` must ge greater than 0");
}
+4 -4
View File
@@ -20,11 +20,11 @@
use super::*;
// Migration from single schedule to multiple schedules.
pub(crate) mod v1 {
pub mod v1 {
use super::*;
#[cfg(feature = "try-runtime")]
pub(crate) fn pre_migrate<T: Config>() -> Result<(), &'static str> {
pub fn pre_migrate<T: Config>() -> Result<(), &'static str> {
assert!(StorageVersion::<T>::get() == Releases::V0, "Storage version too high.");
log::debug!(
@@ -37,7 +37,7 @@ pub(crate) mod v1 {
/// Migrate from single schedule to multi schedule storage.
/// WARNING: This migration will delete schedules if `MaxVestingSchedules < 1`.
pub(crate) fn migrate<T: Config>() -> Weight {
pub fn migrate<T: Config>() -> Weight {
let mut reads_writes = 0;
Vesting::<T>::translate::<VestingInfo<BalanceOf<T>, T::BlockNumber>, _>(
@@ -65,7 +65,7 @@ pub(crate) mod v1 {
}
#[cfg(feature = "try-runtime")]
pub(crate) fn post_migrate<T: Config>() -> Result<(), &'static str> {
pub fn post_migrate<T: Config>() -> Result<(), &'static str> {
assert_eq!(StorageVersion::<T>::get(), Releases::V1);
for (_key, schedules) in Vesting::<T>::iter() {