difftreelog
Scheduler benchmarks fixed. Useless code in pallet was removed.
in: master
4 files changed
Makefilediffbeforeafterboth--- a/Makefile
+++ b/Makefile
@@ -93,5 +93,9 @@
bench-structure:
make _bench PALLET=structure
+.PHONY: bench-scheduler
+bench-scheduler:
+ make _bench PALLET=unq-scheduler
+
.PHONY: bench
-bench: bench-evm-migration bench-unique bench-structure bench-fungible bench-refungible bench-nonfungible
+bench: bench-evm-migration bench-unique bench-structure bench-fungible bench-refungible bench-nonfungible bench-scheduler
pallets/fungible/src/weights.rsdiffbeforeafterboth--- a/pallets/fungible/src/weights.rs
+++ b/pallets/fungible/src/weights.rs
@@ -3,12 +3,13 @@
//! Autogenerated weights for pallet_fungible
//!
//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev
-//! DATE: 2022-03-01, STEPS: `50`, REPEAT: 200, LOW RANGE: `[]`, HIGH RANGE: `[]`
+//! DATE: 2022-06-09, STEPS: `50`, REPEAT: 200, LOW RANGE: `[]`, HIGH RANGE: `[]`
//! EXECUTION: None, WASM-EXECUTION: Compiled, CHAIN: None, DB CACHE: 1024
// Executed Command:
// target/release/unique-collator
// benchmark
+// pallet
// --pallet
// pallet-fungible
// --wasm-execution
@@ -47,16 +48,16 @@
// Storage: Fungible TotalSupply (r:1 w:1)
// Storage: Fungible Balance (r:1 w:1)
fn create_item() -> Weight {
- (14_407_000 as Weight)
+ (40_678_000 as Weight)
.saturating_add(T::DbWeight::get().reads(2 as Weight))
.saturating_add(T::DbWeight::get().writes(2 as Weight))
}
// Storage: Fungible TotalSupply (r:1 w:1)
// Storage: Fungible Balance (r:4 w:4)
fn create_multiple_items_ex(b: u32, ) -> Weight {
- (13_030_000 as Weight)
- // Standard Error: 1_000
- .saturating_add((3_779_000 as Weight).saturating_mul(b as Weight))
+ (13_036_000 as Weight)
+ // Standard Error: 9_000
+ .saturating_add((15_611_000 as Weight).saturating_mul(b as Weight))
.saturating_add(T::DbWeight::get().reads(1 as Weight))
.saturating_add(T::DbWeight::get().reads((1 as Weight).saturating_mul(b as Weight)))
.saturating_add(T::DbWeight::get().writes(1 as Weight))
@@ -65,28 +66,27 @@
// Storage: Fungible TotalSupply (r:1 w:1)
// Storage: Fungible Balance (r:1 w:1)
fn burn_item() -> Weight {
- (15_565_000 as Weight)
+ (42_340_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 {
- (17_713_000 as Weight)
+ (47_321_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 {
- (14_834_000 as Weight)
+ (38_385_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 {
- (25_189_000 as Weight)
+ (69_001_000 as Weight)
.saturating_add(T::DbWeight::get().reads(3 as Weight))
.saturating_add(T::DbWeight::get().writes(3 as Weight))
}
@@ -94,7 +94,7 @@
// Storage: Fungible TotalSupply (r:1 w:1)
// Storage: Fungible Balance (r:1 w:1)
fn burn_from() -> Weight {
- (24_065_000 as Weight)
+ (63_996_000 as Weight)
.saturating_add(T::DbWeight::get().reads(3 as Weight))
.saturating_add(T::DbWeight::get().writes(3 as Weight))
}
@@ -105,16 +105,16 @@
// Storage: Fungible TotalSupply (r:1 w:1)
// Storage: Fungible Balance (r:1 w:1)
fn create_item() -> Weight {
- (14_407_000 as Weight)
+ (40_678_000 as Weight)
.saturating_add(RocksDbWeight::get().reads(2 as Weight))
.saturating_add(RocksDbWeight::get().writes(2 as Weight))
}
// Storage: Fungible TotalSupply (r:1 w:1)
// Storage: Fungible Balance (r:4 w:4)
fn create_multiple_items_ex(b: u32, ) -> Weight {
- (13_030_000 as Weight)
- // Standard Error: 1_000
- .saturating_add((3_779_000 as Weight).saturating_mul(b as Weight))
+ (13_036_000 as Weight)
+ // Standard Error: 9_000
+ .saturating_add((15_611_000 as Weight).saturating_mul(b as Weight))
.saturating_add(RocksDbWeight::get().reads(1 as Weight))
.saturating_add(RocksDbWeight::get().reads((1 as Weight).saturating_mul(b as Weight)))
.saturating_add(RocksDbWeight::get().writes(1 as Weight))
@@ -123,28 +123,27 @@
// Storage: Fungible TotalSupply (r:1 w:1)
// Storage: Fungible Balance (r:1 w:1)
fn burn_item() -> Weight {
- (15_565_000 as Weight)
+ (42_340_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 {
- (17_713_000 as Weight)
+ (47_321_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 {
- (14_834_000 as Weight)
+ (38_385_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 {
- (25_189_000 as Weight)
+ (69_001_000 as Weight)
.saturating_add(RocksDbWeight::get().reads(3 as Weight))
.saturating_add(RocksDbWeight::get().writes(3 as Weight))
}
@@ -152,7 +151,7 @@
// Storage: Fungible TotalSupply (r:1 w:1)
// Storage: Fungible Balance (r:1 w:1)
fn burn_from() -> Weight {
- (24_065_000 as Weight)
+ (63_996_000 as Weight)
.saturating_add(RocksDbWeight::get().reads(3 as Weight))
.saturating_add(RocksDbWeight::get().writes(3 as Weight))
}
pallets/scheduler/src/benchmarking.rsdiffbeforeafterboth1// This file is part of Substrate.23// Copyright (C) 2020-2022 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.1920use super::*;21use frame_benchmarking::benchmarks;22use frame_support::{23 ensure,24 traits::{OnInitialize, PreimageProvider, PreimageRecipient},25};26use frame_system::RawOrigin;27use sp_runtime::traits::Hash;28use sp_std::{prelude::*, vec};2930use crate::Pallet as Scheduler;31use frame_system::Pallet as System;3233const BLOCK_NUMBER: u32 = 2;3435/// Add `n` named items to the schedule.36///37/// For `resolved`:38/// - `None`: aborted (hash without preimage)39/// - `Some(true)`: hash resolves into call if possible, plain call otherwise40/// - `Some(false)`: plain call41fn fill_schedule<T: Config>(42 when: T::BlockNumber,43 n: u32,44 periodic: bool,45 named: bool,46 resolved: Option<bool>,47) -> Result<(), &'static str> {48 for i in 0..n {49 // Named schedule is strictly heavier than anonymous50 let (call, hash) = call_and_hash::<T>(i);51 let call_or_hash = match resolved {52 Some(true) => {53 T::PreimageProvider::note_preimage(call.encode().try_into().unwrap());54 if T::PreimageProvider::have_preimage(&hash) {55 CallOrHashOf::<T>::Hash(hash)56 } else {57 call.into()58 }59 },60 Some(false) => call.into(),61 None => CallOrHashOf::<T>::Hash(hash),62 };63 let period = match periodic {64 true => Some(((i + 100).into(), 100)),65 false => None,66 };67 let t = DispatchTime::At(when);68 let origin = frame_system::RawOrigin::Root.into();69 if named {70 Scheduler::<T>::do_schedule_named(i.encode().try_into().unwrap_or([0; MAX_TASK_ID_LENGTH_IN_BYTES as usize]),71 t, period, 0, origin, call_or_hash)?;72 } else {73 Scheduler::<T>::do_schedule(t, period, 0, origin, call_or_hash)?;74 }75 }76 ensure!(Agenda::<T>::get(when).len() == n as usize, "didn't fill schedule");77 Ok(())78}7980fn call_and_hash<T: Config>(i: u32) -> (<T as Config>::Call, T::Hash) {81 // Essentially a no-op call.82 let call: <T as Config>::Call = frame_system::Call::remark { remark: i.encode() }.into();83 let hash = T::Hashing::hash_of(&call);84 (call, hash)85}868788benchmarks! {89 on_initialize_periodic_named_resolved {90 let s in 1 .. T::MaxScheduledPerBlock::get();91 let when = BLOCK_NUMBER.into();92 fill_schedule::<T>(when, s, true, true, Some(true))?;93 }: { Scheduler::<T>::on_initialize(BLOCK_NUMBER.into()); }94 verify {95 assert_eq!(System::<T>::event_count(), s * 2);96 for i in 0..s {97 assert_eq!(Agenda::<T>::get(when + (i + 100).into()).len(), 1 as usize);98 }99 }100101 on_initialize_named_resolved {102 let s in 1 .. T::MaxScheduledPerBlock::get();103 let when = BLOCK_NUMBER.into();104 fill_schedule::<T>(when, s, false, true, Some(true))?;105 }: { Scheduler::<T>::on_initialize(BLOCK_NUMBER.into()); }106 verify {107 assert_eq!(System::<T>::event_count(), s * 2);108 assert!(Agenda::<T>::iter().count() == 0);109 }110111 on_initialize_periodic_resolved {112 let s in 1 .. T::MaxScheduledPerBlock::get();113 let when = BLOCK_NUMBER.into();114 fill_schedule::<T>(when, s, true, false, Some(true))?;115 }: { Scheduler::<T>::on_initialize(BLOCK_NUMBER.into()); }116 verify {117 assert_eq!(System::<T>::event_count(), s * 2);118 for i in 0..s {119 assert_eq!(Agenda::<T>::get(when + (i + 100).into()).len(), 1 as usize);120 }121 }122123 on_initialize_resolved {124 let s in 1 .. T::MaxScheduledPerBlock::get();125 let when = BLOCK_NUMBER.into();126 fill_schedule::<T>(when, s, false, false, Some(true))?;127 }: { Scheduler::<T>::on_initialize(BLOCK_NUMBER.into()); }128 verify {129 assert_eq!(System::<T>::event_count(), s * 2);130 assert!(Agenda::<T>::iter().count() == 0);131 }132133 on_initialize_named_aborted {134 let s in 1 .. T::MaxScheduledPerBlock::get();135 let when = BLOCK_NUMBER.into();136 fill_schedule::<T>(when, s, false, true, None)?;137 }: { Scheduler::<T>::on_initialize(BLOCK_NUMBER.into()); }138 verify {139 assert_eq!(System::<T>::event_count(), 0);140 if let Some(delay) = T::NoPreimagePostponement::get() {141 assert_eq!(Agenda::<T>::get(when + delay).len(), s as usize);142 } else {143 assert!(Agenda::<T>::iter().count() == 0);144 }145 }146147 on_initialize_aborted {148 let s in 1 .. T::MaxScheduledPerBlock::get();149 let when = BLOCK_NUMBER.into();150 fill_schedule::<T>(when, s, false, false, None)?;151 }: { Scheduler::<T>::on_initialize(BLOCK_NUMBER.into()); }152 verify {153 assert_eq!(System::<T>::event_count(), 0);154 if let Some(delay) = T::NoPreimagePostponement::get() {155 assert_eq!(Agenda::<T>::get(when + delay).len(), s as usize);156 } else {157 assert!(Agenda::<T>::iter().count() == 0);158 }159 }160161 on_initialize_periodic_named {162 let s in 1 .. T::MaxScheduledPerBlock::get();163 let when = BLOCK_NUMBER.into();164 fill_schedule::<T>(when, s, true, true, Some(false))?;165 }: { Scheduler::<T>::on_initialize(BLOCK_NUMBER.into()); }166 verify {167 assert_eq!(System::<T>::event_count(), s);168 for i in 0..s {169 assert_eq!(Agenda::<T>::get(when + (i + 100).into()).len(), 1 as usize);170 }171 }172173 on_initialize_periodic {174 let s in 1 .. T::MaxScheduledPerBlock::get();175 let when = BLOCK_NUMBER.into();176 fill_schedule::<T>(when, s, true, false, Some(false))?;177 }: { Scheduler::<T>::on_initialize(when); }178 verify {179 assert_eq!(System::<T>::event_count(), s);180 for i in 0..s {181 assert_eq!(Agenda::<T>::get(when + (i + 100).into()).len(), 1 as usize);182 }183 }184185 on_initialize_named {186 let s in 1 .. T::MaxScheduledPerBlock::get();187 let when = BLOCK_NUMBER.into();188 fill_schedule::<T>(when, s, false, true, Some(false))?;189 }: { Scheduler::<T>::on_initialize(BLOCK_NUMBER.into()); }190 verify {191 assert_eq!(System::<T>::event_count(), s);192 assert!(Agenda::<T>::iter().count() == 0);193 }194195 on_initialize {196 let s in 1 .. T::MaxScheduledPerBlock::get();197 let when = BLOCK_NUMBER.into();198 fill_schedule::<T>(when, s, false, false, Some(false))?;199 }: { Scheduler::<T>::on_initialize(BLOCK_NUMBER.into()); }200 verify {201 assert_eq!(System::<T>::event_count(), s);202 assert!(Agenda::<T>::iter().count() == 0);203 }204205 schedule_named {206 let s in 0 .. T::MaxScheduledPerBlock::get();207 let id = s.encode().try_into().unwrap_or([0; MAX_TASK_ID_LENGTH_IN_BYTES as usize]);208 let when = BLOCK_NUMBER.into();209 let periodic = Some((T::BlockNumber::one(), 100));210 let priority = 0;211 // Essentially a no-op call.212 let inner_call = frame_system::Call::set_storage { items: vec![] }.into();213 let call = Box::new(CallOrHashOf::<T>::Value(inner_call));214215 fill_schedule::<T>(when, s, true, true, Some(false))?;216 }: _(RawOrigin::Root, id, when, periodic, priority, call)217 verify {218 ensure!(219 Agenda::<T>::get(when).len() == (s + 1) as usize,220 "didn't add to schedule"221 );222 }223224 cancel_named {225 let s in 1 .. T::MaxScheduledPerBlock::get();226 let when = BLOCK_NUMBER.into();227 let id = 0.encode().try_into().unwrap_or([0; MAX_TASK_ID_LENGTH_IN_BYTES as usize]);228229 fill_schedule::<T>(when, s, true, true, Some(false))?;230 }: _(RawOrigin::Root, id)231 verify {232 ensure!(233 Lookup::<T>::get(id).is_none(),234 "didn't remove from lookup"235 );236 // Removed schedule is NONE237 ensure!(238 Agenda::<T>::get(when)[0].is_none(),239 "didn't remove from schedule"240 );241 }242243 impl_benchmark_test_suite!(Scheduler, crate::mock::new_test_ext(), crate::mock::Test);244}pallets/scheduler/src/lib.rsdiffbeforeafterboth--- a/pallets/scheduler/src/lib.rs
+++ b/pallets/scheduler/src/lib.rs
@@ -60,9 +60,8 @@
// Ensure we're `no_std` when compiling for Wasm.
#![cfg_attr(not(feature = "std"), no_std)]
-// FIXME
-// #[cfg(feature = "runtime-benchmarks")]
-// mod benchmarking;
+#[cfg(feature = "runtime-benchmarks")]
+mod benchmarking;
pub mod weights;
@@ -639,66 +638,7 @@
Ok((when, index))
}
-
- fn do_cancel(
- origin: Option<T::PalletsOrigin>,
- (when, index): TaskAddress<T::BlockNumber>,
- ) -> Result<(), DispatchError> {
- let scheduled = Agenda::<T>::try_mutate(when, |agenda| {
- agenda.get_mut(index as usize).map_or(
- Ok(None),
- |s| -> Result<Option<Scheduled<_, _, _, _>>, DispatchError> {
- if let (Some(ref o), Some(ref s)) = (origin, s.borrow()) {
- if matches!(
- T::OriginPrivilegeCmp::cmp_privilege(o, &s.origin),
- Some(Ordering::Less) | None
- ) {
- return Err(BadOrigin.into());
- }
- };
- Ok(s.take())
- },
- )
- })?;
- if let Some(s) = scheduled {
- s.call.ensure_unrequested::<T::PreimageProvider>();
- if let Some(id) = s.maybe_id {
- Lookup::<T>::remove(id);
- }
- Self::deposit_event(Event::Canceled { when, index });
- Ok(())
- } else {
- Err(Error::<T>::NotFound)?
- }
- }
-
- fn do_reschedule(
- (when, index): TaskAddress<T::BlockNumber>,
- new_time: DispatchTime<T::BlockNumber>,
- ) -> Result<TaskAddress<T::BlockNumber>, DispatchError> {
- let new_time = Self::resolve_time(new_time)?;
-
- if new_time == when {
- return Err(Error::<T>::RescheduleNoChange.into());
- }
- Agenda::<T>::try_mutate(when, |agenda| -> DispatchResult {
- let task = agenda.get_mut(index as usize).ok_or(Error::<T>::NotFound)?;
- let task = task.take().ok_or(Error::<T>::NotFound)?;
- Agenda::<T>::append(new_time, Some(task));
- Ok(())
- })?;
-
- let new_index = Agenda::<T>::decode_len(new_time).unwrap_or(1) as u32 - 1;
- Self::deposit_event(Event::Canceled { when, index });
- Self::deposit_event(Event::Scheduled {
- when: new_time,
- index: new_index,
- });
-
- Ok((new_time, new_index))
- }
-
fn do_schedule_named(
id: ScheduledId,
when: DispatchTime<T::BlockNumber>,
@@ -790,124 +730,3 @@
}
})
}
-
- fn do_reschedule_named(
- id: ScheduledId,
- new_time: DispatchTime<T::BlockNumber>,
- ) -> Result<TaskAddress<T::BlockNumber>, DispatchError> {
- let new_time = Self::resolve_time(new_time)?;
-
- Lookup::<T>::try_mutate_exists(
- id,
- |lookup| -> Result<TaskAddress<T::BlockNumber>, DispatchError> {
- let (when, index) = lookup.ok_or(Error::<T>::NotFound)?;
-
- if new_time == when {
- return Err(Error::<T>::RescheduleNoChange.into());
- }
-
- Agenda::<T>::try_mutate(when, |agenda| -> DispatchResult {
- let task = agenda.get_mut(index as usize).ok_or(Error::<T>::NotFound)?;
- let task = task.take().ok_or(Error::<T>::NotFound)?;
- Agenda::<T>::append(new_time, Some(task));
-
- Ok(())
- })?;
-
- let new_index = Agenda::<T>::decode_len(new_time).unwrap_or(1) as u32 - 1;
- Self::deposit_event(Event::Canceled { when, index });
- Self::deposit_event(Event::Scheduled {
- when: new_time,
- index: new_index,
- });
-
- *lookup = Some((new_time, new_index));
-
- Ok((new_time, new_index))
- },
- )
- }
-}
-
-impl<T: Config> schedule::v2::Anon<T::BlockNumber, <T as Config>::Call, T::PalletsOrigin>
- for Pallet<T>
-{
- type Address = TaskAddress<T::BlockNumber>;
- type Hash = T::Hash;
-
- fn schedule(
- when: DispatchTime<T::BlockNumber>,
- maybe_periodic: Option<schedule::Period<T::BlockNumber>>,
- priority: schedule::Priority,
- origin: T::PalletsOrigin,
- call: CallOrHashOf<T>,
- ) -> Result<Self::Address, DispatchError> {
- Self::do_schedule(when, maybe_periodic, priority, origin, call)
- }
-
- fn cancel((when, index): Self::Address) -> Result<(), ()> {
- Self::do_cancel(None, (when, index)).map_err(|_| ())
- }
-
- fn reschedule(
- address: Self::Address,
- when: DispatchTime<T::BlockNumber>,
- ) -> Result<Self::Address, DispatchError> {
- Self::do_reschedule(address, when)
- }
-
- fn next_dispatch_time((when, index): Self::Address) -> Result<T::BlockNumber, ()> {
- Agenda::<T>::get(when)
- .get(index as usize)
- .ok_or(())
- .map(|_| when)
- }
-}
-
-impl<T: Config> schedule::v2::Named<T::BlockNumber, <T as Config>::Call, T::PalletsOrigin>
- for Pallet<T>
-{
- type Address = TaskAddress<T::BlockNumber>;
- type Hash = T::Hash;
-
- fn schedule_named(
- id: Vec<u8>,
- when: DispatchTime<T::BlockNumber>,
- maybe_periodic: Option<schedule::Period<T::BlockNumber>>,
- priority: schedule::Priority,
- origin: T::PalletsOrigin,
- call: CallOrHashOf<T>,
- ) -> Result<Self::Address, ()> {
- let inner_id: ScheduledId = id
- .try_into()
- .unwrap_or([0; MAX_TASK_ID_LENGTH_IN_BYTES as usize]);
- Self::do_schedule_named(inner_id, when, maybe_periodic, priority, origin, call)
- .map_err(|_| ())
- }
-
- fn cancel_named(id: Vec<u8>) -> Result<(), ()> {
- let inner_id: ScheduledId = id
- .try_into()
- .unwrap_or([0; MAX_TASK_ID_LENGTH_IN_BYTES as usize]);
- Self::do_cancel_named(None, inner_id).map_err(|_| ())
- }
-
- fn reschedule_named(
- id: Vec<u8>,
- when: DispatchTime<T::BlockNumber>,
- ) -> Result<Self::Address, DispatchError> {
- let inner_id: ScheduledId = id
- .try_into()
- .unwrap_or([0; MAX_TASK_ID_LENGTH_IN_BYTES as usize]);
- Self::do_reschedule_named(inner_id, when)
- }
-
- fn next_dispatch_time(id: Vec<u8>) -> Result<T::BlockNumber, ()> {
- let inner_id: ScheduledId = id
- .try_into()
- .unwrap_or([0; MAX_TASK_ID_LENGTH_IN_BYTES as usize]);
- Lookup::<T>::get(inner_id)
- .and_then(|(when, index)| Agenda::<T>::get(when).get(index as usize).map(|_| when))
- .ok_or(())
- }
-}