polkadot_runtime_common/assigned_slots/
migration.rs1use super::{Config, MaxPermanentSlots, MaxTemporarySlots, Pallet, LOG_TARGET};
18use frame_support::traits::{Get, GetStorageVersion, UncheckedOnRuntimeUpgrade};
19
20#[cfg(feature = "try-runtime")]
21use alloc::vec::Vec;
22#[cfg(feature = "try-runtime")]
23use frame_support::ensure;
24
25pub mod v1 {
26 use super::*;
27 pub struct VersionUncheckedMigrateToV1<T>(core::marker::PhantomData<T>);
28 impl<T: Config> UncheckedOnRuntimeUpgrade for VersionUncheckedMigrateToV1<T> {
29 #[cfg(feature = "try-runtime")]
30 fn pre_upgrade() -> Result<Vec<u8>, sp_runtime::TryRuntimeError> {
31 let on_chain_version = Pallet::<T>::on_chain_storage_version();
32 ensure!(on_chain_version < 1, "assigned_slots::MigrateToV1 migration can be deleted");
33 Ok(Default::default())
34 }
35
36 fn on_runtime_upgrade() -> frame_support::weights::Weight {
37 let on_chain_version = Pallet::<T>::on_chain_storage_version();
38 if on_chain_version < 1 {
39 const MAX_PERMANENT_SLOTS: u32 = 100;
40 const MAX_TEMPORARY_SLOTS: u32 = 100;
41
42 MaxPermanentSlots::<T>::put(MAX_PERMANENT_SLOTS);
43 MaxTemporarySlots::<T>::put(MAX_TEMPORARY_SLOTS);
44 T::DbWeight::get().reads_writes(1, 3)
46 } else {
47 log::info!(target: LOG_TARGET, "MigrateToV1 should be removed");
48 T::DbWeight::get().reads(1)
49 }
50 }
51
52 #[cfg(feature = "try-runtime")]
53 fn post_upgrade(_state: Vec<u8>) -> Result<(), sp_runtime::TryRuntimeError> {
54 let on_chain_version = Pallet::<T>::on_chain_storage_version();
55 ensure!(on_chain_version == 1, "assigned_slots::MigrateToV1 needs to be run");
56 assert_eq!(MaxPermanentSlots::<T>::get(), 100);
57 assert_eq!(MaxTemporarySlots::<T>::get(), 100);
58 Ok(())
59 }
60 }
61
62 pub type MigrateToV1<T> = frame_support::migrations::VersionedMigration<
66 0,
67 1,
68 VersionUncheckedMigrateToV1<T>,
69 Pallet<T>,
70 <T as frame_system::Config>::DbWeight,
71 >;
72}