Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cleanup old migrations #3002

Merged
merged 2 commits into from
Oct 10, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
113 changes: 57 additions & 56 deletions runtime/common/src/migrations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,57 +48,57 @@ where
}
}

// pub struct MigrateCodeToStateTrieV1<Runtime>(PhantomData<Runtime>);
// impl<Runtime> Migration for MigrateCodeToStateTrieV1<Runtime>
// 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(<Runtime as frame_system::Config>::DbWeight::get().reads_writes(1, 1))
// }

// #[cfg(feature = "try-runtime")]
// fn pre_upgrade(&self) -> Result<Vec<u8>, 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<u8>) -> 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<Runtime>(PhantomData<Runtime>);
impl<Runtime> Migration for MigrateCodeToStateTrieV1<Runtime>
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(<Runtime as frame_system::Config>::DbWeight::get().reads_writes(1, 1))
}

#[cfg(feature = "try-runtime")]
fn pre_upgrade(&self) -> Result<Vec<u8>, 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<u8>) -> 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 {
Expand Down Expand Up @@ -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::<Runtime>(Default::default())),
// Box::new(remove_collectives_addresses
// completed in runtime 3200
Box::new(MigrateXcmFeesAssetsMeatdata::<Runtime>(Default::default())),
// permanent migrations
Box::new(MigrateToLatestXcmVersion::<Runtime>(Default::default())),
// Box::new(MigrateXcmFeesAssetsMeatdata::<Runtime>(Default::default())),
// complete in runtime 3300
Box::new(MigrateCodeToStateTrieV1::<Runtime>(Default::default())),
Box::new(MigrateStakingParachainBondConfig::<Runtime>(
Default::default(),
)),
// permanent migrations
Box::new(MigrateToLatestXcmVersion::<Runtime>(Default::default())),
]
}
}
Loading