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

feat: remove old storage migrations #643

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion runtime/basilisk/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "basilisk-runtime"
version = "106.0.0"
version = "107.0.0"
authors = ["GalacticCouncil"]
edition = "2021"
homepage = "https://github.com/galacticcouncil/Basilisk-node"
Expand Down
15 changes: 2 additions & 13 deletions runtime/basilisk/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
spec_name: create_runtime_str!("basilisk"),
impl_name: create_runtime_str!("basilisk"),
authoring_version: 1,
spec_version: 106,
spec_version: 107,
impl_version: 0,
apis: RUNTIME_API_VERSIONS,
transaction_version: 1,
Expand Down Expand Up @@ -257,18 +257,7 @@ pub type Executive = frame_executive::Executive<
frame_system::ChainContext<Runtime>,
Runtime,
AllPalletsReversedWithSystemFirst,
(
pallet_preimage::migration::v1::Migration<Runtime>,
pallet_democracy::migrations::v1::Migration<Runtime>,
pallet_multisig::migrations::v1::MigrateToV1<Runtime>,
pallet_xcm::migration::v1::MigrateToV1<Runtime>,
DmpQueue,
XcmpQueue,
ParachainSystem,
migrations::OnRuntimeUpgradeMigration,
migrations::MigrateRegistryLocationToV3<Runtime>,
migrations::XcmRateLimitMigration,
),
(migrations::OnRuntimeUpgradeMigration,),
>;

impl_runtime_apis! {
Expand Down
97 changes: 4 additions & 93 deletions runtime/basilisk/src/migrations.rs
Original file line number Diff line number Diff line change
@@ -1,112 +1,23 @@
use super::*;

use frame_support::{
log, migration::storage_key_iter, pallet_prelude::*, traits::OnRuntimeUpgrade, weights::Weight, StoragePrefixedMap,
};
use pallet_asset_registry::{AssetLocations, LocationAssets};
use polkadot_xcm::v3::MultiLocation;
use frame_support::{traits::OnRuntimeUpgrade, weights::Weight};

pub struct OnRuntimeUpgradeMigration;
impl OnRuntimeUpgrade for OnRuntimeUpgradeMigration {
#[cfg(feature = "try-runtime")]
fn pre_upgrade() -> Result<Vec<u8>, &'static str> {
frame_support::log::info!("PreMigrate Duster Pallet start");
pallet_duster::migration::v1::pre_migrate::<Runtime, Duster>();
frame_support::log::info!("PreMigrate Duster Pallet end");
// TODO: include migrations for transaction pause and collator rewards pallets in the next release
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Roznovjak shouldn't it be included in this PR then?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The pallet versions/revisions used in the master have not yet been updated to the latest version that contain the migrations. Updating dependencies probably deserves own PR.

// (not in the 106 release, because we don't use the latest pallet versions there).

Ok(vec![])
}

fn on_runtime_upgrade() -> Weight {
let mut weight: Weight = Weight::zero();

frame_support::log::info!("Migrate Scheduler Pallet to v4 start");
weight = weight.saturating_add(Scheduler::migrate_v1_to_v4());
frame_support::log::info!("Migrate Scheduler Pallet to v4 end");

frame_support::log::info!("Migrate Duster Pallet to v1 start");
weight = weight.saturating_add(pallet_duster::migration::v1::migrate::<Runtime, Duster>(
get_all_module_accounts(),
TreasuryAccount::get(),
TreasuryAccount::get(),
));
frame_support::log::info!("Migrate Duster Pallet to v1 end");

weight
}

#[cfg(feature = "try-runtime")]
fn post_upgrade(_state: Vec<u8>) -> Result<(), &'static str> {
frame_support::log::info!("PostMigrate Duster Pallet start");
pallet_duster::migration::v1::post_migrate::<Runtime, Duster>();
frame_support::log::info!("PostMigrate Duster Pallet end");
Ok(())
}
}

#[derive(Debug, Encode, Decode, Clone, PartialEq, Eq, TypeInfo)]
pub struct AssetLocationV2(pub polkadot_xcm::v2::MultiLocation);

pub struct MigrateRegistryLocationToV3<T>(PhantomData<T>);
impl<T: pallet_asset_registry::Config> OnRuntimeUpgrade for MigrateRegistryLocationToV3<T>
where
AssetLocation: Into<T::AssetNativeLocation>,
{
fn on_runtime_upgrade() -> Weight {
log::info!(
target: "runtime::asset-registry",
"MigrateRegistryLocationToV3::on_runtime_upgrade: migrating asset locations to v3"
);

let mut weight: Weight = Weight::zero();

AssetLocations::<T>::translate(|_asset_id, old_location: AssetLocationV2| {
weight.saturating_accrue(T::DbWeight::get().reads_writes(1, 1));
let new_multi_loc: MultiLocation = old_location.0.try_into().expect("xcm::v1::MultiLocation");
let new_location: T::AssetNativeLocation = AssetLocation(new_multi_loc).into();
Some(new_location)
});

let module_prefix = LocationAssets::<T>::module_prefix();
let storage_prefix = LocationAssets::<T>::storage_prefix();
let old_data = storage_key_iter::<AssetLocationV2, T::AssetId, Blake2_128Concat>(module_prefix, storage_prefix)
.drain()
.collect::<Vec<_>>();
for (old_location, asset_id) in old_data {
weight.saturating_accrue(T::DbWeight::get().reads_writes(1, 1));
let new_multi_loc: MultiLocation = old_location.0.try_into().expect("xcm::v1::MultiLocation");
let new_location: T::AssetNativeLocation = AssetLocation(new_multi_loc).into();
LocationAssets::<T>::insert(new_location, asset_id);
}
weight
}
}

pub struct XcmRateLimitMigration;
impl OnRuntimeUpgrade for XcmRateLimitMigration {
#[cfg(feature = "try-runtime")]
fn pre_upgrade() -> Result<Vec<u8>, &'static str> {
frame_support::log::info!("PreMigrate Asset Registry Pallet start");
pallet_asset_registry::migration::v1::pre_migrate::<Runtime>();
frame_support::log::info!("PreMigrate Asset Registry Pallet end");

Ok(vec![])
}

fn on_runtime_upgrade() -> Weight {
log::info!(
target: "runtime::asset-registry",
"XcmRateLimitMigration::on_runtime_upgrade: migrating asset details to include xcm rate limit"
);

pallet_asset_registry::migration::v1::migrate::<Runtime>()
Weight::zero()
}

#[cfg(feature = "try-runtime")]
fn post_upgrade(_state: Vec<u8>) -> Result<(), &'static str> {
frame_support::log::info!("PostMigrate Asset Registry Pallet start");
pallet_asset_registry::migration::v1::post_migrate::<Runtime>();
frame_support::log::info!("PostMigrate Asset Registry Pallet end");
Ok(())
}
}