diff --git a/runtime/common/src/migrations.rs b/runtime/common/src/migrations.rs index 58e4eb52bd..58f2dcc5d6 100644 --- a/runtime/common/src/migrations.rs +++ b/runtime/common/src/migrations.rs @@ -48,57 +48,57 @@ where } } -// pub struct MigrateCodeToStateTrieV1(PhantomData); -// impl Migration for MigrateCodeToStateTrieV1 -// where -// Runtime: frame_system::Config, -// { -// fn friendly_name(&self) -> &str { -// "MM_MigrateCodeToStateTrieVersion1" -// } - -// fn migrate(&self, _available_weight: Weight) -> Weight { -// use cumulus_primitives_storage_weight_reclaim::get_proof_size; -// use sp_core::Get; - -// let proof_size_before: u64 = get_proof_size().unwrap_or(0); - -// let key = sp_core::storage::well_known_keys::CODE; -// let data = sp_io::storage::get(&key); -// if let Some(data) = data { -// sp_io::storage::set(&key, &data); -// } - -// let proof_size_after: u64 = get_proof_size().unwrap_or(0); -// let proof_size_diff = proof_size_after.saturating_sub(proof_size_before); - -// Weight::from_parts(0, proof_size_diff) -// .saturating_add(::DbWeight::get().reads_writes(1, 1)) -// } - -// #[cfg(feature = "try-runtime")] -// fn pre_upgrade(&self) -> Result, sp_runtime::DispatchError> { -// use parity_scale_codec::Encode; - -// let key = sp_core::storage::well_known_keys::CODE; -// let data = sp_io::storage::get(&key); -// Ok(Encode::encode(&data)) -// } - -// #[cfg(feature = "try-runtime")] -// fn post_upgrade(&self, state: Vec) -> Result<(), sp_runtime::DispatchError> { -// use frame_support::ensure; -// use parity_scale_codec::Encode; -// use sp_core::storage::StorageKey; - -// let key = StorageKey(sp_core::storage::well_known_keys::CODE.to_vec()); -// let data = sp_io::storage::get(key.as_ref()); - -// ensure!(Encode::encode(&data) == state, "Invalid state"); - -// Ok(()) -// } -// } +pub struct MigrateCodeToStateTrieV1(PhantomData); +impl Migration for MigrateCodeToStateTrieV1 +where + Runtime: frame_system::Config, +{ + fn friendly_name(&self) -> &str { + "MM_MigrateCodeToStateTrieVersion1" + } + + fn migrate(&self, _available_weight: Weight) -> Weight { + use cumulus_primitives_storage_weight_reclaim::get_proof_size; + use sp_core::Get; + + let proof_size_before: u64 = get_proof_size().unwrap_or(0); + + let key = sp_core::storage::well_known_keys::CODE; + let data = sp_io::storage::get(&key); + if let Some(data) = data { + sp_io::storage::set(&key, &data); + } + + let proof_size_after: u64 = get_proof_size().unwrap_or(0); + let proof_size_diff = proof_size_after.saturating_sub(proof_size_before); + + Weight::from_parts(0, proof_size_diff) + .saturating_add(::DbWeight::get().reads_writes(1, 1)) + } + + #[cfg(feature = "try-runtime")] + fn pre_upgrade(&self) -> Result, sp_runtime::DispatchError> { + use parity_scale_codec::Encode; + + let key = sp_core::storage::well_known_keys::CODE; + let data = sp_io::storage::get(&key); + Ok(Encode::encode(&data)) + } + + #[cfg(feature = "try-runtime")] + fn post_upgrade(&self, state: Vec) -> Result<(), sp_runtime::DispatchError> { + use frame_support::ensure; + use parity_scale_codec::Encode; + use sp_core::storage::StorageKey; + + let key = StorageKey(sp_core::storage::well_known_keys::CODE.to_vec()); + let data = sp_io::storage::get(key.as_ref()); + + ensure!(Encode::encode(&data) == state, "Invalid state"); + + Ok(()) + } +} #[derive(parity_scale_codec::Decode, Eq, Ord, PartialEq, PartialOrd)] enum OldAssetType { @@ -378,15 +378,16 @@ where // Box::new(pallet_collective_drop_gov_v1_collectives), // completed in runtime 2900 // Box::new(remove_pallet_democracy), - // Box::new(remove_collectives_addresses), - // Box::new(MigrateCodeToStateTrieV1::(Default::default())), + // Box::new(remove_collectives_addresses // completed in runtime 3200 - Box::new(MigrateXcmFeesAssetsMeatdata::(Default::default())), - // permanent migrations - Box::new(MigrateToLatestXcmVersion::(Default::default())), + // Box::new(MigrateXcmFeesAssetsMeatdata::(Default::default())), + // complete in runtime 3300 + Box::new(MigrateCodeToStateTrieV1::(Default::default())), Box::new(MigrateStakingParachainBondConfig::( Default::default(), )), + // permanent migrations + Box::new(MigrateToLatestXcmVersion::(Default::default())), ] } }