From 2b39b01c9333996f62dab60e22424bd6d92de4ab Mon Sep 17 00:00:00 2001 From: Francisco Aguirre Date: Thu, 14 Mar 2024 14:01:19 +0700 Subject: [PATCH 01/32] feat(asset-hub-rococo-runtime): add a migration from foreign assets V3 to V4 --- Cargo.lock | 3 + .../assets/asset-hub-rococo/Cargo.toml | 4 + .../assets/asset-hub-rococo/src/lib.rs | 25 ++++- .../frame_runtime_upgrades_and_migrations.rs | 2 +- substrate/frame/assets/Cargo.toml | 4 + .../assets/src/foreign_assets_migration.rs | 104 ++++++++++++++++++ substrate/frame/assets/src/lib.rs | 1 + 7 files changed, 139 insertions(+), 4 deletions(-) create mode 100644 substrate/frame/assets/src/foreign_assets_migration.rs diff --git a/Cargo.lock b/Cargo.lock index 5eab3cf7c24f..5b235f2bc8cd 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -884,6 +884,7 @@ dependencies = [ "pallet-balances", "pallet-collator-selection", "pallet-message-queue", + "pallet-migrations", "pallet-multisig", "pallet-nft-fractionalization", "pallet-nfts", @@ -891,6 +892,7 @@ dependencies = [ "pallet-proxy", "pallet-session", "pallet-state-trie-migration", + "pallet-sudo", "pallet-timestamp", "pallet-transaction-payment", "pallet-transaction-payment-rpc-runtime-api", @@ -9089,6 +9091,7 @@ dependencies = [ "sp-io", "sp-runtime", "sp-std 14.0.0", + "staging-xcm", ] [[package]] diff --git a/cumulus/parachains/runtimes/assets/asset-hub-rococo/Cargo.toml b/cumulus/parachains/runtimes/assets/asset-hub-rococo/Cargo.toml index 3eb63a24b74e..470c9e1a6639 100644 --- a/cumulus/parachains/runtimes/assets/asset-hub-rococo/Cargo.toml +++ b/cumulus/parachains/runtimes/assets/asset-hub-rococo/Cargo.toml @@ -42,6 +42,7 @@ pallet-transaction-payment = { path = "../../../../../substrate/frame/transactio pallet-transaction-payment-rpc-runtime-api = { path = "../../../../../substrate/frame/transaction-payment/rpc/runtime-api", default-features = false } pallet-uniques = { path = "../../../../../substrate/frame/uniques", default-features = false } pallet-utility = { path = "../../../../../substrate/frame/utility", default-features = false } +pallet-migrations = { path = "../../../../../substrate/frame/migrations", default-features = false } sp-api = { path = "../../../../../substrate/primitives/api", default-features = false } sp-block-builder = { path = "../../../../../substrate/primitives/block-builder", default-features = false } sp-consensus-aura = { path = "../../../../../substrate/primitives/consensus/aura", default-features = false } @@ -134,6 +135,7 @@ runtime-benchmarks = [ "pallet-transaction-payment/runtime-benchmarks", "pallet-uniques/runtime-benchmarks", "pallet-utility/runtime-benchmarks", + "pallet-migrations/runtime-benchmarks", "pallet-xcm-benchmarks/runtime-benchmarks", "pallet-xcm-bridge-hub-router/runtime-benchmarks", "pallet-xcm/runtime-benchmarks", @@ -172,6 +174,7 @@ try-runtime = [ "pallet-transaction-payment/try-runtime", "pallet-uniques/try-runtime", "pallet-utility/try-runtime", + "pallet-migrations/try-runtime", "pallet-xcm-bridge-hub-router/try-runtime", "pallet-xcm/try-runtime", "parachain-info/try-runtime", @@ -221,6 +224,7 @@ std = [ "pallet-transaction-payment/std", "pallet-uniques/std", "pallet-utility/std", + "pallet-migrations/std", "pallet-xcm-benchmarks?/std", "pallet-xcm-bridge-hub-router/std", "pallet-xcm/std", diff --git a/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/lib.rs b/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/lib.rs index 32966ab6341d..c91b79add530 100644 --- a/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/lib.rs +++ b/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/lib.rs @@ -63,6 +63,7 @@ use frame_support::{ TransformOrigin, }, weights::{ConstantMultiplier, Weight}, + migrations::FreezeChainOnFailedMigration, BoundedVec, PalletId, }; use frame_system::{ @@ -182,8 +183,25 @@ impl frame_system::Config for Runtime { type SS58Prefix = SS58Prefix; type OnSetCode = cumulus_pallet_parachain_system::ParachainSetCode; type MaxConsumers = frame_support::traits::ConstU32<16>; + type SingleBlockMigrations = SingleBlockMigrations; + type MultiBlockMigrator = MultiBlockMigrator; } +impl pallet_migrations::Config for Runtime { + type RuntimeEvent = RuntimeEvent; + type Migrations = MultiBlockMigrations; + type CursorMaxLen = ConstU32<256>; + type IdentifierMaxLen = ConstU32<256>; + type MigrationStatusHandler = (); + type FailedMigrationHandler = FreezeChainOnFailedMigration; + type MaxServiceWeight = (); + type WeightInfo = (); +} + +type MultiBlockMigrations = ( + pallet_assets::foreign_assets_migration::MigrateForeignAssets, +); + impl pallet_timestamp::Config for Runtime { /// A timestamp: milliseconds since the unix epoch. type Moment = u64; @@ -385,7 +403,7 @@ pub type ForeignAssetsInstance = pallet_assets::Instance2; impl pallet_assets::Config for Runtime { type RuntimeEvent = RuntimeEvent; type Balance = Balance; - type AssetId = xcm::v3::Location; + type AssetId = xcm::v3::Location; // TODO: This is what I want to migrate to V4. type AssetIdParameter = xcm::v3::Location; type Currency = Balances; type CreateOrigin = ForeignCreators< @@ -904,6 +922,7 @@ construct_runtime!( ParachainSystem: cumulus_pallet_parachain_system = 1, Timestamp: pallet_timestamp = 3, ParachainInfo: parachain_info = 4, + MultiBlockMigrator: pallet_migrations = 5, // Monetary stuff. Balances: pallet_balances = 10, @@ -968,7 +987,7 @@ pub type TxExtension = ( pub type UncheckedExtrinsic = generic::UncheckedExtrinsic; /// Migrations to apply on runtime upgrade. -pub type Migrations = ( +pub type SingleBlockMigrations = ( pallet_collator_selection::migration::v1::MigrateToV1, InitStorageVersions, // unreleased @@ -1036,7 +1055,7 @@ pub type Executive = frame_executive::Executive< frame_system::ChainContext, Runtime, AllPalletsWithSystem, - Migrations, + (), >; #[cfg(feature = "runtime-benchmarks")] diff --git a/docs/sdk/src/reference_docs/frame_runtime_upgrades_and_migrations.rs b/docs/sdk/src/reference_docs/frame_runtime_upgrades_and_migrations.rs index 7d870b432218..ca94edf9c3a8 100644 --- a/docs/sdk/src/reference_docs/frame_runtime_upgrades_and_migrations.rs +++ b/docs/sdk/src/reference_docs/frame_runtime_upgrades_and_migrations.rs @@ -24,7 +24,7 @@ //! //! ## Performing a Runtime Upgrade //! -//! To upgrade a runtime, an [`Origin`](frame_system::RawOrigin) with the necesarry permissions +//! To upgrade a runtime, an [`Origin`](frame_system::RawOrigin) with the necessary permissions //! (usually via governance) changes the `:code` storage. Usually, this is performed via a call to //! [`set_code`] (or [`set_code_without_checks`]) with the desired new runtime blob, scheduled //! using [`pallet_scheduler`]. diff --git a/substrate/frame/assets/Cargo.toml b/substrate/frame/assets/Cargo.toml index 2efc96348cb5..a43493033f7e 100644 --- a/substrate/frame/assets/Cargo.toml +++ b/substrate/frame/assets/Cargo.toml @@ -29,6 +29,9 @@ frame-system = { path = "../system", default-features = false } frame-benchmarking = { path = "../benchmarking", default-features = false, optional = true } sp-core = { path = "../../primitives/core", default-features = false } +# TODO: Remove migrations from here since they require XCM +xcm = { package = "staging-xcm", path = "../../../polkadot/xcm", default-features = false } + [dev-dependencies] sp-std = { path = "../../primitives/std" } sp-io = { path = "../../primitives/io" } @@ -48,6 +51,7 @@ std = [ "sp-io/std", "sp-runtime/std", "sp-std/std", + "xcm/std", ] runtime-benchmarks = [ "frame-benchmarking/runtime-benchmarks", diff --git a/substrate/frame/assets/src/foreign_assets_migration.rs b/substrate/frame/assets/src/foreign_assets_migration.rs new file mode 100644 index 000000000000..f8cf36a90249 --- /dev/null +++ b/substrate/frame/assets/src/foreign_assets_migration.rs @@ -0,0 +1,104 @@ +// This file is part of Substrate. + +// Copyright (C) Parity Technologies (UK) Ltd. +// SPDX-License-Identifier: Apache-2.0 + +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +//! This migration is meant to upgrade the XCM version of asset locations from V3 to V4. +//! It's only needed if the `AssetId` for this pallet is `VersionedLocation` + +use crate::pallet::{Config, Asset}; +use frame_support::{ + migrations::{SteppedMigration, SteppedMigrationError}, + pallet_prelude::PhantomData, + weights::WeightMeter, + Hashable, +}; + +// TODO: Move this further up. +mod identifier { + use codec::{MaxEncodedLen, Encode, Decode}; + + #[derive(MaxEncodedLen, Encode, Decode)] + pub struct MigrationIdentifier { + pub pallet_identifier: [u8; 16], + pub version_from: u8, + pub version_to: u8, + } + + pub const PALLET_MIGRATIONS_ID: &[u8; 13] = b"pallet-assets"; +} + +use identifier::*; + +/// Storage aliases for on-chain storage types before running the migration. +mod old { + use super::Config; + use crate::pallet::Pallet; + use crate::types::{AssetDetails, DepositBalanceOf}; + use frame_support::{storage_alias, Blake2_128Concat}; + + /// The storage item we are migrating from. + #[storage_alias] + pub(super) type Asset, I: 'static> = StorageMap< + Pallet, + Blake2_128Concat, + xcm::v3::Location, + AssetDetails<>::Balance, ::AccountId, DepositBalanceOf>, + >; +} + +pub struct MigrateForeignAssets, I: 'static>(PhantomData<(T, I)>); +impl, I: 'static> SteppedMigration for MigrateForeignAssets { + type Cursor = T::AssetId; + type Identifier = MigrationIdentifier; + + fn id() -> Self::Identifier { + MigrationIdentifier { + pallet_identifier: (*PALLET_MIGRATIONS_ID).twox_128(), + version_from: 0, + version_to: 1, + } + } + + // TODO: For now I'm letting it run forever, check. + fn max_steps() -> Option { + None + } + + fn step( + cursor: Option, + _meter: &mut WeightMeter, + ) -> Result, SteppedMigrationError> { + let mut iter = if let Some(last_key) = cursor { + // If a cursor is provided, start iterating from the value corresponding + // to the last key processed in the previous step of the migration. + old::Asset::::iter_from(old::Asset::::hashed_key_for(last_key)) + } else { + // If there is no cursor, start iterating from the beginning. + old::Asset::::iter() + }; + + if let Some((key, _value)) = iter.next() { + // If there is a next item in the iterator, migrate it. + Asset::::remove(key); + // TODO: Insert the item with a V4 key. + // Return the processed key as the new cursor to continue the migration. + Ok(Some(key)) + } else { + // Signal the migration is complete. + Ok(None) + } + } +} diff --git a/substrate/frame/assets/src/lib.rs b/substrate/frame/assets/src/lib.rs index 09d59ae1b8b5..5504acbcc28d 100644 --- a/substrate/frame/assets/src/lib.rs +++ b/substrate/frame/assets/src/lib.rs @@ -143,6 +143,7 @@ #[cfg(feature = "runtime-benchmarks")] pub mod benchmarking; pub mod migration; +pub mod foreign_assets_migration; // TODO: move to `migrations` mod #[cfg(test)] pub mod mock; #[cfg(test)] From 94738d1a6fbf020dd74897a2774754ee1be24221 Mon Sep 17 00:00:00 2001 From: Francisco Aguirre Date: Wed, 26 Jun 2024 19:03:45 +0200 Subject: [PATCH 02/32] fix: fmt --- .../assets/asset-hub-rococo/src/lib.rs | 2 +- .../assets/src/foreign_assets_migration.rs | 132 ++++++++++-------- substrate/frame/assets/src/lib.rs | 2 +- 3 files changed, 72 insertions(+), 64 deletions(-) diff --git a/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/lib.rs b/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/lib.rs index 9a0b03b6d4e3..aeef3c70dea5 100644 --- a/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/lib.rs +++ b/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/lib.rs @@ -56,6 +56,7 @@ use frame_support::{ construct_runtime, derive_impl, dispatch::DispatchClass, genesis_builder_helper::{build_state, get_preset}, + migrations::FreezeChainOnFailedMigration, ord_parameter_types, parameter_types, traits::{ fungible, fungibles, tokens::imbalance::ResolveAssetTo, AsEnsureOriginWithArg, ConstBool, @@ -63,7 +64,6 @@ use frame_support::{ TransformOrigin, }, weights::{ConstantMultiplier, Weight, WeightToFee as _}, - migrations::FreezeChainOnFailedMigration, BoundedVec, PalletId, }; use frame_system::{ diff --git a/substrate/frame/assets/src/foreign_assets_migration.rs b/substrate/frame/assets/src/foreign_assets_migration.rs index f8cf36a90249..6894f68b8118 100644 --- a/substrate/frame/assets/src/foreign_assets_migration.rs +++ b/substrate/frame/assets/src/foreign_assets_migration.rs @@ -18,87 +18,95 @@ //! This migration is meant to upgrade the XCM version of asset locations from V3 to V4. //! It's only needed if the `AssetId` for this pallet is `VersionedLocation` -use crate::pallet::{Config, Asset}; +use crate::pallet::{Asset, Config}; use frame_support::{ - migrations::{SteppedMigration, SteppedMigrationError}, - pallet_prelude::PhantomData, - weights::WeightMeter, - Hashable, + migrations::{SteppedMigration, SteppedMigrationError}, + pallet_prelude::PhantomData, + weights::WeightMeter, + Hashable, }; // TODO: Move this further up. mod identifier { - use codec::{MaxEncodedLen, Encode, Decode}; + use codec::{Decode, Encode, MaxEncodedLen}; - #[derive(MaxEncodedLen, Encode, Decode)] - pub struct MigrationIdentifier { - pub pallet_identifier: [u8; 16], - pub version_from: u8, - pub version_to: u8, - } + #[derive(MaxEncodedLen, Encode, Decode)] + pub struct MigrationIdentifier { + pub pallet_identifier: [u8; 16], + pub version_from: u8, + pub version_to: u8, + } - pub const PALLET_MIGRATIONS_ID: &[u8; 13] = b"pallet-assets"; + pub const PALLET_MIGRATIONS_ID: &[u8; 13] = b"pallet-assets"; } use identifier::*; /// Storage aliases for on-chain storage types before running the migration. mod old { - use super::Config; - use crate::pallet::Pallet; - use crate::types::{AssetDetails, DepositBalanceOf}; - use frame_support::{storage_alias, Blake2_128Concat}; + use super::Config; + use crate::{ + pallet::Pallet, + types::{AssetDetails, DepositBalanceOf}, + }; + use frame_support::{storage_alias, Blake2_128Concat}; - /// The storage item we are migrating from. - #[storage_alias] - pub(super) type Asset, I: 'static> = StorageMap< - Pallet, - Blake2_128Concat, - xcm::v3::Location, - AssetDetails<>::Balance, ::AccountId, DepositBalanceOf>, - >; + /// The storage item we are migrating from. + #[storage_alias] + pub(super) type Asset, I: 'static> = StorageMap< + Pallet, + Blake2_128Concat, + xcm::v3::Location, + AssetDetails< + >::Balance, + ::AccountId, + DepositBalanceOf, + >, + >; } pub struct MigrateForeignAssets, I: 'static>(PhantomData<(T, I)>); -impl, I: 'static> SteppedMigration for MigrateForeignAssets { - type Cursor = T::AssetId; - type Identifier = MigrationIdentifier; +impl, I: 'static> SteppedMigration + for MigrateForeignAssets +{ + type Cursor = T::AssetId; + type Identifier = MigrationIdentifier; - fn id() -> Self::Identifier { - MigrationIdentifier { - pallet_identifier: (*PALLET_MIGRATIONS_ID).twox_128(), - version_from: 0, - version_to: 1, - } - } + fn id() -> Self::Identifier { + MigrationIdentifier { + pallet_identifier: (*PALLET_MIGRATIONS_ID).twox_128(), + version_from: 0, + version_to: 1, + } + } - // TODO: For now I'm letting it run forever, check. - fn max_steps() -> Option { - None - } + // TODO: For now I'm letting it run forever, check. + fn max_steps() -> Option { + None + } - fn step( - cursor: Option, - _meter: &mut WeightMeter, - ) -> Result, SteppedMigrationError> { - let mut iter = if let Some(last_key) = cursor { - // If a cursor is provided, start iterating from the value corresponding - // to the last key processed in the previous step of the migration. - old::Asset::::iter_from(old::Asset::::hashed_key_for(last_key)) - } else { - // If there is no cursor, start iterating from the beginning. - old::Asset::::iter() - }; + fn step( + cursor: Option, + _meter: &mut WeightMeter, + ) -> Result, SteppedMigrationError> { + let mut iter = if let Some(last_key) = cursor { + // If a cursor is provided, start iterating from the value corresponding + // to the last key processed in the previous step of the migration. + old::Asset::::iter_from(old::Asset::::hashed_key_for(last_key)) + } else { + // If there is no cursor, start iterating from the beginning. + old::Asset::::iter() + }; - if let Some((key, _value)) = iter.next() { - // If there is a next item in the iterator, migrate it. - Asset::::remove(key); - // TODO: Insert the item with a V4 key. - // Return the processed key as the new cursor to continue the migration. - Ok(Some(key)) - } else { - // Signal the migration is complete. - Ok(None) - } - } + if let Some((key, _value)) = iter.next() { + // If there is a next item in the iterator, migrate it. + Asset::::remove(key); + // TODO: Insert the item with a V4 key. + // Return the processed key as the new cursor to continue the migration. + Ok(Some(key)) + } else { + // Signal the migration is complete. + Ok(None) + } + } } diff --git a/substrate/frame/assets/src/lib.rs b/substrate/frame/assets/src/lib.rs index 650830cff917..4a55cef5a3cf 100644 --- a/substrate/frame/assets/src/lib.rs +++ b/substrate/frame/assets/src/lib.rs @@ -152,8 +152,8 @@ #[cfg(feature = "runtime-benchmarks")] pub mod benchmarking; -pub mod migration; pub mod foreign_assets_migration; // TODO: move to `migrations` mod +pub mod migration; #[cfg(test)] pub mod mock; #[cfg(test)] From f0356f0d0338f532ddf144a2d1f07e8bff923f95 Mon Sep 17 00:00:00 2001 From: Francisco Aguirre Date: Wed, 26 Jun 2024 20:55:12 +0200 Subject: [PATCH 03/32] feat(assets-common): add foreign assets migration --- Cargo.lock | 3 + .../assets/asset-hub-rococo/src/lib.rs | 64 +--------------- .../assets/asset-hub-rococo/src/tests/mod.rs | 74 +++++++++++++++++++ .../runtimes/assets/common/Cargo.toml | 9 +++ .../src/foreign_assets_migration/mod.rs | 15 ++-- .../src/foreign_assets_migration/tests.rs | 55 ++++++++++++++ .../runtimes/assets/common/src/lib.rs | 1 + substrate/frame/assets/src/lib.rs | 3 +- substrate/frame/assets/src/types.rs | 2 +- 9 files changed, 156 insertions(+), 70 deletions(-) create mode 100644 cumulus/parachains/runtimes/assets/asset-hub-rococo/src/tests/mod.rs rename substrate/frame/assets/src/foreign_assets_migration.rs => cumulus/parachains/runtimes/assets/common/src/foreign_assets_migration/mod.rs (93%) create mode 100644 cumulus/parachains/runtimes/assets/common/src/foreign_assets_migration/tests.rs diff --git a/Cargo.lock b/Cargo.lock index f92ddaa56d54..3fb3a9ed0ed0 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1079,9 +1079,12 @@ version = "0.7.0" dependencies = [ "cumulus-primitives-core", "frame-support", + "frame-system", "impl-trait-for-tuples", "log", "pallet-asset-conversion", + "pallet-assets", + "pallet-balances", "pallet-xcm", "parachains-common", "parity-scale-codec", diff --git a/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/lib.rs b/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/lib.rs index aeef3c70dea5..41ae6f002c57 100644 --- a/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/lib.rs +++ b/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/lib.rs @@ -86,6 +86,9 @@ use xcm_config::{ TrustBackedAssetsConvertedConcreteId, TrustBackedAssetsPalletLocationV3, }; +#[cfg(test)] +mod tests; + #[cfg(any(feature = "std", test))] pub use sp_runtime::BuildStorage; @@ -1790,64 +1793,3 @@ cumulus_pallet_parachain_system::register_validate_block! { Runtime = Runtime, BlockExecutor = cumulus_pallet_aura_ext::BlockExecutor::, } - -#[cfg(test)] -mod tests { - use super::*; - use crate::{CENTS, MILLICENTS}; - use sp_runtime::traits::Zero; - use sp_weights::WeightToFee; - use testnet_parachains_constants::rococo::fee; - - /// We can fit at least 1000 transfers in a block. - #[test] - fn sane_block_weight() { - use pallet_balances::WeightInfo; - let block = RuntimeBlockWeights::get().max_block; - let base = RuntimeBlockWeights::get().get(DispatchClass::Normal).base_extrinsic; - let transfer = - base + weights::pallet_balances::WeightInfo::::transfer_allow_death(); - - let fit = block.checked_div_per_component(&transfer).unwrap_or_default(); - assert!(fit >= 1000, "{} should be at least 1000", fit); - } - - /// The fee for one transfer is at most 1 CENT. - #[test] - fn sane_transfer_fee() { - use pallet_balances::WeightInfo; - let base = RuntimeBlockWeights::get().get(DispatchClass::Normal).base_extrinsic; - let transfer = - base + weights::pallet_balances::WeightInfo::::transfer_allow_death(); - - let fee: Balance = fee::WeightToFee::weight_to_fee(&transfer); - assert!(fee <= CENTS, "{} MILLICENTS should be at most 1000", fee / MILLICENTS); - } - - /// Weight is being charged for both dimensions. - #[test] - fn weight_charged_for_both_components() { - let fee: Balance = fee::WeightToFee::weight_to_fee(&Weight::from_parts(10_000, 0)); - assert!(!fee.is_zero(), "Charges for ref time"); - - let fee: Balance = fee::WeightToFee::weight_to_fee(&Weight::from_parts(0, 10_000)); - assert_eq!(fee, CENTS, "10kb maps to CENT"); - } - - /// Filling up a block by proof size is at most 30 times more expensive than ref time. - /// - /// This is just a sanity check. - #[test] - fn full_block_fee_ratio() { - let block = RuntimeBlockWeights::get().max_block; - let time_fee: Balance = - fee::WeightToFee::weight_to_fee(&Weight::from_parts(block.ref_time(), 0)); - let proof_fee: Balance = - fee::WeightToFee::weight_to_fee(&Weight::from_parts(0, block.proof_size())); - - let proof_o_time = proof_fee.checked_div(time_fee).unwrap_or_default(); - assert!(proof_o_time <= 30, "{} should be at most 30", proof_o_time); - let time_o_proof = time_fee.checked_div(proof_fee).unwrap_or_default(); - assert!(time_o_proof <= 30, "{} should be at most 30", time_o_proof); - } -} diff --git a/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/tests/mod.rs b/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/tests/mod.rs new file mode 100644 index 000000000000..f534ddba2630 --- /dev/null +++ b/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/tests/mod.rs @@ -0,0 +1,74 @@ +// Copyright (C) Parity Technologies (UK) Ltd. +// SPDX-License-Identifier: Apache-2.0 + +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +//! # Tests for the Rococo runtime. + +use super::*; +use crate::{CENTS, MILLICENTS}; +use sp_runtime::traits::Zero; +use sp_weights::WeightToFee; +use testnet_parachains_constants::rococo::fee; + +/// We can fit at least 1000 transfers in a block. +#[test] +fn sane_block_weight() { + use pallet_balances::WeightInfo; + let block = RuntimeBlockWeights::get().max_block; + let base = RuntimeBlockWeights::get().get(DispatchClass::Normal).base_extrinsic; + let transfer = + base + weights::pallet_balances::WeightInfo::::transfer_allow_death(); + + let fit = block.checked_div_per_component(&transfer).unwrap_or_default(); + assert!(fit >= 1000, "{} should be at least 1000", fit); +} + +/// The fee for one transfer is at most 1 CENT. +#[test] +fn sane_transfer_fee() { + use pallet_balances::WeightInfo; + let base = RuntimeBlockWeights::get().get(DispatchClass::Normal).base_extrinsic; + let transfer = + base + weights::pallet_balances::WeightInfo::::transfer_allow_death(); + + let fee: Balance = fee::WeightToFee::weight_to_fee(&transfer); + assert!(fee <= CENTS, "{} MILLICENTS should be at most 1000", fee / MILLICENTS); +} + +/// Weight is being charged for both dimensions. +#[test] +fn weight_charged_for_both_components() { + let fee: Balance = fee::WeightToFee::weight_to_fee(&Weight::from_parts(10_000, 0)); + assert!(!fee.is_zero(), "Charges for ref time"); + + let fee: Balance = fee::WeightToFee::weight_to_fee(&Weight::from_parts(0, 10_000)); + assert_eq!(fee, CENTS, "10kb maps to CENT"); +} + +/// Filling up a block by proof size is at most 30 times more expensive than ref time. +/// +/// This is just a sanity check. +#[test] +fn full_block_fee_ratio() { + let block = RuntimeBlockWeights::get().max_block; + let time_fee: Balance = + fee::WeightToFee::weight_to_fee(&Weight::from_parts(block.ref_time(), 0)); + let proof_fee: Balance = + fee::WeightToFee::weight_to_fee(&Weight::from_parts(0, block.proof_size())); + + let proof_o_time = proof_fee.checked_div(time_fee).unwrap_or_default(); + assert!(proof_o_time <= 30, "{} should be at most 30", proof_o_time); + let time_o_proof = time_fee.checked_div(proof_fee).unwrap_or_default(); + assert!(time_o_proof <= 30, "{} should be at most 30", time_o_proof); +} diff --git a/cumulus/parachains/runtimes/assets/common/Cargo.toml b/cumulus/parachains/runtimes/assets/common/Cargo.toml index 94612506f510..f455ff8b1087 100644 --- a/cumulus/parachains/runtimes/assets/common/Cargo.toml +++ b/cumulus/parachains/runtimes/assets/common/Cargo.toml @@ -17,9 +17,12 @@ impl-trait-for-tuples = { workspace = true } # Substrate frame-support = { workspace = true } +frame-system = { workspace = true } sp-api = { workspace = true } sp-std = { workspace = true } sp-runtime = { workspace = true } +pallet-balances = { workspace = true } +pallet-assets = { workspace = true } pallet-asset-conversion = { workspace = true } # Polkadot @@ -52,6 +55,9 @@ std = [ "xcm-builder/std", "xcm-executor/std", "xcm/std", + "frame-system/std", + "pallet-assets/std", + "pallet-balances/std", ] runtime-benchmarks = [ @@ -63,4 +69,7 @@ runtime-benchmarks = [ "sp-runtime/runtime-benchmarks", "xcm-builder/runtime-benchmarks", "xcm-executor/runtime-benchmarks", + "frame-system/runtime-benchmarks", + "pallet-assets/runtime-benchmarks", + "pallet-balances/runtime-benchmarks", ] diff --git a/substrate/frame/assets/src/foreign_assets_migration.rs b/cumulus/parachains/runtimes/assets/common/src/foreign_assets_migration/mod.rs similarity index 93% rename from substrate/frame/assets/src/foreign_assets_migration.rs rename to cumulus/parachains/runtimes/assets/common/src/foreign_assets_migration/mod.rs index 6894f68b8118..8c37ba5dc824 100644 --- a/substrate/frame/assets/src/foreign_assets_migration.rs +++ b/cumulus/parachains/runtimes/assets/common/src/foreign_assets_migration/mod.rs @@ -18,7 +18,7 @@ //! This migration is meant to upgrade the XCM version of asset locations from V3 to V4. //! It's only needed if the `AssetId` for this pallet is `VersionedLocation` -use crate::pallet::{Asset, Config}; +use pallet_assets::{Asset, Config}; use frame_support::{ migrations::{SteppedMigration, SteppedMigrationError}, pallet_prelude::PhantomData, @@ -26,6 +26,9 @@ use frame_support::{ Hashable, }; +#[cfg(test)] +mod tests; + // TODO: Move this further up. mod identifier { use codec::{Decode, Encode, MaxEncodedLen}; @@ -45,9 +48,9 @@ use identifier::*; /// Storage aliases for on-chain storage types before running the migration. mod old { use super::Config; - use crate::{ - pallet::Pallet, - types::{AssetDetails, DepositBalanceOf}, + use pallet_assets::{ + Pallet, + AssetDetails, DepositBalanceOf, }; use frame_support::{storage_alias, Blake2_128Concat}; @@ -65,9 +68,9 @@ mod old { >; } -pub struct MigrateForeignAssets, I: 'static>(PhantomData<(T, I)>); +pub struct Migration, I: 'static>(PhantomData<(T, I)>); impl, I: 'static> SteppedMigration - for MigrateForeignAssets + for Migration { type Cursor = T::AssetId; type Identifier = MigrationIdentifier; diff --git a/cumulus/parachains/runtimes/assets/common/src/foreign_assets_migration/tests.rs b/cumulus/parachains/runtimes/assets/common/src/foreign_assets_migration/tests.rs new file mode 100644 index 000000000000..e35a625ad9e4 --- /dev/null +++ b/cumulus/parachains/runtimes/assets/common/src/foreign_assets_migration/tests.rs @@ -0,0 +1,55 @@ +// Copyright (C) Parity Technologies (UK) Ltd. +// SPDX-License-Identifier: Apache-2.0 + +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +//! Tests for the foreign assets migration. + +use frame_support::{derive_impl, construct_runtime, traits::AsEnsureOriginWithArg}; +use frame_system::{EnsureRoot, EnsureSigned}; + +construct_runtime! { + pub struct Runtime { + System: frame_system, + Balances: pallet_balances, + Assets: pallet_assets, + } +} + +type Block = frame_system::mocking::MockBlock; +type AccountId = u64; +type Balance = u64; + +#[derive_impl(frame_system::config_preludes::TestDefaultConfig)] +impl frame_system::Config for Runtime { + type Block = Block; + type AccountData = pallet_balances::AccountData; +} + +#[derive_impl(pallet_balances::config_preludes::TestDefaultConfig)] +impl pallet_balances::Config for Runtime { + type AccountStore = System; +} + +#[derive_impl(pallet_assets::config_preludes::TestDefaultConfig)] +impl pallet_assets::Config for Runtime { + type Currency = Balances; + type CreateOrigin = AsEnsureOriginWithArg>; + type ForceOrigin = EnsureRoot; + type Freezer = (); +} + +#[test] +fn migration_works() { + +} diff --git a/cumulus/parachains/runtimes/assets/common/src/lib.rs b/cumulus/parachains/runtimes/assets/common/src/lib.rs index 431b5766147a..e31edb7167d9 100644 --- a/cumulus/parachains/runtimes/assets/common/src/lib.rs +++ b/cumulus/parachains/runtimes/assets/common/src/lib.rs @@ -22,6 +22,7 @@ pub mod fungible_conversion; pub mod local_and_foreign_assets; pub mod matching; pub mod runtime_api; +pub mod foreign_assets_migration; use crate::matching::{LocalLocationPattern, ParentLocation}; use frame_support::traits::{Equals, EverythingBut}; diff --git a/substrate/frame/assets/src/lib.rs b/substrate/frame/assets/src/lib.rs index 4a55cef5a3cf..2b9e81a9d767 100644 --- a/substrate/frame/assets/src/lib.rs +++ b/substrate/frame/assets/src/lib.rs @@ -152,7 +152,6 @@ #[cfg(feature = "runtime-benchmarks")] pub mod benchmarking; -pub mod foreign_assets_migration; // TODO: move to `migrations` mod pub mod migration; #[cfg(test)] pub mod mock; @@ -374,7 +373,7 @@ pub mod pallet { #[pallet::storage] /// Details of an asset. - pub(super) type Asset, I: 'static = ()> = StorageMap< + pub type Asset, I: 'static = ()> = StorageMap< _, Blake2_128Concat, T::AssetId, diff --git a/substrate/frame/assets/src/types.rs b/substrate/frame/assets/src/types.rs index 11edc7d3fcb5..4332a7aec4e5 100644 --- a/substrate/frame/assets/src/types.rs +++ b/substrate/frame/assets/src/types.rs @@ -24,7 +24,7 @@ use frame_support::{ }; use sp_runtime::{traits::Convert, FixedPointNumber, FixedU128}; -pub(super) type DepositBalanceOf = +pub type DepositBalanceOf = <>::Currency as Currency<::AccountId>>::Balance; pub(super) type AssetAccountOf = AssetAccount< >::Balance, From ca8c876f2564cf19165f4e090a5a7a82dd0d3a5b Mon Sep 17 00:00:00 2001 From: Francisco Aguirre Date: Mon, 1 Jul 2024 19:21:54 +0200 Subject: [PATCH 04/32] feat(foreign-assets-migration): move to assets common --- Cargo.lock | 10 ++- .../assets/asset-hub-rococo/src/lib.rs | 48 +++++++------- .../assets/asset-hub-rococo/src/xcm_config.rs | 15 ++--- .../runtimes/assets/common/Cargo.toml | 5 ++ .../src/foreign_assets_migration/mod.rs | 29 +++++---- .../src/foreign_assets_migration/tests.rs | 63 ++++++++++++++++++- substrate/frame/assets/src/types.rs | 26 ++++---- 7 files changed, 133 insertions(+), 63 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 3fb3a9ed0ed0..bde861d8d997 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1080,6 +1080,7 @@ dependencies = [ "cumulus-primitives-core", "frame-support", "frame-system", + "hex-display", "impl-trait-for-tuples", "log", "pallet-asset-conversion", @@ -1090,6 +1091,7 @@ dependencies = [ "parity-scale-codec", "scale-info", "sp-api", + "sp-io", "sp-runtime", "sp-std 14.0.0", "staging-xcm", @@ -6783,6 +6785,12 @@ version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "212ab92002354b4819390025006c897e8140934349e8635c9b077f47b4dcbd20" +[[package]] +name = "hex-display" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b53d6a634507c5d9fdee77261ae54a8d1ff7887f5304389025b03c3292a1756" + [[package]] name = "hex-literal" version = "0.4.1" @@ -15736,7 +15744,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "22505a5c94da8e3b7c2996394d1c933236c4d743e81a410bcca4e6989fc066a4" dependencies = [ "bytes", - "heck 0.4.1", + "heck 0.5.0", "itertools 0.11.0", "log", "multimap", diff --git a/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/lib.rs b/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/lib.rs index 41ae6f002c57..a234de111acf 100644 --- a/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/lib.rs +++ b/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/lib.rs @@ -82,8 +82,8 @@ use sp_runtime::{Perbill, RuntimeDebug}; use testnet_parachains_constants::rococo::{consensus::*, currency::*, fee::WeightToFee, time::*}; use xcm_config::{ ForeignAssetsConvertedConcreteId, ForeignCreatorsSovereignAccountOf, GovernanceLocation, - PoolAssetsConvertedConcreteId, TokenLocation, TokenLocationV3, - TrustBackedAssetsConvertedConcreteId, TrustBackedAssetsPalletLocationV3, + PoolAssetsConvertedConcreteId, TokenLocation, + TrustBackedAssetsConvertedConcreteId, TrustBackedAssetsPalletLocation, }; #[cfg(test)] @@ -193,7 +193,7 @@ impl pallet_migrations::Config for Runtime { } type MultiBlockMigrations = ( - pallet_assets::foreign_assets_migration::MigrateForeignAssets, + assets_common::foreign_assets_migration::Migration, ); impl pallet_timestamp::Config for Runtime { @@ -343,11 +343,11 @@ pub type LocalAndForeignAssets = fungibles::UnionOf< Assets, ForeignAssets, LocalFromLeft< - AssetIdForTrustBackedAssetsConvert, + AssetIdForTrustBackedAssetsConvert, AssetIdForTrustBackedAssets, - xcm::v3::Location, + xcm::v4::Location, >, - xcm::v3::Location, + xcm::v4::Location, AccountId, >; @@ -355,25 +355,25 @@ pub type LocalAndForeignAssets = fungibles::UnionOf< pub type NativeAndAssets = fungible::UnionOf< Balances, LocalAndForeignAssets, - TargetFromLeft, - xcm::v3::Location, + TargetFromLeft, + xcm::v4::Location, AccountId, >; pub type PoolIdToAccountId = pallet_asset_conversion::AccountIdConverter< AssetConversionPalletId, - (xcm::v3::Location, xcm::v3::Location), + (xcm::v4::Location, xcm::v4::Location), >; impl pallet_asset_conversion::Config for Runtime { type RuntimeEvent = RuntimeEvent; type Balance = Balance; type HigherPrecisionBalance = sp_core::U256; - type AssetKind = xcm::v3::Location; + type AssetKind = xcm::v4::Location; type Assets = NativeAndAssets; type PoolId = (Self::AssetKind, Self::AssetKind); type PoolLocator = pallet_asset_conversion::WithFirstAsset< - TokenLocationV3, + TokenLocation, AccountId, Self::AssetKind, PoolIdToAccountId, @@ -381,7 +381,7 @@ impl pallet_asset_conversion::Config for Runtime { type PoolAssetId = u32; type PoolAssets = PoolAssets; type PoolSetupFee = ConstU128<0>; // Asset class deposit fees are sufficient to prevent spam - type PoolSetupFeeAsset = TokenLocationV3; + type PoolSetupFeeAsset = TokenLocation; type PoolSetupFeeTarget = ResolveAssetTo; type LiquidityWithdrawalFee = LiquidityWithdrawalFee; type LPFee = ConstU32<3>; @@ -391,10 +391,10 @@ impl pallet_asset_conversion::Config for Runtime { type WeightInfo = weights::pallet_asset_conversion::WeightInfo; #[cfg(feature = "runtime-benchmarks")] type BenchmarkHelper = assets_common::benchmarks::AssetPairFactory< - TokenLocationV3, + TokenLocation, parachain_info::Pallet, xcm_config::TrustBackedAssetsPalletIndex, - xcm::v3::Location, + xcm::v4::Location, >; } @@ -428,17 +428,17 @@ pub type ForeignAssetsInstance = pallet_assets::Instance2; impl pallet_assets::Config for Runtime { type RuntimeEvent = RuntimeEvent; type Balance = Balance; - type AssetId = xcm::v3::Location; // TODO: This is what I want to migrate to V4. - type AssetIdParameter = xcm::v3::Location; + type AssetId = xcm::v4::Location; + type AssetIdParameter = xcm::v4::Location; type Currency = Balances; type CreateOrigin = ForeignCreators< ( - FromSiblingParachain, xcm::v3::Location>, - FromNetwork, + FromSiblingParachain, xcm::v4::Location>, + FromNetwork, ), ForeignCreatorsSovereignAccountOf, AccountId, - xcm::v3::Location, + xcm::v4::Location, >; type ForceOrigin = AssetsForceOrigin; type AssetDeposit = ForeignAssetsAssetDeposit; @@ -821,7 +821,7 @@ impl pallet_asset_conversion_tx_payment::Config for Runtime { type RuntimeEvent = RuntimeEvent; type Fungibles = LocalAndForeignAssets; type OnChargeAssetTransaction = - AssetConversionAdapter; + AssetConversionAdapter; } parameter_types! { @@ -1246,16 +1246,16 @@ impl_runtime_apis! { impl pallet_asset_conversion::AssetConversionApi< Block, Balance, - xcm::v3::Location, + xcm::v4::Location, > for Runtime { - fn quote_price_exact_tokens_for_tokens(asset1: xcm::v3::Location, asset2: xcm::v3::Location, amount: Balance, include_fee: bool) -> Option { + fn quote_price_exact_tokens_for_tokens(asset1: xcm::v4::Location, asset2: xcm::v4::Location, amount: Balance, include_fee: bool) -> Option { AssetConversion::quote_price_exact_tokens_for_tokens(asset1, asset2, amount, include_fee) } - fn quote_price_tokens_for_exact_tokens(asset1: xcm::v3::Location, asset2: xcm::v3::Location, amount: Balance, include_fee: bool) -> Option { + fn quote_price_tokens_for_exact_tokens(asset1: xcm::v4::Location, asset2: xcm::v4::Location, amount: Balance, include_fee: bool) -> Option { AssetConversion::quote_price_tokens_for_exact_tokens(asset1, asset2, amount, include_fee) } - fn get_reserves(asset1: xcm::v3::Location, asset2: xcm::v3::Location) -> Option<(Balance, Balance)> { + fn get_reserves(asset1: xcm::v4::Location, asset2: xcm::v4::Location) -> Option<(Balance, Balance)> { AssetConversion::get_reserves(asset1, asset2).ok() } } diff --git a/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/xcm_config.rs b/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/xcm_config.rs index cf5a3905e581..6b9bf63958b5 100644 --- a/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/xcm_config.rs +++ b/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/xcm_config.rs @@ -65,7 +65,6 @@ use xcm_executor::XcmExecutor; parameter_types! { pub const TokenLocation: Location = Location::parent(); - pub const TokenLocationV3: xcm::v3::Location = xcm::v3::Location::parent(); pub const RelayNetwork: NetworkId = NetworkId::Rococo; pub RelayChainOrigin: RuntimeOrigin = cumulus_pallet_xcm::Origin::Relay.into(); pub UniversalLocation: InteriorLocation = @@ -74,8 +73,6 @@ parameter_types! { pub TrustBackedAssetsPalletLocation: Location = PalletInstance(TrustBackedAssetsPalletIndex::get()).into(); pub TrustBackedAssetsPalletIndex: u8 = ::index() as u8; - pub TrustBackedAssetsPalletLocationV3: xcm::v3::Location = - xcm::v3::Junction::PalletInstance(::index() as u8).into(); pub ForeignAssetsPalletLocation: Location = PalletInstance(::index() as u8).into(); pub PoolAssetsPalletLocation: Location = @@ -177,7 +174,7 @@ pub type ForeignAssetsConvertedConcreteId = assets_common::ForeignAssetsConverte StartsWithExplicitGlobalConsensus, ), Balance, - xcm::v3::Location, + xcm::v4::Location, >; /// Means for transacting foreign assets from different global consensus. @@ -360,7 +357,7 @@ impl xcm_executor::Config for XcmConfig { ResolveTo, >, cumulus_primitives_utility::SwapFirstAssetTrader< - TokenLocationV3, + TokenLocation, crate::AssetConversion, WeightToFee, crate::NativeAndAssets, @@ -368,7 +365,7 @@ impl xcm_executor::Config for XcmConfig { TrustBackedAssetsAsLocation< TrustBackedAssetsPalletLocation, Balance, - xcm::v3::Location, + xcm::v4::Location, >, ForeignAssetsConvertedConcreteId, ), @@ -501,9 +498,9 @@ pub type ForeignCreatorsSovereignAccountOf = ( /// Simple conversion of `u32` into an `AssetId` for use in benchmarking. pub struct XcmBenchmarkHelper; #[cfg(feature = "runtime-benchmarks")] -impl pallet_assets::BenchmarkHelper for XcmBenchmarkHelper { - fn create_asset_id_parameter(id: u32) -> xcm::v3::Location { - xcm::v3::Location::new(1, [xcm::v3::Junction::Parachain(id)]) +impl pallet_assets::BenchmarkHelper for XcmBenchmarkHelper { + fn create_asset_id_parameter(id: u32) -> xcm::v4::Location { + xcm::v4::Location::new(1, [xcm::v4::Junction::Parachain(id)]) } } diff --git a/cumulus/parachains/runtimes/assets/common/Cargo.toml b/cumulus/parachains/runtimes/assets/common/Cargo.toml index f455ff8b1087..5b87c450b90f 100644 --- a/cumulus/parachains/runtimes/assets/common/Cargo.toml +++ b/cumulus/parachains/runtimes/assets/common/Cargo.toml @@ -35,6 +35,10 @@ xcm-executor = { workspace = true } parachains-common = { workspace = true } cumulus-primitives-core = { workspace = true } +[dev-dependencies] +sp-io = { workspace = true } +hex-display = "0.3.0" + [build-dependencies] substrate-wasm-builder = { workspace = true, default-features = true } @@ -58,6 +62,7 @@ std = [ "frame-system/std", "pallet-assets/std", "pallet-balances/std", + "sp-io/std", ] runtime-benchmarks = [ diff --git a/cumulus/parachains/runtimes/assets/common/src/foreign_assets_migration/mod.rs b/cumulus/parachains/runtimes/assets/common/src/foreign_assets_migration/mod.rs index 8c37ba5dc824..3c40f3257a63 100644 --- a/cumulus/parachains/runtimes/assets/common/src/foreign_assets_migration/mod.rs +++ b/cumulus/parachains/runtimes/assets/common/src/foreign_assets_migration/mod.rs @@ -46,7 +46,7 @@ mod identifier { use identifier::*; /// Storage aliases for on-chain storage types before running the migration. -mod old { +pub mod old { use super::Config; use pallet_assets::{ Pallet, @@ -68,11 +68,11 @@ mod old { >; } -pub struct Migration, I: 'static>(PhantomData<(T, I)>); -impl, I: 'static> SteppedMigration +pub struct Migration, I: 'static = ()>(PhantomData<(T, I)>); +impl, I: 'static> SteppedMigration for Migration { - type Cursor = T::AssetId; + type Cursor = xcm::v3::Location; type Identifier = MigrationIdentifier; fn id() -> Self::Identifier { @@ -83,11 +83,6 @@ impl, I: 'static> SteppedMigration } } - // TODO: For now I'm letting it run forever, check. - fn max_steps() -> Option { - None - } - fn step( cursor: Option, _meter: &mut WeightMeter, @@ -101,11 +96,19 @@ impl, I: 'static> SteppedMigration old::Asset::::iter() }; - if let Some((key, _value)) = iter.next() { + if let Some((key, value)) = iter.next() { // If there is a next item in the iterator, migrate it. - Asset::::remove(key); - // TODO: Insert the item with a V4 key. - // Return the processed key as the new cursor to continue the migration. + old::Asset::::remove(key.clone()); + // Most likely all locations will be able to be converted, but if they can't + // we log them to try again later. + let maybe_new_key: Result = key.try_into(); + if let Ok(new_key) = maybe_new_key { + Asset::::insert(new_key.clone(), value); + log::info!(target: "migration", "Successfully migrated key: {:?}", new_key); + } else { + log::warn!(target: "migration", "{:?} couldn't be converted to V4", key); + } + // Return the key as the new cursor to continue the migration. Ok(Some(key)) } else { // Signal the migration is complete. diff --git a/cumulus/parachains/runtimes/assets/common/src/foreign_assets_migration/tests.rs b/cumulus/parachains/runtimes/assets/common/src/foreign_assets_migration/tests.rs index e35a625ad9e4..e38009efd679 100644 --- a/cumulus/parachains/runtimes/assets/common/src/foreign_assets_migration/tests.rs +++ b/cumulus/parachains/runtimes/assets/common/src/foreign_assets_migration/tests.rs @@ -15,14 +15,28 @@ //! Tests for the foreign assets migration. -use frame_support::{derive_impl, construct_runtime, traits::AsEnsureOriginWithArg}; +use codec::Encode; +use frame_support::{ + construct_runtime, derive_impl, + Hashable, + traits::AsEnsureOriginWithArg, + migrations::SteppedMigration, + weights::WeightMeter, +}; use frame_system::{EnsureRoot, EnsureSigned}; +use hex_display::HexDisplayExt; +use pallet_assets::{Asset, AssetDetails, AssetStatus}; +use sp_io::{hashing, storage, TestExternalities}; +use sp_runtime::BuildStorage; +use xcm::{v3, v4}; + +use super::{old, Migration}; construct_runtime! { pub struct Runtime { System: frame_system, Balances: pallet_balances, - Assets: pallet_assets, + ForeignAssets: pallet_assets, } } @@ -43,13 +57,56 @@ impl pallet_balances::Config for Runtime { #[derive_impl(pallet_assets::config_preludes::TestDefaultConfig)] impl pallet_assets::Config for Runtime { + type AssetId = v4::Location; // TODO: This is what we want to migrate to V4. + type AssetIdParameter = v4::Location; type Currency = Balances; type CreateOrigin = AsEnsureOriginWithArg>; type ForceOrigin = EnsureRoot; type Freezer = (); } +fn new_test_ext() -> TestExternalities { + let mut t = frame_system::GenesisConfig::::default().build_storage().unwrap(); + + let test_account = 1; + let initial_balance = 1000; + pallet_balances::GenesisConfig:: { + balances: vec![(test_account, initial_balance)], + }.assimilate_storage(&mut t).unwrap(); + + t.into() +} + #[test] fn migration_works() { - + new_test_ext().execute_with(|| { + let key = v3::Location::new(1, [v3::Junction::Parachain(2004)]); + let mock_asset_details = mock_asset_details(); + old::Asset::::insert(key.clone(), mock_asset_details); + + // Perform one step of the migration. + let cursor = Migration::::step(None, &mut WeightMeter::new()).unwrap().unwrap(); + // Second time works. + assert!(Migration::::step(Some(cursor), &mut WeightMeter::new()).unwrap().is_none()); + + let new_key = v4::Location::new(1, [v4::Junction::Parachain(2004)]); + assert!(Asset::::contains_key(new_key)); + }) +} + +fn mock_asset_details() -> AssetDetails { + AssetDetails { + owner: 0, + issuer: 0, + admin: 0, + freezer: 0, + supply: 0, + deposit: 0, + min_balance: 1, + is_sufficient: false, + accounts: 0, + sufficients: 0, + approvals: 0, + status: AssetStatus::Live, + } } diff --git a/substrate/frame/assets/src/types.rs b/substrate/frame/assets/src/types.rs index 4332a7aec4e5..613e7eb53996 100644 --- a/substrate/frame/assets/src/types.rs +++ b/substrate/frame/assets/src/types.rs @@ -38,7 +38,7 @@ pub(super) type ExistenceReasonOf = /// AssetStatus holds the current state of the asset. It could either be Live and available for use, /// or in a Destroying state. #[derive(Clone, Encode, Decode, Eq, PartialEq, RuntimeDebug, MaxEncodedLen, TypeInfo)] -pub(super) enum AssetStatus { +pub enum AssetStatus { /// The asset is active and able to be used. Live, /// Whether the asset is frozen for non-admin transfers. @@ -51,30 +51,30 @@ pub(super) enum AssetStatus { #[derive(Clone, Encode, Decode, Eq, PartialEq, RuntimeDebug, MaxEncodedLen, TypeInfo)] pub struct AssetDetails { /// Can change `owner`, `issuer`, `freezer` and `admin` accounts. - pub(super) owner: AccountId, + pub owner: AccountId, /// Can mint tokens. - pub(super) issuer: AccountId, + pub issuer: AccountId, /// Can thaw tokens, force transfers and burn tokens from any account. - pub(super) admin: AccountId, + pub admin: AccountId, /// Can freeze tokens. - pub(super) freezer: AccountId, + pub freezer: AccountId, /// The total supply across all accounts. - pub(super) supply: Balance, + pub supply: Balance, /// The balance deposited for this asset. This pays for the data stored here. - pub(super) deposit: DepositBalance, + pub deposit: DepositBalance, /// The ED for virtual accounts. - pub(super) min_balance: Balance, + pub min_balance: Balance, /// If `true`, then any account with this asset is given a provider reference. Otherwise, it /// requires a consumer reference. - pub(super) is_sufficient: bool, + pub is_sufficient: bool, /// The total number of accounts. - pub(super) accounts: u32, + pub accounts: u32, /// The total number of accounts for which we have placed a self-sufficient reference. - pub(super) sufficients: u32, + pub sufficients: u32, /// The total number of approvals. - pub(super) approvals: u32, + pub approvals: u32, /// The status of the asset - pub(super) status: AssetStatus, + pub status: AssetStatus, } /// Data concerning an approval. From e2a53980a957f888207f106255bf1def88fd895a Mon Sep 17 00:00:00 2001 From: Francisco Aguirre Date: Mon, 29 Jul 2024 14:45:52 +0200 Subject: [PATCH 05/32] fix: another v3 -> v4 change --- .../chains/parachains/assets/asset-hub-rococo/src/lib.rs | 2 +- .../chains/parachains/assets/asset-hub-westend/src/lib.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/cumulus/parachains/integration-tests/emulated/chains/parachains/assets/asset-hub-rococo/src/lib.rs b/cumulus/parachains/integration-tests/emulated/chains/parachains/assets/asset-hub-rococo/src/lib.rs index 80d2376c6811..1f98d3ba964d 100644 --- a/cumulus/parachains/integration-tests/emulated/chains/parachains/assets/asset-hub-rococo/src/lib.rs +++ b/cumulus/parachains/integration-tests/emulated/chains/parachains/assets/asset-hub-rococo/src/lib.rs @@ -59,5 +59,5 @@ impl_accounts_helpers_for_parachain!(AssetHubRococo); impl_assert_events_helpers_for_parachain!(AssetHubRococo); impl_assets_helpers_for_system_parachain!(AssetHubRococo, Rococo); impl_assets_helpers_for_parachain!(AssetHubRococo); -impl_foreign_assets_helpers_for_parachain!(AssetHubRococo, xcm::v3::Location); +impl_foreign_assets_helpers_for_parachain!(AssetHubRococo, xcm::v4::Location); impl_xcm_helpers_for_parachain!(AssetHubRococo); diff --git a/cumulus/parachains/integration-tests/emulated/chains/parachains/assets/asset-hub-westend/src/lib.rs b/cumulus/parachains/integration-tests/emulated/chains/parachains/assets/asset-hub-westend/src/lib.rs index 608690218d2f..6066adec52c3 100644 --- a/cumulus/parachains/integration-tests/emulated/chains/parachains/assets/asset-hub-westend/src/lib.rs +++ b/cumulus/parachains/integration-tests/emulated/chains/parachains/assets/asset-hub-westend/src/lib.rs @@ -59,5 +59,5 @@ impl_accounts_helpers_for_parachain!(AssetHubWestend); impl_assert_events_helpers_for_parachain!(AssetHubWestend); impl_assets_helpers_for_system_parachain!(AssetHubWestend, Westend); impl_assets_helpers_for_parachain!(AssetHubWestend); -impl_foreign_assets_helpers_for_parachain!(AssetHubWestend, xcm::v3::Location); +impl_foreign_assets_helpers_for_parachain!(AssetHubWestend, xcm::v4::Location); impl_xcm_helpers_for_parachain!(AssetHubWestend); From a656f4b34e7c99d41652b0b18b2f299e0eeb10be Mon Sep 17 00:00:00 2001 From: Francisco Aguirre Date: Wed, 31 Jul 2024 19:22:58 +0200 Subject: [PATCH 06/32] feat(assets-common-migrations): create a pallet for asset migrations --- Cargo.lock | 25 ++++++ Cargo.toml | 1 + .../runtimes/assets/migrations/Cargo.toml | 77 +++++++++++++++++++ .../runtimes/assets/migrations/src/lib.rs | 30 ++++++++ .../assets/migrations/src/v1/benchmarks.rs | 48 ++++++++++++ .../src/v1}/mod.rs | 72 ++++++++--------- .../src/v1}/tests.rs | 37 ++++----- 7 files changed, 235 insertions(+), 55 deletions(-) create mode 100644 cumulus/parachains/runtimes/assets/migrations/Cargo.toml create mode 100644 cumulus/parachains/runtimes/assets/migrations/src/lib.rs create mode 100644 cumulus/parachains/runtimes/assets/migrations/src/v1/benchmarks.rs rename cumulus/parachains/runtimes/assets/{common/src/foreign_assets_migration => migrations/src/v1}/mod.rs (72%) rename cumulus/parachains/runtimes/assets/{common/src/foreign_assets_migration => migrations/src/v1}/tests.rs (82%) diff --git a/Cargo.lock b/Cargo.lock index 29639cd9cbd8..c9ea1d3a1adf 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1130,6 +1130,31 @@ dependencies = [ "substrate-wasm-builder", ] +[[package]] +name = "assets-common-migrations" +version = "0.1.0" +dependencies = [ + "frame-benchmarking", + "frame-support", + "frame-system", + "hex-display", + "log", + "pallet-asset-conversion", + "pallet-assets", + "pallet-balances", + "pallet-xcm", + "parachains-common", + "parity-scale-codec", + "scale-info", + "sp-api", + "sp-io", + "sp-runtime", + "staging-xcm", + "staging-xcm-builder", + "staging-xcm-executor", + "substrate-wasm-builder", +] + [[package]] name = "async-attributes" version = "1.1.2" diff --git a/Cargo.toml b/Cargo.toml index 85f21be900bd..cc018f8cac77 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -117,6 +117,7 @@ members = [ "cumulus/parachains/runtimes/assets/asset-hub-rococo", "cumulus/parachains/runtimes/assets/asset-hub-westend", "cumulus/parachains/runtimes/assets/common", + "cumulus/parachains/runtimes/assets/migrations", "cumulus/parachains/runtimes/assets/test-utils", "cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo", "cumulus/parachains/runtimes/bridge-hubs/bridge-hub-westend", diff --git a/cumulus/parachains/runtimes/assets/migrations/Cargo.toml b/cumulus/parachains/runtimes/assets/migrations/Cargo.toml new file mode 100644 index 000000000000..c0296204df82 --- /dev/null +++ b/cumulus/parachains/runtimes/assets/migrations/Cargo.toml @@ -0,0 +1,77 @@ +[package] +name = "assets-common-migrations" +version = "0.1.0" +authors.workspace = true +edition.workspace = true +description = "Common migrations for assets" +license = "Apache-2.0" + +[lints] +workspace = true + +[dependencies] +codec = { features = ["derive"], workspace = true } +scale-info = { features = ["derive"], workspace = true } +log = { workspace = true } + +# Substrate +frame-support = { workspace = true } +frame-system = { workspace = true } +frame-benchmarking = { optional = true, workspace = true } +sp-api = { workspace = true } +sp-runtime = { workspace = true } +pallet-balances = { workspace = true } +pallet-assets = { workspace = true } +pallet-asset-conversion = { workspace = true } + +# Polkadot +pallet-xcm = { workspace = true } +xcm = { workspace = true } +xcm-builder = { workspace = true } +xcm-executor = { workspace = true } + +# Cumulus +parachains-common = { workspace = true } + +[dev-dependencies] +sp-io = { workspace = true } +hex-display = "0.3.0" + +[build-dependencies] +substrate-wasm-builder = { workspace = true, default-features = true } + +[features] +default = ["std"] +std = [ + "frame-benchmarking?/std", + "codec/std", + "frame-support/std", + "log/std", + "pallet-asset-conversion/std", + "pallet-xcm/std", + "parachains-common/std", + "scale-info/std", + "sp-api/std", + "sp-runtime/std", + "xcm-builder/std", + "xcm-executor/std", + "xcm/std", + "frame-system/std", + "pallet-assets/std", + "pallet-balances/std", + "sp-io/std", +] + +runtime-benchmarks = [ + "frame-benchmarking/runtime-benchmarks", + "frame-support/runtime-benchmarks", + "pallet-asset-conversion/runtime-benchmarks", + "pallet-xcm/runtime-benchmarks", + "parachains-common/runtime-benchmarks", + "sp-runtime/runtime-benchmarks", + "xcm-builder/runtime-benchmarks", + "xcm-executor/runtime-benchmarks", + "frame-system/runtime-benchmarks", + "pallet-assets/runtime-benchmarks", + "pallet-balances/runtime-benchmarks", +] diff --git a/cumulus/parachains/runtimes/assets/migrations/src/lib.rs b/cumulus/parachains/runtimes/assets/migrations/src/lib.rs new file mode 100644 index 000000000000..4915b9967bd1 --- /dev/null +++ b/cumulus/parachains/runtimes/assets/migrations/src/lib.rs @@ -0,0 +1,30 @@ +// Copyright (C) Parity Technologies (UK) Ltd. +// SPDX-License-Identifier: Apache-2.0 + +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +//! A utility pallet for migrating storage items in the asset hub runtimes. +//! It's only a pallet since the benchmarking machinery requires it. + +mod v1; + +pub use pallet::*; + +#[frame_support::pallet] +pub mod pallet { + #[pallet::pallet] + pub struct Pallet(_); + + #[pallet::config] + pub trait Config: frame_system::Config {} +} diff --git a/cumulus/parachains/runtimes/assets/migrations/src/v1/benchmarks.rs b/cumulus/parachains/runtimes/assets/migrations/src/v1/benchmarks.rs new file mode 100644 index 000000000000..d7959b693195 --- /dev/null +++ b/cumulus/parachains/runtimes/assets/migrations/src/v1/benchmarks.rs @@ -0,0 +1,48 @@ +// Copyright (C) Parity Technologies (UK) Ltd. +// SPDX-License-Identifier: Apache-2.0 + +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +//! Benchmarks for the foreign assets migration. + +use frame_benchmarking::v2::*; +use frame_support::{migrations::SteppedMigration, weights::WeightMeter}; +use pallet_assets::{Config, Asset}; +use xcm::{v3, v4}; + +use crate::Pallet; +use super::{old, Migration, mock_asset_details}; + +#[benchmarks] +mod benches { + use super::*; + + #[benchmark] + fn step() { + let key = v3::Location::new(1, [v3::Junction::Parachain(2004)]); + let mock_asset_details = mock_asset_details(); + dbg!(&std::any::type_name::<::AssetId>()); + // old::Asset::::insert(key.clone(), mock_asset_details); + + let mut meter = WeightMeter::new(); + #[block] + { + Migration::::step(None, &mut meter).unwrap(); + } + + // let new_key = v4::Location::new(1, [v4::Junction::Parachain(2004)]); + // assert!(Asset::::contains_key(new_key)); + } + + impl_benchmark_test_suite!(Pallet, crate::v1::tests::new_test_ext(), crate::v1::tests::Runtime); +} diff --git a/cumulus/parachains/runtimes/assets/common/src/foreign_assets_migration/mod.rs b/cumulus/parachains/runtimes/assets/migrations/src/v1/mod.rs similarity index 72% rename from cumulus/parachains/runtimes/assets/common/src/foreign_assets_migration/mod.rs rename to cumulus/parachains/runtimes/assets/migrations/src/v1/mod.rs index 3c40f3257a63..d0d73bf54fca 100644 --- a/cumulus/parachains/runtimes/assets/common/src/foreign_assets_migration/mod.rs +++ b/cumulus/parachains/runtimes/assets/migrations/src/v1/mod.rs @@ -1,5 +1,3 @@ -// This file is part of Substrate. - // Copyright (C) Parity Technologies (UK) Ltd. // SPDX-License-Identifier: Apache-2.0 @@ -15,39 +13,31 @@ // See the License for the specific language governing permissions and // limitations under the License. +//! V1 migration. +//! //! This migration is meant to upgrade the XCM version of asset locations from V3 to V4. //! It's only needed if the `AssetId` for this pallet is `VersionedLocation` -use pallet_assets::{Asset, Config}; +#[cfg(test)] +mod tests; + +#[cfg(feature = "runtime-benchmarks")] +mod benchmarks; + +use pallet_assets::{Asset, Config, AssetDetails, AssetStatus}; use frame_support::{ - migrations::{SteppedMigration, SteppedMigrationError}, + migrations::{MigrationId, SteppedMigration, SteppedMigrationError}, pallet_prelude::PhantomData, weights::WeightMeter, Hashable, }; +use xcm::{v3, v4}; -#[cfg(test)] -mod tests; - -// TODO: Move this further up. -mod identifier { - use codec::{Decode, Encode, MaxEncodedLen}; - - #[derive(MaxEncodedLen, Encode, Decode)] - pub struct MigrationIdentifier { - pub pallet_identifier: [u8; 16], - pub version_from: u8, - pub version_to: u8, - } - - pub const PALLET_MIGRATIONS_ID: &[u8; 13] = b"pallet-assets"; -} - -use identifier::*; +pub const PALLET_MIGRATIONS_ID: &[u8; 13] = b"pallet-assets"; /// Storage aliases for on-chain storage types before running the migration. pub mod old { - use super::Config; + use super::{Config, v3}; use pallet_assets::{ Pallet, AssetDetails, DepositBalanceOf, @@ -59,7 +49,7 @@ pub mod old { pub(super) type Asset, I: 'static> = StorageMap< Pallet, Blake2_128Concat, - xcm::v3::Location, + v3::Location, AssetDetails< >::Balance, ::AccountId, @@ -69,18 +59,14 @@ pub mod old { } pub struct Migration, I: 'static = ()>(PhantomData<(T, I)>); -impl, I: 'static> SteppedMigration +impl, I: 'static> SteppedMigration for Migration { - type Cursor = xcm::v3::Location; - type Identifier = MigrationIdentifier; + type Cursor = v3::Location; + type Identifier = MigrationId<13>; fn id() -> Self::Identifier { - MigrationIdentifier { - pallet_identifier: (*PALLET_MIGRATIONS_ID).twox_128(), - version_from: 0, - version_to: 1, - } + MigrationId { pallet_id: *PALLET_MIGRATIONS_ID, version_from: 0, version_to: 1 } } fn step( @@ -97,12 +83,11 @@ impl, I: 'static> SteppedMigration }; if let Some((key, value)) = iter.next() { - // If there is a next item in the iterator, migrate it. - old::Asset::::remove(key.clone()); // Most likely all locations will be able to be converted, but if they can't // we log them to try again later. - let maybe_new_key: Result = key.try_into(); + let maybe_new_key: Result = key.try_into(); if let Ok(new_key) = maybe_new_key { + old::Asset::::remove(key.clone()); Asset::::insert(new_key.clone(), value); log::info!(target: "migration", "Successfully migrated key: {:?}", new_key); } else { @@ -116,3 +101,20 @@ impl, I: 'static> SteppedMigration } } } + +fn mock_asset_details() -> AssetDetails { + AssetDetails { + owner: 0, + issuer: 0, + admin: 0, + freezer: 0, + supply: 0, + deposit: 0, + min_balance: 1, + is_sufficient: false, + accounts: 0, + sufficients: 0, + approvals: 0, + status: AssetStatus::Live, + } +} diff --git a/cumulus/parachains/runtimes/assets/common/src/foreign_assets_migration/tests.rs b/cumulus/parachains/runtimes/assets/migrations/src/v1/tests.rs similarity index 82% rename from cumulus/parachains/runtimes/assets/common/src/foreign_assets_migration/tests.rs rename to cumulus/parachains/runtimes/assets/migrations/src/v1/tests.rs index e38009efd679..0ab3860b3312 100644 --- a/cumulus/parachains/runtimes/assets/common/src/foreign_assets_migration/tests.rs +++ b/cumulus/parachains/runtimes/assets/migrations/src/v1/tests.rs @@ -30,7 +30,7 @@ use sp_io::{hashing, storage, TestExternalities}; use sp_runtime::BuildStorage; use xcm::{v3, v4}; -use super::{old, Migration}; +use super::{old, Migration, mock_asset_details}; construct_runtime! { pub struct Runtime { @@ -47,25 +47,39 @@ type Balance = u64; #[derive_impl(frame_system::config_preludes::TestDefaultConfig)] impl frame_system::Config for Runtime { type Block = Block; + type AccountId = AccountId; type AccountData = pallet_balances::AccountData; } #[derive_impl(pallet_balances::config_preludes::TestDefaultConfig)] impl pallet_balances::Config for Runtime { type AccountStore = System; + type Balance = Balance; } #[derive_impl(pallet_assets::config_preludes::TestDefaultConfig)] impl pallet_assets::Config for Runtime { - type AssetId = v4::Location; // TODO: This is what we want to migrate to V4. + type AssetId = v4::Location; type AssetIdParameter = v4::Location; + type Balance = Balance; type Currency = Balances; type CreateOrigin = AsEnsureOriginWithArg>; type ForceOrigin = EnsureRoot; type Freezer = (); + #[cfg(feature = "runtime-benchmarks")] + type BenchmarkHelper = XcmBenchmarkHelper; } -fn new_test_ext() -> TestExternalities { +/// Simple conversion of `u32` into an `AssetId` for use in benchmarking. +pub struct XcmBenchmarkHelper; +#[cfg(feature = "runtime-benchmarks")] +impl pallet_assets::BenchmarkHelper for XcmBenchmarkHelper { + fn create_asset_id_parameter(id: u32) -> v4::Location { + v4::Location::new(1, [v4::Junction::Parachain(id)]) + } +} + +pub(crate) fn new_test_ext() -> TestExternalities { let mut t = frame_system::GenesisConfig::::default().build_storage().unwrap(); let test_account = 1; @@ -93,20 +107,3 @@ fn migration_works() { assert!(Asset::::contains_key(new_key)); }) } - -fn mock_asset_details() -> AssetDetails { - AssetDetails { - owner: 0, - issuer: 0, - admin: 0, - freezer: 0, - supply: 0, - deposit: 0, - min_balance: 1, - is_sufficient: false, - accounts: 0, - sufficients: 0, - approvals: 0, - status: AssetStatus::Live, - } -} From 1457f3ff562031a01e22242f2dd2fdcbfbc5c180 Mon Sep 17 00:00:00 2001 From: Oliver Tale-Yazdi Date: Thu, 1 Aug 2024 12:23:28 +0200 Subject: [PATCH 07/32] nearly works Signed-off-by: Oliver Tale-Yazdi --- .../runtimes/assets/migrations/src/lib.rs | 11 --- .../assets/migrations/src/v1/benchmarks.rs | 70 ++++++++++----- .../runtimes/assets/migrations/src/v1/mod.rs | 59 ++++++------- .../assets/migrations/src/v1/tests.rs | 87 +++++++++---------- 4 files changed, 115 insertions(+), 112 deletions(-) diff --git a/cumulus/parachains/runtimes/assets/migrations/src/lib.rs b/cumulus/parachains/runtimes/assets/migrations/src/lib.rs index 4915b9967bd1..9d7ccf48d3f1 100644 --- a/cumulus/parachains/runtimes/assets/migrations/src/lib.rs +++ b/cumulus/parachains/runtimes/assets/migrations/src/lib.rs @@ -17,14 +17,3 @@ //! It's only a pallet since the benchmarking machinery requires it. mod v1; - -pub use pallet::*; - -#[frame_support::pallet] -pub mod pallet { - #[pallet::pallet] - pub struct Pallet(_); - - #[pallet::config] - pub trait Config: frame_system::Config {} -} diff --git a/cumulus/parachains/runtimes/assets/migrations/src/v1/benchmarks.rs b/cumulus/parachains/runtimes/assets/migrations/src/v1/benchmarks.rs index d7959b693195..d34e0be8f455 100644 --- a/cumulus/parachains/runtimes/assets/migrations/src/v1/benchmarks.rs +++ b/cumulus/parachains/runtimes/assets/migrations/src/v1/benchmarks.rs @@ -17,32 +17,54 @@ use frame_benchmarking::v2::*; use frame_support::{migrations::SteppedMigration, weights::WeightMeter}; -use pallet_assets::{Config, Asset}; +use pallet_assets::{Asset, Config}; use xcm::{v3, v4}; -use crate::Pallet; -use super::{old, Migration, mock_asset_details}; +use crate::v1::{old::AssetDetailsOf, AssetDetails, AssetStatus}; -#[benchmarks] +use super::{old, Migration}; + +// Mocked non-FRAME pallet type to make benchmarks compile. +pub struct Pallet, I: 'static = ()>(core::marker::PhantomData<(T, I)>); + +#[instance_benchmarks] mod benches { - use super::*; - - #[benchmark] - fn step() { - let key = v3::Location::new(1, [v3::Junction::Parachain(2004)]); - let mock_asset_details = mock_asset_details(); - dbg!(&std::any::type_name::<::AssetId>()); - // old::Asset::::insert(key.clone(), mock_asset_details); - - let mut meter = WeightMeter::new(); - #[block] - { - Migration::::step(None, &mut meter).unwrap(); - } - - // let new_key = v4::Location::new(1, [v4::Junction::Parachain(2004)]); - // assert!(Asset::::contains_key(new_key)); - } - - impl_benchmark_test_suite!(Pallet, crate::v1::tests::new_test_ext(), crate::v1::tests::Runtime); + use super::*; + + #[benchmark] + fn step() { + let key = v3::Location::new(1, [v3::Junction::Parachain(2004)]); + let mock_asset_details = mock_asset_details::(); + //dbg!(&std::any::type_name::>::AssetId>()); + old::Asset::::insert(key.clone(), mock_asset_details); + + let mut meter = WeightMeter::new(); + #[block] + { + //Migration::::step(None, &mut meter).unwrap(); + } + + // let new_key = v4::Location::new(1, [v4::Junction::Parachain(2004)]); + // assert!(Asset::::contains_key(new_key)); + } + + //impl_benchmark_test_suite!(Pallet, crate::v1::tests::new_test_ext(), + // crate::v1::tests::Runtime); +} + +fn mock_asset_details, I: 'static>() -> AssetDetailsOf { + AssetDetails { + owner: whitelisted_caller(), + issuer: whitelisted_caller(), + admin: whitelisted_caller(), + freezer: whitelisted_caller(), + supply: Default::default(), + deposit: Default::default(), + min_balance: 1u32.into(), + is_sufficient: false, + accounts: Default::default(), + sufficients: Default::default(), + approvals: Default::default(), + status: AssetStatus::Live, + } } diff --git a/cumulus/parachains/runtimes/assets/migrations/src/v1/mod.rs b/cumulus/parachains/runtimes/assets/migrations/src/v1/mod.rs index d0d73bf54fca..be06c38f7cba 100644 --- a/cumulus/parachains/runtimes/assets/migrations/src/v1/mod.rs +++ b/cumulus/parachains/runtimes/assets/migrations/src/v1/mod.rs @@ -24,44 +24,37 @@ mod tests; #[cfg(feature = "runtime-benchmarks")] mod benchmarks; -use pallet_assets::{Asset, Config, AssetDetails, AssetStatus}; use frame_support::{ migrations::{MigrationId, SteppedMigration, SteppedMigrationError}, pallet_prelude::PhantomData, weights::WeightMeter, Hashable, }; +use pallet_assets::{Asset, AssetDetails, AssetStatus, Config}; use xcm::{v3, v4}; pub const PALLET_MIGRATIONS_ID: &[u8; 13] = b"pallet-assets"; /// Storage aliases for on-chain storage types before running the migration. pub mod old { - use super::{Config, v3}; - use pallet_assets::{ - Pallet, - AssetDetails, DepositBalanceOf, - }; + use super::{v3, Config}; use frame_support::{storage_alias, Blake2_128Concat}; + use pallet_assets::{AssetDetails, DepositBalanceOf, Pallet}; + + pub type AssetDetailsOf = AssetDetails< + >::Balance, + ::AccountId, + DepositBalanceOf, + >; /// The storage item we are migrating from. #[storage_alias] - pub(super) type Asset, I: 'static> = StorageMap< - Pallet, - Blake2_128Concat, - v3::Location, - AssetDetails< - >::Balance, - ::AccountId, - DepositBalanceOf, - >, - >; + pub(super) type Asset, I: 'static> = + StorageMap, Blake2_128Concat, v3::Location, AssetDetailsOf>; } pub struct Migration, I: 'static = ()>(PhantomData<(T, I)>); -impl, I: 'static> SteppedMigration - for Migration -{ +impl, I: 'static> SteppedMigration for Migration { type Cursor = v3::Location; type Identifier = MigrationId<13>; @@ -103,18 +96,18 @@ impl, I: 'static> SteppedMigration } fn mock_asset_details() -> AssetDetails { - AssetDetails { - owner: 0, - issuer: 0, - admin: 0, - freezer: 0, - supply: 0, - deposit: 0, - min_balance: 1, - is_sufficient: false, - accounts: 0, - sufficients: 0, - approvals: 0, - status: AssetStatus::Live, - } + AssetDetails { + owner: 0, + issuer: 0, + admin: 0, + freezer: 0, + supply: 0, + deposit: 0, + min_balance: 1, + is_sufficient: false, + accounts: 0, + sufficients: 0, + approvals: 0, + status: AssetStatus::Live, + } } diff --git a/cumulus/parachains/runtimes/assets/migrations/src/v1/tests.rs b/cumulus/parachains/runtimes/assets/migrations/src/v1/tests.rs index 0ab3860b3312..a35202500644 100644 --- a/cumulus/parachains/runtimes/assets/migrations/src/v1/tests.rs +++ b/cumulus/parachains/runtimes/assets/migrations/src/v1/tests.rs @@ -17,11 +17,8 @@ use codec::Encode; use frame_support::{ - construct_runtime, derive_impl, - Hashable, - traits::AsEnsureOriginWithArg, - migrations::SteppedMigration, - weights::WeightMeter, + construct_runtime, derive_impl, migrations::SteppedMigration, traits::AsEnsureOriginWithArg, + weights::WeightMeter, Hashable, }; use frame_system::{EnsureRoot, EnsureSigned}; use hex_display::HexDisplayExt; @@ -30,14 +27,14 @@ use sp_io::{hashing, storage, TestExternalities}; use sp_runtime::BuildStorage; use xcm::{v3, v4}; -use super::{old, Migration, mock_asset_details}; +use super::{mock_asset_details, old, Migration}; construct_runtime! { - pub struct Runtime { - System: frame_system, - Balances: pallet_balances, - ForeignAssets: pallet_assets, - } + pub struct Runtime { + System: frame_system, + Balances: pallet_balances, + ForeignAssets: pallet_assets, + } } type Block = frame_system::mocking::MockBlock; @@ -46,28 +43,28 @@ type Balance = u64; #[derive_impl(frame_system::config_preludes::TestDefaultConfig)] impl frame_system::Config for Runtime { - type Block = Block; - type AccountId = AccountId; + type Block = Block; + type AccountId = AccountId; type AccountData = pallet_balances::AccountData; } #[derive_impl(pallet_balances::config_preludes::TestDefaultConfig)] impl pallet_balances::Config for Runtime { - type AccountStore = System; - type Balance = Balance; + type AccountStore = System; + type Balance = Balance; } #[derive_impl(pallet_assets::config_preludes::TestDefaultConfig)] impl pallet_assets::Config for Runtime { - type AssetId = v4::Location; - type AssetIdParameter = v4::Location; - type Balance = Balance; - type Currency = Balances; - type CreateOrigin = AsEnsureOriginWithArg>; - type ForceOrigin = EnsureRoot; - type Freezer = (); - #[cfg(feature = "runtime-benchmarks")] - type BenchmarkHelper = XcmBenchmarkHelper; + type AssetId = v4::Location; + type AssetIdParameter = v4::Location; + type Balance = Balance; + type Currency = Balances; + type CreateOrigin = AsEnsureOriginWithArg>; + type ForceOrigin = EnsureRoot; + type Freezer = (); + #[cfg(feature = "runtime-benchmarks")] + type BenchmarkHelper = XcmBenchmarkHelper; } /// Simple conversion of `u32` into an `AssetId` for use in benchmarking. @@ -80,30 +77,32 @@ impl pallet_assets::BenchmarkHelper for XcmBenchmarkHelper { } pub(crate) fn new_test_ext() -> TestExternalities { - let mut t = frame_system::GenesisConfig::::default().build_storage().unwrap(); + let mut t = frame_system::GenesisConfig::::default().build_storage().unwrap(); - let test_account = 1; - let initial_balance = 1000; - pallet_balances::GenesisConfig:: { - balances: vec![(test_account, initial_balance)], - }.assimilate_storage(&mut t).unwrap(); + let test_account = 1; + let initial_balance = 1000; + pallet_balances::GenesisConfig:: { balances: vec![(test_account, initial_balance)] } + .assimilate_storage(&mut t) + .unwrap(); - t.into() + t.into() } #[test] fn migration_works() { - new_test_ext().execute_with(|| { - let key = v3::Location::new(1, [v3::Junction::Parachain(2004)]); - let mock_asset_details = mock_asset_details(); - old::Asset::::insert(key.clone(), mock_asset_details); - - // Perform one step of the migration. - let cursor = Migration::::step(None, &mut WeightMeter::new()).unwrap().unwrap(); - // Second time works. - assert!(Migration::::step(Some(cursor), &mut WeightMeter::new()).unwrap().is_none()); - - let new_key = v4::Location::new(1, [v4::Junction::Parachain(2004)]); - assert!(Asset::::contains_key(new_key)); - }) + new_test_ext().execute_with(|| { + let key = v3::Location::new(1, [v3::Junction::Parachain(2004)]); + let mock_asset_details = mock_asset_details(); + old::Asset::::insert(key.clone(), mock_asset_details); + + // Perform one step of the migration. + let cursor = Migration::::step(None, &mut WeightMeter::new()).unwrap().unwrap(); + // Second time works. + assert!(Migration::::step(Some(cursor), &mut WeightMeter::new()) + .unwrap() + .is_none()); + + let new_key = v4::Location::new(1, [v4::Junction::Parachain(2004)]); + assert!(Asset::::contains_key(new_key)); + }) } From 211207eb1eb1940dba7e2cdb089aedb8c602c73f Mon Sep 17 00:00:00 2001 From: Oliver Tale-Yazdi Date: Thu, 1 Aug 2024 12:23:58 +0200 Subject: [PATCH 08/32] nearly works Signed-off-by: Oliver Tale-Yazdi --- cumulus/parachains/runtimes/assets/migrations/src/v1/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cumulus/parachains/runtimes/assets/migrations/src/v1/mod.rs b/cumulus/parachains/runtimes/assets/migrations/src/v1/mod.rs index be06c38f7cba..fde54109004f 100644 --- a/cumulus/parachains/runtimes/assets/migrations/src/v1/mod.rs +++ b/cumulus/parachains/runtimes/assets/migrations/src/v1/mod.rs @@ -54,7 +54,7 @@ pub mod old { } pub struct Migration, I: 'static = ()>(PhantomData<(T, I)>); -impl, I: 'static> SteppedMigration for Migration { +impl, I: 'static> SteppedMigration for Migration { type Cursor = v3::Location; type Identifier = MigrationId<13>; From d1efea4e40e637966bc056eb77a7e0265877ad64 Mon Sep 17 00:00:00 2001 From: Oliver Tale-Yazdi Date: Thu, 1 Aug 2024 12:31:24 +0200 Subject: [PATCH 09/32] make compile Signed-off-by: Oliver Tale-Yazdi --- .../assets/migrations/src/v1/benchmarks.rs | 14 ++++++++------ .../runtimes/assets/migrations/src/v1/mod.rs | 10 +++++++--- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/cumulus/parachains/runtimes/assets/migrations/src/v1/benchmarks.rs b/cumulus/parachains/runtimes/assets/migrations/src/v1/benchmarks.rs index d34e0be8f455..8f516de9a227 100644 --- a/cumulus/parachains/runtimes/assets/migrations/src/v1/benchmarks.rs +++ b/cumulus/parachains/runtimes/assets/migrations/src/v1/benchmarks.rs @@ -27,7 +27,10 @@ use super::{old, Migration}; // Mocked non-FRAME pallet type to make benchmarks compile. pub struct Pallet, I: 'static = ()>(core::marker::PhantomData<(T, I)>); -#[instance_benchmarks] +#[instance_benchmarks( + // This is needed for the migration and could also be in its own "migration config": + where >::AssetId: From +)] mod benches { use super::*; @@ -41,15 +44,14 @@ mod benches { let mut meter = WeightMeter::new(); #[block] { - //Migration::::step(None, &mut meter).unwrap(); + Migration::::step(None, &mut meter).unwrap(); } - // let new_key = v4::Location::new(1, [v4::Junction::Parachain(2004)]); - // assert!(Asset::::contains_key(new_key)); + //let new_key = v4::Location::new(1, [v4::Junction::Parachain(2004)]); + //assert!(Asset::::contains_key(new_key)); } - //impl_benchmark_test_suite!(Pallet, crate::v1::tests::new_test_ext(), - // crate::v1::tests::Runtime); + impl_benchmark_test_suite!(Pallet, crate::v1::tests::new_test_ext(), crate::v1::tests::Runtime); } fn mock_asset_details, I: 'static>() -> AssetDetailsOf { diff --git a/cumulus/parachains/runtimes/assets/migrations/src/v1/mod.rs b/cumulus/parachains/runtimes/assets/migrations/src/v1/mod.rs index fde54109004f..50aef8088332 100644 --- a/cumulus/parachains/runtimes/assets/migrations/src/v1/mod.rs +++ b/cumulus/parachains/runtimes/assets/migrations/src/v1/mod.rs @@ -54,7 +54,10 @@ pub mod old { } pub struct Migration, I: 'static = ()>(PhantomData<(T, I)>); -impl, I: 'static> SteppedMigration for Migration { +impl, I: 'static> SteppedMigration for Migration +where + >::AssetId: From, +{ type Cursor = v3::Location; type Identifier = MigrationId<13>; @@ -80,8 +83,9 @@ impl, I: 'static> SteppedMigration for Migration { // we log them to try again later. let maybe_new_key: Result = key.try_into(); if let Ok(new_key) = maybe_new_key { - old::Asset::::remove(key.clone()); - Asset::::insert(new_key.clone(), value); + old::Asset::::remove(&key); + let new_key: >::AssetId = new_key.into(); + Asset::::insert(&new_key, value); log::info!(target: "migration", "Successfully migrated key: {:?}", new_key); } else { log::warn!(target: "migration", "{:?} couldn't be converted to V4", key); From e610689f4cbdf4e467bece9d2cf1a0166e706c9d Mon Sep 17 00:00:00 2001 From: Francisco Aguirre Date: Thu, 1 Aug 2024 12:43:22 +0200 Subject: [PATCH 10/32] feat(assets-common-migrations): benchmark tests passing --- .../runtimes/assets/migrations/src/v1/benchmarks.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cumulus/parachains/runtimes/assets/migrations/src/v1/benchmarks.rs b/cumulus/parachains/runtimes/assets/migrations/src/v1/benchmarks.rs index 8f516de9a227..c1dee1c822ee 100644 --- a/cumulus/parachains/runtimes/assets/migrations/src/v1/benchmarks.rs +++ b/cumulus/parachains/runtimes/assets/migrations/src/v1/benchmarks.rs @@ -47,8 +47,8 @@ mod benches { Migration::::step(None, &mut meter).unwrap(); } - //let new_key = v4::Location::new(1, [v4::Junction::Parachain(2004)]); - //assert!(Asset::::contains_key(new_key)); + let new_key: >::AssetId = v4::Location::new(1, [v4::Junction::Parachain(2004)]).into(); + assert!(Asset::::contains_key(new_key)); } impl_benchmark_test_suite!(Pallet, crate::v1::tests::new_test_ext(), crate::v1::tests::Runtime); From ec88a62b4d6b5ac3523f16a5c83cae223aa93a81 Mon Sep 17 00:00:00 2001 From: Francisco Aguirre Date: Thu, 1 Aug 2024 13:31:20 +0200 Subject: [PATCH 11/32] feat(asset-hub-westend): migrate from v3 to v4 --- Cargo.lock | 2 +- Cargo.toml | 1 + .../assets/asset-hub-rococo/src/lib.rs | 9 +- .../assets/asset-hub-rococo/src/tests/mod.rs | 6 +- .../assets/asset-hub-westend/Cargo.toml | 3 + .../assets/asset-hub-westend/src/lib.rs | 48 +++---- .../asset-hub-westend/src/xcm_config.rs | 15 +-- .../assets/asset-hub-westend/tests/tests.rs | 118 +++++++++--------- .../runtimes/assets/common/src/lib.rs | 1 - .../runtimes/assets/migrations/Cargo.toml | 2 - .../runtimes/assets/migrations/src/lib.rs | 13 ++ .../assets/migrations/src/v1/benchmarks.rs | 11 +- .../runtimes/assets/migrations/src/v1/mod.rs | 18 --- .../assets/test-utils/src/test_cases.rs | 48 ++++--- .../test-utils/src/test_cases_over_bridge.rs | 17 ++- 15 files changed, 146 insertions(+), 166 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index c9ea1d3a1adf..57d6de900e04 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -999,6 +999,7 @@ version = "0.15.0" dependencies = [ "asset-test-utils", "assets-common", + "assets-common-migrations", "bp-asset-hub-rococo", "bp-asset-hub-westend", "bp-bridge-hub-rococo", @@ -1147,7 +1148,6 @@ dependencies = [ "parity-scale-codec", "scale-info", "sp-api", - "sp-io", "sp-runtime", "staging-xcm", "staging-xcm-builder", diff --git a/Cargo.toml b/Cargo.toml index cc018f8cac77..92f504ccdf28 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -604,6 +604,7 @@ asset-hub-westend-emulated-chain = { path = "cumulus/parachains/integration-test asset-hub-westend-runtime = { path = "cumulus/parachains/runtimes/assets/asset-hub-westend" } asset-test-utils = { path = "cumulus/parachains/runtimes/assets/test-utils", default-features = false } assets-common = { path = "cumulus/parachains/runtimes/assets/common", default-features = false } +assets-common-migrations = { path = "cumulus/parachains/runtimes/assets/migrations", default-features = false } async-channel = { version = "1.8.0" } async-std = { version = "1.9.0" } async-trait = { version = "0.1.79" } diff --git a/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/lib.rs b/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/lib.rs index 540388ebcc92..f3454662829f 100644 --- a/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/lib.rs +++ b/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/lib.rs @@ -84,8 +84,8 @@ use sp_runtime::{Perbill, RuntimeDebug}; use testnet_parachains_constants::rococo::{consensus::*, currency::*, fee::WeightToFee, time::*}; use xcm_config::{ ForeignAssetsConvertedConcreteId, ForeignCreatorsSovereignAccountOf, GovernanceLocation, - PoolAssetsConvertedConcreteId, TokenLocation, - TrustBackedAssetsConvertedConcreteId, TrustBackedAssetsPalletLocation, + PoolAssetsConvertedConcreteId, TokenLocation, TrustBackedAssetsConvertedConcreteId, + TrustBackedAssetsPalletLocation, }; #[cfg(test)] @@ -194,9 +194,8 @@ impl pallet_migrations::Config for Runtime { type WeightInfo = (); } -type MultiBlockMigrations = ( - assets_common::foreign_assets_migration::Migration, -); +type MultiBlockMigrations = + (assets_common::foreign_assets_migration::Migration,); impl pallet_timestamp::Config for Runtime { /// A timestamp: milliseconds since the unix epoch. diff --git a/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/tests/mod.rs b/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/tests/mod.rs index f534ddba2630..12c0bc4e1688 100644 --- a/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/tests/mod.rs +++ b/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/tests/mod.rs @@ -27,8 +27,7 @@ fn sane_block_weight() { use pallet_balances::WeightInfo; let block = RuntimeBlockWeights::get().max_block; let base = RuntimeBlockWeights::get().get(DispatchClass::Normal).base_extrinsic; - let transfer = - base + weights::pallet_balances::WeightInfo::::transfer_allow_death(); + let transfer = base + weights::pallet_balances::WeightInfo::::transfer_allow_death(); let fit = block.checked_div_per_component(&transfer).unwrap_or_default(); assert!(fit >= 1000, "{} should be at least 1000", fit); @@ -39,8 +38,7 @@ fn sane_block_weight() { fn sane_transfer_fee() { use pallet_balances::WeightInfo; let base = RuntimeBlockWeights::get().get(DispatchClass::Normal).base_extrinsic; - let transfer = - base + weights::pallet_balances::WeightInfo::::transfer_allow_death(); + let transfer = base + weights::pallet_balances::WeightInfo::::transfer_allow_death(); let fee: Balance = fee::WeightToFee::weight_to_fee(&transfer); assert!(fee <= CENTS, "{} MILLICENTS should be at most 1000", fee / MILLICENTS); diff --git a/cumulus/parachains/runtimes/assets/asset-hub-westend/Cargo.toml b/cumulus/parachains/runtimes/assets/asset-hub-westend/Cargo.toml index 6b1bf769ace3..251b0651a73f 100644 --- a/cumulus/parachains/runtimes/assets/asset-hub-westend/Cargo.toml +++ b/cumulus/parachains/runtimes/assets/asset-hub-westend/Cargo.toml @@ -86,6 +86,7 @@ parachain-info = { workspace = true } parachains-common = { workspace = true } testnet-parachains-constants = { features = ["westend"], workspace = true } assets-common = { workspace = true } +assets-common-migrations = { workspace = true } # Bridges pallet-xcm-bridge-hub-router = { workspace = true } @@ -104,6 +105,7 @@ substrate-wasm-builder = { optional = true, workspace = true, default-features = default = ["std"] runtime-benchmarks = [ "assets-common/runtime-benchmarks", + "assets-common-migrations/runtime-benchmarks", "cumulus-pallet-parachain-system/runtime-benchmarks", "cumulus-pallet-session-benchmarking/runtime-benchmarks", "cumulus-pallet-xcmp-queue/runtime-benchmarks", @@ -176,6 +178,7 @@ try-runtime = [ ] std = [ "assets-common/std", + "assets-common-migrations/std", "bp-asset-hub-rococo/std", "bp-asset-hub-westend/std", "bp-bridge-hub-rococo/std", diff --git a/cumulus/parachains/runtimes/assets/asset-hub-westend/src/lib.rs b/cumulus/parachains/runtimes/assets/asset-hub-westend/src/lib.rs index 2d9de07f251f..91d1dbedb8d6 100644 --- a/cumulus/parachains/runtimes/assets/asset-hub-westend/src/lib.rs +++ b/cumulus/parachains/runtimes/assets/asset-hub-westend/src/lib.rs @@ -78,8 +78,7 @@ use testnet_parachains_constants::westend::{consensus::*, currency::*, fee::Weig use xcm_config::{ ForeignAssetsConvertedConcreteId, ForeignCreatorsSovereignAccountOf, PoolAssetsConvertedConcreteId, TrustBackedAssetsConvertedConcreteId, - TrustBackedAssetsPalletLocationV3, WestendLocation, WestendLocationV3, - XcmOriginToTransactDispatchOrigin, + TrustBackedAssetsPalletLocation, WestendLocation, XcmOriginToTransactDispatchOrigin, }; #[cfg(any(feature = "std", test))] @@ -321,11 +320,11 @@ pub type LocalAndForeignAssets = fungibles::UnionOf< Assets, ForeignAssets, LocalFromLeft< - AssetIdForTrustBackedAssetsConvert, + AssetIdForTrustBackedAssetsConvert, AssetIdForTrustBackedAssets, - xcm::v3::Location, + xcm::v4::Location, >, - xcm::v3::Location, + xcm::v4::Location, AccountId, >; @@ -333,25 +332,25 @@ pub type LocalAndForeignAssets = fungibles::UnionOf< pub type NativeAndAssets = fungible::UnionOf< Balances, LocalAndForeignAssets, - TargetFromLeft, - xcm::v3::Location, + TargetFromLeft, + xcm::v4::Location, AccountId, >; pub type PoolIdToAccountId = pallet_asset_conversion::AccountIdConverter< AssetConversionPalletId, - (xcm::v3::Location, xcm::v3::Location), + (xcm::v4::Location, xcm::v4::Location), >; impl pallet_asset_conversion::Config for Runtime { type RuntimeEvent = RuntimeEvent; type Balance = Balance; type HigherPrecisionBalance = sp_core::U256; - type AssetKind = xcm::v3::Location; + type AssetKind = xcm::v4::Location; type Assets = NativeAndAssets; type PoolId = (Self::AssetKind, Self::AssetKind); type PoolLocator = pallet_asset_conversion::WithFirstAsset< - WestendLocationV3, + WestendLocation, AccountId, Self::AssetKind, PoolIdToAccountId, @@ -359,7 +358,7 @@ impl pallet_asset_conversion::Config for Runtime { type PoolAssetId = u32; type PoolAssets = PoolAssets; type PoolSetupFee = ConstU128<0>; // Asset class deposit fees are sufficient to prevent spam - type PoolSetupFeeAsset = WestendLocationV3; + type PoolSetupFeeAsset = WestendLocation; type PoolSetupFeeTarget = ResolveAssetTo; type LiquidityWithdrawalFee = LiquidityWithdrawalFee; type LPFee = ConstU32<3>; @@ -369,10 +368,10 @@ impl pallet_asset_conversion::Config for Runtime { type WeightInfo = weights::pallet_asset_conversion::WeightInfo; #[cfg(feature = "runtime-benchmarks")] type BenchmarkHelper = assets_common::benchmarks::AssetPairFactory< - WestendLocationV3, + WestendLocation, parachain_info::Pallet, xcm_config::TrustBackedAssetsPalletIndex, - xcm::v3::Location, + xcm::v4::Location, >; } @@ -406,14 +405,14 @@ pub type ForeignAssetsInstance = pallet_assets::Instance2; impl pallet_assets::Config for Runtime { type RuntimeEvent = RuntimeEvent; type Balance = Balance; - type AssetId = xcm::v3::Location; - type AssetIdParameter = xcm::v3::Location; + type AssetId = xcm::v4::Location; + type AssetIdParameter = xcm::v4::Location; type Currency = Balances; type CreateOrigin = ForeignCreators< - FromSiblingParachain, xcm::v3::Location>, + FromSiblingParachain, xcm::v4::Location>, ForeignCreatorsSovereignAccountOf, AccountId, - xcm::v3::Location, + xcm::v4::Location, >; type ForceOrigin = AssetsForceOrigin; type AssetDeposit = ForeignAssetsAssetDeposit; @@ -793,9 +792,9 @@ parameter_types! { impl pallet_asset_conversion_tx_payment::Config for Runtime { type RuntimeEvent = RuntimeEvent; - type AssetId = xcm::v3::Location; + type AssetId = xcm::v4::Location; type OnChargeAssetTransaction = SwapAssetAdapter< - WestendLocationV3, + WestendLocation, NativeAndAssets, AssetConversion, ResolveAssetTo, @@ -1167,6 +1166,7 @@ mod benches { [pallet_asset_conversion_ops, AssetConversionMigration] // XCM [pallet_xcm, PalletXcmExtrinsicsBenchmark::] + [assets_common_migrations, AssetsCommonMigrations] // NOTE: Make sure you point to the individual modules below. [pallet_xcm_benchmarks::fungible, XcmBalances] [pallet_xcm_benchmarks::generic, XcmGeneric] @@ -1323,18 +1323,18 @@ impl_runtime_apis! { impl pallet_asset_conversion::AssetConversionApi< Block, Balance, - xcm::v3::Location, + xcm::v4::Location, > for Runtime { - fn quote_price_exact_tokens_for_tokens(asset1: xcm::v3::Location, asset2: xcm::v3::Location, amount: Balance, include_fee: bool) -> Option { + fn quote_price_exact_tokens_for_tokens(asset1: xcm::v4::Location, asset2: xcm::v4::Location, amount: Balance, include_fee: bool) -> Option { AssetConversion::quote_price_exact_tokens_for_tokens(asset1, asset2, amount, include_fee) } - fn quote_price_tokens_for_exact_tokens(asset1: xcm::v3::Location, asset2: xcm::v3::Location, amount: Balance, include_fee: bool) -> Option { + fn quote_price_tokens_for_exact_tokens(asset1: xcm::v4::Location, asset2: xcm::v4::Location, amount: Balance, include_fee: bool) -> Option { AssetConversion::quote_price_tokens_for_exact_tokens(asset1, asset2, amount, include_fee) } - fn get_reserves(asset1: xcm::v3::Location, asset2: xcm::v3::Location) -> Option<(Balance, Balance)> { + fn get_reserves(asset1: xcm::v4::Location, asset2: xcm::v4::Location) -> Option<(Balance, Balance)> { AssetConversion::get_reserves(asset1, asset2).ok() } } @@ -1520,6 +1520,7 @@ impl_runtime_apis! { // are referenced in that call. type XcmBalances = pallet_xcm_benchmarks::fungible::Pallet::; type XcmGeneric = pallet_xcm_benchmarks::generic::Pallet::; + type AssetsCommonMigrations = assets_common_migrations::Pallet::; // Benchmark files generated for `Assets/ForeignAssets` instances are by default // `pallet_assets_assets.rs / pallet_assets_foreign_assets`, which is not really nice, @@ -1823,6 +1824,7 @@ impl_runtime_apis! { type XcmBalances = pallet_xcm_benchmarks::fungible::Pallet::; type XcmGeneric = pallet_xcm_benchmarks::generic::Pallet::; + type AssetsCommonMigrations = assets_common_migrations::Pallet::; type Local = pallet_assets::Pallet::; type Foreign = pallet_assets::Pallet::; diff --git a/cumulus/parachains/runtimes/assets/asset-hub-westend/src/xcm_config.rs b/cumulus/parachains/runtimes/assets/asset-hub-westend/src/xcm_config.rs index 5ecfce18b6da..ff3df173c98a 100644 --- a/cumulus/parachains/runtimes/assets/asset-hub-westend/src/xcm_config.rs +++ b/cumulus/parachains/runtimes/assets/asset-hub-westend/src/xcm_config.rs @@ -60,7 +60,6 @@ use xcm_executor::XcmExecutor; parameter_types! { pub const WestendLocation: Location = Location::parent(); - pub const WestendLocationV3: xcm::v3::Location = xcm::v3::Location::parent(); pub const RelayNetwork: Option = Some(NetworkId::Westend); pub RelayChainOrigin: RuntimeOrigin = cumulus_pallet_xcm::Origin::Relay.into(); pub UniversalLocation: InteriorLocation = @@ -69,8 +68,6 @@ parameter_types! { pub TrustBackedAssetsPalletLocation: Location = PalletInstance(TrustBackedAssetsPalletIndex::get()).into(); pub TrustBackedAssetsPalletIndex: u8 = ::index() as u8; - pub TrustBackedAssetsPalletLocationV3: xcm::v3::Location = - xcm::v3::Junction::PalletInstance(::index() as u8).into(); pub ForeignAssetsPalletLocation: Location = PalletInstance(::index() as u8).into(); pub PoolAssetsPalletLocation: Location = @@ -169,7 +166,7 @@ pub type ForeignAssetsConvertedConcreteId = assets_common::ForeignAssetsConverte StartsWithExplicitGlobalConsensus, ), Balance, - xcm::v3::Location, + xcm::v4::Location, >; /// Means for transacting foreign assets from different global consensus. @@ -376,7 +373,7 @@ impl xcm_executor::Config for XcmConfig { ResolveTo, >, cumulus_primitives_utility::SwapFirstAssetTrader< - WestendLocationV3, + WestendLocation, crate::AssetConversion, WeightToFee, crate::NativeAndAssets, @@ -384,7 +381,7 @@ impl xcm_executor::Config for XcmConfig { TrustBackedAssetsAsLocation< TrustBackedAssetsPalletLocation, Balance, - xcm::v3::Location, + xcm::v4::Location, >, ForeignAssetsConvertedConcreteId, ), @@ -509,9 +506,9 @@ pub type ForeignCreatorsSovereignAccountOf = ( /// Simple conversion of `u32` into an `AssetId` for use in benchmarking. pub struct XcmBenchmarkHelper; #[cfg(feature = "runtime-benchmarks")] -impl pallet_assets::BenchmarkHelper for XcmBenchmarkHelper { - fn create_asset_id_parameter(id: u32) -> xcm::v3::Location { - xcm::v3::Location::new(1, [xcm::v3::Junction::Parachain(id)]) +impl pallet_assets::BenchmarkHelper for XcmBenchmarkHelper { + fn create_asset_id_parameter(id: u32) -> xcm::v4::Location { + xcm::v4::Location::new(1, [xcm::v4::Junction::Parachain(id)]) } } diff --git a/cumulus/parachains/runtimes/assets/asset-hub-westend/tests/tests.rs b/cumulus/parachains/runtimes/assets/asset-hub-westend/tests/tests.rs index 48e6c11d268c..1c334d6f84f8 100644 --- a/cumulus/parachains/runtimes/assets/asset-hub-westend/tests/tests.rs +++ b/cumulus/parachains/runtimes/assets/asset-hub-westend/tests/tests.rs @@ -86,7 +86,7 @@ fn slot_durations() -> SlotDurations { fn setup_pool_for_paying_fees_with_foreign_assets( (foreign_asset_owner, foreign_asset_id_location, foreign_asset_id_minimum_balance): ( AccountId, - xcm::v3::Location, + xcm::v4::Location, Balance, ), ) { @@ -94,7 +94,7 @@ fn setup_pool_for_paying_fees_with_foreign_assets( // setup a pool to pay fees with `foreign_asset_id_location` tokens let pool_owner: AccountId = [14u8; 32].into(); - let native_asset = xcm::v3::Location::parent(); + let native_asset = xcm::v4::Location::parent(); let pool_liquidity: Balance = existential_deposit.max(foreign_asset_id_minimum_balance).mul(100_000); @@ -106,15 +106,15 @@ fn setup_pool_for_paying_fees_with_foreign_assets( assert_ok!(ForeignAssets::mint( RuntimeOrigin::signed(foreign_asset_owner), - foreign_asset_id_location.into(), + foreign_asset_id_location.clone().into(), pool_owner.clone().into(), (foreign_asset_id_minimum_balance + pool_liquidity).mul(2).into(), )); assert_ok!(AssetConversion::create_pool( RuntimeOrigin::signed(pool_owner.clone()), - Box::new(native_asset.into()), - Box::new(foreign_asset_id_location.into()) + Box::new(native_asset.clone().into()), + Box::new(foreign_asset_id_location.clone().into()) )); assert_ok!(AssetConversion::add_liquidity( @@ -219,10 +219,10 @@ fn test_buy_and_refund_weight_with_swap_local_asset_xcm_trader() { assert_ok!(AssetConversion::create_pool( RuntimeHelper::origin_of(bob.clone()), Box::new( - xcm::v3::Location::try_from(native_location.clone()).expect("conversion works") + xcm::v4::Location::try_from(native_location.clone()).expect("conversion works") ), Box::new( - xcm::v3::Location::try_from(asset_1_location.clone()) + xcm::v4::Location::try_from(asset_1_location.clone()) .expect("conversion works") ) )); @@ -230,10 +230,10 @@ fn test_buy_and_refund_weight_with_swap_local_asset_xcm_trader() { assert_ok!(AssetConversion::add_liquidity( RuntimeHelper::origin_of(bob.clone()), Box::new( - xcm::v3::Location::try_from(native_location.clone()).expect("conversion works") + xcm::v4::Location::try_from(native_location.clone()).expect("conversion works") ), Box::new( - xcm::v3::Location::try_from(asset_1_location.clone()) + xcm::v4::Location::try_from(asset_1_location.clone()) .expect("conversion works") ), pool_liquidity, @@ -271,8 +271,8 @@ fn test_buy_and_refund_weight_with_swap_local_asset_xcm_trader() { let refund_weight = Weight::from_parts(1_000_000_000, 0); let refund = WeightToFee::weight_to_fee(&refund_weight); let (reserve1, reserve2) = AssetConversion::get_reserves( - xcm::v3::Location::try_from(native_location).expect("conversion works"), - xcm::v3::Location::try_from(asset_1_location.clone()).expect("conversion works"), + xcm::v4::Location::try_from(native_location).expect("conversion works"), + xcm::v4::Location::try_from(asset_1_location.clone()).expect("conversion works"), ) .unwrap(); let asset_refund = @@ -310,12 +310,12 @@ fn test_buy_and_refund_weight_with_swap_foreign_asset_xcm_trader() { let bob: AccountId = SOME_ASSET_ADMIN.into(); let staking_pot = CollatorSelection::account_id(); let native_location = - xcm::v3::Location::try_from(WestendLocation::get()).expect("conversion works"); - let foreign_location = xcm::v3::Location { + xcm::v4::Location::try_from(WestendLocation::get()).expect("conversion works"); + let foreign_location = xcm::v4::Location { parents: 1, interior: ( - xcm::v3::Junction::Parachain(1234), - xcm::v3::Junction::GeneralIndex(12345), + xcm::v4::Junction::Parachain(1234), + xcm::v4::Junction::GeneralIndex(12345), ) .into(), }; @@ -326,26 +326,26 @@ fn test_buy_and_refund_weight_with_swap_foreign_asset_xcm_trader() { // init asset, balances and pool. assert_ok!(>::create( - foreign_location, + foreign_location.clone(), bob.clone(), true, 10 )); - assert_ok!(ForeignAssets::mint_into(foreign_location, &bob, initial_balance)); + assert_ok!(ForeignAssets::mint_into(foreign_location.clone(), &bob, initial_balance)); assert_ok!(Balances::mint_into(&bob, initial_balance)); assert_ok!(Balances::mint_into(&staking_pot, initial_balance)); assert_ok!(AssetConversion::create_pool( RuntimeHelper::origin_of(bob.clone()), - Box::new(native_location), - Box::new(foreign_location) + Box::new(native_location.clone()), + Box::new(foreign_location.clone()) )); assert_ok!(AssetConversion::add_liquidity( RuntimeHelper::origin_of(bob.clone()), - Box::new(native_location), - Box::new(foreign_location), + Box::new(native_location.clone()), + Box::new(foreign_location.clone()), pool_liquidity, pool_liquidity, 1, @@ -354,11 +354,9 @@ fn test_buy_and_refund_weight_with_swap_foreign_asset_xcm_trader() { )); // keep initial total issuance to assert later. - let asset_total_issuance = ForeignAssets::total_issuance(foreign_location); + let asset_total_issuance = ForeignAssets::total_issuance(foreign_location.clone()); let native_total_issuance = Balances::total_issuance(); - let foreign_location_latest: Location = foreign_location.try_into().unwrap(); - // prepare input to buy weight. let weight = Weight::from_parts(4_000_000_000, 0); let fee = WeightToFee::weight_to_fee(&weight); @@ -366,7 +364,7 @@ fn test_buy_and_refund_weight_with_swap_foreign_asset_xcm_trader() { AssetConversion::get_amount_in(&fee, &pool_liquidity, &pool_liquidity).unwrap(); let extra_amount = 100; let ctx = XcmContext { origin: None, message_id: XcmHash::default(), topic: None }; - let payment: Asset = (foreign_location_latest.clone(), asset_fee + extra_amount).into(); + let payment: Asset = (foreign_location.clone(), asset_fee + extra_amount).into(); // init trader and buy weight. let mut trader = ::Trader::new(); @@ -374,13 +372,11 @@ fn test_buy_and_refund_weight_with_swap_foreign_asset_xcm_trader() { trader.buy_weight(weight, payment.into(), &ctx).expect("Expected Ok"); // assert. - let unused_amount = unused_asset - .fungible - .get(&foreign_location_latest.clone().into()) - .map_or(0, |a| *a); + let unused_amount = + unused_asset.fungible.get(&foreign_location.clone().into()).map_or(0, |a| *a); assert_eq!(unused_amount, extra_amount); assert_eq!( - ForeignAssets::total_issuance(foreign_location), + ForeignAssets::total_issuance(foreign_location.clone()), asset_total_issuance + asset_fee ); @@ -388,13 +384,13 @@ fn test_buy_and_refund_weight_with_swap_foreign_asset_xcm_trader() { let refund_weight = Weight::from_parts(1_000_000_000, 0); let refund = WeightToFee::weight_to_fee(&refund_weight); let (reserve1, reserve2) = - AssetConversion::get_reserves(native_location, foreign_location).unwrap(); + AssetConversion::get_reserves(native_location, foreign_location.clone()).unwrap(); let asset_refund = AssetConversion::get_amount_out(&refund, &reserve1, &reserve2).unwrap(); // refund. let actual_refund = trader.refund_weight(refund_weight, &ctx).unwrap(); - assert_eq!(actual_refund, (foreign_location_latest, asset_refund).into()); + assert_eq!(actual_refund, (foreign_location.clone(), asset_refund).into()); // assert. assert_eq!(Balances::balance(&staking_pot), initial_balance); @@ -501,17 +497,17 @@ fn test_foreign_asset_xcm_take_first_trader() { .execute_with(|| { // We need root origin to create a sufficient asset let minimum_asset_balance = 3333333_u128; - let foreign_location = xcm::v3::Location { + let foreign_location = xcm::v4::Location { parents: 1, interior: ( - xcm::v3::Junction::Parachain(1234), - xcm::v3::Junction::GeneralIndex(12345), + xcm::v4::Junction::Parachain(1234), + xcm::v4::Junction::GeneralIndex(12345), ) .into(), }; assert_ok!(ForeignAssets::force_create( RuntimeHelper::root_origin(), - foreign_location.into(), + foreign_location.clone().into(), AccountId::from(ALICE).into(), true, minimum_asset_balance @@ -520,12 +516,12 @@ fn test_foreign_asset_xcm_take_first_trader() { // We first mint enough asset for the account to exist for assets assert_ok!(ForeignAssets::mint( RuntimeHelper::origin_of(AccountId::from(ALICE)), - foreign_location.into(), + foreign_location.clone().into(), AccountId::from(ALICE).into(), minimum_asset_balance )); - let asset_location_v4: Location = foreign_location.try_into().unwrap(); + let asset_location_v4: Location = foreign_location.clone().try_into().unwrap(); // Set Alice as block author, who will receive fees RuntimeHelper::run_to_block(2, AccountId::from(ALICE)); @@ -534,7 +530,7 @@ fn test_foreign_asset_xcm_take_first_trader() { let bought = Weight::from_parts(4_000_000_000u64, 0); // Lets calculate amount needed - let asset_amount_needed = ForeignAssetFeeAsExistentialDepositMultiplierFeeCharger::charge_weight_in_fungibles(foreign_location, bought) + let asset_amount_needed = ForeignAssetFeeAsExistentialDepositMultiplierFeeCharger::charge_weight_in_fungibles(foreign_location.clone(), bought) .expect("failed to compute"); // Lets pay with: asset_amount_needed + asset_amount_extra @@ -557,7 +553,7 @@ fn test_foreign_asset_xcm_take_first_trader() { // Make sure author(Alice) has received the amount assert_eq!( - ForeignAssets::balance(foreign_location, AccountId::from(ALICE)), + ForeignAssets::balance(foreign_location.clone(), AccountId::from(ALICE)), minimum_asset_balance + asset_amount_needed ); @@ -837,11 +833,11 @@ fn test_assets_balances_api_works() { .build() .execute_with(|| { let local_asset_id = 1; - let foreign_asset_id_location = xcm::v3::Location { + let foreign_asset_id_location = xcm::v4::Location { parents: 1, interior: [ - xcm::v3::Junction::Parachain(1234), - xcm::v3::Junction::GeneralIndex(12345), + xcm::v4::Junction::Parachain(1234), + xcm::v4::Junction::GeneralIndex(12345), ] .into(), }; @@ -849,7 +845,7 @@ fn test_assets_balances_api_works() { // check before assert_eq!(Assets::balance(local_asset_id, AccountId::from(ALICE)), 0); assert_eq!( - ForeignAssets::balance(foreign_asset_id_location, AccountId::from(ALICE)), + ForeignAssets::balance(foreign_asset_id_location.clone(), AccountId::from(ALICE)), 0 ); assert_eq!(Balances::free_balance(AccountId::from(ALICE)), 0); @@ -886,7 +882,7 @@ fn test_assets_balances_api_works() { let foreign_asset_minimum_asset_balance = 3333333_u128; assert_ok!(ForeignAssets::force_create( RuntimeHelper::root_origin(), - foreign_asset_id_location, + foreign_asset_id_location.clone(), AccountId::from(SOME_ASSET_ADMIN).into(), false, foreign_asset_minimum_asset_balance @@ -895,7 +891,7 @@ fn test_assets_balances_api_works() { // We first mint enough asset for the account to exist for assets assert_ok!(ForeignAssets::mint( RuntimeHelper::origin_of(AccountId::from(SOME_ASSET_ADMIN)), - foreign_asset_id_location, + foreign_asset_id_location.clone(), AccountId::from(ALICE).into(), 6 * foreign_asset_minimum_asset_balance )); @@ -906,7 +902,7 @@ fn test_assets_balances_api_works() { minimum_asset_balance ); assert_eq!( - ForeignAssets::balance(foreign_asset_id_location, AccountId::from(ALICE)), + ForeignAssets::balance(foreign_asset_id_location.clone(), AccountId::from(ALICE)), 6 * minimum_asset_balance ); assert_eq!(Balances::free_balance(AccountId::from(ALICE)), some_currency); @@ -932,7 +928,7 @@ fn test_assets_balances_api_works() { .into()))); // check foreign asset assert!(result.inner().iter().any(|asset| asset.eq(&( - WithLatestLocationConverter::::convert_back( + WithLatestLocationConverter::::convert_back( &foreign_asset_id_location ) .unwrap(), @@ -1025,13 +1021,13 @@ asset_test_utils::include_asset_transactor_transfer_with_pallet_assets_instance_ Runtime, XcmConfig, ForeignAssetsInstance, - xcm::v3::Location, + xcm::v4::Location, JustTry, collator_session_keys(), ExistentialDeposit::get(), - xcm::v3::Location { + xcm::v4::Location { parents: 1, - interior: [xcm::v3::Junction::Parachain(1313), xcm::v3::Junction::GeneralIndex(12345)] + interior: [xcm::v4::Junction::Parachain(1313), xcm::v4::Junction::GeneralIndex(12345)] .into() }, Box::new(|| { @@ -1048,8 +1044,8 @@ asset_test_utils::include_create_and_manage_foreign_assets_for_local_consensus_p WeightToFee, ForeignCreatorsSovereignAccountOf, ForeignAssetsInstance, - xcm::v3::Location, - WithLatestLocationConverter, + xcm::v4::Location, + WithLatestLocationConverter, collator_session_keys(), ExistentialDeposit::get(), AssetDeposit::get(), @@ -1127,12 +1123,12 @@ fn receive_reserve_asset_deposited_roc_from_asset_hub_rococo_fees_paid_by_pool_s let staking_pot = StakingPot::get(); let foreign_asset_id_location = - xcm::v3::Location::new(2, [xcm::v3::Junction::GlobalConsensus(xcm::v3::NetworkId::Rococo)]); + xcm::v4::Location::new(2, [xcm::v4::Junction::GlobalConsensus(xcm::v4::NetworkId::Rococo)]); let foreign_asset_id_minimum_balance = 1_000_000_000; // sovereign account as foreign asset owner (can be whoever for this scenario) let foreign_asset_owner = LocationToAccountId::convert_location(&Location::parent()).unwrap(); let foreign_asset_create_params = - (foreign_asset_owner, foreign_asset_id_location, foreign_asset_id_minimum_balance); + (foreign_asset_owner, foreign_asset_id_location.clone(), foreign_asset_id_minimum_balance); asset_test_utils::test_cases_over_bridge::receive_reserve_asset_deposited_from_different_consensus_works::< Runtime, @@ -1166,7 +1162,7 @@ fn receive_reserve_asset_deposited_roc_from_asset_hub_rococo_fees_paid_by_pool_s // check now foreign asset for staking pot assert_eq!( ForeignAssets::balance( - foreign_asset_id_location.into(), + foreign_asset_id_location.clone().into(), &staking_pot ), 0 @@ -1180,7 +1176,7 @@ fn receive_reserve_asset_deposited_roc_from_asset_hub_rococo_fees_paid_by_pool_s // staking pot receives no foreign assets assert_eq!( ForeignAssets::balance( - foreign_asset_id_location.into(), + foreign_asset_id_location.clone().into(), &staking_pot ), 0 @@ -1196,12 +1192,12 @@ fn receive_reserve_asset_deposited_roc_from_asset_hub_rococo_fees_paid_by_suffic let staking_pot = StakingPot::get(); let foreign_asset_id_location = - xcm::v3::Location::new(2, [xcm::v3::Junction::GlobalConsensus(xcm::v3::NetworkId::Rococo)]); + xcm::v4::Location::new(2, [xcm::v4::Junction::GlobalConsensus(xcm::v4::NetworkId::Rococo)]); let foreign_asset_id_minimum_balance = 1_000_000_000; // sovereign account as foreign asset owner (can be whoever for this scenario) let foreign_asset_owner = LocationToAccountId::convert_location(&Location::parent()).unwrap(); let foreign_asset_create_params = - (foreign_asset_owner, foreign_asset_id_location, foreign_asset_id_minimum_balance); + (foreign_asset_owner, foreign_asset_id_location.clone(), foreign_asset_id_minimum_balance); asset_test_utils::test_cases_over_bridge::receive_reserve_asset_deposited_from_different_consensus_works::< Runtime, @@ -1226,7 +1222,7 @@ fn receive_reserve_asset_deposited_roc_from_asset_hub_rococo_fees_paid_by_suffic // check block author before assert_eq!( ForeignAssets::balance( - foreign_asset_id_location.into(), + foreign_asset_id_location.clone().into(), &block_author_account ), 0 @@ -1236,7 +1232,7 @@ fn receive_reserve_asset_deposited_roc_from_asset_hub_rococo_fees_paid_by_suffic // `TakeFirstAssetTrader` puts fees to the block author assert!( ForeignAssets::balance( - foreign_asset_id_location.into(), + foreign_asset_id_location.clone().into(), &block_author_account ) > 0 ); diff --git a/cumulus/parachains/runtimes/assets/common/src/lib.rs b/cumulus/parachains/runtimes/assets/common/src/lib.rs index d33a8151e3c3..4bb593f98929 100644 --- a/cumulus/parachains/runtimes/assets/common/src/lib.rs +++ b/cumulus/parachains/runtimes/assets/common/src/lib.rs @@ -22,7 +22,6 @@ pub mod fungible_conversion; pub mod local_and_foreign_assets; pub mod matching; pub mod runtime_api; -pub mod foreign_assets_migration; extern crate alloc; diff --git a/cumulus/parachains/runtimes/assets/migrations/Cargo.toml b/cumulus/parachains/runtimes/assets/migrations/Cargo.toml index c0296204df82..ddbd8580cc0f 100644 --- a/cumulus/parachains/runtimes/assets/migrations/Cargo.toml +++ b/cumulus/parachains/runtimes/assets/migrations/Cargo.toml @@ -34,7 +34,6 @@ xcm-executor = { workspace = true } parachains-common = { workspace = true } [dev-dependencies] -sp-io = { workspace = true } hex-display = "0.3.0" [build-dependencies] @@ -59,7 +58,6 @@ std = [ "frame-system/std", "pallet-assets/std", "pallet-balances/std", - "sp-io/std", ] runtime-benchmarks = [ diff --git a/cumulus/parachains/runtimes/assets/migrations/src/lib.rs b/cumulus/parachains/runtimes/assets/migrations/src/lib.rs index 9d7ccf48d3f1..51a631a3c763 100644 --- a/cumulus/parachains/runtimes/assets/migrations/src/lib.rs +++ b/cumulus/parachains/runtimes/assets/migrations/src/lib.rs @@ -16,4 +16,17 @@ //! A utility pallet for migrating storage items in the asset hub runtimes. //! It's only a pallet since the benchmarking machinery requires it. +#![cfg_attr(not(feature = "std"), no_std)] + mod v1; + +pub use pallet::*; + +#[frame_support::pallet] +pub mod pallet { + #[pallet::pallet] + pub struct Pallet(_); + + #[pallet::config] + pub trait Config: frame_system::Config {} +} diff --git a/cumulus/parachains/runtimes/assets/migrations/src/v1/benchmarks.rs b/cumulus/parachains/runtimes/assets/migrations/src/v1/benchmarks.rs index c1dee1c822ee..9af65ad82fdc 100644 --- a/cumulus/parachains/runtimes/assets/migrations/src/v1/benchmarks.rs +++ b/cumulus/parachains/runtimes/assets/migrations/src/v1/benchmarks.rs @@ -20,13 +20,13 @@ use frame_support::{migrations::SteppedMigration, weights::WeightMeter}; use pallet_assets::{Asset, Config}; use xcm::{v3, v4}; -use crate::v1::{old::AssetDetailsOf, AssetDetails, AssetStatus}; +use crate::{ + v1::{old::AssetDetailsOf, AssetDetails, AssetStatus}, + Pallet, +}; use super::{old, Migration}; -// Mocked non-FRAME pallet type to make benchmarks compile. -pub struct Pallet, I: 'static = ()>(core::marker::PhantomData<(T, I)>); - #[instance_benchmarks( // This is needed for the migration and could also be in its own "migration config": where >::AssetId: From @@ -47,7 +47,8 @@ mod benches { Migration::::step(None, &mut meter).unwrap(); } - let new_key: >::AssetId = v4::Location::new(1, [v4::Junction::Parachain(2004)]).into(); + let new_key: >::AssetId = + v4::Location::new(1, [v4::Junction::Parachain(2004)]).into(); assert!(Asset::::contains_key(new_key)); } diff --git a/cumulus/parachains/runtimes/assets/migrations/src/v1/mod.rs b/cumulus/parachains/runtimes/assets/migrations/src/v1/mod.rs index 50aef8088332..162d79f75bd5 100644 --- a/cumulus/parachains/runtimes/assets/migrations/src/v1/mod.rs +++ b/cumulus/parachains/runtimes/assets/migrations/src/v1/mod.rs @@ -28,7 +28,6 @@ use frame_support::{ migrations::{MigrationId, SteppedMigration, SteppedMigrationError}, pallet_prelude::PhantomData, weights::WeightMeter, - Hashable, }; use pallet_assets::{Asset, AssetDetails, AssetStatus, Config}; use xcm::{v3, v4}; @@ -98,20 +97,3 @@ where } } } - -fn mock_asset_details() -> AssetDetails { - AssetDetails { - owner: 0, - issuer: 0, - admin: 0, - freezer: 0, - supply: 0, - deposit: 0, - min_balance: 1, - is_sufficient: false, - accounts: 0, - sufficients: 0, - approvals: 0, - status: AssetStatus::Live, - } -} diff --git a/cumulus/parachains/runtimes/assets/test-utils/src/test_cases.rs b/cumulus/parachains/runtimes/assets/test-utils/src/test_cases.rs index 884b71369e79..67b585ecfe86 100644 --- a/cumulus/parachains/runtimes/assets/test-utils/src/test_cases.rs +++ b/cumulus/parachains/runtimes/assets/test-utils/src/test_cases.rs @@ -367,9 +367,9 @@ pub fn teleports_for_foreign_assets_works< ::Balance: From + Into, SovereignAccountOf: ConvertLocation>, >::AssetId: - From + Into, + From + Into, >::AssetIdParameter: - From + Into, + From + Into, >::Balance: From + Into, ::AccountId: @@ -381,11 +381,11 @@ pub fn teleports_for_foreign_assets_works< { // foreign parachain with the same consensus currency as asset let foreign_para_id = 2222; - let foreign_asset_id_location = xcm::v3::Location { + let foreign_asset_id_location = xcm::v4::Location { parents: 1, interior: [ - xcm::v3::Junction::Parachain(foreign_para_id), - xcm::v3::Junction::GeneralIndex(1234567), + xcm::v4::Junction::Parachain(foreign_para_id), + xcm::v4::Junction::GeneralIndex(1234567), ] .into(), }; @@ -438,14 +438,14 @@ pub fn teleports_for_foreign_assets_works< ); assert_eq!( >::balance( - foreign_asset_id_location.into(), + foreign_asset_id_location.clone().into(), &target_account ), 0.into() ); assert_eq!( >::balance( - foreign_asset_id_location.into(), + foreign_asset_id_location.clone().into(), &CheckingAccount::get() ), 0.into() @@ -454,14 +454,14 @@ pub fn teleports_for_foreign_assets_works< assert_total::< pallet_assets::Pallet, AccountIdOf, - >(foreign_asset_id_location, 0, 0); + >(foreign_asset_id_location.clone(), 0, 0); // create foreign asset (0 total issuance) let asset_minimum_asset_balance = 3333333_u128; assert_ok!( >::force_create( RuntimeHelper::::root_origin(), - foreign_asset_id_location.into(), + foreign_asset_id_location.clone().into(), asset_owner.into(), false, asset_minimum_asset_balance.into() @@ -470,12 +470,9 @@ pub fn teleports_for_foreign_assets_works< assert_total::< pallet_assets::Pallet, AccountIdOf, - >(foreign_asset_id_location, 0, 0); + >(foreign_asset_id_location.clone(), 0, 0); assert!(teleported_foreign_asset_amount > asset_minimum_asset_balance); - let foreign_asset_id_location_latest: Location = - foreign_asset_id_location.try_into().unwrap(); - // 1. process received teleported assets from sibling parachain (foreign_para_id) let xcm = Xcm(vec![ // BuyExecution with relaychain native token @@ -489,12 +486,12 @@ pub fn teleports_for_foreign_assets_works< }, // Process teleported asset ReceiveTeleportedAsset(Assets::from(vec![Asset { - id: AssetId(foreign_asset_id_location_latest.clone()), + id: AssetId(foreign_asset_id_location.clone()), fun: Fungible(teleported_foreign_asset_amount), }])), DepositAsset { assets: Wild(AllOf { - id: AssetId(foreign_asset_id_location_latest.clone()), + id: AssetId(foreign_asset_id_location.clone()), fun: WildFungibility::Fungible, }), beneficiary: Location { @@ -526,7 +523,7 @@ pub fn teleports_for_foreign_assets_works< ); assert_eq!( >::balance( - foreign_asset_id_location.into(), + foreign_asset_id_location.clone().into(), &target_account ), teleported_foreign_asset_amount.into() @@ -538,7 +535,7 @@ pub fn teleports_for_foreign_assets_works< ); assert_eq!( >::balance( - foreign_asset_id_location.into(), + foreign_asset_id_location.clone().into(), &CheckingAccount::get() ), 0.into() @@ -548,7 +545,7 @@ pub fn teleports_for_foreign_assets_works< pallet_assets::Pallet, AccountIdOf, >( - foreign_asset_id_location, + foreign_asset_id_location.clone(), teleported_foreign_asset_amount, teleported_foreign_asset_amount, ); @@ -566,7 +563,7 @@ pub fn teleports_for_foreign_assets_works< let target_account_balance_before_teleport = >::balance( - foreign_asset_id_location.into(), + foreign_asset_id_location.clone().into(), &target_account, ); let asset_to_teleport_away = asset_minimum_asset_balance * 3; @@ -580,7 +577,7 @@ pub fn teleports_for_foreign_assets_works< // Make sure the target account has enough native asset to pay for delivery fees let delivery_fees = xcm_helpers::teleport_assets_delivery_fees::( - (foreign_asset_id_location_latest.clone(), asset_to_teleport_away).into(), + (foreign_asset_id_location.clone(), asset_to_teleport_away).into(), 0, Unlimited, dest_beneficiary.clone(), @@ -596,7 +593,7 @@ pub fn teleports_for_foreign_assets_works< RuntimeHelper::::origin_of(target_account.clone()), dest, dest_beneficiary, - (foreign_asset_id_location_latest.clone(), asset_to_teleport_away), + (foreign_asset_id_location.clone(), asset_to_teleport_away), Some((runtime_para_id, foreign_para_id)), included_head, &alice, @@ -606,14 +603,14 @@ pub fn teleports_for_foreign_assets_works< // check balances assert_eq!( >::balance( - foreign_asset_id_location.into(), + foreign_asset_id_location.clone().into(), &target_account ), (target_account_balance_before_teleport - asset_to_teleport_away.into()) ); assert_eq!( >::balance( - foreign_asset_id_location.into(), + foreign_asset_id_location.clone().into(), &CheckingAccount::get() ), 0.into() @@ -623,7 +620,7 @@ pub fn teleports_for_foreign_assets_works< pallet_assets::Pallet, AccountIdOf, >( - foreign_asset_id_location, + foreign_asset_id_location.clone(), teleported_foreign_asset_amount - asset_to_teleport_away, teleported_foreign_asset_amount - asset_to_teleport_away, ); @@ -1559,9 +1556,6 @@ pub fn reserve_transfer_native_asset_to_non_teleport_para_works< ) .unwrap(); - let v4_xcm: Xcm<()> = xcm_sent.clone().try_into().unwrap(); - dbg!(&v4_xcm); - let delivery_fees = get_fungible_delivery_fees::< ::XcmSender, >(dest.clone(), Xcm::try_from(xcm_sent.clone()).unwrap()); diff --git a/cumulus/parachains/runtimes/assets/test-utils/src/test_cases_over_bridge.rs b/cumulus/parachains/runtimes/assets/test-utils/src/test_cases_over_bridge.rs index 0b2364dbb8bd..e0b3f70c7546 100644 --- a/cumulus/parachains/runtimes/assets/test-utils/src/test_cases_over_bridge.rs +++ b/cumulus/parachains/runtimes/assets/test-utils/src/test_cases_over_bridge.rs @@ -331,7 +331,7 @@ pub fn receive_reserve_asset_deposited_from_different_consensus_works< block_author_account: AccountIdOf, (foreign_asset_owner, foreign_asset_id_location, foreign_asset_id_minimum_balance): ( AccountIdOf, - xcm::v3::Location, + xcm::v4::Location, u128, ), foreign_asset_id_amount_to_transfer: u128, @@ -357,9 +357,9 @@ pub fn receive_reserve_asset_deposited_from_different_consensus_works< BalanceOf: From + Into, XcmConfig: xcm_executor::Config, >::AssetId: - From + Into, + From + Into, >::AssetIdParameter: - From + Into, + From + Into, >::Balance: From + Into + From, ::AccountId: Into<<::RuntimeOrigin as OriginTrait>::AccountId> @@ -390,7 +390,7 @@ pub fn receive_reserve_asset_deposited_from_different_consensus_works< assert_ok!( >::force_create( RuntimeHelper::::root_origin(), - foreign_asset_id_location.into(), + foreign_asset_id_location.clone().into(), foreign_asset_owner.into(), true, // is_sufficient=true foreign_asset_id_minimum_balance.into() @@ -409,7 +409,7 @@ pub fn receive_reserve_asset_deposited_from_different_consensus_works< // ForeignAssets balances before assert_eq!( >::balance( - foreign_asset_id_location.into(), + foreign_asset_id_location.clone().into(), &target_account ), 0.into() @@ -418,11 +418,8 @@ pub fn receive_reserve_asset_deposited_from_different_consensus_works< // additional check before additional_checks_before(); - let foreign_asset_id_location_latest: Location = - foreign_asset_id_location.try_into().unwrap(); - let expected_assets = Assets::from(vec![Asset { - id: AssetId(foreign_asset_id_location_latest.clone()), + id: AssetId(foreign_asset_id_location.clone()), fun: Fungible(foreign_asset_id_amount_to_transfer), }]); let expected_beneficiary = Location::new( @@ -439,7 +436,7 @@ pub fn receive_reserve_asset_deposited_from_different_consensus_works< ClearOrigin, BuyExecution { fees: Asset { - id: AssetId(foreign_asset_id_location_latest.clone()), + id: AssetId(foreign_asset_id_location.clone()), fun: Fungible(foreign_asset_id_amount_to_transfer), }, weight_limit: Unlimited, From 310b1bfa06dbf58eb33803f3c5ef4f577543f49b Mon Sep 17 00:00:00 2001 From: Francisco Aguirre Date: Thu, 1 Aug 2024 13:46:59 +0200 Subject: [PATCH 12/32] fix(assets-common-migrations): tests work --- Cargo.lock | 1 + .../src/weights/assets_common_migrations.rs | 68 +++++++++++++++++++ .../runtimes/assets/migrations/Cargo.toml | 2 + .../assets/migrations/src/v1/benchmarks.rs | 1 - .../assets/migrations/src/v1/tests.rs | 25 +++++-- 5 files changed, 91 insertions(+), 6 deletions(-) create mode 100644 cumulus/parachains/runtimes/assets/asset-hub-westend/src/weights/assets_common_migrations.rs diff --git a/Cargo.lock b/Cargo.lock index 57d6de900e04..9a897d0227a4 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1148,6 +1148,7 @@ dependencies = [ "parity-scale-codec", "scale-info", "sp-api", + "sp-io", "sp-runtime", "staging-xcm", "staging-xcm-builder", diff --git a/cumulus/parachains/runtimes/assets/asset-hub-westend/src/weights/assets_common_migrations.rs b/cumulus/parachains/runtimes/assets/asset-hub-westend/src/weights/assets_common_migrations.rs new file mode 100644 index 000000000000..62d6b6c40de3 --- /dev/null +++ b/cumulus/parachains/runtimes/assets/asset-hub-westend/src/weights/assets_common_migrations.rs @@ -0,0 +1,68 @@ + +//! Autogenerated weights for `assets_common_migrations` +//! +//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 38.0.0 +//! DATE: 2024-08-01, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! WORST CASE MAP SIZE: `1000000` +//! HOSTNAME: `Ciscos-MBP.lan`, CPU: `` +//! WASM-EXECUTION: `Compiled`, CHAIN: `None`, DB CACHE: `1024` + +// Executed Command: +// frame-omni-bencher +// v1 +// benchmark +// pallet +// --runtime +// target/debug/wbuild/asset-hub-westend-runtime/asset_hub_westend_runtime.wasm +// --pallet +// assets_common_migrations +// --extrinsic +// * +// --template +// substrate/.maintain/frame-weight-template.hbs +// --output +// cumulus/parachains/runtimes/assets/asset-hub-westend/src/weights/assets_common_migrations.rs + +#![cfg_attr(rustfmt, rustfmt_skip)] +#![allow(unused_parens)] +#![allow(unused_imports)] +#![allow(missing_docs)] + +use frame_support::{traits::Get, weights::{Weight, constants::RocksDbWeight}}; +use core::marker::PhantomData; + +/// Weight functions needed for `assets_common_migrations`. +pub trait WeightInfo { + fn step() -> Weight; +} + +/// Weights for `assets_common_migrations` using the Substrate node and recommended hardware. +pub struct SubstrateWeight(PhantomData); +impl WeightInfo for SubstrateWeight { + /// Storage: `ForeignAssets::Asset` (r:2 w:1) + /// Proof: `ForeignAssets::Asset` (`max_values`: None, `max_size`: Some(808), added: 3283, mode: `MaxEncodedLen`) + fn step() -> Weight { + // Proof Size summary in bytes: + // Measured: `161` + // Estimated: `7556` + // Minimum execution time: 12_000_000 picoseconds. + Weight::from_parts(14_000_000, 7556) + .saturating_add(T::DbWeight::get().reads(2_u64)) + .saturating_add(T::DbWeight::get().writes(1_u64)) + } +} + +// For backwards compatibility and tests. +impl WeightInfo for () { + /// Storage: `ForeignAssets::Asset` (r:2 w:1) + /// Proof: `ForeignAssets::Asset` (`max_values`: None, `max_size`: Some(808), added: 3283, mode: `MaxEncodedLen`) + fn step() -> Weight { + // Proof Size summary in bytes: + // Measured: `161` + // Estimated: `7556` + // Minimum execution time: 12_000_000 picoseconds. + Weight::from_parts(14_000_000, 7556) + .saturating_add(RocksDbWeight::get().reads(2_u64)) + .saturating_add(RocksDbWeight::get().writes(1_u64)) + } +} diff --git a/cumulus/parachains/runtimes/assets/migrations/Cargo.toml b/cumulus/parachains/runtimes/assets/migrations/Cargo.toml index ddbd8580cc0f..c0296204df82 100644 --- a/cumulus/parachains/runtimes/assets/migrations/Cargo.toml +++ b/cumulus/parachains/runtimes/assets/migrations/Cargo.toml @@ -34,6 +34,7 @@ xcm-executor = { workspace = true } parachains-common = { workspace = true } [dev-dependencies] +sp-io = { workspace = true } hex-display = "0.3.0" [build-dependencies] @@ -58,6 +59,7 @@ std = [ "frame-system/std", "pallet-assets/std", "pallet-balances/std", + "sp-io/std", ] runtime-benchmarks = [ diff --git a/cumulus/parachains/runtimes/assets/migrations/src/v1/benchmarks.rs b/cumulus/parachains/runtimes/assets/migrations/src/v1/benchmarks.rs index 9af65ad82fdc..ba7f2eb0b63e 100644 --- a/cumulus/parachains/runtimes/assets/migrations/src/v1/benchmarks.rs +++ b/cumulus/parachains/runtimes/assets/migrations/src/v1/benchmarks.rs @@ -38,7 +38,6 @@ mod benches { fn step() { let key = v3::Location::new(1, [v3::Junction::Parachain(2004)]); let mock_asset_details = mock_asset_details::(); - //dbg!(&std::any::type_name::>::AssetId>()); old::Asset::::insert(key.clone(), mock_asset_details); let mut meter = WeightMeter::new(); diff --git a/cumulus/parachains/runtimes/assets/migrations/src/v1/tests.rs b/cumulus/parachains/runtimes/assets/migrations/src/v1/tests.rs index a35202500644..662d4bd7788e 100644 --- a/cumulus/parachains/runtimes/assets/migrations/src/v1/tests.rs +++ b/cumulus/parachains/runtimes/assets/migrations/src/v1/tests.rs @@ -15,19 +15,17 @@ //! Tests for the foreign assets migration. -use codec::Encode; use frame_support::{ construct_runtime, derive_impl, migrations::SteppedMigration, traits::AsEnsureOriginWithArg, - weights::WeightMeter, Hashable, + weights::WeightMeter, }; use frame_system::{EnsureRoot, EnsureSigned}; -use hex_display::HexDisplayExt; use pallet_assets::{Asset, AssetDetails, AssetStatus}; -use sp_io::{hashing, storage, TestExternalities}; +use sp_io::TestExternalities; use sp_runtime::BuildStorage; use xcm::{v3, v4}; -use super::{mock_asset_details, old, Migration}; +use super::{old, Migration}; construct_runtime! { pub struct Runtime { @@ -106,3 +104,20 @@ fn migration_works() { assert!(Asset::::contains_key(new_key)); }) } + +fn mock_asset_details() -> AssetDetails { + AssetDetails { + owner: 0, + issuer: 0, + admin: 0, + freezer: 0, + supply: Default::default(), + deposit: Default::default(), + min_balance: 1u32.into(), + is_sufficient: false, + accounts: Default::default(), + sufficients: Default::default(), + approvals: Default::default(), + status: AssetStatus::Live, + } +} From a619548bffb6766139fe8d687447fb519cde7f28 Mon Sep 17 00:00:00 2001 From: Francisco Aguirre Date: Thu, 1 Aug 2024 13:53:50 +0200 Subject: [PATCH 13/32] doc: prdoc --- prdoc/pr_4129.prdoc | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 prdoc/pr_4129.prdoc diff --git a/prdoc/pr_4129.prdoc b/prdoc/pr_4129.prdoc new file mode 100644 index 000000000000..9e174cf4b35a --- /dev/null +++ b/prdoc/pr_4129.prdoc @@ -0,0 +1,24 @@ +# Schema: Polkadot SDK PRDoc Schema (prdoc) v1.0.0 +# See doc at https://raw.githubusercontent.com/paritytech/polkadot-sdk/master/prdoc/schema_user.json + +title: Migrate ForeignAssets from xcm::v3::Location to xcm::v4::Location + +doc: + - audience: Runtime Dev + description: | + There's a new migration, under the new crate `assets-common-migrations`, that migrates foreign assets + from xcm::v3::Location to xcm::v4::Location. + This simplifies a lot of code converting v3 to v4 in tests. + It was the missing step from v4 and is a stepping stone for XCMv5. + This is a multi-block migration (MBM), so when executed, it will potentially take some blocks to execute. + The setup for MBMs was done for asset-hub-rococo and asset-hub-westend. + - audience: Runtime User + description: | + There's now a migration for foreign assets from XCMv3 to XCMv4. + The underlying assets are still the same. + +crates: + - name: asset-hub-rococo-runtime + bump: minor + - name: asset-hub-westend-runtime + bump: minor From 2e3931aa6b5333c6d105eca7dcf409aabdcd64ec Mon Sep 17 00:00:00 2001 From: Francisco Aguirre Date: Thu, 1 Aug 2024 13:56:08 +0200 Subject: [PATCH 14/32] fix(assets-common-migrations): some lints --- cumulus/parachains/runtimes/assets/migrations/src/v1/mod.rs | 2 +- cumulus/parachains/runtimes/assets/migrations/src/v1/tests.rs | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/cumulus/parachains/runtimes/assets/migrations/src/v1/mod.rs b/cumulus/parachains/runtimes/assets/migrations/src/v1/mod.rs index 162d79f75bd5..54f7e035bb45 100644 --- a/cumulus/parachains/runtimes/assets/migrations/src/v1/mod.rs +++ b/cumulus/parachains/runtimes/assets/migrations/src/v1/mod.rs @@ -29,7 +29,7 @@ use frame_support::{ pallet_prelude::PhantomData, weights::WeightMeter, }; -use pallet_assets::{Asset, AssetDetails, AssetStatus, Config}; +use pallet_assets::{Asset, Config}; use xcm::{v3, v4}; pub const PALLET_MIGRATIONS_ID: &[u8; 13] = b"pallet-assets"; diff --git a/cumulus/parachains/runtimes/assets/migrations/src/v1/tests.rs b/cumulus/parachains/runtimes/assets/migrations/src/v1/tests.rs index 662d4bd7788e..409713a40c0f 100644 --- a/cumulus/parachains/runtimes/assets/migrations/src/v1/tests.rs +++ b/cumulus/parachains/runtimes/assets/migrations/src/v1/tests.rs @@ -66,6 +66,7 @@ impl pallet_assets::Config for Runtime { } /// Simple conversion of `u32` into an `AssetId` for use in benchmarking. +#[cfg(feature = "runtime-benchmarks")] pub struct XcmBenchmarkHelper; #[cfg(feature = "runtime-benchmarks")] impl pallet_assets::BenchmarkHelper for XcmBenchmarkHelper { @@ -91,7 +92,7 @@ fn migration_works() { new_test_ext().execute_with(|| { let key = v3::Location::new(1, [v3::Junction::Parachain(2004)]); let mock_asset_details = mock_asset_details(); - old::Asset::::insert(key.clone(), mock_asset_details); + old::Asset::::insert(key, mock_asset_details); // Perform one step of the migration. let cursor = Migration::::step(None, &mut WeightMeter::new()).unwrap().unwrap(); From 435a4127de3513b7bcd585a449e4fadd63a99c66 Mon Sep 17 00:00:00 2001 From: Francisco Aguirre Date: Thu, 1 Aug 2024 13:59:13 +0200 Subject: [PATCH 15/32] fix(assets-common-migrations): some fixes and a license --- .../src/weights/assets_common_migrations.rs | 15 +++++++++++++++ .../assets/migrations/src/v1/benchmarks.rs | 7 ++----- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/cumulus/parachains/runtimes/assets/asset-hub-westend/src/weights/assets_common_migrations.rs b/cumulus/parachains/runtimes/assets/asset-hub-westend/src/weights/assets_common_migrations.rs index 62d6b6c40de3..ce3430d81e04 100644 --- a/cumulus/parachains/runtimes/assets/asset-hub-westend/src/weights/assets_common_migrations.rs +++ b/cumulus/parachains/runtimes/assets/asset-hub-westend/src/weights/assets_common_migrations.rs @@ -1,3 +1,18 @@ +// Copyright (C) Parity Technologies (UK) Ltd. +// This file is part of Polkadot. + +// Polkadot is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// Polkadot is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with Polkadot. If not, see . //! Autogenerated weights for `assets_common_migrations` //! diff --git a/cumulus/parachains/runtimes/assets/migrations/src/v1/benchmarks.rs b/cumulus/parachains/runtimes/assets/migrations/src/v1/benchmarks.rs index ba7f2eb0b63e..3e6d968a1de3 100644 --- a/cumulus/parachains/runtimes/assets/migrations/src/v1/benchmarks.rs +++ b/cumulus/parachains/runtimes/assets/migrations/src/v1/benchmarks.rs @@ -17,13 +17,10 @@ use frame_benchmarking::v2::*; use frame_support::{migrations::SteppedMigration, weights::WeightMeter}; -use pallet_assets::{Asset, Config}; +use pallet_assets::{Asset, AssetDetails, AssetStatus, Config}; use xcm::{v3, v4}; -use crate::{ - v1::{old::AssetDetailsOf, AssetDetails, AssetStatus}, - Pallet, -}; +use crate::{v1::old::AssetDetailsOf, Pallet}; use super::{old, Migration}; From b43ae14df2b6702e3e656ee6c2935988cbf48db7 Mon Sep 17 00:00:00 2001 From: Francisco Aguirre Date: Thu, 1 Aug 2024 18:16:10 +0200 Subject: [PATCH 16/32] fix(asset-hub-westend): actually run the migration --- .../assets/asset-hub-rococo/src/lib.rs | 7 +++++- .../assets/asset-hub-westend/Cargo.toml | 4 ++++ .../assets/asset-hub-westend/src/lib.rs | 24 ++++++++++++++++--- .../runtimes/assets/migrations/src/lib.rs | 2 +- .../runtimes/assets/migrations/src/v1/mod.rs | 2 +- 5 files changed, 33 insertions(+), 6 deletions(-) diff --git a/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/lib.rs b/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/lib.rs index f3454662829f..e9aacdfbc92a 100644 --- a/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/lib.rs +++ b/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/lib.rs @@ -195,7 +195,7 @@ impl pallet_migrations::Config for Runtime { } type MultiBlockMigrations = - (assets_common::foreign_assets_migration::Migration,); + (assets_common_migrations::v1::Migration,); impl pallet_timestamp::Config for Runtime { /// A timestamp: milliseconds since the unix epoch. @@ -1141,6 +1141,7 @@ mod benches { [cumulus_pallet_xcmp_queue, XcmpQueue] [pallet_xcm_bridge_hub_router, ToWestend] [pallet_asset_conversion_ops, AssetConversionMigration] + [assets_common_migrations, AssetsCommonMigrations] // XCM [pallet_xcm, PalletXcmExtrinsicsBenchmark::] // NOTE: Make sure you point to the individual modules below. @@ -1451,6 +1452,8 @@ impl_runtime_apis! { type XcmBalances = pallet_xcm_benchmarks::fungible::Pallet::; type XcmGeneric = pallet_xcm_benchmarks::generic::Pallet::; + type AssetsCommonMigrations = assets_common_migrations::Pallet::; + // Benchmark files generated for `Assets/ForeignAssets` instances are by default // `pallet_assets_assets.rs / pallet_assets_foreign_assets`, which is not really nice, // so with this redefinition we can change names to nicer: @@ -1754,6 +1757,8 @@ impl_runtime_apis! { type XcmBalances = pallet_xcm_benchmarks::fungible::Pallet::; type XcmGeneric = pallet_xcm_benchmarks::generic::Pallet::; + type AssetsCommonMigrations = assets_common_migrations::Pallet::; + type Local = pallet_assets::Pallet::; type Foreign = pallet_assets::Pallet::; type Pool = pallet_assets::Pallet::; diff --git a/cumulus/parachains/runtimes/assets/asset-hub-westend/Cargo.toml b/cumulus/parachains/runtimes/assets/asset-hub-westend/Cargo.toml index 251b0651a73f..167ebff5dab4 100644 --- a/cumulus/parachains/runtimes/assets/asset-hub-westend/Cargo.toml +++ b/cumulus/parachains/runtimes/assets/asset-hub-westend/Cargo.toml @@ -44,6 +44,7 @@ pallet-transaction-payment = { workspace = true } pallet-transaction-payment-rpc-runtime-api = { workspace = true } pallet-uniques = { workspace = true } pallet-utility = { workspace = true } +pallet-migrations = { workspace = true } sp-api = { workspace = true } sp-block-builder = { workspace = true } sp-consensus-aura = { workspace = true } @@ -130,6 +131,7 @@ runtime-benchmarks = [ "pallet-timestamp/runtime-benchmarks", "pallet-uniques/runtime-benchmarks", "pallet-utility/runtime-benchmarks", + "pallet-migrations/runtime-benchmarks", "pallet-xcm-benchmarks/runtime-benchmarks", "pallet-xcm-bridge-hub-router/runtime-benchmarks", "pallet-xcm/runtime-benchmarks", @@ -170,6 +172,7 @@ try-runtime = [ "pallet-transaction-payment/try-runtime", "pallet-uniques/try-runtime", "pallet-utility/try-runtime", + "pallet-migrations/try-runtime", "pallet-xcm-bridge-hub-router/try-runtime", "pallet-xcm/try-runtime", "parachain-info/try-runtime", @@ -224,6 +227,7 @@ std = [ "pallet-transaction-payment/std", "pallet-uniques/std", "pallet-utility/std", + "pallet-migrations/std", "pallet-xcm-benchmarks?/std", "pallet-xcm-bridge-hub-router/std", "pallet-xcm/std", diff --git a/cumulus/parachains/runtimes/assets/asset-hub-westend/src/lib.rs b/cumulus/parachains/runtimes/assets/asset-hub-westend/src/lib.rs index 91d1dbedb8d6..6f4f74580d23 100644 --- a/cumulus/parachains/runtimes/assets/asset-hub-westend/src/lib.rs +++ b/cumulus/parachains/runtimes/assets/asset-hub-westend/src/lib.rs @@ -41,6 +41,7 @@ use frame_support::{ construct_runtime, derive_impl, dispatch::DispatchClass, genesis_builder_helper::{build_state, get_preset}, + migrations::FreezeChainOnFailedMigration, ord_parameter_types, parameter_types, traits::{ fungible, fungibles, @@ -173,8 +174,24 @@ impl frame_system::Config for Runtime { type SS58Prefix = SS58Prefix; type OnSetCode = cumulus_pallet_parachain_system::ParachainSetCode; type MaxConsumers = frame_support::traits::ConstU32<16>; + type SingleBlockMigrations = SingleBlockMigrations; + type MultiBlockMigrator = MultiBlockMigrator; } +impl pallet_migrations::Config for Runtime { + type RuntimeEvent = RuntimeEvent; + type Migrations = MultiBlockMigrations; + type CursorMaxLen = ConstU32<256>; + type IdentifierMaxLen = ConstU32<256>; + type MigrationStatusHandler = (); + type FailedMigrationHandler = FreezeChainOnFailedMigration; + type MaxServiceWeight = (); + type WeightInfo = (); +} + +type MultiBlockMigrations = + (assets_common_migrations::v1::Migration,); + impl pallet_timestamp::Config for Runtime { /// A timestamp: milliseconds since the unix epoch. type Moment = u64; @@ -938,6 +955,7 @@ construct_runtime!( // RandomnessCollectiveFlip = 2 removed Timestamp: pallet_timestamp = 3, ParachainInfo: parachain_info = 4, + MultiBlockMigrator: pallet_migrations = 5, // Monetary stuff. Balances: pallet_balances = 10, @@ -1011,7 +1029,7 @@ pub type UncheckedExtrinsic = generic::UncheckedExtrinsic; /// Migrations to apply on runtime upgrade. -pub type Migrations = ( +pub type SingleBlockMigrations = ( // v9420 pallet_nfts::migration::v1::MigrateToV1, // unreleased @@ -1138,7 +1156,7 @@ pub type Executive = frame_executive::Executive< frame_system::ChainContext, Runtime, AllPalletsWithSystem, - Migrations, + (), >; #[cfg(feature = "runtime-benchmarks")] @@ -1164,9 +1182,9 @@ mod benches { [cumulus_pallet_xcmp_queue, XcmpQueue] [pallet_xcm_bridge_hub_router, ToRococo] [pallet_asset_conversion_ops, AssetConversionMigration] + [assets_common_migrations, AssetsCommonMigrations] // XCM [pallet_xcm, PalletXcmExtrinsicsBenchmark::] - [assets_common_migrations, AssetsCommonMigrations] // NOTE: Make sure you point to the individual modules below. [pallet_xcm_benchmarks::fungible, XcmBalances] [pallet_xcm_benchmarks::generic, XcmGeneric] diff --git a/cumulus/parachains/runtimes/assets/migrations/src/lib.rs b/cumulus/parachains/runtimes/assets/migrations/src/lib.rs index 51a631a3c763..43adc1c677c2 100644 --- a/cumulus/parachains/runtimes/assets/migrations/src/lib.rs +++ b/cumulus/parachains/runtimes/assets/migrations/src/lib.rs @@ -18,7 +18,7 @@ #![cfg_attr(not(feature = "std"), no_std)] -mod v1; +pub mod v1; pub use pallet::*; diff --git a/cumulus/parachains/runtimes/assets/migrations/src/v1/mod.rs b/cumulus/parachains/runtimes/assets/migrations/src/v1/mod.rs index 54f7e035bb45..cfaa54efffae 100644 --- a/cumulus/parachains/runtimes/assets/migrations/src/v1/mod.rs +++ b/cumulus/parachains/runtimes/assets/migrations/src/v1/mod.rs @@ -85,7 +85,7 @@ where old::Asset::::remove(&key); let new_key: >::AssetId = new_key.into(); Asset::::insert(&new_key, value); - log::info!(target: "migration", "Successfully migrated key: {:?}", new_key); + log::trace!(target: "migration", "Successfully migrated key: {:?}", new_key); } else { log::warn!(target: "migration", "{:?} couldn't be converted to V4", key); } From be9a5203a6ec2d16b157b52a8529aaa13fc6e273 Mon Sep 17 00:00:00 2001 From: Francisco Aguirre Date: Thu, 1 Aug 2024 18:25:02 +0200 Subject: [PATCH 17/32] fix: update Cargo.lock --- Cargo.lock | 1 + 1 file changed, 1 insertion(+) diff --git a/Cargo.lock b/Cargo.lock index 9a897d0227a4..6d3bf267f65d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1033,6 +1033,7 @@ dependencies = [ "pallet-balances", "pallet-collator-selection", "pallet-message-queue", + "pallet-migrations", "pallet-multisig", "pallet-nft-fractionalization", "pallet-nfts", From 3d3e718119cf6b703117d827e6d279e51eb82db6 Mon Sep 17 00:00:00 2001 From: Francisco Aguirre Date: Thu, 1 Aug 2024 19:04:12 +0200 Subject: [PATCH 18/32] fix(asset-hub-westend): missing dependency --- Cargo.lock | 1 + cumulus/parachains/runtimes/assets/asset-hub-rococo/Cargo.toml | 3 +++ 2 files changed, 4 insertions(+) diff --git a/Cargo.lock b/Cargo.lock index 46b62dd92fa6..a13dca80097e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -868,6 +868,7 @@ version = "0.11.0" dependencies = [ "asset-test-utils", "assets-common", + "assets-common-migrations", "bp-asset-hub-rococo", "bp-asset-hub-westend", "bp-bridge-hub-rococo", diff --git a/cumulus/parachains/runtimes/assets/asset-hub-rococo/Cargo.toml b/cumulus/parachains/runtimes/assets/asset-hub-rococo/Cargo.toml index c8a321af0956..025862aef4e4 100644 --- a/cumulus/parachains/runtimes/assets/asset-hub-rococo/Cargo.toml +++ b/cumulus/parachains/runtimes/assets/asset-hub-rococo/Cargo.toml @@ -87,6 +87,7 @@ parachain-info = { workspace = true } parachains-common = { workspace = true } testnet-parachains-constants = { features = ["rococo"], workspace = true } assets-common = { workspace = true } +assets-common-migrations = { workspace = true } # Bridges pallet-xcm-bridge-hub-router = { workspace = true } @@ -106,6 +107,7 @@ substrate-wasm-builder = { optional = true, workspace = true, default-features = default = ["std"] runtime-benchmarks = [ "assets-common/runtime-benchmarks", + "assets-common-migrations/runtime-benchmarks", "cumulus-pallet-parachain-system/runtime-benchmarks", "cumulus-pallet-session-benchmarking/runtime-benchmarks", "cumulus-pallet-xcmp-queue/runtime-benchmarks", @@ -179,6 +181,7 @@ try-runtime = [ ] std = [ "assets-common/std", + "assets-common-migrations/std", "bp-asset-hub-rococo/std", "bp-asset-hub-westend/std", "bp-bridge-hub-rococo/std", From 9fe6e8b453b76c182e40e96c224737b2a73c989f Mon Sep 17 00:00:00 2001 From: Francisco Aguirre Date: Fri, 2 Aug 2024 16:01:54 +0200 Subject: [PATCH 19/32] fix: moved test code from using v3 to v4 --- .../emulated/common/src/lib.rs | 10 ++--- .../assets/asset-hub-rococo/src/tests/send.rs | 11 ++--- .../assets/asset-hub-rococo/src/tests/swap.rs | 41 +++++++++---------- .../asset-hub-rococo/src/tests/teleport.rs | 6 +-- .../tests/assets/asset-hub-westend/src/lib.rs | 5 +-- .../asset-hub-westend/src/tests/send.rs | 11 ++--- .../asset-hub-westend/src/tests/swap.rs | 38 ++++++++--------- .../asset-hub-westend/src/tests/teleport.rs | 6 +-- 8 files changed, 56 insertions(+), 72 deletions(-) diff --git a/cumulus/parachains/integration-tests/emulated/common/src/lib.rs b/cumulus/parachains/integration-tests/emulated/common/src/lib.rs index 7077fbbb0a9a..770fda5d6e5f 100644 --- a/cumulus/parachains/integration-tests/emulated/common/src/lib.rs +++ b/cumulus/parachains/integration-tests/emulated/common/src/lib.rs @@ -63,11 +63,11 @@ pub const PENPAL_ID: u32 = 2000; pub const ASSETS_PALLET_ID: u8 = 50; parameter_types! { - pub PenpalTeleportableAssetLocation: xcm::v3::Location - = xcm::v3::Location::new(1, [ - xcm::v3::Junction::Parachain(PENPAL_ID), - xcm::v3::Junction::PalletInstance(ASSETS_PALLET_ID), - xcm::v3::Junction::GeneralIndex(TELEPORTABLE_ASSET_ID.into()), + pub PenpalTeleportableAssetLocation: xcm::v4::Location + = xcm::v4::Location::new(1, [ + xcm::v4::Junction::Parachain(PENPAL_ID), + xcm::v4::Junction::PalletInstance(ASSETS_PALLET_ID), + xcm::v4::Junction::GeneralIndex(TELEPORTABLE_ASSET_ID.into()), ] ); pub PenpalSiblingSovereignAccount: AccountId = Sibling::from(PENPAL_ID).into_account_truncating(); diff --git a/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-rococo/src/tests/send.rs b/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-rococo/src/tests/send.rs index 364fbd0d439f..ab407611c736 100644 --- a/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-rococo/src/tests/send.rs +++ b/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-rococo/src/tests/send.rs @@ -36,21 +36,18 @@ fn send_xcm_from_para_to_system_para_paying_fee_with_system_assets_works() { let para_sovereign_account = AssetHubRococo::sovereign_account_id_of( AssetHubRococo::sibling_location_of(PenpalA::para_id()), ); - let asset_location_on_penpal = v3::Location::new( + let asset_location_on_penpal = Location::new( 0, - [ - v3::Junction::PalletInstance(ASSETS_PALLET_ID), - v3::Junction::GeneralIndex(ASSET_ID.into()), - ], + [Junction::PalletInstance(ASSETS_PALLET_ID), Junction::GeneralIndex(ASSET_ID.into())], ); let foreign_asset_at_asset_hub = - v3::Location::new(1, [v3::Junction::Parachain(PenpalA::para_id().into())]) + Location::new(1, [Junction::Parachain(PenpalA::para_id().into())]) .appended_with(asset_location_on_penpal) .unwrap(); // Encoded `create_asset` call to be executed in AssetHub let call = AssetHubRococo::create_foreign_asset_call( - foreign_asset_at_asset_hub, + foreign_asset_at_asset_hub.clone(), ASSET_MIN_BALANCE, para_sovereign_account.clone(), ); diff --git a/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-rococo/src/tests/swap.rs b/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-rococo/src/tests/swap.rs index 16e0512da960..ac0c90ba198d 100644 --- a/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-rococo/src/tests/swap.rs +++ b/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-rococo/src/tests/swap.rs @@ -17,13 +17,10 @@ use crate::imports::*; #[test] fn swap_locally_on_chain_using_local_assets() { - let asset_native = Box::new(v3::Location::try_from(RelayLocation::get()).unwrap()); - let asset_one = Box::new(v3::Location::new( + let asset_native = Box::new(Location::try_from(RelayLocation::get()).unwrap()); + let asset_one = Box::new(Location::new( 0, - [ - v3::Junction::PalletInstance(ASSETS_PALLET_ID), - v3::Junction::GeneralIndex(ASSET_ID.into()), - ], + [Junction::PalletInstance(ASSETS_PALLET_ID), Junction::GeneralIndex(ASSET_ID.into())], )); AssetHubRococo::execute_with(|| { @@ -112,11 +109,11 @@ fn swap_locally_on_chain_using_local_assets() { #[test] fn swap_locally_on_chain_using_foreign_assets() { - let asset_native = Box::new(v3::Location::try_from(RelayLocation::get()).unwrap()); + let asset_native = Box::new(Location::try_from(RelayLocation::get()).unwrap()); let asset_location_on_penpal = - v3::Location::try_from(PenpalLocalTeleportableToAssetHub::get()).unwrap(); + Location::try_from(PenpalLocalTeleportableToAssetHub::get()).unwrap(); let foreign_asset_at_asset_hub_rococo = - v3::Location::new(1, [v3::Junction::Parachain(PenpalA::para_id().into())]) + Location::new(1, [Junction::Parachain(PenpalA::para_id().into())]) .appended_with(asset_location_on_penpal) .unwrap(); @@ -141,7 +138,7 @@ fn swap_locally_on_chain_using_foreign_assets() { // 1. Mint foreign asset (in reality this should be a teleport or some such) assert_ok!(::ForeignAssets::mint( ::RuntimeOrigin::signed(sov_penpal_on_ahr.clone().into()), - foreign_asset_at_asset_hub_rococo, + foreign_asset_at_asset_hub_rococo.clone(), sov_penpal_on_ahr.clone().into(), ASSET_HUB_ROCOCO_ED * 3_000_000_000_000, )); @@ -157,7 +154,7 @@ fn swap_locally_on_chain_using_foreign_assets() { assert_ok!(::AssetConversion::create_pool( ::RuntimeOrigin::signed(AssetHubRococoSender::get()), asset_native.clone(), - Box::new(foreign_asset_at_asset_hub_rococo), + Box::new(foreign_asset_at_asset_hub_rococo.clone()), )); assert_expected_events!( @@ -171,7 +168,7 @@ fn swap_locally_on_chain_using_foreign_assets() { assert_ok!(::AssetConversion::add_liquidity( ::RuntimeOrigin::signed(sov_penpal_on_ahr.clone()), asset_native.clone(), - Box::new(foreign_asset_at_asset_hub_rococo), + Box::new(foreign_asset_at_asset_hub_rococo.clone()), 1_000_000_000_000, 2_000_000_000_000, 0, @@ -189,7 +186,7 @@ fn swap_locally_on_chain_using_foreign_assets() { ); // 4. Swap! - let path = vec![asset_native.clone(), Box::new(foreign_asset_at_asset_hub_rococo)]; + let path = vec![asset_native.clone(), Box::new(foreign_asset_at_asset_hub_rococo.clone())]; assert_ok!( ::AssetConversion::swap_exact_tokens_for_tokens( @@ -216,7 +213,7 @@ fn swap_locally_on_chain_using_foreign_assets() { assert_ok!(::AssetConversion::remove_liquidity( ::RuntimeOrigin::signed(sov_penpal_on_ahr.clone()), asset_native.clone(), - Box::new(foreign_asset_at_asset_hub_rococo), + Box::new(foreign_asset_at_asset_hub_rococo.clone()), 1414213562273 - ASSET_HUB_ROCOCO_ED * 2, // all but the 2 EDs can't be retrieved. 0, 0, @@ -252,8 +249,8 @@ fn cannot_create_pool_from_pool_assets() { assert_matches::assert_matches!( ::AssetConversion::create_pool( ::RuntimeOrigin::signed(AssetHubRococoSender::get()), - Box::new(v3::Location::try_from(asset_native).unwrap()), - Box::new(v3::Location::try_from(asset_one).unwrap()), + Box::new(Location::try_from(asset_native).unwrap()), + Box::new(Location::try_from(asset_one).unwrap()), ), Err(DispatchError::Module(ModuleError{index: _, error: _, message})) => assert_eq!(message, Some("Unknown")) ); @@ -262,12 +259,12 @@ fn cannot_create_pool_from_pool_assets() { #[test] fn pay_xcm_fee_with_some_asset_swapped_for_native() { - let asset_native = v3::Location::try_from(RelayLocation::get()).unwrap(); - let asset_one = xcm::v3::Location { + let asset_native = Location::try_from(RelayLocation::get()).unwrap(); + let asset_one = Location { parents: 0, interior: [ - xcm::v3::Junction::PalletInstance(ASSETS_PALLET_ID), - xcm::v3::Junction::GeneralIndex(ASSET_ID.into()), + Junction::PalletInstance(ASSETS_PALLET_ID), + Junction::GeneralIndex(ASSET_ID.into()), ] .into(), }; @@ -296,8 +293,8 @@ fn pay_xcm_fee_with_some_asset_swapped_for_native() { assert_ok!(::AssetConversion::create_pool( ::RuntimeOrigin::signed(AssetHubRococoSender::get()), - Box::new(asset_native), - Box::new(asset_one), + Box::new(asset_native.clone()), + Box::new(asset_one.clone()), )); assert_expected_events!( diff --git a/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-rococo/src/tests/teleport.rs b/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-rococo/src/tests/teleport.rs index f74378d7631a..5f9131b8c123 100644 --- a/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-rococo/src/tests/teleport.rs +++ b/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-rococo/src/tests/teleport.rs @@ -141,7 +141,6 @@ fn penpal_to_ah_foreign_assets_receiver_assertions(t: ParaToSystemParaTest) { ); let (expected_foreign_asset_id, expected_foreign_asset_amount) = non_fee_asset(&t.args.assets, t.args.fee_asset_item as usize).unwrap(); - let expected_foreign_asset_id_v3: v3::Location = expected_foreign_asset_id.try_into().unwrap(); AssetHubRococo::assert_xcmp_queue_success(None); @@ -159,7 +158,7 @@ fn penpal_to_ah_foreign_assets_receiver_assertions(t: ParaToSystemParaTest) { who: *who == t.receiver.account_id, }, RuntimeEvent::ForeignAssets(pallet_assets::Event::Issued { asset_id, owner, amount }) => { - asset_id: *asset_id == expected_foreign_asset_id_v3, + asset_id: *asset_id == expected_foreign_asset_id, owner: *owner == t.receiver.account_id, amount: *amount == expected_foreign_asset_amount, }, @@ -173,7 +172,6 @@ fn ah_to_penpal_foreign_assets_sender_assertions(t: SystemParaToParaTest) { AssetHubRococo::assert_xcm_pallet_attempted_complete(None); let (expected_foreign_asset_id, expected_foreign_asset_amount) = non_fee_asset(&t.args.assets, t.args.fee_asset_item as usize).unwrap(); - let expected_foreign_asset_id_v3: v3::Location = expected_foreign_asset_id.try_into().unwrap(); assert_expected_events!( AssetHubRococo, vec![ @@ -189,7 +187,7 @@ fn ah_to_penpal_foreign_assets_sender_assertions(t: SystemParaToParaTest) { }, // foreign asset is burned locally as part of teleportation RuntimeEvent::ForeignAssets(pallet_assets::Event::Burned { asset_id, owner, balance }) => { - asset_id: *asset_id == expected_foreign_asset_id_v3, + asset_id: *asset_id == expected_foreign_asset_id, owner: *owner == t.sender.account_id, balance: *balance == expected_foreign_asset_amount, }, diff --git a/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-westend/src/lib.rs b/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-westend/src/lib.rs index 060c3fb39254..e5c8a11572c0 100644 --- a/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-westend/src/lib.rs +++ b/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-westend/src/lib.rs @@ -26,10 +26,7 @@ mod imports { }; // Polkadot - pub use xcm::{ - prelude::{AccountId32 as AccountId32Junction, *}, - v3, - }; + pub use xcm::prelude::{AccountId32 as AccountId32Junction, *}; pub use xcm_executor::traits::TransferType; // Cumulus diff --git a/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-westend/src/tests/send.rs b/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-westend/src/tests/send.rs index eb0e985cc0ce..ac006653ca67 100644 --- a/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-westend/src/tests/send.rs +++ b/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-westend/src/tests/send.rs @@ -36,21 +36,18 @@ fn send_xcm_from_para_to_system_para_paying_fee_with_system_assets_works() { let para_sovereign_account = AssetHubWestend::sovereign_account_id_of( AssetHubWestend::sibling_location_of(PenpalA::para_id()), ); - let asset_location_on_penpal = v3::Location::new( + let asset_location_on_penpal = Location::new( 0, - [ - v3::Junction::PalletInstance(ASSETS_PALLET_ID), - v3::Junction::GeneralIndex(ASSET_ID.into()), - ], + [Junction::PalletInstance(ASSETS_PALLET_ID), Junction::GeneralIndex(ASSET_ID.into())], ); let foreign_asset_at_asset_hub = - v3::Location::new(1, [v3::Junction::Parachain(PenpalA::para_id().into())]) + Location::new(1, [Junction::Parachain(PenpalA::para_id().into())]) .appended_with(asset_location_on_penpal) .unwrap(); // Encoded `create_asset` call to be executed in AssetHub let call = AssetHubWestend::create_foreign_asset_call( - foreign_asset_at_asset_hub, + foreign_asset_at_asset_hub.clone(), ASSET_MIN_BALANCE, para_sovereign_account.clone(), ); diff --git a/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-westend/src/tests/swap.rs b/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-westend/src/tests/swap.rs index cf429378cf6d..1a2821452155 100644 --- a/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-westend/src/tests/swap.rs +++ b/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-westend/src/tests/swap.rs @@ -18,12 +18,12 @@ use crate::imports::*; #[test] fn swap_locally_on_chain_using_local_assets() { let asset_native = - Box::new(v3::Location::try_from(RelayLocation::get()).expect("conversion works")); - let asset_one = Box::new(v3::Location { + Box::new(Location::try_from(RelayLocation::get()).expect("conversion works")); + let asset_one = Box::new(Location { parents: 0, interior: [ - v3::Junction::PalletInstance(ASSETS_PALLET_ID), - v3::Junction::GeneralIndex(ASSET_ID.into()), + Junction::PalletInstance(ASSETS_PALLET_ID), + Junction::GeneralIndex(ASSET_ID.into()), ] .into(), }); @@ -112,11 +112,11 @@ fn swap_locally_on_chain_using_local_assets() { #[test] fn swap_locally_on_chain_using_foreign_assets() { - let asset_native = Box::new(v3::Location::try_from(RelayLocation::get()).unwrap()); + let asset_native = Box::new(Location::try_from(RelayLocation::get()).unwrap()); let asset_location_on_penpal = - v3::Location::try_from(PenpalLocalTeleportableToAssetHub::get()).expect("conversion_works"); + Location::try_from(PenpalLocalTeleportableToAssetHub::get()).expect("conversion_works"); let foreign_asset_at_asset_hub_westend = - v3::Location::new(1, [v3::Junction::Parachain(PenpalA::para_id().into())]) + Location::new(1, [Junction::Parachain(PenpalA::para_id().into())]) .appended_with(asset_location_on_penpal) .unwrap(); @@ -141,7 +141,7 @@ fn swap_locally_on_chain_using_foreign_assets() { // 1. Mint foreign asset (in reality this should be a teleport or some such) assert_ok!(::ForeignAssets::mint( ::RuntimeOrigin::signed(sov_penpal_on_ahr.clone().into()), - foreign_asset_at_asset_hub_westend, + foreign_asset_at_asset_hub_westend.clone(), sov_penpal_on_ahr.clone().into(), ASSET_HUB_WESTEND_ED * 3_000_000_000_000, )); @@ -157,7 +157,7 @@ fn swap_locally_on_chain_using_foreign_assets() { assert_ok!(::AssetConversion::create_pool( ::RuntimeOrigin::signed(AssetHubWestendSender::get()), asset_native.clone(), - Box::new(foreign_asset_at_asset_hub_westend), + Box::new(foreign_asset_at_asset_hub_westend.clone()), )); assert_expected_events!( @@ -171,7 +171,7 @@ fn swap_locally_on_chain_using_foreign_assets() { assert_ok!(::AssetConversion::add_liquidity( ::RuntimeOrigin::signed(sov_penpal_on_ahr.clone()), asset_native.clone(), - Box::new(foreign_asset_at_asset_hub_westend), + Box::new(foreign_asset_at_asset_hub_westend.clone()), 1_000_000_000_000_000, 2_000_000_000_000_000, 0, @@ -189,7 +189,7 @@ fn swap_locally_on_chain_using_foreign_assets() { ); // 4. Swap! - let path = vec![asset_native.clone(), Box::new(foreign_asset_at_asset_hub_westend)]; + let path = vec![asset_native.clone(), Box::new(foreign_asset_at_asset_hub_westend.clone())]; assert_ok!( ::AssetConversion::swap_exact_tokens_for_tokens( @@ -252,8 +252,8 @@ fn cannot_create_pool_from_pool_assets() { assert_matches::assert_matches!( ::AssetConversion::create_pool( ::RuntimeOrigin::signed(AssetHubWestendSender::get()), - Box::new(v3::Location::try_from(asset_native).expect("conversion works")), - Box::new(v3::Location::try_from(asset_one).expect("conversion works")), + Box::new(Location::try_from(asset_native).expect("conversion works")), + Box::new(Location::try_from(asset_one).expect("conversion works")), ), Err(DispatchError::Module(ModuleError{index: _, error: _, message})) => assert_eq!(message, Some("Unknown")) ); @@ -262,12 +262,12 @@ fn cannot_create_pool_from_pool_assets() { #[test] fn pay_xcm_fee_with_some_asset_swapped_for_native() { - let asset_native = v3::Location::try_from(RelayLocation::get()).expect("conversion works"); - let asset_one = xcm::v3::Location { + let asset_native = Location::try_from(RelayLocation::get()).expect("conversion works"); + let asset_one = Location { parents: 0, interior: [ - xcm::v3::Junction::PalletInstance(ASSETS_PALLET_ID), - xcm::v3::Junction::GeneralIndex(ASSET_ID.into()), + Junction::PalletInstance(ASSETS_PALLET_ID), + Junction::GeneralIndex(ASSET_ID.into()), ] .into(), }; @@ -296,8 +296,8 @@ fn pay_xcm_fee_with_some_asset_swapped_for_native() { assert_ok!(::AssetConversion::create_pool( ::RuntimeOrigin::signed(AssetHubWestendSender::get()), - Box::new(asset_native), - Box::new(asset_one), + Box::new(asset_native.clone()), + Box::new(asset_one.clone()), )); assert_expected_events!( diff --git a/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-westend/src/tests/teleport.rs b/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-westend/src/tests/teleport.rs index a524b87b2daf..02a0bc0207bb 100644 --- a/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-westend/src/tests/teleport.rs +++ b/cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-westend/src/tests/teleport.rs @@ -141,7 +141,6 @@ fn penpal_to_ah_foreign_assets_receiver_assertions(t: ParaToSystemParaTest) { ); let (expected_foreign_asset_id, expected_foreign_asset_amount) = non_fee_asset(&t.args.assets, t.args.fee_asset_item as usize).unwrap(); - let expected_foreign_asset_id_v3: v3::Location = expected_foreign_asset_id.try_into().unwrap(); AssetHubWestend::assert_xcmp_queue_success(None); @@ -159,7 +158,7 @@ fn penpal_to_ah_foreign_assets_receiver_assertions(t: ParaToSystemParaTest) { who: *who == t.receiver.account_id, }, RuntimeEvent::ForeignAssets(pallet_assets::Event::Issued { asset_id, owner, amount }) => { - asset_id: *asset_id == expected_foreign_asset_id_v3, + asset_id: *asset_id == expected_foreign_asset_id, owner: *owner == t.receiver.account_id, amount: *amount == expected_foreign_asset_amount, }, @@ -173,7 +172,6 @@ fn ah_to_penpal_foreign_assets_sender_assertions(t: SystemParaToParaTest) { AssetHubWestend::assert_xcm_pallet_attempted_complete(None); let (expected_foreign_asset_id, expected_foreign_asset_amount) = non_fee_asset(&t.args.assets, t.args.fee_asset_item as usize).unwrap(); - let expected_foreign_asset_id_v3: v3::Location = expected_foreign_asset_id.try_into().unwrap(); assert_expected_events!( AssetHubWestend, vec![ @@ -189,7 +187,7 @@ fn ah_to_penpal_foreign_assets_sender_assertions(t: SystemParaToParaTest) { }, // foreign asset is burned locally as part of teleportation RuntimeEvent::ForeignAssets(pallet_assets::Event::Burned { asset_id, owner, balance }) => { - asset_id: *asset_id == expected_foreign_asset_id_v3, + asset_id: *asset_id == expected_foreign_asset_id, owner: *owner == t.sender.account_id, balance: *balance == expected_foreign_asset_amount, }, From 8bb13b7a4970d5392617781d4ab1e7d3b088d82e Mon Sep 17 00:00:00 2001 From: Francisco Aguirre Date: Mon, 5 Aug 2024 14:02:56 +0200 Subject: [PATCH 20/32] fix(assets-common-migrations): make benchmarks work and benchmark asset hubs --- Cargo.lock | 1 + .../assets/asset-hub-rococo/src/lib.rs | 20 ++- .../src/weights/assets_common_migrations.rs | 68 ++++++++ .../asset-hub-rococo/src/weights/mod.rs | 1 + .../assets/asset-hub-rococo/tests/tests.rs | 162 +++++++----------- .../assets/asset-hub-westend/src/lib.rs | 20 ++- .../src/weights/assets_common_migrations.rs | 33 +--- .../asset-hub-westend/src/weights/mod.rs | 1 + .../runtimes/assets/migrations/Cargo.toml | 3 + .../assets/migrations/src/v1/benchmarks.rs | 10 +- .../runtimes/assets/migrations/src/v1/mod.rs | 40 ++++- .../assets/migrations/src/v1/tests.rs | 56 ++++-- .../assets/migrations/src/v1/weights.rs | 83 +++++++++ 13 files changed, 345 insertions(+), 153 deletions(-) create mode 100644 cumulus/parachains/runtimes/assets/asset-hub-rococo/src/weights/assets_common_migrations.rs create mode 100644 cumulus/parachains/runtimes/assets/migrations/src/v1/weights.rs diff --git a/Cargo.lock b/Cargo.lock index a13dca80097e..14854ca28c24 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1145,6 +1145,7 @@ dependencies = [ "pallet-asset-conversion", "pallet-assets", "pallet-balances", + "pallet-migrations", "pallet-xcm", "parachains-common", "parity-scale-codec", diff --git a/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/lib.rs b/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/lib.rs index 3545ee0d6797..b702458d2b11 100644 --- a/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/lib.rs +++ b/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/lib.rs @@ -183,19 +183,31 @@ impl frame_system::Config for Runtime { type MultiBlockMigrator = MultiBlockMigrator; } +// We destine 80% of the block's weight to MBMs. +parameter_types! { + pub MbmServiceWeight: Weight = Perbill::from_percent(80) * RuntimeBlockWeights::get().max_block; +} + impl pallet_migrations::Config for Runtime { type RuntimeEvent = RuntimeEvent; + #[cfg(not(feature = "runtime-benchmarks"))] type Migrations = MultiBlockMigrations; - type CursorMaxLen = ConstU32<256>; + #[cfg(feature = "runtime-benchmarks")] + type Migrations = pallet_migrations::mock_helpers::MockedMigrations; + type CursorMaxLen = ConstU32<1024>; type IdentifierMaxLen = ConstU32<256>; type MigrationStatusHandler = (); type FailedMigrationHandler = FreezeChainOnFailedMigration; - type MaxServiceWeight = (); + type MaxServiceWeight = MbmServiceWeight; type WeightInfo = (); } -type MultiBlockMigrations = - (assets_common_migrations::v1::Migration,); +#[cfg(not(feature = "runtime-benchmarks"))] +type MultiBlockMigrations = assets_common_migrations::v1::Migration< + Runtime, + ForeignAssetsInstance, + weights::assets_common_migrations::SubstrateWeight, +>; impl pallet_timestamp::Config for Runtime { /// A timestamp: milliseconds since the unix epoch. diff --git a/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/weights/assets_common_migrations.rs b/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/weights/assets_common_migrations.rs new file mode 100644 index 000000000000..64225b619fcf --- /dev/null +++ b/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/weights/assets_common_migrations.rs @@ -0,0 +1,68 @@ + +//! Autogenerated weights for `assets_common_migrations` +//! +//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 38.0.0 +//! DATE: 2024-08-05, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! WORST CASE MAP SIZE: `1000000` +//! HOSTNAME: `Ciscos-MBP.lan`, CPU: `` +//! WASM-EXECUTION: `Compiled`, CHAIN: `None`, DB CACHE: `1024` + +// Executed Command: +// frame-omni-bencher +// v1 +// benchmark +// pallet +// --runtime +// target/release/wbuild/asset-hub-rococo-runtime/asset_hub_rococo_runtime.compact.compressed.wasm +// --pallet +// assets_common_migrations +// --extrinsic +// * +// --template +// substrate/.maintain/frame-weight-template.hbs +// --output +// cumulus/parachains/runtimes/assets/asset-hub-rococo/src/weights/assets_common_migrations.rs + +#![cfg_attr(rustfmt, rustfmt_skip)] +#![allow(unused_parens)] +#![allow(unused_imports)] +#![allow(missing_docs)] + +use frame_support::{traits::Get, weights::{Weight, constants::RocksDbWeight}}; +use core::marker::PhantomData; + +/// Weight functions needed for `assets_common_migrations`. +pub trait WeightInfo { + fn conversion_step() -> Weight; +} + +/// Weights for `assets_common_migrations` using the Substrate node and recommended hardware. +pub struct SubstrateWeight(PhantomData); +impl WeightInfo for SubstrateWeight { + /// Storage: `ForeignAssets::Asset` (r:2 w:1) + /// Proof: `ForeignAssets::Asset` (`max_values`: None, `max_size`: Some(808), added: 3283, mode: `MaxEncodedLen`) + fn conversion_step() -> Weight { + // Proof Size summary in bytes: + // Measured: `161` + // Estimated: `7556` + // Minimum execution time: 6_000_000 picoseconds. + Weight::from_parts(7_000_000, 7556) + .saturating_add(T::DbWeight::get().reads(2_u64)) + .saturating_add(T::DbWeight::get().writes(1_u64)) + } +} + +// For backwards compatibility and tests. +impl WeightInfo for () { + /// Storage: `ForeignAssets::Asset` (r:2 w:1) + /// Proof: `ForeignAssets::Asset` (`max_values`: None, `max_size`: Some(808), added: 3283, mode: `MaxEncodedLen`) + fn conversion_step() -> Weight { + // Proof Size summary in bytes: + // Measured: `161` + // Estimated: `7556` + // Minimum execution time: 6_000_000 picoseconds. + Weight::from_parts(7_000_000, 7556) + .saturating_add(RocksDbWeight::get().reads(2_u64)) + .saturating_add(RocksDbWeight::get().writes(1_u64)) + } +} diff --git a/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/weights/mod.rs b/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/weights/mod.rs index f20790cde39c..e43e1f4b3fc0 100644 --- a/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/weights/mod.rs +++ b/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/weights/mod.rs @@ -14,6 +14,7 @@ // You should have received a copy of the GNU General Public License // along with Cumulus. If not, see . +pub mod assets_common_migrations; pub mod block_weights; pub mod cumulus_pallet_parachain_system; pub mod cumulus_pallet_xcmp_queue; diff --git a/cumulus/parachains/runtimes/assets/asset-hub-rococo/tests/tests.rs b/cumulus/parachains/runtimes/assets/asset-hub-rococo/tests/tests.rs index ee1461b7f9c8..83f4f9ec3dc5 100644 --- a/cumulus/parachains/runtimes/assets/asset-hub-rococo/tests/tests.rs +++ b/cumulus/parachains/runtimes/assets/asset-hub-rococo/tests/tests.rs @@ -85,7 +85,7 @@ fn slot_durations() -> SlotDurations { fn setup_pool_for_paying_fees_with_foreign_assets( (foreign_asset_owner, foreign_asset_id_location, foreign_asset_id_minimum_balance): ( AccountId, - xcm::v3::Location, + Location, Balance, ), ) { @@ -93,7 +93,7 @@ fn setup_pool_for_paying_fees_with_foreign_assets( // setup a pool to pay fees with `foreign_asset_id_location` tokens let pool_owner: AccountId = [14u8; 32].into(); - let native_asset = xcm::v3::Location::parent(); + let native_asset = Location::parent(); let pool_liquidity: Balance = existential_deposit.max(foreign_asset_id_minimum_balance).mul(100_000); @@ -105,15 +105,15 @@ fn setup_pool_for_paying_fees_with_foreign_assets( assert_ok!(ForeignAssets::mint( RuntimeOrigin::signed(foreign_asset_owner), - foreign_asset_id_location.into(), + foreign_asset_id_location.clone().into(), pool_owner.clone().into(), (foreign_asset_id_minimum_balance + pool_liquidity).mul(2).into(), )); assert_ok!(AssetConversion::create_pool( RuntimeOrigin::signed(pool_owner.clone()), - Box::new(native_asset.into()), - Box::new(foreign_asset_id_location.into()) + Box::new(native_asset.clone().into()), + Box::new(foreign_asset_id_location.clone().into()) )); assert_ok!(AssetConversion::add_liquidity( @@ -217,24 +217,14 @@ fn test_buy_and_refund_weight_with_swap_local_asset_xcm_trader() { assert_ok!(AssetConversion::create_pool( RuntimeHelper::origin_of(bob.clone()), - Box::new( - xcm::v3::Location::try_from(native_location.clone()).expect("conversion works") - ), - Box::new( - xcm::v3::Location::try_from(asset_1_location.clone()) - .expect("conversion works") - ) + Box::new(Location::try_from(native_location.clone()).expect("conversion works")), + Box::new(Location::try_from(asset_1_location.clone()).expect("conversion works")) )); assert_ok!(AssetConversion::add_liquidity( RuntimeHelper::origin_of(bob.clone()), - Box::new( - xcm::v3::Location::try_from(native_location.clone()).expect("conversion works") - ), - Box::new( - xcm::v3::Location::try_from(asset_1_location.clone()) - .expect("conversion works") - ), + Box::new(Location::try_from(native_location.clone()).expect("conversion works")), + Box::new(Location::try_from(asset_1_location.clone()).expect("conversion works")), pool_liquidity, pool_liquidity, 1, @@ -270,8 +260,8 @@ fn test_buy_and_refund_weight_with_swap_local_asset_xcm_trader() { let refund_weight = Weight::from_parts(1_000_000_000, 0); let refund = WeightToFee::weight_to_fee(&refund_weight); let (reserve1, reserve2) = AssetConversion::get_reserves( - xcm::v3::Location::try_from(native_location).expect("conversion works"), - xcm::v3::Location::try_from(asset_1_location.clone()).expect("conversion works"), + Location::try_from(native_location).expect("conversion works"), + Location::try_from(asset_1_location.clone()).expect("conversion works"), ) .unwrap(); let asset_refund = @@ -309,14 +299,10 @@ fn test_buy_and_refund_weight_with_swap_foreign_asset_xcm_trader() { let bob: AccountId = SOME_ASSET_ADMIN.into(); let staking_pot = CollatorSelection::account_id(); let native_location = - xcm::v3::Location::try_from(TokenLocation::get()).expect("conversion works"); - let foreign_location = xcm::v3::Location { + Location::try_from(TokenLocation::get()).expect("conversion works"); + let foreign_location = Location { parents: 1, - interior: ( - xcm::v3::Junction::Parachain(1234), - xcm::v3::Junction::GeneralIndex(12345), - ) - .into(), + interior: (Junction::Parachain(1234), Junction::GeneralIndex(12345)).into(), }; // bob's initial balance for native and `asset1` assets. let initial_balance = 200 * UNITS; @@ -325,26 +311,26 @@ fn test_buy_and_refund_weight_with_swap_foreign_asset_xcm_trader() { // init asset, balances and pool. assert_ok!(>::create( - foreign_location, + foreign_location.clone(), bob.clone(), true, 10 )); - assert_ok!(ForeignAssets::mint_into(foreign_location, &bob, initial_balance)); + assert_ok!(ForeignAssets::mint_into(foreign_location.clone(), &bob, initial_balance)); assert_ok!(Balances::mint_into(&bob, initial_balance)); assert_ok!(Balances::mint_into(&staking_pot, initial_balance)); assert_ok!(AssetConversion::create_pool( RuntimeHelper::origin_of(bob.clone()), - Box::new(native_location), - Box::new(foreign_location) + Box::new(native_location.clone()), + Box::new(foreign_location.clone()) )); assert_ok!(AssetConversion::add_liquidity( RuntimeHelper::origin_of(bob.clone()), - Box::new(native_location), - Box::new(foreign_location), + Box::new(native_location.clone()), + Box::new(foreign_location.clone()), pool_liquidity, pool_liquidity, 1, @@ -353,11 +339,9 @@ fn test_buy_and_refund_weight_with_swap_foreign_asset_xcm_trader() { )); // keep initial total issuance to assert later. - let asset_total_issuance = ForeignAssets::total_issuance(foreign_location); + let asset_total_issuance = ForeignAssets::total_issuance(foreign_location.clone()); let native_total_issuance = Balances::total_issuance(); - let foreign_location_latest: Location = foreign_location.try_into().unwrap(); - // prepare input to buy weight. let weight = Weight::from_parts(4_000_000_000, 0); let fee = WeightToFee::weight_to_fee(&weight); @@ -365,7 +349,7 @@ fn test_buy_and_refund_weight_with_swap_foreign_asset_xcm_trader() { AssetConversion::get_amount_in(&fee, &pool_liquidity, &pool_liquidity).unwrap(); let extra_amount = 100; let ctx = XcmContext { origin: None, message_id: XcmHash::default(), topic: None }; - let payment: Asset = (foreign_location_latest.clone(), asset_fee + extra_amount).into(); + let payment: Asset = (foreign_location.clone(), asset_fee + extra_amount).into(); // init trader and buy weight. let mut trader = ::Trader::new(); @@ -373,13 +357,11 @@ fn test_buy_and_refund_weight_with_swap_foreign_asset_xcm_trader() { trader.buy_weight(weight, payment.into(), &ctx).expect("Expected Ok"); // assert. - let unused_amount = unused_asset - .fungible - .get(&foreign_location_latest.clone().into()) - .map_or(0, |a| *a); + let unused_amount = + unused_asset.fungible.get(&foreign_location.clone().into()).map_or(0, |a| *a); assert_eq!(unused_amount, extra_amount); assert_eq!( - ForeignAssets::total_issuance(foreign_location), + ForeignAssets::total_issuance(foreign_location.clone()), asset_total_issuance + asset_fee ); @@ -387,13 +369,13 @@ fn test_buy_and_refund_weight_with_swap_foreign_asset_xcm_trader() { let refund_weight = Weight::from_parts(1_000_000_000, 0); let refund = WeightToFee::weight_to_fee(&refund_weight); let (reserve1, reserve2) = - AssetConversion::get_reserves(native_location, foreign_location).unwrap(); + AssetConversion::get_reserves(native_location, foreign_location.clone()).unwrap(); let asset_refund = AssetConversion::get_amount_out(&refund, &reserve1, &reserve2).unwrap(); // refund. let actual_refund = trader.refund_weight(refund_weight, &ctx).unwrap(); - assert_eq!(actual_refund, (foreign_location_latest, asset_refund).into()); + assert_eq!(actual_refund, (foreign_location.clone(), asset_refund).into()); // assert. assert_eq!(Balances::balance(&staking_pot), initial_balance); @@ -500,17 +482,13 @@ fn test_foreign_asset_xcm_take_first_trader() { .execute_with(|| { // We need root origin to create a sufficient asset let minimum_asset_balance = 3333333_u128; - let foreign_location = xcm::v3::Location { + let foreign_location = Location { parents: 1, - interior: ( - xcm::v3::Junction::Parachain(1234), - xcm::v3::Junction::GeneralIndex(12345), - ) - .into(), + interior: (Junction::Parachain(1234), Junction::GeneralIndex(12345)).into(), }; assert_ok!(ForeignAssets::force_create( RuntimeHelper::root_origin(), - foreign_location.into(), + foreign_location.clone().into(), AccountId::from(ALICE).into(), true, minimum_asset_balance @@ -519,13 +497,11 @@ fn test_foreign_asset_xcm_take_first_trader() { // We first mint enough asset for the account to exist for assets assert_ok!(ForeignAssets::mint( RuntimeHelper::origin_of(AccountId::from(ALICE)), - foreign_location.into(), + foreign_location.clone().into(), AccountId::from(ALICE).into(), minimum_asset_balance )); - let asset_location_v4: Location = foreign_location.try_into().unwrap(); - // Set Alice as block author, who will receive fees RuntimeHelper::run_to_block(2, AccountId::from(ALICE)); @@ -535,7 +511,7 @@ fn test_foreign_asset_xcm_take_first_trader() { // Lets calculate amount needed let asset_amount_needed = ForeignAssetFeeAsExistentialDepositMultiplierFeeCharger::charge_weight_in_fungibles( - foreign_location, + foreign_location.clone(), bought ) .expect("failed to compute"); @@ -543,7 +519,7 @@ fn test_foreign_asset_xcm_take_first_trader() { // Lets pay with: asset_amount_needed + asset_amount_extra let asset_amount_extra = 100_u128; let asset: Asset = - (asset_location_v4.clone(), asset_amount_needed + asset_amount_extra).into(); + (foreign_location.clone(), asset_amount_needed + asset_amount_extra).into(); let mut trader = ::Trader::new(); let ctx = XcmContext { origin: None, message_id: XcmHash::default(), topic: None }; @@ -551,16 +527,15 @@ fn test_foreign_asset_xcm_take_first_trader() { // Lets buy_weight and make sure buy_weight does not return an error let unused_assets = trader.buy_weight(bought, asset.into(), &ctx).expect("Expected Ok"); // Check whether a correct amount of unused assets is returned - assert_ok!( - unused_assets.ensure_contains(&(asset_location_v4, asset_amount_extra).into()) - ); + assert_ok!(unused_assets + .ensure_contains(&(foreign_location.clone(), asset_amount_extra).into())); // Drop trader drop(trader); // Make sure author(Alice) has received the amount assert_eq!( - ForeignAssets::balance(foreign_location, AccountId::from(ALICE)), + ForeignAssets::balance(foreign_location.clone(), AccountId::from(ALICE)), minimum_asset_balance + asset_amount_needed ); @@ -841,15 +816,13 @@ fn test_assets_balances_api_works() { .build() .execute_with(|| { let local_asset_id = 1; - let foreign_asset_id_location = xcm::v3::Location::new( - 1, - [xcm::v3::Junction::Parachain(1234), xcm::v3::Junction::GeneralIndex(12345)], - ); + let foreign_asset_id_location = + Location::new(1, [Junction::Parachain(1234), Junction::GeneralIndex(12345)]); // check before assert_eq!(Assets::balance(local_asset_id, AccountId::from(ALICE)), 0); assert_eq!( - ForeignAssets::balance(foreign_asset_id_location, AccountId::from(ALICE)), + ForeignAssets::balance(foreign_asset_id_location.clone(), AccountId::from(ALICE)), 0 ); assert_eq!(Balances::free_balance(AccountId::from(ALICE)), 0); @@ -886,7 +859,7 @@ fn test_assets_balances_api_works() { let foreign_asset_minimum_asset_balance = 3333333_u128; assert_ok!(ForeignAssets::force_create( RuntimeHelper::root_origin(), - foreign_asset_id_location, + foreign_asset_id_location.clone(), AccountId::from(SOME_ASSET_ADMIN).into(), false, foreign_asset_minimum_asset_balance @@ -895,7 +868,7 @@ fn test_assets_balances_api_works() { // We first mint enough asset for the account to exist for assets assert_ok!(ForeignAssets::mint( RuntimeHelper::origin_of(AccountId::from(SOME_ASSET_ADMIN)), - foreign_asset_id_location, + foreign_asset_id_location.clone(), AccountId::from(ALICE).into(), 6 * foreign_asset_minimum_asset_balance )); @@ -906,7 +879,7 @@ fn test_assets_balances_api_works() { minimum_asset_balance ); assert_eq!( - ForeignAssets::balance(foreign_asset_id_location, AccountId::from(ALICE)), + ForeignAssets::balance(foreign_asset_id_location.clone(), AccountId::from(ALICE)), 6 * minimum_asset_balance ); assert_eq!(Balances::free_balance(AccountId::from(ALICE)), some_currency); @@ -932,10 +905,8 @@ fn test_assets_balances_api_works() { .into()))); // check foreign asset assert!(result.inner().iter().any(|asset| asset.eq(&( - WithLatestLocationConverter::::convert_back( - &foreign_asset_id_location - ) - .unwrap(), + WithLatestLocationConverter::::convert_back(&foreign_asset_id_location) + .unwrap(), 6 * foreign_asset_minimum_asset_balance ) .into()))); @@ -1025,14 +996,11 @@ asset_test_utils::include_asset_transactor_transfer_with_pallet_assets_instance_ Runtime, XcmConfig, ForeignAssetsInstance, - xcm::v3::Location, + Location, JustTry, collator_session_keys(), ExistentialDeposit::get(), - xcm::v3::Location::new( - 1, - [xcm::v3::Junction::Parachain(1313), xcm::v3::Junction::GeneralIndex(12345)] - ), + Location::new(1, [Junction::Parachain(1313), Junction::GeneralIndex(12345)]), Box::new(|| { assert!(Assets::asset_ids().collect::>().is_empty()); }), @@ -1047,8 +1015,8 @@ asset_test_utils::include_create_and_manage_foreign_assets_for_local_consensus_p WeightToFee, ForeignCreatorsSovereignAccountOf, ForeignAssetsInstance, - xcm::v3::Location, - WithLatestLocationConverter, + Location, + WithLatestLocationConverter, collator_session_keys(), ExistentialDeposit::get(), AssetDeposit::get(), @@ -1138,16 +1106,17 @@ mod asset_hub_rococo_tests { let block_author_account = AccountId::from(BLOCK_AUTHOR_ACCOUNT); let staking_pot = StakingPot::get(); - let foreign_asset_id_location = xcm::v3::Location::new( - 2, - [xcm::v3::Junction::GlobalConsensus(xcm::v3::NetworkId::Westend)], - ); + let foreign_asset_id_location = + Location::new(2, [Junction::GlobalConsensus(NetworkId::Westend)]); let foreign_asset_id_minimum_balance = 1_000_000_000; // sovereign account as foreign asset owner (can be whoever for this scenario) let foreign_asset_owner = LocationToAccountId::convert_location(&Location::parent()).unwrap(); - let foreign_asset_create_params = - (foreign_asset_owner, foreign_asset_id_location, foreign_asset_id_minimum_balance); + let foreign_asset_create_params = ( + foreign_asset_owner, + foreign_asset_id_location.clone(), + foreign_asset_id_minimum_balance, + ); asset_test_utils::test_cases_over_bridge::receive_reserve_asset_deposited_from_different_consensus_works::< Runtime, @@ -1181,7 +1150,7 @@ mod asset_hub_rococo_tests { // check now foreign asset for staking pot assert_eq!( ForeignAssets::balance( - foreign_asset_id_location.into(), + foreign_asset_id_location.clone().into(), &staking_pot ), 0 @@ -1195,7 +1164,7 @@ mod asset_hub_rococo_tests { // staking pot receives no foreign assets assert_eq!( ForeignAssets::balance( - foreign_asset_id_location.into(), + foreign_asset_id_location.clone().into(), &staking_pot ), 0 @@ -1211,16 +1180,17 @@ mod asset_hub_rococo_tests { let block_author_account = AccountId::from(BLOCK_AUTHOR_ACCOUNT); let staking_pot = StakingPot::get(); - let foreign_asset_id_location = xcm::v3::Location::new( - 2, - [xcm::v3::Junction::GlobalConsensus(xcm::v3::NetworkId::Westend)], - ); + let foreign_asset_id_location = + Location::new(2, [Junction::GlobalConsensus(NetworkId::Westend)]); let foreign_asset_id_minimum_balance = 1_000_000_000; // sovereign account as foreign asset owner (can be whoever for this scenario) let foreign_asset_owner = LocationToAccountId::convert_location(&Location::parent()).unwrap(); - let foreign_asset_create_params = - (foreign_asset_owner, foreign_asset_id_location, foreign_asset_id_minimum_balance); + let foreign_asset_create_params = ( + foreign_asset_owner, + foreign_asset_id_location.clone(), + foreign_asset_id_minimum_balance, + ); asset_test_utils::test_cases_over_bridge::receive_reserve_asset_deposited_from_different_consensus_works::< Runtime, @@ -1245,7 +1215,7 @@ mod asset_hub_rococo_tests { // check block author before assert_eq!( ForeignAssets::balance( - foreign_asset_id_location.into(), + foreign_asset_id_location.clone().into(), &block_author_account ), 0 @@ -1255,7 +1225,7 @@ mod asset_hub_rococo_tests { // `TakeFirstAssetTrader` puts fees to the block author assert!( ForeignAssets::balance( - foreign_asset_id_location.into(), + foreign_asset_id_location.clone().into(), &block_author_account ) > 0 ); diff --git a/cumulus/parachains/runtimes/assets/asset-hub-westend/src/lib.rs b/cumulus/parachains/runtimes/assets/asset-hub-westend/src/lib.rs index 4cadfe6c287f..d2d03bfe9cd2 100644 --- a/cumulus/parachains/runtimes/assets/asset-hub-westend/src/lib.rs +++ b/cumulus/parachains/runtimes/assets/asset-hub-westend/src/lib.rs @@ -178,19 +178,31 @@ impl frame_system::Config for Runtime { type MultiBlockMigrator = MultiBlockMigrator; } +// We destine 80% of the block's weight to MBMs. +parameter_types! { + pub MbmServiceWeight: Weight = Perbill::from_percent(80) * RuntimeBlockWeights::get().max_block; +} + impl pallet_migrations::Config for Runtime { type RuntimeEvent = RuntimeEvent; + #[cfg(not(feature = "runtime-benchmarks"))] type Migrations = MultiBlockMigrations; - type CursorMaxLen = ConstU32<256>; + #[cfg(feature = "runtime-benchmarks")] + type Migrations = pallet_migrations::mock_helpers::MockedMigrations; + type CursorMaxLen = ConstU32<1024>; type IdentifierMaxLen = ConstU32<256>; type MigrationStatusHandler = (); type FailedMigrationHandler = FreezeChainOnFailedMigration; - type MaxServiceWeight = (); + type MaxServiceWeight = MbmServiceWeight; type WeightInfo = (); } -type MultiBlockMigrations = - (assets_common_migrations::v1::Migration,); +#[cfg(not(feature = "runtime-benchmarks"))] +type MultiBlockMigrations = assets_common_migrations::v1::Migration< + Runtime, + ForeignAssetsInstance, + weights::assets_common_migrations::SubstrateWeight, +>; impl pallet_timestamp::Config for Runtime { /// A timestamp: milliseconds since the unix epoch. diff --git a/cumulus/parachains/runtimes/assets/asset-hub-westend/src/weights/assets_common_migrations.rs b/cumulus/parachains/runtimes/assets/asset-hub-westend/src/weights/assets_common_migrations.rs index ce3430d81e04..20f72027005b 100644 --- a/cumulus/parachains/runtimes/assets/asset-hub-westend/src/weights/assets_common_migrations.rs +++ b/cumulus/parachains/runtimes/assets/asset-hub-westend/src/weights/assets_common_migrations.rs @@ -1,23 +1,8 @@ -// Copyright (C) Parity Technologies (UK) Ltd. -// This file is part of Polkadot. - -// Polkadot is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// Polkadot is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with Polkadot. If not, see . //! Autogenerated weights for `assets_common_migrations` //! //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 38.0.0 -//! DATE: 2024-08-01, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! DATE: 2024-08-05, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]` //! WORST CASE MAP SIZE: `1000000` //! HOSTNAME: `Ciscos-MBP.lan`, CPU: `` //! WASM-EXECUTION: `Compiled`, CHAIN: `None`, DB CACHE: `1024` @@ -28,7 +13,7 @@ // benchmark // pallet // --runtime -// target/debug/wbuild/asset-hub-westend-runtime/asset_hub_westend_runtime.wasm +// target/release/wbuild/asset-hub-westend-runtime/asset_hub_westend_runtime.compact.compressed.wasm // --pallet // assets_common_migrations // --extrinsic @@ -48,7 +33,7 @@ use core::marker::PhantomData; /// Weight functions needed for `assets_common_migrations`. pub trait WeightInfo { - fn step() -> Weight; + fn conversion_step() -> Weight; } /// Weights for `assets_common_migrations` using the Substrate node and recommended hardware. @@ -56,12 +41,12 @@ pub struct SubstrateWeight(PhantomData); impl WeightInfo for SubstrateWeight { /// Storage: `ForeignAssets::Asset` (r:2 w:1) /// Proof: `ForeignAssets::Asset` (`max_values`: None, `max_size`: Some(808), added: 3283, mode: `MaxEncodedLen`) - fn step() -> Weight { + fn conversion_step() -> Weight { // Proof Size summary in bytes: // Measured: `161` // Estimated: `7556` - // Minimum execution time: 12_000_000 picoseconds. - Weight::from_parts(14_000_000, 7556) + // Minimum execution time: 6_000_000 picoseconds. + Weight::from_parts(6_000_000, 7556) .saturating_add(T::DbWeight::get().reads(2_u64)) .saturating_add(T::DbWeight::get().writes(1_u64)) } @@ -71,12 +56,12 @@ impl WeightInfo for SubstrateWeight { impl WeightInfo for () { /// Storage: `ForeignAssets::Asset` (r:2 w:1) /// Proof: `ForeignAssets::Asset` (`max_values`: None, `max_size`: Some(808), added: 3283, mode: `MaxEncodedLen`) - fn step() -> Weight { + fn conversion_step() -> Weight { // Proof Size summary in bytes: // Measured: `161` // Estimated: `7556` - // Minimum execution time: 12_000_000 picoseconds. - Weight::from_parts(14_000_000, 7556) + // Minimum execution time: 6_000_000 picoseconds. + Weight::from_parts(6_000_000, 7556) .saturating_add(RocksDbWeight::get().reads(2_u64)) .saturating_add(RocksDbWeight::get().writes(1_u64)) } diff --git a/cumulus/parachains/runtimes/assets/asset-hub-westend/src/weights/mod.rs b/cumulus/parachains/runtimes/assets/asset-hub-westend/src/weights/mod.rs index 4eebb1f8d786..1dc3421228ca 100644 --- a/cumulus/parachains/runtimes/assets/asset-hub-westend/src/weights/mod.rs +++ b/cumulus/parachains/runtimes/assets/asset-hub-westend/src/weights/mod.rs @@ -13,6 +13,7 @@ // See the License for the specific language governing permissions and // limitations under the License. +pub mod assets_common_migrations; pub mod block_weights; pub mod cumulus_pallet_parachain_system; pub mod cumulus_pallet_xcmp_queue; diff --git a/cumulus/parachains/runtimes/assets/migrations/Cargo.toml b/cumulus/parachains/runtimes/assets/migrations/Cargo.toml index c0296204df82..5a58c3111124 100644 --- a/cumulus/parachains/runtimes/assets/migrations/Cargo.toml +++ b/cumulus/parachains/runtimes/assets/migrations/Cargo.toml @@ -23,6 +23,7 @@ sp-runtime = { workspace = true } pallet-balances = { workspace = true } pallet-assets = { workspace = true } pallet-asset-conversion = { workspace = true } +pallet-migrations = { workspace = true } # Polkadot pallet-xcm = { workspace = true } @@ -49,6 +50,7 @@ std = [ "log/std", "pallet-asset-conversion/std", "pallet-xcm/std", + "pallet-migrations/std", "parachains-common/std", "scale-info/std", "sp-api/std", @@ -67,6 +69,7 @@ runtime-benchmarks = [ "frame-support/runtime-benchmarks", "pallet-asset-conversion/runtime-benchmarks", "pallet-xcm/runtime-benchmarks", + "pallet-migrations/runtime-benchmarks", "parachains-common/runtime-benchmarks", "sp-runtime/runtime-benchmarks", "xcm-builder/runtime-benchmarks", diff --git a/cumulus/parachains/runtimes/assets/migrations/src/v1/benchmarks.rs b/cumulus/parachains/runtimes/assets/migrations/src/v1/benchmarks.rs index 3e6d968a1de3..a5d84822764b 100644 --- a/cumulus/parachains/runtimes/assets/migrations/src/v1/benchmarks.rs +++ b/cumulus/parachains/runtimes/assets/migrations/src/v1/benchmarks.rs @@ -16,7 +16,6 @@ //! Benchmarks for the foreign assets migration. use frame_benchmarking::v2::*; -use frame_support::{migrations::SteppedMigration, weights::WeightMeter}; use pallet_assets::{Asset, AssetDetails, AssetStatus, Config}; use xcm::{v3, v4}; @@ -32,20 +31,19 @@ mod benches { use super::*; #[benchmark] - fn step() { + fn conversion_step() { let key = v3::Location::new(1, [v3::Junction::Parachain(2004)]); let mock_asset_details = mock_asset_details::(); - old::Asset::::insert(key.clone(), mock_asset_details); + old::Asset::::insert(key.clone(), mock_asset_details.clone()); - let mut meter = WeightMeter::new(); #[block] { - Migration::::step(None, &mut meter).unwrap(); + Migration::::conversion_step(None).unwrap(); } let new_key: >::AssetId = v4::Location::new(1, [v4::Junction::Parachain(2004)]).into(); - assert!(Asset::::contains_key(new_key)); + assert_eq!(Asset::::get(new_key), Some(mock_asset_details.clone())); } impl_benchmark_test_suite!(Pallet, crate::v1::tests::new_test_ext(), crate::v1::tests::Runtime); diff --git a/cumulus/parachains/runtimes/assets/migrations/src/v1/mod.rs b/cumulus/parachains/runtimes/assets/migrations/src/v1/mod.rs index cfaa54efffae..c4b81c45ed24 100644 --- a/cumulus/parachains/runtimes/assets/migrations/src/v1/mod.rs +++ b/cumulus/parachains/runtimes/assets/migrations/src/v1/mod.rs @@ -24,6 +24,8 @@ mod tests; #[cfg(feature = "runtime-benchmarks")] mod benchmarks; +mod weights; + use frame_support::{ migrations::{MigrationId, SteppedMigration, SteppedMigrationError}, pallet_prelude::PhantomData, @@ -52,8 +54,8 @@ pub mod old { StorageMap, Blake2_128Concat, v3::Location, AssetDetailsOf>; } -pub struct Migration, I: 'static = ()>(PhantomData<(T, I)>); -impl, I: 'static> SteppedMigration for Migration +pub struct Migration(PhantomData<(T, I, W)>); +impl, I: 'static, W: weights::WeightInfo> SteppedMigration for Migration where >::AssetId: From, { @@ -65,9 +67,35 @@ where } fn step( - cursor: Option, - _meter: &mut WeightMeter, + mut cursor: Option, + meter: &mut WeightMeter, ) -> Result, SteppedMigrationError> { + let required = W::conversion_step(); + if meter.remaining().any_lt(required) { + return Err(SteppedMigrationError::InsufficientWeight { required }); + } + + loop { + if meter.try_consume(required).is_err() { + break; + } + + cursor = Self::conversion_step(cursor); + + if cursor.is_none() { + break; + } + } + + Ok(cursor) + } +} + +impl, I: 'static, W> Migration +where + >::AssetId: From, +{ + pub fn conversion_step(cursor: Option) -> Option { let mut iter = if let Some(last_key) = cursor { // If a cursor is provided, start iterating from the value corresponding // to the last key processed in the previous step of the migration. @@ -90,10 +118,10 @@ where log::warn!(target: "migration", "{:?} couldn't be converted to V4", key); } // Return the key as the new cursor to continue the migration. - Ok(Some(key)) + Some(key) } else { // Signal the migration is complete. - Ok(None) + None } } } diff --git a/cumulus/parachains/runtimes/assets/migrations/src/v1/tests.rs b/cumulus/parachains/runtimes/assets/migrations/src/v1/tests.rs index 409713a40c0f..d8b6e24e168e 100644 --- a/cumulus/parachains/runtimes/assets/migrations/src/v1/tests.rs +++ b/cumulus/parachains/runtimes/assets/migrations/src/v1/tests.rs @@ -16,8 +16,11 @@ //! Tests for the foreign assets migration. use frame_support::{ - construct_runtime, derive_impl, migrations::SteppedMigration, traits::AsEnsureOriginWithArg, - weights::WeightMeter, + construct_runtime, derive_impl, + migrations::SteppedMigration, + parameter_types, + traits::{AsEnsureOriginWithArg, OnRuntimeUpgrade}, + weights::{Weight, WeightMeter}, }; use frame_system::{EnsureRoot, EnsureSigned}; use pallet_assets::{Asset, AssetDetails, AssetStatus}; @@ -25,13 +28,14 @@ use sp_io::TestExternalities; use sp_runtime::BuildStorage; use xcm::{v3, v4}; -use super::{old, Migration}; +use super::{old, weights, Migration}; construct_runtime! { pub struct Runtime { System: frame_system, Balances: pallet_balances, ForeignAssets: pallet_assets, + Migrations: pallet_migrations, } } @@ -44,6 +48,21 @@ impl frame_system::Config for Runtime { type Block = Block; type AccountId = AccountId; type AccountData = pallet_balances::AccountData; + type MultiBlockMigrator = Migrations; +} + +parameter_types! { + pub storage MigratorServiceWeight: Weight = Weight::from_parts(100, 100); // do not use in prod +} + +#[derive_impl(pallet_migrations::config_preludes::TestDefaultConfig)] +impl pallet_migrations::Config for Runtime { + #[cfg(not(feature = "runtime-benchmarks"))] + type Migrations = + (crate::v1::Migration>,); + #[cfg(feature = "runtime-benchmarks")] + type Migrations = pallet_migrations::mock_helpers::MockedMigrations; + type MaxServiceWeight = MigratorServiceWeight; } #[derive_impl(pallet_balances::config_preludes::TestDefaultConfig)] @@ -90,19 +109,30 @@ pub(crate) fn new_test_ext() -> TestExternalities { #[test] fn migration_works() { new_test_ext().execute_with(|| { - let key = v3::Location::new(1, [v3::Junction::Parachain(2004)]); let mock_asset_details = mock_asset_details(); - old::Asset::::insert(key, mock_asset_details); + + // Insert a bunch of items in the old map. + for i in 0..1024 { + let key = v3::Location::new(1, [v3::Junction::Parachain(2004), v3::Junction::PalletInstance(50), v3::Junction::GeneralIndex(i)]); + old::Asset::::insert(key, mock_asset_details.clone()); + } + + // Give the migration some limit. + let limit = <::WeightInfo as pallet_migrations::WeightInfo>::progress_mbms_none() + + pallet_migrations::Pallet::::exec_migration_max_weight() + + as weights::WeightInfo>::conversion_step() * 16; + MigratorServiceWeight::set(&limit); + + System::set_block_number(1); + AllPalletsWithSystem::on_runtime_upgrade(); // onboard MBMs // Perform one step of the migration. - let cursor = Migration::::step(None, &mut WeightMeter::new()).unwrap().unwrap(); - // Second time works. - assert!(Migration::::step(Some(cursor), &mut WeightMeter::new()) - .unwrap() - .is_none()); - - let new_key = v4::Location::new(1, [v4::Junction::Parachain(2004)]); - assert!(Asset::::contains_key(new_key)); + assert!(Migration::::step(None, &mut WeightMeter::new()).unwrap().is_none()); + + for i in 0..1024 { + let new_key = v4::Location::new(1, [v4::Junction::Parachain(2004), v4::Junction::PalletInstance(50), v4::Junction::GeneralIndex(i)]); + assert_eq!(Asset::::get(new_key), Some(mock_asset_details.clone())); + } }) } diff --git a/cumulus/parachains/runtimes/assets/migrations/src/v1/weights.rs b/cumulus/parachains/runtimes/assets/migrations/src/v1/weights.rs new file mode 100644 index 000000000000..8926b443f249 --- /dev/null +++ b/cumulus/parachains/runtimes/assets/migrations/src/v1/weights.rs @@ -0,0 +1,83 @@ +// Copyright (C) Parity Technologies (UK) Ltd. +// This file is part of Polkadot. + +// Polkadot is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// Polkadot is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with Polkadot. If not, see . + +//! Autogenerated weights for `assets_common_migrations` +//! +//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 38.0.0 +//! DATE: 2024-08-01, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! WORST CASE MAP SIZE: `1000000` +//! HOSTNAME: `Ciscos-MBP.lan`, CPU: `` +//! WASM-EXECUTION: `Compiled`, CHAIN: `None`, DB CACHE: `1024` + +// Executed Command: +// frame-omni-bencher +// v1 +// benchmark +// pallet +// --runtime +// target/release/wbuild/kitchensink-runtime/kitchensink_runtime.compact.compressed.wasm +// --pallet +// assets_common_migrations +// --extrinsic +// * +// --template +// substrate/.maintain/frame-weight-template.hbs +// --output +// cumulus/parachains/runtimes/assets/migrations/src/v1/weights.rs + +#![cfg_attr(rustfmt, rustfmt_skip)] +#![allow(unused_parens)] +#![allow(unused_imports)] +#![allow(missing_docs)] + +use frame_support::{traits::Get, weights::{Weight, constants::RocksDbWeight}}; +use core::marker::PhantomData; + +/// Weight functions needed for `assets_common_migrations`. +pub trait WeightInfo { + fn conversion_step() -> Weight; +} + +/// Weights for `assets_common_migrations` using the Substrate node and recommended hardware. +pub struct SubstrateWeight(PhantomData); +impl WeightInfo for SubstrateWeight { + /// Storage: `ForeignAssets::Asset` (r:2 w:1) + /// Proof: `ForeignAssets::Asset` (`max_values`: None, `max_size`: Some(808), added: 3283, mode: `MaxEncodedLen`) + fn conversion_step() -> Weight { + // Proof Size summary in bytes: + // Measured: `161` + // Estimated: `7556` + // Minimum execution time: 12_000_000 picoseconds. + Weight::from_parts(14_000_000, 7556) + .saturating_add(T::DbWeight::get().reads(2_u64)) + .saturating_add(T::DbWeight::get().writes(1_u64)) + } +} + +// For backwards compatibility and tests. +impl WeightInfo for () { + /// Storage: `ForeignAssets::Asset` (r:2 w:1) + /// Proof: `ForeignAssets::Asset` (`max_values`: None, `max_size`: Some(808), added: 3283, mode: `MaxEncodedLen`) + fn conversion_step() -> Weight { + // Proof Size summary in bytes: + // Measured: `161` + // Estimated: `7556` + // Minimum execution time: 12_000_000 picoseconds. + Weight::from_parts(14_000_000, 7556) + .saturating_add(RocksDbWeight::get().reads(2_u64)) + .saturating_add(RocksDbWeight::get().writes(1_u64)) + } +} From d37daa0bf5e7e1958d425a9f6febb6d72bc2eb46 Mon Sep 17 00:00:00 2001 From: Francisco Aguirre Date: Mon, 5 Aug 2024 14:04:46 +0200 Subject: [PATCH 21/32] fix: add licenses to weight files --- .../src/weights/assets_common_migrations.rs | 14 ++++++++++++++ .../src/weights/assets_common_migrations.rs | 14 ++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/weights/assets_common_migrations.rs b/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/weights/assets_common_migrations.rs index 64225b619fcf..f08e5632c563 100644 --- a/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/weights/assets_common_migrations.rs +++ b/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/weights/assets_common_migrations.rs @@ -1,3 +1,17 @@ +// Copyright (C) Parity Technologies (UK) Ltd. +// SPDX-License-Identifier: Apache-2.0 + +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. //! Autogenerated weights for `assets_common_migrations` //! diff --git a/cumulus/parachains/runtimes/assets/asset-hub-westend/src/weights/assets_common_migrations.rs b/cumulus/parachains/runtimes/assets/asset-hub-westend/src/weights/assets_common_migrations.rs index 20f72027005b..04581f2d0bff 100644 --- a/cumulus/parachains/runtimes/assets/asset-hub-westend/src/weights/assets_common_migrations.rs +++ b/cumulus/parachains/runtimes/assets/asset-hub-westend/src/weights/assets_common_migrations.rs @@ -1,3 +1,17 @@ +// Copyright (C) Parity Technologies (UK) Ltd. +// SPDX-License-Identifier: Apache-2.0 + +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. //! Autogenerated weights for `assets_common_migrations` //! From 61a6e899495cc20208766b9659c8334e609ba28d Mon Sep 17 00:00:00 2001 From: Francisco Aguirre Date: Mon, 5 Aug 2024 16:06:00 +0200 Subject: [PATCH 22/32] chore(assets-common-migrations): remove unnecessary dependencies --- Cargo.lock | 7 ------- .../runtimes/assets/common/Cargo.toml | 1 + .../runtimes/assets/migrations/Cargo.toml | 20 ------------------- 3 files changed, 1 insertion(+), 27 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 713181bb495f..31973669c0d0 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1140,23 +1140,16 @@ dependencies = [ "frame-benchmarking", "frame-support", "frame-system", - "hex-display", "log", "pallet-asset-conversion", "pallet-assets", "pallet-balances", "pallet-migrations", - "pallet-xcm", - "parachains-common", "parity-scale-codec", "scale-info", - "sp-api", "sp-io", "sp-runtime", "staging-xcm", - "staging-xcm-builder", - "staging-xcm-executor", - "substrate-wasm-builder", ] [[package]] diff --git a/cumulus/parachains/runtimes/assets/common/Cargo.toml b/cumulus/parachains/runtimes/assets/common/Cargo.toml index 5bce8e84240f..08bda5c82cb7 100644 --- a/cumulus/parachains/runtimes/assets/common/Cargo.toml +++ b/cumulus/parachains/runtimes/assets/common/Cargo.toml @@ -61,6 +61,7 @@ std = [ "pallet-assets/std", "pallet-balances/std", "sp-io/std", + "hex-display/std" ] runtime-benchmarks = [ diff --git a/cumulus/parachains/runtimes/assets/migrations/Cargo.toml b/cumulus/parachains/runtimes/assets/migrations/Cargo.toml index 5a58c3111124..1eb088a1f066 100644 --- a/cumulus/parachains/runtimes/assets/migrations/Cargo.toml +++ b/cumulus/parachains/runtimes/assets/migrations/Cargo.toml @@ -18,7 +18,6 @@ log = { workspace = true } frame-support = { workspace = true } frame-system = { workspace = true } frame-benchmarking = { optional = true, workspace = true } -sp-api = { workspace = true } sp-runtime = { workspace = true } pallet-balances = { workspace = true } pallet-assets = { workspace = true } @@ -26,20 +25,10 @@ pallet-asset-conversion = { workspace = true } pallet-migrations = { workspace = true } # Polkadot -pallet-xcm = { workspace = true } xcm = { workspace = true } -xcm-builder = { workspace = true } -xcm-executor = { workspace = true } - -# Cumulus -parachains-common = { workspace = true } [dev-dependencies] sp-io = { workspace = true } -hex-display = "0.3.0" - -[build-dependencies] -substrate-wasm-builder = { workspace = true, default-features = true } [features] default = ["std"] @@ -49,14 +38,9 @@ std = [ "frame-support/std", "log/std", "pallet-asset-conversion/std", - "pallet-xcm/std", "pallet-migrations/std", - "parachains-common/std", "scale-info/std", - "sp-api/std", "sp-runtime/std", - "xcm-builder/std", - "xcm-executor/std", "xcm/std", "frame-system/std", "pallet-assets/std", @@ -68,12 +52,8 @@ runtime-benchmarks = [ "frame-benchmarking/runtime-benchmarks", "frame-support/runtime-benchmarks", "pallet-asset-conversion/runtime-benchmarks", - "pallet-xcm/runtime-benchmarks", "pallet-migrations/runtime-benchmarks", - "parachains-common/runtime-benchmarks", "sp-runtime/runtime-benchmarks", - "xcm-builder/runtime-benchmarks", - "xcm-executor/runtime-benchmarks", "frame-system/runtime-benchmarks", "pallet-assets/runtime-benchmarks", "pallet-balances/runtime-benchmarks", From 0154c579bd4110eb90829fbbdf6709dbfe6b8046 Mon Sep 17 00:00:00 2001 From: Francisco Aguirre Date: Wed, 7 Aug 2024 10:23:27 +0200 Subject: [PATCH 23/32] fix(assets): change migration name and use correct WeightInfo --- .../assets/asset-hub-rococo/src/lib.rs | 2 +- .../src/weights/assets_common_migrations.rs | 22 +------------------ .../assets/asset-hub-westend/src/lib.rs | 2 +- .../src/weights/assets_common_migrations.rs | 22 +------------------ .../benchmarks.rs | 0 .../src/{v1 => foreign_assets_to_v4}/mod.rs | 1 + .../src/{v1 => foreign_assets_to_v4}/tests.rs | 2 +- .../{v1 => foreign_assets_to_v4}/weights.rs | 0 .../runtimes/assets/migrations/src/lib.rs | 2 +- 9 files changed, 7 insertions(+), 46 deletions(-) rename cumulus/parachains/runtimes/assets/migrations/src/{v1 => foreign_assets_to_v4}/benchmarks.rs (100%) rename cumulus/parachains/runtimes/assets/migrations/src/{v1 => foreign_assets_to_v4}/mod.rs (99%) rename cumulus/parachains/runtimes/assets/migrations/src/{v1 => foreign_assets_to_v4}/tests.rs (97%) rename cumulus/parachains/runtimes/assets/migrations/src/{v1 => foreign_assets_to_v4}/weights.rs (100%) diff --git a/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/lib.rs b/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/lib.rs index b702458d2b11..aa673f8d0935 100644 --- a/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/lib.rs +++ b/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/lib.rs @@ -203,7 +203,7 @@ impl pallet_migrations::Config for Runtime { } #[cfg(not(feature = "runtime-benchmarks"))] -type MultiBlockMigrations = assets_common_migrations::v1::Migration< +type MultiBlockMigrations = assets_common_migrations::foreign_assets_to_v4::Migration< Runtime, ForeignAssetsInstance, weights::assets_common_migrations::SubstrateWeight, diff --git a/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/weights/assets_common_migrations.rs b/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/weights/assets_common_migrations.rs index f08e5632c563..131c08334818 100644 --- a/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/weights/assets_common_migrations.rs +++ b/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/weights/assets_common_migrations.rs @@ -45,14 +45,9 @@ use frame_support::{traits::Get, weights::{Weight, constants::RocksDbWeight}}; use core::marker::PhantomData; -/// Weight functions needed for `assets_common_migrations`. -pub trait WeightInfo { - fn conversion_step() -> Weight; -} - /// Weights for `assets_common_migrations` using the Substrate node and recommended hardware. pub struct SubstrateWeight(PhantomData); -impl WeightInfo for SubstrateWeight { +impl assets_common_migrations::foreign_assets_to_v4::WeightInfo for SubstrateWeight { /// Storage: `ForeignAssets::Asset` (r:2 w:1) /// Proof: `ForeignAssets::Asset` (`max_values`: None, `max_size`: Some(808), added: 3283, mode: `MaxEncodedLen`) fn conversion_step() -> Weight { @@ -65,18 +60,3 @@ impl WeightInfo for SubstrateWeight { .saturating_add(T::DbWeight::get().writes(1_u64)) } } - -// For backwards compatibility and tests. -impl WeightInfo for () { - /// Storage: `ForeignAssets::Asset` (r:2 w:1) - /// Proof: `ForeignAssets::Asset` (`max_values`: None, `max_size`: Some(808), added: 3283, mode: `MaxEncodedLen`) - fn conversion_step() -> Weight { - // Proof Size summary in bytes: - // Measured: `161` - // Estimated: `7556` - // Minimum execution time: 6_000_000 picoseconds. - Weight::from_parts(7_000_000, 7556) - .saturating_add(RocksDbWeight::get().reads(2_u64)) - .saturating_add(RocksDbWeight::get().writes(1_u64)) - } -} diff --git a/cumulus/parachains/runtimes/assets/asset-hub-westend/src/lib.rs b/cumulus/parachains/runtimes/assets/asset-hub-westend/src/lib.rs index d2d03bfe9cd2..81422780d1c1 100644 --- a/cumulus/parachains/runtimes/assets/asset-hub-westend/src/lib.rs +++ b/cumulus/parachains/runtimes/assets/asset-hub-westend/src/lib.rs @@ -198,7 +198,7 @@ impl pallet_migrations::Config for Runtime { } #[cfg(not(feature = "runtime-benchmarks"))] -type MultiBlockMigrations = assets_common_migrations::v1::Migration< +type MultiBlockMigrations = assets_common_migrations::foreign_assets_to_v4::Migration< Runtime, ForeignAssetsInstance, weights::assets_common_migrations::SubstrateWeight, diff --git a/cumulus/parachains/runtimes/assets/asset-hub-westend/src/weights/assets_common_migrations.rs b/cumulus/parachains/runtimes/assets/asset-hub-westend/src/weights/assets_common_migrations.rs index 04581f2d0bff..f365e27b845b 100644 --- a/cumulus/parachains/runtimes/assets/asset-hub-westend/src/weights/assets_common_migrations.rs +++ b/cumulus/parachains/runtimes/assets/asset-hub-westend/src/weights/assets_common_migrations.rs @@ -45,14 +45,9 @@ use frame_support::{traits::Get, weights::{Weight, constants::RocksDbWeight}}; use core::marker::PhantomData; -/// Weight functions needed for `assets_common_migrations`. -pub trait WeightInfo { - fn conversion_step() -> Weight; -} - /// Weights for `assets_common_migrations` using the Substrate node and recommended hardware. pub struct SubstrateWeight(PhantomData); -impl WeightInfo for SubstrateWeight { +impl assets_common_migrations::foreign_assets_to_v4::WeightInfo for SubstrateWeight { /// Storage: `ForeignAssets::Asset` (r:2 w:1) /// Proof: `ForeignAssets::Asset` (`max_values`: None, `max_size`: Some(808), added: 3283, mode: `MaxEncodedLen`) fn conversion_step() -> Weight { @@ -65,18 +60,3 @@ impl WeightInfo for SubstrateWeight { .saturating_add(T::DbWeight::get().writes(1_u64)) } } - -// For backwards compatibility and tests. -impl WeightInfo for () { - /// Storage: `ForeignAssets::Asset` (r:2 w:1) - /// Proof: `ForeignAssets::Asset` (`max_values`: None, `max_size`: Some(808), added: 3283, mode: `MaxEncodedLen`) - fn conversion_step() -> Weight { - // Proof Size summary in bytes: - // Measured: `161` - // Estimated: `7556` - // Minimum execution time: 6_000_000 picoseconds. - Weight::from_parts(6_000_000, 7556) - .saturating_add(RocksDbWeight::get().reads(2_u64)) - .saturating_add(RocksDbWeight::get().writes(1_u64)) - } -} diff --git a/cumulus/parachains/runtimes/assets/migrations/src/v1/benchmarks.rs b/cumulus/parachains/runtimes/assets/migrations/src/foreign_assets_to_v4/benchmarks.rs similarity index 100% rename from cumulus/parachains/runtimes/assets/migrations/src/v1/benchmarks.rs rename to cumulus/parachains/runtimes/assets/migrations/src/foreign_assets_to_v4/benchmarks.rs diff --git a/cumulus/parachains/runtimes/assets/migrations/src/v1/mod.rs b/cumulus/parachains/runtimes/assets/migrations/src/foreign_assets_to_v4/mod.rs similarity index 99% rename from cumulus/parachains/runtimes/assets/migrations/src/v1/mod.rs rename to cumulus/parachains/runtimes/assets/migrations/src/foreign_assets_to_v4/mod.rs index c4b81c45ed24..2b53ac1bf556 100644 --- a/cumulus/parachains/runtimes/assets/migrations/src/v1/mod.rs +++ b/cumulus/parachains/runtimes/assets/migrations/src/foreign_assets_to_v4/mod.rs @@ -25,6 +25,7 @@ mod tests; mod benchmarks; mod weights; +pub use weights::WeightInfo; use frame_support::{ migrations::{MigrationId, SteppedMigration, SteppedMigrationError}, diff --git a/cumulus/parachains/runtimes/assets/migrations/src/v1/tests.rs b/cumulus/parachains/runtimes/assets/migrations/src/foreign_assets_to_v4/tests.rs similarity index 97% rename from cumulus/parachains/runtimes/assets/migrations/src/v1/tests.rs rename to cumulus/parachains/runtimes/assets/migrations/src/foreign_assets_to_v4/tests.rs index d8b6e24e168e..2b2c915ea25b 100644 --- a/cumulus/parachains/runtimes/assets/migrations/src/v1/tests.rs +++ b/cumulus/parachains/runtimes/assets/migrations/src/foreign_assets_to_v4/tests.rs @@ -59,7 +59,7 @@ parameter_types! { impl pallet_migrations::Config for Runtime { #[cfg(not(feature = "runtime-benchmarks"))] type Migrations = - (crate::v1::Migration>,); + (crate::foreign_assets_to_v4::Migration>,); #[cfg(feature = "runtime-benchmarks")] type Migrations = pallet_migrations::mock_helpers::MockedMigrations; type MaxServiceWeight = MigratorServiceWeight; diff --git a/cumulus/parachains/runtimes/assets/migrations/src/v1/weights.rs b/cumulus/parachains/runtimes/assets/migrations/src/foreign_assets_to_v4/weights.rs similarity index 100% rename from cumulus/parachains/runtimes/assets/migrations/src/v1/weights.rs rename to cumulus/parachains/runtimes/assets/migrations/src/foreign_assets_to_v4/weights.rs diff --git a/cumulus/parachains/runtimes/assets/migrations/src/lib.rs b/cumulus/parachains/runtimes/assets/migrations/src/lib.rs index 43adc1c677c2..aae31d7afb65 100644 --- a/cumulus/parachains/runtimes/assets/migrations/src/lib.rs +++ b/cumulus/parachains/runtimes/assets/migrations/src/lib.rs @@ -18,7 +18,7 @@ #![cfg_attr(not(feature = "std"), no_std)] -pub mod v1; +pub mod foreign_assets_to_v4; pub use pallet::*; From 7f91f734fc29cbb4e74ef774d92cf1899a545a6d Mon Sep 17 00:00:00 2001 From: Francisco Aguirre Date: Wed, 7 Aug 2024 10:57:45 +0200 Subject: [PATCH 24/32] fix: remove hex-display --- Cargo.lock | 7 ------- .../runtimes/assets/asset-hub-rococo/Cargo.toml | 10 +++++----- .../runtimes/assets/asset-hub-westend/Cargo.toml | 10 +++++----- .../parachains/runtimes/assets/common/Cargo.toml | 16 +++++++--------- .../runtimes/assets/migrations/Cargo.toml | 16 ++++++++-------- .../migrations/src/foreign_assets_to_v4/tests.rs | 9 +++++++-- 6 files changed, 32 insertions(+), 36 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 31973669c0d0..44b00f46c8dc 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1114,7 +1114,6 @@ dependencies = [ "cumulus-primitives-core", "frame-support", "frame-system", - "hex-display", "impl-trait-for-tuples", "log", "pallet-asset-conversion", @@ -6841,12 +6840,6 @@ version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "212ab92002354b4819390025006c897e8140934349e8635c9b077f47b4dcbd20" -[[package]] -name = "hex-display" -version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8b53d6a634507c5d9fdee77261ae54a8d1ff7887f5304389025b03c3292a1756" - [[package]] name = "hex-literal" version = "0.4.1" diff --git a/cumulus/parachains/runtimes/assets/asset-hub-rococo/Cargo.toml b/cumulus/parachains/runtimes/assets/asset-hub-rococo/Cargo.toml index 025862aef4e4..7310be3b7f70 100644 --- a/cumulus/parachains/runtimes/assets/asset-hub-rococo/Cargo.toml +++ b/cumulus/parachains/runtimes/assets/asset-hub-rococo/Cargo.toml @@ -106,8 +106,8 @@ substrate-wasm-builder = { optional = true, workspace = true, default-features = [features] default = ["std"] runtime-benchmarks = [ - "assets-common/runtime-benchmarks", "assets-common-migrations/runtime-benchmarks", + "assets-common/runtime-benchmarks", "cumulus-pallet-parachain-system/runtime-benchmarks", "cumulus-pallet-session-benchmarking/runtime-benchmarks", "cumulus-pallet-xcmp-queue/runtime-benchmarks", @@ -124,6 +124,7 @@ runtime-benchmarks = [ "pallet-balances/runtime-benchmarks", "pallet-collator-selection/runtime-benchmarks", "pallet-message-queue/runtime-benchmarks", + "pallet-migrations/runtime-benchmarks", "pallet-multisig/runtime-benchmarks", "pallet-nft-fractionalization/runtime-benchmarks", "pallet-nfts/runtime-benchmarks", @@ -131,7 +132,6 @@ runtime-benchmarks = [ "pallet-timestamp/runtime-benchmarks", "pallet-uniques/runtime-benchmarks", "pallet-utility/runtime-benchmarks", - "pallet-migrations/runtime-benchmarks", "pallet-xcm-benchmarks/runtime-benchmarks", "pallet-xcm-bridge-hub-router/runtime-benchmarks", "pallet-xcm/runtime-benchmarks", @@ -163,6 +163,7 @@ try-runtime = [ "pallet-balances/try-runtime", "pallet-collator-selection/try-runtime", "pallet-message-queue/try-runtime", + "pallet-migrations/try-runtime", "pallet-multisig/try-runtime", "pallet-nft-fractionalization/try-runtime", "pallet-nfts/try-runtime", @@ -172,7 +173,6 @@ try-runtime = [ "pallet-transaction-payment/try-runtime", "pallet-uniques/try-runtime", "pallet-utility/try-runtime", - "pallet-migrations/try-runtime", "pallet-xcm-bridge-hub-router/try-runtime", "pallet-xcm/try-runtime", "parachain-info/try-runtime", @@ -180,8 +180,8 @@ try-runtime = [ "sp-runtime/try-runtime", ] std = [ - "assets-common/std", "assets-common-migrations/std", + "assets-common/std", "bp-asset-hub-rococo/std", "bp-asset-hub-westend/std", "bp-bridge-hub-rococo/std", @@ -215,6 +215,7 @@ std = [ "pallet-balances/std", "pallet-collator-selection/std", "pallet-message-queue/std", + "pallet-migrations/std", "pallet-multisig/std", "pallet-nft-fractionalization/std", "pallet-nfts-runtime-api/std", @@ -226,7 +227,6 @@ std = [ "pallet-transaction-payment/std", "pallet-uniques/std", "pallet-utility/std", - "pallet-migrations/std", "pallet-xcm-benchmarks?/std", "pallet-xcm-bridge-hub-router/std", "pallet-xcm/std", diff --git a/cumulus/parachains/runtimes/assets/asset-hub-westend/Cargo.toml b/cumulus/parachains/runtimes/assets/asset-hub-westend/Cargo.toml index 167ebff5dab4..7acbe34f2b8a 100644 --- a/cumulus/parachains/runtimes/assets/asset-hub-westend/Cargo.toml +++ b/cumulus/parachains/runtimes/assets/asset-hub-westend/Cargo.toml @@ -105,8 +105,8 @@ substrate-wasm-builder = { optional = true, workspace = true, default-features = [features] default = ["std"] runtime-benchmarks = [ - "assets-common/runtime-benchmarks", "assets-common-migrations/runtime-benchmarks", + "assets-common/runtime-benchmarks", "cumulus-pallet-parachain-system/runtime-benchmarks", "cumulus-pallet-session-benchmarking/runtime-benchmarks", "cumulus-pallet-xcmp-queue/runtime-benchmarks", @@ -123,6 +123,7 @@ runtime-benchmarks = [ "pallet-balances/runtime-benchmarks", "pallet-collator-selection/runtime-benchmarks", "pallet-message-queue/runtime-benchmarks", + "pallet-migrations/runtime-benchmarks", "pallet-multisig/runtime-benchmarks", "pallet-nft-fractionalization/runtime-benchmarks", "pallet-nfts/runtime-benchmarks", @@ -131,7 +132,6 @@ runtime-benchmarks = [ "pallet-timestamp/runtime-benchmarks", "pallet-uniques/runtime-benchmarks", "pallet-utility/runtime-benchmarks", - "pallet-migrations/runtime-benchmarks", "pallet-xcm-benchmarks/runtime-benchmarks", "pallet-xcm-bridge-hub-router/runtime-benchmarks", "pallet-xcm/runtime-benchmarks", @@ -162,6 +162,7 @@ try-runtime = [ "pallet-balances/try-runtime", "pallet-collator-selection/try-runtime", "pallet-message-queue/try-runtime", + "pallet-migrations/try-runtime", "pallet-multisig/try-runtime", "pallet-nft-fractionalization/try-runtime", "pallet-nfts/try-runtime", @@ -172,7 +173,6 @@ try-runtime = [ "pallet-transaction-payment/try-runtime", "pallet-uniques/try-runtime", "pallet-utility/try-runtime", - "pallet-migrations/try-runtime", "pallet-xcm-bridge-hub-router/try-runtime", "pallet-xcm/try-runtime", "parachain-info/try-runtime", @@ -180,8 +180,8 @@ try-runtime = [ "sp-runtime/try-runtime", ] std = [ - "assets-common/std", "assets-common-migrations/std", + "assets-common/std", "bp-asset-hub-rococo/std", "bp-asset-hub-westend/std", "bp-bridge-hub-rococo/std", @@ -215,6 +215,7 @@ std = [ "pallet-balances/std", "pallet-collator-selection/std", "pallet-message-queue/std", + "pallet-migrations/std", "pallet-multisig/std", "pallet-nft-fractionalization/std", "pallet-nfts-runtime-api/std", @@ -227,7 +228,6 @@ std = [ "pallet-transaction-payment/std", "pallet-uniques/std", "pallet-utility/std", - "pallet-migrations/std", "pallet-xcm-benchmarks?/std", "pallet-xcm-bridge-hub-router/std", "pallet-xcm/std", diff --git a/cumulus/parachains/runtimes/assets/common/Cargo.toml b/cumulus/parachains/runtimes/assets/common/Cargo.toml index 08bda5c82cb7..2b42f0e5becc 100644 --- a/cumulus/parachains/runtimes/assets/common/Cargo.toml +++ b/cumulus/parachains/runtimes/assets/common/Cargo.toml @@ -36,7 +36,6 @@ cumulus-primitives-core = { workspace = true } [dev-dependencies] sp-io = { workspace = true } -hex-display = "0.3.0" [build-dependencies] substrate-wasm-builder = { workspace = true, default-features = true } @@ -47,33 +46,32 @@ std = [ "codec/std", "cumulus-primitives-core/std", "frame-support/std", + "frame-system/std", "log/std", "pallet-asset-conversion/std", + "pallet-assets/std", + "pallet-balances/std", "pallet-xcm/std", "parachains-common/std", "scale-info/std", "sp-api/std", + "sp-io/std", "sp-runtime/std", "xcm-builder/std", "xcm-executor/std", "xcm/std", - "frame-system/std", - "pallet-assets/std", - "pallet-balances/std", - "sp-io/std", - "hex-display/std" ] runtime-benchmarks = [ "cumulus-primitives-core/runtime-benchmarks", "frame-support/runtime-benchmarks", + "frame-system/runtime-benchmarks", "pallet-asset-conversion/runtime-benchmarks", + "pallet-assets/runtime-benchmarks", + "pallet-balances/runtime-benchmarks", "pallet-xcm/runtime-benchmarks", "parachains-common/runtime-benchmarks", "sp-runtime/runtime-benchmarks", "xcm-builder/runtime-benchmarks", "xcm-executor/runtime-benchmarks", - "frame-system/runtime-benchmarks", - "pallet-assets/runtime-benchmarks", - "pallet-balances/runtime-benchmarks", ] diff --git a/cumulus/parachains/runtimes/assets/migrations/Cargo.toml b/cumulus/parachains/runtimes/assets/migrations/Cargo.toml index 1eb088a1f066..655a62c2c856 100644 --- a/cumulus/parachains/runtimes/assets/migrations/Cargo.toml +++ b/cumulus/parachains/runtimes/assets/migrations/Cargo.toml @@ -33,28 +33,28 @@ sp-io = { workspace = true } [features] default = ["std"] std = [ - "frame-benchmarking?/std", "codec/std", + "frame-benchmarking?/std", "frame-support/std", + "frame-system/std", "log/std", "pallet-asset-conversion/std", + "pallet-assets/std", + "pallet-balances/std", "pallet-migrations/std", "scale-info/std", + "sp-io/std", "sp-runtime/std", "xcm/std", - "frame-system/std", - "pallet-assets/std", - "pallet-balances/std", - "sp-io/std", ] runtime-benchmarks = [ "frame-benchmarking/runtime-benchmarks", "frame-support/runtime-benchmarks", - "pallet-asset-conversion/runtime-benchmarks", - "pallet-migrations/runtime-benchmarks", - "sp-runtime/runtime-benchmarks", "frame-system/runtime-benchmarks", + "pallet-asset-conversion/runtime-benchmarks", "pallet-assets/runtime-benchmarks", "pallet-balances/runtime-benchmarks", + "pallet-migrations/runtime-benchmarks", + "sp-runtime/runtime-benchmarks", ] diff --git a/cumulus/parachains/runtimes/assets/migrations/src/foreign_assets_to_v4/tests.rs b/cumulus/parachains/runtimes/assets/migrations/src/foreign_assets_to_v4/tests.rs index 2b2c915ea25b..84a08664eccd 100644 --- a/cumulus/parachains/runtimes/assets/migrations/src/foreign_assets_to_v4/tests.rs +++ b/cumulus/parachains/runtimes/assets/migrations/src/foreign_assets_to_v4/tests.rs @@ -58,8 +58,13 @@ parameter_types! { #[derive_impl(pallet_migrations::config_preludes::TestDefaultConfig)] impl pallet_migrations::Config for Runtime { #[cfg(not(feature = "runtime-benchmarks"))] - type Migrations = - (crate::foreign_assets_to_v4::Migration>,); + type Migrations = ( + crate::foreign_assets_to_v4::Migration< + Runtime, + (), + crate::foreign_assets_to_v4::weights::SubstrateWeight, + >, + ); #[cfg(feature = "runtime-benchmarks")] type Migrations = pallet_migrations::mock_helpers::MockedMigrations; type MaxServiceWeight = MigratorServiceWeight; From 41ba43d409a965c9be4e060440bada9784a27602 Mon Sep 17 00:00:00 2001 From: Francisco Aguirre Date: Wed, 7 Aug 2024 12:59:23 +0200 Subject: [PATCH 25/32] fix: bridge hub integration tests --- .../bridges/bridge-hub-rococo/src/lib.rs | 3 +- .../src/tests/asset_transfers.rs | 58 ++++++++++--------- .../bridge-hub-rococo/src/tests/mod.rs | 18 +++--- .../bridges/bridge-hub-westend/src/lib.rs | 3 +- .../src/tests/asset_transfers.rs | 50 ++++++++-------- .../bridge-hub-westend/src/tests/mod.rs | 22 +++---- 6 files changed, 78 insertions(+), 76 deletions(-) diff --git a/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-rococo/src/lib.rs b/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-rococo/src/lib.rs index 3ee509389c67..cae2b15d11c3 100644 --- a/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-rococo/src/lib.rs +++ b/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-rococo/src/lib.rs @@ -23,7 +23,8 @@ mod imports { pub use xcm::{ latest::ParentThen, prelude::{AccountId32 as AccountId32Junction, *}, - v3::{self, NetworkId::Westend as WestendId}, + v3::NetworkId::Westend as WestendId, + v4, }; pub use xcm_executor::traits::TransferType; diff --git a/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-rococo/src/tests/asset_transfers.rs b/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-rococo/src/tests/asset_transfers.rs index 6053936487b2..8a674f89c9ef 100644 --- a/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-rococo/src/tests/asset_transfers.rs +++ b/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-rococo/src/tests/asset_transfers.rs @@ -36,10 +36,10 @@ fn send_assets_over_bridge(send_fn: F) { fn set_up_rocs_for_penpal_rococo_through_ahr_to_ahw( sender: &AccountId, amount: u128, -) -> (Location, v3::Location) { +) -> (Location, v4::Location) { let roc_at_rococo_parachains = roc_at_ah_rococo(); - let roc_at_asset_hub_westend = bridged_roc_at_ah_westend().try_into().unwrap(); - create_foreign_on_ah_westend(roc_at_asset_hub_westend, true); + let roc_at_asset_hub_westend = bridged_roc_at_ah_westend(); + create_foreign_on_ah_westend(roc_at_asset_hub_westend.clone(), true); let penpal_location = AssetHubRococo::sibling_location_of(PenpalA::para_id()); let sov_penpal_on_ahr = AssetHubRococo::sovereign_account_id_of(penpal_location); @@ -121,11 +121,11 @@ fn send_roc_usdt_and_weth_from_asset_hub_rococo_to_asset_hub_westend() { let amount = ASSET_HUB_ROCOCO_ED * 1_000_000; let sender = AssetHubRococoSender::get(); let receiver = AssetHubWestendReceiver::get(); - let roc_at_asset_hub_rococo: v3::Location = roc_at_ah_rococo().try_into().unwrap(); - let bridged_roc_at_asset_hub_westend = bridged_roc_at_ah_westend().try_into().unwrap(); + let roc_at_asset_hub_rococo = roc_at_ah_rococo(); + let bridged_roc_at_asset_hub_westend = bridged_roc_at_ah_westend(); - create_foreign_on_ah_westend(bridged_roc_at_asset_hub_westend, true); - set_up_pool_with_wnd_on_ah_westend(bridged_roc_at_asset_hub_westend); + create_foreign_on_ah_westend(bridged_roc_at_asset_hub_westend.clone(), true); + set_up_pool_with_wnd_on_ah_westend(bridged_roc_at_asset_hub_westend.clone()); //////////////////////////////////////////////////////////// // Let's first send over just some ROCs as a simple example @@ -138,12 +138,13 @@ fn send_roc_usdt_and_weth_from_asset_hub_rococo_to_asset_hub_westend() { ::account_data_of(sov_ahw_on_ahr.clone()).free; let sender_rocs_before = ::account_data_of(sender.clone()).free; let receiver_rocs_before = - foreign_balance_on_ah_westend(bridged_roc_at_asset_hub_westend, &receiver); + foreign_balance_on_ah_westend(bridged_roc_at_asset_hub_westend.clone(), &receiver); // send ROCs, use them for fees send_assets_over_bridge(|| { let destination = asset_hub_westend_location(); - let assets: Assets = (Location::try_from(roc_at_asset_hub_rococo).unwrap(), amount).into(); + let assets: Assets = + (Location::try_from(roc_at_asset_hub_rococo.clone()).unwrap(), amount).into(); let fee_idx = 0; assert_ok!(send_assets_from_asset_hub_rococo(destination, assets, fee_idx)); }); @@ -185,9 +186,9 @@ fn send_roc_usdt_and_weth_from_asset_hub_rococo_to_asset_hub_westend() { ///////////////////////////////////////////////////////////// let usdt_at_asset_hub_rococo = usdt_at_ah_rococo(); - let bridged_usdt_at_asset_hub_westend = bridged_usdt_at_ah_westend().try_into().unwrap(); + let bridged_usdt_at_asset_hub_westend = bridged_usdt_at_ah_westend(); // wETH has same relative location on both Rococo and Westend AssetHubs - let bridged_weth_at_ah = weth_at_asset_hubs().try_into().unwrap(); + let bridged_weth_at_ah = weth_at_asset_hubs(); // mint USDT in sender's account (USDT already created in genesis) AssetHubRococo::mint_asset( @@ -197,19 +198,23 @@ fn send_roc_usdt_and_weth_from_asset_hub_rococo_to_asset_hub_westend() { amount * 2, ); // create wETH at src and dest and prefund sender's account - create_foreign_on_ah_rococo(bridged_weth_at_ah, true, vec![(sender.clone(), amount * 2)]); - create_foreign_on_ah_westend(bridged_weth_at_ah, true); - create_foreign_on_ah_westend(bridged_usdt_at_asset_hub_westend, true); - set_up_pool_with_wnd_on_ah_westend(bridged_usdt_at_asset_hub_westend); + create_foreign_on_ah_rococo( + bridged_weth_at_ah.clone(), + true, + vec![(sender.clone(), amount * 2)], + ); + create_foreign_on_ah_westend(bridged_weth_at_ah.clone(), true); + create_foreign_on_ah_westend(bridged_usdt_at_asset_hub_westend.clone(), true); + set_up_pool_with_wnd_on_ah_westend(bridged_usdt_at_asset_hub_westend.clone()); let receiver_usdts_before = - foreign_balance_on_ah_westend(bridged_usdt_at_asset_hub_westend, &receiver); - let receiver_weth_before = foreign_balance_on_ah_westend(bridged_weth_at_ah, &receiver); + foreign_balance_on_ah_westend(bridged_usdt_at_asset_hub_westend.clone(), &receiver); + let receiver_weth_before = foreign_balance_on_ah_westend(bridged_weth_at_ah.clone(), &receiver); // send USDTs and wETHs let assets: Assets = vec![ (usdt_at_asset_hub_rococo.clone(), amount).into(), - (Location::try_from(bridged_weth_at_ah).unwrap(), amount).into(), + (Location::try_from(bridged_weth_at_ah.clone()).unwrap(), amount).into(), ] .into(); // use USDT for fees @@ -258,9 +263,8 @@ fn send_back_wnds_from_asset_hub_rococo_to_asset_hub_westend() { let sender = AssetHubRococoSender::get(); let receiver = AssetHubWestendReceiver::get(); let wnd_at_asset_hub_rococo = bridged_wnd_at_ah_rococo(); - let wnd_at_asset_hub_rococo_v3 = wnd_at_asset_hub_rococo.clone().try_into().unwrap(); let prefund_accounts = vec![(sender.clone(), prefund_amount)]; - create_foreign_on_ah_rococo(wnd_at_asset_hub_rococo_v3, true, prefund_accounts); + create_foreign_on_ah_rococo(wnd_at_asset_hub_rococo.clone(), true, prefund_accounts); // fund the AHR's SA on AHW with the WND tokens held in reserve let sov_ahr_on_ahw = AssetHubWestend::sovereign_account_of_parachain_on_other_global_consensus( @@ -273,14 +277,14 @@ fn send_back_wnds_from_asset_hub_rococo_to_asset_hub_westend() { ::account_data_of(sov_ahr_on_ahw.clone()).free; assert_eq!(wnds_in_reserve_on_ahw_before, prefund_amount); - let sender_wnds_before = foreign_balance_on_ah_rococo(wnd_at_asset_hub_rococo_v3, &sender); + let sender_wnds_before = foreign_balance_on_ah_rococo(wnd_at_asset_hub_rococo.clone(), &sender); assert_eq!(sender_wnds_before, prefund_amount); let receiver_wnds_before = ::account_data_of(receiver.clone()).free; // send back WNDs, use them for fees send_assets_over_bridge(|| { let destination = asset_hub_westend_location(); - let assets: Assets = (wnd_at_asset_hub_rococo, amount_to_send).into(); + let assets: Assets = (wnd_at_asset_hub_rococo.clone(), amount_to_send).into(); let fee_idx = 0; assert_ok!(send_assets_from_asset_hub_rococo(destination, assets, fee_idx)); }); @@ -309,7 +313,7 @@ fn send_back_wnds_from_asset_hub_rococo_to_asset_hub_westend() { ); }); - let sender_wnds_after = foreign_balance_on_ah_rococo(wnd_at_asset_hub_rococo_v3, &sender); + let sender_wnds_after = foreign_balance_on_ah_rococo(wnd_at_asset_hub_rococo, &sender); let receiver_wnds_after = ::account_data_of(receiver).free; let wnds_in_reserve_on_ahw_after = ::account_data_of(sov_ahr_on_ahw).free; @@ -341,7 +345,8 @@ fn send_rocs_from_penpal_rococo_through_asset_hub_rococo_to_asset_hub_westend() type ForeignAssets = ::ForeignAssets; >::balance(roc_at_rococo_parachains.clone(), &sender) }); - let receiver_rocs_before = foreign_balance_on_ah_westend(roc_at_asset_hub_westend, &receiver); + let receiver_rocs_before = + foreign_balance_on_ah_westend(roc_at_asset_hub_westend.clone(), &receiver); // Send ROCs over bridge { @@ -372,7 +377,7 @@ fn send_rocs_from_penpal_rococo_through_asset_hub_rococo_to_asset_hub_westend() vec![ // issue ROCs on AHW RuntimeEvent::ForeignAssets(pallet_assets::Event::Issued { asset_id, owner, .. }) => { - asset_id: *asset_id == roc_at_rococo_parachains.clone().try_into().unwrap(), + asset_id: *asset_id == roc_at_rococo_parachains.clone(), owner: owner == &receiver, }, // message processed successfully @@ -403,7 +408,6 @@ fn send_rocs_from_penpal_rococo_through_asset_hub_rococo_to_asset_hub_westend() #[test] fn send_back_wnds_from_penpal_rococo_through_asset_hub_rococo_to_asset_hub_westend() { let wnd_at_rococo_parachains = bridged_wnd_at_ah_rococo(); - let wnd_at_rococo_parachains_v3 = wnd_at_rococo_parachains.clone().try_into().unwrap(); let amount = ASSET_HUB_ROCOCO_ED * 10_000_000; let sender = PenpalASender::get(); let receiver = AssetHubWestendReceiver::get(); @@ -416,7 +420,7 @@ fn send_back_wnds_from_penpal_rococo_through_asset_hub_rococo_to_asset_hub_weste let penpal_location = AssetHubRococo::sibling_location_of(PenpalA::para_id()); let sov_penpal_on_ahr = AssetHubRococo::sovereign_account_id_of(penpal_location); let prefund_accounts = vec![(sov_penpal_on_ahr, amount * 2)]; - create_foreign_on_ah_rococo(wnd_at_rococo_parachains_v3, true, prefund_accounts); + create_foreign_on_ah_rococo(wnd_at_rococo_parachains.clone(), true, prefund_accounts); let asset_owner: AccountId = AssetHubRococo::account_id_of(ALICE); PenpalA::force_create_foreign_asset( wnd_at_rococo_parachains.clone(), diff --git a/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-rococo/src/tests/mod.rs b/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-rococo/src/tests/mod.rs index ceccf98a0240..6ce8ecef0df3 100644 --- a/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-rococo/src/tests/mod.rs +++ b/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-rococo/src/tests/mod.rs @@ -69,7 +69,7 @@ pub(crate) fn weth_at_asset_hubs() -> Location { } pub(crate) fn create_foreign_on_ah_rococo( - id: v3::Location, + id: v4::Location, sufficient: bool, prefund_accounts: Vec<(AccountId, u128)>, ) { @@ -78,18 +78,18 @@ pub(crate) fn create_foreign_on_ah_rococo( AssetHubRococo::force_create_foreign_asset(id, owner, sufficient, min, prefund_accounts); } -pub(crate) fn create_foreign_on_ah_westend(id: v3::Location, sufficient: bool) { +pub(crate) fn create_foreign_on_ah_westend(id: v4::Location, sufficient: bool) { let owner = AssetHubWestend::account_id_of(ALICE); AssetHubWestend::force_create_foreign_asset(id, owner, sufficient, ASSET_MIN_BALANCE, vec![]); } -pub(crate) fn foreign_balance_on_ah_rococo(id: v3::Location, who: &AccountId) -> u128 { +pub(crate) fn foreign_balance_on_ah_rococo(id: v4::Location, who: &AccountId) -> u128 { AssetHubRococo::execute_with(|| { type Assets = ::ForeignAssets; >::balance(id, who) }) } -pub(crate) fn foreign_balance_on_ah_westend(id: v3::Location, who: &AccountId) -> u128 { +pub(crate) fn foreign_balance_on_ah_westend(id: v4::Location, who: &AccountId) -> u128 { AssetHubWestend::execute_with(|| { type Assets = ::ForeignAssets; >::balance(id, who) @@ -97,8 +97,8 @@ pub(crate) fn foreign_balance_on_ah_westend(id: v3::Location, who: &AccountId) - } // set up pool -pub(crate) fn set_up_pool_with_wnd_on_ah_westend(foreign_asset: v3::Location) { - let wnd: v3::Location = v3::Parent.into(); +pub(crate) fn set_up_pool_with_wnd_on_ah_westend(foreign_asset: v4::Location) { + let wnd: v4::Location = v4::Parent.into(); AssetHubWestend::execute_with(|| { type RuntimeEvent = ::RuntimeEvent; let owner = AssetHubWestendSender::get(); @@ -106,14 +106,14 @@ pub(crate) fn set_up_pool_with_wnd_on_ah_westend(foreign_asset: v3::Location) { assert_ok!(::ForeignAssets::mint( signed_owner.clone(), - foreign_asset.into(), + foreign_asset.clone().into(), owner.clone().into(), 3_000_000_000_000, )); assert_ok!(::AssetConversion::create_pool( signed_owner.clone(), - Box::new(wnd), - Box::new(foreign_asset), + Box::new(wnd.clone()), + Box::new(foreign_asset.clone()), )); assert_expected_events!( AssetHubWestend, diff --git a/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-westend/src/lib.rs b/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-westend/src/lib.rs index 782b83bac475..3262cc17ba56 100644 --- a/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-westend/src/lib.rs +++ b/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-westend/src/lib.rs @@ -23,8 +23,7 @@ mod imports { pub use xcm::{ latest::ParentThen, prelude::{AccountId32 as AccountId32Junction, *}, - v3, - v4::NetworkId::Rococo as RococoId, + v4::{self, NetworkId::Rococo as RococoId}, }; pub use xcm_executor::traits::TransferType; diff --git a/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-westend/src/tests/asset_transfers.rs b/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-westend/src/tests/asset_transfers.rs index 0c0b04cd45a9..e2c496802e2c 100644 --- a/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-westend/src/tests/asset_transfers.rs +++ b/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-westend/src/tests/asset_transfers.rs @@ -35,10 +35,10 @@ fn send_assets_over_bridge(send_fn: F) { fn set_up_wnds_for_penpal_westend_through_ahw_to_ahr( sender: &AccountId, amount: u128, -) -> (Location, v3::Location) { +) -> (Location, v4::Location) { let wnd_at_westend_parachains = wnd_at_ah_westend(); - let wnd_at_asset_hub_rococo = bridged_wnd_at_ah_rococo().try_into().unwrap(); - create_foreign_on_ah_rococo(wnd_at_asset_hub_rococo, true); + let wnd_at_asset_hub_rococo = bridged_wnd_at_ah_rococo(); + create_foreign_on_ah_rococo(wnd_at_asset_hub_rococo.clone(), true); let penpal_location = AssetHubWestend::sibling_location_of(PenpalB::para_id()); let sov_penpal_on_ahw = AssetHubWestend::sovereign_account_id_of(penpal_location); @@ -116,10 +116,10 @@ fn send_wnds_from_asset_hub_westend_to_asset_hub_rococo() { let sender = AssetHubWestendSender::get(); let receiver = AssetHubRococoReceiver::get(); let wnd_at_asset_hub_westend = wnd_at_ah_westend(); - let bridged_wnd_at_asset_hub_rococo = bridged_wnd_at_ah_rococo().try_into().unwrap(); - create_foreign_on_ah_rococo(bridged_wnd_at_asset_hub_rococo, true); + let bridged_wnd_at_asset_hub_rococo = bridged_wnd_at_ah_rococo(); + create_foreign_on_ah_rococo(bridged_wnd_at_asset_hub_rococo.clone(), true); - set_up_pool_with_roc_on_ah_rococo(bridged_wnd_at_asset_hub_rococo, true); + set_up_pool_with_roc_on_ah_rococo(bridged_wnd_at_asset_hub_rococo.clone(), true); let sov_ahr_on_ahw = AssetHubWestend::sovereign_account_of_parachain_on_other_global_consensus( Rococo, @@ -129,7 +129,7 @@ fn send_wnds_from_asset_hub_westend_to_asset_hub_rococo() { ::account_data_of(sov_ahr_on_ahw.clone()).free; let sender_wnds_before = ::account_data_of(sender.clone()).free; let receiver_wnds_before = - foreign_balance_on_ah_rococo(bridged_wnd_at_asset_hub_rococo, &receiver); + foreign_balance_on_ah_rococo(bridged_wnd_at_asset_hub_rococo.clone(), &receiver); // send WNDs, use them for fees send_assets_over_bridge(|| { @@ -187,10 +187,8 @@ fn send_back_rocs_usdt_and_weth_from_asset_hub_westend_to_asset_hub_rococo() { let sender = AssetHubWestendSender::get(); let receiver = AssetHubRococoReceiver::get(); let bridged_roc_at_asset_hub_westend = bridged_roc_at_ah_westend(); - let bridged_roc_at_asset_hub_westend_v3 = - bridged_roc_at_asset_hub_westend.clone().try_into().unwrap(); let prefund_accounts = vec![(sender.clone(), prefund_amount)]; - create_foreign_on_ah_westend(bridged_roc_at_asset_hub_westend_v3, true, prefund_accounts); + create_foreign_on_ah_westend(bridged_roc_at_asset_hub_westend.clone(), true, prefund_accounts); //////////////////////////////////////////////////////////// // Let's first send back just some ROCs as a simple example @@ -208,14 +206,14 @@ fn send_back_rocs_usdt_and_weth_from_asset_hub_westend_to_asset_hub_rococo() { assert_eq!(rocs_in_reserve_on_ahr_before, prefund_amount); let sender_rocs_before = - foreign_balance_on_ah_westend(bridged_roc_at_asset_hub_westend_v3, &sender); + foreign_balance_on_ah_westend(bridged_roc_at_asset_hub_westend.clone(), &sender); assert_eq!(sender_rocs_before, prefund_amount); let receiver_rocs_before = ::account_data_of(receiver.clone()).free; // send back ROCs, use them for fees send_assets_over_bridge(|| { let destination = asset_hub_rococo_location(); - let assets: Assets = (bridged_roc_at_asset_hub_westend, amount_to_send).into(); + let assets: Assets = (bridged_roc_at_asset_hub_westend.clone(), amount_to_send).into(); let fee_idx = 0; assert_ok!(send_assets_from_asset_hub_westend(destination, assets, fee_idx)); }); @@ -245,7 +243,7 @@ fn send_back_rocs_usdt_and_weth_from_asset_hub_westend_to_asset_hub_rococo() { }); let sender_rocs_after = - foreign_balance_on_ah_westend(bridged_roc_at_asset_hub_westend_v3, &sender); + foreign_balance_on_ah_westend(bridged_roc_at_asset_hub_westend, &sender); let receiver_rocs_after = ::account_data_of(receiver.clone()).free; let rocs_in_reserve_on_ahr_after = ::account_data_of(sov_ahw_on_ahr.clone()).free; @@ -262,14 +260,14 @@ fn send_back_rocs_usdt_and_weth_from_asset_hub_westend_to_asset_hub_rococo() { ////////////////////////////////////////////////////////////////// // wETH has same relative location on both Rococo and Westend AssetHubs - let bridged_weth_at_ah = weth_at_asset_hubs().try_into().unwrap(); - let bridged_usdt_at_asset_hub_westend = bridged_usdt_at_ah_westend().try_into().unwrap(); + let bridged_weth_at_ah = weth_at_asset_hubs(); + let bridged_usdt_at_asset_hub_westend = bridged_usdt_at_ah_westend(); // set up destination chain AH Rococo: // create a ROC/USDT pool to be able to pay fees with USDT (USDT created in genesis) - set_up_pool_with_roc_on_ah_rococo(usdt_at_ah_rococo().try_into().unwrap(), false); + set_up_pool_with_roc_on_ah_rococo(usdt_at_ah_rococo(), false); // create wETH on Rococo (IRL it's already created by Snowbridge) - create_foreign_on_ah_rococo(bridged_weth_at_ah, true); + create_foreign_on_ah_rococo(bridged_weth_at_ah.clone(), true); // prefund AHW's sovereign account on AHR to be able to withdraw USDT and wETH from reserves let sov_ahw_on_ahr = AssetHubRococo::sovereign_account_of_parachain_on_other_global_consensus( Westend, @@ -283,7 +281,7 @@ fn send_back_rocs_usdt_and_weth_from_asset_hub_westend_to_asset_hub_rococo() { ); AssetHubRococo::mint_foreign_asset( ::RuntimeOrigin::signed(AssetHubRococo::account_id_of(ALICE)), - bridged_weth_at_ah, + bridged_weth_at_ah.clone(), sov_ahw_on_ahr, amount_to_send * 2, ); @@ -291,21 +289,21 @@ fn send_back_rocs_usdt_and_weth_from_asset_hub_westend_to_asset_hub_rococo() { // set up source chain AH Westend: // create wETH and USDT foreign assets on Westend and prefund sender's account let prefund_accounts = vec![(sender.clone(), amount_to_send * 2)]; - create_foreign_on_ah_westend(bridged_weth_at_ah, true, prefund_accounts.clone()); - create_foreign_on_ah_westend(bridged_usdt_at_asset_hub_westend, true, prefund_accounts); + create_foreign_on_ah_westend(bridged_weth_at_ah.clone(), true, prefund_accounts.clone()); + create_foreign_on_ah_westend(bridged_usdt_at_asset_hub_westend.clone(), true, prefund_accounts); // check balances before let receiver_usdts_before = AssetHubRococo::execute_with(|| { type Assets = ::Assets; >::balance(USDT_ID, &receiver) }); - let receiver_weth_before = foreign_balance_on_ah_rococo(bridged_weth_at_ah, &receiver); + let receiver_weth_before = foreign_balance_on_ah_rococo(bridged_weth_at_ah.clone(), &receiver); let usdt_id: AssetId = Location::try_from(bridged_usdt_at_asset_hub_westend).unwrap().into(); // send USDTs and wETHs let assets: Assets = vec![ (usdt_id.clone(), amount_to_send).into(), - (Location::try_from(bridged_weth_at_ah).unwrap(), amount_to_send).into(), + (Location::try_from(bridged_weth_at_ah.clone()).unwrap(), amount_to_send).into(), ] .into(); // use USDT for fees @@ -367,7 +365,8 @@ fn send_wnds_from_penpal_westend_through_asset_hub_westend_to_asset_hub_rococo() type ForeignAssets = ::ForeignAssets; >::balance(wnd_at_westend_parachains.clone(), &sender) }); - let receiver_wnds_before = foreign_balance_on_ah_rococo(wnd_at_asset_hub_rococo, &receiver); + let receiver_wnds_before = + foreign_balance_on_ah_rococo(wnd_at_asset_hub_rococo.clone(), &receiver); // Send WNDs over bridge { @@ -398,7 +397,7 @@ fn send_wnds_from_penpal_westend_through_asset_hub_westend_to_asset_hub_rococo() vec![ // issue WNDs on AHR RuntimeEvent::ForeignAssets(pallet_assets::Event::Issued { asset_id, owner, .. }) => { - asset_id: *asset_id == wnd_at_westend_parachains.clone().try_into().unwrap(), + asset_id: *asset_id == wnd_at_westend_parachains.clone(), owner: owner == &receiver, }, // message processed successfully @@ -429,7 +428,6 @@ fn send_wnds_from_penpal_westend_through_asset_hub_westend_to_asset_hub_rococo() #[test] fn send_back_rocs_from_penpal_westend_through_asset_hub_westend_to_asset_hub_rococo() { let roc_at_westend_parachains = bridged_roc_at_ah_westend(); - let roc_at_westend_parachains_v3 = roc_at_westend_parachains.clone().try_into().unwrap(); let amount = ASSET_HUB_WESTEND_ED * 10_000_000; let sender = PenpalBSender::get(); let receiver = AssetHubRococoReceiver::get(); @@ -442,7 +440,7 @@ fn send_back_rocs_from_penpal_westend_through_asset_hub_westend_to_asset_hub_roc let penpal_location = AssetHubWestend::sibling_location_of(PenpalB::para_id()); let sov_penpal_on_ahr = AssetHubWestend::sovereign_account_id_of(penpal_location); let prefund_accounts = vec![(sov_penpal_on_ahr, amount * 2)]; - create_foreign_on_ah_westend(roc_at_westend_parachains_v3, true, prefund_accounts); + create_foreign_on_ah_westend(roc_at_westend_parachains.clone(), true, prefund_accounts); let asset_owner: AccountId = AssetHubWestend::account_id_of(ALICE); PenpalB::force_create_foreign_asset( roc_at_westend_parachains.clone(), diff --git a/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-westend/src/tests/mod.rs b/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-westend/src/tests/mod.rs index 768b647a13fc..22c422900744 100644 --- a/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-westend/src/tests/mod.rs +++ b/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-westend/src/tests/mod.rs @@ -73,13 +73,13 @@ pub(crate) fn weth_at_asset_hubs() -> Location { ) } -pub(crate) fn create_foreign_on_ah_rococo(id: v3::Location, sufficient: bool) { +pub(crate) fn create_foreign_on_ah_rococo(id: v4::Location, sufficient: bool) { let owner = AssetHubRococo::account_id_of(ALICE); AssetHubRococo::force_create_foreign_asset(id, owner, sufficient, ASSET_MIN_BALANCE, vec![]); } pub(crate) fn create_foreign_on_ah_westend( - id: v3::Location, + id: v4::Location, sufficient: bool, prefund_accounts: Vec<(AccountId, u128)>, ) { @@ -88,13 +88,13 @@ pub(crate) fn create_foreign_on_ah_westend( AssetHubWestend::force_create_foreign_asset(id, owner, sufficient, min, prefund_accounts); } -pub(crate) fn foreign_balance_on_ah_rococo(id: v3::Location, who: &AccountId) -> u128 { +pub(crate) fn foreign_balance_on_ah_rococo(id: v4::Location, who: &AccountId) -> u128 { AssetHubRococo::execute_with(|| { type Assets = ::ForeignAssets; >::balance(id, who) }) } -pub(crate) fn foreign_balance_on_ah_westend(id: v3::Location, who: &AccountId) -> u128 { +pub(crate) fn foreign_balance_on_ah_westend(id: v4::Location, who: &AccountId) -> u128 { AssetHubWestend::execute_with(|| { type Assets = ::ForeignAssets; >::balance(id, who) @@ -102,8 +102,8 @@ pub(crate) fn foreign_balance_on_ah_westend(id: v3::Location, who: &AccountId) - } // set up pool -pub(crate) fn set_up_pool_with_roc_on_ah_rococo(asset: v3::Location, is_foreign: bool) { - let roc: v3::Location = v3::Parent.into(); +pub(crate) fn set_up_pool_with_roc_on_ah_rococo(asset: v4::Location, is_foreign: bool) { + let roc: v4::Location = v4::Parent.into(); AssetHubRococo::execute_with(|| { type RuntimeEvent = ::RuntimeEvent; let owner = AssetHubRococoSender::get(); @@ -112,13 +112,13 @@ pub(crate) fn set_up_pool_with_roc_on_ah_rococo(asset: v3::Location, is_foreign: if is_foreign { assert_ok!(::ForeignAssets::mint( signed_owner.clone(), - asset.into(), + asset.clone().into(), owner.clone().into(), 3_000_000_000_000, )); } else { - let asset_id = match asset.interior.split_last() { - (_, Some(v3::Junction::GeneralIndex(id))) => id as u32, + let asset_id = match asset.interior.last() { + Some(v4::Junction::GeneralIndex(id)) => *id as u32, _ => unreachable!(), }; assert_ok!(::Assets::mint( @@ -130,8 +130,8 @@ pub(crate) fn set_up_pool_with_roc_on_ah_rococo(asset: v3::Location, is_foreign: } assert_ok!(::AssetConversion::create_pool( signed_owner.clone(), - Box::new(roc), - Box::new(asset), + Box::new(roc.clone()), + Box::new(asset.clone()), )); assert_expected_events!( AssetHubRococo, From 57fe4225ece01d83dc63215619d5254742bc8dde Mon Sep 17 00:00:00 2001 From: Francisco Aguirre Date: Wed, 7 Aug 2024 13:57:01 +0200 Subject: [PATCH 26/32] fix(assets-common-migrations): use correct module name --- .../assets/migrations/src/foreign_assets_to_v4/benchmarks.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cumulus/parachains/runtimes/assets/migrations/src/foreign_assets_to_v4/benchmarks.rs b/cumulus/parachains/runtimes/assets/migrations/src/foreign_assets_to_v4/benchmarks.rs index a5d84822764b..0d9524106e4a 100644 --- a/cumulus/parachains/runtimes/assets/migrations/src/foreign_assets_to_v4/benchmarks.rs +++ b/cumulus/parachains/runtimes/assets/migrations/src/foreign_assets_to_v4/benchmarks.rs @@ -19,7 +19,7 @@ use frame_benchmarking::v2::*; use pallet_assets::{Asset, AssetDetails, AssetStatus, Config}; use xcm::{v3, v4}; -use crate::{v1::old::AssetDetailsOf, Pallet}; +use crate::{foreign_assets_to_v4::old::AssetDetailsOf, Pallet}; use super::{old, Migration}; From 41ca88c2d138c2d1123a71451b2f56806d218071 Mon Sep 17 00:00:00 2001 From: Francisco Aguirre Date: Wed, 7 Aug 2024 14:23:57 +0200 Subject: [PATCH 27/32] fix(assets-common-migrations): use correct module name --- .../migrations/src/foreign_assets_to_v4/benchmarks.rs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/cumulus/parachains/runtimes/assets/migrations/src/foreign_assets_to_v4/benchmarks.rs b/cumulus/parachains/runtimes/assets/migrations/src/foreign_assets_to_v4/benchmarks.rs index 0d9524106e4a..7c1f07a42c8c 100644 --- a/cumulus/parachains/runtimes/assets/migrations/src/foreign_assets_to_v4/benchmarks.rs +++ b/cumulus/parachains/runtimes/assets/migrations/src/foreign_assets_to_v4/benchmarks.rs @@ -34,7 +34,7 @@ mod benches { fn conversion_step() { let key = v3::Location::new(1, [v3::Junction::Parachain(2004)]); let mock_asset_details = mock_asset_details::(); - old::Asset::::insert(key.clone(), mock_asset_details.clone()); + old::Asset::::insert(key, mock_asset_details.clone()); #[block] { @@ -46,7 +46,11 @@ mod benches { assert_eq!(Asset::::get(new_key), Some(mock_asset_details.clone())); } - impl_benchmark_test_suite!(Pallet, crate::v1::tests::new_test_ext(), crate::v1::tests::Runtime); + impl_benchmark_test_suite!( + Pallet, + crate::foreign_assets_to_v4::tests::new_test_ext(), + crate::foreign_assets_to_v4::tests::Runtime + ); } fn mock_asset_details, I: 'static>() -> AssetDetailsOf { From 634b84d35dd7da468c782f7e49ae509753693816 Mon Sep 17 00:00:00 2001 From: Francisco Aguirre Date: Wed, 7 Aug 2024 15:03:30 +0200 Subject: [PATCH 28/32] fix(umbrella): regenerate umbrella crate --- Cargo.lock | 1 + umbrella/Cargo.toml | 8 ++++++++ umbrella/src/lib.rs | 4 ++++ 3 files changed, 13 insertions(+) diff --git a/Cargo.lock b/Cargo.lock index eeb01b90d75c..89a1d197f969 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -14264,6 +14264,7 @@ version = "0.1.0" dependencies = [ "asset-test-utils", "assets-common", + "assets-common-migrations", "binary-merkle-tree", "bp-asset-hub-rococo", "bp-asset-hub-westend", diff --git a/umbrella/Cargo.toml b/umbrella/Cargo.toml index 8d85e26d8fe7..1ebf84ebabb3 100644 --- a/umbrella/Cargo.toml +++ b/umbrella/Cargo.toml @@ -8,6 +8,7 @@ license = "Apache-2.0" default = ["std"] std = [ "asset-test-utils?/std", + "assets-common-migrations?/std", "assets-common?/std", "binary-merkle-tree?/std", "bp-asset-hub-rococo?/std", @@ -243,6 +244,7 @@ std = [ "xcm-runtime-apis?/std", ] runtime-benchmarks = [ + "assets-common-migrations?/runtime-benchmarks", "assets-common?/runtime-benchmarks", "bridge-hub-common?/runtime-benchmarks", "bridge-runtime-common?/runtime-benchmarks", @@ -542,6 +544,7 @@ with-tracing = [ ] runtime = [ "assets-common", + "assets-common-migrations", "binary-merkle-tree", "bp-asset-hub-rococo", "bp-asset-hub-westend", @@ -798,6 +801,11 @@ path = "../cumulus/parachains/runtimes/assets/common" default-features = false optional = true +[dependencies.assets-common-migrations] +path = "../cumulus/parachains/runtimes/assets/migrations" +default-features = false +optional = true + [dependencies.binary-merkle-tree] path = "../substrate/utils/binary-merkle-tree" default-features = false diff --git a/umbrella/src/lib.rs b/umbrella/src/lib.rs index 58a5691961d9..54713a34f4b8 100644 --- a/umbrella/src/lib.rs +++ b/umbrella/src/lib.rs @@ -19,6 +19,10 @@ pub use asset_test_utils; #[cfg(feature = "assets-common")] pub use assets_common; +/// Common migrations for assets. +#[cfg(feature = "assets-common-migrations")] +pub use assets_common_migrations; + /// A no-std/Substrate compatible library to construct binary merkle tree. #[cfg(feature = "binary-merkle-tree")] pub use binary_merkle_tree; From f00f5e891fc2d43a396c76338c232671dd595a1b Mon Sep 17 00:00:00 2001 From: command-bot <> Date: Wed, 7 Aug 2024 14:19:10 +0000 Subject: [PATCH 29/32] ".git/.scripts/commands/bench/bench.sh" --subcommand=pallet --runtime=asset-hub-westend --runtime_dir=assets --target_dir=cumulus --pallet=assets_common_migrations --- .../src/weights/assets_common_migrations.rs | 77 ++++++++++--------- 1 file changed, 39 insertions(+), 38 deletions(-) diff --git a/cumulus/parachains/runtimes/assets/asset-hub-westend/src/weights/assets_common_migrations.rs b/cumulus/parachains/runtimes/assets/asset-hub-westend/src/weights/assets_common_migrations.rs index f365e27b845b..f6d95f33f2dc 100644 --- a/cumulus/parachains/runtimes/assets/asset-hub-westend/src/weights/assets_common_migrations.rs +++ b/cumulus/parachains/runtimes/assets/asset-hub-westend/src/weights/assets_common_migrations.rs @@ -1,62 +1,63 @@ // Copyright (C) Parity Technologies (UK) Ltd. -// SPDX-License-Identifier: Apache-2.0 - -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. +// This file is part of Cumulus. + +// Cumulus is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// Cumulus is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with Cumulus. If not, see . //! Autogenerated weights for `assets_common_migrations` //! -//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 38.0.0 -//! DATE: 2024-08-05, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 32.0.0 +//! DATE: 2024-08-07, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]` //! WORST CASE MAP SIZE: `1000000` -//! HOSTNAME: `Ciscos-MBP.lan`, CPU: `` -//! WASM-EXECUTION: `Compiled`, CHAIN: `None`, DB CACHE: `1024` +//! HOSTNAME: `runner-696hpswk-project-674-concurrent-0`, CPU: `Intel(R) Xeon(R) CPU @ 2.60GHz` +//! WASM-EXECUTION: `Compiled`, CHAIN: `Some("asset-hub-westend-dev")`, DB CACHE: 1024 // Executed Command: -// frame-omni-bencher -// v1 +// target/production/polkadot-parachain // benchmark // pallet -// --runtime -// target/release/wbuild/asset-hub-westend-runtime/asset_hub_westend_runtime.compact.compressed.wasm -// --pallet -// assets_common_migrations -// --extrinsic -// * -// --template -// substrate/.maintain/frame-weight-template.hbs -// --output -// cumulus/parachains/runtimes/assets/asset-hub-westend/src/weights/assets_common_migrations.rs +// --steps=50 +// --repeat=20 +// --extrinsic=* +// --wasm-execution=compiled +// --heap-pages=4096 +// --json-file=/builds/parity/mirrors/polkadot-sdk/.git/.artifacts/bench.json +// --pallet=assets_common_migrations +// --chain=asset-hub-westend-dev +// --header=./cumulus/file_header.txt +// --output=./cumulus/parachains/runtimes/assets/asset-hub-westend/src/weights/ #![cfg_attr(rustfmt, rustfmt_skip)] #![allow(unused_parens)] #![allow(unused_imports)] #![allow(missing_docs)] -use frame_support::{traits::Get, weights::{Weight, constants::RocksDbWeight}}; +use frame_support::{traits::Get, weights::Weight}; use core::marker::PhantomData; -/// Weights for `assets_common_migrations` using the Substrate node and recommended hardware. -pub struct SubstrateWeight(PhantomData); -impl assets_common_migrations::foreign_assets_to_v4::WeightInfo for SubstrateWeight { +/// Weight functions for `assets_common_migrations`. +pub struct WeightInfo(PhantomData); +impl assets_common_migrations::WeightInfo for WeightInfo { /// Storage: `ForeignAssets::Asset` (r:2 w:1) /// Proof: `ForeignAssets::Asset` (`max_values`: None, `max_size`: Some(808), added: 3283, mode: `MaxEncodedLen`) fn conversion_step() -> Weight { // Proof Size summary in bytes: - // Measured: `161` + // Measured: `243` // Estimated: `7556` - // Minimum execution time: 6_000_000 picoseconds. - Weight::from_parts(6_000_000, 7556) - .saturating_add(T::DbWeight::get().reads(2_u64)) - .saturating_add(T::DbWeight::get().writes(1_u64)) + // Minimum execution time: 12_296_000 picoseconds. + Weight::from_parts(12_590_000, 0) + .saturating_add(Weight::from_parts(0, 7556)) + .saturating_add(T::DbWeight::get().reads(2)) + .saturating_add(T::DbWeight::get().writes(1)) } } From f59f7da3444d1285beb26d1fb827b63809b49087 Mon Sep 17 00:00:00 2001 From: Francisco Aguirre Date: Thu, 8 Aug 2024 19:52:18 +0200 Subject: [PATCH 30/32] revert: remove all the data migration stuff --- Cargo.lock | 28 --- Cargo.toml | 2 - .../assets/asset-hub-rococo/Cargo.toml | 7 - .../assets/asset-hub-rococo/src/lib.rs | 39 +---- .../src/weights/assets_common_migrations.rs | 62 ------- .../asset-hub-rococo/src/weights/mod.rs | 1 - .../assets/asset-hub-westend/Cargo.toml | 7 - .../assets/asset-hub-westend/src/lib.rs | 37 +--- .../src/weights/assets_common_migrations.rs | 63 ------- .../asset-hub-westend/src/weights/mod.rs | 1 - .../runtimes/assets/common/Cargo.toml | 13 -- .../runtimes/assets/migrations/Cargo.toml | 60 ------- .../src/foreign_assets_to_v4/benchmarks.rs | 71 -------- .../src/foreign_assets_to_v4/mod.rs | 128 -------------- .../src/foreign_assets_to_v4/tests.rs | 159 ------------------ .../src/foreign_assets_to_v4/weights.rs | 83 --------- .../runtimes/assets/migrations/src/lib.rs | 32 ---- substrate/frame/assets/src/lib.rs | 2 +- substrate/frame/assets/src/types.rs | 28 +-- umbrella/Cargo.toml | 8 - umbrella/src/lib.rs | 4 - 21 files changed, 19 insertions(+), 816 deletions(-) delete mode 100644 cumulus/parachains/runtimes/assets/asset-hub-rococo/src/weights/assets_common_migrations.rs delete mode 100644 cumulus/parachains/runtimes/assets/asset-hub-westend/src/weights/assets_common_migrations.rs delete mode 100644 cumulus/parachains/runtimes/assets/migrations/Cargo.toml delete mode 100644 cumulus/parachains/runtimes/assets/migrations/src/foreign_assets_to_v4/benchmarks.rs delete mode 100644 cumulus/parachains/runtimes/assets/migrations/src/foreign_assets_to_v4/mod.rs delete mode 100644 cumulus/parachains/runtimes/assets/migrations/src/foreign_assets_to_v4/tests.rs delete mode 100644 cumulus/parachains/runtimes/assets/migrations/src/foreign_assets_to_v4/weights.rs delete mode 100644 cumulus/parachains/runtimes/assets/migrations/src/lib.rs diff --git a/Cargo.lock b/Cargo.lock index 89a1d197f969..dd5b4fc3f028 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -868,7 +868,6 @@ version = "0.11.0" dependencies = [ "asset-test-utils", "assets-common", - "assets-common-migrations", "bp-asset-hub-rococo", "bp-asset-hub-westend", "bp-bridge-hub-rococo", @@ -902,7 +901,6 @@ dependencies = [ "pallet-balances", "pallet-collator-selection", "pallet-message-queue", - "pallet-migrations", "pallet-multisig", "pallet-nft-fractionalization", "pallet-nfts", @@ -1000,7 +998,6 @@ version = "0.15.0" dependencies = [ "asset-test-utils", "assets-common", - "assets-common-migrations", "bp-asset-hub-rococo", "bp-asset-hub-westend", "bp-bridge-hub-rococo", @@ -1034,7 +1031,6 @@ dependencies = [ "pallet-balances", "pallet-collator-selection", "pallet-message-queue", - "pallet-migrations", "pallet-multisig", "pallet-nft-fractionalization", "pallet-nfts", @@ -1115,18 +1111,14 @@ version = "0.7.0" dependencies = [ "cumulus-primitives-core", "frame-support", - "frame-system", "impl-trait-for-tuples", "log", "pallet-asset-conversion", - "pallet-assets", - "pallet-balances", "pallet-xcm", "parachains-common", "parity-scale-codec", "scale-info", "sp-api", - "sp-io", "sp-runtime", "staging-xcm", "staging-xcm-builder", @@ -1134,25 +1126,6 @@ dependencies = [ "substrate-wasm-builder", ] -[[package]] -name = "assets-common-migrations" -version = "0.1.0" -dependencies = [ - "frame-benchmarking", - "frame-support", - "frame-system", - "log", - "pallet-asset-conversion", - "pallet-assets", - "pallet-balances", - "pallet-migrations", - "parity-scale-codec", - "scale-info", - "sp-io", - "sp-runtime", - "staging-xcm", -] - [[package]] name = "async-attributes" version = "1.1.2" @@ -14264,7 +14237,6 @@ version = "0.1.0" dependencies = [ "asset-test-utils", "assets-common", - "assets-common-migrations", "binary-merkle-tree", "bp-asset-hub-rococo", "bp-asset-hub-westend", diff --git a/Cargo.toml b/Cargo.toml index 9938064dda5c..7ae7c3bd1811 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -117,7 +117,6 @@ members = [ "cumulus/parachains/runtimes/assets/asset-hub-rococo", "cumulus/parachains/runtimes/assets/asset-hub-westend", "cumulus/parachains/runtimes/assets/common", - "cumulus/parachains/runtimes/assets/migrations", "cumulus/parachains/runtimes/assets/test-utils", "cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo", "cumulus/parachains/runtimes/bridge-hubs/bridge-hub-westend", @@ -604,7 +603,6 @@ asset-hub-westend-emulated-chain = { path = "cumulus/parachains/integration-test asset-hub-westend-runtime = { path = "cumulus/parachains/runtimes/assets/asset-hub-westend" } asset-test-utils = { path = "cumulus/parachains/runtimes/assets/test-utils", default-features = false } assets-common = { path = "cumulus/parachains/runtimes/assets/common", default-features = false } -assets-common-migrations = { path = "cumulus/parachains/runtimes/assets/migrations", default-features = false } async-channel = { version = "1.8.0" } async-std = { version = "1.9.0" } async-trait = { version = "0.1.79" } diff --git a/cumulus/parachains/runtimes/assets/asset-hub-rococo/Cargo.toml b/cumulus/parachains/runtimes/assets/asset-hub-rococo/Cargo.toml index 7310be3b7f70..98df41090a40 100644 --- a/cumulus/parachains/runtimes/assets/asset-hub-rococo/Cargo.toml +++ b/cumulus/parachains/runtimes/assets/asset-hub-rococo/Cargo.toml @@ -44,7 +44,6 @@ pallet-transaction-payment = { workspace = true } pallet-transaction-payment-rpc-runtime-api = { workspace = true } pallet-uniques = { workspace = true } pallet-utility = { workspace = true } -pallet-migrations = { workspace = true } sp-api = { workspace = true } sp-block-builder = { workspace = true } sp-consensus-aura = { workspace = true } @@ -87,7 +86,6 @@ parachain-info = { workspace = true } parachains-common = { workspace = true } testnet-parachains-constants = { features = ["rococo"], workspace = true } assets-common = { workspace = true } -assets-common-migrations = { workspace = true } # Bridges pallet-xcm-bridge-hub-router = { workspace = true } @@ -106,7 +104,6 @@ substrate-wasm-builder = { optional = true, workspace = true, default-features = [features] default = ["std"] runtime-benchmarks = [ - "assets-common-migrations/runtime-benchmarks", "assets-common/runtime-benchmarks", "cumulus-pallet-parachain-system/runtime-benchmarks", "cumulus-pallet-session-benchmarking/runtime-benchmarks", @@ -124,7 +121,6 @@ runtime-benchmarks = [ "pallet-balances/runtime-benchmarks", "pallet-collator-selection/runtime-benchmarks", "pallet-message-queue/runtime-benchmarks", - "pallet-migrations/runtime-benchmarks", "pallet-multisig/runtime-benchmarks", "pallet-nft-fractionalization/runtime-benchmarks", "pallet-nfts/runtime-benchmarks", @@ -163,7 +159,6 @@ try-runtime = [ "pallet-balances/try-runtime", "pallet-collator-selection/try-runtime", "pallet-message-queue/try-runtime", - "pallet-migrations/try-runtime", "pallet-multisig/try-runtime", "pallet-nft-fractionalization/try-runtime", "pallet-nfts/try-runtime", @@ -180,7 +175,6 @@ try-runtime = [ "sp-runtime/try-runtime", ] std = [ - "assets-common-migrations/std", "assets-common/std", "bp-asset-hub-rococo/std", "bp-asset-hub-westend/std", @@ -215,7 +209,6 @@ std = [ "pallet-balances/std", "pallet-collator-selection/std", "pallet-message-queue/std", - "pallet-migrations/std", "pallet-multisig/std", "pallet-nft-fractionalization/std", "pallet-nfts-runtime-api/std", diff --git a/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/lib.rs b/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/lib.rs index aa673f8d0935..accbdcd5b132 100644 --- a/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/lib.rs +++ b/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/lib.rs @@ -58,7 +58,6 @@ use frame_support::{ construct_runtime, derive_impl, dispatch::DispatchClass, genesis_builder_helper::{build_state, get_preset}, - migrations::FreezeChainOnFailedMigration, ord_parameter_types, parameter_types, traits::{ fungible, fungibles, tokens::imbalance::ResolveAssetTo, AsEnsureOriginWithArg, ConstBool, @@ -179,36 +178,8 @@ impl frame_system::Config for Runtime { type SS58Prefix = SS58Prefix; type OnSetCode = cumulus_pallet_parachain_system::ParachainSetCode; type MaxConsumers = frame_support::traits::ConstU32<16>; - type SingleBlockMigrations = SingleBlockMigrations; - type MultiBlockMigrator = MultiBlockMigrator; } -// We destine 80% of the block's weight to MBMs. -parameter_types! { - pub MbmServiceWeight: Weight = Perbill::from_percent(80) * RuntimeBlockWeights::get().max_block; -} - -impl pallet_migrations::Config for Runtime { - type RuntimeEvent = RuntimeEvent; - #[cfg(not(feature = "runtime-benchmarks"))] - type Migrations = MultiBlockMigrations; - #[cfg(feature = "runtime-benchmarks")] - type Migrations = pallet_migrations::mock_helpers::MockedMigrations; - type CursorMaxLen = ConstU32<1024>; - type IdentifierMaxLen = ConstU32<256>; - type MigrationStatusHandler = (); - type FailedMigrationHandler = FreezeChainOnFailedMigration; - type MaxServiceWeight = MbmServiceWeight; - type WeightInfo = (); -} - -#[cfg(not(feature = "runtime-benchmarks"))] -type MultiBlockMigrations = assets_common_migrations::foreign_assets_to_v4::Migration< - Runtime, - ForeignAssetsInstance, - weights::assets_common_migrations::SubstrateWeight, ->; - impl pallet_timestamp::Config for Runtime { /// A timestamp: milliseconds since the unix epoch. type Moment = u64; @@ -981,7 +952,6 @@ construct_runtime!( ParachainSystem: cumulus_pallet_parachain_system = 1, Timestamp: pallet_timestamp = 3, ParachainInfo: parachain_info = 4, - MultiBlockMigrator: pallet_migrations = 5, // Monetary stuff. Balances: pallet_balances = 10, @@ -1052,7 +1022,7 @@ pub type SignedExtra = ( pub type UncheckedExtrinsic = generic::UncheckedExtrinsic; /// Migrations to apply on runtime upgrade. -pub type SingleBlockMigrations = ( +pub type Migrations = ( pallet_collator_selection::migration::v1::MigrateToV1, InitStorageVersions, // unreleased @@ -1127,7 +1097,7 @@ pub type Executive = frame_executive::Executive< frame_system::ChainContext, Runtime, AllPalletsWithSystem, - (), + Migrations, >; #[cfg(feature = "runtime-benchmarks")] @@ -1153,7 +1123,6 @@ mod benches { [cumulus_pallet_xcmp_queue, XcmpQueue] [pallet_xcm_bridge_hub_router, ToWestend] [pallet_asset_conversion_ops, AssetConversionMigration] - [assets_common_migrations, AssetsCommonMigrations] // XCM [pallet_xcm, PalletXcmExtrinsicsBenchmark::] // NOTE: Make sure you point to the individual modules below. @@ -1464,8 +1433,6 @@ impl_runtime_apis! { type XcmBalances = pallet_xcm_benchmarks::fungible::Pallet::; type XcmGeneric = pallet_xcm_benchmarks::generic::Pallet::; - type AssetsCommonMigrations = assets_common_migrations::Pallet::; - // Benchmark files generated for `Assets/ForeignAssets` instances are by default // `pallet_assets_assets.rs / pallet_assets_foreign_assets`, which is not really nice, // so with this redefinition we can change names to nicer: @@ -1769,8 +1736,6 @@ impl_runtime_apis! { type XcmBalances = pallet_xcm_benchmarks::fungible::Pallet::; type XcmGeneric = pallet_xcm_benchmarks::generic::Pallet::; - type AssetsCommonMigrations = assets_common_migrations::Pallet::; - type Local = pallet_assets::Pallet::; type Foreign = pallet_assets::Pallet::; type Pool = pallet_assets::Pallet::; diff --git a/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/weights/assets_common_migrations.rs b/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/weights/assets_common_migrations.rs deleted file mode 100644 index 131c08334818..000000000000 --- a/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/weights/assets_common_migrations.rs +++ /dev/null @@ -1,62 +0,0 @@ -// Copyright (C) Parity Technologies (UK) Ltd. -// SPDX-License-Identifier: Apache-2.0 - -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -//! Autogenerated weights for `assets_common_migrations` -//! -//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 38.0.0 -//! DATE: 2024-08-05, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]` -//! WORST CASE MAP SIZE: `1000000` -//! HOSTNAME: `Ciscos-MBP.lan`, CPU: `` -//! WASM-EXECUTION: `Compiled`, CHAIN: `None`, DB CACHE: `1024` - -// Executed Command: -// frame-omni-bencher -// v1 -// benchmark -// pallet -// --runtime -// target/release/wbuild/asset-hub-rococo-runtime/asset_hub_rococo_runtime.compact.compressed.wasm -// --pallet -// assets_common_migrations -// --extrinsic -// * -// --template -// substrate/.maintain/frame-weight-template.hbs -// --output -// cumulus/parachains/runtimes/assets/asset-hub-rococo/src/weights/assets_common_migrations.rs - -#![cfg_attr(rustfmt, rustfmt_skip)] -#![allow(unused_parens)] -#![allow(unused_imports)] -#![allow(missing_docs)] - -use frame_support::{traits::Get, weights::{Weight, constants::RocksDbWeight}}; -use core::marker::PhantomData; - -/// Weights for `assets_common_migrations` using the Substrate node and recommended hardware. -pub struct SubstrateWeight(PhantomData); -impl assets_common_migrations::foreign_assets_to_v4::WeightInfo for SubstrateWeight { - /// Storage: `ForeignAssets::Asset` (r:2 w:1) - /// Proof: `ForeignAssets::Asset` (`max_values`: None, `max_size`: Some(808), added: 3283, mode: `MaxEncodedLen`) - fn conversion_step() -> Weight { - // Proof Size summary in bytes: - // Measured: `161` - // Estimated: `7556` - // Minimum execution time: 6_000_000 picoseconds. - Weight::from_parts(7_000_000, 7556) - .saturating_add(T::DbWeight::get().reads(2_u64)) - .saturating_add(T::DbWeight::get().writes(1_u64)) - } -} diff --git a/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/weights/mod.rs b/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/weights/mod.rs index e43e1f4b3fc0..f20790cde39c 100644 --- a/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/weights/mod.rs +++ b/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/weights/mod.rs @@ -14,7 +14,6 @@ // You should have received a copy of the GNU General Public License // along with Cumulus. If not, see . -pub mod assets_common_migrations; pub mod block_weights; pub mod cumulus_pallet_parachain_system; pub mod cumulus_pallet_xcmp_queue; diff --git a/cumulus/parachains/runtimes/assets/asset-hub-westend/Cargo.toml b/cumulus/parachains/runtimes/assets/asset-hub-westend/Cargo.toml index 08ce19bcc938..2f244a07e8f1 100644 --- a/cumulus/parachains/runtimes/assets/asset-hub-westend/Cargo.toml +++ b/cumulus/parachains/runtimes/assets/asset-hub-westend/Cargo.toml @@ -44,7 +44,6 @@ pallet-transaction-payment = { workspace = true } pallet-transaction-payment-rpc-runtime-api = { workspace = true } pallet-uniques = { workspace = true } pallet-utility = { workspace = true } -pallet-migrations = { workspace = true } sp-api = { workspace = true } sp-block-builder = { workspace = true } sp-consensus-aura = { workspace = true } @@ -88,7 +87,6 @@ parachain-info = { workspace = true } parachains-common = { workspace = true } testnet-parachains-constants = { features = ["westend"], workspace = true } assets-common = { workspace = true } -assets-common-migrations = { workspace = true } # Bridges pallet-xcm-bridge-hub-router = { workspace = true } @@ -107,7 +105,6 @@ substrate-wasm-builder = { optional = true, workspace = true, default-features = [features] default = ["std"] runtime-benchmarks = [ - "assets-common-migrations/runtime-benchmarks", "assets-common/runtime-benchmarks", "cumulus-pallet-parachain-system/runtime-benchmarks", "cumulus-pallet-session-benchmarking/runtime-benchmarks", @@ -125,7 +122,6 @@ runtime-benchmarks = [ "pallet-balances/runtime-benchmarks", "pallet-collator-selection/runtime-benchmarks", "pallet-message-queue/runtime-benchmarks", - "pallet-migrations/runtime-benchmarks", "pallet-multisig/runtime-benchmarks", "pallet-nft-fractionalization/runtime-benchmarks", "pallet-nfts/runtime-benchmarks", @@ -165,7 +161,6 @@ try-runtime = [ "pallet-balances/try-runtime", "pallet-collator-selection/try-runtime", "pallet-message-queue/try-runtime", - "pallet-migrations/try-runtime", "pallet-multisig/try-runtime", "pallet-nft-fractionalization/try-runtime", "pallet-nfts/try-runtime", @@ -183,7 +178,6 @@ try-runtime = [ "sp-runtime/try-runtime", ] std = [ - "assets-common-migrations/std", "assets-common/std", "bp-asset-hub-rococo/std", "bp-asset-hub-westend/std", @@ -218,7 +212,6 @@ std = [ "pallet-balances/std", "pallet-collator-selection/std", "pallet-message-queue/std", - "pallet-migrations/std", "pallet-multisig/std", "pallet-nft-fractionalization/std", "pallet-nfts-runtime-api/std", diff --git a/cumulus/parachains/runtimes/assets/asset-hub-westend/src/lib.rs b/cumulus/parachains/runtimes/assets/asset-hub-westend/src/lib.rs index 544b550c2efa..ebbc000d1413 100644 --- a/cumulus/parachains/runtimes/assets/asset-hub-westend/src/lib.rs +++ b/cumulus/parachains/runtimes/assets/asset-hub-westend/src/lib.rs @@ -41,7 +41,6 @@ use frame_support::{ construct_runtime, derive_impl, dispatch::DispatchClass, genesis_builder_helper::{build_state, get_preset}, - migrations::FreezeChainOnFailedMigration, ord_parameter_types, parameter_types, traits::{ fungible, fungibles, @@ -179,36 +178,8 @@ impl frame_system::Config for Runtime { type SS58Prefix = SS58Prefix; type OnSetCode = cumulus_pallet_parachain_system::ParachainSetCode; type MaxConsumers = frame_support::traits::ConstU32<16>; - type SingleBlockMigrations = SingleBlockMigrations; - type MultiBlockMigrator = MultiBlockMigrator; } -// We destine 80% of the block's weight to MBMs. -parameter_types! { - pub MbmServiceWeight: Weight = Perbill::from_percent(80) * RuntimeBlockWeights::get().max_block; -} - -impl pallet_migrations::Config for Runtime { - type RuntimeEvent = RuntimeEvent; - #[cfg(not(feature = "runtime-benchmarks"))] - type Migrations = MultiBlockMigrations; - #[cfg(feature = "runtime-benchmarks")] - type Migrations = pallet_migrations::mock_helpers::MockedMigrations; - type CursorMaxLen = ConstU32<1024>; - type IdentifierMaxLen = ConstU32<256>; - type MigrationStatusHandler = (); - type FailedMigrationHandler = FreezeChainOnFailedMigration; - type MaxServiceWeight = MbmServiceWeight; - type WeightInfo = (); -} - -#[cfg(not(feature = "runtime-benchmarks"))] -type MultiBlockMigrations = assets_common_migrations::foreign_assets_to_v4::Migration< - Runtime, - ForeignAssetsInstance, - weights::assets_common_migrations::SubstrateWeight, ->; - impl pallet_timestamp::Config for Runtime { /// A timestamp: milliseconds since the unix epoch. type Moment = u64; @@ -975,7 +946,6 @@ construct_runtime!( // RandomnessCollectiveFlip = 2 removed Timestamp: pallet_timestamp = 3, ParachainInfo: parachain_info = 4, - MultiBlockMigrator: pallet_migrations = 5, // Monetary stuff. Balances: pallet_balances = 10, @@ -1049,7 +1019,7 @@ pub type UncheckedExtrinsic = generic::UncheckedExtrinsic; /// Migrations to apply on runtime upgrade. -pub type SingleBlockMigrations = ( +pub type Migrations = ( // v9420 pallet_nfts::migration::v1::MigrateToV1, // unreleased @@ -1176,7 +1146,7 @@ pub type Executive = frame_executive::Executive< frame_system::ChainContext, Runtime, AllPalletsWithSystem, - (), + Migrations, >; #[cfg(feature = "runtime-benchmarks")] @@ -1202,7 +1172,6 @@ mod benches { [cumulus_pallet_xcmp_queue, XcmpQueue] [pallet_xcm_bridge_hub_router, ToRococo] [pallet_asset_conversion_ops, AssetConversionMigration] - [assets_common_migrations, AssetsCommonMigrations] // XCM [pallet_xcm, PalletXcmExtrinsicsBenchmark::] // NOTE: Make sure you point to the individual modules below. @@ -1558,7 +1527,6 @@ impl_runtime_apis! { // are referenced in that call. type XcmBalances = pallet_xcm_benchmarks::fungible::Pallet::; type XcmGeneric = pallet_xcm_benchmarks::generic::Pallet::; - type AssetsCommonMigrations = assets_common_migrations::Pallet::; // Benchmark files generated for `Assets/ForeignAssets` instances are by default // `pallet_assets_assets.rs / pallet_assets_foreign_assets`, which is not really nice, @@ -1862,7 +1830,6 @@ impl_runtime_apis! { type XcmBalances = pallet_xcm_benchmarks::fungible::Pallet::; type XcmGeneric = pallet_xcm_benchmarks::generic::Pallet::; - type AssetsCommonMigrations = assets_common_migrations::Pallet::; type Local = pallet_assets::Pallet::; type Foreign = pallet_assets::Pallet::; diff --git a/cumulus/parachains/runtimes/assets/asset-hub-westend/src/weights/assets_common_migrations.rs b/cumulus/parachains/runtimes/assets/asset-hub-westend/src/weights/assets_common_migrations.rs deleted file mode 100644 index f6d95f33f2dc..000000000000 --- a/cumulus/parachains/runtimes/assets/asset-hub-westend/src/weights/assets_common_migrations.rs +++ /dev/null @@ -1,63 +0,0 @@ -// Copyright (C) Parity Technologies (UK) Ltd. -// This file is part of Cumulus. - -// Cumulus is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// Cumulus is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with Cumulus. If not, see . - -//! Autogenerated weights for `assets_common_migrations` -//! -//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 32.0.0 -//! DATE: 2024-08-07, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]` -//! WORST CASE MAP SIZE: `1000000` -//! HOSTNAME: `runner-696hpswk-project-674-concurrent-0`, CPU: `Intel(R) Xeon(R) CPU @ 2.60GHz` -//! WASM-EXECUTION: `Compiled`, CHAIN: `Some("asset-hub-westend-dev")`, DB CACHE: 1024 - -// Executed Command: -// target/production/polkadot-parachain -// benchmark -// pallet -// --steps=50 -// --repeat=20 -// --extrinsic=* -// --wasm-execution=compiled -// --heap-pages=4096 -// --json-file=/builds/parity/mirrors/polkadot-sdk/.git/.artifacts/bench.json -// --pallet=assets_common_migrations -// --chain=asset-hub-westend-dev -// --header=./cumulus/file_header.txt -// --output=./cumulus/parachains/runtimes/assets/asset-hub-westend/src/weights/ - -#![cfg_attr(rustfmt, rustfmt_skip)] -#![allow(unused_parens)] -#![allow(unused_imports)] -#![allow(missing_docs)] - -use frame_support::{traits::Get, weights::Weight}; -use core::marker::PhantomData; - -/// Weight functions for `assets_common_migrations`. -pub struct WeightInfo(PhantomData); -impl assets_common_migrations::WeightInfo for WeightInfo { - /// Storage: `ForeignAssets::Asset` (r:2 w:1) - /// Proof: `ForeignAssets::Asset` (`max_values`: None, `max_size`: Some(808), added: 3283, mode: `MaxEncodedLen`) - fn conversion_step() -> Weight { - // Proof Size summary in bytes: - // Measured: `243` - // Estimated: `7556` - // Minimum execution time: 12_296_000 picoseconds. - Weight::from_parts(12_590_000, 0) - .saturating_add(Weight::from_parts(0, 7556)) - .saturating_add(T::DbWeight::get().reads(2)) - .saturating_add(T::DbWeight::get().writes(1)) - } -} diff --git a/cumulus/parachains/runtimes/assets/asset-hub-westend/src/weights/mod.rs b/cumulus/parachains/runtimes/assets/asset-hub-westend/src/weights/mod.rs index 1dc3421228ca..4eebb1f8d786 100644 --- a/cumulus/parachains/runtimes/assets/asset-hub-westend/src/weights/mod.rs +++ b/cumulus/parachains/runtimes/assets/asset-hub-westend/src/weights/mod.rs @@ -13,7 +13,6 @@ // See the License for the specific language governing permissions and // limitations under the License. -pub mod assets_common_migrations; pub mod block_weights; pub mod cumulus_pallet_parachain_system; pub mod cumulus_pallet_xcmp_queue; diff --git a/cumulus/parachains/runtimes/assets/common/Cargo.toml b/cumulus/parachains/runtimes/assets/common/Cargo.toml index 2b42f0e5becc..c6740269339d 100644 --- a/cumulus/parachains/runtimes/assets/common/Cargo.toml +++ b/cumulus/parachains/runtimes/assets/common/Cargo.toml @@ -17,11 +17,8 @@ impl-trait-for-tuples = { workspace = true } # Substrate frame-support = { workspace = true } -frame-system = { workspace = true } sp-api = { workspace = true } sp-runtime = { workspace = true } -pallet-balances = { workspace = true } -pallet-assets = { workspace = true } pallet-asset-conversion = { workspace = true } # Polkadot @@ -34,9 +31,6 @@ xcm-executor = { workspace = true } parachains-common = { workspace = true } cumulus-primitives-core = { workspace = true } -[dev-dependencies] -sp-io = { workspace = true } - [build-dependencies] substrate-wasm-builder = { workspace = true, default-features = true } @@ -46,16 +40,12 @@ std = [ "codec/std", "cumulus-primitives-core/std", "frame-support/std", - "frame-system/std", "log/std", "pallet-asset-conversion/std", - "pallet-assets/std", - "pallet-balances/std", "pallet-xcm/std", "parachains-common/std", "scale-info/std", "sp-api/std", - "sp-io/std", "sp-runtime/std", "xcm-builder/std", "xcm-executor/std", @@ -65,10 +55,7 @@ std = [ runtime-benchmarks = [ "cumulus-primitives-core/runtime-benchmarks", "frame-support/runtime-benchmarks", - "frame-system/runtime-benchmarks", "pallet-asset-conversion/runtime-benchmarks", - "pallet-assets/runtime-benchmarks", - "pallet-balances/runtime-benchmarks", "pallet-xcm/runtime-benchmarks", "parachains-common/runtime-benchmarks", "sp-runtime/runtime-benchmarks", diff --git a/cumulus/parachains/runtimes/assets/migrations/Cargo.toml b/cumulus/parachains/runtimes/assets/migrations/Cargo.toml deleted file mode 100644 index 655a62c2c856..000000000000 --- a/cumulus/parachains/runtimes/assets/migrations/Cargo.toml +++ /dev/null @@ -1,60 +0,0 @@ -[package] -name = "assets-common-migrations" -version = "0.1.0" -authors.workspace = true -edition.workspace = true -description = "Common migrations for assets" -license = "Apache-2.0" - -[lints] -workspace = true - -[dependencies] -codec = { features = ["derive"], workspace = true } -scale-info = { features = ["derive"], workspace = true } -log = { workspace = true } - -# Substrate -frame-support = { workspace = true } -frame-system = { workspace = true } -frame-benchmarking = { optional = true, workspace = true } -sp-runtime = { workspace = true } -pallet-balances = { workspace = true } -pallet-assets = { workspace = true } -pallet-asset-conversion = { workspace = true } -pallet-migrations = { workspace = true } - -# Polkadot -xcm = { workspace = true } - -[dev-dependencies] -sp-io = { workspace = true } - -[features] -default = ["std"] -std = [ - "codec/std", - "frame-benchmarking?/std", - "frame-support/std", - "frame-system/std", - "log/std", - "pallet-asset-conversion/std", - "pallet-assets/std", - "pallet-balances/std", - "pallet-migrations/std", - "scale-info/std", - "sp-io/std", - "sp-runtime/std", - "xcm/std", -] - -runtime-benchmarks = [ - "frame-benchmarking/runtime-benchmarks", - "frame-support/runtime-benchmarks", - "frame-system/runtime-benchmarks", - "pallet-asset-conversion/runtime-benchmarks", - "pallet-assets/runtime-benchmarks", - "pallet-balances/runtime-benchmarks", - "pallet-migrations/runtime-benchmarks", - "sp-runtime/runtime-benchmarks", -] diff --git a/cumulus/parachains/runtimes/assets/migrations/src/foreign_assets_to_v4/benchmarks.rs b/cumulus/parachains/runtimes/assets/migrations/src/foreign_assets_to_v4/benchmarks.rs deleted file mode 100644 index 7c1f07a42c8c..000000000000 --- a/cumulus/parachains/runtimes/assets/migrations/src/foreign_assets_to_v4/benchmarks.rs +++ /dev/null @@ -1,71 +0,0 @@ -// Copyright (C) Parity Technologies (UK) Ltd. -// SPDX-License-Identifier: Apache-2.0 - -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -//! Benchmarks for the foreign assets migration. - -use frame_benchmarking::v2::*; -use pallet_assets::{Asset, AssetDetails, AssetStatus, Config}; -use xcm::{v3, v4}; - -use crate::{foreign_assets_to_v4::old::AssetDetailsOf, Pallet}; - -use super::{old, Migration}; - -#[instance_benchmarks( - // This is needed for the migration and could also be in its own "migration config": - where >::AssetId: From -)] -mod benches { - use super::*; - - #[benchmark] - fn conversion_step() { - let key = v3::Location::new(1, [v3::Junction::Parachain(2004)]); - let mock_asset_details = mock_asset_details::(); - old::Asset::::insert(key, mock_asset_details.clone()); - - #[block] - { - Migration::::conversion_step(None).unwrap(); - } - - let new_key: >::AssetId = - v4::Location::new(1, [v4::Junction::Parachain(2004)]).into(); - assert_eq!(Asset::::get(new_key), Some(mock_asset_details.clone())); - } - - impl_benchmark_test_suite!( - Pallet, - crate::foreign_assets_to_v4::tests::new_test_ext(), - crate::foreign_assets_to_v4::tests::Runtime - ); -} - -fn mock_asset_details, I: 'static>() -> AssetDetailsOf { - AssetDetails { - owner: whitelisted_caller(), - issuer: whitelisted_caller(), - admin: whitelisted_caller(), - freezer: whitelisted_caller(), - supply: Default::default(), - deposit: Default::default(), - min_balance: 1u32.into(), - is_sufficient: false, - accounts: Default::default(), - sufficients: Default::default(), - approvals: Default::default(), - status: AssetStatus::Live, - } -} diff --git a/cumulus/parachains/runtimes/assets/migrations/src/foreign_assets_to_v4/mod.rs b/cumulus/parachains/runtimes/assets/migrations/src/foreign_assets_to_v4/mod.rs deleted file mode 100644 index 2b53ac1bf556..000000000000 --- a/cumulus/parachains/runtimes/assets/migrations/src/foreign_assets_to_v4/mod.rs +++ /dev/null @@ -1,128 +0,0 @@ -// Copyright (C) Parity Technologies (UK) Ltd. -// SPDX-License-Identifier: Apache-2.0 - -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -//! V1 migration. -//! -//! This migration is meant to upgrade the XCM version of asset locations from V3 to V4. -//! It's only needed if the `AssetId` for this pallet is `VersionedLocation` - -#[cfg(test)] -mod tests; - -#[cfg(feature = "runtime-benchmarks")] -mod benchmarks; - -mod weights; -pub use weights::WeightInfo; - -use frame_support::{ - migrations::{MigrationId, SteppedMigration, SteppedMigrationError}, - pallet_prelude::PhantomData, - weights::WeightMeter, -}; -use pallet_assets::{Asset, Config}; -use xcm::{v3, v4}; - -pub const PALLET_MIGRATIONS_ID: &[u8; 13] = b"pallet-assets"; - -/// Storage aliases for on-chain storage types before running the migration. -pub mod old { - use super::{v3, Config}; - use frame_support::{storage_alias, Blake2_128Concat}; - use pallet_assets::{AssetDetails, DepositBalanceOf, Pallet}; - - pub type AssetDetailsOf = AssetDetails< - >::Balance, - ::AccountId, - DepositBalanceOf, - >; - - /// The storage item we are migrating from. - #[storage_alias] - pub(super) type Asset, I: 'static> = - StorageMap, Blake2_128Concat, v3::Location, AssetDetailsOf>; -} - -pub struct Migration(PhantomData<(T, I, W)>); -impl, I: 'static, W: weights::WeightInfo> SteppedMigration for Migration -where - >::AssetId: From, -{ - type Cursor = v3::Location; - type Identifier = MigrationId<13>; - - fn id() -> Self::Identifier { - MigrationId { pallet_id: *PALLET_MIGRATIONS_ID, version_from: 0, version_to: 1 } - } - - fn step( - mut cursor: Option, - meter: &mut WeightMeter, - ) -> Result, SteppedMigrationError> { - let required = W::conversion_step(); - if meter.remaining().any_lt(required) { - return Err(SteppedMigrationError::InsufficientWeight { required }); - } - - loop { - if meter.try_consume(required).is_err() { - break; - } - - cursor = Self::conversion_step(cursor); - - if cursor.is_none() { - break; - } - } - - Ok(cursor) - } -} - -impl, I: 'static, W> Migration -where - >::AssetId: From, -{ - pub fn conversion_step(cursor: Option) -> Option { - let mut iter = if let Some(last_key) = cursor { - // If a cursor is provided, start iterating from the value corresponding - // to the last key processed in the previous step of the migration. - old::Asset::::iter_from(old::Asset::::hashed_key_for(last_key)) - } else { - // If there is no cursor, start iterating from the beginning. - old::Asset::::iter() - }; - - if let Some((key, value)) = iter.next() { - // Most likely all locations will be able to be converted, but if they can't - // we log them to try again later. - let maybe_new_key: Result = key.try_into(); - if let Ok(new_key) = maybe_new_key { - old::Asset::::remove(&key); - let new_key: >::AssetId = new_key.into(); - Asset::::insert(&new_key, value); - log::trace!(target: "migration", "Successfully migrated key: {:?}", new_key); - } else { - log::warn!(target: "migration", "{:?} couldn't be converted to V4", key); - } - // Return the key as the new cursor to continue the migration. - Some(key) - } else { - // Signal the migration is complete. - None - } - } -} diff --git a/cumulus/parachains/runtimes/assets/migrations/src/foreign_assets_to_v4/tests.rs b/cumulus/parachains/runtimes/assets/migrations/src/foreign_assets_to_v4/tests.rs deleted file mode 100644 index 84a08664eccd..000000000000 --- a/cumulus/parachains/runtimes/assets/migrations/src/foreign_assets_to_v4/tests.rs +++ /dev/null @@ -1,159 +0,0 @@ -// Copyright (C) Parity Technologies (UK) Ltd. -// SPDX-License-Identifier: Apache-2.0 - -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -//! Tests for the foreign assets migration. - -use frame_support::{ - construct_runtime, derive_impl, - migrations::SteppedMigration, - parameter_types, - traits::{AsEnsureOriginWithArg, OnRuntimeUpgrade}, - weights::{Weight, WeightMeter}, -}; -use frame_system::{EnsureRoot, EnsureSigned}; -use pallet_assets::{Asset, AssetDetails, AssetStatus}; -use sp_io::TestExternalities; -use sp_runtime::BuildStorage; -use xcm::{v3, v4}; - -use super::{old, weights, Migration}; - -construct_runtime! { - pub struct Runtime { - System: frame_system, - Balances: pallet_balances, - ForeignAssets: pallet_assets, - Migrations: pallet_migrations, - } -} - -type Block = frame_system::mocking::MockBlock; -type AccountId = u64; -type Balance = u64; - -#[derive_impl(frame_system::config_preludes::TestDefaultConfig)] -impl frame_system::Config for Runtime { - type Block = Block; - type AccountId = AccountId; - type AccountData = pallet_balances::AccountData; - type MultiBlockMigrator = Migrations; -} - -parameter_types! { - pub storage MigratorServiceWeight: Weight = Weight::from_parts(100, 100); // do not use in prod -} - -#[derive_impl(pallet_migrations::config_preludes::TestDefaultConfig)] -impl pallet_migrations::Config for Runtime { - #[cfg(not(feature = "runtime-benchmarks"))] - type Migrations = ( - crate::foreign_assets_to_v4::Migration< - Runtime, - (), - crate::foreign_assets_to_v4::weights::SubstrateWeight, - >, - ); - #[cfg(feature = "runtime-benchmarks")] - type Migrations = pallet_migrations::mock_helpers::MockedMigrations; - type MaxServiceWeight = MigratorServiceWeight; -} - -#[derive_impl(pallet_balances::config_preludes::TestDefaultConfig)] -impl pallet_balances::Config for Runtime { - type AccountStore = System; - type Balance = Balance; -} - -#[derive_impl(pallet_assets::config_preludes::TestDefaultConfig)] -impl pallet_assets::Config for Runtime { - type AssetId = v4::Location; - type AssetIdParameter = v4::Location; - type Balance = Balance; - type Currency = Balances; - type CreateOrigin = AsEnsureOriginWithArg>; - type ForceOrigin = EnsureRoot; - type Freezer = (); - #[cfg(feature = "runtime-benchmarks")] - type BenchmarkHelper = XcmBenchmarkHelper; -} - -/// Simple conversion of `u32` into an `AssetId` for use in benchmarking. -#[cfg(feature = "runtime-benchmarks")] -pub struct XcmBenchmarkHelper; -#[cfg(feature = "runtime-benchmarks")] -impl pallet_assets::BenchmarkHelper for XcmBenchmarkHelper { - fn create_asset_id_parameter(id: u32) -> v4::Location { - v4::Location::new(1, [v4::Junction::Parachain(id)]) - } -} - -pub(crate) fn new_test_ext() -> TestExternalities { - let mut t = frame_system::GenesisConfig::::default().build_storage().unwrap(); - - let test_account = 1; - let initial_balance = 1000; - pallet_balances::GenesisConfig:: { balances: vec![(test_account, initial_balance)] } - .assimilate_storage(&mut t) - .unwrap(); - - t.into() -} - -#[test] -fn migration_works() { - new_test_ext().execute_with(|| { - let mock_asset_details = mock_asset_details(); - - // Insert a bunch of items in the old map. - for i in 0..1024 { - let key = v3::Location::new(1, [v3::Junction::Parachain(2004), v3::Junction::PalletInstance(50), v3::Junction::GeneralIndex(i)]); - old::Asset::::insert(key, mock_asset_details.clone()); - } - - // Give the migration some limit. - let limit = <::WeightInfo as pallet_migrations::WeightInfo>::progress_mbms_none() + - pallet_migrations::Pallet::::exec_migration_max_weight() + - as weights::WeightInfo>::conversion_step() * 16; - MigratorServiceWeight::set(&limit); - - System::set_block_number(1); - AllPalletsWithSystem::on_runtime_upgrade(); // onboard MBMs - - // Perform one step of the migration. - assert!(Migration::::step(None, &mut WeightMeter::new()).unwrap().is_none()); - - for i in 0..1024 { - let new_key = v4::Location::new(1, [v4::Junction::Parachain(2004), v4::Junction::PalletInstance(50), v4::Junction::GeneralIndex(i)]); - assert_eq!(Asset::::get(new_key), Some(mock_asset_details.clone())); - } - }) -} - -fn mock_asset_details() -> AssetDetails { - AssetDetails { - owner: 0, - issuer: 0, - admin: 0, - freezer: 0, - supply: Default::default(), - deposit: Default::default(), - min_balance: 1u32.into(), - is_sufficient: false, - accounts: Default::default(), - sufficients: Default::default(), - approvals: Default::default(), - status: AssetStatus::Live, - } -} diff --git a/cumulus/parachains/runtimes/assets/migrations/src/foreign_assets_to_v4/weights.rs b/cumulus/parachains/runtimes/assets/migrations/src/foreign_assets_to_v4/weights.rs deleted file mode 100644 index 8926b443f249..000000000000 --- a/cumulus/parachains/runtimes/assets/migrations/src/foreign_assets_to_v4/weights.rs +++ /dev/null @@ -1,83 +0,0 @@ -// Copyright (C) Parity Technologies (UK) Ltd. -// This file is part of Polkadot. - -// Polkadot is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// Polkadot is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with Polkadot. If not, see . - -//! Autogenerated weights for `assets_common_migrations` -//! -//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 38.0.0 -//! DATE: 2024-08-01, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]` -//! WORST CASE MAP SIZE: `1000000` -//! HOSTNAME: `Ciscos-MBP.lan`, CPU: `` -//! WASM-EXECUTION: `Compiled`, CHAIN: `None`, DB CACHE: `1024` - -// Executed Command: -// frame-omni-bencher -// v1 -// benchmark -// pallet -// --runtime -// target/release/wbuild/kitchensink-runtime/kitchensink_runtime.compact.compressed.wasm -// --pallet -// assets_common_migrations -// --extrinsic -// * -// --template -// substrate/.maintain/frame-weight-template.hbs -// --output -// cumulus/parachains/runtimes/assets/migrations/src/v1/weights.rs - -#![cfg_attr(rustfmt, rustfmt_skip)] -#![allow(unused_parens)] -#![allow(unused_imports)] -#![allow(missing_docs)] - -use frame_support::{traits::Get, weights::{Weight, constants::RocksDbWeight}}; -use core::marker::PhantomData; - -/// Weight functions needed for `assets_common_migrations`. -pub trait WeightInfo { - fn conversion_step() -> Weight; -} - -/// Weights for `assets_common_migrations` using the Substrate node and recommended hardware. -pub struct SubstrateWeight(PhantomData); -impl WeightInfo for SubstrateWeight { - /// Storage: `ForeignAssets::Asset` (r:2 w:1) - /// Proof: `ForeignAssets::Asset` (`max_values`: None, `max_size`: Some(808), added: 3283, mode: `MaxEncodedLen`) - fn conversion_step() -> Weight { - // Proof Size summary in bytes: - // Measured: `161` - // Estimated: `7556` - // Minimum execution time: 12_000_000 picoseconds. - Weight::from_parts(14_000_000, 7556) - .saturating_add(T::DbWeight::get().reads(2_u64)) - .saturating_add(T::DbWeight::get().writes(1_u64)) - } -} - -// For backwards compatibility and tests. -impl WeightInfo for () { - /// Storage: `ForeignAssets::Asset` (r:2 w:1) - /// Proof: `ForeignAssets::Asset` (`max_values`: None, `max_size`: Some(808), added: 3283, mode: `MaxEncodedLen`) - fn conversion_step() -> Weight { - // Proof Size summary in bytes: - // Measured: `161` - // Estimated: `7556` - // Minimum execution time: 12_000_000 picoseconds. - Weight::from_parts(14_000_000, 7556) - .saturating_add(RocksDbWeight::get().reads(2_u64)) - .saturating_add(RocksDbWeight::get().writes(1_u64)) - } -} diff --git a/cumulus/parachains/runtimes/assets/migrations/src/lib.rs b/cumulus/parachains/runtimes/assets/migrations/src/lib.rs deleted file mode 100644 index aae31d7afb65..000000000000 --- a/cumulus/parachains/runtimes/assets/migrations/src/lib.rs +++ /dev/null @@ -1,32 +0,0 @@ -// Copyright (C) Parity Technologies (UK) Ltd. -// SPDX-License-Identifier: Apache-2.0 - -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -//! A utility pallet for migrating storage items in the asset hub runtimes. -//! It's only a pallet since the benchmarking machinery requires it. - -#![cfg_attr(not(feature = "std"), no_std)] - -pub mod foreign_assets_to_v4; - -pub use pallet::*; - -#[frame_support::pallet] -pub mod pallet { - #[pallet::pallet] - pub struct Pallet(_); - - #[pallet::config] - pub trait Config: frame_system::Config {} -} diff --git a/substrate/frame/assets/src/lib.rs b/substrate/frame/assets/src/lib.rs index 533109d4f97a..e9b9a7b1e3cc 100644 --- a/substrate/frame/assets/src/lib.rs +++ b/substrate/frame/assets/src/lib.rs @@ -414,7 +414,7 @@ pub mod pallet { #[pallet::storage] /// Details of an asset. - pub type Asset, I: 'static = ()> = StorageMap< + pub(super) type Asset, I: 'static = ()> = StorageMap< _, Blake2_128Concat, T::AssetId, diff --git a/substrate/frame/assets/src/types.rs b/substrate/frame/assets/src/types.rs index 613e7eb53996..11edc7d3fcb5 100644 --- a/substrate/frame/assets/src/types.rs +++ b/substrate/frame/assets/src/types.rs @@ -24,7 +24,7 @@ use frame_support::{ }; use sp_runtime::{traits::Convert, FixedPointNumber, FixedU128}; -pub type DepositBalanceOf = +pub(super) type DepositBalanceOf = <>::Currency as Currency<::AccountId>>::Balance; pub(super) type AssetAccountOf = AssetAccount< >::Balance, @@ -38,7 +38,7 @@ pub(super) type ExistenceReasonOf = /// AssetStatus holds the current state of the asset. It could either be Live and available for use, /// or in a Destroying state. #[derive(Clone, Encode, Decode, Eq, PartialEq, RuntimeDebug, MaxEncodedLen, TypeInfo)] -pub enum AssetStatus { +pub(super) enum AssetStatus { /// The asset is active and able to be used. Live, /// Whether the asset is frozen for non-admin transfers. @@ -51,30 +51,30 @@ pub enum AssetStatus { #[derive(Clone, Encode, Decode, Eq, PartialEq, RuntimeDebug, MaxEncodedLen, TypeInfo)] pub struct AssetDetails { /// Can change `owner`, `issuer`, `freezer` and `admin` accounts. - pub owner: AccountId, + pub(super) owner: AccountId, /// Can mint tokens. - pub issuer: AccountId, + pub(super) issuer: AccountId, /// Can thaw tokens, force transfers and burn tokens from any account. - pub admin: AccountId, + pub(super) admin: AccountId, /// Can freeze tokens. - pub freezer: AccountId, + pub(super) freezer: AccountId, /// The total supply across all accounts. - pub supply: Balance, + pub(super) supply: Balance, /// The balance deposited for this asset. This pays for the data stored here. - pub deposit: DepositBalance, + pub(super) deposit: DepositBalance, /// The ED for virtual accounts. - pub min_balance: Balance, + pub(super) min_balance: Balance, /// If `true`, then any account with this asset is given a provider reference. Otherwise, it /// requires a consumer reference. - pub is_sufficient: bool, + pub(super) is_sufficient: bool, /// The total number of accounts. - pub accounts: u32, + pub(super) accounts: u32, /// The total number of accounts for which we have placed a self-sufficient reference. - pub sufficients: u32, + pub(super) sufficients: u32, /// The total number of approvals. - pub approvals: u32, + pub(super) approvals: u32, /// The status of the asset - pub status: AssetStatus, + pub(super) status: AssetStatus, } /// Data concerning an approval. diff --git a/umbrella/Cargo.toml b/umbrella/Cargo.toml index 1ebf84ebabb3..8d85e26d8fe7 100644 --- a/umbrella/Cargo.toml +++ b/umbrella/Cargo.toml @@ -8,7 +8,6 @@ license = "Apache-2.0" default = ["std"] std = [ "asset-test-utils?/std", - "assets-common-migrations?/std", "assets-common?/std", "binary-merkle-tree?/std", "bp-asset-hub-rococo?/std", @@ -244,7 +243,6 @@ std = [ "xcm-runtime-apis?/std", ] runtime-benchmarks = [ - "assets-common-migrations?/runtime-benchmarks", "assets-common?/runtime-benchmarks", "bridge-hub-common?/runtime-benchmarks", "bridge-runtime-common?/runtime-benchmarks", @@ -544,7 +542,6 @@ with-tracing = [ ] runtime = [ "assets-common", - "assets-common-migrations", "binary-merkle-tree", "bp-asset-hub-rococo", "bp-asset-hub-westend", @@ -801,11 +798,6 @@ path = "../cumulus/parachains/runtimes/assets/common" default-features = false optional = true -[dependencies.assets-common-migrations] -path = "../cumulus/parachains/runtimes/assets/migrations" -default-features = false -optional = true - [dependencies.binary-merkle-tree] path = "../substrate/utils/binary-merkle-tree" default-features = false diff --git a/umbrella/src/lib.rs b/umbrella/src/lib.rs index 54713a34f4b8..58a5691961d9 100644 --- a/umbrella/src/lib.rs +++ b/umbrella/src/lib.rs @@ -19,10 +19,6 @@ pub use asset_test_utils; #[cfg(feature = "assets-common")] pub use assets_common; -/// Common migrations for assets. -#[cfg(feature = "assets-common-migrations")] -pub use assets_common_migrations; - /// A no-std/Substrate compatible library to construct binary merkle tree. #[cfg(feature = "binary-merkle-tree")] pub use binary_merkle_tree; From f5a3eb540353f1001ce514773bc96ce46ebfb8d6 Mon Sep 17 00:00:00 2001 From: Francisco Aguirre Date: Thu, 8 Aug 2024 19:55:29 +0200 Subject: [PATCH 31/32] doc(prdoc): update now that there's no data migration --- prdoc/pr_4129.prdoc | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/prdoc/pr_4129.prdoc b/prdoc/pr_4129.prdoc index 9e174cf4b35a..eb5ca6021a80 100644 --- a/prdoc/pr_4129.prdoc +++ b/prdoc/pr_4129.prdoc @@ -1,21 +1,15 @@ # Schema: Polkadot SDK PRDoc Schema (prdoc) v1.0.0 # See doc at https://raw.githubusercontent.com/paritytech/polkadot-sdk/master/prdoc/schema_user.json -title: Migrate ForeignAssets from xcm::v3::Location to xcm::v4::Location +title: Update ForeignAssets from xcm::v3::Location to xcm::v4::Location doc: - audience: Runtime Dev description: | - There's a new migration, under the new crate `assets-common-migrations`, that migrates foreign assets - from xcm::v3::Location to xcm::v4::Location. - This simplifies a lot of code converting v3 to v4 in tests. - It was the missing step from v4 and is a stepping stone for XCMv5. - This is a multi-block migration (MBM), so when executed, it will potentially take some blocks to execute. - The setup for MBMs was done for asset-hub-rococo and asset-hub-westend. + As a stepping stone for XCMv5, the foreign asset ids have been updated from v3::Location to v4::Location. - audience: Runtime User description: | - There's now a migration for foreign assets from XCMv3 to XCMv4. - The underlying assets are still the same. + As a stepping stone for XCMv5, the foreign asset ids have been updated from v3::Location to v4::Location. crates: - name: asset-hub-rococo-runtime From ae7e32671e70805f1dbda50c5e8726657eba5be4 Mon Sep 17 00:00:00 2001 From: Francisco Aguirre Date: Tue, 13 Aug 2024 16:12:14 +0200 Subject: [PATCH 32/32] chore: feedback --- .../emulated/tests/bridges/bridge-hub-rococo/src/lib.rs | 2 +- .../tests/bridges/bridge-hub-rococo/src/tests/send_xcm.rs | 2 +- .../parachains/runtimes/assets/asset-hub-rococo/src/lib.rs | 1 - prdoc/pr_4129.prdoc | 7 +++---- 4 files changed, 5 insertions(+), 7 deletions(-) diff --git a/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-rococo/src/lib.rs b/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-rococo/src/lib.rs index cae2b15d11c3..0aefe5b6352c 100644 --- a/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-rococo/src/lib.rs +++ b/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-rococo/src/lib.rs @@ -23,8 +23,8 @@ mod imports { pub use xcm::{ latest::ParentThen, prelude::{AccountId32 as AccountId32Junction, *}, - v3::NetworkId::Westend as WestendId, v4, + v4::NetworkId::Westend as WestendId, }; pub use xcm_executor::traits::TransferType; diff --git a/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-rococo/src/tests/send_xcm.rs b/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-rococo/src/tests/send_xcm.rs index 652447fa5601..3f2038b4bdd1 100644 --- a/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-rococo/src/tests/send_xcm.rs +++ b/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-rococo/src/tests/send_xcm.rs @@ -29,7 +29,7 @@ fn send_xcm_from_rococo_relay_to_westend_asset_hub_should_fail_on_not_applicable let xcm = VersionedXcm::from(Xcm(vec![ UnpaidExecution { weight_limit, check_origin }, ExportMessage { - network: WestendId.into(), + network: WestendId, destination: [Parachain(AssetHubWestend::para_id().into())].into(), xcm: remote_xcm, }, diff --git a/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/lib.rs b/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/lib.rs index accbdcd5b132..4c7356707ab6 100644 --- a/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/lib.rs +++ b/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/lib.rs @@ -1023,7 +1023,6 @@ pub type UncheckedExtrinsic = generic::UncheckedExtrinsic; /// Migrations to apply on runtime upgrade. pub type Migrations = ( - pallet_collator_selection::migration::v1::MigrateToV1, InitStorageVersions, // unreleased cumulus_pallet_xcmp_queue::migration::v4::MigrationToV4, diff --git a/prdoc/pr_4129.prdoc b/prdoc/pr_4129.prdoc index eb5ca6021a80..dfcc9b9ef030 100644 --- a/prdoc/pr_4129.prdoc +++ b/prdoc/pr_4129.prdoc @@ -4,10 +4,9 @@ title: Update ForeignAssets from xcm::v3::Location to xcm::v4::Location doc: - - audience: Runtime Dev - description: | - As a stepping stone for XCMv5, the foreign asset ids have been updated from v3::Location to v4::Location. - - audience: Runtime User + - audience: + - Runtime Dev + - Runtime User description: | As a stepping stone for XCMv5, the foreign asset ids have been updated from v3::Location to v4::Location.