From 84c58de7820d49acf81e7e4b6a5e28f8572bef95 Mon Sep 17 00:00:00 2001 From: zjb0807 Date: Thu, 14 Dec 2023 09:10:18 +0800 Subject: [PATCH 1/2] Upgrade rust-1.74.0 (#970) --- .github/workflows/test.yml | 2 +- rust-toolchain.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index f3e377223..241a03334 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -24,7 +24,7 @@ jobs: env: SCCACHE_CACHE_SIZE: "60G" steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Install toolchain uses: dtolnay/rust-toolchain@nightly - name: Install Wasm toolchain diff --git a/rust-toolchain.toml b/rust-toolchain.toml index 6939a60b0..70f3463b8 100644 --- a/rust-toolchain.toml +++ b/rust-toolchain.toml @@ -1,4 +1,4 @@ [toolchain] -channel = "1.73.0" +channel = "1.74.0" components = ["rustfmt", "clippy"] targets = ["wasm32-unknown-unknown"] From 139c32f3522b4b3e603ad5cb9dca106e1afc9110 Mon Sep 17 00:00:00 2001 From: zjb0807 Date: Fri, 22 Dec 2023 04:17:32 +0800 Subject: [PATCH 2/2] remove migrations (#972) --- asset-registry/src/lib.rs | 3 - asset-registry/src/migrations.rs | 44 ----------- asset-registry/src/tests.rs | 129 +------------------------------ unknown-tokens/src/lib.rs | 3 - unknown-tokens/src/migrations.rs | 86 --------------------- unknown-tokens/src/tests.rs | 113 +-------------------------- 6 files changed, 2 insertions(+), 376 deletions(-) delete mode 100644 asset-registry/src/migrations.rs delete mode 100644 unknown-tokens/src/migrations.rs diff --git a/asset-registry/src/lib.rs b/asset-registry/src/lib.rs index 9f1cb727b..7f6e4caef 100644 --- a/asset-registry/src/lib.rs +++ b/asset-registry/src/lib.rs @@ -28,9 +28,6 @@ mod mock; #[cfg(test)] mod tests; -mod migrations; -pub use migrations::Migration; - #[frame_support::pallet] pub mod module { use super::*; diff --git a/asset-registry/src/migrations.rs b/asset-registry/src/migrations.rs deleted file mode 100644 index eadf9dab1..000000000 --- a/asset-registry/src/migrations.rs +++ /dev/null @@ -1,44 +0,0 @@ -use crate::{Config, LocationToAssetId, Pallet, Weight}; -use frame_support::pallet_prelude::*; -use frame_support::{migration::storage_key_iter, traits::OnRuntimeUpgrade, StoragePrefixedMap}; - -use xcm::v3::prelude::*; - -pub struct Migration(PhantomData); -impl OnRuntimeUpgrade for Migration { - fn on_runtime_upgrade() -> Weight { - let mut weight: Weight = Weight::zero(); - let onchain_version = Pallet::::on_chain_storage_version(); - if onchain_version < 2 { - let inner_weight = v2::migrate::(); - weight.saturating_accrue(inner_weight); - } - weight - } -} - -mod v2 { - use super::*; - - pub(crate) fn migrate() -> Weight { - let mut weight: Weight = Weight::zero(); - let module_prefix = LocationToAssetId::::pallet_prefix(); - let storage_prefix = LocationToAssetId::::storage_prefix(); - - weight.saturating_accrue(T::DbWeight::get().reads(1)); - let old_data = - storage_key_iter::(module_prefix, storage_prefix) - .drain() - .collect::>(); - - for (old_key, value) in old_data { - weight.saturating_accrue(T::DbWeight::get().writes(1)); - let new_key: MultiLocation = old_key.try_into().expect("Stored xcm::v2::MultiLocation"); - LocationToAssetId::::insert(new_key, value); - } - - StorageVersion::new(2).put::>(); - weight.saturating_accrue(T::DbWeight::get().writes(1)); - weight - } -} diff --git a/asset-registry/src/tests.rs b/asset-registry/src/tests.rs index 5ccaa3142..d8bc6b206 100644 --- a/asset-registry/src/tests.rs +++ b/asset-registry/src/tests.rs @@ -3,12 +3,7 @@ use super::*; use crate as orml_asset_registry; use crate::tests::para::{AdminAssetTwo, AssetRegistry, CustomMetadata, RuntimeOrigin, Tokens, TreasuryAccount}; -use frame_support::{ - assert_noop, assert_ok, - storage::migration::{get_storage_value, put_storage_value}, - traits::OnRuntimeUpgrade, - StorageHasher, -}; +use frame_support::{assert_noop, assert_ok, traits::OnRuntimeUpgrade, StorageHasher}; use mock::{para::RuntimeCall, *}; use orml_traits::MultiCurrency; use polkadot_parachain_primitives::primitives::Sibling; @@ -594,128 +589,6 @@ fn test_v2_to_v3_incompatible_multilocation() { ); } -#[test] -fn from_unversioned_to_v2_storage() { - TestNet::reset(); - - ParaA::execute_with(|| { - let module_prefix = b"AssetRegistry"; - let storage_prefix = b"LocationToAssetId"; - - // StorageVersion is 0 before migration - assert_eq!(StorageVersion::get::>(), 0); - - // V2 storage - let old_multilocation_0 = xcm::v2::MultiLocation::new( - 0, - xcm::v2::Junctions::X1(xcm::v2::Junction::GeneralKey(vec![0].try_into().unwrap())), - ); - let old_multilocation_1 = xcm::v2::MultiLocation::new( - 1, - xcm::v2::Junctions::X2( - xcm::v2::Junction::Parachain(2096), - xcm::v2::Junction::GeneralKey(vec![0, 0, 0, 0, 0, 0, 0, 0, 0].try_into().unwrap()), - ), - ); - let old_multilocation_2 = xcm::v2::MultiLocation::new( - 1, - xcm::v2::Junctions::X2( - xcm::v2::Junction::Parachain(2096), - xcm::v2::Junction::GeneralKey(vec![1, 1].try_into().unwrap()), - ), - ); - - let asset_id_0: para::ParaAssetId = 5u32; - let asset_id_1: para::ParaAssetId = 6u32; - let asset_id_2: para::ParaAssetId = 7u32; - - // Store raw xcm::v2 data - put_storage_value( - module_prefix, - storage_prefix, - &Twox64Concat::hash(&old_multilocation_0.encode()), - asset_id_0, - ); - put_storage_value( - module_prefix, - storage_prefix, - &Twox64Concat::hash(&old_multilocation_1.encode()), - asset_id_1, - ); - put_storage_value( - module_prefix, - storage_prefix, - &Twox64Concat::hash(&old_multilocation_2.encode()), - asset_id_2, - ); - - // V3 storage key - let new_multilocation_0 = MultiLocation::new(0, X1(Junction::from(BoundedVec::try_from(vec![0]).unwrap()))); - let new_multilocation_1 = MultiLocation::new( - 1, - X2( - Parachain(2096), - Junction::from(BoundedVec::try_from(vec![0, 0, 0, 0, 0, 0, 0, 0, 0]).unwrap()), - ), - ); - let new_multilocation_2 = MultiLocation::new( - 1, - X2( - Parachain(2096), - Junction::from(BoundedVec::try_from(vec![1, 1]).unwrap()), - ), - ); - - // Assert new StorageKey still does not exist - assert_eq!(AssetRegistry::location_to_asset_id(new_multilocation_0), None); - assert_eq!(AssetRegistry::location_to_asset_id(new_multilocation_1), None); - assert_eq!(AssetRegistry::location_to_asset_id(new_multilocation_2), None); - - // Run StorageKey migration - crate::Migration::::on_runtime_upgrade(); - - // StorageVersion is 2 after migration - assert_eq!(StorageVersion::get::>(), 2); - - // Assert the StorageKey exists and has been migrated to xcm::v3 - assert_eq!( - AssetRegistry::location_to_asset_id(new_multilocation_0), - Some(asset_id_0) - ); - assert_eq!( - AssetRegistry::location_to_asset_id(new_multilocation_1), - Some(asset_id_1) - ); - assert_eq!( - AssetRegistry::location_to_asset_id(new_multilocation_2), - Some(asset_id_2) - ); - - // Assert the old key does not exist anymore - assert!(get_storage_value::( - module_prefix, - storage_prefix, - &Twox64Concat::hash(&old_multilocation_0.encode()), - ) - .is_none()); - assert!(get_storage_value::( - module_prefix, - storage_prefix, - &Twox64Concat::hash(&old_multilocation_1.encode()), - ) - .is_none()); - assert!(get_storage_value::( - module_prefix, - storage_prefix, - &Twox64Concat::hash(&old_multilocation_2.encode()), - ) - .is_none()); - - // Assert further calls are no-op - assert_eq!(crate::Migration::::on_runtime_upgrade(), Weight::zero()); - }); -} - #[test] fn test_decode_bounded_vec() { TestNet::reset(); diff --git a/unknown-tokens/src/lib.rs b/unknown-tokens/src/lib.rs index 9f3608241..1cc6caf67 100644 --- a/unknown-tokens/src/lib.rs +++ b/unknown-tokens/src/lib.rs @@ -12,9 +12,6 @@ pub use module::*; mod mock; mod tests; -mod migrations; -pub use migrations::Migration; - #[frame_support::pallet] pub mod module { use super::*; diff --git a/unknown-tokens/src/migrations.rs b/unknown-tokens/src/migrations.rs deleted file mode 100644 index 05177dc5a..000000000 --- a/unknown-tokens/src/migrations.rs +++ /dev/null @@ -1,86 +0,0 @@ -use crate::{AbstractFungibleBalances, ConcreteFungibleBalances, Config, Pallet, Weight}; -use frame_support::pallet_prelude::*; -use frame_support::{migration::storage_iter, traits::OnRuntimeUpgrade, ReversibleStorageHasher, StoragePrefixedMap}; - -use sp_std::vec::Vec; - -use xcm::v3::prelude::*; - -pub struct Migration(PhantomData); -impl OnRuntimeUpgrade for Migration { - fn on_runtime_upgrade() -> Weight { - let mut weight: Weight = Weight::zero(); - let onchain_version = Pallet::::on_chain_storage_version(); - if onchain_version < 2 { - let inner_weight = v2::migrate::(); - weight.saturating_accrue(inner_weight); - } - weight - } -} - -mod v2 { - use super::*; - - pub(crate) fn migrate() -> Weight { - let mut weight: Weight = Weight::zero(); - - // ConcreteFungibleBalances - let module_prefix = ConcreteFungibleBalances::::pallet_prefix(); - let storage_prefix = ConcreteFungibleBalances::::storage_prefix(); - - weight.saturating_accrue(T::DbWeight::get().reads(1)); - - let old_data = storage_iter::(module_prefix, storage_prefix) - .drain() - .collect::>(); - - for (raw_k, value) in old_data { - let mut full_key = Vec::new(); - full_key.extend_from_slice(&raw_k); - - let mut k1_k2_material = Blake2_128Concat::reverse(&full_key); - let k1: xcm::v2::MultiLocation = - Decode::decode(&mut k1_k2_material).expect("Stored k1 xcm::v2::MultiLocation"); - - let mut k2_material = Blake2_128Concat::reverse(k1_k2_material); - let k2: xcm::v2::MultiLocation = - Decode::decode(&mut k2_material).expect("Stored k2 xcm::v2::MultiLocation"); - - weight.saturating_accrue(T::DbWeight::get().writes(1)); - let k1_new: MultiLocation = k1.try_into().expect("Stored k1 xcm::v2::MultiLocation"); - let k2_new: MultiLocation = k2.try_into().expect("Stored k2 xcm::v2::MultiLocation"); - ConcreteFungibleBalances::::insert(k1_new, k2_new, value); - } - - // AbstractFungibleBalances - let module_prefix = AbstractFungibleBalances::::pallet_prefix(); - let storage_prefix = AbstractFungibleBalances::::storage_prefix(); - - weight.saturating_accrue(T::DbWeight::get().reads(1)); - - let old_data = storage_iter::(module_prefix, storage_prefix) - .drain() - .collect::>(); - - for (raw_k, value) in old_data { - let mut full_key = Vec::new(); - full_key.extend_from_slice(&raw_k); - - let mut k1_k2_material = Blake2_128Concat::reverse(&full_key); - let k1: xcm::v2::MultiLocation = - Decode::decode(&mut k1_k2_material).expect("Stored k1 xcm::v2::MultiLocation"); - - let mut k2_material = Blake2_128Concat::reverse(k1_k2_material); - let k2_new: Vec = Decode::decode(&mut k2_material).expect("Stored k1 xcm::v2::MultiLocation"); - - weight.saturating_accrue(T::DbWeight::get().writes(1)); - let k1_new: MultiLocation = k1.try_into().expect("Stored k1 xcm::v2::MultiLocation"); - AbstractFungibleBalances::::insert(k1_new, k2_new, value); - } - - StorageVersion::new(2).put::>(); - weight.saturating_accrue(T::DbWeight::get().writes(1)); - weight - } -} diff --git a/unknown-tokens/src/tests.rs b/unknown-tokens/src/tests.rs index 66d573cc6..5ef1d1a74 100644 --- a/unknown-tokens/src/tests.rs +++ b/unknown-tokens/src/tests.rs @@ -5,14 +5,7 @@ use super::*; use mock::*; -use frame_support::{ - assert_err, assert_ok, - storage::{ - migration::{get_storage_value, put_storage_value}, - unhashed::put_raw, - }, - traits::OnRuntimeUpgrade, -}; +use frame_support::{assert_err, assert_ok, storage::unhashed::put_raw, traits::OnRuntimeUpgrade}; const MOCK_RECIPIENT: MultiLocation = MultiLocation::parent(); const MOCK_CONCRETE_FUNGIBLE_ID: MultiLocation = MultiLocation::parent(); @@ -158,107 +151,3 @@ fn withdraw_unhandled_asset_should_fail() { ); }); } - -#[test] -fn from_unversioned_to_v2_storage() { - ExtBuilder.build().execute_with(|| { - fn blake2_128_concat(d: &[u8]) -> Vec { - let mut v = sp_io::hashing::blake2_128(d).to_vec(); - v.extend_from_slice(d); - v - } - - // StorageVersion is 0 before migration - assert_eq!(StorageVersion::get::>(), 0); - - // V2 `ConcreteFungibleBalances` key - let mut old_concrete_key = Vec::new(); - old_concrete_key.extend_from_slice( - &xcm::v2::MultiLocation::new( - 0, - xcm::v2::Junctions::X1(xcm::v2::Junction::GeneralKey(vec![0].try_into().unwrap())), - ) - .using_encoded(blake2_128_concat), - ); - old_concrete_key.extend_from_slice(&xcm::v2::MultiLocation::here().using_encoded(blake2_128_concat)); - - let balance = 55u128; - - put_storage_value( - b"UnknownTokens", - b"ConcreteFungibleBalances", - &old_concrete_key, - balance, - ); - - // V2 `AbstractFungibleBalances` key - let mut old_abstract_key = Vec::new(); - old_abstract_key.extend_from_slice( - &xcm::v2::MultiLocation::new( - 0, - xcm::v2::Junctions::X1(xcm::v2::Junction::GeneralKey(vec![0].try_into().unwrap())), - ) - .using_encoded(blake2_128_concat), - ); - old_abstract_key.extend_from_slice(&vec![1].using_encoded(blake2_128_concat)); - - let balance = 77u128; - - put_storage_value( - b"UnknownTokens", - b"AbstractFungibleBalances", - &old_abstract_key, - balance, - ); - - // V3 storage keys - let new_concrete_k1 = MultiLocation::new(0, X1(Junction::from(BoundedVec::try_from(vec![0]).unwrap()))); - let new_concrete_k2 = MultiLocation::here(); - let new_abstract_k1 = MultiLocation::new(0, X1(Junction::from(BoundedVec::try_from(vec![0]).unwrap()))); - let new_abstract_k2 = vec![1]; - - // Assert new StorageKey still does not exist - assert_eq!( - UnknownTokens::concrete_fungible_balances(new_concrete_k1, new_concrete_k2), - 0 - ); - assert_eq!( - UnknownTokens::abstract_fungible_balances(new_abstract_k1, new_abstract_k2.clone()), - 0 - ); - - // Migrate - crate::Migration::::on_runtime_upgrade(); - - // StorageVersion is 2 after migration - assert_eq!(StorageVersion::get::>(), 2); - - // Assert the StorageKey exists and has been migrated to xcm::v3 - assert_eq!( - UnknownTokens::concrete_fungible_balances(new_concrete_k1, new_concrete_k2), - 55 - ); - assert_eq!( - UnknownTokens::abstract_fungible_balances(new_abstract_k1, new_abstract_k2), - 77 - ); - - // Assert the old concrete key does not exist anymore - assert!(get_storage_value::(b"UnknownTokens", b"ConcreteFungibleBalances", &old_concrete_key,).is_none()); - - // Assert the old abstract key does not exist anymore - assert!(get_storage_value::(b"UnknownTokens", b"AbstractFungibleBalances", &old_concrete_key,).is_none()); - - // Assert further calls are no-op - assert_eq!(crate::Migration::::on_runtime_upgrade(), Weight::zero()); - }); -} - -#[test] -fn migrate_should_not_panic() { - ExtBuilder.build().execute_with(|| { - put_raw(&hex_literal::hex!["8d4649c9ee31ba6b2d10c66f5fcc252e76391a415c3fca956dccff701fe02e98082b3a7e1c0db7de23c07c6f14cc6c51000100411f728d113b5f9fee983dba4cbb22827c05000106080081"], &hex_literal::hex!["0b2493d4010000000000000000000000"]); - - crate::Migration::::on_runtime_upgrade(); - }); -}