Skip to content
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

[AHM] Stage management #584

Open
wants to merge 7 commits into
base: dev-asset-hub-migration
Choose a base branch
from

Conversation

muharem
Copy link
Contributor

@muharem muharem commented Feb 9, 2025

meant to be merged into ahm dev branch

Stage management for the Asset Hub migration

@muharem muharem marked this pull request as ready for review February 10, 2025 04:35
@@ -172,6 +193,10 @@ pub mod pallet {
pub type RcAccounts<T: Config> =
StorageMap<_, Twox64Concat, T::AccountId, RcAccountFor<T>, OptionQuery>;

/// The Asset Hub migration state.
#[pallet::storage]
pub type AhMigrationStage<T: Config> = StorageValue<_, MigrationStage, ValueQuery>;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if ValueQuery makes sense if our default is Pending which says that the migration will start in the next block.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I changed the doc for Pending in both pallets (...will start in the future). In both pallets it's ValueQuery. I think its better than the alternative with OptionQuery and no Pending variants at all (otherwise its never reachable stage).

pallets/ah-migrator/src/lib.rs Outdated Show resolved Hide resolved
&old,
&new
);
Self::deposit_event(Event::StageTransition { old, new });
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe this should send an UMP each time there is a stage transition? Then the relay can keep track of progress and we only have to send it from one spot in the code.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But what we achieve by that? AH does not really know much about the stage (it does not know if all pallets data is sent).
I can see that we can have AH sending an XCM message after it processes every XCM message, but it might increase the migration time significantly.
Or we can let AH know that this message with the data is the last on this pallet, but AH still can get congested just on one pallet with a lot of data.

#[derive(Encode, Decode)]
pub enum RcMigratorCall {
#[codec(index = 2)]
StartDataMigration,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should maybe be something like AhStageChanged(stage) and then define the stage type either in the RC pallet or in a shared crate.

Copy link
Contributor Author

@muharem muharem Feb 11, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, can be put this way. but if we have only few (e.g. three) stage notification from ah, a separate calls might be simpler

@@ -283,6 +291,10 @@ pub mod pallet {
{
/// The overarching event type.
type RuntimeEvent: From<Event<Self>> + IsType<<Self as frame_system::Config>::RuntimeEvent>;
/// The origin that can perform permissioned operations like setting the migration stage.
///
/// This is generally root and Fellows origins.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could try to tie this in with a point on this plan here: https://docs.google.com/document/d/1urpWdOkvQuhROeXf3FyjkdOcLiC36NpfKVADmig0lQI/edit?tab=t.0#heading=h.nc2w1yrxt8yf
Not sure if Donal sent it to you yet

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PS: comment should include Asset Hub as origin.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could try to tie this in with a point on this plan here: https://docs.google.com/document/d/1urpWdOkvQuhROeXf3FyjkdOcLiC36NpfKVADmig0lQI/edit?tab=t.0#heading=h.nc2w1yrxt8yf Not sure if Donal sent it to you yet

It opens a doc for me at the first line.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated the doc

pallets/rc-migrator/src/lib.rs Outdated Show resolved Hide resolved
/// This is typically called by the Asset Hub to indicate it's readiness to receive the
/// migration data.
#[pallet::call_index(2)]
pub fn start_data_migration(origin: OriginFor<T>) -> DispatchResult {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
pub fn start_data_migration(origin: OriginFor<T>) -> DispatchResult {
pub fn ah_ready_for_data(origin: OriginFor<T>) -> DispatchResult {

? I think it could help to include ah in there to show that it comes from the AH.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think can be more general, we might include more. But also no strong opinion. I just trying to not create too many stages to not waste time.

block_number: BlockNumber,
},
/// The migration is initializing.
Initializing,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Initializing,
WaitingForAhReadiness,

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

may be I better update the doc? It will be more general and if needed we can include more into it.

#[pallet::call_index(2)]
pub fn start_data_migration(origin: OriginFor<T>) -> DispatchResult {
<T as Config>::ManagerOrigin::ensure_origin(origin)?;
Self::transition(MigrationStage::AccountsMigrationInit);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe defensive assert to check that we are in the right phase.

Self::transition(MigrationStage::AccountsMigrationInit);
},
MigrationStage::Scheduled { block_number } =>
if now >= block_number {
match Self::send_xcm(types::AhMigratorCall::<T>::StartMigration) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
match Self::send_xcm(types::AhMigratorCall::<T>::StartMigration) {
match Self::send_xcm(types::AhMigratorCall::<T>::IsAhReadyToMigrate) {

Sorry for the silly naming suggestions, but i think it can help later to see what is happening.

}
},
MigrationStage::Initializing => {
// waiting AH to send a message and to start sending the data
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could add some timeout in case AH does not send back the Ok, but should not do now.

@@ -1120,6 +1120,10 @@ impl pallet_claims::Config for Runtime {

impl pallet_ah_migrator::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type ManagerOrigin = EitherOfDiverse<
EnsureRoot<AccountId>,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The relay chain will come in as root, right? So we dont need to use this EnsureXcm?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants