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

Migrate foreign assets v3::Location to v4::Location #4129

Merged
merged 44 commits into from
Aug 14, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
2b39b01
feat(asset-hub-rococo-runtime): add a migration from foreign assets V…
franciscoaguirre Mar 14, 2024
da042a3
Merge branch 'master' into migrate-assets-to-v4
franciscoaguirre Jun 26, 2024
94738d1
fix: fmt
franciscoaguirre Jun 26, 2024
f0356f0
feat(assets-common): add foreign assets migration
franciscoaguirre Jun 26, 2024
ca8c876
feat(foreign-assets-migration): move to assets common
franciscoaguirre Jul 1, 2024
dce5ce1
Merge branch 'master' into migrate-assets-to-v4
franciscoaguirre Jul 29, 2024
e2a5398
fix: another v3 -> v4 change
franciscoaguirre Jul 29, 2024
a656f4b
feat(assets-common-migrations): create a pallet for asset migrations
franciscoaguirre Jul 31, 2024
1457f3f
nearly works
ggwpez Aug 1, 2024
211207e
nearly works
ggwpez Aug 1, 2024
d1efea4
make compile
ggwpez Aug 1, 2024
e610689
feat(assets-common-migrations): benchmark tests passing
franciscoaguirre Aug 1, 2024
ec88a62
feat(asset-hub-westend): migrate from v3 to v4
franciscoaguirre Aug 1, 2024
310b1bf
fix(assets-common-migrations): tests work
franciscoaguirre Aug 1, 2024
a619548
doc: prdoc
franciscoaguirre Aug 1, 2024
2e3931a
fix(assets-common-migrations): some lints
franciscoaguirre Aug 1, 2024
435a412
fix(assets-common-migrations): some fixes and a license
franciscoaguirre Aug 1, 2024
b43ae14
fix(asset-hub-westend): actually run the migration
franciscoaguirre Aug 1, 2024
be9a520
fix: update Cargo.lock
franciscoaguirre Aug 1, 2024
d1f8048
Merge branch 'master' into migrate-assets-to-v4
franciscoaguirre Aug 1, 2024
3d3e718
fix(asset-hub-westend): missing dependency
franciscoaguirre Aug 1, 2024
9fe6e8b
fix: moved test code from using v3 to v4
franciscoaguirre Aug 2, 2024
8bb13b7
fix(assets-common-migrations): make benchmarks work and benchmark ass…
franciscoaguirre Aug 5, 2024
d37daa0
fix: add licenses to weight files
franciscoaguirre Aug 5, 2024
72e7f43
Merge branch 'master' into migrate-assets-to-v4
franciscoaguirre Aug 5, 2024
61a6e89
chore(assets-common-migrations): remove unnecessary dependencies
franciscoaguirre Aug 5, 2024
0154c57
fix(assets): change migration name and use correct WeightInfo
franciscoaguirre Aug 7, 2024
7f91f73
fix: remove hex-display
franciscoaguirre Aug 7, 2024
0564298
Merge branch 'master' into migrate-assets-to-v4
franciscoaguirre Aug 7, 2024
41ba43d
fix: bridge hub integration tests
franciscoaguirre Aug 7, 2024
acb2a31
Merge branch 'master' into migrate-assets-to-v4
franciscoaguirre Aug 7, 2024
57fe422
fix(assets-common-migrations): use correct module name
franciscoaguirre Aug 7, 2024
41ca88c
fix(assets-common-migrations): use correct module name
franciscoaguirre Aug 7, 2024
634b84d
fix(umbrella): regenerate umbrella crate
franciscoaguirre Aug 7, 2024
f00f5e8
".git/.scripts/commands/bench/bench.sh" --subcommand=pallet --runtime…
Aug 7, 2024
f59f7da
revert: remove all the data migration stuff
franciscoaguirre Aug 8, 2024
f5a3eb5
doc(prdoc): update now that there's no data migration
franciscoaguirre Aug 8, 2024
280ff6b
Merge branch 'master' into migrate-assets-to-v4
franciscoaguirre Aug 8, 2024
d4ccba2
Merge branch 'master' into migrate-assets-to-v4
franciscoaguirre Aug 9, 2024
11f7c7d
Merge branch 'master' into migrate-assets-to-v4
franciscoaguirre Aug 12, 2024
917e2f9
Merge branch 'master' into migrate-assets-to-v4
franciscoaguirre Aug 13, 2024
e0f40cb
Merge branch 'master' into migrate-assets-to-v4
franciscoaguirre Aug 13, 2024
ae7e326
chore: feedback
franciscoaguirre Aug 13, 2024
2dca782
Merge branch 'master' into migrate-assets-to-v4
franciscoaguirre Aug 13, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix: fmt
  • Loading branch information
