git.delta.rocks / unique-network / refs/commits / 4e1bd65c37e5

difftreelog

feat(nonfungible) benchmarking

Yaroslav Bolyukin2021-10-22parent: #54a17a4.patch.diff
in: master

5 files changed

modifiedpallets/nonfungible/Cargo.tomldiffbeforeafterboth
20evm-coder = { default-features = false, path = '../../crates/evm-coder' }20evm-coder = { default-features = false, path = '../../crates/evm-coder' }
21pallet-evm-coder-substrate = { default-features = false, path = '../evm-coder-substrate' }21pallet-evm-coder-substrate = { default-features = false, path = '../evm-coder-substrate' }
22ethereum = { default-features = false, version = "0.9.0" }22ethereum = { default-features = false, version = "0.9.0" }
23frame-benchmarking = { default-features = false, optional = true, git = 'https://github.com/paritytech/substrate.git', branch = 'polkadot-v0.9.10' }
2324
24[features]25[features]
25default = ["std"]26default = ["std"]
33 "evm-coder/std",34 "evm-coder/std",
34 "ethereum/std",35 "ethereum/std",
35 "pallet-evm-coder-substrate/std",36 "pallet-evm-coder-substrate/std",
37 'frame-benchmarking/std',
36]38]
37runtime-benchmarks = []39runtime-benchmarks = [
40 'frame-benchmarking',
41 'frame-support/runtime-benchmarks',
42 'frame-system/runtime-benchmarks',
43]
3844
modifiedpallets/nonfungible/src/benchmarking.rsdiffbeforeafterboth
1use super::*;
2use crate::{Pallet, Config, NonfungibleHandle};
3
4use sp_std::prelude::*;
5use pallet_common::benchmarking::{create_collection_raw, create_data};
6use frame_benchmarking::{benchmarks, account};
7use nft_data_structs::{CollectionMode, MAX_ITEMS_PER_BATCH};
8use pallet_common::bench_init;
9use core::convert::TryInto;
10
11const SEED: u32 = 1;
12
13fn create_max_item_data<T: Config>(owner: T::CrossAccountId) -> CreateItemData<T> {
14 let const_data = create_data(CUSTOM_DATA_LIMIT as usize).try_into().unwrap();
15 let variable_data = create_data(CUSTOM_DATA_LIMIT as usize).try_into().unwrap();
16 CreateItemData {
17 const_data,
18 variable_data,
19 owner,
20 }
21}
22fn create_max_item<T: Config>(
23 collection: &NonfungibleHandle<T>,
24 sender: &T::CrossAccountId,
25 owner: T::CrossAccountId,
26) -> Result<TokenId, DispatchError> {
27 <Pallet<T>>::create_item(&collection, sender, create_max_item_data(owner))?;
28 Ok(TokenId(<TokensMinted<T>>::get(&collection.id)))
29}
30
31fn create_collection<T: Config>(
32 owner: T::AccountId,
33) -> Result<NonfungibleHandle<T>, DispatchError> {
34 create_collection_raw(
35 owner,
36 CollectionMode::NFT,
37 <Pallet<T>>::init_collection,
38 NonfungibleHandle::cast,
39 )
40}
41
1#![cfg(feature = "runtime-benchmarking")]42benchmarks! {
43 create_item {
44 bench_init!{
45 owner: sub; collection: collection(owner);
46 sender: cross_from_sub(owner); to: cross_sub;
47 };
48 }: {create_max_item(&collection, &sender, to.clone())?}
49
50 create_multiple_items {
51 let b in 0..MAX_ITEMS_PER_BATCH;
52 bench_init!{
53 owner: sub; collection: collection(owner);
54 sender: cross_from_sub(owner); to: cross_sub;
55 };
56 let data = (0..b).map(|_| create_max_item_data(to.clone())).collect();
57 }: {<Pallet<T>>::create_multiple_items(&collection, &sender, data)?}
58
59 burn_item {
60 bench_init!{
61 owner: sub; collection: collection(owner);
62 sender: cross_from_sub(owner); burner: cross_sub;
63 };
64 let item = create_max_item(&collection, &sender, burner.clone())?;
65 }: {<Pallet<T>>::burn(&collection, &burner, item)?}
66
67 transfer {
68 bench_init!{
69 owner: sub; collection: collection(owner);
70 owner: cross_from_sub; sender: cross_sub; receiver: cross_sub;
71 };
72 let item = create_max_item(&collection, &owner, sender.clone())?;
73 }: {<Pallet<T>>::transfer(&collection, &sender, &receiver, item)?}
74
75 approve {
76 bench_init!{
77 owner: sub; collection: collection(owner);
78 owner: cross_from_sub; sender: cross_sub; spender: cross_sub;
79 };
80 let item = create_max_item(&collection, &owner, sender.clone())?;
81 }: {<Pallet<T>>::set_allowance(&collection, &sender, item, Some(&spender))?}
82
83 transfer_from {
84 bench_init!{
85 owner: sub; collection: collection(owner);
86 owner: cross_from_sub; sender: cross_sub; spender: cross_sub; receiver: cross_sub;
87 };
88 let item = create_max_item(&collection, &owner, sender.clone())?;
89 <Pallet<T>>::set_allowance(&collection, &sender, item, Some(&spender))?;
90 }: {<Pallet<T>>::transfer_from(&collection, &spender, &sender, &receiver, item)?}
91
92 set_variable_metadata {
93 let b in 0..CUSTOM_DATA_LIMIT;
94 bench_init!{
95 owner: sub; collection: collection(owner);
96 owner: cross_from_sub; sender: cross_sub;
97 };
98 let item = create_max_item(&collection, &owner, sender.clone())?;
99 let data = create_data(b as usize);
100 }: {<Pallet<T>>::set_variable_metadata(&collection, &sender, item, data)?}
101}
2102
modifiedpallets/nonfungible/src/common.rsdiffbeforeafterboth
9use sp_std::vec::Vec;9use sp_std::vec::Vec;
1010
11use crate::{11use crate::{
12 AccountBalance, Allowance, Config, CreateItemData, DataKind, Error, NonfungibleHandle, Owned,12 AccountBalance, Allowance, Config, CreateItemData, Error, NonfungibleHandle, Owned, Pallet,
13 Owner, Pallet, SelfWeightOf, TokenData, weights::WeightInfo,13 SelfWeightOf, TokenData, weights::WeightInfo, TokensMinted,
14};14};
1515
16pub struct CommonWeights<T: Config>(PhantomData<T>);16pub struct CommonWeights<T: Config>(PhantomData<T>);
39 <SelfWeightOf<T>>::transfer_from()39 <SelfWeightOf<T>>::transfer_from()
40 }40 }
4141
42 fn set_variable_metadata(_bytes: u32) -> Weight {42 fn set_variable_metadata(bytes: u32) -> Weight {
43 <SelfWeightOf<T>>::set_variable_metadata()43 <SelfWeightOf<T>>::set_variable_metadata(bytes)
44 }44 }
45}45}
4646
67 ) -> DispatchResultWithPostInfo {67 ) -> DispatchResultWithPostInfo {
68 with_weight(68 with_weight(
69 <Pallet<T>>::create_item(self, &sender, map_create_data(data, &to)?),69 <Pallet<T>>::create_item(self, &sender, map_create_data(data, &to)?),
70 <SelfWeightOf<T>>::create_item(),70 <CommonWeights<T>>::create_item(),
71 )71 )
72 }72 }
7373
85 let amount = data.len();85 let amount = data.len();
86 with_weight(86 with_weight(
87 <Pallet<T>>::create_multiple_items(self, &sender, data),87 <Pallet<T>>::create_multiple_items(self, &sender, data),
88 <SelfWeightOf<T>>::create_multiple_items(amount as u32),88 <CommonWeights<T>>::create_multiple_items(amount as u32),
89 )89 )
90 }90 }
9191
99 if amount == 1 {99 if amount == 1 {
100 with_weight(100 with_weight(
101 <Pallet<T>>::burn(&self, &sender, token),101 <Pallet<T>>::burn(&self, &sender, token),
102 <SelfWeightOf<T>>::burn_item(),102 <CommonWeights<T>>::burn_item(),
103 )103 )
104 } else {104 } else {
105 Ok(().into())105 Ok(().into())
117 if amount == 1 {117 if amount == 1 {
118 with_weight(118 with_weight(
119 <Pallet<T>>::transfer(&self, &from, &to, token),119 <Pallet<T>>::transfer(&self, &from, &to, token),
120 <SelfWeightOf<T>>::transfer(),120 <CommonWeights<T>>::transfer(),
121 )121 )
122 } else {122 } else {
123 Ok(().into())123 Ok(().into())
139 } else {139 } else {
140 <Pallet<T>>::set_allowance(&self, &sender, token, None)140 <Pallet<T>>::set_allowance(&self, &sender, token, None)
141 },141 },
142 <SelfWeightOf<T>>::approve(),142 <CommonWeights<T>>::approve(),
143 )143 )
144 }144 }
145145
156 if amount == 1 {156 if amount == 1 {
157 with_weight(157 with_weight(
158 <Pallet<T>>::transfer_from(&self, &sender, &from, &to, token),158 <Pallet<T>>::transfer_from(&self, &sender, &from, &to, token),
159 <SelfWeightOf<T>>::transfer_from(),159 <CommonWeights<T>>::transfer_from(),
160 )160 )
161 } else {161 } else {
162 Ok(().into())162 Ok(().into())
169 token: TokenId,169 token: TokenId,
170 data: Vec<u8>,170 data: Vec<u8>,
171 ) -> DispatchResultWithPostInfo {171 ) -> DispatchResultWithPostInfo {
172 let len = data.len();
172 with_weight(173 with_weight(
173 <Pallet<T>>::set_variable_metadata(&self, &sender, token, data),174 <Pallet<T>>::set_variable_metadata(&self, &sender, token, data),
174 <SelfWeightOf<T>>::set_variable_metadata(),175 <CommonWeights<T>>::set_variable_metadata(len as u32),
175 )176 )
176 }177 }
177178
modifiedpallets/nonfungible/src/lib.rsdiffbeforeafterboth
16use codec::{Encode, Decode};16use codec::{Encode, Decode};
1717
18pub use pallet::*;18pub use pallet::*;
19#[cfg(feature = "runtime-benchmarks")]
19pub mod benchmarking;20pub mod benchmarking;
20pub mod common;21pub mod common;
21pub mod erc;22pub mod erc;
modifiedpallets/nonfungible/src/weights.rsdiffbeforeafterboth
1// Template adopted from https://github.com/paritytech/substrate/blob/master/.maintain/frame-weight-template.hbs
2
3//! Autogenerated weights for pallet_nonfungible
4//!
5//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev
6//! DATE: 2021-10-21, STEPS: `50`, REPEAT: 20, LOW RANGE: `[]`, HIGH RANGE: `[]`
7//! EXECUTION: None, WASM-EXECUTION: Compiled, CHAIN: None, DB CACHE: 128
8
9// Executed Command:
10// target/release/nft
11// benchmark
12// --pallet
13// pallet-nonfungible
14// --wasm-execution
15// compiled
16// --extrinsic
17// *
18// --template
19// .maintain/frame-weight-template.hbs
20// --steps=50
21// --repeat=20
22// --output=./pallets/nonfungible/src/weights.rs
23
24
1#![cfg_attr(rustfmt, rustfmt_skip)]25#![cfg_attr(rustfmt, rustfmt_skip)]
5use frame_support::{traits::Get, weights::{Weight, constants::RocksDbWeight}};29use frame_support::{traits::Get, weights::{Weight, constants::RocksDbWeight}};
6use sp_std::marker::PhantomData;30use sp_std::marker::PhantomData;
731
32/// Weight functions needed for pallet_nonfungible.
8pub trait WeightInfo {33pub trait WeightInfo {
9 fn create_item() -> Weight;34 fn create_item() -> Weight;
10 fn create_multiple_items(b: u32) -> Weight;35 fn create_multiple_items(b: u32, ) -> Weight;
11 fn burn_item() -> Weight;36 fn burn_item() -> Weight;
12 fn transfer() -> Weight;37 fn transfer() -> Weight;
13 fn approve() -> Weight;38 fn approve() -> Weight;
14 fn transfer_from() -> Weight;39 fn transfer_from() -> Weight;
15 fn set_variable_metadata() -> Weight;40 fn set_variable_metadata(b: u32, ) -> Weight;
16}41}
1742
43/// Weights for pallet_nonfungible using the Substrate node and recommended hardware.
18pub struct SubstrateWeight<T>(PhantomData<T>);44pub struct SubstrateWeight<T>(PhantomData<T>);
19impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> {45impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> {
46 // Storage: Nonfungible TokensMinted (r:1 w:1)
47 // Storage: Nonfungible AccountBalance (r:1 w:1)
48 // Storage: Nonfungible TokenData (r:0 w:1)
49 // Storage: Nonfungible Owned (r:0 w:1)
20 fn create_item() -> Weight {0}50 fn create_item() -> Weight {
51 (16_902_000 as Weight)
52 .saturating_add(T::DbWeight::get().reads(2 as Weight))
53 .saturating_add(T::DbWeight::get().writes(4 as Weight))
54 }
55 // Storage: Nonfungible TokensMinted (r:1 w:1)
56 // Storage: Nonfungible AccountBalance (r:1 w:1)
57 // Storage: Nonfungible TokenData (r:0 w:4)
58 // Storage: Nonfungible Owned (r:0 w:4)
21 fn create_multiple_items(_b: u32) -> Weight {0}59 fn create_multiple_items(b: u32, ) -> Weight {
60 (15_860_000 as Weight)
61 // Standard Error: 5_000
62 .saturating_add((3_916_000 as Weight).saturating_mul(b as Weight))
63 .saturating_add(T::DbWeight::get().reads(2 as Weight))
64 .saturating_add(T::DbWeight::get().writes(2 as Weight))
65 .saturating_add(T::DbWeight::get().writes((2 as Weight).saturating_mul(b as Weight)))
66 }
67 // Storage: Nonfungible TokenData (r:1 w:1)
68 // Storage: Nonfungible TokensBurnt (r:1 w:1)
69 // Storage: Nonfungible Allowance (r:1 w:0)
70 // Storage: Nonfungible Owned (r:0 w:1)
22 fn burn_item() -> Weight {0}71 fn burn_item() -> Weight {
72 (17_966_000 as Weight)
73 .saturating_add(T::DbWeight::get().reads(3 as Weight))
74 .saturating_add(T::DbWeight::get().writes(3 as Weight))
75 }
76 // Storage: Nonfungible TokenData (r:1 w:1)
77 // Storage: Nonfungible AccountBalance (r:2 w:2)
78 // Storage: Nonfungible Allowance (r:1 w:0)
79 // Storage: Nonfungible Owned (r:0 w:2)
23 fn transfer() -> Weight {0}80 fn transfer() -> Weight {
81 (23_886_000 as Weight)
82 .saturating_add(T::DbWeight::get().reads(4 as Weight))
83 .saturating_add(T::DbWeight::get().writes(5 as Weight))
84 }
85 // Storage: Nonfungible TokenData (r:1 w:0)
86 // Storage: Nonfungible Allowance (r:1 w:1)
24 fn approve() -> Weight {0}87 fn approve() -> Weight {
88 (14_697_000 as Weight)
89 .saturating_add(T::DbWeight::get().reads(2 as Weight))
90 .saturating_add(T::DbWeight::get().writes(1 as Weight))
91 }
92 // Storage: Nonfungible Allowance (r:1 w:1)
93 // Storage: Nonfungible TokenData (r:1 w:1)
94 // Storage: Nonfungible AccountBalance (r:2 w:2)
95 // Storage: Nonfungible Owned (r:0 w:2)
25 fn transfer_from() -> Weight {0}96 fn transfer_from() -> Weight {
97 (28_001_000 as Weight)
98 .saturating_add(T::DbWeight::get().reads(4 as Weight))
99 .saturating_add(T::DbWeight::get().writes(6 as Weight))
100 }
101 // Storage: Nonfungible TokenData (r:1 w:1)
26 fn set_variable_metadata() -> Weight {0}102 fn set_variable_metadata(_b: u32, ) -> Weight {
103 (6_380_000 as Weight)
104 .saturating_add(T::DbWeight::get().reads(1 as Weight))
105 .saturating_add(T::DbWeight::get().writes(1 as Weight))
106 }
27}107}
28108
109// For backwards compatibility and tests
29impl WeightInfo for () {110impl WeightInfo for () {
111 // Storage: Nonfungible TokensMinted (r:1 w:1)
112 // Storage: Nonfungible AccountBalance (r:1 w:1)
113 // Storage: Nonfungible TokenData (r:0 w:1)
114 // Storage: Nonfungible Owned (r:0 w:1)
30 fn create_item() -> Weight {0}115 fn create_item() -> Weight {
116 (16_902_000 as Weight)
117 .saturating_add(RocksDbWeight::get().reads(2 as Weight))
118 .saturating_add(RocksDbWeight::get().writes(4 as Weight))
119 }
120 // Storage: Nonfungible TokensMinted (r:1 w:1)
121 // Storage: Nonfungible AccountBalance (r:1 w:1)
122 // Storage: Nonfungible TokenData (r:0 w:4)
123 // Storage: Nonfungible Owned (r:0 w:4)
31 fn create_multiple_items(_b: u32) -> Weight {0}124 fn create_multiple_items(b: u32, ) -> Weight {
125 (15_860_000 as Weight)
126 // Standard Error: 5_000
127 .saturating_add((3_916_000 as Weight).saturating_mul(b as Weight))
128 .saturating_add(RocksDbWeight::get().reads(2 as Weight))
129 .saturating_add(RocksDbWeight::get().writes(2 as Weight))
130 .saturating_add(RocksDbWeight::get().writes((2 as Weight).saturating_mul(b as Weight)))
131 }
132 // Storage: Nonfungible TokenData (r:1 w:1)
133 // Storage: Nonfungible TokensBurnt (r:1 w:1)
134 // Storage: Nonfungible Allowance (r:1 w:0)
135 // Storage: Nonfungible Owned (r:0 w:1)
32 fn burn_item() -> Weight {0}136 fn burn_item() -> Weight {
137 (17_966_000 as Weight)
138 .saturating_add(RocksDbWeight::get().reads(3 as Weight))
139 .saturating_add(RocksDbWeight::get().writes(3 as Weight))
140 }
141 // Storage: Nonfungible TokenData (r:1 w:1)
142 // Storage: Nonfungible AccountBalance (r:2 w:2)
143 // Storage: Nonfungible Allowance (r:1 w:0)
144 // Storage: Nonfungible Owned (r:0 w:2)
33 fn transfer() -> Weight {0}145 fn transfer() -> Weight {
146 (23_886_000 as Weight)
147 .saturating_add(RocksDbWeight::get().reads(4 as Weight))
148 .saturating_add(RocksDbWeight::get().writes(5 as Weight))
149 }
150 // Storage: Nonfungible TokenData (r:1 w:0)
151 // Storage: Nonfungible Allowance (r:1 w:1)
34 fn approve() -> Weight {0}152 fn approve() -> Weight {
153 (14_697_000 as Weight)
154 .saturating_add(RocksDbWeight::get().reads(2 as Weight))
155 .saturating_add(RocksDbWeight::get().writes(1 as Weight))
156 }
157 // Storage: Nonfungible Allowance (r:1 w:1)
158 // Storage: Nonfungible TokenData (r:1 w:1)
159 // Storage: Nonfungible AccountBalance (r:2 w:2)
160 // Storage: Nonfungible Owned (r:0 w:2)
35 fn transfer_from() -> Weight {0}161 fn transfer_from() -> Weight {
162 (28_001_000 as Weight)
163 .saturating_add(RocksDbWeight::get().reads(4 as Weight))
164 .saturating_add(RocksDbWeight::get().writes(6 as Weight))
165 }
166 // Storage: Nonfungible TokenData (r:1 w:1)
36 fn set_variable_metadata() -> Weight {0}167 fn set_variable_metadata(_b: u32, ) -> Weight {
168 (6_380_000 as Weight)
169 .saturating_add(RocksDbWeight::get().reads(1 as Weight))
170 .saturating_add(RocksDbWeight::get().writes(1 as Weight))