git.delta.rocks / unique-network / refs/commits / 21b23e7b1db8

difftreelog

feat benchmark rmrk proxy equip

Daniel Shiposha2022-06-16parent: #c214759.patch.diff
in: master

9 files changed

modifiedMakefilediffbeforeafterboth
101bench-rmrk-core:101bench-rmrk-core:
102 make _bench PALLET=proxy-rmrk-core102 make _bench PALLET=proxy-rmrk-core
103
104.PHONY: bench-rmrk-equip
105bench-rmrk-equip:
106 make _bench PALLET=proxy-rmrk-equip
103107
104.PHONY: bench108.PHONY: bench
105bench: bench-evm-migration bench-unique bench-structure bench-fungible bench-refungible bench-nonfungible bench-scheduler bench-rmrk-core109bench: bench-evm-migration bench-unique bench-structure bench-fungible bench-refungible bench-nonfungible bench-scheduler bench-rmrk-core bench-rmrk-equip
106110
addedpallets/proxy-rmrk-equip/src/benchmarking.rsdiffbeforeafterboth
--- /dev/null
+++ b/pallets/proxy-rmrk-equip/src/benchmarking.rs
@@ -0,0 +1,91 @@
+use sp_std::vec;
+
+use frame_benchmarking::{benchmarks, account};
+use frame_system::RawOrigin;
+use frame_support::{
+	traits::{Currency, Get},
+	BoundedVec,
+};
+
+use up_data_structs::*;
+
+use super::*;
+
+const SEED: u32 = 1;
+
+fn create_data<S: Get<u32>>() -> BoundedVec<u8, S> {
+	vec![b'A'; S::get() as usize].try_into().expect("size == S")
+}
+
+fn create_u32_array<S: Get<u32>>() -> BoundedVec<u32, S> {
+	vec![0; S::get() as usize].try_into().expect("size == S")
+}
+
+fn create_max_part() -> RmrkPartType {
+    RmrkPartType::SlotPart(
+        RmrkSlotPart {
+            id: 42,
+            equippable: RmrkEquippableList::Custom(create_u32_array()),
+            src: create_data(),
+            z: 1,
+        }
+    )
+}
+
+fn create_parts_array<S: Get<u32>>(num: u32) -> BoundedVec<RmrkPartType, S> {
+	vec![create_max_part(); num as usize].try_into().expect("num <= S")
+}
+
+fn create_max_theme_property() -> RmrkThemeProperty {
+    RmrkThemeProperty {
+        key: create_data(),
+        value: create_data(),
+    }   
+}
+
+fn create_theme_properties_array<S: Get<u32>>(num: u32) -> BoundedVec<RmrkThemeProperty, S> {
+	vec![create_max_theme_property(); num as usize].try_into().expect("num <= S")
+}
+
+fn create_max_theme(name: RmrkString, props_num: u32) -> RmrkBoundedTheme {
+    RmrkBoundedTheme {
+        name,
+        properties: create_theme_properties_array(props_num),
+        inherit: false,
+    }
+}
+
+benchmarks! {
+    create_base {
+        let b in 0..RmrkPartsLimit::get();
+
+        let caller = account("caller", 0, SEED);
+		<T as pallet_common::Config>::Currency::deposit_creating(&caller, T::CollectionCreationPrice::get());
+
+        let base_type = create_data();
+        let symbol = create_data();
+        let parts = create_parts_array(b);
+    }: _(RawOrigin::Signed(caller), base_type, symbol, parts)
+
+    theme_add {
+        let b in 0..MaxPropertiesPerTheme::get();
+
+        let caller = account("caller", 0, SEED);
+		<T as pallet_common::Config>::Currency::deposit_creating(&caller, T::CollectionCreationPrice::get());
+
+        let base_type = create_data();
+        let symbol = create_data();
+        let parts = create_parts_array(0);
+
+        <Pallet<T>>::create_base(RawOrigin::Signed(caller.clone()).into(), base_type, symbol, parts)?;
+        let base_id = 1;
+
+        
+        let default_theme_name = b"default".to_vec().try_into().expect("default is a valid name; qed");
+        let default_theme = create_max_theme(default_theme_name, 0);
+
+        <Pallet<T>>::theme_add(RawOrigin::Signed(caller.clone()).into(), base_id, default_theme)?;
+
+        let theme = create_max_theme(create_data(), b);
+    }: _(RawOrigin::Signed(caller), base_id, theme)
+}
modifiedpallets/proxy-rmrk-equip/src/lib.rsdiffbeforeafterboth
--- a/pallets/proxy-rmrk-equip/src/lib.rs
+++ b/pallets/proxy-rmrk-equip/src/lib.rs
@@ -28,9 +28,16 @@
 };
 use pallet_nonfungible::{Pallet as PalletNft, NonfungibleHandle};
 use pallet_evm::account::CrossAccountId;
