diff --git a/frame/balances/src/lib.rs b/frame/balances/src/lib.rs index 99d77a3e73361..f62ea6be7d3eb 100644 --- a/frame/balances/src/lib.rs +++ b/frame/balances/src/lib.rs @@ -267,7 +267,7 @@ pub mod pallet { /// /// The dispatch origin for this call must be `Signed` by the transactor. /// - /// # + /// ## Complexity /// - Dependent on arguments but not critical, given proper implementations for input config /// types. See related functions below. /// - It contains a limited number of reads and writes internally and no complex @@ -281,9 +281,6 @@ pub mod pallet { /// - Removing enough funds from an account will trigger `T::DustRemoval::on_unbalanced`. /// - `transfer_keep_alive` works the same way as `transfer`, but has an additional check /// that the transfer will not kill the origin account. - /// --------------------------------- - /// - Origin account is already in memory, so no DB operations for them. - /// # #[pallet::call_index(0)] #[pallet::weight(T::WeightInfo::transfer())] pub fn transfer( @@ -360,10 +357,9 @@ pub mod pallet { /// Exactly as `transfer`, except the origin must be root and the source account may be /// specified. - /// # + /// ## Complexity /// - Same as transfer, but additional read and write because the source account is not /// assumed to be in the overlay. - /// # #[pallet::call_index(2)] #[pallet::weight(T::WeightInfo::force_transfer())] pub fn force_transfer( @@ -417,9 +413,8 @@ pub mod pallet { /// - `keep_alive`: A boolean to determine if the `transfer_all` operation should send all /// of the funds the account has, causing the sender account to be killed (false), or /// transfer everything except at least the existential deposit, which will guarantee to - /// keep the sender account alive (true). # + /// keep the sender account alive (true). ## Complexity /// - O(1). Just like transfer, but reading the user's transferable balance first. - /// # #[pallet::call_index(4)] #[pallet::weight(T::WeightInfo::transfer_all())] pub fn transfer_all( @@ -1484,10 +1479,9 @@ where // restrictions like locks and vesting balance. // Is a no-op if amount to be withdrawn is zero. // - // # + // ## Complexity // Despite iterating over a list of locks, they are limited by the number of // lock IDs, which means the number of runtime pallets that intend to use and create locks. - // # fn ensure_can_withdraw( who: &T::AccountId, amount: T::Balance, diff --git a/frame/bounties/src/lib.rs b/frame/bounties/src/lib.rs index c3c2c08d24b2a..afdcfef8279bd 100644 --- a/frame/bounties/src/lib.rs +++ b/frame/bounties/src/lib.rs @@ -349,9 +349,8 @@ pub mod pallet { /// /// May only be called from `T::SpendOrigin`. /// - /// # + /// ## Complexity /// - O(1). - /// # #[pallet::call_index(1)] #[pallet::weight(>::WeightInfo::approve_bounty())] pub fn approve_bounty( @@ -381,9 +380,8 @@ pub mod pallet { /// /// May only be called from `T::SpendOrigin`. /// - /// # + /// ## Complexity /// - O(1). - /// # #[pallet::call_index(2)] #[pallet::weight(>::WeightInfo::propose_curator())] pub fn propose_curator( @@ -431,9 +429,8 @@ pub mod pallet { /// anyone in the community to call out that a curator is not doing their due diligence, and /// we should pick a new curator. In this case the curator should also be slashed. /// - /// # + /// ## Complexity /// - O(1). - /// # #[pallet::call_index(3)] #[pallet::weight(>::WeightInfo::unassign_curator())] pub fn unassign_curator( @@ -517,9 +514,8 @@ pub mod pallet { /// /// May only be called from the curator. /// - /// # + /// ## Complexity /// - O(1). - /// # #[pallet::call_index(4)] #[pallet::weight(>::WeightInfo::accept_curator())] pub fn accept_curator( @@ -560,9 +556,8 @@ pub mod pallet { /// - `bounty_id`: Bounty ID to award. /// - `beneficiary`: The beneficiary account whom will receive the payout. /// - /// # + /// ## Complexity /// - O(1). - /// # #[pallet::call_index(5)] #[pallet::weight(>::WeightInfo::award_bounty())] pub fn award_bounty( @@ -608,9 +603,8 @@ pub mod pallet { /// /// - `bounty_id`: Bounty ID to claim. /// - /// # + /// ## Complexity /// - O(1). - /// # #[pallet::call_index(6)] #[pallet::weight(>::WeightInfo::claim_bounty())] pub fn claim_bounty( @@ -672,9 +666,8 @@ pub mod pallet { /// /// - `bounty_id`: Bounty ID to cancel. /// - /// # + /// ## Complexity /// - O(1). - /// # #[pallet::call_index(7)] #[pallet::weight(>::WeightInfo::close_bounty_proposed() .max(>::WeightInfo::close_bounty_active()))] @@ -764,9 +757,8 @@ pub mod pallet { /// - `bounty_id`: Bounty ID to extend. /// - `remark`: additional information. /// - /// # + /// ## Complexity /// - O(1). - /// # #[pallet::call_index(8)] #[pallet::weight(>::WeightInfo::extend_bounty_expiry())] pub fn extend_bounty_expiry( diff --git a/frame/collective/src/lib.rs b/frame/collective/src/lib.rs index 7d625a69a4bf7..8424527b154a4 100644 --- a/frame/collective/src/lib.rs +++ b/frame/collective/src/lib.rs @@ -364,19 +364,11 @@ pub mod pallet { /// Any call to `set_members` must be careful that the member set doesn't get out of sync /// with other logic managing the member set. /// - /// # - /// ## Weight + /// ## Complexity: /// - `O(MP + N)` where: /// - `M` old-members-count (code- and governance-bounded) /// - `N` new-members-count (code- and governance-bounded) /// - `P` proposals-count (code-bounded) - /// - DB: - /// - 1 storage mutation (codec `O(M)` read, `O(N)` write) for reading and writing the - /// members - /// - 1 storage read (codec `O(P)`) for reading the proposals - /// - `P` storage mutations (codec `O(M)`) for updating the votes for each proposal - /// - 1 storage write (codec `O(1)`) for deleting the old `prime` and setting the new one - /// # #[pallet::call_index(0)] #[pallet::weight(( T::WeightInfo::set_members( @@ -428,13 +420,11 @@ pub mod pallet { /// /// Origin must be a member of the collective. /// - /// # - /// ## Weight - /// - `O(M + P)` where `M` members-count (code-bounded) and `P` complexity of dispatching - /// `proposal` - /// - DB: 1 read (codec `O(M)`) + DB access of `proposal` - /// - 1 event - /// # + /// ## Complexity: + /// - `O(B + M + P)` where: + /// - `B` is `proposal` size in bytes (length-fee-bounded) + /// - `M` members-count (code-bounded) + /// - `P` complexity of dispatching `proposal` #[pallet::call_index(1)] #[pallet::weight(( T::WeightInfo::execute( @@ -479,26 +469,13 @@ pub mod pallet { /// `threshold` determines whether `proposal` is executed directly (`threshold < 2`) /// or put up for voting. /// - /// # - /// ## Weight + /// ## Complexity /// - `O(B + M + P1)` or `O(B + M + P2)` where: /// - `B` is `proposal` size in bytes (length-fee-bounded) /// - `M` is members-count (code- and governance-bounded) /// - branching is influenced by `threshold` where: /// - `P1` is proposal execution complexity (`threshold < 2`) /// - `P2` is proposals-count (code-bounded) (`threshold >= 2`) - /// - DB: - /// - 1 storage read `is_member` (codec `O(M)`) - /// - 1 storage read `ProposalOf::contains_key` (codec `O(1)`) - /// - DB accesses influenced by `threshold`: - /// - EITHER storage accesses done by `proposal` (`threshold < 2`) - /// - OR proposal insertion (`threshold <= 2`) - /// - 1 storage mutation `Proposals` (codec `O(P2)`) - /// - 1 storage mutation `ProposalCount` (codec `O(1)`) - /// - 1 storage write `ProposalOf` (codec `O(B)`) - /// - 1 storage write `Voting` (codec `O(M)`) - /// - 1 event - /// # #[pallet::call_index(2)] #[pallet::weight(( if *threshold < 2 { @@ -557,14 +534,8 @@ pub mod pallet { /// Transaction fees will be waived if the member is voting on any particular proposal /// for the first time and the call is successful. Subsequent vote changes will charge a /// fee. - /// # - /// ## Weight + /// ## Complexity /// - `O(M)` where `M` is members-count (code- and governance-bounded) - /// - DB: - /// - 1 storage read `Members` (codec `O(M)`) - /// - 1 storage mutation `Voting` (codec `O(M)`) - /// - 1 event - /// # #[pallet::call_index(3)] #[pallet::weight((T::WeightInfo::vote(T::MaxMembers::get()), DispatchClass::Operational))] pub fn vote( @@ -605,20 +576,12 @@ pub mod pallet { /// + `length_bound`: The upper bound for the length of the proposal in storage. Checked via /// `storage::read` so it is `size_of::() == 4` larger than the pure length. /// - /// # - /// ## Weight + /// ## Complexity /// - `O(B + M + P1 + P2)` where: /// - `B` is `proposal` size in bytes (length-fee-bounded) /// - `M` is members-count (code- and governance-bounded) /// - `P1` is the complexity of `proposal` preimage. /// - `P2` is proposal-count (code-bounded) - /// - DB: - /// - 2 storage reads (`Members`: codec `O(M)`, `Prime`: codec `O(1)`) - /// - 3 mutations (`Voting`: codec `O(M)`, `ProposalOf`: codec `O(B)`, `Proposals`: codec - /// `O(P2)`) - /// - any mutations done while executing `proposal` (`P1`) - /// - up to 3 events - /// # #[pallet::call_index(4)] #[pallet::weight(( { @@ -657,12 +620,8 @@ pub mod pallet { /// Parameters: /// * `proposal_hash`: The hash of the proposal that should be disapproved. /// - /// # - /// Complexity: O(P) where P is the number of max proposals - /// DB Weight: - /// * Reads: Proposals - /// * Writes: Voting, Proposals, ProposalOf - /// # + /// ## Complexity + /// O(P) where P is the number of max proposals #[pallet::call_index(5)] #[pallet::weight(T::WeightInfo::disapprove_proposal(T::MaxProposals::get()))] pub fn disapprove_proposal( @@ -692,20 +651,12 @@ pub mod pallet { /// + `length_bound`: The upper bound for the length of the proposal in storage. Checked via /// `storage::read` so it is `size_of::() == 4` larger than the pure length. /// - /// # - /// ## Weight + /// ## Complexity /// - `O(B + M + P1 + P2)` where: /// - `B` is `proposal` size in bytes (length-fee-bounded) /// - `M` is members-count (code- and governance-bounded) /// - `P1` is the complexity of `proposal` preimage. /// - `P2` is proposal-count (code-bounded) - /// - DB: - /// - 2 storage reads (`Members`: codec `O(M)`, `Prime`: codec `O(1)`) - /// - 3 mutations (`Voting`: codec `O(M)`, `ProposalOf`: codec `O(B)`, `Proposals`: codec - /// `O(P2)`) - /// - any mutations done while executing `proposal` (`P1`) - /// - up to 3 events - /// # #[pallet::call_index(6)] #[pallet::weight(( { @@ -1026,18 +977,11 @@ impl, I: 'static> ChangeMembers for Pallet { /// NOTE: Does not enforce the expected `MaxMembers` limit on the amount of members, but /// the weight estimations rely on it to estimate dispatchable weight. /// - /// # - /// ## Weight + /// ## Complexity /// - `O(MP + N)` /// - where `M` old-members-count (governance-bounded) /// - where `N` new-members-count (governance-bounded) /// - where `P` proposals-count - /// - DB: - /// - 1 storage read (codec `O(P)`) for reading the proposals - /// - `P` storage mutations for updating the votes (codec `O(M)`) - /// - 1 storage write (codec `O(N)`) for storing the new members - /// - 1 storage write (codec `O(1)`) for deleting the old prime - /// # fn change_members_sorted( _incoming: &[T::AccountId], outgoing: &[T::AccountId], diff --git a/frame/democracy/src/lib.rs b/frame/democracy/src/lib.rs index 3aa8bc0015d38..d9aae63ce6aae 100644 --- a/frame/democracy/src/lib.rs +++ b/frame/democracy/src/lib.rs @@ -1617,15 +1617,9 @@ impl Pallet { /// Current era is ending; we should finish up any proposals. /// /// - /// # + /// ## Complexity: /// If a referendum is launched or maturing, this will take full block weight if queue is not - /// empty. Otherwise: - /// - Complexity: `O(R)` where `R` is the number of unbaked referenda. - /// - Db reads: `LastTabledWasExternal`, `NextExternal`, `PublicProps`, `account`, - /// `ReferendumCount`, `LowestUnbaked` - /// - Db writes: `PublicProps`, `account`, `ReferendumCount`, `DepositOf`, `ReferendumInfoOf` - /// - Db reads per R: `DepositOf`, `ReferendumInfoOf` - /// # + /// empty. Otherwise, `O(R)` where `R` is the number of unbaked referenda. fn begin_block(now: T::BlockNumber) -> Weight { let max_block_weight = T::BlockWeights::get().max_block; let mut weight = Weight::zero(); diff --git a/frame/elections-phragmen/src/lib.rs b/frame/elections-phragmen/src/lib.rs index c655d4a16230b..37ee44f34dc3d 100644 --- a/frame/elections-phragmen/src/lib.rs +++ b/frame/elections-phragmen/src/lib.rs @@ -435,9 +435,9 @@ pub mod pallet { /// Even if a candidate ends up being a member, they must call [`Call::renounce_candidacy`] /// to get their deposit back. Losing the spot in an election will always lead to a slash. /// - /// # /// The number of current candidates must be provided as witness data. - /// # + /// ## Complexity + /// O(C + log(C)) where C is candidate_count. #[pallet::call_index(2)] #[pallet::weight(T::WeightInfo::submit_candidacy(*candidate_count))] pub fn submit_candidacy( @@ -479,10 +479,12 @@ pub mod pallet { /// next round. /// /// The dispatch origin of this call must be signed, and have one of the above roles. - /// - /// # /// The type of renouncing must be provided as witness data. - /// # + /// + /// ## Complexity + /// - Renouncing::Candidate(count): O(count + log(count)) + /// - Renouncing::Member: O(1) + /// - Renouncing::RunnerUp: O(1) #[pallet::call_index(3)] #[pallet::weight(match *renouncing { Renouncing::Candidate(count) => T::WeightInfo::renounce_candidacy_candidate(count), @@ -542,10 +544,8 @@ pub mod pallet { /// /// Note that this does not affect the designated block number of the next election. /// - /// # - /// If we have a replacement, we use a small weight. Else, since this is a root call and - /// will go into phragmen, we assume full block for now. - /// # + /// ## Complexity + /// - Check details of remove_and_replace_member() and do_phragmen(). #[pallet::call_index(4)] #[pallet::weight(if *rerun_election { T::WeightInfo::remove_member_without_replacement() @@ -579,9 +579,8 @@ pub mod pallet { /// /// The dispatch origin of this call must be root. /// - /// # - /// The total number of voters and those that are defunct must be provided as witness data. - /// # + /// ## Complexity + /// - Check is_defunct_voter() details. #[pallet::call_index(5)] #[pallet::weight(T::WeightInfo::clean_defunct_voters(*_num_voters, *_num_defunct))] pub fn clean_defunct_voters( diff --git a/frame/identity/src/lib.rs b/frame/identity/src/lib.rs index 8eab2c67418a1..39d828ef26f83 100644 --- a/frame/identity/src/lib.rs +++ b/frame/identity/src/lib.rs @@ -279,11 +279,8 @@ pub mod pallet { /// /// Emits `RegistrarAdded` if successful. /// - /// # + /// ## Complexity /// - `O(R)` where `R` registrar-count (governance-bounded and code-bounded). - /// - One storage mutation (codec `O(R)`). - /// - One event. - /// # #[pallet::call_index(0)] #[pallet::weight(T::WeightInfo::add_registrar(T::MaxRegistrars::get()))] pub fn add_registrar( @@ -322,14 +319,10 @@ pub mod pallet { /// /// Emits `IdentitySet` if successful. /// - /// # + /// ## Complexity /// - `O(X + X' + R)` /// - where `X` additional-field-count (deposit-bounded and code-bounded) /// - where `R` judgements-count (registrar-count-bounded) - /// - One balance reserve operation. - /// - One storage mutation (codec-read `O(X' + R)`, codec-write `O(X + R)`). - /// - One event. - /// # #[pallet::call_index(1)] #[pallet::weight( T::WeightInfo::set_identity( T::MaxRegistrars::get(), // R @@ -389,17 +382,10 @@ pub mod pallet { /// /// - `subs`: The identity's (new) sub-accounts. /// - /// # + /// ## Complexity /// - `O(P + S)` /// - where `P` old-subs-count (hard- and deposit-bounded). /// - where `S` subs-count (hard- and deposit-bounded). - /// - At most one balance operations. - /// - DB: - /// - `P + S` storage mutations (codec complexity `O(1)`) - /// - One storage read (codec complexity `O(P)`). - /// - One storage write (codec complexity `O(S)`). - /// - One storage-exists (`IdentityOf::contains_key`). - /// # // TODO: This whole extrinsic screams "not optimized". For example we could // filter any overlap between new and old subs, and avoid reading/writing // to those values... We could also ideally avoid needing to write to @@ -469,15 +455,11 @@ pub mod pallet { /// /// Emits `IdentityCleared` if successful. /// - /// # + /// ## Complexity /// - `O(R + S + X)` /// - where `R` registrar-count (governance-bounded). /// - where `S` subs-count (hard- and deposit-bounded). /// - where `X` additional-field-count (deposit-bounded and code-bounded). - /// - One balance-unreserve operation. - /// - `2` storage reads and `S + 2` storage deletions. - /// - One event. - /// # #[pallet::call_index(3)] #[pallet::weight(T::WeightInfo::clear_identity( T::MaxRegistrars::get(), // R @@ -524,12 +506,10 @@ pub mod pallet { /// /// Emits `JudgementRequested` if successful. /// - /// # + /// ## Complexity /// - `O(R + X)`. - /// - One balance-reserve operation. - /// - Storage: 1 read `O(R)`, 1 mutate `O(X + R)`. - /// - One event. - /// # + /// - where `R` registrar-count (governance-bounded). + /// - where `X` additional-field-count (deposit-bounded and code-bounded). #[pallet::call_index(4)] #[pallet::weight(T::WeightInfo::request_judgement( T::MaxRegistrars::get(), // R @@ -587,12 +567,10 @@ pub mod pallet { /// /// Emits `JudgementUnrequested` if successful. /// - /// # + /// ## Complexity /// - `O(R + X)`. - /// - One balance-reserve operation. - /// - One storage mutation `O(R + X)`. - /// - One event - /// # + /// - where `R` registrar-count (governance-bounded). + /// - where `X` additional-field-count (deposit-bounded and code-bounded). #[pallet::call_index(5)] #[pallet::weight(T::WeightInfo::cancel_request( T::MaxRegistrars::get(), // R @@ -637,11 +615,9 @@ pub mod pallet { /// - `index`: the index of the registrar whose fee is to be set. /// - `fee`: the new fee. /// - /// # + /// ## Complexity /// - `O(R)`. - /// - One storage mutation `O(R)`. - /// - Benchmark: 7.315 + R * 0.329 µs (min squares analysis) - /// # + /// - where `R` registrar-count (governance-bounded). #[pallet::call_index(6)] #[pallet::weight(T::WeightInfo::set_fee(T::MaxRegistrars::get()))] // R pub fn set_fee( @@ -676,11 +652,9 @@ pub mod pallet { /// - `index`: the index of the registrar whose fee is to be set. /// - `new`: the new account ID. /// - /// # + /// ## Complexity /// - `O(R)`. - /// - One storage mutation `O(R)`. - /// - Benchmark: 8.823 + R * 0.32 µs (min squares analysis) - /// # + /// - where `R` registrar-count (governance-bounded). #[pallet::call_index(7)] #[pallet::weight(T::WeightInfo::set_account_id(T::MaxRegistrars::get()))] // R pub fn set_account_id( @@ -716,11 +690,9 @@ pub mod pallet { /// - `index`: the index of the registrar whose fee is to be set. /// - `fields`: the fields that the registrar concerns themselves with. /// - /// # + /// ## Complexity /// - `O(R)`. - /// - One storage mutation `O(R)`. - /// - Benchmark: 7.464 + R * 0.325 µs (min squares analysis) - /// # + /// - where `R` registrar-count (governance-bounded). #[pallet::call_index(8)] #[pallet::weight(T::WeightInfo::set_fields(T::MaxRegistrars::get()))] // R pub fn set_fields( @@ -763,13 +735,10 @@ pub mod pallet { /// /// Emits `JudgementGiven` if successful. /// - /// # + /// ## Complexity /// - `O(R + X)`. - /// - One balance-transfer operation. - /// - Up to one account-lookup operation. - /// - Storage: 1 read `O(R)`, 1 mutate `O(R + X)`. - /// - One event. - /// # + /// - where `R` registrar-count (governance-bounded). + /// - where `X` additional-field-count (deposit-bounded and code-bounded). #[pallet::call_index(9)] #[pallet::weight(T::WeightInfo::provide_judgement( T::MaxRegistrars::get(), // R @@ -838,12 +807,11 @@ pub mod pallet { /// /// Emits `IdentityKilled` if successful. /// - /// # - /// - `O(R + S + X)`. - /// - One balance-reserve operation. - /// - `S + 2` storage mutations. - /// - One event. - /// # + /// ## Complexity + /// - `O(R + S + X)` + /// - where `R` registrar-count (governance-bounded). + /// - where `S` subs-count (hard- and deposit-bounded). + /// - where `X` additional-field-count (deposit-bounded and code-bounded). #[pallet::call_index(10)] #[pallet::weight(T::WeightInfo::kill_identity( T::MaxRegistrars::get(), // R diff --git a/frame/im-online/src/lib.rs b/frame/im-online/src/lib.rs index 8c1f46978e8bc..3be1f53fc418d 100644 --- a/frame/im-online/src/lib.rs +++ b/frame/im-online/src/lib.rs @@ -463,15 +463,11 @@ pub mod pallet { #[pallet::call] impl Pallet { - /// # - /// - Complexity: `O(K + E)` where K is length of `Keys` (heartbeat.validators_len) and E is - /// length of `heartbeat.network_state.external_address` + /// ## Complexity: + /// - `O(K + E)` where K is length of `Keys` (heartbeat.validators_len) and E is length of + /// `heartbeat.network_state.external_address` /// - `O(K)`: decoding of length `K` /// - `O(E)`: decoding/encoding of length `E` - /// - DbReads: pallet_session `Validators`, pallet_session `CurrentIndex`, `Keys`, - /// `ReceivedHeartbeats` - /// - DbWrites: `ReceivedHeartbeats` - /// # // NOTE: the weight includes the cost of validate_unsigned as it is part of the cost to // import block with such an extrinsic. #[pallet::call_index(0)] diff --git a/frame/indices/src/lib.rs b/frame/indices/src/lib.rs index 95d3cf4b2eed1..0eaee0f4b9eb7 100644 --- a/frame/indices/src/lib.rs +++ b/frame/indices/src/lib.rs @@ -90,14 +90,8 @@ pub mod pallet { /// /// Emits `IndexAssigned` if successful. /// - /// # + /// ## Complexity /// - `O(1)`. - /// - One storage mutation (codec `O(1)`). - /// - One reserve operation. - /// - One event. - /// ------------------- - /// - DB Weight: 1 Read/Write (Accounts) - /// # #[pallet::call_index(0)] #[pallet::weight(T::WeightInfo::claim())] pub fn claim(origin: OriginFor, index: T::AccountIndex) -> DispatchResult { @@ -122,16 +116,8 @@ pub mod pallet { /// /// Emits `IndexAssigned` if successful. /// - /// # + /// ## Complexity /// - `O(1)`. - /// - One storage mutation (codec `O(1)`). - /// - One transfer operation. - /// - One event. - /// ------------------- - /// - DB Weight: - /// - Reads: Indices Accounts, System Account (recipient) - /// - Writes: Indices Accounts, System Account (recipient) - /// # #[pallet::call_index(1)] #[pallet::weight(T::WeightInfo::transfer())] pub fn transfer( @@ -165,14 +151,8 @@ pub mod pallet { /// /// Emits `IndexFreed` if successful. /// - /// # + /// ## Complexity /// - `O(1)`. - /// - One storage mutation (codec `O(1)`). - /// - One reserve operation. - /// - One event. - /// ------------------- - /// - DB Weight: 1 Read/Write (Accounts) - /// # #[pallet::call_index(2)] #[pallet::weight(T::WeightInfo::free())] pub fn free(origin: OriginFor, index: T::AccountIndex) -> DispatchResult { @@ -200,16 +180,8 @@ pub mod pallet { /// /// Emits `IndexAssigned` if successful. /// - /// # + /// ## Complexity /// - `O(1)`. - /// - One storage mutation (codec `O(1)`). - /// - Up to one reserve operation. - /// - One event. - /// ------------------- - /// - DB Weight: - /// - Reads: Indices Accounts, System Account (original owner) - /// - Writes: Indices Accounts, System Account (original owner) - /// # #[pallet::call_index(3)] #[pallet::weight(T::WeightInfo::force_transfer())] pub fn force_transfer( @@ -241,14 +213,8 @@ pub mod pallet { /// /// Emits `IndexFrozen` if successful. /// - /// # + /// ## Complexity /// - `O(1)`. - /// - One storage mutation (codec `O(1)`). - /// - Up to one slash operation. - /// - One event. - /// ------------------- - /// - DB Weight: 1 Read/Write (Accounts) - /// # #[pallet::call_index(4)] #[pallet::weight(T::WeightInfo::freeze())] pub fn freeze(origin: OriginFor, index: T::AccountIndex) -> DispatchResult { diff --git a/frame/multisig/src/lib.rs b/frame/multisig/src/lib.rs index 03d7ddec6a316..de20a9e5143d9 100644 --- a/frame/multisig/src/lib.rs +++ b/frame/multisig/src/lib.rs @@ -263,12 +263,8 @@ pub mod pallet { /// /// Result is equivalent to the dispatched result. /// - /// # + /// ## Complexity /// O(Z + C) where Z is the length of the call and C its execution weight. - /// ------------------------------- - /// - DB Weight: None - /// - Plus Call Weight - /// # #[pallet::call_index(0)] #[pallet::weight({ let dispatch_info = call.get_dispatch_info(); @@ -344,7 +340,7 @@ pub mod pallet { /// on success, result is `Ok` and the result from the interior call, if it was executed, /// may be found in the deposited `MultisigExecuted` event. /// - /// # + /// ## Complexity /// - `O(S + Z + Call)`. /// - Up to one balance-reserve or unreserve operation. /// - One passthrough operation, one insert, both `O(S)` where `S` is the number of @@ -357,12 +353,6 @@ pub mod pallet { /// - The weight of the `call`. /// - Storage: inserts one item, value size bounded by `MaxSignatories`, with a deposit /// taken for its lifetime of `DepositBase + threshold * DepositFactor`. - /// ------------------------------- - /// - DB Weight: - /// - Reads: Multisig Storage, [Caller Account] - /// - Writes: Multisig Storage, [Caller Account] - /// - Plus Call Weight - /// # #[pallet::call_index(1)] #[pallet::weight({ let s = other_signatories.len() as u32; @@ -411,7 +401,7 @@ pub mod pallet { /// /// NOTE: If this is the final approval, you will want to use `as_multi` instead. /// - /// # + /// ## Complexity /// - `O(S)`. /// - Up to one balance-reserve or unreserve operation. /// - One passthrough operation, one insert, both `O(S)` where `S` is the number of @@ -422,11 +412,6 @@ pub mod pallet { /// - One event. /// - Storage: inserts one item, value size bounded by `MaxSignatories`, with a deposit /// taken for its lifetime of `DepositBase + threshold * DepositFactor`. - /// ---------------------------------- - /// - DB Weight: - /// - Read: Multisig Storage, [Caller Account] - /// - Write: Multisig Storage, [Caller Account] - /// # #[pallet::call_index(2)] #[pallet::weight({ let s = other_signatories.len() as u32; @@ -466,7 +451,7 @@ pub mod pallet { /// transaction for this dispatch. /// - `call_hash`: The hash of the call to be executed. /// - /// # + /// ## Complexity /// - `O(S)`. /// - Up to one balance-reserve or unreserve operation. /// - One passthrough operation, one insert, both `O(S)` where `S` is the number of @@ -475,11 +460,6 @@ pub mod pallet { /// - One event. /// - I/O: 1 read `O(S)`, one remove. /// - Storage: removes one item. - /// ---------------------------------- - /// - DB Weight: - /// - Read: Multisig Storage, [Caller Account], Refund Account - /// - Write: Multisig Storage, [Caller Account], Refund Account - /// # #[pallet::call_index(3)] #[pallet::weight(T::WeightInfo::cancel_as_multi(other_signatories.len() as u32))] pub fn cancel_as_multi( diff --git a/frame/nicks/src/lib.rs b/frame/nicks/src/lib.rs index 3d8307c434107..05d1a36395b94 100644 --- a/frame/nicks/src/lib.rs +++ b/frame/nicks/src/lib.rs @@ -129,12 +129,8 @@ pub mod pallet { /// /// The dispatch origin for this call must be _Signed_. /// - /// # + /// ## Complexity /// - O(1). - /// - At most one balance operation. - /// - One storage read/write. - /// - One event. - /// # #[pallet::call_index(0)] #[pallet::weight(50_000_000)] pub fn set_name(origin: OriginFor, name: Vec) -> DispatchResult { @@ -162,12 +158,8 @@ pub mod pallet { /// /// The dispatch origin for this call must be _Signed_. /// - /// # + /// ## Complexity /// - O(1). - /// - One balance operation. - /// - One storage read/write. - /// - One event. - /// # #[pallet::call_index(1)] #[pallet::weight(70_000_000)] pub fn clear_name(origin: OriginFor) -> DispatchResult { @@ -189,12 +181,8 @@ pub mod pallet { /// /// The dispatch origin for this call must match `T::ForceOrigin`. /// - /// # + /// ## Complexity /// - O(1). - /// - One unbalanced handler (probably a balance transfer) - /// - One storage read/write. - /// - One event. - /// # #[pallet::call_index(2)] #[pallet::weight(70_000_000)] pub fn kill_name(origin: OriginFor, target: AccountIdLookupOf) -> DispatchResult { @@ -217,12 +205,8 @@ pub mod pallet { /// /// The dispatch origin for this call must match `T::ForceOrigin`. /// - /// # + /// ## Complexity /// - O(1). - /// - At most one balance operation. - /// - One storage read/write. - /// - One event. - /// # #[pallet::call_index(3)] #[pallet::weight(70_000_000)] pub fn force_name( diff --git a/frame/scheduler/src/lib.rs b/frame/scheduler/src/lib.rs index dfec98d4e443a..97aaaaf0da7de 100644 --- a/frame/scheduler/src/lib.rs +++ b/frame/scheduler/src/lib.rs @@ -363,10 +363,6 @@ pub mod pallet { } /// Anonymously schedule a task after a delay. - /// - /// # - /// Same as [`schedule`]. - /// # #[pallet::call_index(4)] #[pallet::weight(::WeightInfo::schedule(T::MaxScheduledPerBlock::get()))] pub fn schedule_after( @@ -389,10 +385,6 @@ pub mod pallet { } /// Schedule a named task after a delay. - /// - /// # - /// Same as [`schedule_named`](Self::schedule_named). - /// # #[pallet::call_index(5)] #[pallet::weight(::WeightInfo::schedule_named(T::MaxScheduledPerBlock::get()))] pub fn schedule_named_after( diff --git a/frame/session/src/lib.rs b/frame/session/src/lib.rs index 4e2caf5e0874e..38a5c0f57f73c 100644 --- a/frame/session/src/lib.rs +++ b/frame/session/src/lib.rs @@ -587,14 +587,9 @@ pub mod pallet { /// /// The dispatch origin of this function must be signed. /// - /// # - /// - Complexity: `O(1)`. Actual cost depends on the number of length of - /// `T::Keys::key_ids()` which is fixed. - /// - DbReads: `origin account`, `T::ValidatorIdOf`, `NextKeys` - /// - DbWrites: `origin account`, `NextKeys` - /// - DbReads per key id: `KeyOwner` - /// - DbWrites per key id: `KeyOwner` - /// # + /// ## Complexity + /// - `O(1)`. Actual cost depends on the number of length of `T::Keys::key_ids()` which is + /// fixed. #[pallet::call_index(0)] #[pallet::weight(T::WeightInfo::set_keys())] pub fn set_keys(origin: OriginFor, keys: T::Keys, proof: Vec) -> DispatchResult { @@ -614,13 +609,9 @@ pub mod pallet { /// means being a controller account) or directly convertible into a validator ID (which /// usually means being a stash account). /// - /// # - /// - Complexity: `O(1)` in number of key types. Actual cost depends on the number of length - /// of `T::Keys::key_ids()` which is fixed. - /// - DbReads: `T::ValidatorIdOf`, `NextKeys`, `origin account` - /// - DbWrites: `NextKeys`, `origin account` - /// - DbWrites per key id: `KeyOwner` - /// # + /// ## Complexity + /// - `O(1)` in number of key types. Actual cost depends on the number of length of + /// `T::Keys::key_ids()` which is fixed. #[pallet::call_index(1)] #[pallet::weight(T::WeightInfo::purge_keys())] pub fn purge_keys(origin: OriginFor) -> DispatchResult { diff --git a/frame/society/src/lib.rs b/frame/society/src/lib.rs index 18152b9e29ec4..4e83d938b2e2d 100644 --- a/frame/society/src/lib.rs +++ b/frame/society/src/lib.rs @@ -689,30 +689,12 @@ pub mod pallet { /// Parameters: /// - `value`: A one time payment the bid would like to receive when joining the society. /// - /// # - /// Key: B (len of bids), C (len of candidates), M (len of members), X (balance reserve) - /// - Storage Reads: - /// - One storage read to check for suspended candidate. O(1) - /// - One storage read to check for suspended member. O(1) - /// - One storage read to retrieve all current bids. O(B) - /// - One storage read to retrieve all current candidates. O(C) - /// - One storage read to retrieve all members. O(M) - /// - Storage Writes: - /// - One storage mutate to add a new bid to the vector O(B) (TODO: possible optimization - /// w/ read) - /// - Up to one storage removal if bid.len() > MAX_BID_COUNT. O(1) - /// - Notable Computation: - /// - O(B + C + log M) search to check user is not already a part of society. - /// - O(log B) search to insert the new bid sorted. - /// - External Pallet Operations: - /// - One balance reserve operation. O(X) - /// - Up to one balance unreserve operation if bids.len() > MAX_BID_COUNT. - /// - Events: - /// - One event for new bid. - /// - Up to one event for AutoUnbid if bid.len() > MAX_BID_COUNT. - /// - /// Total Complexity: O(M + B + C + logM + logB + X) - /// # + /// ## Complexity + /// - O(M + B + C + logM + logB + X) + /// - B (len of bids) + /// - C (len of candidates) + /// - M (len of members) + /// - X (balance reserve) #[pallet::call_index(0)] #[pallet::weight(T::BlockWeights::get().max_block / 10)] pub fn bid(origin: OriginFor, value: BalanceOf) -> DispatchResult { @@ -745,14 +727,10 @@ pub mod pallet { /// Parameters: /// - `pos`: Position in the `Bids` vector of the bid who wants to unbid. /// - /// # - /// Key: B (len of bids), X (balance unreserve) - /// - One storage read and write to retrieve and update the bids. O(B) - /// - Either one unreserve balance action O(X) or one vouching storage removal. O(1) - /// - One event. - /// - /// Total Complexity: O(B + X) - /// # + /// ## Complexity + /// - O(B + X) + /// - B (len of bids) + /// - X (balance unreserve) #[pallet::call_index(1)] #[pallet::weight(T::BlockWeights::get().max_block / 10)] pub fn unbid(origin: OriginFor, pos: u32) -> DispatchResult { @@ -799,33 +777,12 @@ pub mod pallet { /// - `tip`: Your cut of the total `value` payout when the candidate is inducted into /// the society. Tips larger than `value` will be saturated upon payout. /// - /// # - /// Key: B (len of bids), C (len of candidates), M (len of members) - /// - Storage Reads: - /// - One storage read to retrieve all members. O(M) - /// - One storage read to check member is not already vouching. O(1) - /// - One storage read to check for suspended candidate. O(1) - /// - One storage read to check for suspended member. O(1) - /// - One storage read to retrieve all current bids. O(B) - /// - One storage read to retrieve all current candidates. O(C) - /// - Storage Writes: - /// - One storage write to insert vouching status to the member. O(1) - /// - One storage mutate to add a new bid to the vector O(B) (TODO: possible optimization - /// w/ read) - /// - Up to one storage removal if bid.len() > MAX_BID_COUNT. O(1) - /// - Notable Computation: - /// - O(log M) search to check sender is a member. - /// - O(B + C + log M) search to check user is not already a part of society. - /// - O(log B) search to insert the new bid sorted. - /// - External Pallet Operations: - /// - One balance reserve operation. O(X) - /// - Up to one balance unreserve operation if bids.len() > MAX_BID_COUNT. - /// - Events: - /// - One event for vouch. - /// - Up to one event for AutoUnbid if bid.len() > MAX_BID_COUNT. - /// - /// Total Complexity: O(M + B + C + logM + logB + X) - /// # + /// ## Complexity + /// - O(M + B + C + logM + logB + X) + /// - B (len of bids) + /// - C (len of candidates) + /// - M (len of members) + /// - X (balance reserve) #[pallet::call_index(2)] #[pallet::weight(T::BlockWeights::get().max_block / 10)] pub fn vouch( @@ -869,15 +826,9 @@ pub mod pallet { /// Parameters: /// - `pos`: Position in the `Bids` vector of the bid who should be unvouched. /// - /// # - /// Key: B (len of bids) - /// - One storage read O(1) to check the signer is a vouching member. - /// - One storage mutate to retrieve and update the bids. O(B) - /// - One vouching storage removal. O(1) - /// - One event. - /// - /// Total Complexity: O(B) - /// # + /// ## Complexity + /// - O(B) + /// - B (len of bids) #[pallet::call_index(3)] #[pallet::weight(T::BlockWeights::get().max_block / 10)] pub fn unvouch(origin: OriginFor, pos: u32) -> DispatchResult { @@ -910,16 +861,10 @@ pub mod pallet { /// - `approve`: A boolean which says if the candidate should be approved (`true`) or /// rejected (`false`). /// - /// # - /// Key: C (len of candidates), M (len of members) - /// - One storage read O(M) and O(log M) search to check user is a member. - /// - One account lookup. - /// - One storage read O(C) and O(C) search to check that user is a candidate. - /// - One storage write to add vote to votes. O(1) - /// - One event. - /// - /// Total Complexity: O(M + logM + C) - /// # + /// ## Complexity + /// - O(M + logM + C) + /// - C (len of candidates) + /// - M (len of members) #[pallet::call_index(4)] #[pallet::weight(T::BlockWeights::get().max_block / 10)] pub fn vote( @@ -949,14 +894,9 @@ pub mod pallet { /// - `approve`: A boolean which says if the candidate should be /// approved (`true`) or rejected (`false`). /// - /// # - /// - Key: M (len of members) - /// - One storage read O(M) and O(log M) search to check user is a member. - /// - One storage write to add vote to votes. O(1) - /// - One event. - /// - /// Total Complexity: O(M + logM) - /// # + /// ## Complexity + /// - O(M + logM) + /// - M (len of members) #[pallet::call_index(5)] #[pallet::weight(T::BlockWeights::get().max_block / 10)] pub fn defender_vote(origin: OriginFor, approve: bool) -> DispatchResult { @@ -982,16 +922,11 @@ pub mod pallet { /// The dispatch origin for this call must be _Signed_ and a member with /// payouts remaining. /// - /// # - /// Key: M (len of members), P (number of payouts for a particular member) - /// - One storage read O(M) and O(log M) search to check signer is a member. - /// - One storage read O(P) to get all payouts for a member. - /// - One storage read O(1) to get the current block number. - /// - One currency transfer call. O(X) - /// - One storage write or removal to update the member's payouts. O(P) - /// - /// Total Complexity: O(M + logM + P + X) - /// # + /// ## Complexity + /// - O(M + logM + P + X) + /// - M (len of members) + /// - P (number of payouts for a particular member) + /// - X (currency transfer call) #[pallet::call_index(6)] #[pallet::weight(T::BlockWeights::get().max_block / 10)] pub fn payout(origin: OriginFor) -> DispatchResult { @@ -1028,13 +963,8 @@ pub mod pallet { /// - `max_members` - The initial max number of members for the society. /// - `rules` - The rules of this society concerning membership. /// - /// # - /// - Two storage mutates to set `Head` and `Founder`. O(1) - /// - One storage write to add the first member to society. O(1) - /// - One event. - /// - /// Total Complexity: O(1) - /// # + /// ## Complexity + /// - O(1) #[pallet::call_index(7)] #[pallet::weight(T::BlockWeights::get().max_block / 10)] pub fn found( @@ -1063,13 +993,8 @@ pub mod pallet { /// the `Founder` and the `Head`. This implies that it may only be done when there is one /// member. /// - /// # - /// - Two storage reads O(1). - /// - Four storage removals O(1). - /// - One event. - /// - /// Total Complexity: O(1) - /// # + /// ## Complexity + /// - O(1) #[pallet::call_index(8)] #[pallet::weight(T::BlockWeights::get().max_block / 10)] pub fn unfound(origin: OriginFor) -> DispatchResult { @@ -1103,19 +1028,10 @@ pub mod pallet { /// - `forgive` - A boolean representing whether the suspension judgement origin forgives /// (`true`) or rejects (`false`) a suspended member. /// - /// # - /// Key: B (len of bids), M (len of members) - /// - One storage read to check `who` is a suspended member. O(1) - /// - Up to one storage write O(M) with O(log M) binary search to add a member back to - /// society. - /// - Up to 3 storage removals O(1) to clean up a removed member. - /// - Up to one storage write O(B) with O(B) search to remove vouched bid from bids. - /// - Up to one additional event if unvouch takes place. - /// - One storage removal. O(1) - /// - One event for the judgement. - /// - /// Total Complexity: O(M + logM + B) - /// # + /// ## Complexity + /// - O(M + logM + B) + /// - B (len of bids) + /// - M (len of members) #[pallet::call_index(9)] #[pallet::weight(T::BlockWeights::get().max_block / 10)] pub fn judge_suspended_member( @@ -1171,29 +1087,11 @@ pub mod pallet { /// - `who` - The suspended candidate to be judged. /// - `judgement` - `Approve`, `Reject`, or `Rebid`. /// - /// # - /// Key: B (len of bids), M (len of members), X (balance action) - /// - One storage read to check `who` is a suspended candidate. - /// - One storage removal of the suspended candidate. - /// - Approve Logic - /// - One storage read to get the available pot to pay users with. O(1) - /// - One storage write to update the available pot. O(1) - /// - One storage read to get the current block number. O(1) - /// - One storage read to get all members. O(M) - /// - Up to one unreserve currency action. - /// - Up to two new storage writes to payouts. - /// - Up to one storage write with O(log M) binary search to add a member to society. - /// - Reject Logic - /// - Up to one repatriate reserved currency action. O(X) - /// - Up to one storage write to ban the vouching member from vouching again. - /// - Rebid Logic - /// - Storage mutate with O(log B) binary search to place the user back into bids. - /// - Up to one additional event if unvouch takes place. - /// - One storage removal. - /// - One event for the judgement. - /// - /// Total Complexity: O(M + logM + B + X) - /// # + /// ## Complexity + /// - O(M + logM + B + X) + /// - B (len of bids) + /// - M (len of members) + /// - X (balance action) #[pallet::call_index(10)] #[pallet::weight(T::BlockWeights::get().max_block / 10)] pub fn judge_suspended_candidate( @@ -1262,12 +1160,8 @@ pub mod pallet { /// Parameters: /// - `max` - The maximum number of members for the society. /// - /// # - /// - One storage write to update the max. O(1) - /// - One event. - /// - /// Total Complexity: O(1) - /// # + /// ## Complexity + /// - O(1) #[pallet::call_index(11)] #[pallet::weight(T::BlockWeights::get().max_block / 10)] pub fn set_max_members(origin: OriginFor, max: u32) -> DispatchResult { diff --git a/frame/staking/src/pallet/mod.rs b/frame/staking/src/pallet/mod.rs index c0c18b40cf02f..4b0e8133bc0b6 100644 --- a/frame/staking/src/pallet/mod.rs +++ b/frame/staking/src/pallet/mod.rs @@ -840,15 +840,13 @@ pub mod pallet { /// The dispatch origin for this call must be _Signed_ by the stash account. /// /// Emits `Bonded`. - /// # + /// ## Complexity /// - Independent of the arguments. Moderate complexity. /// - O(1). /// - Three extra DB entries. /// /// NOTE: Two of the storage writes (`Self::bonded`, `Self::payee`) are _never_ cleaned /// unless the `origin` falls below _existential deposit_ and gets removed as dust. - /// ------------------ - /// # #[pallet::call_index(0)] #[pallet::weight(T::WeightInfo::bond())] pub fn bond( @@ -915,10 +913,9 @@ pub mod pallet { /// /// Emits `Bonded`. /// - /// # + /// ## Complexity /// - Independent of the arguments. Insignificant complexity. /// - O(1). - /// # #[pallet::call_index(1)] #[pallet::weight(T::WeightInfo::bond_extra())] pub fn bond_extra( @@ -1076,10 +1073,9 @@ pub mod pallet { /// /// See also [`Call::unbond`]. /// - /// # - /// Complexity O(S) where S is the number of slashing spans to remove + /// ## Complexity + /// O(S) where S is the number of slashing spans to remove /// NOTE: Weight annotation is the kill scenario, we refund otherwise. - /// # #[pallet::call_index(3)] #[pallet::weight(T::WeightInfo::withdraw_unbonded_kill(*num_slashing_spans))] pub fn withdraw_unbonded( @@ -1136,11 +1132,10 @@ pub mod pallet { /// /// The dispatch origin for this call must be _Signed_ by the controller, not the stash. /// - /// # + /// ## Complexity /// - The transaction's complexity is proportional to the size of `targets` (N) /// which is capped at CompactAssignments::LIMIT (T::MaxNominations). /// - Both the reads and writes follow a similar pattern. - /// # #[pallet::call_index(5)] #[pallet::weight(T::WeightInfo::nominate(targets.len() as u32))] pub fn nominate( @@ -1205,11 +1200,10 @@ pub mod pallet { /// /// The dispatch origin for this call must be _Signed_ by the controller, not the stash. /// - /// # + /// ## Complexity /// - Independent of the arguments. Insignificant complexity. /// - Contains one read. /// - Writes are limited to the `origin` account key. - /// # #[pallet::call_index(6)] #[pallet::weight(T::WeightInfo::chill())] pub fn chill(origin: OriginFor) -> DispatchResult { @@ -1225,16 +1219,12 @@ pub mod pallet { /// /// The dispatch origin for this call must be _Signed_ by the controller, not the stash. /// - /// # + /// ## Complexity + /// - O(1) /// - Independent of the arguments. Insignificant complexity. /// - Contains a limited number of reads. /// - Writes are limited to the `origin` account key. /// --------- - /// - Weight: O(1) - /// - DB Weight: - /// - Read: Ledger - /// - Write: Payee - /// # #[pallet::call_index(7)] #[pallet::weight(T::WeightInfo::set_payee())] pub fn set_payee( @@ -1254,16 +1244,11 @@ pub mod pallet { /// /// The dispatch origin for this call must be _Signed_ by the stash, not the controller. /// - /// # + /// ## Complexity + /// O(1) /// - Independent of the arguments. Insignificant complexity. /// - Contains a limited number of reads. /// - Writes are limited to the `origin` account key. - /// ---------- - /// Weight: O(1) - /// DB Weight: - /// - Read: Bonded, Ledger New Controller, Ledger Old Controller - /// - Write: Bonded, Ledger New Controller, Ledger Old Controller - /// # #[pallet::call_index(8)] #[pallet::weight(T::WeightInfo::set_controller())] pub fn set_controller( @@ -1289,10 +1274,8 @@ pub mod pallet { /// /// The dispatch origin must be Root. /// - /// # - /// Weight: O(1) - /// Write: Validator Count - /// # + /// ## Complexity + /// O(1) #[pallet::call_index(9)] #[pallet::weight(T::WeightInfo::set_validator_count())] pub fn set_validator_count( @@ -1315,9 +1298,8 @@ pub mod pallet { /// /// The dispatch origin must be Root. /// - /// # + /// ## Complexity /// Same as [`Self::set_validator_count`]. - /// # #[pallet::call_index(10)] #[pallet::weight(T::WeightInfo::set_validator_count())] pub fn increase_validator_count( @@ -1341,9 +1323,8 @@ pub mod pallet { /// /// The dispatch origin must be Root. /// - /// # + /// ## Complexity /// Same as [`Self::set_validator_count`]. - /// # #[pallet::call_index(11)] #[pallet::weight(T::WeightInfo::set_validator_count())] pub fn scale_validator_count(origin: OriginFor, factor: Percent) -> DispatchResult { @@ -1370,11 +1351,9 @@ pub mod pallet { /// Thus the election process may be ongoing when this is called. In this case the /// election will continue until the next era is triggered. /// - /// # + /// ## Complexity /// - No arguments. /// - Weight: O(1) - /// - Write: ForceEra - /// # #[pallet::call_index(12)] #[pallet::weight(T::WeightInfo::force_no_eras())] pub fn force_no_eras(origin: OriginFor) -> DispatchResult { @@ -1394,11 +1373,9 @@ pub mod pallet { /// If this is called just before a new era is triggered, the election process may not /// have enough blocks to get a result. /// - /// # + /// ## Complexity /// - No arguments. /// - Weight: O(1) - /// - Write ForceEra - /// # #[pallet::call_index(13)] #[pallet::weight(T::WeightInfo::force_new_era())] pub fn force_new_era(origin: OriginFor) -> DispatchResult { @@ -1497,18 +1474,8 @@ pub mod pallet { /// The origin of this call must be _Signed_. Any account can call this function, even if /// it is not one of the stakers. /// - /// # - /// - Time complexity: at most O(MaxNominatorRewardedPerValidator). - /// - Contains a limited number of reads and writes. - /// ----------- - /// N is the Number of payouts for the validator (including the validator) - /// Weight: - /// - Reward Destination Staked: O(N) - /// - Reward Destination Controller (Creating): O(N) - /// - /// NOTE: weights are assuming that payouts are made to alive stash account (Staked). - /// Paying even a dead controller is cheaper weight-wise. We don't do any refunds here. - /// # + /// ## Complexity + /// - At most O(MaxNominatorRewardedPerValidator). #[pallet::call_index(18)] #[pallet::weight(T::WeightInfo::payout_stakers_alive_staked( T::MaxNominatorRewardedPerValidator::get() @@ -1526,11 +1493,9 @@ pub mod pallet { /// /// The dispatch origin must be signed by the controller. /// - /// # + /// ## Complexity /// - Time complexity: O(L), where L is unlocking chunks /// - Bounded by `MaxUnlockingChunks`. - /// - Storage changes: Can't increase storage, only decrease it. - /// # #[pallet::call_index(19)] #[pallet::weight(T::WeightInfo::rebond(T::MaxUnlockingChunks::get() as u32))] pub fn rebond( diff --git a/frame/sudo/src/lib.rs b/frame/sudo/src/lib.rs index 0867f24b1691e..3a708b6d5d6b1 100644 --- a/frame/sudo/src/lib.rs +++ b/frame/sudo/src/lib.rs @@ -142,12 +142,8 @@ pub mod pallet { /// /// The dispatch origin for this call must be _Signed_. /// - /// # + /// ## Complexity /// - O(1). - /// - Limited storage reads. - /// - One DB write (event). - /// - Weight of derivative `call` execution + 10,000. - /// # #[pallet::call_index(0)] #[pallet::weight({ let dispatch_info = call.get_dispatch_info(); @@ -173,10 +169,8 @@ pub mod pallet { /// /// The dispatch origin for this call must be _Signed_. /// - /// # + /// ## Complexity /// - O(1). - /// - The weight of this call is defined by the caller. - /// # #[pallet::call_index(1)] #[pallet::weight((*_weight, call.get_dispatch_info().class))] pub fn sudo_unchecked_weight( @@ -199,11 +193,8 @@ pub mod pallet { /// /// The dispatch origin for this call must be _Signed_. /// - /// # + /// ## Complexity /// - O(1). - /// - Limited storage reads. - /// - One DB change. - /// # #[pallet::call_index(2)] #[pallet::weight(0)] pub fn set_key( @@ -226,12 +217,8 @@ pub mod pallet { /// /// The dispatch origin for this call must be _Signed_. /// - /// # + /// ## Complexity /// - O(1). - /// - Limited storage reads. - /// - One DB write (event). - /// - Weight of derivative `call` execution + 10,000. - /// # #[pallet::call_index(3)] #[pallet::weight({ let dispatch_info = call.get_dispatch_info(); diff --git a/frame/system/src/lib.rs b/frame/system/src/lib.rs index c5d1706006154..c22a68296a159 100644 --- a/frame/system/src/lib.rs +++ b/frame/system/src/lib.rs @@ -374,9 +374,8 @@ pub mod pallet { impl Pallet { /// Make some on-chain remark. /// - /// # + /// ## Complexity /// - `O(1)` - /// # #[pallet::call_index(0)] #[pallet::weight(T::SystemWeightInfo::remark(_remark.len() as u32))] pub fn remark(origin: OriginFor, _remark: Vec) -> DispatchResultWithPostInfo { @@ -396,16 +395,8 @@ pub mod pallet { /// Set the new runtime code. /// - /// # + /// ## Complexity /// - `O(C + S)` where `C` length of `code` and `S` complexity of `can_set_code` - /// - 1 call to `can_set_code`: `O(S)` (calls `sp_io::misc::runtime_version` which is - /// expensive). - /// - 1 storage write (codec `O(C)`). - /// - 1 digest item. - /// - 1 event. - /// The weight of this function is dependent on the runtime, but generally this is very - /// expensive. We will treat this as a full block. - /// # #[pallet::call_index(2)] #[pallet::weight((T::BlockWeights::get().max_block, DispatchClass::Operational))] pub fn set_code(origin: OriginFor, code: Vec) -> DispatchResultWithPostInfo { @@ -417,13 +408,8 @@ pub mod pallet { /// Set the new runtime code without doing any checks of the given `code`. /// - /// # + /// ## Complexity /// - `O(C)` where `C` length of `code` - /// - 1 storage write (codec `O(C)`). - /// - 1 digest item. - /// - 1 event. - /// The weight of this function is dependent on the runtime. We will treat this as a full - /// block. # #[pallet::call_index(3)] #[pallet::weight((T::BlockWeights::get().max_block, DispatchClass::Operational))] pub fn set_code_without_checks( @@ -1423,10 +1409,8 @@ impl Pallet { /// Deposits a log and ensures it matches the block's log data. /// - /// # + /// ## Complexity /// - `O(1)` - /// - 1 storage write (codec `O(1)`) - /// # pub fn deposit_log(item: generic::DigestItem) { >::append(item); } diff --git a/frame/timestamp/src/lib.rs b/frame/timestamp/src/lib.rs index e859474c2cb9e..6e9c887824d17 100644 --- a/frame/timestamp/src/lib.rs +++ b/frame/timestamp/src/lib.rs @@ -171,10 +171,8 @@ pub mod pallet { T::WeightInfo::on_finalize() } - /// # + /// ## Complexity /// - `O(1)` - /// - 1 storage deletion (codec `O(1)`). - /// # fn on_finalize(_n: BlockNumberFor) { assert!(DidUpdate::::take(), "Timestamp must be updated once in the block"); } @@ -192,12 +190,11 @@ pub mod pallet { /// /// The dispatch origin for this call must be `Inherent`. /// - /// # + /// ## Complexity /// - `O(1)` (Note that implementations of `OnTimestampSet` must also be `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`. Must be `O(1)`. - /// # #[pallet::call_index(0)] #[pallet::weight(( T::WeightInfo::set(), diff --git a/frame/tips/src/lib.rs b/frame/tips/src/lib.rs index 43002c7b5f196..175fc3ac39d02 100644 --- a/frame/tips/src/lib.rs +++ b/frame/tips/src/lib.rs @@ -231,12 +231,9 @@ pub mod pallet { /// /// Emits `NewTip` if successful. /// - /// # - /// - Complexity: `O(R)` where `R` length of `reason`. + /// ## Complexity + /// - `O(R)` where `R` length of `reason`. /// - encoding and hashing of 'reason' - /// - DbReads: `Reasons`, `Tips` - /// - DbWrites: `Reasons`, `Tips` - /// # #[pallet::call_index(0)] #[pallet::weight(>::WeightInfo::report_awesome(reason.len() as u32))] pub fn report_awesome( @@ -289,12 +286,9 @@ pub mod pallet { /// /// Emits `TipRetracted` if successful. /// - /// # - /// - Complexity: `O(1)` + /// ## Complexity + /// - `O(1)` /// - Depends on the length of `T::Hash` which is fixed. - /// - DbReads: `Tips`, `origin account` - /// - DbWrites: `Reasons`, `Tips`, `origin account` - /// # #[pallet::call_index(1)] #[pallet::weight(>::WeightInfo::retract_tip())] pub fn retract_tip(origin: OriginFor, hash: T::Hash) -> DispatchResult { @@ -325,15 +319,12 @@ pub mod pallet { /// /// Emits `NewTip` if successful. /// - /// # - /// - Complexity: `O(R + T)` where `R` length of `reason`, `T` is the number of tippers. + /// ## Complexity + /// - `O(R + T)` where `R` length of `reason`, `T` is the number of tippers. /// - `O(T)`: decoding `Tipper` vec of length `T`. `T` is charged as upper bound given by /// `ContainsLengthBound`. The actual cost depends on the implementation of /// `T::Tippers`. /// - `O(R)`: hashing and encoding of reason of length `R` - /// - DbReads: `Tippers`, `Reasons` - /// - DbWrites: `Reasons`, `Tips` - /// # #[pallet::call_index(2)] #[pallet::weight(>::WeightInfo::tip_new(reason.len() as u32, T::Tippers::max_len() as u32))] pub fn tip_new( @@ -379,16 +370,13 @@ pub mod pallet { /// Emits `TipClosing` if the threshold of tippers has been reached and the countdown period /// has started. /// - /// # - /// - Complexity: `O(T)` where `T` is the number of tippers. decoding `Tipper` vec of length - /// `T`, insert tip and check closing, `T` is charged as upper bound given by - /// `ContainsLengthBound`. The actual cost depends on the implementation of `T::Tippers`. + /// ## Complexity + /// - `O(T)` where `T` is the number of tippers. decoding `Tipper` vec of length `T`, insert + /// tip and check closing, `T` is charged as upper bound given by `ContainsLengthBound`. + /// The actual cost depends on the implementation of `T::Tippers`. /// /// Actually weight could be lower as it depends on how many tips are in `OpenTip` but it /// is weighted as if almost full i.e of length `T-1`. - /// - DbReads: `Tippers`, `Tips` - /// - DbWrites: `Tips` - /// # #[pallet::call_index(3)] #[pallet::weight(>::WeightInfo::tip(T::Tippers::max_len() as u32))] pub fn tip( @@ -416,13 +404,10 @@ pub mod pallet { /// - `hash`: The identity of the open tip for which a tip value is declared. This is formed /// as the hash of the tuple of the original tip `reason` and the beneficiary account ID. /// - /// # - /// - Complexity: `O(T)` where `T` is the number of tippers. decoding `Tipper` vec of length - /// `T`. `T` is charged as upper bound given by `ContainsLengthBound`. The actual cost - /// depends on the implementation of `T::Tippers`. - /// - DbReads: `Tips`, `Tippers`, `tip finder` - /// - DbWrites: `Reasons`, `Tips`, `Tippers`, `tip finder` - /// # + /// ## Complexity + /// - : `O(T)` where `T` is the number of tippers. decoding `Tipper` vec of length `T`. `T` + /// is charged as upper bound given by `ContainsLengthBound`. The actual cost depends on + /// the implementation of `T::Tippers`. #[pallet::call_index(4)] #[pallet::weight(>::WeightInfo::close_tip(T::Tippers::max_len() as u32))] pub fn close_tip(origin: OriginFor, hash: T::Hash) -> DispatchResult { @@ -446,10 +431,8 @@ pub mod pallet { /// /// Emits `TipSlashed` if successful. /// - /// # - /// `T` is charged as upper bound given by `ContainsLengthBound`. - /// The actual cost depends on the implementation of `T::Tippers`. - /// # + /// ## Complexity + /// - O(1). #[pallet::call_index(5)] #[pallet::weight(>::WeightInfo::slash_tip(T::Tippers::max_len() as u32))] pub fn slash_tip(origin: OriginFor, hash: T::Hash) -> DispatchResult { diff --git a/frame/transaction-storage/src/lib.rs b/frame/transaction-storage/src/lib.rs index cda7610efdf87..aaa484d58ad28 100644 --- a/frame/transaction-storage/src/lib.rs +++ b/frame/transaction-storage/src/lib.rs @@ -184,10 +184,9 @@ pub mod pallet { impl Pallet { /// Index and store data off chain. Minimum data size is 1 bytes, maximum is /// `MaxTransactionSize`. Data will be removed after `STORAGE_PERIOD` blocks, unless `renew` - /// is called. # - /// - n*log(n) of data size, as all data is pushed to an in-memory trie. - /// Additionally contains a DB write. - /// # + /// is called. + /// ## Complexity + /// - O(n*log(n)) of data size, as all data is pushed to an in-memory trie. #[pallet::call_index(0)] #[pallet::weight(T::WeightInfo::store(data.len() as u32))] pub fn store(origin: OriginFor, data: Vec) -> DispatchResult { @@ -234,9 +233,8 @@ pub mod pallet { /// previous `store` or `renew` call and transaction index within that block. /// Transaction index is emitted in the `Stored` or `Renewed` event. /// Applies same fees as `store`. - /// # - /// - Constant. - /// # + /// ## Complexity + /// - O(1). #[pallet::call_index(1)] #[pallet::weight(T::WeightInfo::renew())] pub fn renew( @@ -277,12 +275,10 @@ pub mod pallet { /// Check storage proof for block number `block_number() - StoragePeriod`. /// If such block does not exist the proof is expected to be `None`. - /// # + /// ## Complexity /// - Linear w.r.t the number of indexed transactions in the proved block for random /// probing. /// There's a DB read for each transaction. - /// Here we assume a maximum of 100 probed transactions. - /// # #[pallet::call_index(2)] #[pallet::weight((T::WeightInfo::check_proof_max(), DispatchClass::Mandatory))] pub fn check_proof( diff --git a/frame/treasury/src/lib.rs b/frame/treasury/src/lib.rs index 1bde1238191a4..f5ca0a984bc49 100644 --- a/frame/treasury/src/lib.rs +++ b/frame/treasury/src/lib.rs @@ -315,13 +315,8 @@ pub mod pallet { #[pallet::hooks] impl, I: 'static> Hooks> for Pallet { - /// # - /// - Complexity: `O(A)` where `A` is the number of approvals - /// - Db reads and writes: `Approvals`, `pot account data` - /// - Db reads and writes per approval: `Proposals`, `proposer account data`, `beneficiary - /// account data` - /// - The weight is overestimated if some approvals got missed. - /// # + /// ## Complexity + /// - `O(A)` where `A` is the number of approvals fn on_initialize(n: T::BlockNumber) -> Weight { let pot = Self::pot(); let deactivated = Deactivated::::get(); @@ -350,11 +345,8 @@ pub mod pallet { /// is reserved and slashed if the proposal is rejected. It is returned once the /// proposal is awarded. /// - /// # - /// - Complexity: O(1) - /// - DbReads: `ProposalCount`, `origin account` - /// - DbWrites: `ProposalCount`, `Proposals`, `origin account` - /// # + /// ## Complexity + /// - O(1) #[pallet::call_index(0)] #[pallet::weight(T::WeightInfo::propose_spend())] pub fn propose_spend( @@ -381,11 +373,8 @@ pub mod pallet { /// /// May only be called from `T::RejectOrigin`. /// - /// # - /// - Complexity: O(1) - /// - DbReads: `Proposals`, `rejected proposer account` - /// - DbWrites: `Proposals`, `rejected proposer account` - /// # + /// ## Complexity + /// - O(1) #[pallet::call_index(1)] #[pallet::weight((T::WeightInfo::reject_proposal(), DispatchClass::Operational))] pub fn reject_proposal( @@ -412,11 +401,8 @@ pub mod pallet { /// /// May only be called from `T::ApproveOrigin`. /// - /// # - /// - Complexity: O(1). - /// - DbReads: `Proposals`, `Approvals` - /// - DbWrite: `Approvals` - /// # + /// ## Complexity + /// - O(1). #[pallet::call_index(2)] #[pallet::weight((T::WeightInfo::approve_proposal(T::MaxApprovals::get()), DispatchClass::Operational))] pub fn approve_proposal( @@ -472,10 +458,8 @@ pub mod pallet { /// May only be called from `T::RejectOrigin`. /// - `proposal_id`: The index of a proposal /// - /// # - /// - Complexity: O(A) where `A` is the number of approvals - /// - Db reads and writes: `Approvals` - /// # + /// ## Complexity + /// - O(A) where `A` is the number of approvals /// /// Errors: /// - `ProposalNotApproved`: The `proposal_id` supplied was not found in the approval queue, diff --git a/frame/utility/src/lib.rs b/frame/utility/src/lib.rs index 2d60ae15679d5..a28dd4994dfa6 100644 --- a/frame/utility/src/lib.rs +++ b/frame/utility/src/lib.rs @@ -172,9 +172,8 @@ pub mod pallet { /// If origin is root then the calls are dispatched without checking origin filter. (This /// includes bypassing `frame_system::Config::BaseCallFilter`). /// - /// # - /// - Complexity: O(C) where C is the number of calls to be batched. - /// # + /// ## Complexity + /// - O(C) where C is the number of calls to be batched. /// /// This will return `Ok` in all circumstances. To determine the success of the batch, an /// event is deposited. If a call failed and the batch was interrupted, then the @@ -301,9 +300,8 @@ pub mod pallet { /// If origin is root then the calls are dispatched without checking origin filter. (This /// includes bypassing `frame_system::Config::BaseCallFilter`). /// - /// # - /// - Complexity: O(C) where C is the number of calls to be batched. - /// # + /// ## Complexity + /// - O(C) where C is the number of calls to be batched. #[pallet::call_index(2)] #[pallet::weight({ let dispatch_infos = calls.iter().map(|call| call.get_dispatch_info()).collect::>(); @@ -374,12 +372,8 @@ pub mod pallet { /// /// The dispatch origin for this call must be _Root_. /// - /// # + /// ## Complexity /// - O(1). - /// - Limited storage reads. - /// - One DB write (event). - /// - Weight of derivative `call` execution + T::WeightInfo::dispatch_as(). - /// # #[pallet::call_index(3)] #[pallet::weight({ let dispatch_info = call.get_dispatch_info(); @@ -415,9 +409,8 @@ pub mod pallet { /// If origin is root then the calls are dispatch without checking origin filter. (This /// includes bypassing `frame_system::Config::BaseCallFilter`). /// - /// # - /// - Complexity: O(C) where C is the number of calls to be batched. - /// # + /// ## Complexity + /// - O(C) where C is the number of calls to be batched. #[pallet::call_index(4)] #[pallet::weight({ let dispatch_infos = calls.iter().map(|call| call.get_dispatch_info()).collect::>(); diff --git a/frame/vesting/src/lib.rs b/frame/vesting/src/lib.rs index 3439608af3ce4..6cde546f387b4 100644 --- a/frame/vesting/src/lib.rs +++ b/frame/vesting/src/lib.rs @@ -297,12 +297,8 @@ pub mod pallet { /// /// Emits either `VestingCompleted` or `VestingUpdated`. /// - /// # + /// ## Complexity /// - `O(1)`. - /// - DbWeight: 2 Reads, 2 Writes - /// - Reads: Vesting Storage, Balances Locks, [Sender Account] - /// - Writes: Vesting Storage, Balances Locks, [Sender Account] - /// # #[pallet::call_index(0)] #[pallet::weight(T::WeightInfo::vest_locked(MaxLocksOf::::get(), T::MAX_VESTING_SCHEDULES) .max(T::WeightInfo::vest_unlocked(MaxLocksOf::::get(), T::MAX_VESTING_SCHEDULES)) @@ -321,12 +317,8 @@ pub mod pallet { /// /// Emits either `VestingCompleted` or `VestingUpdated`. /// - /// # + /// ## Complexity /// - `O(1)`. - /// - DbWeight: 3 Reads, 3 Writes - /// - Reads: Vesting Storage, Balances Locks, Target Account - /// - Writes: Vesting Storage, Balances Locks, Target Account - /// # #[pallet::call_index(1)] #[pallet::weight(T::WeightInfo::vest_other_locked(MaxLocksOf::::get(), T::MAX_VESTING_SCHEDULES) .max(T::WeightInfo::vest_other_unlocked(MaxLocksOf::::get(), T::MAX_VESTING_SCHEDULES)) @@ -348,12 +340,8 @@ pub mod pallet { /// /// NOTE: This will unlock all schedules through the current block. /// - /// # + /// ## Complexity /// - `O(1)`. - /// - DbWeight: 3 Reads, 3 Writes - /// - Reads: Vesting Storage, Balances Locks, Target Account, [Sender Account] - /// - Writes: Vesting Storage, Balances Locks, Target Account, [Sender Account] - /// # #[pallet::call_index(2)] #[pallet::weight( T::WeightInfo::vested_transfer(MaxLocksOf::::get(), T::MAX_VESTING_SCHEDULES) @@ -380,12 +368,8 @@ pub mod pallet { /// /// NOTE: This will unlock all schedules through the current block. /// - /// # + /// ## Complexity /// - `O(1)`. - /// - DbWeight: 4 Reads, 4 Writes - /// - Reads: Vesting Storage, Balances Locks, Target Account, Source Account - /// - Writes: Vesting Storage, Balances Locks, Target Account, Source Account - /// # #[pallet::call_index(3)] #[pallet::weight( T::WeightInfo::force_vested_transfer(MaxLocksOf::::get(), T::MAX_VESTING_SCHEDULES)