--- a/Makefile +++ b/Makefile @@ -57,5 +57,9 @@ bench-nonfungible: make _bench PALLET=nonfungible +.PHONY: bench-structure +bench-structure: + make _bench PALLET=structure + .PHONY: bench -bench: bench-evm-migration bench-unique bench-fungible bench-refungible bench-nonfungible +bench: bench-evm-migration bench-unique bench-structure bench-fungible bench-refungible bench-nonfungible --- a/pallets/structure/Cargo.toml +++ b/pallets/structure/Cargo.toml @@ -6,6 +6,7 @@ [dependencies] frame-support = { default-features = false, git = 'https://github.com/paritytech/substrate.git', branch = 'polkadot-v0.9.17' } frame-system = { default-features = false, git = 'https://github.com/paritytech/substrate.git', branch = 'polkadot-v0.9.17' } +frame-benchmarking = { default-features = false, optional = true, git = 'https://github.com/paritytech/substrate.git', branch = 'polkadot-v0.9.17' } sp-std = { default-features = false, git = 'https://github.com/paritytech/substrate.git', branch = 'polkadot-v0.9.17' } pallet-common = { path = "../common", default-features = false } parity-scale-codec = { version = "2.0.0", default-features = false, features = [ @@ -21,9 +22,11 @@ std = [ "frame-support/std", "frame-system/std", + "frame-benchmarking/std", "sp-std/std", "pallet-common/std", "scale-info/std", "parity-scale-codec/std", "up-data-structs/std", ] +runtime-benchmarks = ['frame-benchmarking', 'pallet-common/runtime-benchmarks'] --- /dev/null +++ b/pallets/structure/src/benchmarking.rs @@ -0,0 +1,28 @@ +use super::*; + +use frame_benchmarking::{benchmarks, account}; +use frame_support::traits::{Currency, Get}; +use up_data_structs::{CreateCollectionData, CollectionMode, CreateItemData, CreateNftData}; +use pallet_common::CrossAccountId; + +const SEED: u32 = 1; + +benchmarks! { + find_parent { + let caller: T::AccountId = account("caller", 0, SEED); + let caller_cross = T::CrossAccountId::from_sub(caller.clone()); + + T::Currency::deposit_creating(&caller, T::CollectionCreationPrice::get()); + T::CollectionDispatch::create(caller, CreateCollectionData { + mode: CollectionMode::NFT, + ..Default::default() + })?; + let dispatch = T::CollectionDispatch::dispatch(CollectionHandle::try_get(CollectionId(1))?); + let dispatch = dispatch.as_dyn(); + + dispatch.create_item(caller_cross.clone(), caller_cross.clone(), CreateItemData::NFT(CreateNftData::default()))?; + }: { + let parent = >::find_parent(CollectionId(1), TokenId(1))?; + assert!(matches!(parent, Parent::Normal(_))) + } +} --- /dev/null +++ b/pallets/structure/src/weights.rs @@ -0,0 +1,57 @@ +// Template adopted from https://github.com/paritytech/substrate/blob/master/.maintain/frame-weight-template.hbs + +//! Autogenerated weights for pallet_structure +//! +//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev +//! DATE: 2022-03-24, STEPS: `50`, REPEAT: 200, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! EXECUTION: None, WASM-EXECUTION: Compiled, CHAIN: None, DB CACHE: 1024 + +// Executed Command: +// target/release/unique-collator +// benchmark +// --pallet +// pallet-structure +// --wasm-execution +// compiled +// --extrinsic +// * +// --template +// .maintain/frame-weight-template.hbs +// --steps=50 +// --repeat=200 +// --heap-pages=4096 +// --output=./pallets/structure/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_structure. +pub trait WeightInfo { + fn find_parent() -> Weight; +} + +/// Weights for pallet_structure using the Substrate node and recommended hardware. +pub struct SubstrateWeight(PhantomData); +impl WeightInfo for SubstrateWeight { + // Storage: Common CollectionById (r:1 w:0) + // Storage: Nonfungible TokenData (r:1 w:0) + fn find_parent() -> Weight { + (6_302_000 as Weight) + .saturating_add(T::DbWeight::get().reads(2 as Weight)) + } +} + +// For backwards compatibility and tests +impl WeightInfo for () { + // Storage: Common CollectionById (r:1 w:0) + // Storage: Nonfungible TokenData (r:1 w:0) + fn find_parent() -> Weight { + (6_302_000 as Weight) + .saturating_add(RocksDbWeight::get().reads(2 as Weight)) + } +} --- a/runtime/common/src/runtime_apis.rs +++ b/runtime/common/src/runtime_apis.rs @@ -378,6 +378,7 @@ list_benchmark!(list, extra, pallet_evm_migration, EvmMigration); list_benchmark!(list, extra, pallet_unique, Unique); + list_benchmark!(list, extra, pallet_structure, Structure); list_benchmark!(list, extra, pallet_inflation, Inflation); list_benchmark!(list, extra, pallet_fungible, Fungible); list_benchmark!(list, extra, pallet_refungible, Refungible); @@ -415,6 +416,7 @@ add_benchmark!(params, batches, pallet_evm_migration, EvmMigration); add_benchmark!(params, batches, pallet_unique, Unique); + add_benchmark!(params, batches, pallet_structure, Structure); add_benchmark!(params, batches, pallet_inflation, Inflation); add_benchmark!(params, batches, pallet_fungible, Fungible); add_benchmark!(params, batches, pallet_refungible, Refungible); --- a/runtime/opal/Cargo.toml +++ b/runtime/opal/Cargo.toml @@ -29,6 +29,7 @@ 'pallet-balances/runtime-benchmarks', 'pallet-timestamp/runtime-benchmarks', 'pallet-common/runtime-benchmarks', + 'pallet-structure/runtime-benchmarks', 'pallet-fungible/runtime-benchmarks', 'pallet-refungible/runtime-benchmarks', 'pallet-nonfungible/runtime-benchmarks', @@ -84,6 +85,7 @@ 'serde', 'pallet-inflation/std', 'pallet-common/std', + 'pallet-structure/std', 'pallet-fungible/std', 'pallet-refungible/std', 'pallet-nonfungible/std', --- a/runtime/opal/src/lib.rs +++ b/runtime/opal/src/lib.rs @@ -886,6 +886,7 @@ impl pallet_structure::Config for Runtime { type Event = Event; type Call = Call; + type WeightInfo = pallet_structure::weights::SubstrateWeight; } impl pallet_fungible::Config for Runtime { --- a/runtime/quartz/Cargo.toml +++ b/runtime/quartz/Cargo.toml @@ -29,6 +29,7 @@ 'pallet-balances/runtime-benchmarks', 'pallet-timestamp/runtime-benchmarks', 'pallet-common/runtime-benchmarks', + 'pallet-structure/runtime-benchmarks', 'pallet-fungible/runtime-benchmarks', 'pallet-refungible/runtime-benchmarks', 'pallet-nonfungible/runtime-benchmarks', --- a/runtime/unique/Cargo.toml +++ b/runtime/unique/Cargo.toml @@ -29,6 +29,7 @@ 'pallet-balances/runtime-benchmarks', 'pallet-timestamp/runtime-benchmarks', 'pallet-common/runtime-benchmarks', + 'pallet-structure/runtime-benchmarks', 'pallet-fungible/runtime-benchmarks', 'pallet-refungible/runtime-benchmarks', 'pallet-nonfungible/runtime-benchmarks',