Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
xlc committed Nov 15, 2023
1 parent d2998be commit 67ec825
Show file tree
Hide file tree
Showing 12 changed files with 4,940 additions and 4,158 deletions.
8,490 changes: 4,801 additions & 3,689 deletions Cargo.lock

Large diffs are not rendered by default.

273 changes: 137 additions & 136 deletions Cargo.toml

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion modules/asset-registry/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ use sp_std::{boxed::Box, vec::Vec};

use xcm::{v3::prelude::*, VersionedMultiLocation};

pub mod migrations;
mod mock;
mod tests;
mod weights;
Expand Down
57 changes: 0 additions & 57 deletions modules/asset-registry/src/migrations.rs

This file was deleted.

261 changes: 0 additions & 261 deletions modules/asset-registry/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,267 +64,6 @@ fn test_v2_to_v3_incompatible_multilocation() {
assert!(v2_location.encode() != v3_location.encode());
}

#[test]
fn simulate_migrate_multilocation_storage_to_v3() {
ExtBuilder::default().build().execute_with(|| {
let foreign_asset_locations_module_prefix = ForeignAssetLocations::<Runtime>::module_prefix();
let foreign_asset_locations_storage_prefix = ForeignAssetLocations::<Runtime>::storage_prefix();

let location_to_currency_ids_module_prefix = LocationToCurrencyIds::<Runtime>::module_prefix();
let location_to_currency_ids_storage_prefix = LocationToCurrencyIds::<Runtime>::storage_prefix();

let old_multilocation_0 = xcm::v2::MultiLocation::new(
0,
xcm::v2::Junctions::X1(xcm::v2::Junction::GeneralKey(vec![0].try_into().unwrap())),
);
let old_multilocation_1 = xcm::v2::MultiLocation::new(
0,
xcm::v2::Junctions::X1(xcm::v2::Junction::GeneralKey(vec![1, 1].try_into().unwrap())),
);
let old_multilocation_2 = xcm::v2::MultiLocation::new(
1,
xcm::v2::Junctions::X2(
xcm::v2::Junction::Parachain(2088),
xcm::v2::Junction::GeneralKey(vec![0, 1].try_into().unwrap()),
),
);
let old_multilocation_3 = xcm::v2::MultiLocation::new(
1,
xcm::v2::Junctions::X2(
xcm::v2::Junction::Parachain(2096),
xcm::v2::Junction::GeneralKey(vec![0, 0, 0, 0, 0, 0, 0, 0, 0].try_into().unwrap()),
),
);
let old_multilocation_4 = xcm::v2::MultiLocation::new(
1,
xcm::v2::Junctions::X2(
xcm::v2::Junction::Parachain(2096),
xcm::v2::Junction::GeneralKey(vec![1, 1].try_into().unwrap()),
),
);

let new_multilocation_0 = MultiLocation::try_from(old_multilocation_0.clone()).unwrap();
let new_multilocation_1 = MultiLocation::try_from(old_multilocation_1.clone()).unwrap();
let new_multilocation_2 = MultiLocation::try_from(old_multilocation_2.clone()).unwrap();
let new_multilocation_3 = MultiLocation::try_from(old_multilocation_3.clone()).unwrap();
let new_multilocation_4 = MultiLocation::try_from(old_multilocation_4.clone()).unwrap();
let foreign_asset_id_0: ForeignAssetId = 0;
let foreign_asset_id_1: ForeignAssetId = 1;
let foreign_asset_id_2: ForeignAssetId = 2;
let foreign_asset_id_3: ForeignAssetId = 3;
let foreign_asset_id_4: ForeignAssetId = 4;
let currency_id_0 = CurrencyId::ForeignAsset(foreign_asset_id_0);
let currency_id_1 = CurrencyId::ForeignAsset(foreign_asset_id_1);
let currency_id_2 = CurrencyId::ForeignAsset(foreign_asset_id_2);
let currency_id_3 = CurrencyId::ForeignAsset(foreign_asset_id_3);
let currency_id_4 = CurrencyId::ForeignAsset(foreign_asset_id_4);

// Store raw xcm::v2 data
put_storage_value(
foreign_asset_locations_module_prefix,
foreign_asset_locations_storage_prefix,
&Twox64Concat::hash(&foreign_asset_id_0.encode()),
&old_multilocation_0,
);
put_storage_value(
foreign_asset_locations_module_prefix,
foreign_asset_locations_storage_prefix,
&Twox64Concat::hash(&foreign_asset_id_1.encode()),
&old_multilocation_1,
);
put_storage_value(
foreign_asset_locations_module_prefix,
foreign_asset_locations_storage_prefix,
&Twox64Concat::hash(&foreign_asset_id_2.encode()),
&old_multilocation_2,
);
put_storage_value(
foreign_asset_locations_module_prefix,
foreign_asset_locations_storage_prefix,
&Twox64Concat::hash(&foreign_asset_id_3.encode()),
&old_multilocation_3,
);
put_storage_value(
foreign_asset_locations_module_prefix,
foreign_asset_locations_storage_prefix,
&Twox64Concat::hash(&foreign_asset_id_4.encode()),
&old_multilocation_4,
);
put_storage_value(
location_to_currency_ids_module_prefix,
location_to_currency_ids_storage_prefix,
&Twox64Concat::hash(&old_multilocation_0.encode()),
currency_id_0,
);
put_storage_value(
location_to_currency_ids_module_prefix,
location_to_currency_ids_storage_prefix,
&Twox64Concat::hash(&old_multilocation_1.encode()),
currency_id_1,
);
put_storage_value(
location_to_currency_ids_module_prefix,
location_to_currency_ids_storage_prefix,
&Twox64Concat::hash(&old_multilocation_2.encode()),
currency_id_2,
);
put_storage_value(
location_to_currency_ids_module_prefix,
location_to_currency_ids_storage_prefix,
&Twox64Concat::hash(&old_multilocation_3.encode()),
currency_id_3,
);
put_storage_value(
location_to_currency_ids_module_prefix,
location_to_currency_ids_storage_prefix,
&Twox64Concat::hash(&old_multilocation_4.encode()),
currency_id_4,
);

assert_eq!(
get_storage_value::<CurrencyId>(
location_to_currency_ids_module_prefix,
location_to_currency_ids_storage_prefix,
&Twox64Concat::hash(&old_multilocation_0.encode()),
),
Some(currency_id_0)
);
assert_eq!(
get_storage_value::<CurrencyId>(
location_to_currency_ids_module_prefix,
location_to_currency_ids_storage_prefix,
&Twox64Concat::hash(&old_multilocation_1.encode()),
),
Some(currency_id_1)
);
assert_eq!(
get_storage_value::<CurrencyId>(
location_to_currency_ids_module_prefix,
location_to_currency_ids_storage_prefix,
&Twox64Concat::hash(&old_multilocation_2.encode()),
),
Some(currency_id_2)
);
assert_eq!(
get_storage_value::<CurrencyId>(
location_to_currency_ids_module_prefix,
location_to_currency_ids_storage_prefix,
&Twox64Concat::hash(&old_multilocation_3.encode()),
),
Some(currency_id_3)
);
assert_eq!(
get_storage_value::<CurrencyId>(
location_to_currency_ids_module_prefix,
location_to_currency_ids_storage_prefix,
&Twox64Concat::hash(&old_multilocation_4.encode()),
),
Some(currency_id_4)
);

// Assert the v3 multilocation value does not exist in ForeignAssetLocations
assert_eq!(AssetRegistry::foreign_asset_locations(foreign_asset_id_0), None);
assert_eq!(AssetRegistry::foreign_asset_locations(foreign_asset_id_1), None);

// Assert v3 multilocation key does not exist in LocationToCurrencyIds
assert_eq!(AssetRegistry::location_to_currency_ids(new_multilocation_0), None);
assert_eq!(AssetRegistry::location_to_currency_ids(new_multilocation_1), None);

// Run migration
assert_eq!(
crate::migrations::MigrateV1MultiLocationToV3::<Runtime>::on_runtime_upgrade(),
<<Runtime as frame_system::Config>::DbWeight as Get<frame_support::weights::RuntimeDbWeight>>::get()
.reads_writes(10, 10)
);

// Assert the value type of ForeignAssetLocations has been migrated to v3 MultiLocation
assert_eq!(
AssetRegistry::foreign_asset_locations(foreign_asset_id_0),
Some(new_multilocation_0)
);
assert_eq!(
AssetRegistry::foreign_asset_locations(foreign_asset_id_1),
Some(new_multilocation_1)
);
assert_eq!(
AssetRegistry::foreign_asset_locations(foreign_asset_id_2),
Some(new_multilocation_2)
);
assert_eq!(
AssetRegistry::foreign_asset_locations(foreign_asset_id_3),
Some(new_multilocation_3)
);
assert_eq!(
AssetRegistry::foreign_asset_locations(foreign_asset_id_4),
Some(new_multilocation_4)
);

// Assert the key type of LocationToCurrencyIds has been migrated to v3 MultiLocation
assert_eq!(
AssetRegistry::location_to_currency_ids(new_multilocation_0),
Some(currency_id_0)
);
assert_eq!(
AssetRegistry::location_to_currency_ids(new_multilocation_1),
Some(currency_id_1)
);
assert_eq!(
AssetRegistry::location_to_currency_ids(new_multilocation_2),
Some(currency_id_2)
);
assert_eq!(
AssetRegistry::location_to_currency_ids(new_multilocation_3),
Some(currency_id_3)
);
assert_eq!(
AssetRegistry::location_to_currency_ids(new_multilocation_4),
Some(currency_id_4)
);

// Assert the old key does not exist anymore
assert_eq!(
get_storage_value::<CurrencyId>(
location_to_currency_ids_module_prefix,
location_to_currency_ids_storage_prefix,
&Twox64Concat::hash(&old_multilocation_0.encode()),
),
None
);
assert_eq!(
get_storage_value::<CurrencyId>(
location_to_currency_ids_module_prefix,
location_to_currency_ids_storage_prefix,
&Twox64Concat::hash(&old_multilocation_1.encode()),
),
None
);
assert_eq!(
get_storage_value::<CurrencyId>(
location_to_currency_ids_module_prefix,
location_to_currency_ids_storage_prefix,
&Twox64Concat::hash(&old_multilocation_2.encode()),
),
None
);
assert_eq!(
get_storage_value::<CurrencyId>(
location_to_currency_ids_module_prefix,
location_to_currency_ids_storage_prefix,
&Twox64Concat::hash(&old_multilocation_3.encode()),
),
None
);
assert_eq!(
get_storage_value::<CurrencyId>(
location_to_currency_ids_module_prefix,
location_to_currency_ids_storage_prefix,
&Twox64Concat::hash(&old_multilocation_4.encode()),
),
None
);
});
}

