Timestamp weights (#5775)

* calculate weight for timestamp::set

* reduce db count in kill_identity weight calculation

* return weight of on_finalize in on_initialize

* add comment

* import Weight

* address review comments to update db weight count

* fix full block import test

* update weights and benchmark info to latest benchmark data

* update identity pallet weights and benchmark info

Co-authored-by: Shawn Tabrizi <shawntabrizi@gmail.com>
This commit is contained in:
Alexander Popiak
2020-04-30 13:43:58 +02:00
committed by GitHub
parent a9261cf0ef
commit 71d7dc1dfc
3 changed files with 71 additions and 66 deletions
+18 -4
View File
@@ -100,7 +100,7 @@ use frame_support::debug;
use frame_support::{
Parameter, decl_storage, decl_module,
traits::{Time, UnixTime, Get},
weights::{DispatchClass},
weights::{DispatchClass, Weight},
};
use sp_runtime::{
RuntimeString,
@@ -150,15 +150,22 @@ decl_module! {
///
/// # <weight>
/// - `O(T)` where `T` complexity of `on_timestamp_set`
/// - 2 storage mutations (codec `O(1)`).
/// - 1 storage read and 1 storage mutation (codec `O(1)`). (because of `DidUpdate::take` in `on_finalize`)
/// - 1 event handler `on_timestamp_set` `O(T)`.
/// - Benchmark: 8.523 (min squares analysis)
/// - NOTE: This benchmark was done for a runtime with insignificant `on_timestamp_set` handlers.
/// New benchmarking is needed when adding new handlers.
/// # </weight>
#[weight = (0, DispatchClass::Mandatory)]
#[weight = (
T::DbWeight::get().reads_writes(2, 1) + 9_000_000,
DispatchClass::Mandatory
)]
fn set(origin, #[compact] now: T::Moment) {
ensure_none(origin)?;
assert!(!<Self as Store>::DidUpdate::exists(), "Timestamp must be updated only once in the block");
let prev = Self::now();
assert!(
Self::now().is_zero() || now >= Self::now() + T::MinimumPeriod::get(),
prev.is_zero() || now >= prev + T::MinimumPeriod::get(),
"Timestamp must increment by at least <MinimumPeriod> between sequential blocks"
);
<Self as Store>::Now::put(now);
@@ -167,9 +174,16 @@ decl_module! {
<T::OnTimestampSet as OnTimestampSet<_>>::on_timestamp_set(now);
}
/// dummy `on_initialize` to return the weight used in `on_finalize`.
fn on_initialize() -> Weight {
// weight of `on_finalize`
6_000_000
}
/// # <weight>
/// - `O(1)`
/// - 1 storage deletion (codec `O(1)`).
/// - Benchmark: 5.105 µs (min squares analysis)
/// # </weight>
fn on_finalize() {
assert!(<Self as Store>::DidUpdate::take(), "Timestamp must be updated once in the block");