From 4c8c956fc61d9b9888d2ddf2b77cf7490e5e2c5e Mon Sep 17 00:00:00 2001 From: Ozgun Ozerk Date: Thu, 19 Sep 2024 14:29:38 +0300 Subject: [PATCH] fix asset manager pallet --- pallets/asset-manager/src/benchmarks.rs | 75 -------- pallets/asset-manager/src/lib.rs | 197 +------------------- pallets/asset-manager/src/mock.rs | 5 + pallets/asset-manager/src/tests.rs | 236 +----------------------- pallets/asset-manager/src/weights.rs | 102 ++-------- 5 files changed, 31 insertions(+), 584 deletions(-) diff --git a/pallets/asset-manager/src/benchmarks.rs b/pallets/asset-manager/src/benchmarks.rs index a444a0ae1b..e4c1ec26d7 100644 --- a/pallets/asset-manager/src/benchmarks.rs +++ b/pallets/asset-manager/src/benchmarks.rs @@ -36,47 +36,7 @@ benchmarks! { assert_eq!(Pallet::::asset_id_type(asset_id), Some(asset_type)); } - set_asset_units_per_second { - // We make it dependent on the number of existing assets already - let x in 5..100; - for i in 0..x { - let asset_type: T::ForeignAssetType = Location::new( - 0, - X1(GeneralIndex(i as u128)) - ).into(); - let metadata = T::AssetRegistrarMetadata::default(); - let amount = 1u32.into(); - Pallet::::register_foreign_asset( - RawOrigin::Root.into(), - asset_type.clone(), - metadata, - amount, - true - )?; - Pallet::::set_asset_units_per_second(RawOrigin::Root.into(), asset_type.clone(), 1, i)?; - } - - // does not really matter what we register, as long as it is different than the previous - let asset_type = T::ForeignAssetType::default(); - let metadata = T::AssetRegistrarMetadata::default(); - let amount = 1u32.into(); - let asset_id: T::AssetId = asset_type.clone().into(); - Pallet::::register_foreign_asset( - RawOrigin::Root.into(), - asset_type.clone(), - metadata, - amount, - true - )?; - - }: _(RawOrigin::Root, asset_type.clone(), 1, x) - verify { - assert!(Pallet::::supported_fee_payment_assets().contains(&asset_type)); - assert_eq!(Pallet::::asset_type_units_per_second(asset_type), Some(1)); - } - change_existing_asset_type { - // We make it dependent on the number of existing assets already let x in 5..100; for i in 0..x { let asset_type: T::ForeignAssetType = Location::new(0, X1(GeneralIndex(i as u128))).into(); @@ -89,7 +49,6 @@ benchmarks! { amount, true )?; - Pallet::::set_asset_units_per_second(RawOrigin::Root.into(), asset_type.clone(), 1, i)?; } let new_asset_type = T::ForeignAssetType::default(); @@ -101,40 +60,9 @@ benchmarks! { }: _(RawOrigin::Root, asset_id_to_be_changed, new_asset_type.clone(), x) verify { assert_eq!(Pallet::::asset_id_type(asset_id_to_be_changed), Some(new_asset_type.clone())); - assert_eq!(Pallet::::asset_type_units_per_second(&new_asset_type), Some(1)); - assert!(Pallet::::supported_fee_payment_assets().contains(&new_asset_type)); - } - - remove_supported_asset { - // We make it dependent on the number of existing assets already - let x in 5..100; - for i in 0..x { - let asset_type: T::ForeignAssetType = Location::new(0, X1(GeneralIndex(i as u128))).into(); - let metadata = T::AssetRegistrarMetadata::default(); - let amount = 1u32.into(); - Pallet::::register_foreign_asset( - RawOrigin::Root.into(), - asset_type.clone(), - metadata, - amount, - true - )?; - Pallet::::set_asset_units_per_second(RawOrigin::Root.into(), asset_type.clone(), 1, i)?; - } - let asset_type_to_be_removed: T::ForeignAssetType = Location::new( - 0, - X1(GeneralIndex((x-1) as u128)) - ).into(); - // We try to remove the last asset type - }: _(RawOrigin::Root, asset_type_to_be_removed.clone(), x) - verify { - assert!(!Pallet::::supported_fee_payment_assets().contains(&asset_type_to_be_removed)); - assert_eq!(Pallet::::asset_type_units_per_second(asset_type_to_be_removed), None); } remove_existing_asset_type { - // We make it dependent on the number of existing assets already - // Worst case is we need to remove it from SupportedAAssetsFeePayment too let x in 5..100; for i in 0..x { let asset_type: T::ForeignAssetType = Location::new(0, X1(GeneralIndex(i as u128))).into(); @@ -147,7 +75,6 @@ benchmarks! { amount, true )?; - Pallet::::set_asset_units_per_second(RawOrigin::Root.into(), asset_type.clone(), 1, i)?; } let asset_type_to_be_removed: T::ForeignAssetType = Location::new( @@ -158,8 +85,6 @@ benchmarks! { }: _(RawOrigin::Root, asset_id, x) verify { assert!(Pallet::::asset_id_type(asset_id).is_none()); - assert!(Pallet::::asset_type_units_per_second(&asset_type_to_be_removed).is_none()); - assert!(!Pallet::::supported_fee_payment_assets().contains(&asset_type_to_be_removed)); } } diff --git a/pallets/asset-manager/src/lib.rs b/pallets/asset-manager/src/lib.rs index f72b6ac543..4d5813a326 100644 --- a/pallets/asset-manager/src/lib.rs +++ b/pallets/asset-manager/src/lib.rs @@ -27,8 +27,6 @@ //! //! This pallet has eight extrinsics: register_foreign_asset, which registers a foreign //! asset in this pallet and creates the asset as dictated by the AssetRegistrar trait. -//! set_asset_units_per_second: which sets the unit per second that should be charged for -//! a particular asset. //! change_existing_asset_type: which allows to update the correspondence between AssetId and //! AssetType //! remove_supported_asset: which removes an asset from the supported assets for fee payment @@ -57,7 +55,6 @@ pub mod pallet { use frame_system::pallet_prelude::*; use parity_scale_codec::HasCompact; use sp_runtime::traits::{AccountIdConversion, AtLeast32BitUnsigned}; - use sp_std::vec::Vec; #[pallet::pallet] #[pallet::without_storage_info] @@ -105,28 +102,6 @@ pub mod pallet { } } - impl xcm_primitives::UnitsToWeightRatio for Pallet { - fn payment_is_supported(asset_type: T::ForeignAssetType) -> bool { - SupportedFeePaymentAssets::::get() - .binary_search(&asset_type) - .is_ok() - } - fn get_units_per_second(asset_type: T::ForeignAssetType) -> Option { - AssetTypeUnitsPerSecond::::get(asset_type) - } - #[cfg(feature = "runtime-benchmarks")] - fn set_units_per_second(asset_type: T::ForeignAssetType, fee_per_second: u128) { - // Grab supported assets - let mut supported_assets = SupportedFeePaymentAssets::::get(); - // Only if the asset is not supported we need to push it - if let Err(index) = supported_assets.binary_search(&asset_type) { - supported_assets.insert(index, asset_type.clone()); - SupportedFeePaymentAssets::::put(supported_assets); - } - AssetTypeUnitsPerSecond::::insert(&asset_type, &fee_per_second); - } - } - #[pallet::config] pub trait Config: frame_system::Config { type RuntimeEvent: From> + IsType<::RuntimeEvent>; @@ -177,12 +152,10 @@ pub mod pallet { metadata: T::AssetRegistrarMetadata, }, /// Changed the amount of units we are charging per execution second for a given asset - UnitsPerSecondChanged { - asset_type: T::ForeignAssetType, - units_per_second: u128, - }, + #[deprecated(note = "Should not be used")] + UnitsPerSecondChanged, /// Changed the xcm type mapping for a given asset id - ForeignAssetTypeChanged { + ForeignAssetXcmLocationChanged { asset_id: T::AssetId, new_asset_type: T::ForeignAssetType, }, @@ -218,21 +191,6 @@ pub mod pallet { pub type AssetTypeId = StorageMap<_, Blake2_128Concat, T::ForeignAssetType, T::AssetId>; - /// Stores the units per second for local execution for a AssetType. - /// This is used to know how to charge for XCM execution in a particular - /// asset - /// Not all assets might contain units per second, hence the different storage - #[pallet::storage] - #[pallet::getter(fn asset_type_units_per_second)] - pub type AssetTypeUnitsPerSecond = - StorageMap<_, Blake2_128Concat, T::ForeignAssetType, u128>; - - // Supported fee asset payments - #[pallet::storage] - #[pallet::getter(fn supported_fee_payment_assets)] - pub type SupportedFeePaymentAssets = - StorageValue<_, Vec, ValueQuery>; - #[pallet::call] impl Pallet { /// Register new asset with the asset manager @@ -275,68 +233,19 @@ pub mod pallet { Ok(()) } - /// Change the amount of units we are charging per execution second - /// for a given ForeignAssetType - #[pallet::call_index(1)] - #[pallet::weight(T::WeightInfo::set_asset_units_per_second(*num_assets_weight_hint))] - pub fn set_asset_units_per_second( - origin: OriginFor, - asset_type: T::ForeignAssetType, - units_per_second: u128, - num_assets_weight_hint: u32, - ) -> DispatchResult { - T::ForeignAssetModifierOrigin::ensure_origin(origin)?; - - // Ensure such an assetId does not exist - ensure!( - AssetTypeId::::get(&asset_type).is_some(), - Error::::AssetDoesNotExist - ); - - // Grab supported assets - let mut supported_assets = SupportedFeePaymentAssets::::get(); - - ensure!( - num_assets_weight_hint >= (supported_assets.len() as u32), - Error::::TooLowNumAssetsWeightHint - ); - - // Only if the asset is not supported we need to push it - if let Err(index) = supported_assets.binary_search(&asset_type) { - supported_assets.insert(index, asset_type.clone()); - SupportedFeePaymentAssets::::put(supported_assets); - } - - AssetTypeUnitsPerSecond::::insert(&asset_type, &units_per_second); - - Self::deposit_event(Event::UnitsPerSecondChanged { - asset_type, - units_per_second, - }); - Ok(()) - } - /// Change the xcm type mapping for a given assetId /// We also change this if the previous units per second where pointing at the old /// assetType #[pallet::call_index(2)] - #[pallet::weight(T::WeightInfo::change_existing_asset_type(*num_assets_weight_hint))] + #[pallet::weight(T::WeightInfo::change_existing_asset_type())] pub fn change_existing_asset_type( origin: OriginFor, asset_id: T::AssetId, new_asset_type: T::ForeignAssetType, - num_assets_weight_hint: u32, + _num_assets_weight_hint: u32, ) -> DispatchResult { T::ForeignAssetModifierOrigin::ensure_origin(origin)?; - // Grab supported assets - let mut supported_assets = SupportedFeePaymentAssets::::get(); - - ensure!( - num_assets_weight_hint >= (supported_assets.len() as u32), - Error::::TooLowNumAssetsWeightHint - ); - let previous_asset_type = AssetIdType::::get(&asset_id).ok_or(Error::::AssetDoesNotExist)?; @@ -347,83 +256,23 @@ pub mod pallet { // Remove previous asset type info AssetTypeId::::remove(&previous_asset_type); - // Change AssetTypeUnitsPerSecond - if let Some(units) = AssetTypeUnitsPerSecond::::get(&previous_asset_type) { - // Only if the old asset is supported we need to remove it - if let Ok(index) = supported_assets.binary_search(&previous_asset_type) { - supported_assets.remove(index); - } - - // Only if the new asset is not supported we need to push it - if let Err(index) = supported_assets.binary_search(&new_asset_type) { - supported_assets.insert(index, new_asset_type.clone()); - } - - // Insert supported fee payment assets - SupportedFeePaymentAssets::::put(supported_assets); - - // Remove previous asset type info - AssetTypeUnitsPerSecond::::remove(&previous_asset_type); - AssetTypeUnitsPerSecond::::insert(&new_asset_type, units); - } - - Self::deposit_event(Event::ForeignAssetTypeChanged { + Self::deposit_event(Event::ForeignAssetXcmLocationChanged { asset_id, new_asset_type, }); Ok(()) } - #[pallet::call_index(3)] - #[pallet::weight(T::WeightInfo::remove_supported_asset(*num_assets_weight_hint))] - pub fn remove_supported_asset( - origin: OriginFor, - asset_type: T::ForeignAssetType, - num_assets_weight_hint: u32, - ) -> DispatchResult { - T::ForeignAssetModifierOrigin::ensure_origin(origin)?; - - // Grab supported assets - let mut supported_assets = SupportedFeePaymentAssets::::get(); - - ensure!( - num_assets_weight_hint >= (supported_assets.len() as u32), - Error::::TooLowNumAssetsWeightHint - ); - - // Only if the old asset is supported we need to remove it - if let Ok(index) = supported_assets.binary_search(&asset_type) { - supported_assets.remove(index); - } - - // Insert - SupportedFeePaymentAssets::::put(supported_assets); - - // Remove - AssetTypeUnitsPerSecond::::remove(&asset_type); - - Self::deposit_event(Event::SupportedAssetRemoved { asset_type }); - Ok(()) - } - /// Remove a given assetId -> assetType association #[pallet::call_index(4)] - #[pallet::weight(T::WeightInfo::remove_existing_asset_type(*num_assets_weight_hint))] + #[pallet::weight(T::WeightInfo::remove_existing_asset_type())] pub fn remove_existing_asset_type( origin: OriginFor, asset_id: T::AssetId, - num_assets_weight_hint: u32, + _num_assets_weight_hint: u32, ) -> DispatchResult { T::ForeignAssetModifierOrigin::ensure_origin(origin)?; - // Grab supported assets - let mut supported_assets = SupportedFeePaymentAssets::::get(); - - ensure!( - num_assets_weight_hint >= (supported_assets.len() as u32), - Error::::TooLowNumAssetsWeightHint - ); - let asset_type = AssetIdType::::get(&asset_id).ok_or(Error::::AssetDoesNotExist)?; @@ -431,15 +280,6 @@ pub mod pallet { AssetIdType::::remove(&asset_id); // Remove from AssetTypeId AssetTypeId::::remove(&asset_type); - // Remove previous asset type units per second - AssetTypeUnitsPerSecond::::remove(&asset_type); - - // Only if the old asset is supported we need to remove it - if let Ok(index) = supported_assets.binary_search(&asset_type) { - supported_assets.remove(index); - // Insert - SupportedFeePaymentAssets::::put(supported_assets); - } Self::deposit_event(Event::ForeignAssetRemoved { asset_id, @@ -457,27 +297,19 @@ pub mod pallet { let dispatch_info_weight = T::AssetRegistrar::destroy_asset_dispatch_info_weight( *asset_id ); - T::WeightInfo::remove_existing_asset_type(*num_assets_weight_hint) + T::WeightInfo::remove_existing_asset_type() .saturating_add(dispatch_info_weight) })] pub fn destroy_foreign_asset( origin: OriginFor, asset_id: T::AssetId, - num_assets_weight_hint: u32, + _num_assets_weight_hint: u32, ) -> DispatchResult { T::ForeignAssetModifierOrigin::ensure_origin(origin)?; T::AssetRegistrar::destroy_foreign_asset(asset_id) .map_err(|_| Error::::ErrorDestroyingAsset)?; - // Grab supported assets - let mut supported_assets = SupportedFeePaymentAssets::::get(); - - ensure!( - num_assets_weight_hint >= (supported_assets.len() as u32), - Error::::TooLowNumAssetsWeightHint - ); - let asset_type = AssetIdType::::get(&asset_id).ok_or(Error::::AssetDoesNotExist)?; @@ -485,15 +317,6 @@ pub mod pallet { AssetIdType::::remove(&asset_id); // Remove from AssetTypeId AssetTypeId::::remove(&asset_type); - // Remove previous asset type units per second - AssetTypeUnitsPerSecond::::remove(&asset_type); - - // Only if the old asset is supported we need to remove it - if let Ok(index) = supported_assets.binary_search(&asset_type) { - supported_assets.remove(index); - // Insert - SupportedFeePaymentAssets::::put(supported_assets); - } Self::deposit_event(Event::ForeignAssetDestroyed { asset_id, diff --git a/pallets/asset-manager/src/mock.rs b/pallets/asset-manager/src/mock.rs index 7cc246463c..64def35156 100644 --- a/pallets/asset-manager/src/mock.rs +++ b/pallets/asset-manager/src/mock.rs @@ -69,6 +69,11 @@ impl frame_system::Config for Test { type SS58Prefix = (); type OnSetCode = (); type MaxConsumers = frame_support::traits::ConstU32<16>; + type SingleBlockMigrations = (); + type MultiBlockMigrator = (); + type PreInherents = (); + type PostInherents = (); + type PostTransactions = (); } parameter_types! { diff --git a/pallets/asset-manager/src/tests.rs b/pallets/asset-manager/src/tests.rs index 71bffc3c16..aa2037b727 100644 --- a/pallets/asset-manager/src/tests.rs +++ b/pallets/asset-manager/src/tests.rs @@ -75,44 +75,6 @@ fn test_asset_exists_error() { }); } -#[test] -fn test_root_can_change_units_per_second() { - ExtBuilder::default().build().execute_with(|| { - assert_ok!(AssetManager::register_foreign_asset( - RuntimeOrigin::root(), - MockAssetType::MockAsset(1), - 0u32.into(), - 1u32.into(), - true - )); - - assert_ok!(AssetManager::set_asset_units_per_second( - RuntimeOrigin::root(), - MockAssetType::MockAsset(1), - 200u128.into(), - 0 - )); - - assert_eq!( - AssetManager::asset_type_units_per_second(MockAssetType::MockAsset(1)).unwrap(), - 200 - ); - assert!(AssetManager::supported_fee_payment_assets().contains(&MockAssetType::MockAsset(1))); - - expect_events(vec![ - crate::Event::ForeignAssetRegistered { - asset_id: 1, - asset: MockAssetType::MockAsset(1), - metadata: 0, - }, - crate::Event::UnitsPerSecondChanged { - asset_type: MockAssetType::MockAsset(1), - units_per_second: 200, - }, - ]) - }); -} - #[test] fn test_regular_user_cannot_call_extrinsics() { ExtBuilder::default().build().execute_with(|| { @@ -127,16 +89,6 @@ fn test_regular_user_cannot_call_extrinsics() { sp_runtime::DispatchError::BadOrigin ); - assert_noop!( - AssetManager::set_asset_units_per_second( - RuntimeOrigin::signed(1), - MockAssetType::MockAsset(1), - 200u128.into(), - 0 - ), - sp_runtime::DispatchError::BadOrigin - ); - assert_noop!( AssetManager::change_existing_asset_type( RuntimeOrigin::signed(1), @@ -160,13 +112,6 @@ fn test_root_can_change_asset_id_type() { true )); - assert_ok!(AssetManager::set_asset_units_per_second( - RuntimeOrigin::root(), - MockAssetType::MockAsset(1), - 200u128.into(), - 0 - )); - assert_ok!(AssetManager::change_existing_asset_type( RuntimeOrigin::root(), 1, @@ -174,16 +119,7 @@ fn test_root_can_change_asset_id_type() { 1 )); - // New one contains the new asset type units per second - assert_eq!( - AssetManager::asset_type_units_per_second(MockAssetType::MockAsset(2)).unwrap(), - 200 - ); - - // Old one does not contain units per second - assert!(AssetManager::asset_type_units_per_second(MockAssetType::MockAsset(1)).is_none()); - - // New associations are stablished + // New associations are established assert_eq!( AssetManager::asset_id_type(1).unwrap(), MockAssetType::MockAsset(2) @@ -202,11 +138,7 @@ fn test_root_can_change_asset_id_type() { asset: MockAssetType::MockAsset(1), metadata: 0, }, - crate::Event::UnitsPerSecondChanged { - asset_type: MockAssetType::MockAsset(1), - units_per_second: 200, - }, - crate::Event::ForeignAssetTypeChanged { + crate::Event::ForeignAssetXcmLocationChanged { asset_id: 1, new_asset_type: MockAssetType::MockAsset(2), }, @@ -214,153 +146,9 @@ fn test_root_can_change_asset_id_type() { }); } -#[test] -fn test_change_units_per_second_after_setting_it_once() { - ExtBuilder::default().build().execute_with(|| { - assert_ok!(AssetManager::register_foreign_asset( - RuntimeOrigin::root(), - MockAssetType::MockAsset(1), - 0u32.into(), - 1u32.into(), - true, - )); - - assert_ok!(AssetManager::set_asset_units_per_second( - RuntimeOrigin::root(), - MockAssetType::MockAsset(1), - 200u128.into(), - 0 - )); - - assert_eq!( - AssetManager::asset_type_units_per_second(MockAssetType::MockAsset(1)).unwrap(), - 200 - ); - assert!(AssetManager::supported_fee_payment_assets().contains(&MockAssetType::MockAsset(1))); - - assert_ok!(AssetManager::set_asset_units_per_second( - RuntimeOrigin::root(), - MockAssetType::MockAsset(1), - 100u128.into(), - 1 - )); - - assert_eq!( - AssetManager::asset_type_units_per_second(MockAssetType::MockAsset(1)).unwrap(), - 100 - ); - assert!(AssetManager::supported_fee_payment_assets().contains(&MockAssetType::MockAsset(1))); - - expect_events(vec![ - crate::Event::ForeignAssetRegistered { - asset_id: 1, - asset: MockAssetType::MockAsset(1), - metadata: 0, - }, - crate::Event::UnitsPerSecondChanged { - asset_type: MockAssetType::MockAsset(1), - units_per_second: 200, - }, - crate::Event::UnitsPerSecondChanged { - asset_type: MockAssetType::MockAsset(1), - units_per_second: 100, - }, - ]); - }); -} - -#[test] -fn test_root_can_change_units_per_second_and_then_remove() { - ExtBuilder::default().build().execute_with(|| { - assert_ok!(AssetManager::register_foreign_asset( - RuntimeOrigin::root(), - MockAssetType::MockAsset(1), - 0u32.into(), - 1u32.into(), - true, - )); - - assert_ok!(AssetManager::set_asset_units_per_second( - RuntimeOrigin::root(), - MockAssetType::MockAsset(1), - 200u128.into(), - 0 - )); - - assert_eq!( - AssetManager::asset_type_units_per_second(MockAssetType::MockAsset(1)).unwrap(), - 200 - ); - assert!(AssetManager::supported_fee_payment_assets().contains(&MockAssetType::MockAsset(1))); - - assert_ok!(AssetManager::remove_supported_asset( - RuntimeOrigin::root(), - MockAssetType::MockAsset(1), - 1, - )); - - assert!( - !AssetManager::supported_fee_payment_assets().contains(&MockAssetType::MockAsset(1)) - ); - - expect_events(vec![ - crate::Event::ForeignAssetRegistered { - asset_id: 1, - asset: MockAssetType::MockAsset(1), - metadata: 0, - }, - crate::Event::UnitsPerSecondChanged { - asset_type: MockAssetType::MockAsset(1), - units_per_second: 200, - }, - crate::Event::SupportedAssetRemoved { - asset_type: MockAssetType::MockAsset(1), - }, - ]); - }); -} - -#[test] -fn test_weight_hint_error() { - ExtBuilder::default().build().execute_with(|| { - assert_ok!(AssetManager::register_foreign_asset( - RuntimeOrigin::root(), - MockAssetType::MockAsset(1), - 0u32.into(), - 1u32.into(), - true, - )); - - assert_ok!(AssetManager::set_asset_units_per_second( - RuntimeOrigin::root(), - MockAssetType::MockAsset(1), - 200u128.into(), - 0 - )); - - assert_noop!( - AssetManager::remove_supported_asset( - RuntimeOrigin::root(), - MockAssetType::MockAsset(1), - 0 - ), - Error::::TooLowNumAssetsWeightHint - ); - }); -} - #[test] fn test_asset_id_non_existent_error() { ExtBuilder::default().build().execute_with(|| { - assert_noop!( - AssetManager::set_asset_units_per_second( - RuntimeOrigin::root(), - MockAssetType::MockAsset(1), - 200u128.into(), - 0 - ), - Error::::AssetDoesNotExist - ); assert_noop!( AssetManager::change_existing_asset_type( RuntimeOrigin::root(), @@ -384,13 +172,6 @@ fn test_root_can_remove_asset_association() { true )); - assert_ok!(AssetManager::set_asset_units_per_second( - RuntimeOrigin::root(), - MockAssetType::MockAsset(1), - 200u128.into(), - 0 - )); - assert_ok!(AssetManager::remove_existing_asset_type( RuntimeOrigin::root(), 1, @@ -401,19 +182,12 @@ fn test_root_can_remove_asset_association() { assert!(AssetManager::asset_type_id(MockAssetType::MockAsset(1)).is_none()); assert!(AssetManager::asset_id_type(1).is_none()); - // Units per second removed - assert!(AssetManager::asset_type_units_per_second(MockAssetType::MockAsset(1)).is_none()); - expect_events(vec![ crate::Event::ForeignAssetRegistered { asset_id: 1, asset: MockAssetType::MockAsset(1), metadata: 0, }, - crate::Event::UnitsPerSecondChanged { - asset_type: MockAssetType::MockAsset(1), - units_per_second: 200, - }, crate::Event::ForeignAssetRemoved { asset_id: 1, asset_type: MockAssetType::MockAsset(1), @@ -443,9 +217,6 @@ fn test_removing_without_asset_units_per_second_does_not_panic() { assert!(AssetManager::asset_type_id(MockAssetType::MockAsset(1)).is_none()); assert!(AssetManager::asset_id_type(1).is_none()); - // Units per second removed - assert!(AssetManager::asset_type_units_per_second(MockAssetType::MockAsset(1)).is_none()); - expect_events(vec![ crate::Event::ForeignAssetRegistered { asset_id: 1, @@ -481,9 +252,6 @@ fn test_destroy_foreign_asset_also_removes_everything() { assert!(AssetManager::asset_type_id(MockAssetType::MockAsset(1)).is_none()); assert!(AssetManager::asset_id_type(1).is_none()); - // Units per second removed - assert!(AssetManager::asset_type_units_per_second(MockAssetType::MockAsset(1)).is_none()); - expect_events(vec![ crate::Event::ForeignAssetRegistered { asset_id: 1, diff --git a/pallets/asset-manager/src/weights.rs b/pallets/asset-manager/src/weights.rs index 6d4fb9e6f8..5bab822ae8 100644 --- a/pallets/asset-manager/src/weights.rs +++ b/pallets/asset-manager/src/weights.rs @@ -53,10 +53,8 @@ use sp_std::marker::PhantomData; /// Weight functions needed for pallet_asset_manager. pub trait WeightInfo { fn register_foreign_asset() -> Weight; - fn set_asset_units_per_second(x: u32, ) -> Weight; - fn change_existing_asset_type(x: u32, ) -> Weight; - fn remove_supported_asset(x: u32, ) -> Weight; - fn remove_existing_asset_type(x: u32, ) -> Weight; + fn change_existing_asset_type() -> Weight; + fn remove_existing_asset_type() -> Weight; } /// Weights for pallet_asset_manager using the Substrate node and recommended hardware. @@ -79,25 +77,6 @@ impl WeightInfo for SubstrateWeight { .saturating_add(T::DbWeight::get().reads(3_u64)) .saturating_add(T::DbWeight::get().writes(4_u64)) } - /// Storage: AssetManager AssetTypeId (r:1 w:0) - /// Proof Skipped: AssetManager AssetTypeId (max_values: None, max_size: None, mode: Measured) - /// Storage: AssetManager SupportedFeePaymentAssets (r:1 w:1) - /// Proof Skipped: AssetManager SupportedFeePaymentAssets (max_values: Some(1), max_size: None, mode: Measured) - /// Storage: AssetManager AssetTypeUnitsPerSecond (r:0 w:1) - /// Proof Skipped: AssetManager AssetTypeUnitsPerSecond (max_values: None, max_size: None, mode: Measured) - /// The range of component `x` is `[5, 100]`. - fn set_asset_units_per_second(x: u32, ) -> Weight { - // Proof Size summary in bytes: - // Measured: `611 + x * (9 ±0)` - // Estimated: `6555 + x * (30 ±0)` - // Minimum execution time: 30_927_000 picoseconds. - Weight::from_parts(30_990_835, 6555) - // Standard Error: 2_254 - .saturating_add(Weight::from_parts(494_375, 0).saturating_mul(x.into())) - .saturating_add(T::DbWeight::get().reads(2_u64)) - .saturating_add(T::DbWeight::get().writes(2_u64)) - .saturating_add(Weight::from_parts(0, 30).saturating_mul(x.into())) - } /// Storage: AssetManager SupportedFeePaymentAssets (r:1 w:1) /// Proof Skipped: AssetManager SupportedFeePaymentAssets (max_values: Some(1), max_size: None, mode: Measured) /// Storage: AssetManager AssetIdType (r:1 w:1) @@ -107,34 +86,17 @@ impl WeightInfo for SubstrateWeight { /// Storage: AssetManager AssetTypeId (r:0 w:2) /// Proof Skipped: AssetManager AssetTypeId (max_values: None, max_size: None, mode: Measured) /// The range of component `x` is `[5, 100]`. - fn change_existing_asset_type(x: u32, ) -> Weight { + fn change_existing_asset_type() -> Weight { // Proof Size summary in bytes: // Measured: `926 + x * (13 ±0)` // Estimated: `11791 + x * (60 ±0)` // Minimum execution time: 42_959_000 picoseconds. Weight::from_parts(43_255_055, 11791) // Standard Error: 3_394 - .saturating_add(Weight::from_parts(543_897, 0).saturating_mul(x.into())) + .saturating_add(Weight::from_parts(543_897, 0)) .saturating_add(T::DbWeight::get().reads(3_u64)) .saturating_add(T::DbWeight::get().writes(6_u64)) - .saturating_add(Weight::from_parts(0, 60).saturating_mul(x.into())) - } - /// Storage: AssetManager SupportedFeePaymentAssets (r:1 w:1) - /// Proof Skipped: AssetManager SupportedFeePaymentAssets (max_values: Some(1), max_size: None, mode: Measured) - /// Storage: AssetManager AssetTypeUnitsPerSecond (r:0 w:1) - /// Proof Skipped: AssetManager AssetTypeUnitsPerSecond (max_values: None, max_size: None, mode: Measured) - /// The range of component `x` is `[5, 100]`. - fn remove_supported_asset(x: u32, ) -> Weight { - // Proof Size summary in bytes: - // Measured: `196 + x * (5 ±0)` - // Estimated: `1871 + x * (10 ±0)` - // Minimum execution time: 25_453_000 picoseconds. - Weight::from_parts(24_977_319, 1871) - // Standard Error: 2_109 - .saturating_add(Weight::from_parts(407_717, 0).saturating_mul(x.into())) - .saturating_add(T::DbWeight::get().reads(1_u64)) - .saturating_add(T::DbWeight::get().writes(2_u64)) - .saturating_add(Weight::from_parts(0, 10).saturating_mul(x.into())) + .saturating_add(Weight::from_parts(0, 60)) } /// Storage: AssetManager SupportedFeePaymentAssets (r:1 w:1) /// Proof Skipped: AssetManager SupportedFeePaymentAssets (max_values: Some(1), max_size: None, mode: Measured) @@ -145,17 +107,17 @@ impl WeightInfo for SubstrateWeight { /// Storage: AssetManager AssetTypeId (r:0 w:1) /// Proof Skipped: AssetManager AssetTypeId (max_values: None, max_size: None, mode: Measured) /// The range of component `x` is `[5, 100]`. - fn remove_existing_asset_type(x: u32, ) -> Weight { + fn remove_existing_asset_type() -> Weight { // Proof Size summary in bytes: // Measured: `482 + x * (10 ±0)` // Estimated: `6910 + x * (40 ±0)` // Minimum execution time: 32_960_000 picoseconds. Weight::from_parts(33_257_599, 6910) // Standard Error: 2_430 - .saturating_add(Weight::from_parts(421_651, 0).saturating_mul(x.into())) + .saturating_add(Weight::from_parts(421_651, 0)) .saturating_add(T::DbWeight::get().reads(2_u64)) .saturating_add(T::DbWeight::get().writes(4_u64)) - .saturating_add(Weight::from_parts(0, 40).saturating_mul(x.into())) + .saturating_add(Weight::from_parts(0, 40)) } } @@ -178,25 +140,6 @@ impl WeightInfo for () { .saturating_add(RocksDbWeight::get().reads(3_u64)) .saturating_add(RocksDbWeight::get().writes(4_u64)) } - /// Storage: AssetManager AssetTypeId (r:1 w:0) - /// Proof Skipped: AssetManager AssetTypeId (max_values: None, max_size: None, mode: Measured) - /// Storage: AssetManager SupportedFeePaymentAssets (r:1 w:1) - /// Proof Skipped: AssetManager SupportedFeePaymentAssets (max_values: Some(1), max_size: None, mode: Measured) - /// Storage: AssetManager AssetTypeUnitsPerSecond (r:0 w:1) - /// Proof Skipped: AssetManager AssetTypeUnitsPerSecond (max_values: None, max_size: None, mode: Measured) - /// The range of component `x` is `[5, 100]`. - fn set_asset_units_per_second(x: u32, ) -> Weight { - // Proof Size summary in bytes: - // Measured: `611 + x * (9 ±0)` - // Estimated: `6555 + x * (30 ±0)` - // Minimum execution time: 30_927_000 picoseconds. - Weight::from_parts(30_990_835, 6555) - // Standard Error: 2_254 - .saturating_add(Weight::from_parts(494_375, 0).saturating_mul(x.into())) - .saturating_add(RocksDbWeight::get().reads(2_u64)) - .saturating_add(RocksDbWeight::get().writes(2_u64)) - .saturating_add(Weight::from_parts(0, 30).saturating_mul(x.into())) - } /// Storage: AssetManager SupportedFeePaymentAssets (r:1 w:1) /// Proof Skipped: AssetManager SupportedFeePaymentAssets (max_values: Some(1), max_size: None, mode: Measured) /// Storage: AssetManager AssetIdType (r:1 w:1) @@ -206,34 +149,17 @@ impl WeightInfo for () { /// Storage: AssetManager AssetTypeId (r:0 w:2) /// Proof Skipped: AssetManager AssetTypeId (max_values: None, max_size: None, mode: Measured) /// The range of component `x` is `[5, 100]`. - fn change_existing_asset_type(x: u32, ) -> Weight { + fn change_existing_asset_type() -> Weight { // Proof Size summary in bytes: // Measured: `926 + x * (13 ±0)` // Estimated: `11791 + x * (60 ±0)` // Minimum execution time: 42_959_000 picoseconds. Weight::from_parts(43_255_055, 11791) // Standard Error: 3_394 - .saturating_add(Weight::from_parts(543_897, 0).saturating_mul(x.into())) + .saturating_add(Weight::from_parts(543_897, 0)) .saturating_add(RocksDbWeight::get().reads(3_u64)) .saturating_add(RocksDbWeight::get().writes(6_u64)) - .saturating_add(Weight::from_parts(0, 60).saturating_mul(x.into())) - } - /// Storage: AssetManager SupportedFeePaymentAssets (r:1 w:1) - /// Proof Skipped: AssetManager SupportedFeePaymentAssets (max_values: Some(1), max_size: None, mode: Measured) - /// Storage: AssetManager AssetTypeUnitsPerSecond (r:0 w:1) - /// Proof Skipped: AssetManager AssetTypeUnitsPerSecond (max_values: None, max_size: None, mode: Measured) - /// The range of component `x` is `[5, 100]`. - fn remove_supported_asset(x: u32, ) -> Weight { - // Proof Size summary in bytes: - // Measured: `196 + x * (5 ±0)` - // Estimated: `1871 + x * (10 ±0)` - // Minimum execution time: 25_453_000 picoseconds. - Weight::from_parts(24_977_319, 1871) - // Standard Error: 2_109 - .saturating_add(Weight::from_parts(407_717, 0).saturating_mul(x.into())) - .saturating_add(RocksDbWeight::get().reads(1_u64)) - .saturating_add(RocksDbWeight::get().writes(2_u64)) - .saturating_add(Weight::from_parts(0, 10).saturating_mul(x.into())) + .saturating_add(Weight::from_parts(0, 60)) } /// Storage: AssetManager SupportedFeePaymentAssets (r:1 w:1) /// Proof Skipped: AssetManager SupportedFeePaymentAssets (max_values: Some(1), max_size: None, mode: Measured) @@ -244,16 +170,16 @@ impl WeightInfo for () { /// Storage: AssetManager AssetTypeId (r:0 w:1) /// Proof Skipped: AssetManager AssetTypeId (max_values: None, max_size: None, mode: Measured) /// The range of component `x` is `[5, 100]`. - fn remove_existing_asset_type(x: u32, ) -> Weight { + fn remove_existing_asset_type() -> Weight { // Proof Size summary in bytes: // Measured: `482 + x * (10 ±0)` // Estimated: `6910 + x * (40 ±0)` // Minimum execution time: 32_960_000 picoseconds. Weight::from_parts(33_257_599, 6910) // Standard Error: 2_430 - .saturating_add(Weight::from_parts(421_651, 0).saturating_mul(x.into())) + .saturating_add(Weight::from_parts(421_651, 0)) .saturating_add(RocksDbWeight::get().reads(2_u64)) .saturating_add(RocksDbWeight::get().writes(4_u64)) - .saturating_add(Weight::from_parts(0, 40).saturating_mul(x.into())) + .saturating_add(Weight::from_parts(0, 40)) } } \ No newline at end of file