cumulus_pallet_parachain_system/
migration.rs1use crate::{Config, Pallet, ReservedDmpWeightOverride, ReservedXcmpWeightOverride};
18use frame_support::{
19 pallet_prelude::*,
20 traits::{Get, OnRuntimeUpgrade, StorageVersion},
21 weights::Weight,
22};
23
24pub const STORAGE_VERSION: StorageVersion = StorageVersion::new(2);
26
27pub struct Migration<T: Config>(PhantomData<T>);
29
30impl<T: Config> OnRuntimeUpgrade for Migration<T> {
31 fn on_runtime_upgrade() -> Weight {
32 let mut weight: Weight = T::DbWeight::get().reads(2);
33
34 if StorageVersion::get::<Pallet<T>>() == 0 {
35 weight = weight
36 .saturating_add(v1::migrate::<T>())
37 .saturating_add(T::DbWeight::get().writes(1));
38 StorageVersion::new(1).put::<Pallet<T>>();
39 }
40
41 if StorageVersion::get::<Pallet<T>>() == 1 {
42 weight = weight
43 .saturating_add(v2::migrate::<T>())
44 .saturating_add(T::DbWeight::get().writes(1));
45 StorageVersion::new(2).put::<Pallet<T>>();
46 }
47
48 weight
49 }
50}
51
52mod v2 {
54 use super::*;
55 const DEFAULT_POV_SIZE: u64 = 64 * 1024; pub fn migrate<T: Config>() -> Weight {
58 let translate = |pre: u64| -> Weight { Weight::from_parts(pre, DEFAULT_POV_SIZE) };
59
60 if ReservedXcmpWeightOverride::<T>::translate(|pre| pre.map(translate)).is_err() {
61 log::error!(
62 target: "parachain_system",
63 "unexpected error when performing translation of the ReservedXcmpWeightOverride type during storage upgrade to v2"
64 );
65 }
66
67 if ReservedDmpWeightOverride::<T>::translate(|pre| pre.map(translate)).is_err() {
68 log::error!(
69 target: "parachain_system",
70 "unexpected error when performing translation of the ReservedDmpWeightOverride type during storage upgrade to v2"
71 );
72 }
73
74 T::DbWeight::get().reads_writes(2, 2)
75 }
76}
77
78mod v1 {
81 use crate::{Config, Pallet};
82 #[allow(deprecated)]
83 use frame_support::{migration::remove_storage_prefix, pallet_prelude::*};
84
85 pub fn migrate<T: Config>() -> Weight {
86 #[allow(deprecated)]
87 remove_storage_prefix(<Pallet<T>>::name().as_bytes(), b"LastUpgrade", b"");
88 T::DbWeight::get().writes(1)
89 }
90}