difftreelog
feat(fungible) benchmarking
in: master
5 files changed
pallets/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',
+]
pallets/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)?}
+}
pallets/fungible/src/common.rsdiffbeforeafterboth54 match data {54 match data {55 nft_data_structs::CreateItemData::Fungible(data) => with_weight(55 nft_data_structs::CreateItemData::Fungible(data) => with_weight(56 <Pallet<T>>::create_item(self, &sender, (to, data.value)),56 <Pallet<T>>::create_item(self, &sender, (to, data.value)),57 <SelfWeightOf<T>>::create_item(),57 <CommonWeights<T>>::create_item(),58 ),58 ),59 _ => fail!(<Error<T>>::NotFungibleDataUsedToMintFungibleCollectionToken),59 _ => fail!(<Error<T>>::NotFungibleDataUsedToMintFungibleCollectionToken),60 }60 }808081 with_weight(81 with_weight(82 <Pallet<T>>::create_item(self, &sender, (to, sum)),82 <Pallet<T>>::create_item(self, &sender, (to, sum)),83 <SelfWeightOf<T>>::create_item(),83 <CommonWeights<T>>::create_item(),84 )84 )85 }85 }8686979798 with_weight(98 with_weight(99 <Pallet<T>>::burn(self, &sender, amount),99 <Pallet<T>>::burn(self, &sender, amount),100 <SelfWeightOf<T>>::burn_item(),100 <CommonWeights<T>>::burn_item(),101 )101 )102 }102 }103103115115116 with_weight(116 with_weight(117 <Pallet<T>>::transfer(&self, &from, &to, amount),117 <Pallet<T>>::transfer(&self, &from, &to, amount),118 <SelfWeightOf<T>>::transfer(),118 <CommonWeights<T>>::transfer(),119 )119 )120 }120 }121121133133134 with_weight(134 with_weight(135 <Pallet<T>>::set_allowance(&self, &sender, &spender, amount),135 <Pallet<T>>::set_allowance(&self, &sender, &spender, amount),136 <SelfWeightOf<T>>::approve(),136 <CommonWeights<T>>::approve(),137 )137 )138 }138 }139139152152153 with_weight(153 with_weight(154 <Pallet<T>>::transfer_from(&self, &sender, &from, &to, amount),154 <Pallet<T>>::transfer_from(&self, &sender, &from, &to, amount),155 <SelfWeightOf<T>>::transfer_from(),155 <CommonWeights<T>>::transfer_from(),156 )156 )157 }157 }158158pallets/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;
pallets/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))
+ }
}