Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Commit

Permalink
Document weight for asset, system and timestamp pallets (#5593)
Browse files Browse the repository at this point in the history
Co-Authored-By: thiolliere <[email protected]>
  • Loading branch information
apopiak and gui1117 authored Apr 24, 2020
1 parent 5038c3a commit ebf9df3
Show file tree
Hide file tree
Showing 3 changed files with 86 additions and 0 deletions.
21 changes: 21 additions & 0 deletions frame/assets/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,13 @@ decl_module! {
/// Issue a new class of fungible assets. There are, and will only ever be, `total`
/// such assets and they'll all belong to the `origin` initially. It will have an
/// identifier `AssetId` instance: this will be specified in the `Issued` event.
///
/// # <weight>
/// - `O(1)`
/// - 1 storage mutation (codec `O(1)`).
/// - 2 storage writes (condec `O(1)`).
/// - 1 event.
/// # </weight>
#[weight = MINIMUM_WEIGHT]
fn issue(origin, #[compact] total: T::Balance) {
let origin = ensure_signed(origin)?;
Expand All @@ -172,6 +179,13 @@ decl_module! {
}

/// Move some assets from one holder to another.
///
/// # <weight>
/// - `O(1)`
/// - 1 static lookup
/// - 2 storage mutations (codec `O(1)`).
/// - 1 event.
/// # </weight>
#[weight = MINIMUM_WEIGHT]
fn transfer(origin,
#[compact] id: T::AssetId,
Expand All @@ -191,6 +205,13 @@ decl_module! {
}

/// Destroy any assets of `id` owned by `origin`.
///
/// # <weight>
/// - `O(1)`
/// - 1 storage mutation (codec `O(1)`).
/// - 1 storage deletion (codec `O(1)`).
/// - 1 event.
/// # </weight>
#[weight = MINIMUM_WEIGHT]
fn destroy(origin, #[compact] id: T::AssetId) {
let origin = ensure_signed(origin)?;
Expand Down
55 changes: 55 additions & 0 deletions frame/system/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -494,19 +494,35 @@ decl_module! {
}

/// Make some on-chain remark.
///
/// # <weight>
/// - `O(1)`
/// # </weight>
#[weight = MINIMUM_WEIGHT]
fn remark(origin, _remark: Vec<u8>) {
ensure_signed(origin)?;
}

/// Set the number of pages in the WebAssembly environment's heap.
///
/// # <weight>
/// - `O(1)`
/// - 1 storage write.
/// # </weight>
#[weight = (MINIMUM_WEIGHT, DispatchClass::Operational)]
fn set_heap_pages(origin, pages: u64) {
ensure_root(origin)?;
storage::unhashed::put_raw(well_known_keys::HEAP_PAGES, &pages.encode());
}

/// Set the new runtime code.
///
/// # <weight>
/// - `O(C + S)` where `C` length of `code` and `S` complexity of `can_set_code`
/// - 1 storage write (codec `O(C)`).
/// - 1 call to `can_set_code`: `O(S)` (calls `sp_io::misc::runtime_version` which is expensive).
/// - 1 event.
/// # </weight>
#[weight = (200_000_000, DispatchClass::Operational)]
pub fn set_code(origin, code: Vec<u8>) {
Self::can_set_code(origin, &code)?;
Expand All @@ -516,6 +532,12 @@ decl_module! {
}

/// Set the new runtime code without doing any checks of the given `code`.
///
/// # <weight>
/// - `O(C)` where `C` length of `code`
/// - 1 storage write (codec `O(C)`).
/// - 1 event.
/// # </weight>
#[weight = (200_000_000, DispatchClass::Operational)]
pub fn set_code_without_checks(origin, code: Vec<u8>) {
ensure_root(origin)?;
Expand All @@ -524,6 +546,12 @@ decl_module! {
}

/// Set the new changes trie configuration.
///
/// # <weight>
/// - `O(D)` where `D` length of `Digest`
/// - 1 storage write or delete (codec `O(1)`).
/// - 1 call to `deposit_log`: `O(D)` (which depends on the length of `Digest`)
/// # </weight>
#[weight = (20_000_000, DispatchClass::Operational)]
pub fn set_changes_trie_config(origin, changes_trie_config: Option<ChangesTrieConfiguration>) {
ensure_root(origin)?;
Expand All @@ -542,6 +570,11 @@ decl_module! {
}

/// Set some items of storage.
///
/// # <weight>
/// - `O(I)` where `I` length of `items`
/// - `I` storage writes (`O(1)`).
/// # </weight>
#[weight = (MINIMUM_WEIGHT, DispatchClass::Operational)]
fn set_storage(origin, items: Vec<KeyValue>) {
ensure_root(origin)?;
Expand All @@ -551,6 +584,11 @@ decl_module! {
}

/// Kill some items from storage.
///
/// # <weight>
/// - `O(VK)` where `V` length of `keys` and `K` length of one key
/// - `V` storage deletions.
/// # </weight>
#[weight = (MINIMUM_WEIGHT, DispatchClass::Operational)]
fn kill_storage(origin, keys: Vec<Key>) {
ensure_root(origin)?;
Expand All @@ -560,6 +598,11 @@ decl_module! {
}

/// Kill all storage items with a key that starts with the given prefix.
///
/// # <weight>
/// - `O(P)` where `P` amount of keys with prefix `prefix`
/// - `P` storage deletions.
/// # </weight>
#[weight = (MINIMUM_WEIGHT, DispatchClass::Operational)]
fn kill_prefix(origin, prefix: Key) {
ensure_root(origin)?;
Expand All @@ -568,6 +611,13 @@ decl_module! {

/// Kill the sending account, assuming there are no references outstanding and the composite
/// data is equal to its default value.
///
/// # <weight>
/// - `O(K)` with `K` being complexity of `on_killed_account`
/// - 1 storage read and deletion.
/// - 1 call to `on_killed_account` callback with unknown complexity `K`
/// - 1 event.
/// # </weight>
#[weight = (25_000_000, DispatchClass::Operational)]
fn suicide(origin) {
let who = ensure_signed(origin)?;
Expand Down Expand Up @@ -924,6 +974,11 @@ impl<T: Trait> Module<T> {
}

/// Deposits a log and ensures it matches the block's log data.
///
/// # <weight>
/// - `O(D)` where `D` length of `Digest`
/// - 1 storage mutation (codec `O(D)`).
/// # </weight>
pub fn deposit_log(item: DigestItemOf<T>) {
let mut l = <Digest<T>>::get();
l.push(item);
Expand Down
10 changes: 10 additions & 0 deletions frame/timestamp/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,12 @@ decl_module! {
/// `MinimumPeriod`.
///
/// The dispatch origin for this call must be `Inherent`.
///
/// # <weight>
/// - `O(T)` where `T` complexity of `on_timestamp_set`
/// - 2 storage mutations (codec `O(1)`).
/// - 1 event handler `on_timestamp_set` `O(T)`.
/// # </weight>
#[weight = (MINIMUM_WEIGHT, DispatchClass::Mandatory)]
fn set(origin, #[compact] now: T::Moment) {
ensure_none(origin)?;
Expand All @@ -162,6 +168,10 @@ decl_module! {
<T::OnTimestampSet as OnTimestampSet<_>>::on_timestamp_set(now);
}

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

0 comments on commit ebf9df3

Please sign in to comment.