From 4469adb5861d8b8fef47a931831edbcbbcc60203 Mon Sep 17 00:00:00 2001 From: Yaroslav Bolyukin Date: Thu, 09 Jun 2022 12:32:10 +0000 Subject: [PATCH] feat: rmrk-core benchmarking --- --- a/Makefile +++ b/Makefile @@ -93,5 +93,9 @@ bench-structure: make _bench PALLET=structure +.PHONY: bench-rmrk-core +bench-rmrk-core: + make _bench PALLET=proxy-rmrk-core + .PHONY: bench bench: bench-evm-migration bench-unique bench-structure bench-fungible bench-refungible bench-nonfungible --- a/pallets/common/src/benchmarking.rs +++ b/pallets/common/src/benchmarking.rs @@ -109,7 +109,7 @@ create_collection_raw( owner, CollectionMode::NFT, - |owner, data| >::init_collection(owner, data), + |owner, data| >::init_collection(owner, data, true), |h| h, ) } --- a/pallets/common/src/lib.rs +++ b/pallets/common/src/lib.rs @@ -427,7 +427,7 @@ /// Target collection doesn't supports this operation UnsupportedOperation, - /// Not sufficient founds to perform action + /// Not sufficient funds to perform action NotSufficientFounds, /// Collection has nesting disabled --- a/pallets/nonfungible/src/benchmarking.rs +++ b/pallets/nonfungible/src/benchmarking.rs @@ -51,7 +51,7 @@ create_collection_raw( owner, CollectionMode::NFT, - >::init_collection, + |owner, data| >::init_collection(owner, data, true), NonfungibleHandle::cast, ) } @@ -99,7 +99,7 @@ sender: cross_from_sub(owner); burner: cross_sub; }; let item = create_max_item(&collection, &sender, burner.clone())?; - }: {>::burn_recursively(&collection, &burner, item, &Unlimited, &Unlimited)} + }: {>::burn_recursively(&collection, &burner, item, &Unlimited, &Unlimited)?} burn_recursively_breadth_plus_self_plus_self_per_each_raw { let b in 0..200; @@ -111,7 +111,7 @@ for i in 0..b { create_max_item(&collection, &sender, T::CrossTokenAddressMapping::token_to_address(collection.id, item))?; } - }: {>::burn_recursively(&collection, &burner, item, &Unlimited, &Unlimited)} + }: {>::burn_recursively(&collection, &burner, item, &Unlimited, &Unlimited)?} transfer { bench_init!{ @@ -183,7 +183,7 @@ value: property_value(), }).collect::>(); let item = create_max_item(&collection, &owner, owner.clone())?; - }: {>::set_token_properties(&collection, &owner, item, props)?} + }: {>::set_token_properties(&collection, &owner, item, props, false)?} delete_token_properties { let b in 0..MAX_PROPERTIES_PER_ITEM; @@ -205,7 +205,7 @@ value: property_value(), }).collect::>(); let item = create_max_item(&collection, &owner, owner.clone())?; - >::set_token_properties(&collection, &owner, item, props)?; + >::set_token_properties(&collection, &owner, item, props, false)?; let to_delete = (0..b).map(|k| property_key(k as usize)).collect::>(); }: {>::delete_token_properties(&collection, &owner, item, to_delete)?} } --- /dev/null +++ b/pallets/proxy-rmrk-core/src/benchmarking.rs @@ -0,0 +1,26 @@ +use sp_std::vec; + +use frame_benchmarking::{benchmarks, account}; +use frame_system::RawOrigin; +use frame_support::{ + traits::{Currency, Get}, + BoundedVec, +}; + +use crate::{Config, Pallet, Call}; + +const SEED: u32 = 1; + +fn create_data>() -> BoundedVec { + vec![0; S::get() as usize].try_into().expect("size == S") +} + +benchmarks! { + create_collection { + let caller = account("caller", 0, SEED); + ::Currency::deposit_creating(&caller, T::CollectionCreationPrice::get()); + let metadata = create_data(); + // TODO: Fix CollectionTokenPrefixLimitExceeded with create_data + let symbol = vec![].try_into().expect("0 <= x"); + }: _(RawOrigin::Signed(caller), metadata, None, symbol) +} --- a/pallets/proxy-rmrk-core/src/lib.rs +++ b/pallets/proxy-rmrk-core/src/lib.rs @@ -31,9 +31,15 @@ pub use pallet::*; +#[cfg(feature = "runtime-benchmarks")] +pub mod benchmarking; pub mod misc; pub mod property; +pub mod weights; + +pub type SelfWeightOf = ::WeightInfo; +use weights::WeightInfo; use misc::*; pub use property::*; @@ -51,6 +57,7 @@ frame_system::Config + pallet_common::Config + pallet_nonfungible::Config + account::Config { type Event: From> + IsType<::Event>; + type WeightInfo: WeightInfo; } #[pallet::storage] @@ -169,7 +176,7 @@ #[pallet::call] impl Pallet { - #[pallet::weight(10_000 + T::DbWeight::get().reads_writes(1,1))] + #[pallet::weight(>::create_collection())] #[transactional] pub fn create_collection( origin: OriginFor, --- /dev/null +++ b/pallets/proxy-rmrk-core/src/weights.rs @@ -0,0 +1,74 @@ +// Template adopted from https://github.com/paritytech/substrate/blob/master/.maintain/frame-weight-template.hbs + +//! Autogenerated weights for pallet_proxy_rmrk_core +//! +//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev +//! DATE: 2022-06-09, 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 +// pallet-proxy-rmrk-core +// --wasm-execution +// compiled +// --extrinsic +// * +// --template +// .maintain/frame-weight-template.hbs +// --steps=50 +// --repeat=200 +// --heap-pages=4096 +// --output=./pallets/proxy-rmrk-core/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_core. +pub trait WeightInfo { + fn create_collection() -> Weight; +} + +/// Weights for pallet_proxy_rmrk_core 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: RmrkCore CollectionIndex (r:1 w:1) + // Storage: Common CollectionPropertyPermissions (r:0 w:1) + // Storage: Common CollectionProperties (r:0 w:1) + // Storage: Common CollectionById (r:0 w:1) + // Storage: RmrkCore UniqueCollectionId (r:0 w:1) + // Storage: RmrkCore RmrkInernalCollectionId (r:0 w:1) + fn create_collection() -> Weight { + (76_647_000 as Weight) + .saturating_add(T::DbWeight::get().reads(5 as Weight)) + .saturating_add(T::DbWeight::get().writes(9 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: RmrkCore CollectionIndex (r:1 w:1) + // Storage: Common CollectionPropertyPermissions (r:0 w:1) + // Storage: Common CollectionProperties (r:0 w:1) + // Storage: Common CollectionById (r:0 w:1) + // Storage: RmrkCore UniqueCollectionId (r:0 w:1) + // Storage: RmrkCore RmrkInernalCollectionId (r:0 w:1) + fn create_collection() -> Weight { + (76_647_000 as Weight) + .saturating_add(RocksDbWeight::get().reads(5 as Weight)) + .saturating_add(RocksDbWeight::get().writes(9 as Weight)) + } +} --- a/runtime/common/src/runtime_apis.rs +++ b/runtime/common/src/runtime_apis.rs @@ -827,6 +827,7 @@ list_benchmark!(list, extra, pallet_fungible, Fungible); list_benchmark!(list, extra, pallet_refungible, Refungible); list_benchmark!(list, extra, pallet_nonfungible, Nonfungible); + list_benchmark!(list, extra, pallet_proxy_rmrk_core, RmrkCore); // list_benchmark!(list, extra, pallet_evm_coder_substrate, EvmCoderSubstrate); let storage_info = AllPalletsReversedWithSystemFirst::storage_info(); @@ -870,6 +871,7 @@ add_benchmark!(params, batches, pallet_fungible, Fungible); add_benchmark!(params, batches, pallet_refungible, Refungible); add_benchmark!(params, batches, pallet_nonfungible, Nonfungible); + add_benchmark!(params, batches, pallet_proxy_rmrk_core, RmrkCore); // 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/src/lib.rs +++ b/runtime/opal/src/lib.rs @@ -919,6 +919,7 @@ } impl pallet_proxy_rmrk_core::Config for Runtime { + type WeightInfo = pallet_proxy_rmrk_core::weights::SubstrateWeight; type Event = Event; } --- a/runtime/quartz/src/lib.rs +++ b/runtime/quartz/src/lib.rs @@ -918,6 +918,7 @@ } impl pallet_proxy_rmrk_core::Config for Runtime { + type WeightInfo = pallet_proxy_rmrk_core::weights::SubstrateWeight; type Event = Event; } --- a/runtime/unique/src/lib.rs +++ b/runtime/unique/src/lib.rs @@ -917,6 +917,7 @@ } impl pallet_proxy_rmrk_core::Config for Runtime { + type WeightInfo = pallet_proxy_rmrk_core::weights::SubstrateWeight; type Event = Event; } -- gitstuff