Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
54 commits
Select commit Hold shift + click to select a range
e170f4c
Add statemine like runtime for xcm tests
girazoki Jan 10, 2022
ef6ae21
Be able to receive both prefixes from statemine, while add an extrins…
girazoki Jan 10, 2022
32cdb42
Add statemine/statemint tests
girazoki Jan 10, 2022
a15613b
add statemine runtime test
girazoki Jan 10, 2022
9d44c8f
refactor
girazoki Jan 10, 2022
bf39e2e
More rust and typescript tests
girazoki Jan 11, 2022
aeef2b3
NPX
girazoki Jan 11, 2022
306bb0e
Document tests
girazoki Jan 11, 2022
6bc863c
editorconfig
girazoki Jan 11, 2022
01b0618
Merge remote-tracking branch 'upstream/master' into girazoki-avoid-st…
girazoki Jan 11, 2022
bdeaebf
Update benchmark
girazoki Jan 11, 2022
14c2599
Update weights
girazoki Jan 11, 2022
8b4dcbb
Update message
girazoki Jan 11, 2022
8aa9b70
Merge remote-tracking branch 'upstream/master' into girazoki-avoid-st…
girazoki Jan 12, 2022
c7112a7
Update estamite for assets transfer
girazoki Jan 13, 2022
1895e6c
Adapt test and package-lock to run all tests correctly
girazoki Jan 13, 2022
723dd97
Prettier
girazoki Jan 13, 2022
1b4e8e0
Merge remote-tracking branch 'upstream/master' into girazoki-avoid-st…
girazoki Jan 17, 2022
5ec2c1f
Update test with AssetDoesNotExist
girazoki Jan 17, 2022
2667fef
Update to 3 in alphanet
girazoki Jan 17, 2022
982b6ec
New storage item with mapping from assetType -> AssetId
girazoki Jan 18, 2022
fd2e0dc
Migration referencing units per second by assetType and not by assetId
girazoki Jan 18, 2022
34344aa
Add migrations
girazoki Jan 18, 2022
82f30eb
Add test for new migration
girazoki Jan 18, 2022
67b0aae
adapt traits to new storage item in pallet-asset-amanger
girazoki Jan 18, 2022
13852c4
Remove AsserId bound in FirstAssetTrader
girazoki Jan 18, 2022
5c82ee9
Update all tests to new design
girazoki Jan 18, 2022
c0fc100
Test third migration: migrate prefixes from previous statemine to new…
girazoki Jan 18, 2022
d2694d0
Integration tests change
girazoki Jan 18, 2022
e0cb77f
Update moonriver integration tests
girazoki Jan 18, 2022
e31d450
Merge remote-tracking branch 'upstream/master' into girazoki-avoid-st…
girazoki Jan 19, 2022
cdc8f42
Adapt moonbeam to migrations and statemint
girazoki Jan 19, 2022
42399ad
Make all migrations be independent from each other, and thus they can…
girazoki Jan 19, 2022
fff3b82
Define how we are going to pass statemine info to migration
girazoki Jan 19, 2022
94dbdfa
Update names of migrations
girazoki Jan 19, 2022
eccdb27
Include migration to all runtimes
girazoki Jan 19, 2022
555d0bf
Adapt tests to changes in set assets units per second plus statemint …
girazoki Jan 19, 2022
b23dcf7
Toml sort
girazoki Jan 19, 2022
437d089
Add statemine like to moonbeam
girazoki Jan 19, 2022
f7ef5c0
Prettier
girazoki Jan 19, 2022
a8e899c
EditorConfig
girazoki Jan 19, 2022
ee85d85
Fmt
girazoki Jan 19, 2022
c025e17
Editorconfig
girazoki Jan 19, 2022
c7cdf07
EditorCOnfig too
girazoki Jan 19, 2022
988eb26
Update benchmarks too
girazoki Jan 19, 2022
c7650bd
Editorconfig third try
girazoki Jan 19, 2022
90a2026
Update weights
girazoki Jan 19, 2022
8392853
Remove unused variable
girazoki Jan 19, 2022
9a97266
Remove silly comment
girazoki Jan 19, 2022
239964b
Tests for regular users cannot call root extrinsics
girazoki Jan 19, 2022
4b8faef
Add PR suggestions
girazoki Jan 20, 2022
08452c5
Documentation about migrations
girazoki Jan 20, 2022
5086d17
Merge remote-tracking branch 'upstream/master' into girazoki-avoid-st…
girazoki Jan 20, 2022
fc91d87
Comments in storage items
girazoki Jan 20, 2022
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
Prev Previous commit
Next Next commit
Include migration to all runtimes
  • Loading branch information
