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.rsdiffbeforeafterboth1use super::*;2use crate::{Pallet, Config, FungibleHandle};34use sp_std::prelude::*;5use pallet_common::benchmarking::create_collection_raw;6use frame_benchmarking::{benchmarks, account};7use nft_data_structs::{CollectionMode};8use pallet_common::bench_init;910const SEED: u32 = 1;1112fn create_collection<T: Config>(owner: T::AccountId) -> Result<FungibleHandle<T>, DispatchError> {13 create_collection_raw(14 owner,15 CollectionMode::Fungible(0),16 <Pallet<T>>::init_collection,17 FungibleHandle::cast,18 )19}201#![cfg(feature = "runtime-benchmarking")]21benchmarks! {22 create_item {23 bench_init!{24 owner: sub; collection: collection(owner);25 sender: cross_from_sub(owner); to: cross_sub;26 };27 }: {<Pallet<T>>::create_item(&collection, &sender, (to, 200))?}2829 burn_item {30 bench_init!{31 owner: sub; collection: collection(owner);32 owner: cross_from_sub; burner: cross_sub;33 };34 <Pallet<T>>::create_item(&collection, &owner, (burner.clone(), 200))?;35 }: {<Pallet<T>>::burn(&collection, &burner, 100)?}3637 transfer {38 bench_init!{39 owner: sub; collection: collection(owner);40 owner: cross_from_sub; sender: cross_sub; to: cross_sub;41 };42 <Pallet<T>>::create_item(&collection, &owner, (sender.clone(), 200))?;43 }: {<Pallet<T>>::transfer(&collection, &sender, &to, 200)?}4445 approve {46 bench_init!{47 owner: sub; collection: collection(owner);48 owner: cross_from_sub; sender: cross_sub; spender: cross_sub;49 };50 <Pallet<T>>::create_item(&collection, &owner, (sender.clone(), 200))?;51 }: {<Pallet<T>>::set_allowance(&collection, &sender, &spender, 100)?}5253 transfer_from {54 bench_init!{55 owner: sub; collection: collection(owner);56 owner: cross_from_sub; sender: cross_sub; spender: cross_sub; receiver: cross_sub;57 };58 <Pallet<T>>::create_item(&collection, &owner, (sender.clone(), 200))?;59 <Pallet<T>>::set_allowance(&collection, &sender, &spender, 200)?;60 }: {<Pallet<T>>::transfer_from(&collection, &spender, &sender, &receiver, 100)?}61}262pallets/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(),
)
}
pallets/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))
+ }
}