git.delta.rocks / unique-network / refs/commits / 54a17a4acbdb

difftreelog

feat(fungible) benchmarking

Yaroslav Bolyukin2021-10-22parent: #278f1b9.patch.diff
in: master

5 files changed

modifiedpallets/fungible/Cargo.tomldiffbeforeafterboth
--- a/pallets/fungible/Cargo.toml
+++ b/pallets/fungible/Cargo.toml
@@ -20,6 +20,7 @@
 evm-coder = { default-features = false, path = '../../crates/evm-coder' }
 ethereum = { default-features = false, version = "0.9.0" }
 pallet-evm-coder-substrate = { default-features = false, path = '../evm-coder-substrate' }
+frame-benchmarking = { default-features = false, optional = true, git = 'https://github.com/paritytech/substrate.git', branch = 'polkadot-v0.9.10' }
 
 [features]
 default = ["std"]
@@ -32,5 +33,9 @@
     "pallet-common/std",
     "evm-coder/std",
     "ethereum/std",
+    'frame-benchmarking/std',
 ]
-runtime-benchmarks = []
+runtime-benchmarks = [
+    'frame-benchmarking',
+    'pallet-common/runtime-benchmarks',
+]
modifiedpallets/fungible/src/benchmarking.rsdiffbeforeafterboth
--- a/pallets/fungible/src/benchmarking.rs
+++ b/pallets/fungible/src/benchmarking.rs
@@ -1 +1,61 @@
-#![cfg(feature = "runtime-benchmarking")]
+use super::*;
+use crate::{Pallet, Config, FungibleHandle};
+
+use sp_std::prelude::*;
+use pallet_common::benchmarking::create_collection_raw;
+use frame_benchmarking::{benchmarks, account};
+use nft_data_structs::{CollectionMode};
+use pallet_common::bench_init;
+
+const SEED: u32 = 1;
+
+fn create_collection<T: Config>(owner: T::AccountId) -> Result<FungibleHandle<T>, DispatchError> {
+	create_collection_raw(
+		owner,
+		CollectionMode::Fungible(0),
+		<Pallet<T>>::init_collection,
+		FungibleHandle::cast,
+	)
+}
+
+benchmarks! {
+	create_item {
+		bench_init!{
+			owner: sub; collection: collection(owner);
+			sender: cross_from_sub(owner); to: cross_sub;
+		};
+	}: {<Pallet<T>>::create_item(&collection, &sender, (to, 200))?}
+
+	burn_item {
+		bench_init!{
+			owner: sub; collection: collection(owner);
+			owner: cross_from_sub; burner: cross_sub;
+		};
+		<Pallet<T>>::create_item(&collection, &owner, (burner.clone(), 200))?;
+	}: {<Pallet<T>>::burn(&collection, &burner, 100)?}
+
+	transfer {
+		bench_init!{
+			owner: sub; collection: collection(owner);
+			owner: cross_from_sub; sender: cross_sub; to: cross_sub;
+		};
+		<Pallet<T>>::create_item(&collection, &owner, (sender.clone(), 200))?;
+	}: {<Pallet<T>>::transfer(&collection, &sender, &to, 200)?}
+
+	approve {
+		bench_init!{
+			owner: sub; collection: collection(owner);
+			owner: cross_from_sub; sender: cross_sub; spender: cross_sub;
+		};
+		<Pallet<T>>::create_item(&collection, &owner, (sender.clone(), 200))?;
+	}: {<Pallet<T>>::set_allowance(&collection, &sender, &spender, 100)?}
+
+	transfer_from {
+		bench_init!{
+			owner: sub; collection: collection(owner);
+			owner: cross_from_sub; sender: cross_sub; spender: cross_sub; receiver: cross_sub;
+		};
+		<Pallet<T>>::create_item(&collection, &owner, (sender.clone(), 200))?;
+		<Pallet<T>>::set_allowance(&collection, &sender, &spender, 200)?;
+	}: {<Pallet<T>>::transfer_from(&collection, &spender, &sender, &receiver, 100)?}
+}
modifiedpallets/fungible/src/common.rsdiffbeforeafterboth
--- a/pallets/fungible/src/common.rs
+++ b/pallets/fungible/src/common.rs
@@ -54,7 +54,7 @@
 		match data {
 			nft_data_structs::CreateItemData::Fungible(data) => with_weight(
 				<Pallet<T>>::create_item(self, &sender, (to, data.value)),
-				<SelfWeightOf<T>>::create_item(),
+				<CommonWeights<T>>::create_item(),
 			),
 			_ => fail!(<Error<T>>::NotFungibleDataUsedToMintFungibleCollectionToken),
 		}
@@ -80,7 +80,7 @@
 
 		with_weight(
 			<Pallet<T>>::create_item(self, &sender, (to, sum)),
-			<SelfWeightOf<T>>::create_item(),
+			<CommonWeights<T>>::create_item(),
 		)
 	}
 
@@ -97,7 +97,7 @@
 
 		with_weight(
 			<Pallet<T>>::burn(self, &sender, amount),
-			<SelfWeightOf<T>>::burn_item(),
+			<CommonWeights<T>>::burn_item(),
 		)
 	}
 
@@ -115,7 +115,7 @@
 
 		with_weight(
 			<Pallet<T>>::transfer(&self, &from, &to, amount),
-			<SelfWeightOf<T>>::transfer(),
+			<CommonWeights<T>>::transfer(),
 		)
 	}
 