girazoki committed Jan 19, 2022
commit eccdb27a92d78badd9d3e65f41ffd5083f7d4944
1 change: 1 addition & 0 deletions Cargo.lock

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

6 changes: 5 additions & 1 deletion runtime/common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ sp-std = { git = "https://github.com/purestake/substrate", branch = "moonbeam-po
# Frontier
pallet-evm = { git = "https://github.com/purestake/frontier", branch = "moonbeam-polkadot-v0.9.13", default-features = false }

# Polkadot
xcm = { git = "https://github.com/purestake/polkadot", optional = true, branch = "moonbeam-polkadot-v0.9.13", default-features = false }

[features]
std = [
"frame-support/std",
Expand All @@ -40,6 +43,7 @@ std = [
"sp-core/std",
"sp-runtime/std",
"sp-std/std",
"xcm/std",
"xcm-transactor/std",
]
xcm-support = [ "xcm-transactor" ]
xcm-support = [ "xcm-transactor", "pallet-asset-manager", "xcm"]
128 changes: 116 additions & 12 deletions runtime/common/src/migrations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,14 @@

use frame_support::{
dispatch::GetStorageVersion,
traits::{OnRuntimeUpgrade, PalletInfoAccess},
traits::{Get, OnRuntimeUpgrade, PalletInfoAccess},
weights::Weight,
};
#[cfg(feature = "xcm-support")]
use pallet_asset_manager::{
migrations::{ChangeStateminePrefixes, PopulateAssetTypeIdStorage, UnitsWithAssetType},
Config as AssetManagerConfig,
};
use pallet_author_mapping::{migrations::TwoXToBlake, Config as AuthorMappingConfig};
use pallet_migrations::{GetMigrations, Migration};
use parachain_staking::{
Expand All @@ -29,6 +34,8 @@ use parachain_staking::{
};
use sp_std::{marker::PhantomData, prelude::*};
#[cfg(feature = "xcm-support")]
use xcm::latest::MultiLocation;
#[cfg(feature = "xcm-support")]
use xcm_transactor::{migrations::MaxTransactWeight, Config as XcmTransactorConfig};

/// This module acts as a registry where each migration is defined. Each migration should implement
Expand Down Expand Up @@ -193,6 +200,87 @@ impl<T: XcmTransactorConfig> Migration for XcmTransactorMaxTransactWeight<T> {
}
}

#[cfg(feature = "xcm-support")]
pub struct AssetManagerUnitsWithAssetType<T>(PhantomData<T>);
#[cfg(feature = "xcm-support")]
impl<T: AssetManagerConfig> Migration for AssetManagerUnitsWithAssetType<T> {
fn friendly_name(&self) -> &str {
"MM_Asset_Manager_UnitsWithAssetType"
}

fn migrate(&self, _available_weight: Weight) -> Weight {
UnitsWithAssetType::<T>::on_runtime_upgrade()
}

/// Run a standard pre-runtime test. This works the same way as in a normal runtime upgrade.
#[cfg(feature = "try-runtime")]
fn pre_upgrade(&self) -> Result<(), &'static str> {
UnitsWithAssetType::<T>::pre_upgrade()
}

/// Run a standard post-runtime test. This works the same way as in a normal runtime upgrade.
#[cfg(feature = "try-runtime")]
fn post_upgrade(&self) -> Result<(), &'static str> {
UnitsWithAssetType::<T>::post_upgrade()
}
}

