Skip to content

Commit

Permalink
cleanup <weight></weight> from docs comments (paritytech#13350)
Browse files Browse the repository at this point in the history
* cleanup <weight></weight> from docs comments

* Changes to address review commnets

* Fix CI cargo test --docs

---------

Co-authored-by: parity-processbot <>
  • Loading branch information
vivekvpandya authored and ukint-vs committed Apr 10, 2023
1 parent 6ad789e commit a9eb41d
Show file tree
Hide file tree
Showing 22 changed files with 202 additions and 635 deletions.
14 changes: 4 additions & 10 deletions frame/balances/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ pub mod pallet {
///
/// The dispatch origin for this call must be `Signed` by the transactor.
///
/// # <weight>
/// ## 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
Expand All @@ -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.
/// # </weight>
#[pallet::call_index(0)]
#[pallet::weight(T::WeightInfo::transfer())]
pub fn transfer(
Expand Down Expand Up @@ -360,10 +357,9 @@ pub mod pallet {

/// Exactly as `transfer`, except the origin must be root and the source account may be
/// specified.
/// # <weight>
/// ## Complexity
/// - Same as transfer, but additional read and write because the source account is not
/// assumed to be in the overlay.
/// # </weight>
#[pallet::call_index(2)]
#[pallet::weight(T::WeightInfo::force_transfer())]
pub fn force_transfer(
Expand Down Expand Up @@ -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). # <weight>
/// keep the sender account alive (true). ## Complexity
/// - O(1). Just like transfer, but reading the user's transferable balance first.
/// #</weight>
#[pallet::call_index(4)]
#[pallet::weight(T::WeightInfo::transfer_all())]
pub fn transfer_all(
Expand Down Expand Up @@ -1484,10 +1479,9 @@ where
// restrictions like locks and vesting balance.
// Is a no-op if amount to be withdrawn is zero.
//
// # <weight>
// ## 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.
// # </weight>
fn ensure_can_withdraw(
who: &T::AccountId,
amount: T::Balance,
Expand Down
24 changes: 8 additions & 16 deletions frame/bounties/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -349,9 +349,8 @@ pub mod pallet {
///
/// May only be called from `T::SpendOrigin`.
///
/// # <weight>
/// ## Complexity
/// - O(1).
/// # </weight>
#[pallet::call_index(1)]
#[pallet::weight(<T as Config<I>>::WeightInfo::approve_bounty())]
pub fn approve_bounty(
Expand Down Expand Up @@ -381,9 +380,8 @@ pub mod pallet {
///
/// May only be called from `T::SpendOrigin`.
///
/// # <weight>
/// ## Complexity
/// - O(1).
/// # </weight>
#[pallet::call_index(2)]
#[pallet::weight(<T as Config<I>>::WeightInfo::propose_curator())]
pub fn propose_curator(
Expand Down Expand Up @@ -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.
///
/// # <weight>
/// ## Complexity
/// - O(1).
/// # </weight>
#[pallet::call_index(3)]
#[pallet::weight(<T as Config<I>>::WeightInfo::unassign_curator())]
pub fn unassign_curator(
Expand Down Expand Up @@ -517,9 +514,8 @@ pub mod pallet {
///
/// May only be called from the curator.
///
/// # <weight>
/// ## Complexity
/// - O(1).
/// # </weight>
#[pallet::call_index(4)]
#[pallet::weight(<T as Config<I>>::WeightInfo::accept_curator())]
pub fn accept_curator(
Expand Down Expand Up @@ -560,9 +556,8 @@ pub mod pallet {
/// - `bounty_id`: Bounty ID to award.
/// - `beneficiary`: The beneficiary account whom will receive the payout.
///
/// # <weight>
/// ## Complexity
/// - O(1).
/// # </weight>
#[pallet::call_index(5)]
#[pallet::weight(<T as Config<I>>::WeightInfo::award_bounty())]
pub fn award_bounty(
Expand Down Expand Up @@ -608,9 +603,8 @@ pub mod pallet {
///
/// - `bounty_id`: Bounty ID to claim.
///
/// # <weight>
/// ## Complexity
/// - O(1).
/// # </weight>
#[pallet::call_index(6)]
#[pallet::weight(<T as Config<I>>::WeightInfo::claim_bounty())]
pub fn claim_bounty(
Expand Down Expand Up @@ -672,9 +666,8 @@ pub mod pallet {
///
/// - `bounty_id`: Bounty ID to cancel.
///
/// # <weight>
/// ## Complexity
/// - O(1).
/// # </weight>
#[pallet::call_index(7)]
#[pallet::weight(<T as Config<I>>::WeightInfo::close_bounty_proposed()
.max(<T as Config<I>>::WeightInfo::close_bounty_active()))]
Expand Down Expand Up @@ -764,9 +757,8 @@ pub mod pallet {
/// - `bounty_id`: Bounty ID to extend.
/// - `remark`: additional information.
///
/// # <weight>
/// ## Complexity
/// - O(1).
/// # </weight>
#[pallet::call_index(8)]
#[pallet::weight(<T as Config<I>>::WeightInfo::extend_bounty_expiry())]
pub fn extend_bounty_expiry(
Expand Down
82 changes: 13 additions & 69 deletions frame/collective/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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>
/// ## 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
/// # </weight>
#[pallet::call_index(0)]
#[pallet::weight((
T::WeightInfo::set_members(
Expand Down Expand Up @@ -428,13 +420,11 @@ pub mod pallet {
///
/// Origin must be a member of the collective.
///
/// # <weight>
/// ## 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
/// # </weight>
/// ## 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(
Expand Down Expand Up @@ -479,26 +469,13 @@ pub mod pallet {
/// `threshold` determines whether `proposal` is executed directly (`threshold < 2`)
/// or put up for voting.
///
/// # <weight>
/// ## 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
/// # </weight>
#[pallet::call_index(2)]
#[pallet::weight((
if *threshold < 2 {
Expand Down Expand Up @@ -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>
/// ## 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
/// # </weight>
#[pallet::call_index(3)]
#[pallet::weight((T::WeightInfo::vote(T::MaxMembers::get()), DispatchClass::Operational))]
pub fn vote(
Expand Down Expand Up @@ -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::<u32>() == 4` larger than the pure length.
///
/// # <weight>
/// ## 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
/// # </weight>
#[pallet::call_index(4)]
#[pallet::weight((
{
Expand Down Expand Up @@ -657,12 +620,8 @@ pub mod pallet {
/// Parameters:
/// * `proposal_hash`: The hash of the proposal that should be disapproved.
///
/// # <weight>
/// Complexity: O(P) where P is the number of max proposals
/// DB Weight:
/// * Reads: Proposals
/// * Writes: Voting, Proposals, ProposalOf
/// # </weight>
/// ## 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(
Expand Down Expand Up @@ -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::<u32>() == 4` larger than the pure length.
///
/// # <weight>
/// ## 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
/// # </weight>
#[pallet::call_index(6)]
#[pallet::weight((
{
Expand Down Expand Up @@ -1026,18 +977,11 @@ impl<T: Config<I>, I: 'static> ChangeMembers<T::AccountId> for Pallet<T, I> {
/// 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>
/// ## 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
/// # </weight>
fn change_members_sorted(
_incoming: &[T::AccountId],
outgoing: &[T::AccountId],
Expand Down
10 changes: 2 additions & 8 deletions frame/democracy/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1617,15 +1617,9 @@ impl<T: Config> Pallet<T> {
/// Current era is ending; we should finish up any proposals.
///
///
/// # <weight>
/// ## 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`
/// # </weight>
/// 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();
Expand Down
23 changes: 11 additions & 12 deletions frame/elections-phragmen/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
///
/// # <weight>
/// The number of current candidates must be provided as witness data.
/// # </weight>
/// ## 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(
Expand Down Expand Up @@ -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.
///
/// # <weight>
/// The type of renouncing must be provided as witness data.
/// # </weight>
///
/// ## 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),
Expand Down Expand Up @@ -542,10 +544,8 @@ pub mod pallet {
///
/// Note that this does not affect the designated block number of the next election.
///
/// # <weight>
/// 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.
/// # </weight>
/// ## 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()
Expand Down Expand Up @@ -579,9 +579,8 @@ pub mod pallet {
///
/// The dispatch origin of this call must be root.
///
/// # <weight>
/// The total number of voters and those that are defunct must be provided as witness data.
/// # </weight>
/// ## 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(
Expand Down
Loading

0 comments on commit a9eb41d

Please sign in to comment.