+use weights::WeightInfo;
 
 pub use pallet::*;
 
+#[cfg(feature = "runtime-benchmarks")]
+pub mod benchmarking;
+pub mod weights;
+
+pub type SelfWeightOf<T> = <T as Config>::WeightInfo;
+
 #[frame_support::pallet]
 pub mod pallet {
 	use super::*;
@@ -38,6 +45,7 @@
 	#[pallet::config]
 	pub trait Config: frame_system::Config + pallet_rmrk_core::Config {
 		type Event: From<Event<Self>> + IsType<<Self as frame_system::Config>::Event>;
+		type WeightInfo: WeightInfo;
 	}
 
 	#[pallet::storage]
@@ -83,12 +91,12 @@
 		/// - symbol: arbitrary client-chosen symbol
 		/// - parts: array of Fixed and Slot parts composing the base, confined in length by
 		///   RmrkPartsLimit
-		#[pallet::weight(10_000 + T::DbWeight::get().reads_writes(1,1))]
 		#[transactional]
+		#[pallet::weight(<SelfWeightOf<T>>::create_base(parts.len() as u32))]
 		pub fn create_base(
 			origin: OriginFor<T>,
 			base_type: RmrkString,
-			symbol: RmrkString,
+			symbol: RmrkBaseSymbol,
 			parts: BoundedVec<RmrkPartType, RmrkPartsLimit>,
 		) -> DispatchResult {
 			let sender = ensure_signed(origin)?;
@@ -159,12 +167,12 @@
 		///   - key: arbitrary BoundedString, defined by client
 		///   - value: arbitrary BoundedString, defined by client
 		///   - inherit: optional bool
-		#[pallet::weight(10_000 + T::DbWeight::get().reads_writes(1,1))]
 		#[transactional]
+		#[pallet::weight(<SelfWeightOf<T>>::theme_add(theme.properties.len() as u32))]
 		pub fn theme_add(
 			origin: OriginFor<T>,
 			base_id: RmrkBaseId,
-			theme: RmrkTheme,
+			theme: RmrkBoundedTheme,
 		) -> DispatchResult {
 			let sender = ensure_signed(origin)?;
 
addedpallets/proxy-rmrk-equip/src/weights.rsdiffbeforeafterboth
--- /dev/null
+++ b/pallets/proxy-rmrk-equip/src/weights.rs
@@ -0,0 +1,119 @@
+// Template adopted from https://github.com/paritytech/substrate/blob/master/.maintain/frame-weight-template.hbs
+
+//! Autogenerated weights for pallet_proxy_rmrk_equip
+//!
+//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev
+//! DATE: 2022-06-16, STEPS: `50`, REPEAT: 80, LOW RANGE: `[]`, HIGH RANGE: `[]`
+//! EXECUTION: None, WASM-EXECUTION: Compiled, CHAIN: None, DB CACHE: 1024
+
+// Executed Command:
+// target/release/unique-collator
+// benchmark
+// pallet
+// --pallet
+// pallet-proxy-rmrk-equip
+// --wasm-execution
+// compiled
+// --extrinsic
+// *
+// --template
+// .maintain/frame-weight-template.hbs
+// --steps=50
+// --repeat=80
+// --heap-pages=4096
+// --output=./pallets/proxy-rmrk-equip/src/weights.rs
+
+#![cfg_attr(rustfmt, rustfmt_skip)]
+#![allow(unused_parens)]
+#![allow(unused_imports)]
+#![allow(clippy::unnecessary_cast)]
+
+use frame_support::{traits::Get, weights::{Weight, constants::RocksDbWeight}};
+use sp_std::marker::PhantomData;
+
+/// Weight functions needed for pallet_proxy_rmrk_equip.
+pub trait WeightInfo {
+	fn create_base(b: u32, ) -> Weight;
+	fn theme_add(b: u32, ) -> Weight;
+}
+
+/// Weights for pallet_proxy_rmrk_equip using the Substrate node and recommended hardware.
+pub struct SubstrateWeight<T>(PhantomData<T>);
+impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> {
+	// Storage: Common CreatedCollectionCount (r:1 w:1)
+	// Storage: Common DestroyedCollectionCount (r:1 w:0)
+	// Storage: System Account (r:2 w:2)
+	// Storage: Common CollectionPropertyPermissions (r:0 w:1)
+	// Storage: Common CollectionProperties (r:0 w:1)
+	// Storage: Common CollectionById (r:0 w:1)
+	// Storage: Nonfungible TokensMinted (r:1 w:1)
+	// Storage: Nonfungible AccountBalance (r:1 w:1)
+	// Storage: Nonfungible TokenProperties (r:1 w:1)
+	// Storage: Nonfungible TokenData (r:0 w:1)
+	// Storage: Nonfungible Owned (r:0 w:1)
+	// Storage: RmrkEquip InernalPartId (r:0 w:1)
+	fn create_base(b: u32, ) -> Weight {
+		(43_216_000 as Weight)
+			// Standard Error: 10_000
+			.saturating_add((16_253_000 as Weight).saturating_mul(b as Weight))
+			.saturating_add(T::DbWeight::get().reads(6 as Weight))
+			.saturating_add(T::DbWeight::get().reads((1 as Weight).saturating_mul(b as Weight)))
+			.saturating_add(T::DbWeight::get().writes(9 as Weight))
+			.saturating_add(T::DbWeight::get().writes((3 as Weight).saturating_mul(b as Weight)))
+	}
+	// Storage: Common CollectionProperties (r:1 w:0)
+	// Storage: Common CollectionById (r:1 w:0)
+	// Storage: RmrkEquip BaseHasDefaultTheme (r:1 w:0)
+	// Storage: Nonfungible TokensMinted (r:1 w:1)
+	// Storage: Nonfungible AccountBalance (r:1 w:1)
+	// Storage: Nonfungible TokenProperties (r:1 w:1)
+	// Storage: Nonfungible TokenData (r:0 w:1)
+	// Storage: Nonfungible Owned (r:0 w:1)
+	fn theme_add(b: u32, ) -> Weight {
+		(39_467_000 as Weight)
+			// Standard Error: 15_000
+			.saturating_add((2_332_000 as Weight).saturating_mul(b as Weight))
+			.saturating_add(T::DbWeight::get().reads(6 as Weight))
+			.saturating_add(T::DbWeight::get().writes(5 as Weight))
+	}
+}
+
+// For backwards compatibility and tests
+impl WeightInfo for () {
+	// Storage: Common CreatedCollectionCount (r:1 w:1)
+	// Storage: Common DestroyedCollectionCount (r:1 w:0)
+	// Storage: System Account (r:2 w:2)
+	// Storage: Common CollectionPropertyPermissions (r:0 w:1)
+	// Storage: Common CollectionProperties (r:0 w:1)
+	// Storage: Common CollectionById (r:0 w:1)
+	// Storage: Nonfungible TokensMinted (r:1 w:1)
+	// Storage: Nonfungible AccountBalance (r:1 w:1)
+	// Storage: Nonfungible TokenProperties (r:1 w:1)
+	// Storage: Nonfungible TokenData (r:0 w:1)
+	// Storage: Nonfungible Owned (r:0 w:1)
+	// Storage: RmrkEquip InernalPartId (r:0 w:1)
+	fn create_base(b: u32, ) -> Weight {
+		(43_216_000 as Weight)
+			// Standard Error: 10_000
+			.saturating_add((16_253_000 as Weight).saturating_mul(b as Weight))
+			.saturating_add(RocksDbWeight::get().reads(6 as Weight))
+			.saturating_add(RocksDbWeight::get().reads((1 as Weight).saturating_mul(b as Weight)))
+			.saturating_add(RocksDbWeight::get().writes(9 as Weight))
+			.saturating_add(RocksDbWeight::get().writes((3 as Weight).saturating_mul(b as Weight)))
+	}
+	// Storage: Common CollectionProperties (r:1 w:0)
+	// Storage: Common CollectionById (r:1 w:0)
+	// Storage: RmrkEquip BaseHasDefaultTheme (r:1 w:0)
+	// Storage: Nonfungible TokensMinted (r:1 w:1)
+	// Storage: Nonfungible AccountBalance (r:1 w:1)
+	// Storage: Nonfungible TokenProperties (r:1 w:1)
+	// Storage: Nonfungible TokenData (r:0 w:1)
+	// Storage: Nonfungible Owned (r:0 w:1)
+	fn theme_add(b: u32, ) -> Weight {
+		(39_467_000 as Weight)
+			// Standard Error: 15_000
+			.saturating_add((2_332_000 as Weight).saturating_mul(b as Weight))
+			.saturating_add(RocksDbWeight::get().reads(6 as Weight))
+			.saturating_add(RocksDbWeight::get().writes(5 as Weight))
+	}
+}
modifiedprimitives/data-structs/src/lib.rsdiffbeforeafterboth
--- a/primitives/data-structs/src/lib.rs
+++ b/primitives/data-structs/src/lib.rs
@@ -950,7 +950,9 @@
 	#[derive(PartialEq)]
 	pub const RmrkCollectionSymbolLimit: u32 = MAX_TOKEN_PREFIX_LENGTH;
 	#[derive(PartialEq)]
-	pub const RmrkResourceSymbolLimit: u32 = MAX_TOKEN_PREFIX_LENGTH;
+	pub const RmrkResourceSymbolLimit: u32 = 10;
+	#[derive(PartialEq)]
+	pub const RmrkBaseSymbolLimit: u32 = MAX_TOKEN_PREFIX_LENGTH;
 	#[derive(PartialEq)]
 	pub const RmrkKeyLimit: u32 = 32;
 	#[derive(PartialEq)]
@@ -958,6 +960,8 @@
 	#[derive(PartialEq)]
 	pub const RmrkMaxCollectionsEquippablePerPart: u32 = 100;
 	#[derive(PartialEq)]
+	pub const MaxPropertiesPerTheme: u32 = 5;
+	#[derive(PartialEq)]
 	pub const RmrkPartsLimit: u32 = 25;
 	#[derive(PartialEq)]
 	pub const RmrkMaxPriorities: u32 = 25;
@@ -987,6 +991,7 @@
 	PartType<RmrkString, BoundedVec<RmrkCollectionId, RmrkMaxCollectionsEquippablePerPart>>;
 pub type RmrkThemeProperty = ThemeProperty<RmrkString>;
 pub type RmrkTheme = Theme<RmrkString, Vec<RmrkThemeProperty>>;
+pub type RmrkBoundedTheme = Theme<RmrkString, BoundedVec<RmrkThemeProperty, MaxPropertiesPerTheme>>;
 pub type RmrkResourceTypes = ResourceTypes<RmrkString, RmrkBoundedParts>;
 
 pub type RmrkBasicResource = BasicResource<RmrkString>;
@@ -995,6 +1000,7 @@
 
 pub type RmrkString = BoundedVec<u8, RmrkStringLimit>;
 pub type RmrkCollectionSymbol = BoundedVec<u8, RmrkCollectionSymbolLimit>;
+pub type RmrkBaseSymbol = BoundedVec<u8, RmrkBaseSymbolLimit>;
 pub type RmrkKeyString = BoundedVec<u8, RmrkKeyLimit>;
 pub type RmrkValueString = BoundedVec<u8, RmrkValueLimit>;
 pub type RmrkBoundedResource = BoundedVec<u8, RmrkResourceSymbolLimit>;
modifiedruntime/common/src/runtime_apis.rsdiffbeforeafterboth
--- a/runtime/common/src/runtime_apis.rs
+++ b/runtime/common/src/runtime_apis.rs
@@ -458,6 +458,9 @@
                     #[cfg(not(feature = "unique-runtime"))]
                     list_benchmark!(list, extra, pallet_proxy_rmrk_core, RmrkCore);
 
+                    #[cfg(not(feature = "unique-runtime"))]
+                    list_benchmark!(list, extra, pallet_proxy_rmrk_equip, RmrkEquip);
+
                     // list_benchmark!(list, extra, pallet_evm_coder_substrate, EvmCoderSubstrate);
 
                     let storage_info = AllPalletsReversedWithSystemFirst::storage_info();
@@ -506,6 +509,9 @@
                     #[cfg(not(feature = "unique-runtime"))]
                     add_benchmark!(params, batches, pallet_proxy_rmrk_core, RmrkCore);
 
+                    #[cfg(not(feature = "unique-runtime"))]
+                    add_benchmark!(params, batches, pallet_proxy_rmrk_equip, RmrkEquip);
+
                     // add_benchmark!(params, batches, pallet_evm_coder_substrate, EvmCoderSubstrate);
 
                     if batches.is_empty() { return Err("Benchmark not found for this pallet.".into()) }
modifiedruntime/opal/Cargo.tomldiffbeforeafterboth
--- a/runtime/opal/Cargo.toml
+++ b/runtime/opal/Cargo.toml
@@ -34,6 +34,7 @@
     'pallet-refungible/runtime-benchmarks',
     'pallet-nonfungible/runtime-benchmarks',
     'pallet-proxy-rmrk-core/runtime-benchmarks',
+    'pallet-proxy-rmrk-equip/runtime-benchmarks',
     'pallet-unique/runtime-benchmarks',
     'pallet-inflation/runtime-benchmarks',
     'pallet-unique-scheduler/runtime-benchmarks',
modifiedruntime/opal/src/lib.rsdiffbeforeafterboth
--- a/runtime/opal/src/lib.rs
+++ b/runtime/opal/src/lib.rs
@@ -923,6 +923,7 @@
 }
 
 impl pallet_proxy_rmrk_equip::Config for Runtime {
+	type WeightInfo = pallet_proxy_rmrk_equip::weights::SubstrateWeight<Self>;
 	type Event = Event;
 }
 
modifiedruntime/quartz/src/lib.rsdiffbeforeafterboth
--- a/runtime/quartz/src/lib.rs
+++ b/runtime/quartz/src/lib.rs
@@ -922,6 +922,7 @@
 }
 
 impl pallet_proxy_rmrk_equip::Config for Runtime {
+	type WeightInfo = pallet_proxy_rmrk_equip::weights::SubstrateWeight<Self>;
 	type Event = Event;
 }