franciscoaguirre committed Jun 26, 2024
commit 94738d1a6fbf020dd74897a2774754ee1be24221
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,14 @@ use frame_support::{
construct_runtime, derive_impl,
dispatch::DispatchClass,
genesis_builder_helper::{build_state, get_preset},
migrations::FreezeChainOnFailedMigration,
ord_parameter_types, parameter_types,
traits::{
fungible, fungibles, tokens::imbalance::ResolveAssetTo, AsEnsureOriginWithArg, ConstBool,
ConstU128, ConstU32, ConstU64, ConstU8, EitherOfDiverse, Equals, InstanceFilter,
TransformOrigin,
},
weights::{ConstantMultiplier, Weight, WeightToFee as _},
migrations::FreezeChainOnFailedMigration,
BoundedVec, PalletId,
};
use frame_system::{
Expand Down
132 changes: 70 additions & 62 deletions substrate/frame/assets/src/foreign_assets_migration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,87 +18,95 @@
//! This migration is meant to upgrade the XCM version of asset locations from V3 to V4.
//! It's only needed if the `AssetId` for this pallet is `VersionedLocation`

use crate::pallet::{Config, Asset};
use crate::pallet::{Asset, Config};
use frame_support::{
migrations::{SteppedMigration, SteppedMigrationError},
pallet_prelude::PhantomData,
weights::WeightMeter,
Hashable,
migrations::{SteppedMigration, SteppedMigrationError},
pallet_prelude::PhantomData,
weights::WeightMeter,
Hashable,
};

// TODO: Move this further up.
mod identifier {
use codec::{MaxEncodedLen, Encode, Decode};
use codec::{Decode, Encode, MaxEncodedLen};

#[derive(MaxEncodedLen, Encode, Decode)]
pub struct MigrationIdentifier {
pub pallet_identifier: [u8; 16],
pub version_from: u8,
pub version_to: u8,
}
#[derive(MaxEncodedLen, Encode, Decode)]
pub struct MigrationIdentifier {
pub pallet_identifier: [u8; 16],
pub version_from: u8,
pub version_to: u8,
}

pub const PALLET_MIGRATIONS_ID: &[u8; 13] = b"pallet-assets";
pub const PALLET_MIGRATIONS_ID: &[u8; 13] = b"pallet-assets";
}

use identifier::*;

/// Storage aliases for on-chain storage types before running the migration.
mod old {
use super::Config;
use crate::pallet::Pallet;
use crate::types::{AssetDetails, DepositBalanceOf};
use frame_support::{storage_alias, Blake2_128Concat};
use super::Config;
use crate::{
pallet::Pallet,
types::{AssetDetails, DepositBalanceOf},
};
use frame_support::{storage_alias, Blake2_128Concat};

/// The storage item we are migrating from.
#[storage_alias]
pub(super) type Asset<T: Config<I>, I: 'static> = StorageMap<
Pallet<T, I>,
Blake2_128Concat,
xcm::v3::Location,
AssetDetails<<T as Config<I>>::Balance, <T as frame_system::Config>::AccountId, DepositBalanceOf<T, I>>,
>;
/// The storage item we are migrating from.
#[storage_alias]
pub(super) type Asset<T: Config<I>, I: 'static> = StorageMap<
Pallet<T, I>,
Blake2_128Concat,
xcm::v3::Location,
AssetDetails<
<T as Config<I>>::Balance,
<T as frame_system::Config>::AccountId,
DepositBalanceOf<T, I>,
>,
>;
}

pub struct MigrateForeignAssets<T: Config<I>, I: 'static>(PhantomData<(T, I)>);
impl<T: Config<I, AssetId = xcm::v3::Location>, I: 'static> SteppedMigration for MigrateForeignAssets<T, I> {
type Cursor = T::AssetId;
type Identifier = MigrationIdentifier;
impl<T: Config<I, AssetId = xcm::v3::Location>, I: 'static> SteppedMigration
for MigrateForeignAssets<T, I>
{
type Cursor = T::AssetId;
type Identifier = MigrationIdentifier;

fn id() -> Self::Identifier {
MigrationIdentifier {
pallet_identifier: (*PALLET_MIGRATIONS_ID).twox_128(),
version_from: 0,
version_to: 1,
}
}
fn id() -> Self::Identifier {
MigrationIdentifier {
pallet_identifier: (*PALLET_MIGRATIONS_ID).twox_128(),
version_from: 0,
version_to: 1,
}
}

// TODO: For now I'm letting it run forever, check.
fn max_steps() -> Option<u32> {
None
}
// TODO: For now I'm letting it run forever, check.
fn max_steps() -> Option<u32> {
None
}

fn step(
cursor: Option<Self::Cursor>,
_meter: &mut WeightMeter,
) -> Result<Option<Self::Cursor>, SteppedMigrationError> {
let mut iter = if let Some(last_key) = cursor {
// If a cursor is provided, start iterating from the value corresponding
// to the last key processed in the previous step of the migration.
old::Asset::<T, I>::iter_from(old::Asset::<T, I>::hashed_key_for(last_key))
} else {
// If there is no cursor, start iterating from the beginning.
old::Asset::<T, I>::iter()
};
fn step(
cursor: Option<Self::Cursor>,
_meter: &mut WeightMeter,
) -> Result<Option<Self::Cursor>, SteppedMigrationError> {
let mut iter = if let Some(last_key) = cursor {
// If a cursor is provided, start iterating from the value corresponding
// to the last key processed in the previous step of the migration.
old::Asset::<T, I>::iter_from(old::Asset::<T, I>::hashed_key_for(last_key))
} else {
// If there is no cursor, start iterating from the beginning.
old::Asset::<T, I>::iter()
};

if let Some((key, _value)) = iter.next() {
// If there is a next item in the iterator, migrate it.
Asset::<T, I>::remove(key);
// TODO: Insert the item with a V4 key.
// Return the processed key as the new cursor to continue the migration.
Ok(Some(key))
} else {
// Signal the migration is complete.
Ok(None)
}
}
if let Some((key, _value)) = iter.next() {
// If there is a next item in the iterator, migrate it.
Asset::<T, I>::remove(key);
// TODO: Insert the item with a V4 key.
// Return the processed key as the new cursor to continue the migration.
Ok(Some(key))
} else {
// Signal the migration is complete.
Ok(None)
}
}
}
2 changes: 1 addition & 1 deletion substrate/frame/assets/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,8 @@

#[cfg(feature = "runtime-benchmarks")]
pub mod benchmarking;
pub mod migration;
pub mod foreign_assets_migration; // TODO: move to `migrations` mod
pub mod migration;
#[cfg(test)]
pub mod mock;
#[cfg(test)]
Expand Down
Loading