--- a/Makefile +++ b/Makefile @@ -101,5 +101,9 @@ bench-rmrk-core: make _bench PALLET=proxy-rmrk-core +.PHONY: bench-rmrk-equip +bench-rmrk-equip: + make _bench PALLET=proxy-rmrk-equip + .PHONY: bench -bench: bench-evm-migration bench-unique bench-structure bench-fungible bench-refungible bench-nonfungible bench-scheduler bench-rmrk-core +bench: bench-evm-migration bench-unique bench-structure bench-fungible bench-refungible bench-nonfungible bench-scheduler bench-rmrk-core bench-rmrk-equip --- /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>() -> BoundedVec { + vec![b'A'; S::get() as usize].try_into().expect("size == S") +} + +fn create_u32_array>() -> BoundedVec { + 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>(num: u32) -> BoundedVec { + 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>(num: u32) -> BoundedVec { + 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); + ::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); + ::Currency::deposit_creating(&caller, T::CollectionCreationPrice::get()); + + let base_type = create_data(); + let symbol = create_data(); + let parts = create_parts_array(0); + + >::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); + + >::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) +} --- 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 = ::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> + IsType<::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(>::create_base(parts.len() as u32))] pub fn create_base( origin: OriginFor, base_type: RmrkString, - symbol: RmrkString, + symbol: RmrkBaseSymbol, parts: BoundedVec, ) -> 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(>::theme_add(theme.properties.len() as u32))] pub fn theme_add( origin: OriginFor, base_id: RmrkBaseId, - theme: RmrkTheme, + theme: RmrkBoundedTheme, ) -> DispatchResult { let sender = ensure_signed(origin)?; --- /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(PhantomData); +impl WeightInfo for SubstrateWeight { + // 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)) + } +} --- 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>; pub type RmrkThemeProperty = ThemeProperty; pub type RmrkTheme = Theme>; +pub type RmrkBoundedTheme = Theme>; pub type RmrkResourceTypes = ResourceTypes; pub type RmrkBasicResource = BasicResource; @@ -995,6 +1000,7 @@ pub type RmrkString = BoundedVec; pub type RmrkCollectionSymbol = BoundedVec; +pub type RmrkBaseSymbol = BoundedVec; pub type RmrkKeyString = BoundedVec; pub type RmrkValueString = BoundedVec; pub type RmrkBoundedResource = BoundedVec; --- 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()) } --- 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', --- 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; type Event = Event; } --- 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; type Event = Event; }