git.delta.rocks / unique-network / refs/commits / 23942aa9dbcc

difftreelog

feat benchmark structure

Yaroslav Bolyukin2022-04-07parent: #a588a2c.patch.diff
in: master

9 files changed

modifiedMakefilediffbeforeafterboth
--- 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
modifiedpallets/structure/Cargo.tomldiffbeforeafterboth
--- 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']
addedpallets/structure/src/benchmarking.rsdiffbeforeafterboth
--- /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 = <Pallet<T>>::find_parent(CollectionId(1), TokenId(1))?;
+		assert!(matches!(parent, Parent::Normal(_)))
+	}
+}
addedpallets/structure/src/weights.rsdiffbeforeafterboth
--- /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<T>(PhantomData<T>);
+impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> {
+	// 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))
+	}
+}
modifiedruntime/common/src/runtime_apis.rsdiffbeforeafterboth
--- 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);
modifiedruntime/opal/Cargo.tomldiffbeforeafterboth
--- 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',
modifiedruntime/opal/src/lib.rsdiffbeforeafterboth
--- 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<Self>;
 }
 
 impl pallet_fungible::Config for Runtime {
modifiedruntime/quartz/Cargo.tomldiffbeforeafterboth
--- 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',
modifiedruntime/unique/Cargo.tomldiffbeforeafterboth
29 'pallet-balances/runtime-benchmarks',29 'pallet-balances/runtime-benchmarks',
30 'pallet-timestamp/runtime-benchmarks',30 'pallet-timestamp/runtime-benchmarks',
31 'pallet-common/runtime-benchmarks',31 'pallet-common/runtime-benchmarks',
32 'pallet-structure/runtime-benchmarks',
32 'pallet-fungible/runtime-benchmarks',33 'pallet-fungible/runtime-benchmarks',
33 'pallet-refungible/runtime-benchmarks',34 'pallet-refungible/runtime-benchmarks',
34 'pallet-nonfungible/runtime-benchmarks',35 'pallet-nonfungible/runtime-benchmarks',