From 5f65c111e7be868615c57286c994b726fa812fd8 Mon Sep 17 00:00:00 2001 From: muharem Date: Fri, 20 Dec 2024 19:29:02 +0100 Subject: [PATCH 01/10] accounts migration --- Cargo.lock | 53 +++ Cargo.toml | 7 + pallets/ah-migrator/Cargo.toml | 83 ++++ pallets/ah-migrator/src/lib.rs | 176 ++++++++ pallets/ah-migrator/src/types.rs | 27 ++ pallets/rc-migrator/Cargo.toml | 70 +++ pallets/rc-migrator/src/accounts.rs | 417 ++++++++++++++++++ pallets/rc-migrator/src/lib.rs | 211 +++++++++ pallets/rc-migrator/src/types.rs | 57 +++ pallets/rc-migrator/src/weights.rs | 28 ++ relay/polkadot/Cargo.toml | 12 + relay/polkadot/src/lib.rs | 22 +- relay/polkadot/tests/ahm/accounts.rs | 29 ++ relay/polkadot/tests/ahm/mod.rs | 47 ++ relay/polkadot/tests/mod.rs | 17 + .../asset-hubs/asset-hub-polkadot/Cargo.toml | 12 + .../asset-hubs/asset-hub-polkadot/src/lib.rs | 47 +- .../asset-hub-polkadot/src/migration.rs | 56 +++ .../asset-hub-polkadot/src/xcm_config.rs | 3 +- 19 files changed, 1365 insertions(+), 9 deletions(-) create mode 100644 pallets/ah-migrator/Cargo.toml create mode 100644 pallets/ah-migrator/src/lib.rs create mode 100644 pallets/ah-migrator/src/types.rs create mode 100644 pallets/rc-migrator/Cargo.toml create mode 100644 pallets/rc-migrator/src/accounts.rs create mode 100644 pallets/rc-migrator/src/lib.rs create mode 100644 pallets/rc-migrator/src/types.rs create mode 100644 pallets/rc-migrator/src/weights.rs create mode 100644 relay/polkadot/tests/ahm/accounts.rs create mode 100644 relay/polkadot/tests/ahm/mod.rs create mode 100644 relay/polkadot/tests/mod.rs create mode 100644 system-parachains/asset-hubs/asset-hub-polkadot/src/migration.rs diff --git a/Cargo.lock b/Cargo.lock index a5789d7b41..ab2ae65a15 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -782,6 +782,7 @@ dependencies = [ "hex-literal", "kusama-runtime-constants", "log", + "pallet-ah-migrator", "pallet-asset-conversion", "pallet-asset-conversion-tx-payment", "pallet-assets", @@ -793,6 +794,7 @@ dependencies = [ "pallet-multisig", "pallet-nfts", "pallet-nfts-runtime-api", + "pallet-preimage", "pallet-proxy", "pallet-session", "pallet-timestamp", @@ -7610,6 +7612,32 @@ version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b15813163c1d831bf4a13c3610c05c0d03b39feb07f7e09fa234dac9b15aaf39" +[[package]] +name = "pallet-ah-migrator" +version = "0.1.0" +dependencies = [ + "frame-benchmarking", + "frame-support", + "frame-system", + "log", + "pallet-balances", + "pallet-nomination-pools", + "pallet-preimage", + "pallet-rc-migrator", + "pallet-staking", + "pallet-state-trie-migration", + "parity-scale-codec", + "polkadot-parachain-primitives", + "polkadot-runtime-common", + "polkadot-runtime-parachains", + "scale-info", + "serde", + "sp-core 34.0.0", + "sp-io 37.0.0", + "sp-runtime 38.0.0", + "sp-std", +] + [[package]] name = "pallet-alliance" version = "35.0.0" @@ -8850,6 +8878,29 @@ dependencies = [ "sp-std", ] +[[package]] +name = "pallet-rc-migrator" +version = "0.1.0" +dependencies = [ + "frame-benchmarking", + "frame-support", + "frame-system", + "log", + "pallet-balances", + "pallet-staking", + "parity-scale-codec", + "polkadot-parachain-primitives", + "polkadot-runtime-common", + "polkadot-runtime-parachains", + "scale-info", + "serde", + "sp-core 34.0.0", + "sp-io 37.0.0", + "sp-runtime 38.0.0", + "sp-std", + "staging-xcm", +] + [[package]] name = "pallet-recovery" version = "36.0.0" @@ -10083,6 +10134,7 @@ dependencies = [ "frame-try-runtime", "hex-literal", "log", + "pallet-ah-migrator", "pallet-asset-rate", "pallet-authority-discovery", "pallet-authorship", @@ -10111,6 +10163,7 @@ dependencies = [ "pallet-parameters", "pallet-preimage", "pallet-proxy", + "pallet-rc-migrator", "pallet-referenda", "pallet-scheduler", "pallet-session", diff --git a/Cargo.toml b/Cargo.toml index e96581a7b1..ab8c3fcdc4 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -6,6 +6,12 @@ repository = "https://github.com/polkadot-fellows/runtimes.git" license = "GPL-3.0-only" # TODO [workspace.dependencies] + +# Asset Hub Migration concerning deps +pallet-rc-migrator = { path = "pallets/rc-migrator", default-features = false } +pallet-ah-migrator = { path = "pallets/ah-migrator", default-features = false } +# End: Asset Hub Migration concerning deps + assert_matches = { version = "1.5.0" } approx = { version = "0.5.1" } asset-hub-kusama-emulated-chain = { path = "integration-tests/emulated/chains/parachains/assets/asset-hub-kusama" } @@ -281,6 +287,7 @@ members = [ "integration-tests/emulated/tests/people/people-kusama", "integration-tests/emulated/tests/people/people-polkadot", "integration-tests/zombienet", + "pallets/rc-migrator", "relay/common", "relay/kusama", "relay/kusama/constants", diff --git a/pallets/ah-migrator/Cargo.toml b/pallets/ah-migrator/Cargo.toml new file mode 100644 index 0000000000..61f03854fb --- /dev/null +++ b/pallets/ah-migrator/Cargo.toml @@ -0,0 +1,83 @@ +[package] +name = "pallet-ah-migrator" +description = "Asset Hub migrator pallet for Asset Hub" +license = "Apache-2.0" +version = "0.1.0" +edition.workspace = true +authors.workspace = true +repository.workspace = true + +[dependencies] +codec = { workspace = true, features = ["max-encoded-len"] } +scale-info = { workspace = true, features = ["derive"] } +serde = { features = ["derive"], optional = true, workspace = true } +log = { workspace = true } + +frame-benchmarking = { workspace = true, optional = true } +frame-support = { workspace = true } +frame-system = { workspace = true } +sp-core = { workspace = true } +sp-runtime = { workspace = true } +sp-std = { workspace = true } +sp-io = { workspace = true } + +pallet-rc-migrator = { workspace = true } +pallet-balances = { workspace = true } +pallet-staking = { workspace = true } +pallet-preimage = { workspace = true } +pallet-state-trie-migration = { workspace = true } +pallet-nomination-pools = { workspace = true } + +polkadot-runtime-common = { workspace = true } +runtime-parachains = { workspace = true } +polkadot-parachain-primitives = { workspace = true } + +[features] +default = ["std"] +std = [ + "codec/std", + "frame-benchmarking?/std", + "frame-support/std", + "frame-system/std", + "scale-info/std", + "serde", + "sp-core/std", + "sp-runtime/std", + "sp-std/std", + "sp-io/std", + "pallet-rc-migrator/std", + "pallet-balances/std", + "pallet-staking/std", + "pallet-preimage/std", + "pallet-state-trie-migration/std", + "pallet-nomination-pools/std", + "polkadot-runtime-common/std", + "runtime-parachains/std", +] +runtime-benchmarks = [ + "frame-benchmarking/runtime-benchmarks", + "frame-support/runtime-benchmarks", + "frame-system/runtime-benchmarks", + "sp-runtime/runtime-benchmarks", + "pallet-rc-migrator/runtime-benchmarks", + "pallet-balances/runtime-benchmarks", + "pallet-staking/runtime-benchmarks", + "pallet-preimage/runtime-benchmarks", + "pallet-state-trie-migration/runtime-benchmarks", + "pallet-nomination-pools/runtime-benchmarks", + "polkadot-runtime-common/runtime-benchmarks", + "runtime-parachains/runtime-benchmarks", +] +try-runtime = [ + "frame-support/try-runtime", + "frame-system/try-runtime", + "sp-runtime/try-runtime", + "pallet-rc-migrator/try-runtime", + "pallet-balances/try-runtime", + "pallet-staking/try-runtime", + "pallet-preimage/try-runtime", + "pallet-state-trie-migration/try-runtime", + "pallet-nomination-pools/try-runtime", + "polkadot-runtime-common/try-runtime", + "runtime-parachains/try-runtime", +] diff --git a/pallets/ah-migrator/src/lib.rs b/pallets/ah-migrator/src/lib.rs new file mode 100644 index 0000000000..f725a75632 --- /dev/null +++ b/pallets/ah-migrator/src/lib.rs @@ -0,0 +1,176 @@ +// 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. + +//! The helper pallet for the Asset Hub migration. + +#![cfg_attr(not(feature = "std"), no_std)] + +pub mod types; +pub use pallet::*; + +use frame_support::{ + pallet_prelude::*, + traits::{ + fungible::{InspectFreeze, Mutate, MutateFreeze, MutateHold}, + LockableCurrency, ReservableCurrency, WithdrawReasons as LockWithdrawReasons, + }, +}; +use frame_system::pallet_prelude::*; +use pallet_balances::{AccountData, Reasons as LockReasons}; +use pallet_rc_migrator::accounts::Account as RcAccount; +use sp_runtime::AccountId32; +use sp_std::prelude::*; + +/// The log target of this pallet. +pub const LOG_TARGET: &str = "runtime::ah-migrator"; + +#[frame_support::pallet(dev_mode)] +pub mod pallet { + use sp_runtime::traits::Convert; + + use super::*; + + /// Super trait of all pallets the migration depends on. + #[pallet::config] + pub trait Config: + frame_system::Config, AccountId = AccountId32> + + pallet_balances::Config + { + /// The overarching event type. + type RuntimeEvent: From> + IsType<::RuntimeEvent>; + /// Native asset registry type. + type Currency: Mutate + + MutateHold + + InspectFreeze + + MutateFreeze + + ReservableCurrency + + LockableCurrency; + /// XCM check account. + type CheckingAccount: Get; + /// Relay Chain Hold Reasons. + type RcHoldReason: Parameter; + /// Relay Chain Freeze Reasons. + type RcFreezeReason: Parameter; + /// Relay Chain to Asset Hub Hold Reasons mapping; + type RcToAhHoldReason: Convert; + /// Relay Chain to Asset Hub Freeze Reasons mapping; + type RcToAhFreezeReason: Convert; + } + + #[pallet::error] + pub enum Error { + /// TODO + TODO, + } + + #[pallet::event] + #[pallet::generate_deposit(pub(crate) fn deposit_event)] + pub enum Event { + /// TODO + TODO, + } + + #[pallet::pallet] + pub struct Pallet(_); + + #[pallet::call] + impl Pallet { + // TODO: Currently, we use `debug_assert!` for basic test checks against a production + // snapshot. + + /// Receive accounts from the Relay Chain. + /// + /// The accounts that sent with `pallet_rc_migrator::Pallet::migrate_accounts` function. + #[pallet::call_index(0)] + #[pallet::weight({1})] + pub fn receive_accounts( + origin: OriginFor, + accounts: Vec>, + ) -> DispatchResultWithPostInfo { + ensure_root(origin)?; + + for account in accounts { + let who = account.who; + let total_balance = account.free + account.reserved; + let minted = T::Currency::mint_into(&who, total_balance) + // TODO handle error + .unwrap(); + debug_assert!(minted == total_balance); + + for hold in account.holds { + let _ = T::Currency::hold( + &T::RcToAhHoldReason::convert(hold.id), + &who, + hold.amount, + ) + // TODO handle error + .unwrap(); + } + + let _ = T::Currency::reserve(&who, account.unnamed_reserve) + // TODO handle error + .unwrap(); + + for freeze in account.freezes { + let _ = T::Currency::set_freeze( + &T::RcToAhFreezeReason::convert(freeze.id), + &who, + freeze.amount, + ) + // TODO handle error + .unwrap(); + } + + for lock in account.locks { + T::Currency::set_lock( + lock.id, + &who, + lock.amount, + types::map_lock_reason(lock.reasons), + ); + } + + let storage_account = pallet_balances::Account::::get(&who); + debug_assert!(storage_account.free == account.free); + debug_assert!(storage_account.frozen == account.frozen); + debug_assert!(storage_account.reserved == account.reserved); + + (0..account.consumers).for_each(|_| { + frame_system::Pallet::::inc_consumers(&who) + // TODO handle error + .unwrap(); + }); + (0..account.providers).for_each(|_| { + frame_system::Pallet::::inc_providers(&who); + }); + + // TODO: publish event + } + + // TODO: publish event + + Ok(().into()) + } + } + + #[pallet::hooks] + impl Hooks> for Pallet { + fn on_initialize(_: BlockNumberFor) -> Weight { + Weight::zero() + } + } +} diff --git a/pallets/ah-migrator/src/types.rs b/pallets/ah-migrator/src/types.rs new file mode 100644 index 0000000000..ee2eda2f34 --- /dev/null +++ b/pallets/ah-migrator/src/types.rs @@ -0,0 +1,27 @@ +// 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. + +use super::*; + +/// Backward mapping from https://github.com/paritytech/polkadot-sdk/blob/74a5e1a242274ddaadac1feb3990fc95c8612079/substrate/frame/balances/src/types.rs#L38 +pub fn map_lock_reason(reasons: LockReasons) -> LockWithdrawReasons { + match reasons { + LockReasons::All => LockWithdrawReasons::TRANSACTION_PAYMENT | LockWithdrawReasons::RESERVE, + LockReasons::Fee => LockWithdrawReasons::TRANSACTION_PAYMENT, + LockReasons::Misc => LockWithdrawReasons::TIP, + } +} diff --git a/pallets/rc-migrator/Cargo.toml b/pallets/rc-migrator/Cargo.toml new file mode 100644 index 0000000000..a57cdf7905 --- /dev/null +++ b/pallets/rc-migrator/Cargo.toml @@ -0,0 +1,70 @@ +[package] +name = "pallet-rc-migrator" +description = "Asset Hub migrator pallet for Relay Chain" +license = "Apache-2.0" +version = "0.1.0" +edition.workspace = true +authors.workspace = true +repository.workspace = true + +[dependencies] +codec = { workspace = true, features = ["max-encoded-len"] } +scale-info = { workspace = true, features = ["derive"] } +serde = { features = ["derive"], optional = true, workspace = true } +log = { workspace = true } + +frame-benchmarking = { workspace = true, optional = true } +frame-support = { workspace = true } +frame-system = { workspace = true } +sp-core = { workspace = true } +sp-runtime = { workspace = true } +sp-std = { workspace = true } +sp-io = { workspace = true } + +pallet-balances = { workspace = true } +pallet-staking = { workspace = true } + +polkadot-runtime-common = { workspace = true } +runtime-parachains = { workspace = true } +polkadot-parachain-primitives = { workspace = true } + +xcm = { workspace = true } + +[features] +default = ["std"] +std = [ + "codec/std", + "frame-benchmarking?/std", + "frame-support/std", + "frame-system/std", + "scale-info/std", + "serde", + "sp-core/std", + "sp-runtime/std", + "sp-std/std", + "sp-io/std", + "pallet-balances/std", + "pallet-staking/std", + "polkadot-runtime-common/std", + "runtime-parachains/std", + "xcm/std", +] +runtime-benchmarks = [ + "frame-benchmarking/runtime-benchmarks", + "frame-support/runtime-benchmarks", + "frame-system/runtime-benchmarks", + "sp-runtime/runtime-benchmarks", + "pallet-balances/runtime-benchmarks", + "pallet-staking/runtime-benchmarks", + "polkadot-runtime-common/runtime-benchmarks", + "runtime-parachains/runtime-benchmarks", +] +try-runtime = [ + "frame-support/try-runtime", + "frame-system/try-runtime", + "sp-runtime/try-runtime", + "pallet-balances/try-runtime", + "pallet-staking/try-runtime", + "polkadot-runtime-common/try-runtime", + "runtime-parachains/try-runtime", +] diff --git a/pallets/rc-migrator/src/accounts.rs b/pallets/rc-migrator/src/accounts.rs new file mode 100644 index 0000000000..d4febe2f70 --- /dev/null +++ b/pallets/rc-migrator/src/accounts.rs @@ -0,0 +1,417 @@ +// 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 . + +//! Account/Balance data migrator module. + +/* +TODO: remove this dec comment when not needed + +provider refs: +- crowdloans: fundraising system account / https://github.com/paritytech/polkadot-sdk/blob/ace62f120fbc9ec617d6bab0a5180f0be4441537/polkadot/runtime/common/src/crowdloan/mod.rs#L416 +- parachains_assigner_on_demand / on_demand: pallet's account https://github.com/paritytech/polkadot-sdk/blob/ace62f120fbc9ec617d6bab0a5180f0be4441537/polkadot/runtime/parachains/src/on_demand/mod.rs#L407 +- balances: user account / existential deposit +- session: initial validator set on Genesis / https://github.com/paritytech/polkadot-sdk/blob/ace62f120fbc9ec617d6bab0a5180f0be4441537/substrate/frame/session/src/lib.rs#L466 +- delegated-staking: delegators and agents (users) + +consumer refs: +- balances: +-- might hold on account mutation / https://github.com/paritytech/polkadot-sdk/blob/ace62f120fbc9ec617d6bab0a5180f0be4441537/substrate/frame/balances/src/lib.rs#L1007 +-- on migration to new logic for every migrating account / https://github.com/paritytech/polkadot-sdk/blob/ace62f120fbc9ec617d6bab0a5180f0be4441537/substrate/frame/balances/src/lib.rs#L877 +- session: +-- for user setting the keys / https://github.com/paritytech/polkadot-sdk/blob/ace62f120fbc9ec617d6bab0a5180f0be4441537/substrate/frame/session/src/lib.rs#L812 +-- initial validator set on Genesis / https://github.com/paritytech/polkadot-sdk/blob/ace62f120fbc9ec617d6bab0a5180f0be4441537/substrate/frame/session/src/lib.rs#L461 +- recovery: user on recovery claim / https://github.com/paritytech/polkadot-sdk/blob/ace62f120fbc9ec617d6bab0a5180f0be4441537/substrate/frame/recovery/src/lib.rs#L610 +- staking: +-- for user bonding / https://github.com/paritytech/polkadot-sdk/blob/ace62f120fbc9ec617d6bab0a5180f0be4441537/substrate/frame/staking/src/pallet/mod.rs#L1036 +-- virtual bond / agent key / https://github.com/paritytech/polkadot-sdk/blob/ace62f120fbc9ec617d6bab0a5180f0be4441537/substrate/frame/staking/src/pallet/impls.rs#L1948 + +sufficient refs: +- must be zero since only assets pallet might hold such reference +*/ + +/* +TODO: remove when not needed + +Regular native asset teleport from Relay (mint authority) to Asset Hub looks like: + +Relay: mint_into(checking, amount) // publishes Balances::Minted event +Relay: burn_from(source, amount) // publishes Balances::Burned event +Relay: no effect on total issuance +Relay: XCM with teleport sent +AH: mint_into(dest, amount) // publishes Balances::Minted event +AH: total issuance increased by `amount` +Relay: XCM teleport processed + +^ The minimum what we should replay while moving accounts from Relay to AH + +When the Asset Hub turned to the mint authority +Relay: let checking_total = // total checking account balance +Relay: burn_from(checking, checking_total) // publishes Balances::Burned event +AH: let total_issuance = // total issuance on AH +AH: mint_into(checking, checking_total - total_issuance) // publishes Balances::Minted event + +*/ + +use crate::*; +use frame_support::{traits::tokens::IdAmount, weights::WeightMeter}; +use frame_system::Account as SystemAccount; +use pallet_balances::{AccountData, BalanceLock}; + +/// Account type meant to transfer data between RC and AH. +#[derive(Encode, Decode, Clone, PartialEq, Eq, RuntimeDebug, TypeInfo)] +pub struct Account { + /// The account address + pub who: AccountId, + /// Free balance. + /// + /// `free` + `reserved` - the total balance to be minted for `who` on the Asset Hub. + pub free: Balance, + /// Reserved balance. + /// + /// This is not used to establish the reserved balance on the Asset Hub, but used to assert the + /// total reserve balance after applying all `holds` and `unnamed_reserve`. + pub reserved: Balance, + /// Frozen balance. + /// + /// This is not used to establish the reserved balance on the Asset Hub, but used to assert the + /// total reserve balance after applying all `freezes` and `locks`. + pub frozen: Balance, + /// Account holds from Relay Chain. + pub holds: Vec>, + /// Account freezes from Relay Chain. + pub freezes: Vec>, + /// Account locks from Relay Chain. + pub locks: Vec>, + /// Unnamed reserve. + /// + /// No named reserves for Polkadot and Kusama. + pub unnamed_reserve: Balance, + /// Consumer ref count of migrating to Asset Hub pallets except a reference for `reserved` and + /// `frozen` balance. + /// + /// Since the `reserved` and `frozen` balances will be known on a receiving side (AH) they will + /// be calculated there. + pub consumers: u8, + /// Provider ref count of migrating to Asset Hub pallets except the reference for existential + /// deposit. + /// + /// Since the `free` balance will be known on a receiving side (AH) the ref count will be + /// calculated there. + pub providers: u8, +} + +/// The state for the Relay Chain accounts. +#[derive(Encode, Decode, Clone, PartialEq, Eq, RuntimeDebug, TypeInfo)] +pub enum AccountState { + /// The account should be migrated to AH and removed on RC. + Migrate, + /// The account must stay on RC. + /// + /// E.g. RC system account. + Preserve, + + // We might not need the `Part` variation since there are no many cases for `Part` we can just + // keep the whole account balance on RC + /// The part of the account must be preserved on RC. + /// + /// Cases: + /// - accounts placed deposit for parachain registration (paras_registrar pallet); + /// - accounts placed deposit for hrmp channel registration (parachains_hrmp pallet); + Part { + /// Free part of the account the must be preserved on RC. + /// + /// In practice the new ED. + free: Balance, + /// The reserved balance that must be preserved on RC. + /// + /// In practice reserved by old `Currency` api and has no associated reason. + reserved: Balance, + }, +} + +pub type AccountStateFor = AccountState<::Balance>; +pub type AccountFor = Account< + ::AccountId, + ::Balance, + ::RuntimeHoldReason, + ::FreezeIdentifier, +>; + +impl Pallet { + // TODO: Currently, we use `debug_assert!` for basic test checks against a production snapshot. + + /// Migrate accounts from RC to AH. + /// + /// Parameters: + /// - `maybe_last_key` - the last migrated account from RC to AH if any + /// - `weight_counter` - the weight meter + /// + /// Result: + /// - None - no accounts left to be migrated to AH. + /// - Some(maybe_last_key) - the last migrated account from RC to AH if + pub fn migrate_accounts( + maybe_last_key: Option, + weight_counter: &mut WeightMeter, + ) -> Result>, ()> { + // we should not send more than AH can handle within the block. + let mut ah_weight_counter = WeightMeter::with_limit(T::MaxAhWeight::get()); + // accounts package for the current iteration. + let mut package = Vec::new(); + + // TODO transport weight + let xcm_weight = Weight::from_all(1); + if weight_counter.try_consume(xcm_weight).is_err() { + return Ok(Some(maybe_last_key)); + } + + let iter = if let Some(ref last_key) = maybe_last_key { + SystemAccount::::iter_from_key(last_key) + } else { + SystemAccount::::iter() + }; + + let mut maybe_last_key = maybe_last_key; + let mut last_package = true; + for (who, account_info) in iter { + // account for `get_rc_state` read below + if weight_counter.try_consume(T::DbWeight::get().reads(1)).is_err() { + last_package = false; + break; + } + + let rc_state = Self::get_rc_state(&who); + + if matches!(rc_state, AccountState::Preserve) { + log::debug!( + target: LOG_TARGET, + "Preserve account '{:?}' on Relay Chain", + who.to_ss58check(), + ); + maybe_last_key = Some(who); + continue; + } + + // TODO: we do not expect `Part` variation for now and might delete it later + debug_assert!(!matches!(rc_state, AccountState::Part { .. })); + + log::debug!( + target: LOG_TARGET, + "Migrating account '{:?}'", + who.to_ss58check(), + ); + + // account the weight for migrating a single account on Relay Chain. + if weight_counter.try_consume(T::RcWeightInfo::migrate_account()).is_err() { + last_package = false; + break; + } + + // account the weight for receiving a single account on Asset Hub. + if ah_weight_counter.try_consume(T::AhWeightInfo::migrate_account()).is_err() { + last_package = false; + break; + } + + // migrate the target account: + // - keep `balance`, `holds`, `freezes`, .. in memory + // - release all `holds`, `freezes`, ... + // - teleport all balance from RC to AH: + // -- mint into XCM `checking` account + // -- burn from target account + // - add `balance`, `holds`, `freezes`, .. to the accounts package to be sent via XCM + + let account_data: AccountData = account_info.data.clone(); + + let freezes: Vec> = + pallet_balances::Freezes::::get(&who).into(); + + for freeze in &freezes { + let _ = ::Currency::thaw(&freeze.id, &who) + // TODO: handle error + .unwrap(); + } + + let holds: Vec> = + pallet_balances::Holds::::get(&who).into(); + + for hold in &holds { + let _ = + ::Currency::release(&hold.id, &who, hold.amount, Precision::Exact) + // TODO: handle error + .unwrap(); + } + + let locks: Vec> = + pallet_balances::Locks::::get(&who).into_inner(); + + for lock in &locks { + // Expected lock ids: + // - "staking " // should be transformed to hold with https://github.com/paritytech/polkadot-sdk/pull/5501 + // - "vesting " + // - "pyconvot" + ::Currency::remove_lock(lock.id, &who); + } + + let unnamed_reserve = ::Currency::reserved_balance(&who); + let _ = ::Currency::unreserve(&who, unnamed_reserve); + + // TODO: To ensure the account can be fully withdrawn from RC to AH, we force-update the + // references here. After inspecting the state, it's clear that fully correcting the + // reference counts would be nearly impossible. Instead, for accounts meant to be fully + // migrated to the AH, we will calculate the actual reference counts based on the + // migrating pallets and transfer them to AH. This is done using the + // `Self::get_consumer_count` and `Self::get_provider_count` functions. + SystemAccount::::mutate(&who, |a| { + a.consumers = 0; + a.providers = 1; + }); + + let balance = ::Currency::reducible_balance( + &who, + Preservation::Expendable, + Fortitude::Polite, + ); + let total_balance = ::Currency::total_balance(&who); + + debug_assert!(total_balance == balance); + debug_assert!(total_balance == account_data.free + account_data.reserved); + // TODO: total_balance > ED on AH + + let burned = ::Currency::burn_from( + &who, + total_balance, + Preservation::Expendable, + Precision::Exact, + Fortitude::Polite, + ) + // TODO: handle error + .unwrap(); + + debug_assert!(total_balance == burned); + + let minted = + ::Currency::mint_into(&T::CheckingAccount::get(), total_balance) + // TODO: handle error; + .unwrap(); + + debug_assert!(total_balance == minted); + + let account_to_ah = Account { + who: who.clone(), + free: account_data.free, + reserved: account_data.reserved, + frozen: account_data.frozen, + holds, + freezes, + locks, + unnamed_reserve, + consumers: Self::get_consumer_count(&who, &account_info), + providers: Self::get_provider_count(&who, &account_info), + }; + + package.push(account_to_ah); + maybe_last_key = Some(who); + } + + let call = types::AssetHubPalletConfig::::AhmController( + types::AhMigratorCall::::ReceiveAccounts { accounts: package }, + ); + + let message = Xcm(vec![ + Instruction::UnpaidExecution { + weight_limit: WeightLimit::Unlimited, + check_origin: None, + }, + Instruction::Transact { + origin_kind: OriginKind::Superuser, + require_weight_at_most: Weight::from_all(1), // TODO + call: call.encode().into(), + }, + ]); + + if let Err(_err) = + send_xcm::(Location::new(0, [Junction::Parachain(1000)]), message.clone()) + { + return Err(()); + }; + + if last_package { + Ok(None) + } else { + Ok(Some(maybe_last_key)) + } + } + + /// Consumer ref count of migrating to Asset Hub pallets except a reference for `reserved` and + /// `frozen` balance. + /// + /// Since the `reserved` and `frozen` balances will be known on a receiving side (AH) they will + /// be calculated there. + pub fn get_consumer_count(_who: &T::AccountId, _info: &AccountInfoFor) -> u8 { + // TODO: check the pallets for provider references on Relay Chain. + 0 + } + + /// Provider ref count of migrating to Asset Hub pallets except the reference for existential + /// deposit. + /// + /// Since the `free` balance will be known on a receiving side (AH) the ref count will be + /// calculated there. + pub fn get_provider_count(_who: &T::AccountId, _info: &AccountInfoFor) -> u8 { + // TODO: check the pallets for provider references on Relay Chain. + 0 + } + + /// The part of the balance of the `who` that must stay on the Relay Chain. + pub fn get_rc_state(who: &T::AccountId) -> AccountStateFor { + // TODO: static list of System Accounts that must stay on RC + // e.g. XCM teleport checking account + + if let Some(state) = RcAccounts::::get(who) { + return state; + } + AccountStateFor::::Migrate + } + + /// Obtain all known accounts that must stay on RC and persist it to the [`RcAccounts`] storage + /// item. + /// + /// Should be executed once before the migration starts. + pub fn obtain_rc_accounts() -> Weight { + for (channel_id, _info) in hrmp::HrmpChannels::::iter() { + let sender: T::AccountId = channel_id.sender.into_account_truncating(); + RcAccounts::::insert(sender, AccountStateFor::::Preserve); + + let recipient: T::AccountId = channel_id.recipient.into_account_truncating(); + RcAccounts::::insert(recipient, AccountStateFor::::Preserve); + } + + for (_, info) in Paras::::iter() { + RcAccounts::::insert( + info.manager, + // TODO: we can use `Part` variation to keep only the reserved part on RC + // for now for simplicity we preserve the whole account on RC + AccountStateFor::::Preserve, + ); + } + + // TODO: should we consider `hrmp::HrmpOpenChannelRequests` or we can just clean up it + // before the migration. + + // TODO: define actual weight + Weight::from_all(1) + } +} diff --git a/pallets/rc-migrator/src/lib.rs b/pallets/rc-migrator/src/lib.rs new file mode 100644 index 0000000000..af72948fd8 --- /dev/null +++ b/pallets/rc-migrator/src/lib.rs @@ -0,0 +1,211 @@ +// 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. + +//! The helper pallet for the Asset Hub migration. + +#![cfg_attr(not(feature = "std"), no_std)] + +pub mod accounts; +pub mod types; +mod weights; +pub use pallet::*; + +use frame_support::{ + pallet_prelude::*, + sp_runtime::traits::AccountIdConversion, + storage::transactional::with_transaction_opaque_err, + traits::{ + fungible::{Inspect, InspectFreeze, Mutate, MutateFreeze, MutateHold}, + tokens::{Fortitude, Precision, Preservation}, + LockableCurrency, ReservableCurrency, + }, + weights::WeightMeter, +}; +use frame_system::{pallet_prelude::*, AccountInfo}; +use pallet_balances::AccountData; +use polkadot_parachain_primitives::primitives::Id as ParaId; +use polkadot_runtime_common::paras_registrar; +use runtime_parachains::hrmp; +use sp_core::crypto::Ss58Codec; +use sp_runtime::AccountId32; +use sp_std::prelude::*; +use storage::TransactionOutcome; +use types::AhWeightInfo; +use weights::WeightInfo; +use xcm::prelude::*; + +/// The log target of this pallet. +pub const LOG_TARGET: &str = "runtime::rc-migrator"; + +#[derive(Encode, Decode, Clone, PartialEq, Eq, Default, RuntimeDebug, TypeInfo, MaxEncodedLen)] +pub enum MigrationStage { + /// The migration has not yet started. + #[default] + Pending, + // Initializing + /// Migrating account balances. + MigratingAccounts { + // Last migrated account + last_key: Option, + }, + /// Some next stage + TODO, +} + +type AccountInfoFor = + AccountInfo<::Nonce, ::AccountData>; + +#[frame_support::pallet(dev_mode)] +pub mod pallet { + use super::*; + + /// Paras Registrar Pallet + type ParasRegistrar = paras_registrar::Pallet; + + /// Super trait of all pallets the migration depends on. + #[pallet::config] + pub trait Config: + frame_system::Config, AccountId = AccountId32> + + pallet_balances::Config + + hrmp::Config + + paras_registrar::Config + { + /// The overarching event type. + type RuntimeEvent: From> + IsType<::RuntimeEvent>; + /// Native asset registry type. + type Currency: Mutate + + MutateHold + + InspectFreeze + + MutateFreeze + + ReservableCurrency + + LockableCurrency; + /// XCM checking account. + type CheckingAccount: Get; + /// Send DMP message. + type SendXcm: SendXcm; + /// The maximum weight that this pallet can consume `on_initialize`. + type MaxRcWeight: Get; + /// The maximum weight that Asset Hub can consume for processing one migration package. + /// + /// Every data package that is sent from this pallet should not take more than this. + type MaxAhWeight: Get; + /// Weight information for the functions of this pallet. + type RcWeightInfo: WeightInfo; + /// Weight information for the processing the packages from this pallet on the Asset Hub. + type AhWeightInfo: AhWeightInfo; + } + + #[pallet::error] + pub enum Error { + /// TODO + TODO, + } + + #[pallet::event] + #[pallet::generate_deposit(pub(crate) fn deposit_event)] + pub enum Event { + /// TODO + TODO, + } + + /// The Relay Chain migration state. + #[pallet::storage] + pub type RcMigrationStage = + StorageValue<_, MigrationStage, ValueQuery>; + + /// Helper storage item to obtain and store the known accounts that should be kept partially on + /// fully on Relay Chain. + #[pallet::storage] + pub type RcAccounts = + StorageMap<_, Twox64Concat, T::AccountId, accounts::AccountState, OptionQuery>; + + /// Alias for `Paras` from `paras_registrar`. + /// + /// The fields of the type stored in the original storage item are private, so we define the + /// storage alias to get an access to them. + #[frame_support::storage_alias(pallet_name)] + pub type Paras = StorageMap< + ParasRegistrar, + Twox64Concat, + ParaId, + types::ParaInfo< + ::AccountId, + ::Balance, + >, + >; + + #[pallet::pallet] + pub struct Pallet(_); + + #[pallet::call] + impl Pallet { + /// TODO + #[pallet::call_index(0)] + #[pallet::weight({1})] + pub fn _do_something(_origin: OriginFor) -> DispatchResultWithPostInfo { + Ok(().into()) + } + } + + #[pallet::hooks] + impl Hooks> for Pallet { + fn on_initialize(_: BlockNumberFor) -> Weight { + let mut weight_counter = WeightMeter::with_limit(T::MaxRcWeight::get()); + let stage = RcMigrationStage::::get(); + weight_counter.consume(T::DbWeight::get().reads(1)); + + if stage == MigrationStage::Pending { + // TODO: not complete + + let _ = Self::obtain_rc_accounts(); + + return weight_counter.consumed(); + } + + // TODO init + + if let MigrationStage::MigratingAccounts { last_key } = stage { + let res = + with_transaction_opaque_err::>, (), _>(|| { + match Self::migrate_accounts(last_key, &mut weight_counter) { + Ok(ok) => TransactionOutcome::Commit(Ok(ok)), + Err(err) => TransactionOutcome::Commit(Err(err)), + } + }); + + match res { + Ok(Ok(None)) => { + // accounts migration is completed + // TODO publish event + RcMigrationStage::::put(MigrationStage::TODO); + }, + Ok(Ok(Some(last_key))) => { + // accounts migration continues with the next block + // TODO publish event + RcMigrationStage::::put(MigrationStage::MigratingAccounts { last_key }); + }, + _ => { + // TODO handle error + }, + } + return weight_counter.consumed(); + }; + + return weight_counter.consumed(); + } + } +} diff --git a/pallets/rc-migrator/src/types.rs b/pallets/rc-migrator/src/types.rs new file mode 100644 index 0000000000..2a5e05e04f --- /dev/null +++ b/pallets/rc-migrator/src/types.rs @@ -0,0 +1,57 @@ +// 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 . + +//! Types + +use super::*; + +/// Relay Chain Freeze Reason +#[derive(Encode, Decode)] +pub enum AssetHubPalletConfig { + #[codec(index = 255)] + AhmController(AhMigratorCall), +} + +/// Call encoding for the calls needed from the Broker pallet. +#[derive(Encode, Decode)] +pub enum AhMigratorCall { + #[codec(index = 0)] + ReceiveAccounts { accounts: Vec> }, +} + +/// Copy of `ParaInfo` type from `paras_registrar` pallet. +#[derive(Encode, Decode, Clone, PartialEq, Eq, Default, RuntimeDebug, TypeInfo)] +pub struct ParaInfo { + /// The account that has placed a deposit for registering this para. + pub manager: AccountId, + /// The amount reserved by the `manager` account for the registration. + pub deposit: Balance, + /// Whether the para registration should be locked from being controlled by the manager. + /// None means the lock had not been explicitly set, and should be treated as false. + pub locked: Option, +} + +/// Weight information for the processing the packages from this pallet on the Asset Hub. +pub trait AhWeightInfo { + /// Weight for processing a single account on AH. + fn migrate_account() -> Weight; +} + +impl AhWeightInfo for () { + fn migrate_account() -> Weight { + Weight::from_all(1) + } +} diff --git a/pallets/rc-migrator/src/weights.rs b/pallets/rc-migrator/src/weights.rs new file mode 100644 index 0000000000..b78a4312c1 --- /dev/null +++ b/pallets/rc-migrator/src/weights.rs @@ -0,0 +1,28 @@ +// 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. + +use frame_support::weights::Weight; + +pub trait WeightInfo { + fn migrate_account() -> Weight; +} + +impl WeightInfo for () { + fn migrate_account() -> Weight { + Weight::from_all(1) + } +} diff --git a/relay/polkadot/Cargo.toml b/relay/polkadot/Cargo.toml index ed69433257..dc90d1d70a 100644 --- a/relay/polkadot/Cargo.toml +++ b/relay/polkadot/Cargo.toml @@ -8,6 +8,12 @@ edition.workspace = true license.workspace = true [dependencies] + +# Asset Hub Migration concerning deps +pallet-rc-migrator = { workspace = true } +pallet-ah-migrator = { workspace = true } +# End: Asset Hub Migration concerning deps + codec = { features = ["derive", "max-encoded-len"], workspace = true } scale-info = { features = ["derive"], workspace = true } serde_json = { features = ["alloc"], workspace = true } @@ -128,6 +134,8 @@ default = ["std"] no_std = [] only-staking = [] std = [ + "pallet-rc-migrator/std", + "authority-discovery-primitives/std", "babe-primitives/std", "beefy-primitives/std", @@ -222,6 +230,8 @@ std = [ "xcm/std", ] runtime-benchmarks = [ + "pallet-rc-migrator/runtime-benchmarks", + "frame-benchmarking/runtime-benchmarks", "frame-election-provider-support/runtime-benchmarks", "frame-support/runtime-benchmarks", @@ -273,6 +283,8 @@ runtime-benchmarks = [ "xcm-runtime-apis/runtime-benchmarks", ] try-runtime = [ + "pallet-rc-migrator/try-runtime", + "frame-election-provider-support/try-runtime", "frame-executive/try-runtime", "frame-support/try-runtime", diff --git a/relay/polkadot/src/lib.rs b/relay/polkadot/src/lib.rs index 7f12e15f38..5920113869 100644 --- a/relay/polkadot/src/lib.rs +++ b/relay/polkadot/src/lib.rs @@ -1175,8 +1175,7 @@ impl InstanceFilter for ProxyType { matches!( c, RuntimeCall::Staking(..) | - RuntimeCall::Session(..) | - RuntimeCall::Utility(..) | + RuntimeCall::Session(..) | RuntimeCall::Utility(..) | RuntimeCall::FastUnstake(..) | RuntimeCall::VoterList(..) | RuntimeCall::NominationPools(..) @@ -1607,6 +1606,22 @@ impl OnSwap for SwapLeases { } } +parameter_types! { + pub RcMigratorMaxWeight: Weight = Weight::from_all(1); // TODO set the actual max weight + pub AhMigratorMaxWeight: Weight = Weight::from_all(1); // TODO set the actual max weight +} + +impl pallet_rc_migrator::Config for Runtime { + type RuntimeEvent = RuntimeEvent; + type Currency = Balances; + type CheckingAccount = xcm_config::CheckAccount; + type SendXcm = xcm_config::XcmRouter; + type MaxRcWeight = RcMigratorMaxWeight; + type MaxAhWeight = AhMigratorMaxWeight; + type RcWeightInfo = (); + type AhWeightInfo = (); +} + construct_runtime! { pub enum Runtime { @@ -1717,6 +1732,9 @@ construct_runtime! { // refer to block. See issue #160 for details. Mmr: pallet_mmr = 201, BeefyMmrLeaf: pallet_beefy_mmr = 202, + + // Relay Chain Migrator + RcMigrator: pallet_rc_migrator = 255, } } diff --git a/relay/polkadot/tests/ahm/accounts.rs b/relay/polkadot/tests/ahm/accounts.rs new file mode 100644 index 0000000000..a027fc0972 --- /dev/null +++ b/relay/polkadot/tests/ahm/accounts.rs @@ -0,0 +1,29 @@ +// 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 . + +use frame_support::weights::WeightMeter; + +use super::*; + +#[tokio::test] +async fn account_test() { + let Some(mut ext) = remote_ext_test_setup().await else { return; }; + + ext.execute_with(|| { + let _ = RcMigrator::obtain_rc_accounts(); + let _ = RcMigrator::migrate_accounts(None, &mut WeightMeter::new()).unwrap(); + }); +} diff --git a/relay/polkadot/tests/ahm/mod.rs b/relay/polkadot/tests/ahm/mod.rs new file mode 100644 index 0000000000..ec59e42cb7 --- /dev/null +++ b/relay/polkadot/tests/ahm/mod.rs @@ -0,0 +1,47 @@ +// 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 . + +//! Asset Hub Migrator tests. + +mod accounts; + +// Runtime specific imports +// Use general aliases for the imports to make it easier to copy&paste the tests for other runtimes. +use polkadot_runtime::{RcMigrator, Block, Runtime as T, System, *}; + +// General imports +use remote_externalities::{Builder, Mode, OfflineConfig, RemoteExternalities}; + +async fn remote_ext_test_setup() -> Option> { + sp_tracing::try_init_simple(); + let Some(snap) = std::env::var("SNAP").ok() else{ + return None; + }; + let abs = std::path::absolute(snap.clone()); + + let ext = Builder::::default() + .mode(Mode::Offline( + OfflineConfig { state_snapshot: snap.clone().into() }, + )) + .build() + .await + .map_err(|e| { + eprintln!("Could not load from snapshot: {:?}: {:?}", abs, e); + }) + .unwrap(); + + Some(ext) +} diff --git a/relay/polkadot/tests/mod.rs b/relay/polkadot/tests/mod.rs new file mode 100644 index 0000000000..f01eab3498 --- /dev/null +++ b/relay/polkadot/tests/mod.rs @@ -0,0 +1,17 @@ +// 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 . + +mod ahm; diff --git a/system-parachains/asset-hubs/asset-hub-polkadot/Cargo.toml b/system-parachains/asset-hubs/asset-hub-polkadot/Cargo.toml index 1f207ce943..9b2e293dfb 100644 --- a/system-parachains/asset-hubs/asset-hub-polkadot/Cargo.toml +++ b/system-parachains/asset-hubs/asset-hub-polkadot/Cargo.toml @@ -9,6 +9,8 @@ repository.workspace = true version.workspace = true [dependencies] +pallet-ah-migrator = { workspace = true } + codec = { features = ["derive", "max-encoded-len"], workspace = true } hex-literal = { optional = true, workspace = true } log = { workspace = true } @@ -43,6 +45,7 @@ pallet-message-queue = { workspace = true } pallet-multisig = { workspace = true } pallet-nfts = { workspace = true } pallet-nfts-runtime-api = { workspace = true } +pallet-preimage = { workspace = true } pallet-proxy = { workspace = true } pallet-session = { workspace = true } pallet-timestamp = { workspace = true } @@ -114,6 +117,8 @@ substrate-wasm-builder = { optional = true, workspace = true } [features] default = ["std"] runtime-benchmarks = [ + "pallet-ah-migrator/runtime-benchmarks", + "assets-common/runtime-benchmarks", "cumulus-pallet-parachain-system/runtime-benchmarks", "cumulus-pallet-session-benchmarking/runtime-benchmarks", @@ -132,6 +137,7 @@ runtime-benchmarks = [ "pallet-message-queue/runtime-benchmarks", "pallet-multisig/runtime-benchmarks", "pallet-nfts/runtime-benchmarks", + "pallet-preimage/runtime-benchmarks", "pallet-proxy/runtime-benchmarks", "pallet-timestamp/runtime-benchmarks", "pallet-uniques/runtime-benchmarks", @@ -150,6 +156,8 @@ runtime-benchmarks = [ "xcm-runtime-apis/runtime-benchmarks", ] try-runtime = [ + "pallet-ah-migrator/try-runtime", + "cumulus-pallet-aura-ext/try-runtime", "cumulus-pallet-parachain-system/try-runtime", "cumulus-pallet-xcm/try-runtime", @@ -168,6 +176,7 @@ try-runtime = [ "pallet-message-queue/try-runtime", "pallet-multisig/try-runtime", "pallet-nfts/try-runtime", + "pallet-preimage/try-runtime", "pallet-proxy/try-runtime", "pallet-session/try-runtime", "pallet-timestamp/try-runtime", @@ -182,6 +191,8 @@ try-runtime = [ "sp-runtime/try-runtime", ] std = [ + "pallet-ah-migrator/std", + "assets-common/std", "bp-asset-hub-kusama/std", "bp-asset-hub-polkadot/std", @@ -217,6 +228,7 @@ std = [ "pallet-multisig/std", "pallet-nfts-runtime-api/std", "pallet-nfts/std", + "pallet-preimage/std", "pallet-proxy/std", "pallet-session/std", "pallet-timestamp/std", diff --git a/system-parachains/asset-hubs/asset-hub-polkadot/src/lib.rs b/system-parachains/asset-hubs/asset-hub-polkadot/src/lib.rs index e6760f29b0..248efc3227 100644 --- a/system-parachains/asset-hubs/asset-hub-polkadot/src/lib.rs +++ b/system-parachains/asset-hubs/asset-hub-polkadot/src/lib.rs @@ -62,6 +62,7 @@ include!(concat!(env!("OUT_DIR"), "/wasm_binary.rs")); // Genesis preset configurations. pub mod genesis_config_presets; mod impls; +mod migration; mod weights; pub mod xcm_config; @@ -73,6 +74,7 @@ use assets_common::{ }; use cumulus_pallet_parachain_system::RelayNumberMonotonicallyIncreases; use cumulus_primitives_core::{AggregateMessageOrigin, ParaId}; +use migration::{RcToAhFreezeReason, RcToAhHoldReason}; use sp_api::impl_runtime_apis; use sp_core::{crypto::KeyTypeId, ConstU128, OpaqueMetadata}; use sp_runtime::{ @@ -99,9 +101,11 @@ use frame_support::{ genesis_builder_helper::{build_state, get_preset}, parameter_types, traits::{ - fungible, fungibles, tokens::imbalance::ResolveAssetTo, AsEnsureOriginWithArg, ConstBool, - ConstU32, ConstU64, ConstU8, EitherOfDiverse, Equals, InstanceFilter, NeverEnsureOrigin, - TransformOrigin, WithdrawReasons, + fungible::{self, HoldConsideration}, + fungibles, + tokens::imbalance::ResolveAssetTo, + AsEnsureOriginWithArg, ConstBool, ConstU32, ConstU64, ConstU8, EitherOfDiverse, Equals, + InstanceFilter, LinearStoragePrice, NeverEnsureOrigin, TransformOrigin, WithdrawReasons, }, weights::{ConstantMultiplier, Weight, WeightToFee as _}, PalletId, @@ -494,8 +498,7 @@ impl InstanceFilter for ProxyType { RuntimeCall::Assets { .. } | RuntimeCall::Utility { .. } | RuntimeCall::Multisig { .. } | - RuntimeCall::Nfts { .. } | - RuntimeCall::Uniques { .. } + RuntimeCall::Nfts { .. } | RuntimeCall::Uniques { .. } ) }, ProxyType::AssetOwner => matches!( @@ -962,6 +965,36 @@ impl pallet_asset_conversion::Config for Runtime { >; } +parameter_types! { + pub const PreimageBaseDeposit: Balance = system_para_deposit(2, 64); + pub const PreimageByteDeposit: Balance = system_para_deposit(0, 1); + pub const PreimageHoldReason: RuntimeHoldReason = + RuntimeHoldReason::Preimage(pallet_preimage::HoldReason::Preimage); +} + +impl pallet_preimage::Config for Runtime { + type WeightInfo = (); + type RuntimeEvent = RuntimeEvent; + type Currency = Balances; + type ManagerOrigin = EnsureRoot; + type Consideration = HoldConsideration< + AccountId, + Balances, + PreimageHoldReason, + LinearStoragePrice, + >; +} + +impl pallet_ah_migrator::Config for Runtime { + type RuntimeEvent = RuntimeEvent; + type Currency = Balances; + type CheckingAccount = xcm_config::CheckingAccount; + type RcHoldReason = migration::RcHoldReason; + type RcFreezeReason = migration::RcFreezeReason; + type RcToAhHoldReason = RcToAhHoldReason; + type RcToAhFreezeReason = RcToAhFreezeReason; +} + // Create the runtime by composing the FRAME pallets that were previously configured. construct_runtime!( pub enum Runtime @@ -972,6 +1005,7 @@ construct_runtime!( // RandomnessCollectiveFlip = 2 removed Timestamp: pallet_timestamp = 3, ParachainInfo: parachain_info = 4, + Preimage: pallet_preimage = 5, // Monetary stuff. Balances: pallet_balances = 10, @@ -1006,6 +1040,9 @@ construct_runtime!( ForeignAssets: pallet_assets:: = 53, PoolAssets: pallet_assets:: = 54, AssetConversion: pallet_asset_conversion = 55, + + // Asset Hub Migrator + AhMigrator: pallet_ah_migrator = 255, } ); diff --git a/system-parachains/asset-hubs/asset-hub-polkadot/src/migration.rs b/system-parachains/asset-hubs/asset-hub-polkadot/src/migration.rs new file mode 100644 index 0000000000..bd482deba0 --- /dev/null +++ b/system-parachains/asset-hubs/asset-hub-polkadot/src/migration.rs @@ -0,0 +1,56 @@ +// 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. + +use super::*; +use frame_support::pallet_prelude::TypeInfo; +use sp_runtime::traits::Convert; + +/// Relay Chain Hold Reason +#[derive(Encode, Decode, Clone, PartialEq, Eq, RuntimeDebug, TypeInfo)] +pub enum RcHoldReason { + #[codec(index = 10u8)] + Preimage(pallet_preimage::HoldReason), + // TODO + // #[codec(index = 98u8)] + // StateTrieMigration(pallet_state_trie_migration::HoldReason), +} + +/// Relay Chain Freeze Reason +#[derive(Encode, Decode, Clone, PartialEq, Eq, RuntimeDebug, TypeInfo)] +pub enum RcFreezeReason { + // TODO + // #[codec(index = 39u8)] + // NominationPools(pallet_nomination_pools::FreezeReason), +} + +pub struct RcToAhHoldReason; +impl Convert for RcToAhHoldReason { + fn convert(a: RcHoldReason) -> RuntimeHoldReason { + match a { + // TODO mapping + _ => PreimageHoldReason::get(), + } + } +} + +pub struct RcToAhFreezeReason; +impl Convert for RcToAhFreezeReason { + fn convert(a: RcFreezeReason) -> () { + match a { + // TODO mapping + _ => (), + } + } +} diff --git a/system-parachains/asset-hubs/asset-hub-polkadot/src/xcm_config.rs b/system-parachains/asset-hubs/asset-hub-polkadot/src/xcm_config.rs index a485abd6cb..f7e4d9eab9 100644 --- a/system-parachains/asset-hubs/asset-hub-polkadot/src/xcm_config.rs +++ b/system-parachains/asset-hubs/asset-hub-polkadot/src/xcm_config.rs @@ -670,8 +670,7 @@ pub mod bridging { } } impl, OriginLocation: Get> - ContainsPair - for RemoteAssetFromLocation + ContainsPair for RemoteAssetFromLocation { fn contains(asset: &Asset, origin: &Location) -> bool { >::contains(&asset.id.0, origin) From a18dec900919b8607a452167623d53c870b9e470 Mon Sep 17 00:00:00 2001 From: muharem Date: Fri, 20 Dec 2024 19:38:44 +0100 Subject: [PATCH 02/10] fixes --- Cargo.toml | 1 + pallets/ah-migrator/src/lib.rs | 6 ++---- pallets/rc-migrator/src/lib.rs | 2 +- relay/polkadot/src/lib.rs | 3 ++- system-parachains/asset-hubs/asset-hub-polkadot/src/lib.rs | 3 ++- .../asset-hubs/asset-hub-polkadot/src/xcm_config.rs | 3 ++- 6 files changed, 10 insertions(+), 8 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index ab8c3fcdc4..91feef48df 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -287,6 +287,7 @@ members = [ "integration-tests/emulated/tests/people/people-kusama", "integration-tests/emulated/tests/people/people-polkadot", "integration-tests/zombienet", + "pallets/ah-migrator", "pallets/rc-migrator", "relay/common", "relay/kusama", diff --git a/pallets/ah-migrator/src/lib.rs b/pallets/ah-migrator/src/lib.rs index f725a75632..b99cb57f58 100644 --- a/pallets/ah-migrator/src/lib.rs +++ b/pallets/ah-migrator/src/lib.rs @@ -15,7 +15,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -//! The helper pallet for the Asset Hub migration. +//! The helper pallet for the Asset Hub migration meant to be setup on Asset Hub. #![cfg_attr(not(feature = "std"), no_std)] @@ -32,7 +32,7 @@ use frame_support::{ use frame_system::pallet_prelude::*; use pallet_balances::{AccountData, Reasons as LockReasons}; use pallet_rc_migrator::accounts::Account as RcAccount; -use sp_runtime::AccountId32; +use sp_runtime::{traits::Convert, AccountId32}; use sp_std::prelude::*; /// The log target of this pallet. @@ -40,8 +40,6 @@ pub const LOG_TARGET: &str = "runtime::ah-migrator"; #[frame_support::pallet(dev_mode)] pub mod pallet { - use sp_runtime::traits::Convert; - use super::*; /// Super trait of all pallets the migration depends on. diff --git a/pallets/rc-migrator/src/lib.rs b/pallets/rc-migrator/src/lib.rs index af72948fd8..438c6f4ebc 100644 --- a/pallets/rc-migrator/src/lib.rs +++ b/pallets/rc-migrator/src/lib.rs @@ -15,7 +15,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -//! The helper pallet for the Asset Hub migration. +//! The helper pallet for the Asset Hub migration meant to be setup on Relay Chain. #![cfg_attr(not(feature = "std"), no_std)] diff --git a/relay/polkadot/src/lib.rs b/relay/polkadot/src/lib.rs index 5920113869..8aa1291412 100644 --- a/relay/polkadot/src/lib.rs +++ b/relay/polkadot/src/lib.rs @@ -1175,7 +1175,8 @@ impl InstanceFilter for ProxyType { matches!( c, RuntimeCall::Staking(..) | - RuntimeCall::Session(..) | RuntimeCall::Utility(..) | + RuntimeCall::Session(..) | + RuntimeCall::Utility(..) | RuntimeCall::FastUnstake(..) | RuntimeCall::VoterList(..) | RuntimeCall::NominationPools(..) diff --git a/system-parachains/asset-hubs/asset-hub-polkadot/src/lib.rs b/system-parachains/asset-hubs/asset-hub-polkadot/src/lib.rs index 248efc3227..f8b7346ec9 100644 --- a/system-parachains/asset-hubs/asset-hub-polkadot/src/lib.rs +++ b/system-parachains/asset-hubs/asset-hub-polkadot/src/lib.rs @@ -498,7 +498,8 @@ impl InstanceFilter for ProxyType { RuntimeCall::Assets { .. } | RuntimeCall::Utility { .. } | RuntimeCall::Multisig { .. } | - RuntimeCall::Nfts { .. } | RuntimeCall::Uniques { .. } + RuntimeCall::Nfts { .. } | + RuntimeCall::Uniques { .. } ) }, ProxyType::AssetOwner => matches!( diff --git a/system-parachains/asset-hubs/asset-hub-polkadot/src/xcm_config.rs b/system-parachains/asset-hubs/asset-hub-polkadot/src/xcm_config.rs index f7e4d9eab9..a485abd6cb 100644 --- a/system-parachains/asset-hubs/asset-hub-polkadot/src/xcm_config.rs +++ b/system-parachains/asset-hubs/asset-hub-polkadot/src/xcm_config.rs @@ -670,7 +670,8 @@ pub mod bridging { } } impl, OriginLocation: Get> - ContainsPair for RemoteAssetFromLocation + ContainsPair + for RemoteAssetFromLocation { fn contains(asset: &Asset, origin: &Location) -> bool { >::contains(&asset.id.0, origin) From 063450f08eca84bcd5c2ff18727d8b0174d2b089 Mon Sep 17 00:00:00 2001 From: muharem Date: Sun, 22 Dec 2024 13:44:27 +0100 Subject: [PATCH 03/10] update docs --- pallets/ah-migrator/Cargo.toml | 2 +- pallets/ah-migrator/src/lib.rs | 19 ++++++++++++++++--- pallets/rc-migrator/Cargo.toml | 2 +- pallets/rc-migrator/src/accounts.rs | 7 ++++++- pallets/rc-migrator/src/lib.rs | 19 ++++++++++++++++--- 5 files changed, 40 insertions(+), 9 deletions(-) diff --git a/pallets/ah-migrator/Cargo.toml b/pallets/ah-migrator/Cargo.toml index 61f03854fb..c4e2471362 100644 --- a/pallets/ah-migrator/Cargo.toml +++ b/pallets/ah-migrator/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "pallet-ah-migrator" -description = "Asset Hub migrator pallet for Asset Hub" +description = "Operational pallet managing and processing migration from Relay Chain to Asset Hub on Asset Hub" license = "Apache-2.0" version = "0.1.0" edition.workspace = true diff --git a/pallets/ah-migrator/src/lib.rs b/pallets/ah-migrator/src/lib.rs index b99cb57f58..4078ae1cc4 100644 --- a/pallets/ah-migrator/src/lib.rs +++ b/pallets/ah-migrator/src/lib.rs @@ -15,7 +15,19 @@ // See the License for the specific language governing permissions and // limitations under the License. -//! The helper pallet for the Asset Hub migration meant to be setup on Asset Hub. +//! The operational pallet for the Asset Hub, designed to manage and facilitate the migration of +//! subsystems such as Governance, Staking, Balances from the Relay Chain to the Asset Hub. This +//! pallet works alongside its counterpart, `pallet_rc_migrator`, which handles migration +//! processes on the Relay Chain side. +//! +//! This pallet is responsible for controlling the initiation, progression, and completion of the +//! migration process, including managing its various stages and transferring the necessary data. +//! The pallet directly accesses the storage of other pallets for read/write operations while +//! maintaining compatibility with their existing APIs. +//! +//! To simplify development and avoid the need to edit the original pallets, this pallet may +//! duplicate private items such as storage entries from the original pallets. This ensures that the +//! migration logic can be implemented without altering the original implementations. #![cfg_attr(not(feature = "std"), no_std)] @@ -42,7 +54,8 @@ pub const LOG_TARGET: &str = "runtime::ah-migrator"; pub mod pallet { use super::*; - /// Super trait of all pallets the migration depends on. + /// Super config trait for all pallets that the migration depends on, providing convenient + /// access to their items. #[pallet::config] pub trait Config: frame_system::Config, AccountId = AccountId32> @@ -87,7 +100,7 @@ pub mod pallet { #[pallet::call] impl Pallet { - // TODO: Currently, we use `debug_assert!` for basic test checks against a production + // TODO: Currently, we use `debug_assert!` for easy test checks against a production // snapshot. /// Receive accounts from the Relay Chain. diff --git a/pallets/rc-migrator/Cargo.toml b/pallets/rc-migrator/Cargo.toml index a57cdf7905..73a7ad0a38 100644 --- a/pallets/rc-migrator/Cargo.toml +++ b/pallets/rc-migrator/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "pallet-rc-migrator" -description = "Asset Hub migrator pallet for Relay Chain" +description = "Operational pallet managing and processing migration from Relay Chain to Asset Hub on Relay Chain" license = "Apache-2.0" version = "0.1.0" edition.workspace = true diff --git a/pallets/rc-migrator/src/accounts.rs b/pallets/rc-migrator/src/accounts.rs index d4febe2f70..a4329cd3e1 100644 --- a/pallets/rc-migrator/src/accounts.rs +++ b/pallets/rc-migrator/src/accounts.rs @@ -19,6 +19,8 @@ /* TODO: remove this dec comment when not needed +Sources of account references + provider refs: - crowdloans: fundraising system account / https://github.com/paritytech/polkadot-sdk/blob/ace62f120fbc9ec617d6bab0a5180f0be4441537/polkadot/runtime/common/src/crowdloan/mod.rs#L416 - parachains_assigner_on_demand / on_demand: pallet's account https://github.com/paritytech/polkadot-sdk/blob/ace62f120fbc9ec617d6bab0a5180f0be4441537/polkadot/runtime/parachains/src/on_demand/mod.rs#L407 @@ -58,11 +60,14 @@ Relay: XCM teleport processed ^ The minimum what we should replay while moving accounts from Relay to AH When the Asset Hub turned to the mint authority + Relay: let checking_total = // total checking account balance Relay: burn_from(checking, checking_total) // publishes Balances::Burned event AH: let total_issuance = // total issuance on AH AH: mint_into(checking, checking_total - total_issuance) // publishes Balances::Minted event +^ Ensure that this is the desired method of communicating the mint authority change via events. + */ use crate::*; @@ -97,7 +102,7 @@ pub struct Account { pub locks: Vec>, /// Unnamed reserve. /// - /// No named reserves for Polkadot and Kusama. + /// Only unnamed reserves for Polkadot and Kusama (no named ones). pub unnamed_reserve: Balance, /// Consumer ref count of migrating to Asset Hub pallets except a reference for `reserved` and /// `frozen` balance. diff --git a/pallets/rc-migrator/src/lib.rs b/pallets/rc-migrator/src/lib.rs index 438c6f4ebc..f74139e19a 100644 --- a/pallets/rc-migrator/src/lib.rs +++ b/pallets/rc-migrator/src/lib.rs @@ -15,7 +15,19 @@ // See the License for the specific language governing permissions and // limitations under the License. -//! The helper pallet for the Asset Hub migration meant to be setup on Relay Chain. +//! The operational pallet for the Relay Chain, designed to manage and facilitate the migration of +//! subsystems such as Governance, Staking, Balances from the Relay Chain to the Asset Hub. This +//! pallet works alongside its counterpart, `pallet_ah_migrator`, which handles migration +//! processes on the Asset Hub side. +//! +//! This pallet is responsible for controlling the initiation, progression, and completion of the +//! migration process, including managing its various stages and transferring the necessary data. +//! The pallet directly accesses the storage of other pallets for read/write operations while +//! maintaining compatibility with their existing APIs. +//! +//! To simplify development and avoid the need to edit the original pallets, this pallet may +//! duplicate private items such as storage entries from the original pallets. This ensures that the +//! migration logic can be implemented without altering the original implementations. #![cfg_attr(not(feature = "std"), no_std)] @@ -56,7 +68,7 @@ pub enum MigrationStage { /// The migration has not yet started. #[default] Pending, - // Initializing + // TODO: Initializing? /// Migrating account balances. MigratingAccounts { // Last migrated account @@ -76,7 +88,8 @@ pub mod pallet { /// Paras Registrar Pallet type ParasRegistrar = paras_registrar::Pallet; - /// Super trait of all pallets the migration depends on. + /// Super config trait for all pallets that the migration depends on, providing convenient + /// access to their items. #[pallet::config] pub trait Config: frame_system::Config, AccountId = AccountId32> From f143b49356542c044080461b2e92e00c54b76bd8 Mon Sep 17 00:00:00 2001 From: muharem Date: Sun, 22 Dec 2024 13:52:03 +0100 Subject: [PATCH 04/10] undo fmt --- .../asset-hubs/asset-hub-polkadot/src/lib.rs | 138 +++++++++--------- 1 file changed, 69 insertions(+), 69 deletions(-) diff --git a/system-parachains/asset-hubs/asset-hub-polkadot/src/lib.rs b/system-parachains/asset-hubs/asset-hub-polkadot/src/lib.rs index f32bb50a5d..b3c38de64d 100644 --- a/system-parachains/asset-hubs/asset-hub-polkadot/src/lib.rs +++ b/system-parachains/asset-hubs/asset-hub-polkadot/src/lib.rs @@ -488,89 +488,89 @@ impl InstanceFilter for ProxyType { ), ProxyType::CancelProxy => matches!( c, - RuntimeCall::Proxy(pallet_proxy::Call::reject_announcement { .. }) - | RuntimeCall::Utility { .. } - | RuntimeCall::Multisig { .. } + RuntimeCall::Proxy(pallet_proxy::Call::reject_announcement { .. }) | + RuntimeCall::Utility { .. } | + RuntimeCall::Multisig { .. } ), ProxyType::Assets => { matches!( c, - RuntimeCall::Assets { .. } - | RuntimeCall::Utility { .. } - | RuntimeCall::Multisig { .. } - | RuntimeCall::Nfts { .. } - | RuntimeCall::Uniques { .. } + RuntimeCall::Assets { .. } | + RuntimeCall::Utility { .. } | + RuntimeCall::Multisig { .. } | + RuntimeCall::Nfts { .. } | + RuntimeCall::Uniques { .. } ) }, ProxyType::AssetOwner => matches!( c, - RuntimeCall::Assets(TrustBackedAssetsCall::create { .. }) - | RuntimeCall::Assets(TrustBackedAssetsCall::start_destroy { .. }) - | RuntimeCall::Assets(TrustBackedAssetsCall::destroy_accounts { .. }) - | RuntimeCall::Assets(TrustBackedAssetsCall::destroy_approvals { .. }) - | RuntimeCall::Assets(TrustBackedAssetsCall::finish_destroy { .. }) - | RuntimeCall::Assets(TrustBackedAssetsCall::transfer_ownership { .. }) - | RuntimeCall::Assets(TrustBackedAssetsCall::set_team { .. }) - | RuntimeCall::Assets(TrustBackedAssetsCall::set_metadata { .. }) - | RuntimeCall::Assets(TrustBackedAssetsCall::clear_metadata { .. }) - | RuntimeCall::Assets(TrustBackedAssetsCall::set_min_balance { .. }) - | RuntimeCall::Nfts(pallet_nfts::Call::create { .. }) - | RuntimeCall::Nfts(pallet_nfts::Call::destroy { .. }) - | RuntimeCall::Nfts(pallet_nfts::Call::redeposit { .. }) - | RuntimeCall::Nfts(pallet_nfts::Call::transfer_ownership { .. }) - | RuntimeCall::Nfts(pallet_nfts::Call::set_team { .. }) - | RuntimeCall::Nfts(pallet_nfts::Call::set_collection_max_supply { .. }) - | RuntimeCall::Nfts(pallet_nfts::Call::lock_collection { .. }) - | RuntimeCall::Uniques(pallet_uniques::Call::create { .. }) - | RuntimeCall::Uniques(pallet_uniques::Call::destroy { .. }) - | RuntimeCall::Uniques(pallet_uniques::Call::transfer_ownership { .. }) - | RuntimeCall::Uniques(pallet_uniques::Call::set_team { .. }) - | RuntimeCall::Uniques(pallet_uniques::Call::set_metadata { .. }) - | RuntimeCall::Uniques(pallet_uniques::Call::set_attribute { .. }) - | RuntimeCall::Uniques(pallet_uniques::Call::set_collection_metadata { .. }) - | RuntimeCall::Uniques(pallet_uniques::Call::clear_metadata { .. }) - | RuntimeCall::Uniques(pallet_uniques::Call::clear_attribute { .. }) - | RuntimeCall::Uniques(pallet_uniques::Call::clear_collection_metadata { .. }) - | RuntimeCall::Uniques(pallet_uniques::Call::set_collection_max_supply { .. }) - | RuntimeCall::Utility { .. } - | RuntimeCall::Multisig { .. } + RuntimeCall::Assets(TrustBackedAssetsCall::create { .. }) | + RuntimeCall::Assets(TrustBackedAssetsCall::start_destroy { .. }) | + RuntimeCall::Assets(TrustBackedAssetsCall::destroy_accounts { .. }) | + RuntimeCall::Assets(TrustBackedAssetsCall::destroy_approvals { .. }) | + RuntimeCall::Assets(TrustBackedAssetsCall::finish_destroy { .. }) | + RuntimeCall::Assets(TrustBackedAssetsCall::transfer_ownership { .. }) | + RuntimeCall::Assets(TrustBackedAssetsCall::set_team { .. }) | + RuntimeCall::Assets(TrustBackedAssetsCall::set_metadata { .. }) | + RuntimeCall::Assets(TrustBackedAssetsCall::clear_metadata { .. }) | + RuntimeCall::Assets(TrustBackedAssetsCall::set_min_balance { .. }) | + RuntimeCall::Nfts(pallet_nfts::Call::create { .. }) | + RuntimeCall::Nfts(pallet_nfts::Call::destroy { .. }) | + RuntimeCall::Nfts(pallet_nfts::Call::redeposit { .. }) | + RuntimeCall::Nfts(pallet_nfts::Call::transfer_ownership { .. }) | + RuntimeCall::Nfts(pallet_nfts::Call::set_team { .. }) | + RuntimeCall::Nfts(pallet_nfts::Call::set_collection_max_supply { .. }) | + RuntimeCall::Nfts(pallet_nfts::Call::lock_collection { .. }) | + RuntimeCall::Uniques(pallet_uniques::Call::create { .. }) | + RuntimeCall::Uniques(pallet_uniques::Call::destroy { .. }) | + RuntimeCall::Uniques(pallet_uniques::Call::transfer_ownership { .. }) | + RuntimeCall::Uniques(pallet_uniques::Call::set_team { .. }) | + RuntimeCall::Uniques(pallet_uniques::Call::set_metadata { .. }) | + RuntimeCall::Uniques(pallet_uniques::Call::set_attribute { .. }) | + RuntimeCall::Uniques(pallet_uniques::Call::set_collection_metadata { .. }) | + RuntimeCall::Uniques(pallet_uniques::Call::clear_metadata { .. }) | + RuntimeCall::Uniques(pallet_uniques::Call::clear_attribute { .. }) | + RuntimeCall::Uniques(pallet_uniques::Call::clear_collection_metadata { .. }) | + RuntimeCall::Uniques(pallet_uniques::Call::set_collection_max_supply { .. }) | + RuntimeCall::Utility { .. } | + RuntimeCall::Multisig { .. } ), ProxyType::AssetManager => matches!( c, - RuntimeCall::Assets(TrustBackedAssetsCall::mint { .. }) - | RuntimeCall::Assets(TrustBackedAssetsCall::burn { .. }) - | RuntimeCall::Assets(TrustBackedAssetsCall::freeze { .. }) - | RuntimeCall::Assets(TrustBackedAssetsCall::block { .. }) - | RuntimeCall::Assets(TrustBackedAssetsCall::thaw { .. }) - | RuntimeCall::Assets(TrustBackedAssetsCall::freeze_asset { .. }) - | RuntimeCall::Assets(TrustBackedAssetsCall::thaw_asset { .. }) - | RuntimeCall::Assets(TrustBackedAssetsCall::touch_other { .. }) - | RuntimeCall::Assets(TrustBackedAssetsCall::refund_other { .. }) - | RuntimeCall::Nfts(pallet_nfts::Call::force_mint { .. }) - | RuntimeCall::Nfts(pallet_nfts::Call::update_mint_settings { .. }) - | RuntimeCall::Nfts(pallet_nfts::Call::mint_pre_signed { .. }) - | RuntimeCall::Nfts(pallet_nfts::Call::set_attributes_pre_signed { .. }) - | RuntimeCall::Nfts(pallet_nfts::Call::lock_item_transfer { .. }) - | RuntimeCall::Nfts(pallet_nfts::Call::unlock_item_transfer { .. }) - | RuntimeCall::Nfts(pallet_nfts::Call::lock_item_properties { .. }) - | RuntimeCall::Nfts(pallet_nfts::Call::set_metadata { .. }) - | RuntimeCall::Nfts(pallet_nfts::Call::clear_metadata { .. }) - | RuntimeCall::Nfts(pallet_nfts::Call::set_collection_metadata { .. }) - | RuntimeCall::Nfts(pallet_nfts::Call::clear_collection_metadata { .. }) - | RuntimeCall::Uniques(pallet_uniques::Call::mint { .. }) - | RuntimeCall::Uniques(pallet_uniques::Call::burn { .. }) - | RuntimeCall::Uniques(pallet_uniques::Call::freeze { .. }) - | RuntimeCall::Uniques(pallet_uniques::Call::thaw { .. }) - | RuntimeCall::Uniques(pallet_uniques::Call::freeze_collection { .. }) - | RuntimeCall::Uniques(pallet_uniques::Call::thaw_collection { .. }) - | RuntimeCall::Utility { .. } - | RuntimeCall::Multisig { .. } + RuntimeCall::Assets(TrustBackedAssetsCall::mint { .. }) | + RuntimeCall::Assets(TrustBackedAssetsCall::burn { .. }) | + RuntimeCall::Assets(TrustBackedAssetsCall::freeze { .. }) | + RuntimeCall::Assets(TrustBackedAssetsCall::block { .. }) | + RuntimeCall::Assets(TrustBackedAssetsCall::thaw { .. }) | + RuntimeCall::Assets(TrustBackedAssetsCall::freeze_asset { .. }) | + RuntimeCall::Assets(TrustBackedAssetsCall::thaw_asset { .. }) | + RuntimeCall::Assets(TrustBackedAssetsCall::touch_other { .. }) | + RuntimeCall::Assets(TrustBackedAssetsCall::refund_other { .. }) | + RuntimeCall::Nfts(pallet_nfts::Call::force_mint { .. }) | + RuntimeCall::Nfts(pallet_nfts::Call::update_mint_settings { .. }) | + RuntimeCall::Nfts(pallet_nfts::Call::mint_pre_signed { .. }) | + RuntimeCall::Nfts(pallet_nfts::Call::set_attributes_pre_signed { .. }) | + RuntimeCall::Nfts(pallet_nfts::Call::lock_item_transfer { .. }) | + RuntimeCall::Nfts(pallet_nfts::Call::unlock_item_transfer { .. }) | + RuntimeCall::Nfts(pallet_nfts::Call::lock_item_properties { .. }) | + RuntimeCall::Nfts(pallet_nfts::Call::set_metadata { .. }) | + RuntimeCall::Nfts(pallet_nfts::Call::clear_metadata { .. }) | + RuntimeCall::Nfts(pallet_nfts::Call::set_collection_metadata { .. }) | + RuntimeCall::Nfts(pallet_nfts::Call::clear_collection_metadata { .. }) | + RuntimeCall::Uniques(pallet_uniques::Call::mint { .. }) | + RuntimeCall::Uniques(pallet_uniques::Call::burn { .. }) | + RuntimeCall::Uniques(pallet_uniques::Call::freeze { .. }) | + RuntimeCall::Uniques(pallet_uniques::Call::thaw { .. }) | + RuntimeCall::Uniques(pallet_uniques::Call::freeze_collection { .. }) | + RuntimeCall::Uniques(pallet_uniques::Call::thaw_collection { .. }) | + RuntimeCall::Utility { .. } | + RuntimeCall::Multisig { .. } ), ProxyType::Collator => matches!( c, - RuntimeCall::CollatorSelection { .. } - | RuntimeCall::Utility { .. } - | RuntimeCall::Multisig { .. } + RuntimeCall::CollatorSelection { .. } | + RuntimeCall::Utility { .. } | + RuntimeCall::Multisig { .. } ), } } From 8db8a04839c374c0465796bb49cc19658fdb9c98 Mon Sep 17 00:00:00 2001 From: Oliver Tale-Yazdi Date: Mon, 6 Jan 2025 14:45:57 +0100 Subject: [PATCH 05/10] Review fixes Signed-off-by: Oliver Tale-Yazdi --- pallets/ah-migrator/src/lib.rs | 2 +- pallets/rc-migrator/src/accounts.rs | 2 +- pallets/rc-migrator/src/lib.rs | 4 ++-- pallets/rc-migrator/src/types.rs | 2 ++ relay/polkadot/tests/ahm/mod.rs | 7 +++++++ 5 files changed, 13 insertions(+), 4 deletions(-) diff --git a/pallets/ah-migrator/src/lib.rs b/pallets/ah-migrator/src/lib.rs index 4078ae1cc4..d4e950b8b1 100644 --- a/pallets/ah-migrator/src/lib.rs +++ b/pallets/ah-migrator/src/lib.rs @@ -89,7 +89,7 @@ pub mod pallet { } #[pallet::event] - #[pallet::generate_deposit(pub(crate) fn deposit_event)] + //#[pallet::generate_deposit(pub(crate) fn deposit_event)] pub enum Event { /// TODO TODO, diff --git a/pallets/rc-migrator/src/accounts.rs b/pallets/rc-migrator/src/accounts.rs index a4329cd3e1..a7e763ffe9 100644 --- a/pallets/rc-migrator/src/accounts.rs +++ b/pallets/rc-migrator/src/accounts.rs @@ -49,8 +49,8 @@ TODO: remove when not needed Regular native asset teleport from Relay (mint authority) to Asset Hub looks like: -Relay: mint_into(checking, amount) // publishes Balances::Minted event Relay: burn_from(source, amount) // publishes Balances::Burned event +Relay: mint_into(checking, amount) // publishes Balances::Minted event Relay: no effect on total issuance Relay: XCM with teleport sent AH: mint_into(dest, amount) // publishes Balances::Minted event diff --git a/pallets/rc-migrator/src/lib.rs b/pallets/rc-migrator/src/lib.rs index f74139e19a..72a21d5157 100644 --- a/pallets/rc-migrator/src/lib.rs +++ b/pallets/rc-migrator/src/lib.rs @@ -129,7 +129,7 @@ pub mod pallet { } #[pallet::event] - #[pallet::generate_deposit(pub(crate) fn deposit_event)] + //#[pallet::generate_deposit(pub(crate) fn deposit_event)] pub enum Event { /// TODO TODO, @@ -169,7 +169,7 @@ pub mod pallet { /// TODO #[pallet::call_index(0)] #[pallet::weight({1})] - pub fn _do_something(_origin: OriginFor) -> DispatchResultWithPostInfo { + pub fn do_something(_origin: OriginFor) -> DispatchResultWithPostInfo { Ok(().into()) } } diff --git a/pallets/rc-migrator/src/types.rs b/pallets/rc-migrator/src/types.rs index 2a5e05e04f..9fb0891c4b 100644 --- a/pallets/rc-migrator/src/types.rs +++ b/pallets/rc-migrator/src/types.rs @@ -33,6 +33,8 @@ pub enum AhMigratorCall { } /// Copy of `ParaInfo` type from `paras_registrar` pallet. +/// +/// From: https://github.com/paritytech/polkadot-sdk/blob/b7afe48ed0bfef30836e7ca6359c2d8bb594d16e/polkadot/runtime/common/src/paras_registrar/mod.rs#L50-L59 #[derive(Encode, Decode, Clone, PartialEq, Eq, Default, RuntimeDebug, TypeInfo)] pub struct ParaInfo { /// The account that has placed a deposit for registering this para. diff --git a/relay/polkadot/tests/ahm/mod.rs b/relay/polkadot/tests/ahm/mod.rs index ec59e42cb7..6b808444b2 100644 --- a/relay/polkadot/tests/ahm/mod.rs +++ b/relay/polkadot/tests/ahm/mod.rs @@ -25,6 +25,13 @@ use polkadot_runtime::{RcMigrator, Block, Runtime as T, System, *}; // General imports use remote_externalities::{Builder, Mode, OfflineConfig, RemoteExternalities}; +/// Create externalities that have their state initialized from a snapshot. +/// +/// The path to the snapshot must be provided through the environment variable `SNAP`. If if is not +/// set, this function will return `None`. +/// +/// You can create such a snapshot with the [`try-runtime-cli`](https://github.com/paritytech/try-runtime-cli). For example: +/// `try-runtime create-snapshot --uri wss://rpc.polkadot.io:443 polkadot.snap`. async fn remote_ext_test_setup() -> Option> { sp_tracing::try_init_simple(); let Some(snap) = std::env::var("SNAP").ok() else{ From 1f5c05cacad584b9a61697e2029e515d4875dbfe Mon Sep 17 00:00:00 2001 From: Oliver Tale-Yazdi Date: Mon, 6 Jan 2025 14:46:08 +0100 Subject: [PATCH 06/10] fmt Signed-off-by: Oliver Tale-Yazdi --- relay/polkadot/tests/ahm/accounts.rs | 4 +++- relay/polkadot/tests/ahm/mod.rs | 8 +++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/relay/polkadot/tests/ahm/accounts.rs b/relay/polkadot/tests/ahm/accounts.rs index a027fc0972..1220da9faa 100644 --- a/relay/polkadot/tests/ahm/accounts.rs +++ b/relay/polkadot/tests/ahm/accounts.rs @@ -20,7 +20,9 @@ use super::*; #[tokio::test] async fn account_test() { - let Some(mut ext) = remote_ext_test_setup().await else { return; }; + let Some(mut ext) = remote_ext_test_setup().await else { + return; + }; ext.execute_with(|| { let _ = RcMigrator::obtain_rc_accounts(); diff --git a/relay/polkadot/tests/ahm/mod.rs b/relay/polkadot/tests/ahm/mod.rs index 6b808444b2..cb5bb46925 100644 --- a/relay/polkadot/tests/ahm/mod.rs +++ b/relay/polkadot/tests/ahm/mod.rs @@ -20,7 +20,7 @@ mod accounts; // Runtime specific imports // Use general aliases for the imports to make it easier to copy&paste the tests for other runtimes. -use polkadot_runtime::{RcMigrator, Block, Runtime as T, System, *}; +use polkadot_runtime::{Block, RcMigrator, Runtime as T, System, *}; // General imports use remote_externalities::{Builder, Mode, OfflineConfig, RemoteExternalities}; @@ -34,15 +34,13 @@ use remote_externalities::{Builder, Mode, OfflineConfig, RemoteExternalities}; /// `try-runtime create-snapshot --uri wss://rpc.polkadot.io:443 polkadot.snap`. async fn remote_ext_test_setup() -> Option> { sp_tracing::try_init_simple(); - let Some(snap) = std::env::var("SNAP").ok() else{ + let Some(snap) = std::env::var("SNAP").ok() else { return None; }; let abs = std::path::absolute(snap.clone()); let ext = Builder::::default() - .mode(Mode::Offline( - OfflineConfig { state_snapshot: snap.clone().into() }, - )) + .mode(Mode::Offline(OfflineConfig { state_snapshot: snap.clone().into() })) .build() .await .map_err(|e| { From 751010e67460acc3dae4e5b5e5db7c635edde315 Mon Sep 17 00:00:00 2001 From: Oliver Tale-Yazdi Date: Mon, 6 Jan 2025 14:54:20 +0100 Subject: [PATCH 07/10] clippy Signed-off-by: Oliver Tale-Yazdi --- pallets/ah-migrator/src/lib.rs | 14 +++++--------- pallets/rc-migrator/src/accounts.rs | 2 +- pallets/rc-migrator/src/lib.rs | 2 +- relay/polkadot/tests/ahm/mod.rs | 4 +--- .../asset-hubs/asset-hub-polkadot/src/migration.rs | 2 +- 5 files changed, 9 insertions(+), 15 deletions(-) diff --git a/pallets/ah-migrator/src/lib.rs b/pallets/ah-migrator/src/lib.rs index d4e950b8b1..80a97795ea 100644 --- a/pallets/ah-migrator/src/lib.rs +++ b/pallets/ah-migrator/src/lib.rs @@ -123,21 +123,17 @@ pub mod pallet { debug_assert!(minted == total_balance); for hold in account.holds { - let _ = T::Currency::hold( - &T::RcToAhHoldReason::convert(hold.id), - &who, - hold.amount, - ) - // TODO handle error - .unwrap(); + T::Currency::hold(&T::RcToAhHoldReason::convert(hold.id), &who, hold.amount) + // TODO handle error + .unwrap(); } - let _ = T::Currency::reserve(&who, account.unnamed_reserve) + T::Currency::reserve(&who, account.unnamed_reserve) // TODO handle error .unwrap(); for freeze in account.freezes { - let _ = T::Currency::set_freeze( + T::Currency::set_freeze( &T::RcToAhFreezeReason::convert(freeze.id), &who, freeze.amount, diff --git a/pallets/rc-migrator/src/accounts.rs b/pallets/rc-migrator/src/accounts.rs index a7e763ffe9..992e9db9ec 100644 --- a/pallets/rc-migrator/src/accounts.rs +++ b/pallets/rc-migrator/src/accounts.rs @@ -244,7 +244,7 @@ impl Pallet { pallet_balances::Freezes::::get(&who).into(); for freeze in &freezes { - let _ = ::Currency::thaw(&freeze.id, &who) + ::Currency::thaw(&freeze.id, &who) // TODO: handle error .unwrap(); } diff --git a/pallets/rc-migrator/src/lib.rs b/pallets/rc-migrator/src/lib.rs index 72a21d5157..b411f09241 100644 --- a/pallets/rc-migrator/src/lib.rs +++ b/pallets/rc-migrator/src/lib.rs @@ -218,7 +218,7 @@ pub mod pallet { return weight_counter.consumed(); }; - return weight_counter.consumed(); + weight_counter.consumed() } } } diff --git a/relay/polkadot/tests/ahm/mod.rs b/relay/polkadot/tests/ahm/mod.rs index cb5bb46925..31b6c6d474 100644 --- a/relay/polkadot/tests/ahm/mod.rs +++ b/relay/polkadot/tests/ahm/mod.rs @@ -34,9 +34,7 @@ use remote_externalities::{Builder, Mode, OfflineConfig, RemoteExternalities}; /// `try-runtime create-snapshot --uri wss://rpc.polkadot.io:443 polkadot.snap`. async fn remote_ext_test_setup() -> Option> { sp_tracing::try_init_simple(); - let Some(snap) = std::env::var("SNAP").ok() else { - return None; - }; + let snap = std::env::var("SNAP").ok()?; let abs = std::path::absolute(snap.clone()); let ext = Builder::::default() diff --git a/system-parachains/asset-hubs/asset-hub-polkadot/src/migration.rs b/system-parachains/asset-hubs/asset-hub-polkadot/src/migration.rs index bd482deba0..5545106824 100644 --- a/system-parachains/asset-hubs/asset-hub-polkadot/src/migration.rs +++ b/system-parachains/asset-hubs/asset-hub-polkadot/src/migration.rs @@ -47,7 +47,7 @@ impl Convert for RcToAhHoldReason { pub struct RcToAhFreezeReason; impl Convert for RcToAhFreezeReason { - fn convert(a: RcFreezeReason) -> () { + fn convert(a: RcFreezeReason) { match a { // TODO mapping _ => (), From c3e60caa28c334796d4bb4e788be8efa9705c34e Mon Sep 17 00:00:00 2001 From: Oliver Tale-Yazdi Date: Mon, 6 Jan 2025 15:01:40 +0100 Subject: [PATCH 08/10] zepter Signed-off-by: Oliver Tale-Yazdi --- pallets/ah-migrator/Cargo.toml | 3 +++ pallets/rc-migrator/Cargo.toml | 3 +++ relay/polkadot/Cargo.toml | 3 +++ 3 files changed, 9 insertions(+) diff --git a/pallets/ah-migrator/Cargo.toml b/pallets/ah-migrator/Cargo.toml index c4e2471362..d4de4c04c7 100644 --- a/pallets/ah-migrator/Cargo.toml +++ b/pallets/ah-migrator/Cargo.toml @@ -53,6 +53,8 @@ std = [ "pallet-nomination-pools/std", "polkadot-runtime-common/std", "runtime-parachains/std", + "log/std", + "polkadot-parachain-primitives/std" ] runtime-benchmarks = [ "frame-benchmarking/runtime-benchmarks", @@ -67,6 +69,7 @@ runtime-benchmarks = [ "pallet-nomination-pools/runtime-benchmarks", "polkadot-runtime-common/runtime-benchmarks", "runtime-parachains/runtime-benchmarks", + "polkadot-parachain-primitives/runtime-benchmarks" ] try-runtime = [ "frame-support/try-runtime", diff --git a/pallets/rc-migrator/Cargo.toml b/pallets/rc-migrator/Cargo.toml index 73a7ad0a38..9b3c7f8ead 100644 --- a/pallets/rc-migrator/Cargo.toml +++ b/pallets/rc-migrator/Cargo.toml @@ -48,6 +48,8 @@ std = [ "polkadot-runtime-common/std", "runtime-parachains/std", "xcm/std", + "log/std", + "polkadot-parachain-primitives/std" ] runtime-benchmarks = [ "frame-benchmarking/runtime-benchmarks", @@ -58,6 +60,7 @@ runtime-benchmarks = [ "pallet-staking/runtime-benchmarks", "polkadot-runtime-common/runtime-benchmarks", "runtime-parachains/runtime-benchmarks", + "polkadot-parachain-primitives/runtime-benchmarks" ] try-runtime = [ "frame-support/try-runtime", diff --git a/relay/polkadot/Cargo.toml b/relay/polkadot/Cargo.toml index 932478a9dd..67aeb83c73 100644 --- a/relay/polkadot/Cargo.toml +++ b/relay/polkadot/Cargo.toml @@ -228,6 +228,7 @@ std = [ "xcm-executor/std", "xcm-runtime-apis/std", "xcm/std", + "pallet-ah-migrator/std" ] runtime-benchmarks = [ "pallet-rc-migrator/runtime-benchmarks", @@ -282,6 +283,7 @@ runtime-benchmarks = [ "xcm-builder/runtime-benchmarks", "xcm-executor/runtime-benchmarks", "xcm-runtime-apis/runtime-benchmarks", + "pallet-ah-migrator/runtime-benchmarks" ] try-runtime = [ "pallet-rc-migrator/try-runtime", @@ -331,6 +333,7 @@ try-runtime = [ "polkadot-runtime-common/try-runtime", "runtime-parachains/try-runtime", "sp-runtime/try-runtime", + "pallet-ah-migrator/try-runtime" ] # Enable metadata hash generation at compile time for the `CheckMetadataHash` extension. From b6a88cf9dd1f85b3a0d4f19862fbf6cabbf19853 Mon Sep 17 00:00:00 2001 From: Oliver Tale-Yazdi Date: Mon, 6 Jan 2025 15:13:21 +0100 Subject: [PATCH 09/10] Silence annoying CI warnings for the moment Signed-off-by: Oliver Tale-Yazdi --- .github/workflows/clippy.yml | 2 +- .github/workflows/test.yml | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/.github/workflows/clippy.yml b/.github/workflows/clippy.yml index a5dc42a6eb..30719f84fa 100644 --- a/.github/workflows/clippy.yml +++ b/.github/workflows/clippy.yml @@ -39,5 +39,5 @@ jobs: - name: Clippy run: cargo clippy --all-targets --locked -q env: - RUSTFLAGS: "-D warnings" + #RUSTFLAGS: "-D warnings" FAIL-CI re-enable after AHM SKIP_WASM_BUILD: 1 diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 31fce66445..4a236aaa35 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -95,12 +95,12 @@ jobs: - name: Test ${{ matrix.runtime.name }} run: cargo test -p ${{ matrix.runtime.package }} --release --locked -q env: - RUSTFLAGS: "-C debug-assertions -D warnings" + RUSTFLAGS: "-C debug-assertions" # FAIL-CI "-D warnings" re-enable after AHM dev branch - name: Test all features ${{ matrix.runtime.name }} run: cargo test -p ${{ matrix.runtime.package }} --release --locked -q --all-features env: - RUSTFLAGS: "-C debug-assertions -D warnings" + RUSTFLAGS: "-C debug-assertions" # FAIL-CI "-D warnings" re-enable after AHM dev branch SKIP_WASM_BUILD: 1 - name: Test benchmarks ${{ matrix.runtime.name }} @@ -115,7 +115,7 @@ jobs: echo "Running benchmarking for RUNTIME_BLOB_PATH=$RUNTIME_BLOB_PATH" ./frame-omni-bencher v1 benchmark pallet --runtime $RUNTIME_BLOB_PATH --all --steps 2 --repeat 1 env: - RUSTFLAGS: "-C debug-assertions -D warnings" + RUSTFLAGS: "-C debug-assertions" # FAIL-CI "-D warnings" re-enable after AHM dev branch # Job required by "confirmTestPassed" integration-test: @@ -165,7 +165,7 @@ jobs: - name: Test ${{ matrix.itest.name }} run: cargo test -p ${{ matrix.itest.package }} --release --locked -q env: - RUSTFLAGS: "-C debug-assertions -D warnings" + RUSTFLAGS: "-C debug-assertions" # FAIL-CI "-D warnings" re-enable after AHM dev branch # Job required by "confirmTestPassed" build-chain-spec-generator: @@ -211,7 +211,7 @@ jobs: - name: Build run: cargo test -p chain-spec-generator --release --locked -q --features=runtime-benchmarks env: - RUSTFLAGS: "-C debug-assertions -D warnings" + RUSTFLAGS: "-C debug-assertions" # FAIL-CI "-D warnings" re-enable after AHM dev branch SKIP_WASM_BUILD: 1 # Job required by "confirmTestPassed" From 821abb6304a6d9ef55c4708c6358950a81b7a8e1 Mon Sep 17 00:00:00 2001 From: Oliver Tale-Yazdi Date: Mon, 6 Jan 2025 15:17:16 +0100 Subject: [PATCH 10/10] fmt Signed-off-by: Oliver Tale-Yazdi --- Cargo.toml | 4 ---- pallets/ah-migrator/Cargo.toml | 42 +++++++++++++++++----------------- pallets/rc-migrator/Cargo.toml | 22 +++++++++--------- relay/polkadot/Cargo.toml | 6 ++--- 4 files changed, 35 insertions(+), 39 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 9d08e0fd60..03f8dafce8 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -6,12 +6,8 @@ repository = "https://github.com/polkadot-fellows/runtimes.git" license = "GPL-3.0-only" # TODO [workspace.dependencies] - -# Asset Hub Migration concerning deps pallet-rc-migrator = { path = "pallets/rc-migrator", default-features = false } pallet-ah-migrator = { path = "pallets/ah-migrator", default-features = false } -# End: Asset Hub Migration concerning deps - assert_matches = { version = "1.5.0" } approx = { version = "0.5.1" } asset-hub-kusama-emulated-chain = { path = "integration-tests/emulated/chains/parachains/assets/asset-hub-kusama" } diff --git a/pallets/ah-migrator/Cargo.toml b/pallets/ah-migrator/Cargo.toml index d4de4c04c7..7b30f70b2b 100644 --- a/pallets/ah-migrator/Cargo.toml +++ b/pallets/ah-migrator/Cargo.toml @@ -33,54 +33,54 @@ runtime-parachains = { workspace = true } polkadot-parachain-primitives = { workspace = true } [features] -default = ["std"] +default = ["std"] std = [ "codec/std", "frame-benchmarking?/std", "frame-support/std", "frame-system/std", - "scale-info/std", - "serde", - "sp-core/std", - "sp-runtime/std", - "sp-std/std", - "sp-io/std", - "pallet-rc-migrator/std", + "log/std", "pallet-balances/std", - "pallet-staking/std", + "pallet-nomination-pools/std", "pallet-preimage/std", + "pallet-rc-migrator/std", + "pallet-staking/std", "pallet-state-trie-migration/std", - "pallet-nomination-pools/std", + "polkadot-parachain-primitives/std", "polkadot-runtime-common/std", "runtime-parachains/std", - "log/std", - "polkadot-parachain-primitives/std" + "scale-info/std", + "serde", + "sp-core/std", + "sp-io/std", + "sp-runtime/std", + "sp-std/std", ] runtime-benchmarks = [ "frame-benchmarking/runtime-benchmarks", "frame-support/runtime-benchmarks", "frame-system/runtime-benchmarks", - "sp-runtime/runtime-benchmarks", - "pallet-rc-migrator/runtime-benchmarks", "pallet-balances/runtime-benchmarks", - "pallet-staking/runtime-benchmarks", + "pallet-nomination-pools/runtime-benchmarks", "pallet-preimage/runtime-benchmarks", + "pallet-rc-migrator/runtime-benchmarks", + "pallet-staking/runtime-benchmarks", "pallet-state-trie-migration/runtime-benchmarks", - "pallet-nomination-pools/runtime-benchmarks", + "polkadot-parachain-primitives/runtime-benchmarks", "polkadot-runtime-common/runtime-benchmarks", "runtime-parachains/runtime-benchmarks", - "polkadot-parachain-primitives/runtime-benchmarks" + "sp-runtime/runtime-benchmarks", ] try-runtime = [ "frame-support/try-runtime", "frame-system/try-runtime", - "sp-runtime/try-runtime", - "pallet-rc-migrator/try-runtime", "pallet-balances/try-runtime", - "pallet-staking/try-runtime", + "pallet-nomination-pools/try-runtime", "pallet-preimage/try-runtime", + "pallet-rc-migrator/try-runtime", + "pallet-staking/try-runtime", "pallet-state-trie-migration/try-runtime", - "pallet-nomination-pools/try-runtime", "polkadot-runtime-common/try-runtime", "runtime-parachains/try-runtime", + "sp-runtime/try-runtime", ] diff --git a/pallets/rc-migrator/Cargo.toml b/pallets/rc-migrator/Cargo.toml index 9b3c7f8ead..7a83f4fb1c 100644 --- a/pallets/rc-migrator/Cargo.toml +++ b/pallets/rc-migrator/Cargo.toml @@ -31,43 +31,43 @@ polkadot-parachain-primitives = { workspace = true } xcm = { workspace = true } [features] -default = ["std"] +default = ["std"] std = [ "codec/std", "frame-benchmarking?/std", "frame-support/std", "frame-system/std", + "log/std", + "pallet-balances/std", + "pallet-staking/std", + "polkadot-parachain-primitives/std", + "polkadot-runtime-common/std", + "runtime-parachains/std", "scale-info/std", "serde", "sp-core/std", + "sp-io/std", "sp-runtime/std", "sp-std/std", - "sp-io/std", - "pallet-balances/std", - "pallet-staking/std", - "polkadot-runtime-common/std", - "runtime-parachains/std", "xcm/std", - "log/std", - "polkadot-parachain-primitives/std" ] runtime-benchmarks = [ "frame-benchmarking/runtime-benchmarks", "frame-support/runtime-benchmarks", "frame-system/runtime-benchmarks", - "sp-runtime/runtime-benchmarks", "pallet-balances/runtime-benchmarks", "pallet-staking/runtime-benchmarks", + "polkadot-parachain-primitives/runtime-benchmarks", "polkadot-runtime-common/runtime-benchmarks", "runtime-parachains/runtime-benchmarks", - "polkadot-parachain-primitives/runtime-benchmarks" + "sp-runtime/runtime-benchmarks", ] try-runtime = [ "frame-support/try-runtime", "frame-system/try-runtime", - "sp-runtime/try-runtime", "pallet-balances/try-runtime", "pallet-staking/try-runtime", "polkadot-runtime-common/try-runtime", "runtime-parachains/try-runtime", + "sp-runtime/try-runtime", ] diff --git a/relay/polkadot/Cargo.toml b/relay/polkadot/Cargo.toml index 67aeb83c73..5176168fba 100644 --- a/relay/polkadot/Cargo.toml +++ b/relay/polkadot/Cargo.toml @@ -151,6 +151,7 @@ std = [ "frame-system/std", "frame-try-runtime/std", "log/std", + "pallet-ah-migrator/std", "pallet-asset-rate/std", "pallet-authority-discovery/std", "pallet-authorship/std", @@ -228,7 +229,6 @@ std = [ "xcm-executor/std", "xcm-runtime-apis/std", "xcm/std", - "pallet-ah-migrator/std" ] runtime-benchmarks = [ "pallet-rc-migrator/runtime-benchmarks", @@ -238,6 +238,7 @@ runtime-benchmarks = [ "frame-support/runtime-benchmarks", "frame-system-benchmarking/runtime-benchmarks", "frame-system/runtime-benchmarks", + "pallet-ah-migrator/runtime-benchmarks", "pallet-asset-rate/runtime-benchmarks", "pallet-babe/runtime-benchmarks", "pallet-bags-list/runtime-benchmarks", @@ -283,7 +284,6 @@ runtime-benchmarks = [ "xcm-builder/runtime-benchmarks", "xcm-executor/runtime-benchmarks", "xcm-runtime-apis/runtime-benchmarks", - "pallet-ah-migrator/runtime-benchmarks" ] try-runtime = [ "pallet-rc-migrator/try-runtime", @@ -294,6 +294,7 @@ try-runtime = [ "frame-system/try-runtime", "frame-try-runtime", "frame-try-runtime/try-runtime", + "pallet-ah-migrator/try-runtime", "pallet-asset-rate/try-runtime", "pallet-authority-discovery/try-runtime", "pallet-authorship/try-runtime", @@ -333,7 +334,6 @@ try-runtime = [ "polkadot-runtime-common/try-runtime", "runtime-parachains/try-runtime", "sp-runtime/try-runtime", - "pallet-ah-migrator/try-runtime" ] # Enable metadata hash generation at compile time for the `CheckMetadataHash` extension.