#[test]
fn versioned_multi_location_convert_work() {
ExtBuilder::default().build().execute_with(|| {
Expand Down
2 changes: 0 additions & 2 deletions node/e2e-tests/test-service/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,10 @@ sp-state-machine = { workspace = true, features = ["std"] }
sp-timestamp = { workspace = true, features = ["std"] }
sp-tracing = { workspace = true, features = ["std"] }
sp-trie = { workspace = true, features = ["std"] }
substrate-test-client = { workspace = true }

# Polkadot dependencies
polkadot-primitives = { workspace = true, features = ["std"] }
polkadot-service = { workspace = true }
polkadot-test-service = { workspace = true }

# Cumulus dependencies
cumulus-client-cli = { workspace = true }
Expand Down
2 changes: 1 addition & 1 deletion orml
2 changes: 0 additions & 2 deletions runtime/acala/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,6 @@ substrate-wasm-builder = { workspace = true, optional = true }

[dev-dependencies]
sp-io = { workspace = true, features = ["std"] }
polkadot-runtime = { workspace = true }

[features]
default = ["std"]
Expand Down Expand Up @@ -292,7 +291,6 @@ runtime-benchmarks = [
"polkadot-parachain-primitives/runtime-benchmarks",
"xcm-builder/runtime-benchmarks",
"xcm-executor/runtime-benchmarks",
"polkadot-runtime/runtime-benchmarks",

"orml-authority/runtime-benchmarks",
"orml-parameters/runtime-benchmarks",
Expand Down
2 changes: 0 additions & 2 deletions runtime/common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@ orml-currencies = { workspace = true, optional = true }
orml-rewards = { workspace = true, optional = true }

[dev-dependencies]
polkadot-runtime = { workspace = true }
orml-utilities = { workspace = true, features = ["std"] }

[features]
Expand Down Expand Up @@ -172,5 +171,4 @@ wasm-bench = [
"orml-tokens/runtime-benchmarks",

"xcm-builder/runtime-benchmarks",
"polkadot-runtime/runtime-benchmarks",
]
2 changes: 1 addition & 1 deletion runtime/common/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ pub const MAXIMUM_BLOCK_WEIGHT: Weight = Weight::from_parts(
WEIGHT_REF_TIME_PER_SECOND.saturating_div(2),
// TODO: drop `* 10` after https://github.com/paritytech/substrate/issues/13501
// and the benchmarked size is not 10x of the measured size
polkadot_primitives::v5::MAX_POV_SIZE as u64 * 10,
polkadot_primitives::v6::MAX_POV_SIZE as u64 * 10,
);

const_assert!(NORMAL_DISPATCH_RATIO.deconstruct() >= AVERAGE_ON_INITIALIZE_RATIO.deconstruct());
Expand Down
Loading

0 comments on commit 67ec825

Please sign in to comment.