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 all 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
8 changes: 5 additions & 3 deletions bin/node/executor/tests/basic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use codec::{Encode, Decode, Joiner};
use frame_support::{
StorageValue, StorageMap,
traits::Currency,
weights::{GetDispatchInfo, DispatchInfo, DispatchClass, Pays},
weights::{GetDispatchInfo, DispatchInfo, DispatchClass},
};
use sp_core::{
NeverNativeValue, map, traits::Externalities, storage::{well_known_keys, Storage},
Expand Down Expand Up @@ -337,8 +337,9 @@ fn full_native_block_import_works() {
let events = vec![
EventRecord {
phase: Phase::ApplyExtrinsic(0),
// timestamp set call with weight 9_000_000 + 2 read + 1 write
event: Event::frame_system(frame_system::RawEvent::ExtrinsicSuccess(
DispatchInfo { weight: 0, class: DispatchClass::Mandatory, ..Default::default() }
DispatchInfo { weight: 9_000_000 + 2 * 60_000_000 + 1 * 200_000_000, class: DispatchClass::Mandatory, ..Default::default() }
)),
topics: vec![],
},
Expand Down Expand Up @@ -390,8 +391,9 @@ fn full_native_block_import_works() {
let events = vec![
EventRecord {
phase: Phase::ApplyExtrinsic(0),
// timestamp set call with weight 9_000_000 + 2 read + 1 write
event: Event::frame_system(frame_system::RawEvent::ExtrinsicSuccess(
DispatchInfo { weight: 0, class: DispatchClass::Mandatory, pays_fee: Pays::Yes }
DispatchInfo { weight: 9_000_000 + 2 * 60_000_000 + 1 * 200_000_000, class: DispatchClass::Mandatory, ..Default::default() }
)),
topics: vec![],
},
Expand Down
107 changes: 48 additions & 59 deletions frame/identity/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -472,9 +472,9 @@ mod weight_for {
extra_fields: impl Into<Weight>
) -> Weight {
db.reads_writes(1, 1)
+ 150_000_000 // constant
+ 700_000 * judgements.into() // R
+ 3_000_000 * extra_fields.into() // X
+ 61_000_000 // constant
+ 400_000 * judgements.into() // R
+ 1_500_000 * extra_fields.into() // X
}

/// Weight calculation for `set_subs`.
Expand All @@ -486,9 +486,9 @@ mod weight_for {
db.reads(1) // storage-exists (`IdentityOf::contains_key`)
+ db.reads_writes(1, old_subs.into()) // `SubsOf::get` read + P old DB deletions
+ db.writes(subs.into() + 1) // S + 1 new DB writes
+ 130_000_000 // constant
+ 5_200_000 * old_subs.into() // P
+ 7_300_000 * subs.into() // S
+ 41_000_000 // constant
+ 2_600_000 * old_subs.into() // P
+ 3_700_000 * subs.into() // S
}

/// Weight calculation for `clear_identity`.
Expand All @@ -499,10 +499,10 @@ mod weight_for {
extra_fields: impl Into<Weight>
) -> Weight {
db.reads_writes(2, subs.into() + 2) // S + 2 deletions
+ 160_000_000 // constant
+ 500_000 * judgements.into() // R
+ 5_400_000 * subs.into() // S
+ 2_000_000 * extra_fields.into() // X
+ 58_000_000 // constant
+ 20_000 * judgements.into() // R
+ 2_600_000 * subs.into() // S
+ 900_000 * extra_fields.into() // X
}

/// Weight calculation for `request_judgement`.
Expand All @@ -512,9 +512,9 @@ mod weight_for {
extra_fields: impl Into<Weight>
) -> Weight {
db.reads_writes(2, 1)
+ 180_000_000 // constant
+ 950_000 * judgements.into() // R
+ 3_400_000 * extra_fields.into() // X
+ 60_000_000 // constant
+ 510_000 * judgements.into() // R
+ 1_700_000 * extra_fields.into() // X
}

/// Weight calculation for `cancel_request`.
Expand All @@ -524,9 +524,9 @@ mod weight_for {
extra_fields: impl Into<Weight>
) -> Weight {
db.reads_writes(1, 1)
+ 150_000_000 // constant
+ 600_000 * judgements.into() // R
+ 3_600_000 * extra_fields.into() // X
+ 52_000_000 // constant
+ 400_000 * judgements.into() // R
+ 1_700_000 * extra_fields.into() // X
}

/// Weight calculation for `provide_judgement`.
Expand All @@ -536,9 +536,9 @@ mod weight_for {
extra_fields: impl Into<Weight>
) -> Weight {
db.reads_writes(2, 1)
+ 120_000_000 // constant
+ 1_100_000 * judgements.into() // R
+ 3_500_000 * extra_fields.into()// X
+ 49_000_000 // constant
+ 400_000 * judgements.into() // R
+ 1_700_000 * extra_fields.into()// X
}

/// Weight calculation for `kill_identity`.
Expand All @@ -548,12 +548,12 @@ 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
+ 5_400_000 * subs.into() // S
+ 2_300_000 * extra_fields.into() // X
+ 110_000_000 // constant
+ 100_000 * judgements.into() // R
+ 2_600_000 * subs.into() // S
+ 900_000 * extra_fields.into() // X
}
}

Expand Down Expand Up @@ -598,13 +598,11 @@ decl_module! {
/// - `O(R)` where `R` registrar-count (governance-bounded and code-bounded).
/// - One storage mutation (codec `O(R)`).
/// - One event.
/// - Benchmarks:
/// - 78.71 + R * 0.965 µs (min squares analysis)
/// - 94.28 + R * 0.991 µs (min squares analysis)
/// - Benchmark: 24.63 + R * 0.53 µs (min squares analysis)
/// # </weight>
#[weight = T::DbWeight::get().reads_writes(1, 1)
+ 95_000_000 // constant
+ 1_000_000 * T::MaxRegistrars::get() as Weight // R
+ 25_000_000 // constant
+ 550_000 * T::MaxRegistrars::get() as Weight // R
]
fn add_registrar(origin, account: T::AccountId) -> DispatchResultWithPostInfo {
T::RegistrarOrigin::try_origin(origin)
Expand All @@ -620,7 +618,7 @@ decl_module! {
Self::deposit_event(RawEvent::RegistrarAdded(i));

Ok(Some(T::DbWeight::get().reads_writes(1, 1)
+ 95_000_000 + 1_000_000 * registrar_count as Weight).into())
+ 25_000_000 + 550_000 * registrar_count as Weight).into())
}

/// Set an account's identity information and reserve the appropriate deposit.
Expand All @@ -641,9 +639,7 @@ decl_module! {
/// - One balance reserve operation.
/// - One storage mutation (codec-read `O(X' + R)`, codec-write `O(X + R)`).
/// - One event.
/// - Benchmarks:
/// - 136.6 + R * 0.62 + X * 2.62 µs (min squares analysis)
/// - 146.2 + R * 0.372 + X * 2.98 µs (min squares analysis)
/// - Benchmark: 59.44 + R * 0.389 + X * 1.434 µs (min squares analysis)
/// # </weight>
#[weight = weight_for::set_identity(
T::DbWeight::get(),
Expand Down Expand Up @@ -706,9 +702,7 @@ decl_module! {
/// - One storage read (codec complexity `O(P)`).
/// - One storage write (codec complexity `O(S)`).
/// - One storage-exists (`IdentityOf::contains_key`).
/// - Benchmarks:
/// - 115.2 + P * 5.11 + S * 6.67 µs (min squares analysis)
/// - 121 + P * 4.852 + S * 7.111 µs (min squares analysis)
/// - Benchmark: 39.43 + P * 2.522 + S * 3.698 µs (min squares analysis)
/// # </weight>
#[weight = weight_for::set_subs(
T::DbWeight::get(),
Expand Down Expand Up @@ -771,8 +765,8 @@ decl_module! {
/// - `2` storage reads and `S + 2` storage deletions.
/// - One event.
/// - Benchmarks:
/// - 152.3 + R * 0.306 + S * 4.967 + X * 1.697 µs (min squares analysis)
/// - 139.5 + R * 0.466 + S * 5.304 + X * 1.895 µs (min squares analysis)
/// - 57.36 + R * 0.019 + S * 2.577 + X * 0.874 µs (median slopes analysis)
/// - 57.06 + R * 0.006 + S * 2.579 + X * 0.878 µs (min squares analysis)
/// # </weight>
#[weight = weight_for::clear_identity(
T::DbWeight::get(),
Expand Down Expand Up @@ -825,9 +819,7 @@ decl_module! {
/// - One balance-reserve operation.
/// - Storage: 1 read `O(R)`, 1 mutate `O(X + R)`.
/// - One event.
/// - Benchmarks:
/// - 154 + R * 0.932 + X * 3.302 µs (min squares analysis)
/// - 172.9 + R * 0.69 + X * 3.304 µs (min squares analysis)
/// - Benchmark: 59.02 + R * 0.488 + X * 1.7 µs (min squares analysis)
/// # </weight>
#[weight = weight_for::request_judgement(
T::DbWeight::get(),
Expand Down Expand Up @@ -882,9 +874,7 @@ decl_module! {
/// - One balance-reserve operation.
/// - One storage mutation `O(R + X)`.
/// - One event.
/// - Benchmarks:
/// - 135.3 + R * 0.574 + X * 3.394 µs (min squares analysis)
/// - 144.3 + R * 0.316 + X * 3.53 µs (min squares analysis)
/// - Benchmark: 50.05 + R * 0.321 + X * 1.688 µs (min squares analysis)
/// # </weight>
#[weight = weight_for::cancel_request(
T::DbWeight::get(),
Expand Down Expand Up @@ -924,12 +914,11 @@ decl_module! {
/// # <weight>
/// - `O(R)`.
/// - One storage mutation `O(R)`.
/// - Benchmarks:
/// - 23.81 + R * 0.774 µs (min squares analysis)
/// - Benchmark: 8.848 + R * 0.425 µs (min squares analysis)
/// # </weight>
#[weight = T::DbWeight::get().reads_writes(1, 1)
+ 24_000_000 // constant
+ 780_000 * T::MaxRegistrars::get() as Weight // R
+ 9_000_000 // constant
+ 430_000 * T::MaxRegistrars::get() as Weight // R
]
fn set_fee(origin,
#[compact] index: RegistrarIndex,
Expand All @@ -945,7 +934,7 @@ decl_module! {
Ok(rs.len())
})?;
Ok(Some(T::DbWeight::get().reads_writes(1, 1)
+ 24_000_000 + 780_000 * registrars as Weight // R
+ 9_000_000 + 430_000 * registrars as Weight // R
).into())
}

Expand All @@ -960,11 +949,11 @@ decl_module! {
/// # <weight>
/// - `O(R)`.
/// - One storage mutation `O(R)`.
/// - Benchmark: 24.59 + R * 0.832 µs (min squares analysis)
/// - Benchmark: 10.05 + R * 0.438 µs (min squares analysis)
/// # </weight>
#[weight = T::DbWeight::get().reads_writes(1, 1)
+ 25_000_000 // constant
+ 850_000 * T::MaxRegistrars::get() as Weight // R
+ 10_100_000 // constant
+ 440_000 * T::MaxRegistrars::get() as Weight // R
]
fn set_account_id(origin,
#[compact] index: RegistrarIndex,
Expand All @@ -980,7 +969,7 @@ decl_module! {
Ok(rs.len())
})?;
Ok(Some(T::DbWeight::get().reads_writes(1, 1)
+ 25_000_000 + 850_000 * registrars as Weight // R
+ 10_100_000 + 440_000 * registrars as Weight // R
).into())
}

Expand All @@ -995,11 +984,11 @@ decl_module! {
/// # <weight>
/// - `O(R)`.
/// - One storage mutation `O(R)`.
/// - Benchmark: 22.85 + R * 0.853 µs (min squares analysis)
/// - Benchmark: 8.985 + R * 0.413 µs (min squares analysis)
/// # </weight>
#[weight = T::DbWeight::get().reads_writes(1, 1)
+ 23_000_000 // constant
+ 860_000 * T::MaxRegistrars::get() as Weight // R
+ 9_000_000 // constant
+ 420_000 * T::MaxRegistrars::get() as Weight // R
]
fn set_fields(origin,
#[compact] index: RegistrarIndex,
Expand All @@ -1015,7 +1004,7 @@ decl_module! {
Ok(rs.len())
})?;
Ok(Some(T::DbWeight::get().reads_writes(1, 1)
+ 23_000_000 + 860_000 * registrars as Weight // R
+ 9_000_000 + 420_000 * registrars as Weight // R
).into())
}

Expand All @@ -1037,7 +1026,7 @@ decl_module! {
/// - Up to one account-lookup operation.
/// - Storage: 1 read `O(R)`, 1 mutate `O(R + X)`.
/// - One event.
/// - Benchmark: 110.7 + R * 1.066 + X * 3.402 µs (min squares analysis)
/// - Benchmark: 47.77 + R * 0.336 + X * 1.664 µs (min squares analysis)
/// # </weight>
#[weight = weight_for::provide_judgement(
T::DbWeight::get(),
Expand Down Expand Up @@ -1096,7 +1085,7 @@ decl_module! {
/// - One balance-reserve operation.
/// - `S + 2` storage mutations.
/// - One event.
/// - Benchmark: 167.4 + R * 1.107 + S * 5.343 + X * 2.294 µs (min squares analysis)
/// - Benchmark: 101.9 + R * 0.091 + S * 2.589 + X * 0.871 µs (min squares analysis)
/// # </weight>
#[weight = weight_for::kill_identity(
T::DbWeight::get(),
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: 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);
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`
6_000_000
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why this is not T::DbWeight::write(1)?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This takes DidUpdate, which is empty at the initialization of the block, populated as the first extrinsic in the block, and then removed again at the finalization of the block.

No value actually gets written to the DB layer. Everything happens within one block in-memory.

}

/// # <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");
Expand Down