-
Notifications
You must be signed in to change notification settings - Fork 154
[AHM] refactor events and enable scheduled migration start #634
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
ce5e92d
e533e71
f0c8c20
eeccf8b
f3639f3
c6b6cf4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -35,20 +35,25 @@ 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_support::traits::schedule::DispatchTime; | ||
| use frame_system::pallet_prelude::BlockNumberFor; | ||
| use pallet_ah_migrator::types::AhMigrationCheck; | ||
| 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_core::crypto::Ss58Codec; | ||
| use sp_runtime::AccountId32; | ||
| use std::{collections::BTreeMap, str::FromStr}; | ||
| use xcm_emulator::{ConvertLocation, WeightMeter}; | ||
| use xcm::latest::*; | ||
| use xcm_emulator::{assert_ok, ConvertLocation, WeightMeter}; | ||
|
|
||
| type RcChecks = ( | ||
| pallet_rc_migrator::preimage::PreimageChunkMigrator<Polkadot>, | ||
|
|
@@ -350,6 +355,118 @@ 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::<Polkadot>::get(), RcMigrationStage::Pending); | ||
|
|
||
| // clear the DMP queue. | ||
| let _ = DownwardMessageQueues::<Polkadot>::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::<AssetHub>::get(), AhMigrationStage::Pending); | ||
|
|
||
| // clear the UMP queue. | ||
| let _ = PendingUpwardMessages::<AssetHub>::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::<Polkadot>::block_number(); | ||
| let scheduled_at = now + 2; | ||
|
|
||
| // 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::<Polkadot>::get(), | ||
| RcMigrationStage::Scheduled { block_number: scheduled_at } | ||
| ); | ||
|
|
||
| next_block_rc(); | ||
| // migrating not yet started | ||
| assert_eq!( | ||
| RcMigrationStageStorage::<Polkadot>::get(), | ||
| RcMigrationStage::Scheduled { block_number: scheduled_at } | ||
| ); | ||
| assert_eq!(DownwardMessageQueues::<Polkadot>::take(AH_PARA_ID).len(), 0); | ||
|
|
||
| next_block_rc(); | ||
|
|
||
| // migration started | ||
| assert_eq!(RcMigrationStageStorage::<Polkadot>::get(), RcMigrationStage::Initializing); | ||
| let dmp_messages = DownwardMessageQueues::<Polkadot>::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::<AssetHub>::get(), AhMigrationStage::Pending); | ||
|
|
||
| next_block_ah(); | ||
|
|
||
| assert_eq!( | ||
| AhMigrationStageStorage::<AssetHub>::get(), | ||
| AhMigrationStage::DataMigrationOngoing | ||
| ); | ||
|
|
||
| PendingUpwardMessages::<AssetHub>::take() | ||
| }); | ||
| ah.commit_all().unwrap(); | ||
|
|
||
| // enqueue UMP messages from AH to RC. | ||
| rc.execute_with(|| { | ||
| enqueue_ump(ump_messages); | ||
| }); | ||
| rc.commit_all().unwrap(); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We could make a wrapper for our externalities that always commits after |
||
|
|
||
| // 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::<Polkadot>::get(), RcMigrationStage::Initializing); | ||
|
|
||
| next_block_rc(); | ||
|
|
||
| assert_eq!( | ||
| RcMigrationStageStorage::<Polkadot>::get(), | ||
| RcMigrationStage::AccountsMigrationOngoing { last_key: None } | ||
| ); | ||
| }); | ||
| rc.commit_all().unwrap(); | ||
| } | ||
|
|
||
| #[tokio::test] | ||
| async fn some_account_migration_works() { | ||
| use frame_system::Account as SystemAccount; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -24,14 +24,18 @@ impl<T: Config> Pallet<T> { | |
| 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, | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why 0 here? Sorry for commenting on a merged PR, just trying to understand this. |
||
| }); | ||
|
|
||
| Ok(()) | ||
| } | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.