Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion frame/identity/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -548,7 +548,7 @@ mod weight_for {
subs: impl Into<Weight> + Copy,
extra_fields: impl Into<Weight>
) -> Weight {
db.reads_writes(3, subs.into() + 3) // 2 `take`s + S deletions
db.reads_writes(2, subs.into() + 2) // 2 `take`s + S deletions
+ db.reads_writes(1, 1) // balance ops
+ 170_000_000 // constant
+ 1_200_000 * judgements.into() // R
Expand Down
22 changes: 18 additions & 4 deletions frame/timestamp/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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: 27.36 (median slopes 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) + 28_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);
Expand All @@ -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`
19_000_000
}

/// # <weight>
/// - `O(1)`
/// - 1 storage deletion (codec `O(1)`).
/// - Benchmark: 18.7 µs (min squares analysis)
/// # </weight>
fn on_finalize() {
assert!(<Self as Store>::DidUpdate::take(), "Timestamp must be updated once in the block");
Expand Down