cumulus_pallet_aura_ext/
migration.rs1extern crate alloc;
17
18use crate::{Config, Pallet};
19#[cfg(feature = "try-runtime")]
20use alloc::vec::Vec;
21use frame_support::{migrations::VersionedMigration, pallet_prelude::StorageVersion};
22
23pub const STORAGE_VERSION: StorageVersion = StorageVersion::new(1);
25
26mod v0 {
27 use super::*;
28 use frame_support::{pallet_prelude::OptionQuery, storage_alias};
29 use sp_consensus_aura::Slot;
30
31 #[storage_alias]
35 pub(super) type SlotInfo<T: Config> = StorageValue<Pallet<T>, (Slot, u32), OptionQuery>;
36}
37mod v1 {
38 use super::*;
39 use frame_support::{pallet_prelude::*, traits::UncheckedOnRuntimeUpgrade};
40
41 pub struct UncheckedMigrationToV1<T: Config>(PhantomData<T>);
42
43 impl<T: Config> UncheckedOnRuntimeUpgrade for UncheckedMigrationToV1<T> {
44 fn on_runtime_upgrade() -> Weight {
45 let mut weight: Weight = Weight::zero();
46 weight += migrate::<T>();
47 weight
48 }
49
50 #[cfg(feature = "try-runtime")]
51 fn pre_upgrade() -> Result<Vec<u8>, sp_runtime::TryRuntimeError> {
52 Ok(Vec::new())
53 }
54 #[cfg(feature = "try-runtime")]
55 fn post_upgrade(_state: Vec<u8>) -> Result<(), sp_runtime::TryRuntimeError> {
56 ensure!(!v0::SlotInfo::<T>::exists(), "SlotInfo should not exist");
57 Ok(())
58 }
59 }
60
61 pub fn migrate<T: Config>() -> Weight {
62 v0::SlotInfo::<T>::kill();
63 T::DbWeight::get().writes(1)
64 }
65}
66
67pub type MigrateV0ToV1<T> = VersionedMigration<
69 0,
70 1,
71 v1::UncheckedMigrationToV1<T>,
72 Pallet<T>,
73 <T as frame_system::Config>::DbWeight,
74>;