Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Commit

Permalink
Remove migration (again!)
Browse files Browse the repository at this point in the history
  • Loading branch information
s0me0ne-unkn0wn committed Feb 13, 2023
1 parent 17a66e1 commit 83e8fe4
Show file tree
Hide file tree
Showing 3 changed files with 1 addition and 69 deletions.
68 changes: 1 addition & 67 deletions runtime/parachains/src/session_info/migration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,70 +19,4 @@
use frame_support::traits::StorageVersion;

/// The current storage version.
pub const STORAGE_VERSION: StorageVersion = StorageVersion::new(2);

pub mod v2 {
use super::STORAGE_VERSION;
#[cfg(feature = "try-runtime")]
use crate::session_info::Vec;
use crate::{session_info, session_info::Pallet, shared};
use frame_support::{
pallet_prelude::Weight,
traits::{OnRuntimeUpgrade, StorageVersion},
};
use frame_system::Config;
use primitives::vstaging::ExecutorParams;
use sp_core::Get;

const LOG_TARGET: &'static str = "runtime::session_info::migration::v2";

pub struct MigrateToV2<T>(sp_std::marker::PhantomData<T>);
impl<T: Config + session_info::pallet::Config> OnRuntimeUpgrade for MigrateToV2<T> {
fn on_runtime_upgrade() -> Weight {
// Bootstrap session executor params with the default ones if no parameters for the
// current session are in storage. `ExecutorParams::default()` is supposed to generate
// EXACTLY the same set of parameters the previous implementation used in a hard-coded
// form. This supposed to only run once, when upgrading from pre-parametrized executor
// code.
let db_weight = T::DbWeight::get();
let mut weight = db_weight.reads(1);
if StorageVersion::get::<Pallet<T>>() == 1 {
log::info!(target: LOG_TARGET, "Upgrading storage v1 -> v2");
let first_session = <session_info::Pallet<T>>::earliest_stored_session();
let current_session = <shared::Pallet<T>>::session_index();

for session_index in first_session..=current_session {
session_info::pallet::SessionExecutorParams::<T>::insert(
&session_index,
ExecutorParams::default(),
);
}

STORAGE_VERSION.put::<Pallet<T>>();
weight += db_weight.reads_writes(2, (current_session - first_session + 2) as u64);
} else {
log::warn!(target: LOG_TARGET, "Can only upgrade from version 1");
}
weight
}

#[cfg(feature = "try-runtime")]
fn pre_upgrade() -> Result<Vec<u8>, &'static str> {
log::info!(target: LOG_TARGET, "Performing pre-upgrade checks");
assert_eq!(StorageVersion::get::<Pallet<T>>(), 1);
let session_index = <shared::Pallet<T>>::session_index();
assert!(Pallet::<T>::session_executor_params(session_index).is_none());
Ok(Default::default())
}

#[cfg(feature = "try-runtime")]
fn post_upgrade(_: Vec<u8>) -> Result<(), &'static str> {
log::info!(target: LOG_TARGET, "Performing post-upgrade checks");
assert_eq!(StorageVersion::get::<Pallet<T>>(), 2);
let session_index = <shared::Pallet<T>>::session_index();
let executor_params = Pallet::<T>::session_executor_params(session_index);
assert_eq!(executor_params, Some(ExecutorParams::default()));
Ok(())
}
}
}
pub const STORAGE_VERSION: StorageVersion = StorageVersion::new(1);
1 change: 0 additions & 1 deletion runtime/rococo/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1491,7 +1491,6 @@ pub type Migrations = (
// "Use 2D weights in XCM v3" <https://github.com/paritytech/polkadot/pull/6134>
pallet_xcm::migration::v1::MigrateToV1<Runtime>,
parachains_ump::migration::v1::MigrateToV1<Runtime>,
parachains_session_info::migration::v2::MigrateToV2<Runtime>,
// Remove stale entries in the set id -> session index storage map (after
// this release they will be properly pruned after the bonding duration has
// elapsed)
Expand Down
1 change: 0 additions & 1 deletion runtime/westend/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1247,7 +1247,6 @@ pub type Migrations = (
// "Use 2D weights in XCM v3" <https://github.com/paritytech/polkadot/pull/6134>
pallet_xcm::migration::v1::MigrateToV1<Runtime>,
parachains_ump::migration::v1::MigrateToV1<Runtime>,
parachains_session_info::migration::v2::MigrateToV2<Runtime>,
// Remove stale entries in the set id -> session index storage map (after
// this release they will be properly pruned after the bonding duration has
// elapsed)
Expand Down

0 comments on commit 83e8fe4

Please sign in to comment.