From ce5e92d5ac8e17d2eda32bb1a427cdc2964359fc Mon Sep 17 00:00:00 2001 From: muharem Date: Wed, 19 Mar 2025 15:46:59 +0100 Subject: [PATCH 1/5] refactor ah-migrator events --- pallets/ah-migrator/src/account.rs | 11 +- pallets/ah-migrator/src/asset_rate.rs | 8 +- pallets/ah-migrator/src/claims.rs | 11 +- pallets/ah-migrator/src/conviction_voting.rs | 11 +- pallets/ah-migrator/src/lib.rs | 175 ++----------------- pallets/ah-migrator/src/multisig.rs | 11 +- pallets/ah-migrator/src/preimage.rs | 29 ++- pallets/ah-migrator/src/proxy.rs | 20 ++- pallets/ah-migrator/src/referenda.rs | 21 ++- pallets/ah-migrator/src/scheduler.rs | 11 +- pallets/ah-migrator/src/staking/nom_pools.rs | 8 +- 11 files changed, 130 insertions(+), 186 deletions(-) diff --git a/pallets/ah-migrator/src/account.rs b/pallets/ah-migrator/src/account.rs index d309264625..8c61a1953b 100644 --- a/pallets/ah-migrator/src/account.rs +++ b/pallets/ah-migrator/src/account.rs @@ -25,7 +25,10 @@ impl Pallet { ) -> Result<(), Error> { log::info!(target: LOG_TARGET, "Integrating {} accounts", accounts.len()); - Self::deposit_event(Event::::AccountBatchReceived { count: accounts.len() as u32 }); + Self::deposit_event(Event::::BatchReceived { + pallet: PalletEventName::Balances, + count: accounts.len() as u32, + }); let (mut count_good, mut count_bad) = (0, 0); for account in accounts { @@ -48,7 +51,11 @@ impl Pallet { } } - Self::deposit_event(Event::::AccountBatchProcessed { count_good, count_bad }); + Self::deposit_event(Event::::BatchProcessed { + pallet: PalletEventName::Balances, + count_good, + count_bad, + }); Ok(()) } diff --git a/pallets/ah-migrator/src/asset_rate.rs b/pallets/ah-migrator/src/asset_rate.rs index 11d7b7885c..3fa5114c78 100644 --- a/pallets/ah-migrator/src/asset_rate.rs +++ b/pallets/ah-migrator/src/asset_rate.rs @@ -24,14 +24,18 @@ impl Pallet { log::info!(target: LOG_TARGET, "Processing {} asset rates", rates.len()); let count = rates.len() as u32; - Self::deposit_event(Event::AssetRatesReceived { count }); + Self::deposit_event(Event::BatchReceived { pallet: PalletEventName::AssetRates, count }); for rate in rates { Self::do_receive_asset_rate(rate)?; } log::info!(target: LOG_TARGET, "Processed {} asset rates", count); - Self::deposit_event(Event::AssetRatesProcessed { count_good: count, count_bad: 0 }); + Self::deposit_event(Event::BatchProcessed { + pallet: PalletEventName::AssetRates, + count_good: count, + count_bad: 0, + }); Ok(()) } diff --git a/pallets/ah-migrator/src/claims.rs b/pallets/ah-migrator/src/claims.rs index 038f5d3708..39e3164e2f 100644 --- a/pallets/ah-migrator/src/claims.rs +++ b/pallets/ah-migrator/src/claims.rs @@ -21,7 +21,10 @@ use pallet_rc_migrator::claims::{alias, RcClaimsMessage, RcClaimsMessageOf}; impl Pallet { pub fn do_receive_claims(messages: Vec>) -> Result<(), Error> { log::info!(target: LOG_TARGET, "Integrating {} claims", messages.len()); - Self::deposit_event(Event::ClaimsBatchReceived { count: messages.len() as u32 }); + Self::deposit_event(Event::BatchReceived { + pallet: PalletEventName::Claims, + count: messages.len() as u32, + }); let (mut count_good, mut count_bad) = (0, 0); for message in messages { @@ -33,7 +36,11 @@ impl Pallet { }, } } - Self::deposit_event(Event::ClaimsBatchProcessed { count_good, count_bad }); + Self::deposit_event(Event::BatchProcessed { + pallet: PalletEventName::Claims, + count_good, + count_bad, + }); Ok(()) } diff --git a/pallets/ah-migrator/src/conviction_voting.rs b/pallets/ah-migrator/src/conviction_voting.rs index e76af65467..c13ef2fba2 100644 --- a/pallets/ah-migrator/src/conviction_voting.rs +++ b/pallets/ah-migrator/src/conviction_voting.rs @@ -27,13 +27,20 @@ impl Pallet { ) -> Result<(), Error> { log::info!(target: LOG_TARGET, "Processing {} conviction voting messages", messages.len()); let count = messages.len() as u32; - Self::deposit_event(Event::ConvictionVotingMessagesReceived { count }); + Self::deposit_event(Event::BatchReceived { + pallet: PalletEventName::ConvictionVoting, + count, + }); for message in messages { Self::do_receive_conviction_voting_message(message); } - Self::deposit_event(Event::ConvictionVotingMessagesProcessed { count_good: count }); + Self::deposit_event(Event::BatchProcessed { + pallet: PalletEventName::ConvictionVoting, + count_good: count, + count_bad: 0, + }); Ok(()) } diff --git a/pallets/ah-migrator/src/lib.rs b/pallets/ah-migrator/src/lib.rs index b7bad9491f..b99dcc2513 100644 --- a/pallets/ah-migrator/src/lib.rs +++ b/pallets/ah-migrator/src/lib.rs @@ -111,6 +111,20 @@ pub enum PalletEventName { BagsList, Vesting, Bounties, + Balances, + Multisig, + Claims, + ProxyProxies, + ProxyAnnouncements, + PreimageChunk, + PreimageRequestStatus, + PreimageLegacyStatus, + NomPools, + ReferendaValues, + ReferendaReferendums, + Scheduler, + ConvictionVoting, + AssetRates, } /// The migration stage on the Asset Hub. @@ -283,8 +297,6 @@ pub mod pallet { #[pallet::event] #[pallet::generate_deposit(pub(crate) fn deposit_event)] pub enum Event { - /// The event that should to be replaced by something meaningful. - TODO, /// A stage transition has occurred. StageTransition { /// The old stage before the transition. @@ -292,165 +304,10 @@ pub mod pallet { /// The new stage after the transition. new: MigrationStage, }, - /// We received a batch of accounts that we are going to integrate. - AccountBatchReceived { - /// How many accounts are in the batch. - count: u32, - }, - /// We processed a batch of accounts that we received. - AccountBatchProcessed { - /// How many accounts were successfully integrated. - count_good: u32, - /// How many accounts failed to integrate. - count_bad: u32, - }, - /// We received a batch of multisigs that we are going to integrate. - MultisigBatchReceived { - /// How many multisigs are in the batch. - count: u32, - }, - MultisigBatchProcessed { - /// How many multisigs were successfully integrated. - count_good: u32, - /// How many multisigs failed to integrate. - count_bad: u32, - }, - /// We received a batch of claims that we are going to integrate. - ClaimsBatchReceived { - /// How many claims are in the batch. - count: u32, - }, - /// We processed a batch of claims that we received. - ClaimsBatchProcessed { - /// How many claims were successfully integrated. - count_good: u32, - /// How many claims failed to integrate. - count_bad: u32, - }, - /// We received a batch of proxies that we are going to integrate. - ProxyProxiesBatchReceived { - /// How many proxies are in the batch. - count: u32, - }, - /// We processed a batch of proxies that we received. - ProxyProxiesBatchProcessed { - /// How many proxies were successfully integrated. - count_good: u32, - /// How many proxies failed to integrate. - count_bad: u32, - }, - /// We received a batch of proxy announcements that we are going to integrate. - ProxyAnnouncementsBatchReceived { - /// How many proxy announcements are in the batch. - count: u32, - }, - /// We processed a batch of proxy announcements that we received. - ProxyAnnouncementsBatchProcessed { - /// How many proxy announcements were successfully integrated. - count_good: u32, - /// How many proxy announcements failed to integrate. - count_bad: u32, - }, - /// Received a batch of `RcPreimageChunk` that are going to be integrated. - PreimageChunkBatchReceived { - /// How many preimage chunks are in the batch. - count: u32, - }, - /// We processed a batch of `RcPreimageChunk` that we received. - PreimageChunkBatchProcessed { - /// How many preimage chunks were successfully integrated. - count_good: u32, - /// How many preimage chunks failed to integrate. - count_bad: u32, - }, - /// We received a batch of `RcPreimageRequestStatus` that we are going to integrate. - PreimageRequestStatusBatchReceived { - /// How many preimage request status are in the batch. - count: u32, - }, - /// We processed a batch of `RcPreimageRequestStatus` that we received. - PreimageRequestStatusBatchProcessed { - /// How many preimage request status were successfully integrated. - count_good: u32, - /// How many preimage request status failed to integrate. - count_bad: u32, - }, - /// We received a batch of `RcPreimageLegacyStatus` that we are going to integrate. - PreimageLegacyStatusBatchReceived { - /// How many preimage legacy status are in the batch. - count: u32, - }, - /// We processed a batch of `RcPreimageLegacyStatus` that we received. - PreimageLegacyStatusBatchProcessed { - /// How many preimage legacy status were successfully integrated. - count_good: u32, - /// How many preimage legacy status failed to integrate. - count_bad: u32, - }, - /// Received a batch of `RcNomPoolsMessage` that we are going to integrate. - NomPoolsMessagesBatchReceived { - /// How many nom pools messages are in the batch. - count: u32, - }, - /// Processed a batch of `RcNomPoolsMessage` that we received. - NomPoolsMessagesBatchProcessed { - /// How many nom pools messages were successfully integrated. - count_good: u32, - /// How many nom pools messages failed to integrate. - count_bad: u32, - }, /// We received a batch of messages that will be integrated into a pallet. - BatchReceived { - pallet: PalletEventName, - count: u32, - }, + BatchReceived { pallet: PalletEventName, count: u32 }, /// We processed a batch of messages for this pallet. - BatchProcessed { - pallet: PalletEventName, - count_good: u32, - count_bad: u32, - }, - /// We received a batch of referendums that we are going to integrate. - ReferendumsBatchReceived { - /// How many referendums are in the batch. - count: u32, - }, - /// We processed a batch of referendums that we received. - ReferendumsBatchProcessed { - /// How many referendums were successfully integrated. - count_good: u32, - /// How many referendums failed to integrate. - count_bad: u32, - }, - ReferendaProcessed, - SchedulerMessagesReceived { - /// How many scheduler messages are in the batch. - count: u32, - }, - SchedulerMessagesProcessed { - /// How many scheduler messages were successfully integrated. - count_good: u32, - /// How many scheduler messages failed to integrate. - count_bad: u32, - }, - ConvictionVotingMessagesReceived { - /// How many conviction voting messages are in the batch. - count: u32, - }, - ConvictionVotingMessagesProcessed { - /// How many conviction voting messages were successfully integrated. - count_good: u32, - }, - AssetRatesReceived { - /// How many asset rates are in the batch. - count: u32, - }, - AssetRatesProcessed { - /// How many asset rates were successfully integrated. - count_good: u32, - /// How many asset rates failed to integrate. - count_bad: u32, - }, + BatchProcessed { pallet: PalletEventName, count_good: u32, count_bad: u32 }, } #[pallet::pallet] diff --git a/pallets/ah-migrator/src/multisig.rs b/pallets/ah-migrator/src/multisig.rs index dd43f53fa2..52f747ffe0 100644 --- a/pallets/ah-migrator/src/multisig.rs +++ b/pallets/ah-migrator/src/multisig.rs @@ -32,7 +32,10 @@ const KNOWN_BAD_MULTISIGS: &[AccountId32] = &[ impl Pallet { pub fn do_receive_multisigs(multisigs: Vec>) -> Result<(), Error> { - Self::deposit_event(Event::MultisigBatchReceived { count: multisigs.len() as u32 }); + Self::deposit_event(Event::BatchReceived { + pallet: PalletEventName::Multisig, + count: multisigs.len() as u32, + }); let (mut count_good, mut count_bad) = (0, 0); log::info!(target: LOG_TARGET, "Integrating {} multisigs", multisigs.len()); @@ -45,7 +48,11 @@ impl Pallet { }, } } - Self::deposit_event(Event::MultisigBatchProcessed { count_good, count_bad }); + Self::deposit_event(Event::BatchProcessed { + pallet: PalletEventName::Multisig, + count_good, + count_bad, + }); Ok(()) } diff --git a/pallets/ah-migrator/src/preimage.rs b/pallets/ah-migrator/src/preimage.rs index 8eabbf2afd..967987c299 100644 --- a/pallets/ah-migrator/src/preimage.rs +++ b/pallets/ah-migrator/src/preimage.rs @@ -22,7 +22,10 @@ use sp_runtime::traits::{BlakeTwo256, Hash}; impl Pallet { pub fn do_receive_preimage_chunks(chunks: Vec) -> Result<(), Error> { - Self::deposit_event(Event::PreimageChunkBatchReceived { count: chunks.len() as u32 }); + Self::deposit_event(Event::BatchReceived { + pallet: PalletEventName::PreimageChunk, + count: chunks.len() as u32, + }); let (mut count_good, mut count_bad) = (0, 0); log::info!(target: LOG_TARGET, "Integrating {} preimage chunks", chunks.len()); @@ -35,7 +38,11 @@ impl Pallet { }, } } - Self::deposit_event(Event::PreimageChunkBatchProcessed { count_good, count_bad }); + Self::deposit_event(Event::BatchProcessed { + pallet: PalletEventName::PreimageChunk, + count_good, + count_bad, + }); Ok(()) } @@ -92,7 +99,8 @@ impl Pallet { pub fn do_receive_preimage_request_statuses( request_status: Vec>, ) -> Result<(), Error> { - Self::deposit_event(Event::PreimageRequestStatusBatchReceived { + Self::deposit_event(Event::BatchReceived { + pallet: PalletEventName::PreimageRequestStatus, count: request_status.len() as u32, }); log::info!(target: LOG_TARGET, "Integrating {} preimage request status", request_status.len()); @@ -108,7 +116,11 @@ impl Pallet { } } - Self::deposit_event(Event::PreimageRequestStatusBatchProcessed { count_good, count_bad }); + Self::deposit_event(Event::BatchProcessed { + pallet: PalletEventName::PreimageRequestStatus, + count_good, + count_bad, + }); Ok(()) } @@ -169,7 +181,8 @@ impl Pallet { pub fn do_receive_preimage_legacy_statuses( statuses: Vec>, ) -> Result<(), Error> { - Self::deposit_event(Event::PreimageLegacyStatusBatchReceived { + Self::deposit_event(Event::BatchReceived { + pallet: PalletEventName::PreimageLegacyStatus, count: statuses.len() as u32, }); log::info!(target: LOG_TARGET, "Integrating {} preimage legacy status", statuses.len()); @@ -184,7 +197,11 @@ impl Pallet { } } - Self::deposit_event(Event::PreimageLegacyStatusBatchProcessed { count_good, count_bad }); + Self::deposit_event(Event::BatchProcessed { + pallet: PalletEventName::PreimageLegacyStatus, + count_good, + count_bad, + }); Ok(()) } diff --git a/pallets/ah-migrator/src/proxy.rs b/pallets/ah-migrator/src/proxy.rs index 68f67489f2..23c007a0ed 100644 --- a/pallets/ah-migrator/src/proxy.rs +++ b/pallets/ah-migrator/src/proxy.rs @@ -21,7 +21,10 @@ use sp_runtime::{traits::Zero, BoundedSlice}; impl Pallet { pub fn do_receive_proxies(proxies: Vec>) -> Result<(), Error> { - Self::deposit_event(Event::ProxyProxiesBatchReceived { count: proxies.len() as u32 }); + Self::deposit_event(Event::BatchReceived { + pallet: PalletEventName::ProxyProxies, + count: proxies.len() as u32, + }); let (mut count_good, mut count_bad) = (0, 0); log::info!(target: LOG_TARGET, "Integrating batch proxies of with len {}", proxies.len()); @@ -34,7 +37,11 @@ impl Pallet { }, } } - Self::deposit_event(Event::ProxyProxiesBatchProcessed { count_good, count_bad }); + Self::deposit_event(Event::BatchProcessed { + pallet: PalletEventName::ProxyProxies, + count_good, + count_bad, + }); Ok(()) } @@ -84,7 +91,8 @@ impl Pallet { pub fn do_receive_proxy_announcements( announcements: Vec>, ) -> Result<(), Error> { - Self::deposit_event(Event::ProxyAnnouncementsBatchReceived { + Self::deposit_event(Event::BatchReceived { + pallet: PalletEventName::ProxyAnnouncements, count: announcements.len() as u32, }); @@ -101,7 +109,11 @@ impl Pallet { } } - Self::deposit_event(Event::ProxyAnnouncementsBatchProcessed { count_good, count_bad }); + Self::deposit_event(Event::BatchProcessed { + pallet: PalletEventName::ProxyAnnouncements, + count_good, + count_bad, + }); Ok(()) } diff --git a/pallets/ah-migrator/src/referenda.rs b/pallets/ah-migrator/src/referenda.rs index 8c7fc7c092..baf4dbb9e8 100644 --- a/pallets/ah-migrator/src/referenda.rs +++ b/pallets/ah-migrator/src/referenda.rs @@ -83,7 +83,10 @@ impl Pallet { referendums: Vec<(u32, RcReferendumInfoOf)>, ) -> Result<(), Error> { log::info!(target: LOG_TARGET, "Integrating {} referendums", referendums.len()); - Self::deposit_event(Event::ReferendumsBatchReceived { count: referendums.len() as u32 }); + Self::deposit_event(Event::BatchReceived { + pallet: PalletEventName::ReferendaReferendums, + count: referendums.len() as u32, + }); let (mut count_good, mut count_bad) = (0, 0); for (id, referendum) in referendums { @@ -93,7 +96,11 @@ impl Pallet { } } - Self::deposit_event(Event::ReferendumsBatchProcessed { count_good, count_bad }); + Self::deposit_event(Event::BatchProcessed { + pallet: PalletEventName::ReferendaReferendums, + count_good, + count_bad, + }); log::info!(target: LOG_TARGET, "Processed {} referendums", count_good); Ok(()) @@ -181,6 +188,10 @@ impl Pallet { track_queue: Vec<(TrackIdOf, Vec<(u32, u128)>)>, ) -> Result<(), Error> { log::info!(target: LOG_TARGET, "Integrating referenda pallet"); + Self::deposit_event(Event::BatchReceived { + pallet: PalletEventName::ReferendaValues, + count: 1, + }); ReferendumCount::::put(referendum_count); deciding_count.iter().for_each(|(track_id, count)| { @@ -191,7 +202,11 @@ impl Pallet { TrackQueue::::insert(track_id, queue); }); - Self::deposit_event(Event::ReferendaProcessed); + Self::deposit_event(Event::BatchProcessed { + pallet: PalletEventName::ReferendaValues, + count_good: 1, + count_bad: 0, + }); log::info!(target: LOG_TARGET, "Referenda pallet integrated"); Ok(()) } diff --git a/pallets/ah-migrator/src/scheduler.rs b/pallets/ah-migrator/src/scheduler.rs index 1a5933426d..2446ef1392 100644 --- a/pallets/ah-migrator/src/scheduler.rs +++ b/pallets/ah-migrator/src/scheduler.rs @@ -31,7 +31,10 @@ impl Pallet { messages: Vec>, ) -> Result<(), Error> { log::info!(target: LOG_TARGET, "Processing {} scheduler messages", messages.len()); - Self::deposit_event(Event::SchedulerMessagesReceived { count: messages.len() as u32 }); + Self::deposit_event(Event::BatchReceived { + pallet: PalletEventName::Scheduler, + count: messages.len() as u32, + }); let (mut count_good, mut count_bad) = (0, 0); for message in messages { @@ -41,7 +44,11 @@ impl Pallet { } } - Self::deposit_event(Event::SchedulerMessagesProcessed { count_good, count_bad }); + Self::deposit_event(Event::BatchProcessed { + pallet: PalletEventName::Scheduler, + count_good, + count_bad, + }); log::info!(target: LOG_TARGET, "Processed {} scheduler messages", count_good); Ok(()) diff --git a/pallets/ah-migrator/src/staking/nom_pools.rs b/pallets/ah-migrator/src/staking/nom_pools.rs index 2c830a86f6..62ff9f15f8 100644 --- a/pallets/ah-migrator/src/staking/nom_pools.rs +++ b/pallets/ah-migrator/src/staking/nom_pools.rs @@ -29,14 +29,18 @@ impl Pallet { ) -> Result<(), Error> { let mut good = 0; log::info!(target: LOG_TARGET, "Integrating {} NomPoolsMessages", messages.len()); - Self::deposit_event(Event::NomPoolsMessagesBatchReceived { count: messages.len() as u32 }); + Self::deposit_event(Event::BatchReceived { + pallet: PalletEventName::NomPools, + count: messages.len() as u32, + }); for message in messages { Self::do_receive_nom_pools_message(message); good += 1; } - Self::deposit_event(Event::NomPoolsMessagesBatchProcessed { + Self::deposit_event(Event::BatchProcessed { + pallet: PalletEventName::NomPools, count_good: good as u32, count_bad: 0, }); From e533e7111c47754f0dabdc7576d2584870f12d5b Mon Sep 17 00:00:00 2001 From: muharem Date: Wed, 19 Mar 2025 16:35:32 +0100 Subject: [PATCH 2/5] enable Scheduled stage --- integration-tests/ahm/src/mock.rs | 26 +++---- integration-tests/ahm/src/tests.rs | 119 ++++++++++++++++++++++++++++- pallets/rc-migrator/src/lib.rs | 6 +- 3 files changed, 129 insertions(+), 22 deletions(-) diff --git a/integration-tests/ahm/src/mock.rs b/integration-tests/ahm/src/mock.rs index e68978ffe7..8b161732c8 100644 --- a/integration-tests/ahm/src/mock.rs +++ b/integration-tests/ahm/src/mock.rs @@ -14,7 +14,7 @@ // You should have received a copy of the GNU General Public License // along with Polkadot. If not, see . -use asset_hub_polkadot_runtime::{Block as AssetHubBlock, Runtime as AssetHub}; +use asset_hub_polkadot_runtime::{AhMigrator, Block as AssetHubBlock, Runtime as AssetHub}; use codec::Decode; use cumulus_primitives_core::{ AggregateMessageOrigin as ParachainMessageOrigin, InboundDownwardMessage, ParaId, @@ -25,7 +25,7 @@ use pallet_rc_migrator::{ MigrationStageOf as RcMigrationStageOf, RcMigrationStage as RcMigrationStageStorage, }; use polkadot_primitives::UpwardMessage; -use polkadot_runtime::{Block as PolkadotBlock, Runtime as Polkadot}; +use polkadot_runtime::{Block as PolkadotBlock, RcMigrator, Runtime as Polkadot}; use remote_externalities::{Builder, Mode, OfflineConfig, RemoteExternalities}; use runtime_parachains::{ dmp::DownwardMessageQueues, @@ -75,10 +75,9 @@ pub fn next_block_rc() { frame_system::Pallet::::set_block_number(now); frame_system::Pallet::::reset_events(); let weight = >::on_initialize(now); - let weight = >::on_initialize(now) - .saturating_add(weight); + let weight = >::on_initialize(now).saturating_add(weight); >::on_finalize(now); - >::on_finalize(now); + >::on_finalize(now); let limit = ::BlockWeights::get().max_block; assert!( @@ -96,10 +95,9 @@ pub fn next_block_ah() { frame_system::Pallet::::set_block_number(now); frame_system::Pallet::::reset_events(); let weight = >::on_initialize(now); - let weight = >::on_initialize(now) - .saturating_add(weight); + let weight = >::on_initialize(now).saturating_add(weight); >::on_finalize(now); - >::on_finalize(now); + >::on_finalize(now); let limit = ::BlockWeights::get().max_block; assert!( @@ -155,14 +153,14 @@ pub fn set_initial_migration_stage( relay_chain: &mut RemoteExternalities, ) -> RcMigrationStageOf { let stage = relay_chain.execute_with(|| { - if let Ok(stage) = std::env::var("START_STAGE") { + let stage = if let Ok(stage) = std::env::var("START_STAGE") { log::info!("Setting start stage: {:?}", &stage); - let stage = RcMigrationStage::from_str(&stage).expect("Invalid start stage"); - RcMigrationStageStorage::::put(stage.clone()); - stage + RcMigrationStage::from_str(&stage).expect("Invalid start stage") } else { - RcMigrationStageStorage::::get() - } + RcMigrationStage::AccountsMigrationInit + }; + RcMigrationStageStorage::::put(stage.clone()); + stage }); relay_chain.commit_all().unwrap(); stage diff --git a/integration-tests/ahm/src/tests.rs b/integration-tests/ahm/src/tests.rs index 388b5dec4f..31c4d2bf62 100644 --- a/integration-tests/ahm/src/tests.rs +++ b/integration-tests/ahm/src/tests.rs @@ -35,19 +35,23 @@ use super::{mock::*, proxy_test::ProxiesStillWork}; use asset_hub_polkadot_runtime::Runtime as AssetHub; use cumulus_pallet_parachain_system::PendingUpwardMessages; use cumulus_primitives_core::{BlockT, Junction, Location, ParaId}; -use frame_system::pallet_prelude::BlockNumberFor; -use pallet_ah_migrator::types::AhMigrationCheck; +use frame_support::traits::schedule::DispatchTime; +use frame_system::{pallet_prelude::BlockNumberFor, RawOrigin}; +use pallet_ah_migrator::{ + types::AhMigrationCheck, AhMigrationStage as AhMigrationStageStorage, + MigrationStage as AhMigrationStage, +}; use pallet_rc_migrator::{ types::RcMigrationCheck, MigrationStage as RcMigrationStage, RcMigrationStage as RcMigrationStageStorage, }; -use polkadot_runtime::{Block as PolkadotBlock, Runtime as Polkadot}; +use polkadot_runtime::{Block as PolkadotBlock, RcMigrator, Runtime as Polkadot}; use polkadot_runtime_common::{paras_registrar, slots as pallet_slots}; use remote_externalities::RemoteExternalities; use runtime_parachains::dmp::DownwardMessageQueues; use sp_runtime::AccountId32; use std::{collections::BTreeMap, str::FromStr}; -use xcm_emulator::ConvertLocation; +use xcm_emulator::{assert_ok, ConvertLocation}; type RcChecks = ( pallet_rc_migrator::preimage::PreimageChunkMigrator, @@ -344,3 +348,110 @@ async fn migration_works() { println!("Migration done in {} RC blocks", rc_block_count); } + +#[tokio::test(flavor = "current_thread")] +async fn scheduled_migration_works() { + let Some((mut rc, mut ah)) = load_externalities().await else { return }; + + // Check that the migration is pending on the RC. + rc.execute_with(|| { + log::info!("Asserting the initial state on RC"); + next_block_rc(); + + assert_eq!(RcMigrationStageStorage::::get(), RcMigrationStage::Pending); + + // clear the DMP queue. + let _ = DownwardMessageQueues::::take(AH_PARA_ID); + }); + rc.commit_all().unwrap(); + + // Check that the migration is pending on the AH. + ah.execute_with(|| { + log::info!("Asserting the initial state on AH"); + next_block_ah(); + + assert_eq!(AhMigrationStageStorage::::get(), AhMigrationStage::Pending); + + // clear the UMP queue. + let _ = PendingUpwardMessages::::take(); + }); + ah.commit_all().unwrap(); + + // Schedule the migration on RC. + let dmp_messages = rc.execute_with(|| { + log::info!("Scheduling the migration on RC"); + next_block_rc(); + + let now = frame_system::Pallet::::block_number(); + let scheduled_at = now + 2; + + assert_ok!(RcMigrator::schedule_migration( + RawOrigin::Root.into(), + DispatchTime::At(scheduled_at) + )); + assert_eq!( + RcMigrationStageStorage::::get(), + RcMigrationStage::Scheduled { block_number: scheduled_at } + ); + + next_block_rc(); + // migrating not yet started + assert_eq!( + RcMigrationStageStorage::::get(), + RcMigrationStage::Scheduled { block_number: scheduled_at } + ); + assert_eq!(DownwardMessageQueues::::take(AH_PARA_ID).len(), 0); + + next_block_rc(); + + // migration started + assert_eq!(RcMigrationStageStorage::::get(), RcMigrationStage::Initializing); + let dmp_messages = DownwardMessageQueues::::take(AH_PARA_ID); + assert!(dmp_messages.len() > 0); + + dmp_messages + }); + + // enqueue DMP messages from RC to AH. + ah.execute_with(|| { + enqueue_dmp(dmp_messages); + }); + ah.commit_all().unwrap(); + + // Asset Hub receives the message from the Relay Chain to start the migration and the + // acknowledges it by sending the message back to the Relay Chain. + let ump_messages = ah.execute_with(|| { + log::info!("Acknowledging the start of the migration on AH"); + assert_eq!(AhMigrationStageStorage::::get(), AhMigrationStage::Pending); + + next_block_ah(); + + assert_eq!( + AhMigrationStageStorage::::get(), + AhMigrationStage::DataMigrationOngoing + ); + + PendingUpwardMessages::::take() + }); + ah.commit_all().unwrap(); + + // enqueue UMP messages from AH to RC. + rc.execute_with(|| { + enqueue_ump(ump_messages); + }); + rc.commit_all().unwrap(); + + // Relay Chain receives the acknowledgement from the Asset Hub and starts sending the data. + rc.execute_with(|| { + log::info!("Receiving the acknowledgement from AH on RC"); + assert_eq!(RcMigrationStageStorage::::get(), RcMigrationStage::Initializing); + + next_block_rc(); + + assert_eq!( + RcMigrationStageStorage::::get(), + RcMigrationStage::AccountsMigrationOngoing { last_key: None } + ); + }); + rc.commit_all().unwrap(); +} diff --git a/pallets/rc-migrator/src/lib.rs b/pallets/rc-migrator/src/lib.rs index 3fc324dc70..707d09ea85 100644 --- a/pallets/rc-migrator/src/lib.rs +++ b/pallets/rc-migrator/src/lib.rs @@ -511,10 +511,7 @@ pub mod pallet { match stage { MigrationStage::Pending => { - // TODO: we should do nothing on pending stage. - // On production the AH will send a message and initialize the migration. - // Now we transition to `AccountsMigrationInit` to run tests - Self::transition(MigrationStage::AccountsMigrationInit); + return weight_counter.consumed(); }, MigrationStage::Scheduled { block_number } => if now >= block_number { @@ -533,6 +530,7 @@ pub mod pallet { }, MigrationStage::Initializing => { // waiting AH to send a message and to start sending the data + return weight_counter.consumed(); }, MigrationStage::AccountsMigrationInit => { // TODO: weights From f0c8c20b12a4bb672385bd2e7f8195e2539994ef Mon Sep 17 00:00:00 2001 From: muharem Date: Wed, 19 Mar 2025 16:38:58 +0100 Subject: [PATCH 3/5] docs --- integration-tests/ahm/src/mock.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/integration-tests/ahm/src/mock.rs b/integration-tests/ahm/src/mock.rs index 8b161732c8..c03f9c7515 100644 --- a/integration-tests/ahm/src/mock.rs +++ b/integration-tests/ahm/src/mock.rs @@ -148,7 +148,8 @@ pub fn enqueue_ump(msgs: Vec) { // Sets the initial migration stage on the Relay Chain. // // If the `START_STAGE` environment variable is set, it will be used to set the initial migration -// stage. Otherwise, the current migration stage will be returned. +// stage. Otherwise, the `AccountsMigrationInit` stage will be set bypassing the `Scheduled` stage. +// The `Scheduled` stage is tested separately by the `scheduled_migration_works` test. pub fn set_initial_migration_stage( relay_chain: &mut RemoteExternalities, ) -> RcMigrationStageOf { From eeccf8bfa0fdb9a0cae1e8d0beed6d6438e59c65 Mon Sep 17 00:00:00 2001 From: muharem Date: Wed, 19 Mar 2025 16:52:22 +0100 Subject: [PATCH 4/5] use Fellows origin instead of root --- Cargo.lock | 1 + integration-tests/ahm/Cargo.toml | 1 + integration-tests/ahm/src/tests.rs | 12 +++++++++--- 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 559d017dfd..a36294305e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -10116,6 +10116,7 @@ dependencies = [ "pallet-rc-migrator", "pallet-timestamp", "pallet-whitelist", + "pallet-xcm", "parachains-common", "parity-scale-codec", "polkadot-parachain-primitives", diff --git a/integration-tests/ahm/Cargo.toml b/integration-tests/ahm/Cargo.toml index 6165292798..43d63f94ec 100644 --- a/integration-tests/ahm/Cargo.toml +++ b/integration-tests/ahm/Cargo.toml @@ -49,3 +49,4 @@ hex = { workspace = true } pallet-whitelist = { workspace = true, default-features = true } pallet-bounties = { workspace = true, default-features = true } cumulus-pallet-parachain-system = { workspace = true } +pallet-xcm = { workspace = true, default-features = true } \ No newline at end of file diff --git a/integration-tests/ahm/src/tests.rs b/integration-tests/ahm/src/tests.rs index 31c4d2bf62..f4d7110800 100644 --- a/integration-tests/ahm/src/tests.rs +++ b/integration-tests/ahm/src/tests.rs @@ -51,6 +51,7 @@ use remote_externalities::RemoteExternalities; use runtime_parachains::dmp::DownwardMessageQueues; use sp_runtime::AccountId32; use std::{collections::BTreeMap, str::FromStr}; +use xcm::latest::*; use xcm_emulator::{assert_ok, ConvertLocation}; type RcChecks = ( @@ -385,10 +386,15 @@ async fn scheduled_migration_works() { let now = frame_system::Pallet::::block_number(); let scheduled_at = now + 2; - assert_ok!(RcMigrator::schedule_migration( - RawOrigin::Root.into(), - DispatchTime::At(scheduled_at) + // Fellowship Origin + let origin = pallet_xcm::Origin::Xcm(Location::new( + 0, + [ + Junction::Parachain(1001), + Junction::Plurality { id: BodyId::Technical, part: BodyPart::Voice }, + ], )); + assert_ok!(RcMigrator::schedule_migration(origin.into(), DispatchTime::At(scheduled_at))); assert_eq!( RcMigrationStageStorage::::get(), RcMigrationStage::Scheduled { block_number: scheduled_at } From f3639f38a2baf48a315141869c846cc41f527284 Mon Sep 17 00:00:00 2001 From: muharem Date: Thu, 20 Mar 2025 12:46:55 +0100 Subject: [PATCH 5/5] schedule_migration does not accept start moment <= now --- pallets/rc-migrator/src/lib.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/pallets/rc-migrator/src/lib.rs b/pallets/rc-migrator/src/lib.rs index 707d09ea85..7145bc3a25 100644 --- a/pallets/rc-migrator/src/lib.rs +++ b/pallets/rc-migrator/src/lib.rs @@ -388,6 +388,8 @@ pub mod pallet { XcmError, /// Failed to withdraw account from RC for migration to AH. FailedToWithdrawAccount, + /// Indicates that the specified block number is in the past. + PastBlockNumber, } #[pallet::event] @@ -462,6 +464,7 @@ pub mod pallet { ::ManagerOrigin::ensure_origin(origin)?; let now = frame_system::Pallet::::block_number(); let block_number = start_moment.evaluate(now); + ensure!(block_number > now, Error::::PastBlockNumber); Self::transition(MigrationStage::Scheduled { block_number }); Ok(()) }