#[cfg(feature = "xcm-support")]
pub struct AssetManagerPopulateAssetTypeIdStorage<T>(PhantomData<T>);
#[cfg(feature = "xcm-support")]
impl<T: AssetManagerConfig> Migration for AssetManagerPopulateAssetTypeIdStorage<T> {
fn friendly_name(&self) -> &str {
"MM_Asset_Manager_PopulateAssetTypeIdStorage"
}

fn migrate(&self, _available_weight: Weight) -> Weight {
PopulateAssetTypeIdStorage::<T>::on_runtime_upgrade()
}

/// Run a standard pre-runtime test. This works the same way as in a normal runtime upgrade.
#[cfg(feature = "try-runtime")]
fn pre_upgrade(&self) -> Result<(), &'static str> {
PopulateAssetTypeIdStorage::<T>::pre_upgrade()
}

/// Run a standard post-runtime test. This works the same way as in a normal runtime upgrade.
#[cfg(feature = "try-runtime")]
fn post_upgrade(&self) -> Result<(), &'static str> {
PopulateAssetTypeIdStorage::<T>::post_upgrade()
}
}

#[cfg(feature = "xcm-support")]
pub struct AssetManagerChangeStateminePrefixes<T, StatemineParaIdInfo, StatemineAssetsPalletInfo>(
PhantomData<(T, StatemineParaIdInfo, StatemineAssetsPalletInfo)>,
);
#[cfg(feature = "xcm-support")]
impl<T: AssetManagerConfig, StatemineParaIdInfo: Get<u32>, StatemineAssetsPalletInfo: Get<u8>>
Migration for AssetManagerChangeStateminePrefixes<T, StatemineParaIdInfo, StatemineAssetsPalletInfo>
where
T::AssetType: Into<Option<MultiLocation>> + From<MultiLocation>,
{
fn friendly_name(&self) -> &str {
"MM_Asset_Manager_ChangeStateminePrefixes"
}

fn migrate(&self, _available_weight: Weight) -> Weight {
ChangeStateminePrefixes::<T, StatemineParaIdInfo, StatemineAssetsPalletInfo>::on_runtime_upgrade()
}

/// Run a standard pre-runtime test. This works the same way as in a normal runtime upgrade.
#[cfg(feature = "try-runtime")]
fn pre_upgrade(&self) -> Result<(), &'static str> {
ChangeStateminePrefixes::<T, StatemineParaIdInfo, StatemineAssetsPalletInfo>::pre_upgrade()
}

/// Run a standard post-runtime test. This works the same way as in a normal runtime upgrade.
#[cfg(feature = "try-runtime")]
fn post_upgrade(&self) -> Result<(), &'static str> {
ChangeStateminePrefixes::<T, StatemineParaIdInfo, StatemineAssetsPalletInfo>::post_upgrade()
}
}

pub struct CommonMigrations<Runtime, Council, Tech>(PhantomData<(Runtime, Council, Tech)>);

impl<Runtime, Council, Tech> GetMigrations for CommonMigrations<Runtime, Council, Tech>
Expand Down Expand Up @@ -230,31 +318,47 @@ where
}
}

//TODO: Once the statemine prefix migration is applied, we can remove StatemineParaIdInfo and StatemineAssetsInstanceInfo
// but for now we need a way to pass these parameters, which are distinct for each of the runtimes
#[cfg(feature = "xcm-support")]
pub struct XcmMigrations<Runtime>(PhantomData<Runtime>);
pub struct XcmMigrations<Runtime, StatemineParaIdInfo, StatemineAssetsInstanceInfo>(
PhantomData<(Runtime, StatemineParaIdInfo, StatemineAssetsInstanceInfo)>,
);

