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
before · pallets/structure/Cargo.toml
1[package]2name = "pallet-structure"3version = "0.1.0"4edition = "2021"56[dependencies]7frame-support = { default-features = false, git = 'https://github.com/paritytech/substrate.git', branch = 'polkadot-v0.9.17' }8frame-system = { default-features = false, git = 'https://github.com/paritytech/substrate.git', branch = 'polkadot-v0.9.17' }9sp-std = { default-features = false, git = 'https://github.com/paritytech/substrate.git', branch = 'polkadot-v0.9.17' }10pallet-common = { path = "../common", default-features = false }11parity-scale-codec = { version = "2.0.0", default-features = false, features = [12	"derive",13] }14scale-info = { version = "1.0.0", default-features = false, features = [15	"derive",16] }17up-data-structs = { path = "../../primitives/data-structs", default-features = false }1819[features]20default = ["std"]21std = [22	"frame-support/std",23	"frame-system/std",24	"sp-std/std",25	"pallet-common/std",26	"scale-info/std",27	"parity-scale-codec/std",28	"up-data-structs/std",29]
after · pallets/structure/Cargo.toml
1[package]2name = "pallet-structure"3version = "0.1.0"4edition = "2021"56[dependencies]7frame-support = { default-features = false, git = 'https://github.com/paritytech/substrate.git', branch = 'polkadot-v0.9.17' }8frame-system = { default-features = false, git = 'https://github.com/paritytech/substrate.git', branch = 'polkadot-v0.9.17' }9frame-benchmarking = { default-features = false, optional = true, git = 'https://github.com/paritytech/substrate.git', branch = 'polkadot-v0.9.17' }10sp-std = { default-features = false, git = 'https://github.com/paritytech/substrate.git', branch = 'polkadot-v0.9.17' }11pallet-common = { path = "../common", default-features = false }12parity-scale-codec = { version = "2.0.0", default-features = false, features = [13	"derive",14] }15scale-info = { version = "1.0.0", default-features = false, features = [16	"derive",17] }18up-data-structs = { path = "../../primitives/data-structs", default-features = false }1920[features]21default = ["std"]22std = [23	"frame-support/std",24	"frame-system/std",25	"frame-benchmarking/std",26	"sp-std/std",27	"pallet-common/std",28	"scale-info/std",29	"parity-scale-codec/std",30	"up-data-structs/std",31]32runtime-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
--- 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',