difftreelog
feat add benchmarks for burn_from
in: master
12 files changed
pallets/common/src/benchmarking.rsdiffbeforeafterboth--- a/pallets/common/src/benchmarking.rs
+++ b/pallets/common/src/benchmarking.rs
@@ -54,7 +54,6 @@
variable_on_chain_schema,
const_on_chain_schema,
meta_update_permission: Default::default(),
- transfers_enabled: true,
})
.and_then(CollectionHandle::try_get)
.map(cast)
pallets/fungible/src/benchmarking.rsdiffbeforeafterboth--- a/pallets/fungible/src/benchmarking.rs
+++ b/pallets/fungible/src/benchmarking.rs
@@ -58,4 +58,13 @@
<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)?}
+
+ burn_from {
+ bench_init!{
+ owner: sub; collection: collection(owner);
+ owner: cross_from_sub; sender: cross_sub; burner: cross_sub;
+ };
+ <Pallet<T>>::create_item(&collection, &owner, (sender.clone(), 200))?;
+ <Pallet<T>>::set_allowance(&collection, &sender, &burner, 200)?;
+ }: {<Pallet<T>>::burn_from(&collection, &burner, &sender, 100)?}
}
pallets/fungible/src/common.rsdiffbeforeafterboth--- a/pallets/fungible/src/common.rs
+++ b/pallets/fungible/src/common.rs
@@ -37,7 +37,7 @@
}
fn burn_from() -> Weight {
- 0
+ <SelfWeightOf<T>>::burn_from()
}
fn set_variable_metadata(_bytes: u32) -> Weight {
pallets/fungible/src/weights.rsdiffbeforeafterboth--- a/pallets/fungible/src/weights.rs
+++ b/pallets/fungible/src/weights.rs
@@ -75,6 +75,14 @@
.saturating_add(T::DbWeight::get().reads(3 as Weight))
.saturating_add(T::DbWeight::get().writes(3 as Weight))
}
+ // Storage: Fungible Allowance (r:1 w:1)
+ // Storage: Fungible TotalSupply (r:1 w:1)
+ // Storage: Fungible Balance (r:1 w:1)
+ fn burn_from() -> Weight {
+ (55_874_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
@@ -113,4 +121,12 @@
.saturating_add(RocksDbWeight::get().reads(3 as Weight))
.saturating_add(RocksDbWeight::get().writes(3 as Weight))
}
+ // Storage: Fungible Allowance (r:1 w:1)
+ // Storage: Fungible TotalSupply (r:1 w:1)
+ // Storage: Fungible Balance (r:1 w:1)
+ fn burn_from() -> Weight {
+ (55_874_000 as Weight)
+ .saturating_add(RocksDbWeight::get().reads(3 as Weight))
+ .saturating_add(RocksDbWeight::get().writes(3 as Weight))
+ }
}
pallets/nonfungible/src/benchmarking.rsdiffbeforeafterboth--- a/pallets/nonfungible/src/benchmarking.rs
+++ b/pallets/nonfungible/src/benchmarking.rs
@@ -89,6 +89,15 @@
<Pallet<T>>::set_allowance(&collection, &sender, item, Some(&spender))?;
}: {<Pallet<T>>::transfer_from(&collection, &spender, &sender, &receiver, item)?}
+ burn_from {
+ bench_init!{
+ owner: sub; collection: collection(owner);
+ owner: cross_from_sub; sender: cross_sub; burner: cross_sub;
+ };
+ let item = create_max_item(&collection, &owner, sender.clone())?;
+ <Pallet<T>>::set_allowance(&collection, &sender, item, Some(&burner))?;
+ }: {<Pallet<T>>::burn_from(&collection, &burner, &sender, item)?}
+
set_variable_metadata {
let b in 0..CUSTOM_DATA_LIMIT;
bench_init!{
pallets/nonfungible/src/common.rsdiffbeforeafterboth--- a/pallets/nonfungible/src/common.rs
+++ b/pallets/nonfungible/src/common.rs
@@ -38,7 +38,7 @@
}
fn burn_from() -> Weight {
- 0
+ <SelfWeightOf<T>>::burn_from()
}
fn set_variable_metadata(bytes: u32) -> Weight {
pallets/nonfungible/src/weights.rsdiffbeforeafterboth--- a/pallets/nonfungible/src/weights.rs
+++ b/pallets/nonfungible/src/weights.rs
@@ -98,6 +98,15 @@
.saturating_add(T::DbWeight::get().reads(4 as Weight))
.saturating_add(T::DbWeight::get().writes(6 as Weight))
}
+ // Storage: Nonfungible Allowance (r:1 w:1)
+ // Storage: Nonfungible TokenData (r:1 w:1)
+ // Storage: Nonfungible TokensBurnt (r:1 w:1)
+ // Storage: Nonfungible Owned (r:0 w:1)
+ fn burn_from() -> Weight {
+ (53_429_000 as Weight)
+ .saturating_add(T::DbWeight::get().reads(3 as Weight))
+ .saturating_add(T::DbWeight::get().writes(4 as Weight))
+ }
// Storage: Nonfungible TokenData (r:1 w:1)
fn set_variable_metadata(_b: u32, ) -> Weight {
(6_380_000 as Weight)
@@ -163,6 +172,15 @@
.saturating_add(RocksDbWeight::get().reads(4 as Weight))
.saturating_add(RocksDbWeight::get().writes(6 as Weight))
}
+ // Storage: Nonfungible Allowance (r:1 w:1)
+ // Storage: Nonfungible TokenData (r:1 w:1)
+ // Storage: Nonfungible TokensBurnt (r:1 w:1)
+ // Storage: Nonfungible Owned (r:0 w:1)
+ fn burn_from() -> Weight {
+ (53_429_000 as Weight)
+ .saturating_add(RocksDbWeight::get().reads(3 as Weight))
+ .saturating_add(RocksDbWeight::get().writes(4 as Weight))
+ }
// Storage: Nonfungible TokenData (r:1 w:1)
fn set_variable_metadata(_b: u32, ) -> Weight {
(6_380_000 as Weight)
pallets/refungible/src/benchmarking.rsdiffbeforeafterboth--- a/pallets/refungible/src/benchmarking.rs
+++ b/pallets/refungible/src/benchmarking.rs
@@ -149,6 +149,16 @@
<Pallet<T>>::set_allowance(&collection, &sender, &spender, item, 200)?;
}: {<Pallet<T>>::transfer_from(&collection, &spender, &sender, &receiver, item, 200)?}
+ // Both source account and token is destroyed
+ burn_from {
+ bench_init!{
+ owner: sub; collection: collection(owner);
+ owner: cross_from_sub; sender: cross_sub; burner: cross_sub;
+ };
+ let item = create_max_item(&collection, &owner, [(sender.clone(), 200)])?;
+ <Pallet<T>>::set_allowance(&collection, &sender, &burner, item, 200)?;
+ }: {<Pallet<T>>::burn_from(&collection, &burner, &sender, item, 200)?}
+
set_variable_metadata {
let b in 0..CUSTOM_DATA_LIMIT;
bench_init!{
pallets/refungible/src/weights.rsdiffbeforeafterboth--- a/pallets/refungible/src/weights.rs
+++ b/pallets/refungible/src/weights.rs
@@ -166,6 +166,18 @@
.saturating_add(T::DbWeight::get().reads(5 as Weight))
.saturating_add(T::DbWeight::get().writes(7 as Weight))
}
+ // Storage: Refungible Allowance (r:1 w:1)
+ // Storage: Refungible TotalSupply (r:1 w:1)
+ // Storage: Refungible Balance (r:1 w:1)
+ // Storage: Refungible AccountBalance (r:1 w:1)
+ // Storage: Refungible TokensBurnt (r:1 w:1)
+ // Storage: Refungible TokenData (r:0 w:1)
+ // Storage: Refungible Owned (r:0 w:1)
+ fn burn_from() -> Weight {
+ (60_903_000 as Weight)
+ .saturating_add(T::DbWeight::get().reads(5 as Weight))
+ .saturating_add(T::DbWeight::get().writes(7 as Weight))
+ }
// Storage: Refungible TokenData (r:1 w:1)
fn set_variable_metadata(_b: u32, ) -> Weight {
(6_801_000 as Weight)
@@ -292,6 +304,18 @@
.saturating_add(RocksDbWeight::get().reads(5 as Weight))
.saturating_add(RocksDbWeight::get().writes(7 as Weight))
}
+ // Storage: Refungible Allowance (r:1 w:1)
+ // Storage: Refungible TotalSupply (r:1 w:1)
+ // Storage: Refungible Balance (r:1 w:1)
+ // Storage: Refungible AccountBalance (r:1 w:1)
+ // Storage: Refungible TokensBurnt (r:1 w:1)
+ // Storage: Refungible TokenData (r:0 w:1)
+ // Storage: Refungible Owned (r:0 w:1)
+ fn burn_from() -> Weight {
+ (60_903_000 as Weight)
+ .saturating_add(RocksDbWeight::get().reads(5 as Weight))
+ .saturating_add(RocksDbWeight::get().writes(7 as Weight))
+ }
// Storage: Refungible TokenData (r:1 w:1)
fn set_variable_metadata(_b: u32, ) -> Weight {
(6_801_000 as Weight)
pallets/scheduler/src/benchmarking.rsdiffbeforeafterboth1// This file is part of Substrate.23// Copyright (C) 2020-2021 Parity Technologies (UK) Ltd.4// SPDX-License-Identifier: Apache-2.056// Licensed under the Apache License, Version 2.0 (the "License");7// you may not use this file except in compliance with the License.8// You may obtain a copy of the License at9//10// http://www.apache.org/licenses/LICENSE-2.011//12// Unless required by applicable law or agreed to in writing, software13// distributed under the License is distributed on an "AS IS" BASIS,14// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.15// See the License for the specific language governing permissions and16// limitations under the License.1718//! Scheduler pallet benchmarking.1920#![cfg(feature = "runtime-benchmarks")]2122use super::*;23use sp_std::{vec, prelude::*};24use frame_system::RawOrigin;25use frame_support::{ensure, traits::OnInitialize};26use frame_benchmarking::{benchmarks, impl_benchmark_test_suite};2728use crate::Module as Scheduler;29use frame_system::Pallet as System;3031const BLOCK_NUMBER: u32 = 2;3233// Add `n` named items to the schedule34fn fill_schedule<T: Config>(when: T::BlockNumber, n: u32) -> Result<(), &'static str> {35 // Essentially a no-op call.36 let call = frame_system::Call::set_storage(vec![]);37 for i in 0..n {38 // Named schedule is strictly heavier than anonymous39 Scheduler::<T>::do_schedule_named(40 i.encode(),41 DispatchTime::At(when),42 // Add periodicity43 Some((T::BlockNumber::one(), 100)),44 // HARD_DEADLINE priority means it gets executed no matter what45 0,46 frame_system::RawOrigin::Root.into(),47 call.clone().into(),48 )?;49 }50 ensure!(51 Agenda::<T>::get(when).len() == n as usize,52 "didn't fill schedule"53 );54 Ok(())55}5657benchmarks! {58 schedule {59 let s in 0 .. T::MaxScheduledPerBlock::get();60 let when = BLOCK_NUMBER.into();61 let periodic = Some((T::BlockNumber::one(), 100));62 let priority = 0;63 // Essentially a no-op call.64 let call = Box::new(frame_system::Call::set_storage(vec![]).into());6566 fill_schedule::<T>(when, s)?;67 }: _(RawOrigin::Root, when, periodic, priority, call)68 verify {69 ensure!(70 Agenda::<T>::get(when).len() == (s + 1) as usize,71 "didn't add to schedule"72 );73 }7475 cancel {76 let s in 1 .. T::MaxScheduledPerBlock::get();77 let when = BLOCK_NUMBER.into();7879 fill_schedule::<T>(when, s)?;80 assert_eq!(Agenda::<T>::get(when).len(), s as usize);81 }: _(RawOrigin::Root, when, 0)82 verify {83 ensure!(84 Lookup::<T>::get(0.encode()).is_none(),85 "didn't remove from lookup"86 );87 // Removed schedule is NONE88 ensure!(89 Agenda::<T>::get(when)[0].is_none(),90 "didn't remove from schedule"91 );92 }9394 schedule_named {95 let s in 0 .. T::MaxScheduledPerBlock::get();96 let id = s.encode();97 let when = BLOCK_NUMBER.into();98 let periodic = Some((T::BlockNumber::one(), 100));99 let priority = 0;100 // Essentially a no-op call.101 let call = Box::new(frame_system::Call::set_storage(vec![]).into());102103 fill_schedule::<T>(when, s)?;104 }: _(RawOrigin::Root, id, when, periodic, priority, call)105 verify {106 ensure!(107 Agenda::<T>::get(when).len() == (s + 1) as usize,108 "didn't add to schedule"109 );110 }111112 cancel_named {113 let s in 1 .. T::MaxScheduledPerBlock::get();114 let when = BLOCK_NUMBER.into();115116 fill_schedule::<T>(when, s)?;117 }: _(RawOrigin::Root, 0.encode())118 verify {119 ensure!(120 Lookup::<T>::get(0.encode()).is_none(),121 "didn't remove from lookup"122 );123 // Removed schedule is NONE124 ensure!(125 Agenda::<T>::get(when)[0].is_none(),126 "didn't remove from schedule"127 );128 }129130 // TODO [#7141]: Make this more complex and flexible so it can be used in automation.131 #[extra]132 on_initialize {133 let s in 0 .. T::MaxScheduledPerBlock::get();134 let when = BLOCK_NUMBER.into();135 fill_schedule::<T>(when, s)?;136 }: { Scheduler::<T>::on_initialize(BLOCK_NUMBER.into()); }137 verify {138 assert_eq!(System::<T>::event_count(), s);139 // Next block should have all the schedules again140 ensure!(141 Agenda::<T>::get(when + T::BlockNumber::one()).len() == s as usize,142 "didn't append schedule"143 );144 }145}146147impl_benchmark_test_suite!(Scheduler, crate::tests::new_test_ext(), crate::tests::Test,);1// This file is part of Substrate.23// Copyright (C) 2020-2021 Parity Technologies (UK) Ltd.4// SPDX-License-Identifier: Apache-2.056// Licensed under the Apache License, Version 2.0 (the "License");7// you may not use this file except in compliance with the License.8// You may obtain a copy of the License at9//10// http://www.apache.org/licenses/LICENSE-2.011//12// Unless required by applicable law or agreed to in writing, software13// distributed under the License is distributed on an "AS IS" BASIS,14// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.15// See the License for the specific language governing permissions and16// limitations under the License.1718//! Scheduler pallet benchmarking.1920#![cfg(feature = "runtime-benchmarks")]2122use super::*;23use sp_std::{vec, prelude::*};24use frame_system::RawOrigin;25use frame_support::{ensure, traits::OnInitialize};26use frame_benchmarking::{benchmarks, impl_benchmark_test_suite};2728use crate::Module as Scheduler;29use frame_system::Pallet as System;3031const BLOCK_NUMBER: u32 = 2;3233// Add `n` named items to the schedule34fn fill_schedule<T: Config>(when: T::BlockNumber, n: u32) -> Result<(), &'static str> {35 // Essentially a no-op call.36 let call = frame_system::Call::set_storage { items: vec![] };37 for i in 0..n {38 // Named schedule is strictly heavier than anonymous39 Scheduler::<T>::do_schedule_named(40 i.encode(),41 DispatchTime::At(when),42 // Add periodicity43 Some((T::BlockNumber::one(), 100)),44 // HARD_DEADLINE priority means it gets executed no matter what45 0,46 frame_system::RawOrigin::Root.into(),47 call.clone().into(),48 )?;49 }50 ensure!(51 Agenda::<T>::get(when).len() == n as usize,52 "didn't fill schedule"53 );54 Ok(())55}5657benchmarks! {58 schedule {59 let s in 0 .. T::MaxScheduledPerBlock::get();60 let when = BLOCK_NUMBER.into();61 let periodic = Some((T::BlockNumber::one(), 100));62 let priority = 0;63 // Essentially a no-op call.64 let call = Box::new(frame_system::Call::set_storage { items: vec![] }.into());6566 fill_schedule::<T>(when, s)?;67 }: _(RawOrigin::Root, when, periodic, priority, call)68 verify {69 ensure!(70 Agenda::<T>::get(when).len() == (s + 1) as usize,71 "didn't add to schedule"72 );73 }7475 cancel {76 let s in 1 .. T::MaxScheduledPerBlock::get();77 let when = BLOCK_NUMBER.into();7879 fill_schedule::<T>(when, s)?;80 assert_eq!(Agenda::<T>::get(when).len(), s as usize);81 }: _(RawOrigin::Root, when, 0)82 verify {83 ensure!(84 Lookup::<T>::get(0.encode()).is_none(),85 "didn't remove from lookup"86 );87 // Removed schedule is NONE88 ensure!(89 Agenda::<T>::get(when)[0].is_none(),90 "didn't remove from schedule"91 );92 }9394 schedule_named {95 let s in 0 .. T::MaxScheduledPerBlock::get();96 let id = s.encode();97 let when = BLOCK_NUMBER.into();98 let periodic = Some((T::BlockNumber::one(), 100));99 let priority = 0;100 // Essentially a no-op call.101 let call = Box::new(frame_system::Call::set_storage { items: vec![] }.into());102103 fill_schedule::<T>(when, s)?;104 }: _(RawOrigin::Root, id, when, periodic, priority, call)105 verify {106 ensure!(107 Agenda::<T>::get(when).len() == (s + 1) as usize,108 "didn't add to schedule"109 );110 }111112 cancel_named {113 let s in 1 .. T::MaxScheduledPerBlock::get();114 let when = BLOCK_NUMBER.into();115116 fill_schedule::<T>(when, s)?;117 }: _(RawOrigin::Root, 0.encode())118 verify {119 ensure!(120 Lookup::<T>::get(0.encode()).is_none(),121 "didn't remove from lookup"122 );123 // Removed schedule is NONE124 ensure!(125 Agenda::<T>::get(when)[0].is_none(),126 "didn't remove from schedule"127 );128 }129130 // TODO [#7141]: Make this more complex and flexible so it can be used in automation.131 #[extra]132 on_initialize {133 let s in 0 .. T::MaxScheduledPerBlock::get();134 let when = BLOCK_NUMBER.into();135 fill_schedule::<T>(when, s)?;136 }: { Scheduler::<T>::on_initialize(BLOCK_NUMBER.into()); }137 verify {138 assert_eq!(System::<T>::event_count(), s);139 // Next block should have all the schedules again140 ensure!(141 Agenda::<T>::get(when + T::BlockNumber::one()).len() == s as usize,142 "didn't append schedule"143 );144 }145}146147impl_benchmark_test_suite!(Scheduler, crate::tests::new_test_ext(), crate::tests::Test,);runtime/Cargo.tomldiffbeforeafterboth--- a/runtime/Cargo.toml
+++ b/runtime/Cargo.toml
@@ -23,7 +23,9 @@
'frame-support/runtime-benchmarks',
'frame-system-benchmarking',
'frame-system/runtime-benchmarks',
+ 'pallet-ethereum/runtime-benchmarks',
'pallet-evm-migration/runtime-benchmarks',
+ 'pallet-evm-coder-substrate/runtime-benchmarks',
'pallet-balances/runtime-benchmarks',
'pallet-timestamp/runtime-benchmarks',
'pallet-common/runtime-benchmarks',
runtime/src/lib.rsdiffbeforeafterboth--- a/runtime/src/lib.rs
+++ b/runtime/src/lib.rs
@@ -1327,6 +1327,7 @@
list_benchmark!(list, extra, pallet_fungible, Fungible);
list_benchmark!(list, extra, pallet_refungible, Refungible);
list_benchmark!(list, extra, pallet_nonfungible, Nonfungible);
+ // list_benchmark!(list, extra, pallet_evm_coder_substrate, EvmCoderSubstrate);
let storage_info = AllPalletsWithSystem::storage_info();
@@ -1360,6 +1361,7 @@
add_benchmark!(params, batches, pallet_fungible, Fungible);
add_benchmark!(params, batches, pallet_refungible, Refungible);
add_benchmark!(params, batches, pallet_nonfungible, Nonfungible);
+ // add_benchmark!(params, batches, pallet_evm_coder_substrate, EvmCoderSubstrate);
if batches.is_empty() { return Err("Benchmark not found for this pallet.".into()) }
Ok(batches)