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
13pub use pallet::*;13pub use pallet::*;
1414
15use crate::erc::ERC20Events;15use crate::erc::ERC20Events;
16#[cfg(feature = "runtime-benchmarks")]
16pub mod benchmarking;17pub mod benchmarking;
17pub mod common;18pub mod common;
18pub mod erc;19pub mod erc;
modifiedpallets/fungible/src/weights.rsdiffbeforeafterboth
--- a/pallets/fungible/src/weights.rs
+++ b/pallets/fungible/src/weights.rs
@@ -1,3 +1,27 @@
+// Template adopted from https://github.com/paritytech/substrate/blob/master/.maintain/frame-weight-template.hbs
+
+//! Autogenerated weights for pallet_fungible
+//!
+//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev
+//! DATE: 2021-10-21, STEPS: `50`, REPEAT: 20, LOW RANGE: `[]`, HIGH RANGE: `[]`
+//! EXECUTION: None, WASM-EXECUTION: Compiled, CHAIN: None, DB CACHE: 128
+
+// Executed Command:
+// target/release/nft
+// benchmark
+// --pallet
+// pallet-fungible
+// --wasm-execution
+// compiled
+// --extrinsic
+// *
+// --template
+// .maintain/frame-weight-template.hbs
+// --steps=50
+// --repeat=20
+// --output=./pallets/fungible/src/weights.rs
+
+
 #![cfg_attr(rustfmt, rustfmt_skip)]
 #![allow(unused_parens)]
 #![allow(unused_imports)]
@@ -5,6 +29,7 @@
 use frame_support::{traits::Get, weights::{Weight, constants::RocksDbWeight}};
 use sp_std::marker::PhantomData;
 
+/// Weight functions needed for pallet_fungible.
 pub trait WeightInfo {
 	fn create_item() -> Weight;
 	fn burn_item() -> Weight;
@@ -13,19 +38,79 @@
 	fn transfer_from() -> Weight;
 }
 
+/// Weights for pallet_fungible using the Substrate node and recommended hardware.
 pub struct SubstrateWeight<T>(PhantomData<T>);
 impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> {
-    fn create_item() -> Weight {0}
-	fn burn_item() -> Weight {0}
-	fn transfer() -> Weight {0}
-	fn approve() -> Weight {0}
-	fn transfer_from() -> Weight {0}
+	// Storage: Fungible Balance (r:1 w:1)
+	// Storage: Fungible TotalSupply (r:0 w:1)
+	fn create_item() -> Weight {
+		(12_069_000 as Weight)
+			.saturating_add(T::DbWeight::get().reads(1 as Weight))
+			.saturating_add(T::DbWeight::get().writes(2 as Weight))
+	}
+	// Storage: Fungible TotalSupply (r:1 w:1)
+	// Storage: Fungible Balance (r:1 w:1)
+	fn burn_item() -> Weight {
+		(14_096_000 as Weight)
+			.saturating_add(T::DbWeight::get().reads(2 as Weight))
+			.saturating_add(T::DbWeight::get().writes(2 as Weight))
+	}
+	// Storage: Fungible Balance (r:2 w:2)
+	fn transfer() -> Weight {
+		(15_436_000 as Weight)
+			.saturating_add(T::DbWeight::get().reads(2 as Weight))
+			.saturating_add(T::DbWeight::get().writes(2 as Weight))
+	}
+	// Storage: Fungible Balance (r:1 w:0)
+	// Storage: Fungible Allowance (r:0 w:1)
+	fn approve() -> Weight {
+		(12_867_000 as Weight)
+			.saturating_add(T::DbWeight::get().reads(1 as Weight))
+			.saturating_add(T::DbWeight::get().writes(1 as Weight))
+	}
+	// Storage: Fungible Allowance (r:1 w:1)
+	// Storage: Fungible Balance (r:2 w:2)
+	fn transfer_from() -> Weight {
+		(21_462_000 as Weight)
+			.saturating_add(T::DbWeight::get().reads(3 as Weight))
+			.saturating_add(T::DbWeight::get().writes(3 as Weight))
+	}
 }
 
+// For backwards compatibility and tests
 impl WeightInfo for () {
-    fn create_item() -> Weight {0}
-	fn burn_item() -> Weight {0}
-	fn transfer() -> Weight {0}
-	fn approve() -> Weight {0}
-	fn transfer_from() -> Weight {0}
+	// Storage: Fungible Balance (r:1 w:1)
+	// Storage: Fungible TotalSupply (r:0 w:1)
+	fn create_item() -> Weight {
+		(12_069_000 as Weight)
+			.saturating_add(RocksDbWeight::get().reads(1 as Weight))
+			.saturating_add(RocksDbWeight::get().writes(2 as Weight))
+	}
+	// Storage: Fungible TotalSupply (r:1 w:1)
+	// Storage: Fungible Balance (r:1 w:1)
+	fn burn_item() -> Weight {
+		(14_096_000 as Weight)
+			.saturating_add(RocksDbWeight::get().reads(2 as Weight))
+			.saturating_add(RocksDbWeight::get().writes(2 as Weight))
+	}
+	// Storage: Fungible Balance (r:2 w:2)
+	fn transfer() -> Weight {
+		(15_436_000 as Weight)
+			.saturating_add(RocksDbWeight::get().reads(2 as Weight))
+			.saturating_add(RocksDbWeight::get().writes(2 as Weight))
+	}
+	// Storage: Fungible Balance (r:1 w:0)
+	// Storage: Fungible Allowance (r:0 w:1)
+	fn approve() -> Weight {
+		(12_867_000 as Weight)
+			.saturating_add(RocksDbWeight::get().reads(1 as Weight))
+			.saturating_add(RocksDbWeight::get().writes(1 as Weight))
+	}
+	// Storage: Fungible Allowance (r:1 w:1)
+	// Storage: Fungible Balance (r:2 w:2)
+	fn transfer_from() -> Weight {
+		(21_462_000 as Weight)
+			.saturating_add(RocksDbWeight::get().reads(3 as Weight))
+			.saturating_add(RocksDbWeight::get().writes(3 as Weight))
+	}
 }