From dde99603d7dbd6b8bf541d57eb30d9c07a4fce32 Mon Sep 17 00:00:00 2001 From: Oliver Tale-Yazdi Date: Wed, 8 Jan 2025 16:51:46 +0100 Subject: [PATCH] [AHM] Improve account migration (#532) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 👉 To be merged into the AHM working branch. Changes: - Clean up AH and RC account migration code - Add error logging - Mint Relay blocks until no more account can be moved - Mint AH blocks until all DMP messages are consumed - [x] Does not require a CHANGELOG entry --------- Signed-off-by: Oliver Tale-Yazdi --- Cargo.lock | 1 + integration-tests/ahm/src/mock.rs | 2 + integration-tests/ahm/src/tests.rs | 58 +++-- pallets/ah-migrator/Cargo.toml | 27 ++- pallets/ah-migrator/src/lib.rs | 136 +++++++----- pallets/rc-migrator/src/accounts.rs | 322 +++++++++++++++------------- pallets/rc-migrator/src/lib.rs | 28 +-- relay/polkadot/src/lib.rs | 4 +- 8 files changed, 337 insertions(+), 241 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index a057f4dc1e..fbad58d4f8 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -7643,6 +7643,7 @@ dependencies = [ "polkadot-runtime-parachains", "scale-info", "serde", + "sp-application-crypto 38.0.0", "sp-core 34.0.0", "sp-io 38.0.0", "sp-runtime 39.0.2", diff --git a/integration-tests/ahm/src/mock.rs b/integration-tests/ahm/src/mock.rs index d27a9f8701..529cef3f10 100644 --- a/integration-tests/ahm/src/mock.rs +++ b/integration-tests/ahm/src/mock.rs @@ -56,6 +56,7 @@ pub fn next_block_rc() { log::info!(target: LOG_RC, "Next block: {:?}", now + 1); >::on_finalize(now); frame_system::Pallet::::set_block_number(now + 1); + frame_system::Pallet::::reset_events(); >::on_initialize( now + 1, ); @@ -69,5 +70,6 @@ pub fn next_block_ah() { ); frame_system::Pallet::::set_block_number(now + 1); >::on_initialize(now + 1); + frame_system::Pallet::::reset_events(); >::on_initialize(now + 1); } diff --git a/integration-tests/ahm/src/tests.rs b/integration-tests/ahm/src/tests.rs index 083bd3ed46..fdeec6a55a 100644 --- a/integration-tests/ahm/src/tests.rs +++ b/integration-tests/ahm/src/tests.rs @@ -34,6 +34,7 @@ use cumulus_primitives_core::{AggregateMessageOrigin, ParaId}; use frame_support::{pallet_prelude::*, traits::*, weights::WeightMeter}; use pallet_rc_migrator::RcMigrationStage; +use polkadot_primitives::InboundDownwardMessage; use polkadot_runtime::RcMigrator; use sp_core::H256; use sp_io::TestExternalities; @@ -48,34 +49,63 @@ use super::mock::*; #[tokio::test(flavor = "multi_thread", worker_threads = 2)] async fn account_migration_works() { let Some((mut rc, mut ah)) = load_externalities().await else { return }; + let para_id = ParaId::from(1000); // Simulate 10 relay blocks and grab the DMP messages let dmp_messages = rc.execute_with(|| { - for _ in 0..10 { + let mut dmps = Vec::new(); + + // Loop until no more DMPs are added and we had at least 1 + loop { next_block_rc(); + + let new_dmps = + runtime_parachains::dmp::DownwardMessageQueues::::take(para_id); + if new_dmps.is_empty() && !dmps.is_empty() { + break; + } + dmps.extend(new_dmps); } - // DMP: - let para_id = ParaId::from(1000); - runtime_parachains::dmp::DownwardMessageQueues::::take(para_id) + dmps }); rc.commit_all().unwrap(); log::info!("Num of RC->AH DMP messages: {}", dmp_messages.len()); // Inject the DMP messages into the Asset Hub ah.execute_with(|| { - // We bypass `set_validation_data` and `enqueue_inbound_downward_messages` by just directly - // enqueuing them. - for msg in dmp_messages { - let bounded_msg: BoundedVec = msg.msg.try_into().expect("DMP message too big"); - asset_hub_polkadot_runtime::MessageQueue::enqueue_message( - bounded_msg.as_bounded_slice(), - AggregateMessageOrigin::Parent, - ); - } + let mut fp = + asset_hub_polkadot_runtime::MessageQueue::footprint(AggregateMessageOrigin::Parent); + enqueue_dmp(dmp_messages); - for _ in 0..10 { + // Loop until no more DMPs are queued + loop { + let new_fp = + asset_hub_polkadot_runtime::MessageQueue::footprint(AggregateMessageOrigin::Parent); + if fp == new_fp { + log::info!("AH DMP messages left: {}", fp.storage.count); + break; + } + fp = new_fp; + + log::debug!("AH DMP messages left: {}", fp.storage.count); next_block_ah(); } + // NOTE that the DMP queue is probably not empty because the snapshot that we use contains + // some overweight ones. }); } + +/// Enqueue DMP messages on the parachain side. +/// +/// This bypasses `set_validation_data` and `enqueue_inbound_downward_messages` by just directly +/// enqueuing them. +fn enqueue_dmp(msgs: Vec) { + for msg in msgs { + let bounded_msg: BoundedVec = msg.msg.try_into().expect("DMP message too big"); + asset_hub_polkadot_runtime::MessageQueue::enqueue_message( + bounded_msg.as_bounded_slice(), + AggregateMessageOrigin::Parent, + ); + } +} diff --git a/pallets/ah-migrator/Cargo.toml b/pallets/ah-migrator/Cargo.toml index 7b30f70b2b..491d55cb78 100644 --- a/pallets/ah-migrator/Cargo.toml +++ b/pallets/ah-migrator/Cargo.toml @@ -9,28 +9,26 @@ 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 } +log = { workspace = true } pallet-balances = { workspace = true } -pallet-staking = { workspace = true } +pallet-nomination-pools = { workspace = true } pallet-preimage = { workspace = true } +pallet-rc-migrator = { workspace = true } +pallet-staking = { workspace = true } pallet-state-trie-migration = { workspace = true } -pallet-nomination-pools = { workspace = true } - +polkadot-parachain-primitives = { workspace = true } polkadot-runtime-common = { workspace = true } runtime-parachains = { workspace = true } -polkadot-parachain-primitives = { workspace = true } +scale-info = { workspace = true, features = ["derive"] } +serde = { features = ["derive"], optional = true, workspace = true } +sp-application-crypto = { workspace = true } +sp-core = { workspace = true } +sp-io = { workspace = true } +sp-runtime = { workspace = true } +sp-std = { workspace = true } [features] default = ["std"] @@ -51,6 +49,7 @@ std = [ "runtime-parachains/std", "scale-info/std", "serde", + "sp-application-crypto/std", "sp-core/std", "sp-io/std", "sp-runtime/std", diff --git a/pallets/ah-migrator/src/lib.rs b/pallets/ah-migrator/src/lib.rs index 80a97795ea..467b115b6a 100644 --- a/pallets/ah-migrator/src/lib.rs +++ b/pallets/ah-migrator/src/lib.rs @@ -36,6 +36,7 @@ pub use pallet::*; use frame_support::{ pallet_prelude::*, + storage::{transactional::with_transaction_opaque_err, TransactionOutcome}, traits::{ fungible::{InspectFreeze, Mutate, MutateFreeze, MutateHold}, LockableCurrency, ReservableCurrency, WithdrawReasons as LockWithdrawReasons, @@ -44,6 +45,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_application_crypto::Ss58Codec; use sp_runtime::{traits::Convert, AccountId32}; use sp_std::prelude::*; @@ -111,66 +113,104 @@ pub mod pallet { pub fn receive_accounts( origin: OriginFor, accounts: Vec>, - ) -> DispatchResultWithPostInfo { + ) -> DispatchResult { ensure_root(origin)?; + Self::do_receive_accounts(accounts)?; + // TODO: publish event + + Ok(()) + } + } + + impl Pallet { + fn do_receive_accounts( + accounts: Vec>, + ) -> Result<(), Error> { + log::debug!(target: LOG_TARGET, "Integrating {} accounts", accounts.len()); + 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 _: Result<(), ()> = with_transaction_opaque_err::<(), (), _>(|| { + match Self::do_receive_account(account) { + Ok(()) => TransactionOutcome::Commit(Ok(())), + Err(_) => TransactionOutcome::Rollback(Ok(())), + } + }) + .expect("Always returning Ok; qed"); + } + + Ok(()) + } + + /// MAY CHANGED STORAGE ON ERROR RETURN + fn do_receive_account( + account: RcAccount, + ) -> Result<(), Error> { + let who = account.who; + let total_balance = account.free + account.reserved; + let minted = match T::Currency::mint_into(&who, total_balance) { + Ok(minted) => minted, + Err(e) => { + log::error!(target: LOG_TARGET, "Failed to mint into account {}: {:?}", who.to_ss58check(), e); + return Err(Error::::TODO); + }, + }; + debug_assert!(minted == total_balance); + + for hold in account.holds { + if let Err(e) = T::Currency::hold(&T::RcToAhHoldReason::convert(hold.id), &who, hold.amount) - // TODO handle error - .unwrap(); + { + log::error!(target: LOG_TARGET, "Failed to hold into account {}: {:?}", who.to_ss58check(), e); + return Err(Error::::TODO); } + } - T::Currency::reserve(&who, account.unnamed_reserve) - // TODO handle error - .unwrap(); - - for freeze in account.freezes { - T::Currency::set_freeze( - &T::RcToAhFreezeReason::convert(freeze.id), - &who, - freeze.amount, - ) - // TODO handle error - .unwrap(); - } + if let Err(e) = T::Currency::reserve(&who, account.unnamed_reserve) { + log::error!(target: LOG_TARGET, "Failed to reserve into account {}: {:?}", who.to_ss58check(), e); + return Err(Error::::TODO); + } - for lock in account.locks { - T::Currency::set_lock( - lock.id, - &who, - lock.amount, - types::map_lock_reason(lock.reasons), - ); + for freeze in account.freezes { + if let Err(e) = T::Currency::set_freeze( + &T::RcToAhFreezeReason::convert(freeze.id), + &who, + freeze.amount, + ) { + log::error!(target: LOG_TARGET, "Failed to freeze into account {}: {:?}", who.to_ss58check(), e); + return Err(Error::::TODO); } + } - 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 + for lock in account.locks { + T::Currency::set_lock( + lock.id, + &who, + lock.amount, + types::map_lock_reason(lock.reasons), + ); } - // TODO: publish event + log::debug!( + target: LOG_TARGET, + "Integrating account: {}", who.to_ss58check(), + ); + + // TODO run some post-migration sanity checks - Ok(().into()) + // Apply all additional consumers that were excluded from the balance stuff above: + for _ in 0..account.consumers { + if let Err(e) = frame_system::Pallet::::inc_consumers(&who) { + log::error!(target: LOG_TARGET, "Failed to inc consumers for account {}: {:?}", who.to_ss58check(), e); + return Err(Error::::TODO); + } + } + for _ in 0..account.providers { + frame_system::Pallet::::inc_providers(&who); + } + + // TODO: publish event + Ok(()) } } diff --git a/pallets/rc-migrator/src/accounts.rs b/pallets/rc-migrator/src/accounts.rs index c914dbed64..0046196ab4 100644 --- a/pallets/rc-migrator/src/accounts.rs +++ b/pallets/rc-migrator/src/accounts.rs @@ -70,7 +70,7 @@ AH: mint_into(checking, checking_total - total_issuance) // publishes Balances:: */ -use crate::*; +use crate::{types::*, *}; use frame_support::{traits::tokens::IdAmount, weights::WeightMeter}; use frame_system::Account as SystemAccount; use pallet_balances::{AccountData, BalanceLock}; @@ -175,9 +175,9 @@ impl Pallet { /// - 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, + mut maybe_last_key: Option, weight_counter: &mut WeightMeter, - ) -> Result>, ()> { + ) -> Result, Error> { // 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. @@ -186,156 +186,44 @@ impl Pallet { // 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)); + return Err(Error::OutOfWeight); } - let iter = if let Some(ref last_key) = maybe_last_key { + let mut 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; + loop { + let Some((who, account_info)) = iter.next() else { + maybe_last_key = None; 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 { - ::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); + maybe_last_key = Some(who.clone()); + + match Self::migrate_account( + who, + account_info.clone(), + weight_counter, + &mut ah_weight_counter, + ) { + // Account does not need to be migrated + Ok(None) => continue, + Ok(Some(ah_account)) => package.push(ah_account), + // Not enough weight, lets try again in the next block since we made some progress. + Err(Error::OutOfWeight) if package.len() > 0 => break, + // Not enough weight and was unable to make progress, bad. + Err(Error::OutOfWeight) if package.len() == 0 => { + defensive!("Not enough weight to migrate a single account"); + return Err(Error::OutOfWeight); + }, + Err(e) => { + defensive!("Error while migrating account"); + log::error!(target: LOG_TARGET, "Error while migrating account: {:?}", e); + return Err(e); + }, + } } let call = types::AssetHubPalletConfig::::AhmController( @@ -357,14 +245,150 @@ impl Pallet { if let Err(_err) = send_xcm::(Location::new(0, [Junction::Parachain(1000)]), message.clone()) { - return Err(()); + return Err(Error::TODO); }; - if last_package { - Ok(None) - } else { - Ok(Some(maybe_last_key)) + Ok(maybe_last_key) + } + + /// Migrate a single account out of the Relay chain and return it. + /// + /// The account on the relay chain is modified as part of this operation. + pub fn migrate_account( + who: T::AccountId, + account_info: AccountInfoFor, + rc_weight: &mut WeightMeter, + ah_weight: &mut WeightMeter, + ) -> Result>, Error> { + // account for `get_rc_state` read below + if rc_weight.try_consume(T::DbWeight::get().reads(1)).is_err() { + return Err(Error::OutOfWeight); } + + 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(), + ); + return Ok(None); + } + + // 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 rc_weight.try_consume(T::RcWeightInfo::migrate_account()).is_err() { + return Err(Error::OutOfWeight); + } + + // account the weight for receiving a single account on Asset Hub. + if ah_weight.try_consume(T::AhWeightInfo::migrate_account()).is_err() { + return Err(Error::OutOfWeight); + } + + // 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 { + ::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); + + Ok(Some(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), + })) } /// Consumer ref count of migrating to Asset Hub pallets except a reference for `reserved` and diff --git a/pallets/rc-migrator/src/lib.rs b/pallets/rc-migrator/src/lib.rs index 6d2dd6e757..b2dd475778 100644 --- a/pallets/rc-migrator/src/lib.rs +++ b/pallets/rc-migrator/src/lib.rs @@ -126,8 +126,8 @@ pub mod pallet { #[pallet::error] pub enum Error { - /// TODO TODO, + OutOfWeight, } #[pallet::event] @@ -213,27 +213,27 @@ pub mod pallet { 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)), - } - }); + let res = with_transaction_opaque_err::, Error, _>(|| { + TransactionOutcome::Commit(Self::migrate_accounts( + last_key, + &mut weight_counter, + )) + }) + .expect("Always returning Ok; qed"); match res { - Ok(Ok(None)) => { + Ok(None) => { // accounts migration is completed // TODO publish event - RcMigrationStage::::put(MigrationStage::TODO); + Self::transition(MigrationStage::TODO); }, - Ok(Ok(Some(last_key))) => { + Ok(Some(last_key)) => { // accounts migration continues with the next block // TODO publish event - RcMigrationStage::::put(MigrationStage::MigratingAccounts { last_key }); + Self::transition(MigrationStage::MigratingAccounts { + last_key: Some(last_key), + }); }, _ => { // TODO handle error diff --git a/relay/polkadot/src/lib.rs b/relay/polkadot/src/lib.rs index f0be33c599..051acdc47f 100644 --- a/relay/polkadot/src/lib.rs +++ b/relay/polkadot/src/lib.rs @@ -1551,8 +1551,8 @@ impl OnSwap for SwapLeases { } parameter_types! { - pub RcMigratorMaxWeight: Weight = Weight::from_parts(1_000_000_000, u64::MAX); // TODO set the actual max weight - pub AhMigratorMaxWeight: Weight = Weight::from_parts(1_000_000_000, 5*1024*1024); // TODO set the actual max weight + pub RcMigratorMaxWeight: Weight = Weight::from_parts(10_000_000_000, u64::MAX); // TODO set the actual max weight + pub AhMigratorMaxWeight: Weight = Weight::from_parts(10_000_000_000, 5*1024*1024); // TODO set the actual max weight } impl pallet_rc_migrator::Config for Runtime {