Skip to content

Commit

Permalink
Cleanup old migrations (#3002)
Browse files Browse the repository at this point in the history
* Cleanup old migrations

* Enable missing migration 

re-organize migrations order
  • Loading branch information
noandrea authored Oct 10, 2024
1 parent fea3b49 commit daec7fe
Showing 1 changed file with 57 additions and 56 deletions.
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())),
]
}
}

0 comments on commit daec7fe

Please sign in to comment.