diff --git a/runtime/crab/src/migration.rs b/runtime/crab/src/migration.rs index a0238283b..198778bb6 100644 --- a/runtime/crab/src/migration.rs +++ b/runtime/crab/src/migration.rs @@ -45,15 +45,5 @@ impl frame_support::traits::OnRuntimeUpgrade for CustomOnRuntimeUpgrade { } fn migrate() -> frame_support::weights::Weight { - /// polkadot-sdk - use frame_support::PalletId; - use sp_runtime::traits::AccountIdConversion; - - let _ = Balances::transfer_all( - RuntimeOrigin::signed(PalletId(*b"dar/depo").into_account_truncating()), - Treasury::account_id(), - false, - ); - - ::DbWeight::get().reads_writes(0, 6) + ::DbWeight::get().reads_writes(0, 0) } diff --git a/runtime/darwinia/src/migration.rs b/runtime/darwinia/src/migration.rs index 50f6f9a92..3f4d029e6 100644 --- a/runtime/darwinia/src/migration.rs +++ b/runtime/darwinia/src/migration.rs @@ -21,7 +21,7 @@ use crate::*; // polkadot-sdk #[allow(unused_imports)] -use frame_support::{migration, storage::unhashed}; +use frame_support::migration; pub struct CustomOnRuntimeUpgrade; impl frame_support::traits::OnRuntimeUpgrade for CustomOnRuntimeUpgrade { @@ -29,21 +29,6 @@ impl frame_support::traits::OnRuntimeUpgrade for CustomOnRuntimeUpgrade { fn pre_upgrade() -> Result, sp_runtime::DispatchError> { log::info!("pre"); - assert!(migration::storage_iter::<()>(b"Vesting", b"Vesting").count() == 1); - assert_eq!( - Balances::locks( - // 0x081cbab52e2dbcd52f441c7ae9ad2a3be42e2284. - AccountId::from([ - 8, 28, 186, 181, 46, 45, 188, 213, 47, 68, 28, 122, 233, 173, 42, 59, 228, 46, - 34, 132, - ]), - ) - .into_iter() - .map(|l| l.id) - .collect::>(), - [*b"vesting "], - ); - Ok(Vec::new()) } @@ -51,18 +36,6 @@ impl frame_support::traits::OnRuntimeUpgrade for CustomOnRuntimeUpgrade { fn post_upgrade(_state: Vec) -> Result<(), sp_runtime::DispatchError> { log::info!("post"); - darwinia_staking::migration::post_check::(); - - assert!(migration::storage_iter::<()>(b"Vesting", b"Vesting").count() == 0); - assert!(Balances::locks( - // 0x081cbab52e2dbcd52f441c7ae9ad2a3be42e2284. - AccountId::from([ - 8, 28, 186, 181, 46, 45, 188, 213, 47, 68, 28, 122, 233, 173, 42, 59, 228, 46, 34, - 132, - ]), - ) - .is_empty()); - Ok(()) } @@ -72,26 +45,77 @@ impl frame_support::traits::OnRuntimeUpgrade for CustomOnRuntimeUpgrade { } fn migrate() -> frame_support::weights::Weight { - // polkadot-sdk - use frame_support::{traits::LockableCurrency, PalletId}; - use sp_runtime::traits::AccountIdConversion; - - let (r, w) = darwinia_staking::migration::migrate::(); - let _ = migration::clear_storage_prefix(b"Vesting", b"Vesting", &[], None, None); - - Balances::remove_lock( - *b"vesting ", - // 0x081cbab52e2dbcd52f441c7ae9ad2a3be42e2284. - &AccountId::from([ - 8, 28, 186, 181, 46, 45, 188, 213, 47, 68, 28, 122, 233, 173, 42, 59, 228, 46, 34, 132, - ]), - ); + use codec::Decode; + use frame_support::weights::Weight; + + #[derive(Decode, Eq, Ord, PartialEq, PartialOrd)] + enum OldAssetType { + Xcm(xcm::v3::Location), + } + + let supported_assets = + if let Some(supported_assets) = frame_support::storage::migration::get_storage_value::< + Vec, + >(b"AssetManager", b"SupportedFeePaymentAssets", &[]) + { + sp_std::collections::btree_set::BTreeSet::from_iter( + supported_assets.into_iter().map(|OldAssetType::Xcm(location_v3)| location_v3), + ) + } else { + return Weight::default(); + }; + + let mut assets: Vec<(xcm::v4::Location, (bool, u128))> = Vec::new(); + + for (OldAssetType::Xcm(location_v3), units_per_seconds) in + frame_support::storage::migration::storage_key_iter::< + OldAssetType, + u128, + frame_support::Blake2_128Concat, + >(b"AssetManager", b"AssetTypeUnitsPerSecond") + { + let enabled = supported_assets.contains(&location_v3); + + if let Ok(location_v4) = location_v3.try_into() { + assets.push((location_v4, (enabled, units_per_seconds))); + } + } + + //***** Start mutate storage *****// + + // Write asset metadata in new pallet_xcm_weight_trader + use frame_support::weights::WeightToFee as _; + for (asset_location, (enabled, units_per_second)) in assets { + let native_amount_per_second: u128 = + ::WeightToFee::weight_to_fee( + &Weight::from_parts( + frame_support::weights::constants::WEIGHT_REF_TIME_PER_SECOND, + 0, + ), + ); + let relative_price: u128 = native_amount_per_second + .saturating_mul(10u128.pow(pallet_xcm_weight_trader::RELATIVE_PRICE_DECIMALS)) + .saturating_div(units_per_second); + pallet_xcm_weight_trader::SupportedAssets::::insert( + asset_location, + (enabled, relative_price), + ); + } + + // Remove storage value AssetManager::SupportedFeePaymentAssets + frame_support::storage::unhashed::kill(&frame_support::storage::storage_prefix( + b"AssetManager", + b"SupportedFeePaymentAssets", + )); - let _ = Balances::transfer_all( - RuntimeOrigin::signed(PalletId(*b"dar/depo").into_account_truncating()), - Treasury::account_id(), - false, + // Remove storage map AssetManager::AssetTypeUnitsPerSecond + let _ = frame_support::storage::migration::clear_storage_prefix( + b"AssetManager", + b"AssetTypeUnitsPerSecond", + &[], + None, + None, ); - ::DbWeight::get().reads_writes(r, w + 10) + ::DbWeight::get().reads_writes(30, 30) } diff --git a/runtime/koi/src/lib.rs b/runtime/koi/src/lib.rs index 7d448cc0d..55df6f03b 100644 --- a/runtime/koi/src/lib.rs +++ b/runtime/koi/src/lib.rs @@ -84,7 +84,7 @@ pub const VERSION: sp_version::RuntimeVersion = sp_version::RuntimeVersion { spec_name: sp_runtime::create_runtime_str!("Darwinia Koi"), impl_name: sp_runtime::create_runtime_str!("DarwiniaOfficialRust"), authoring_version: 0, - spec_version: 6_8_1_0, + spec_version: 6_8_1_1, impl_version: 0, apis: RUNTIME_API_VERSIONS, transaction_version: 0, diff --git a/runtime/koi/src/migration.rs b/runtime/koi/src/migration.rs index 350ecc858..e7aaa354f 100644 --- a/runtime/koi/src/migration.rs +++ b/runtime/koi/src/migration.rs @@ -47,7 +47,77 @@ impl frame_support::traits::OnRuntimeUpgrade for CustomOnRuntimeUpgrade { } fn migrate() -> frame_support::weights::Weight { - let (r, w) = darwinia_staking::migration::migrate::(); + use codec::Decode; + use frame_support::weights::Weight; - ::DbWeight::get().reads_writes(r, w) + #[derive(Decode, Eq, Ord, PartialEq, PartialOrd)] + enum OldAssetType { + Xcm(xcm::v3::Location), + } + + let supported_assets = + if let Some(supported_assets) = frame_support::storage::migration::get_storage_value::< + Vec, + >(b"AssetManager", b"SupportedFeePaymentAssets", &[]) + { + sp_std::collections::btree_set::BTreeSet::from_iter( + supported_assets.into_iter().map(|OldAssetType::Xcm(location_v3)| location_v3), + ) + } else { + return Weight::default(); + }; + + let mut assets: Vec<(xcm::v4::Location, (bool, u128))> = Vec::new(); + + for (OldAssetType::Xcm(location_v3), units_per_seconds) in + frame_support::storage::migration::storage_key_iter::< + OldAssetType, + u128, + frame_support::Blake2_128Concat, + >(b"AssetManager", b"AssetTypeUnitsPerSecond") + { + let enabled = supported_assets.contains(&location_v3); + + if let Ok(location_v4) = location_v3.try_into() { + assets.push((location_v4, (enabled, units_per_seconds))); + } + } + + //***** Start mutate storage *****// + + // Write asset metadata in new pallet_xcm_weight_trader + use frame_support::weights::WeightToFee as _; + for (asset_location, (enabled, units_per_second)) in assets { + let native_amount_per_second: u128 = + ::WeightToFee::weight_to_fee( + &Weight::from_parts( + frame_support::weights::constants::WEIGHT_REF_TIME_PER_SECOND, + 0, + ), + ); + let relative_price: u128 = native_amount_per_second + .saturating_mul(10u128.pow(pallet_xcm_weight_trader::RELATIVE_PRICE_DECIMALS)) + .saturating_div(units_per_second); + pallet_xcm_weight_trader::SupportedAssets::::insert( + asset_location, + (enabled, relative_price), + ); + } + + // Remove storage value AssetManager::SupportedFeePaymentAssets + frame_support::storage::unhashed::kill(&frame_support::storage::storage_prefix( + b"AssetManager", + b"SupportedFeePaymentAssets", + )); + + // Remove storage map AssetManager::AssetTypeUnitsPerSecond + let _ = frame_support::storage::migration::clear_storage_prefix( + b"AssetManager", + b"AssetTypeUnitsPerSecond", + &[], + None, + None, + ); + + ::DbWeight::get().reads_writes(15, 15) }