Migration hook fixes (#14174)

* fix offences pre_upgrade hook

* identify source of ensure! failures

* stop migration hooks breaking post migration

* add childbounties storage version

* init child bounties version to zero

* Update frame/child-bounties/src/lib.rs

Co-authored-by: Bastian Köcher <git@kchr.de>

* remove redundant preupgrade version checks

* update test

* fix nom pools v3 migration

* kick ci

* kick ci

---------

Co-authored-by: Bastian Köcher <git@kchr.de>
This commit is contained in:
Liam Aharon
2023-05-24 02:01:51 +10:00
committed by GitHub
parent b6a2948461
commit 078699c354
2 changed files with 41 additions and 43 deletions
+4 -10
View File
@@ -54,9 +54,6 @@ pub mod v1 {
impl<T: Config> OnRuntimeUpgrade for MigrateToV1<T> {
#[cfg(feature = "try-runtime")]
fn pre_upgrade() -> Result<Vec<u8>, TryRuntimeError> {
let onchain = Pallet::<T>::on_chain_storage_version();
ensure!(onchain < 1, "pallet_offences::MigrateToV1 migration can be deleted");
log::info!(
target: LOG_TARGET,
"Number of reports to refund and delete: {}",
@@ -67,19 +64,16 @@ pub mod v1 {
}
fn on_runtime_upgrade() -> Weight {
let onchain = Pallet::<T>::on_chain_storage_version();
if onchain > 0 {
if Pallet::<T>::on_chain_storage_version() > 0 {
log::info!(target: LOG_TARGET, "pallet_offences::MigrateToV1 should be removed");
return T::DbWeight::get().reads(1)
}
let keys_removed = v0::ReportsByKindIndex::<T>::clear(u32::MAX, None).unique as u64;
let weight = T::DbWeight::get().reads_writes(keys_removed, keys_removed);
StorageVersion::new(1).put::<Pallet<T>>();
weight
// + 1 for reading/writing the new storage version
T::DbWeight::get().reads_writes(keys_removed + 1, keys_removed + 1)
}
#[cfg(feature = "try-runtime")]
@@ -147,7 +141,7 @@ mod test {
ext.execute_with(|| {
assert_eq!(
v1::MigrateToV1::<T>::on_runtime_upgrade(),
<T as frame_system::Config>::DbWeight::get().reads_writes(1, 1),
<T as frame_system::Config>::DbWeight::get().reads_writes(2, 2),
);
assert!(<v0::ReportsByKindIndex<T>>::iter_values().count() == 0);