@@ -133,7 +133,7 @@
 
 		with_weight(
 			<Pallet<T>>::set_allowance(&self, &sender, &spender, amount),
-			<SelfWeightOf<T>>::approve(),
+			<CommonWeights<T>>::approve(),
 		)
 	}
 
@@ -152,7 +152,7 @@
 
 		with_weight(
 			<Pallet<T>>::transfer_from(&self, &sender, &from, &to, amount),
-			<SelfWeightOf<T>>::transfer_from(),
+			<CommonWeights<T>>::transfer_from(),
 		)
 	}
 
modifiedpallets/fungible/src/lib.rsdiffbeforeafterboth
--- a/pallets/fungible/src/lib.rs
+++ b/pallets/fungible/src/lib.rs
@@ -13,6 +13,7 @@
 pub use pallet::*;
 
 use crate::erc::ERC20Events;
+#[cfg(feature = "runtime-benchmarks")]
 pub mod benchmarking;
 pub mod common;
 pub mod erc;
modifiedpallets/fungible/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_fungible
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-fungible
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/fungible/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_fungible.
8pub trait WeightInfo {33pub trait WeightInfo {
9 fn create_item() -> Weight;34 fn create_item() -> Weight;
10 fn burn_item() -> Weight;35 fn burn_item() -> Weight;
13 fn transfer_from() -> Weight;38 fn transfer_from() -> Weight;
14}39}
1540
41/// Weights for pallet_fungible using the Substrate node and recommended hardware.
16pub struct SubstrateWeight<T>(PhantomData<T>);42pub struct SubstrateWeight<T>(PhantomData<T>);
17impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> {43impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> {
44 // Storage: Fungible Balance (r:1 w:1)
45 // Storage: Fungible TotalSupply (r:0 w:1)
18 fn create_item() -> Weight {0}46 fn create_item() -> Weight {
47 (12_069_000 as Weight)
48 .saturating_add(T::DbWeight::get().reads(1 as Weight))
49 .saturating_add(T::DbWeight::get().writes(2 as Weight))
50 }
51 // Storage: Fungible TotalSupply (r:1 w:1)
52 // Storage: Fungible Balance (r:1 w:1)
19 fn burn_item() -> Weight {0}53 fn burn_item() -> Weight {
54 (14_096_000 as Weight)
55 .saturating_add(T::DbWeight::get().reads(2 as Weight))
56 .saturating_add(T::DbWeight::get().writes(2 as Weight))
57 }
58 // Storage: Fungible Balance (r:2 w:2)
20 fn transfer() -> Weight {0}59 fn transfer() -> Weight {
60 (15_436_000 as Weight)
61 .saturating_add(T::DbWeight::get().reads(2 as Weight))
62 .saturating_add(T::DbWeight::get().writes(2 as Weight))
63 }
64 // Storage: Fungible Balance (r:1 w:0)
65 // Storage: Fungible Allowance (r:0 w:1)
21 fn approve() -> Weight {0}66 fn approve() -> Weight {
67 (12_867_000 as Weight)
68 .saturating_add(T::DbWeight::get().reads(1 as Weight))
69 .saturating_add(T::DbWeight::get().writes(1 as Weight))
70 }
71 // Storage: Fungible Allowance (r:1 w:1)
72 // Storage: Fungible Balance (r:2 w:2)
22 fn transfer_from() -> Weight {0}73 fn transfer_from() -> Weight {
74 (21_462_000 as Weight)
75 .saturating_add(T::DbWeight::get().reads(3 as Weight))
76 .saturating_add(T::DbWeight::get().writes(3 as Weight))
77 }
23}78}
2479
80// For backwards compatibility and tests
25impl WeightInfo for () {81impl WeightInfo for () {
82 // Storage: Fungible Balance (r:1 w:1)
83 // Storage: Fungible TotalSupply (r:0 w:1)
26 fn create_item() -> Weight {0}84 fn create_item() -> Weight {
85 (12_069_000 as Weight)
86 .saturating_add(RocksDbWeight::get().reads(1 as Weight))
87 .saturating_add(RocksDbWeight::get().writes(2 as Weight))
88 }
89 // Storage: Fungible TotalSupply (r:1 w:1)
90 // Storage: Fungible Balance (r:1 w:1)
27 fn burn_item() -> Weight {0}91 fn burn_item() -> Weight {
92 (14_096_000 as Weight)
93 .saturating_add(RocksDbWeight::get().reads(2 as Weight))
94 .saturating_add(RocksDbWeight::get().writes(2 as Weight))
95 }
96 // Storage: Fungible Balance (r:2 w:2)
28 fn transfer() -> Weight {0}97 fn transfer() -> Weight {
98 (15_436_000 as Weight)
99 .saturating_add(RocksDbWeight::get().reads(2 as Weight))
100 .saturating_add(RocksDbWeight::get().writes(2 as Weight))
101 }
102 // Storage: Fungible Balance (r:1 w:0)
103 // Storage: Fungible Allowance (r:0 w:1)
29 fn approve() -> Weight {0}104 fn approve() -> Weight {
105 (12_867_000 as Weight)
106 .saturating_add(RocksDbWeight::get().reads(1 as Weight))
107 .saturating_add(RocksDbWeight::get().writes(1 as Weight))
108 }
109 // Storage: Fungible Allowance (r:1 w:1)
110 // Storage: Fungible Balance (r:2 w:2)
30 fn transfer_from() -> Weight {0}111 fn transfer_from() -> Weight {
112 (21_462_000 as Weight)
113 .saturating_add(RocksDbWeight::get().reads(3 as Weight))
114 .saturating_add(RocksDbWeight::get().writes(3 as Weight))
115 }
31}116}
32117