#[cfg(feature = "xcm-support")]
impl<Runtime> GetMigrations for XcmMigrations<Runtime>
impl<Runtime, StatemineParaIdInfo, StatemineAssetsInstanceInfo> GetMigrations
for XcmMigrations<Runtime, StatemineParaIdInfo, StatemineAssetsInstanceInfo>
where
Runtime: xcm_transactor::Config + pallet_migrations::Config,
Runtime: xcm_transactor::Config + pallet_migrations::Config + pallet_asset_manager::Config,
StatemineParaIdInfo: Get<u32> + 'static,
StatemineAssetsInstanceInfo: Get<u8> + 'static,
<Runtime as pallet_asset_manager::Config>::AssetType:
Into<Option<MultiLocation>> + From<MultiLocation>,
{
fn get_migrations() -> Vec<Box<dyn Migration>> {
let xcm_transactor_max_weight =
XcmTransactorMaxTransactWeight::<Runtime>(Default::default());

let asset_manager_units_with_asset_type =
AssetManagerUnitsWithAssetType::<Runtime>(Default::default());

let asset_manager_populate_asset_type_id_storage =
AssetManagerPopulateAssetTypeIdStorage::<Runtime>(Default::default());

let asset_manager_change_statemine_prefixes = AssetManagerChangeStateminePrefixes::<
Runtime,
StatemineParaIdInfo,
StatemineAssetsInstanceInfo,
>(Default::default());

// TODO: this is a lot of allocation to do upon every get() call. this *should* be avoided
// except when pallet_migrations undergoes a runtime upgrade -- but TODO: review

vec![
// completed in runtime 800
// Box::new(migration_author_mapping_twox_to_blake),
// completed in runtime 900
// Box::new(migration_collectives),
// completed in runtime 1000
// Box::new(migration_parachain_staking_purge_stale_storage),
// completed in runtime 1000
// Box::new(migration_parachain_staking_manual_exits),
Box::new(xcm_transactor_max_weight),
Box::new(asset_manager_units_with_asset_type),
Box::new(asset_manager_change_statemine_prefixes),
Box::new(asset_manager_populate_asset_type_id_storage),
]
}
}
6 changes: 5 additions & 1 deletion runtime/moonbase/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -975,7 +975,11 @@ impl pallet_migrations::Config for Runtime {
CouncilCollective,
TechCommitteeCollective,
>,
runtime_common::migrations::XcmMigrations<Runtime>,
runtime_common::migrations::XcmMigrations<
Runtime,
StatemintParaId,
StatemintAssetPalletInstance,
>,
);
}

Expand Down
17 changes: 12 additions & 5 deletions runtime/moonriver/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -924,11 +924,18 @@ impl pallet_proxy::Config for Runtime {

impl pallet_migrations::Config for Runtime {
type Event = Event;
type MigrationsList = runtime_common::migrations::CommonMigrations<
Runtime,
CouncilCollective,
TechCommitteeCollective,
>;
type MigrationsList = (
runtime_common::migrations::CommonMigrations<
Runtime,
CouncilCollective,
TechCommitteeCollective,
>,
runtime_common::migrations::XcmMigrations<
Copy link
Contributor

Choose a reason for hiding this comment

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

Just to be pedantic, this means we can order CommonMigrations and XcmMigrations independently, and that all XcmMigrations come after all CommonMigrations.

This is possible because of the impl GetMigrations for Tuple.

I believe this will cause a lot of allocation and copies every time get_migrations() is called, but that shouldn't happen outside of runtime upgrades.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Agree. I think in the near future this will dissappear though, just because xcm is now reaching moonbeam. That means xcm migrations will be moved to common.

Runtime,
StatemineParaId,
StatemineAssetPalletInstance,
>,
);
}

parameter_types! {
Expand Down