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

Fix democracy on-initialize weight #9890

Merged
8 commits merged into from
Sep 30, 2021
Merged
Changes from 2 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
12 changes: 7 additions & 5 deletions frame/democracy/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1726,7 +1726,8 @@ impl<T: Config> Pallet<T> {
///
///
/// # <weight>
/// If a referendum is launched or maturing, this will take full block weight. Otherwise:
/// 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`
Expand All @@ -1739,10 +1740,11 @@ impl<T: Config> Pallet<T> {

// pick out another public referendum if it's time.
if (now % T::LaunchPeriod::get()).is_zero() {
// Errors come from the queue being empty. we don't really care about that, and even if
// we did, there is nothing we can do here.
let _ = Self::launch_next(now);
weight = max_block_weight;
// Errors come from the queue being empty. If the queue is not empty, it will take
// full block weight.
if Self::launch_next(now).is_ok() {
weight = max_block_weight;
}
Copy link
Member

Choose a reason for hiding this comment

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

What we should do here is actually create a benchmark of how much time it takes to process an empty queue, and use that weight here.

You are right that this is probably a huge overestimate, but not recording any weight at all is probably worse than this.

Are you familiar with how do make the benchmark, and are you interested to complete that?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

completed.

}

let next = Self::lowest_unbaked();
Expand Down