From b6505d743f5f29e228e90794724263c88fb886b0 Mon Sep 17 00:00:00 2001 From: Guillaume Thiolliere <gui.thiolliere@gmail.com> Date: Tue, 4 Aug 2020 19:58:03 +0200 Subject: [PATCH] pallet-democracy use of weightinfo (#6783) * democracy use of weightinfo * fix some doc and benchs * todo generate from parity machine * factorize and add license * use final weights * add slightly more sensible default weight * refactor * rename benchmark to avoid confusion * just make remove_other_vote benchmark being the worst case of the extrinsic --- substrate/bin/node/runtime/src/lib.rs | 2 +- substrate/bin/node/runtime/src/weights/mod.rs | 1 + .../runtime/src/weights/pallet_democracy.rs | 155 ++++++++++++ substrate/frame/democracy/src/benchmarking.rs | 86 ++----- .../frame/democracy/src/default_weight.rs | 158 +++++++++++++ substrate/frame/democracy/src/lib.rs | 223 +++++------------- 6 files changed, 395 insertions(+), 230 deletions(-) create mode 100644 substrate/bin/node/runtime/src/weights/pallet_democracy.rs create mode 100644 substrate/frame/democracy/src/default_weight.rs diff --git a/substrate/bin/node/runtime/src/lib.rs b/substrate/bin/node/runtime/src/lib.rs index fff0dd3427f..acc1b072818 100644 --- a/substrate/bin/node/runtime/src/lib.rs +++ b/substrate/bin/node/runtime/src/lib.rs @@ -495,7 +495,7 @@ impl pallet_democracy::Trait for Runtime { type Scheduler = Scheduler; type PalletsOrigin = OriginCaller; type MaxVotes = MaxVotes; - type WeightInfo = (); + type WeightInfo = weights::pallet_democracy::WeightInfo; } parameter_types! { diff --git a/substrate/bin/node/runtime/src/weights/mod.rs b/substrate/bin/node/runtime/src/weights/mod.rs index 70e10d5342f..70bae879ce0 100644 --- a/substrate/bin/node/runtime/src/weights/mod.rs +++ b/substrate/bin/node/runtime/src/weights/mod.rs @@ -16,3 +16,4 @@ //! A list of the different weight modules for our runtime. pub mod pallet_balances; +pub mod pallet_democracy; diff --git a/substrate/bin/node/runtime/src/weights/pallet_democracy.rs b/substrate/bin/node/runtime/src/weights/pallet_democracy.rs new file mode 100644 index 00000000000..2c55a848061 --- /dev/null +++ b/substrate/bin/node/runtime/src/weights/pallet_democracy.rs @@ -0,0 +1,155 @@ +// Copyright (C) 2020 Parity Technologies (UK) Ltd. +// SPDX-License-Identifier: Apache-2.0 + +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +//! Weights for the Democracy Pallet +//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 2.0.0-rc5 + +use frame_support::weights::{Weight, constants::RocksDbWeight as DbWeight}; + +pub struct WeightInfo; +impl pallet_democracy::WeightInfo for WeightInfo { + fn propose() -> Weight { + (49113000 as Weight) + .saturating_add(DbWeight::get().reads(2 as Weight)) + .saturating_add(DbWeight::get().writes(3 as Weight)) + } + fn second(s: u32, ) -> Weight { + (42067000 as Weight) + .saturating_add((220000 as Weight).saturating_mul(s as Weight)) + .saturating_add(DbWeight::get().reads(1 as Weight)) + .saturating_add(DbWeight::get().writes(1 as Weight)) + } + fn vote_new(r: u32, ) -> Weight { + (54159000 as Weight) + .saturating_add((252000 as Weight).saturating_mul(r as Weight)) + .saturating_add(DbWeight::get().reads(3 as Weight)) + .saturating_add(DbWeight::get().writes(3 as Weight)) + } + fn vote_existing(r: u32, ) -> Weight { + (54145000 as Weight) + .saturating_add((262000 as Weight).saturating_mul(r as Weight)) + .saturating_add(DbWeight::get().reads(3 as Weight)) + .saturating_add(DbWeight::get().writes(3 as Weight)) + } + fn emergency_cancel() -> Weight { + (31071000 as Weight) + .saturating_add(DbWeight::get().reads(2 as Weight)) + .saturating_add(DbWeight::get().writes(2 as Weight)) + } + fn external_propose(v: u32, ) -> Weight { + (14282000 as Weight) + .saturating_add((109000 as Weight).saturating_mul(v as Weight)) + .saturating_add(DbWeight::get().reads(2 as Weight)) + .saturating_add(DbWeight::get().writes(1 as Weight)) + } + fn external_propose_majority() -> Weight { + (3478000 as Weight) + .saturating_add(DbWeight::get().writes(1 as Weight)) + } + fn external_propose_default() -> Weight { + (3442000 as Weight) + .saturating_add(DbWeight::get().writes(1 as Weight)) + } + fn fast_track() -> Weight { + (30820000 as Weight) + .saturating_add(DbWeight::get().reads(2 as Weight)) + .saturating_add(DbWeight::get().writes(3 as Weight)) + } + fn veto_external(v: u32, ) -> Weight { + (30971000 as Weight) + .saturating_add((184000 as Weight).saturating_mul(v as Weight)) + .saturating_add(DbWeight::get().reads(2 as Weight)) + .saturating_add(DbWeight::get().writes(2 as Weight)) + } + fn cancel_referendum() -> Weight { + (20431000 as Weight) + .saturating_add(DbWeight::get().writes(1 as Weight)) + } + fn cancel_queued(r: u32, ) -> Weight { + (42438000 as Weight) + .saturating_add((3284000 as Weight).saturating_mul(r as Weight)) + .saturating_add(DbWeight::get().reads(2 as Weight)) + .saturating_add(DbWeight::get().writes(2 as Weight)) + } + fn on_initialize_base(r: u32, ) -> Weight { + (70826000 as Weight) + .saturating_add((10716000 as Weight).saturating_mul(r as Weight)) + .saturating_add(DbWeight::get().reads(6 as Weight)) + .saturating_add(DbWeight::get().reads((2 as Weight).saturating_mul(r as Weight))) + .saturating_add(DbWeight::get().writes(5 as Weight)) + } + fn delegate(r: u32, ) -> Weight { + (72046000 as Weight) + .saturating_add((7837000 as Weight).saturating_mul(r as Weight)) + .saturating_add(DbWeight::get().reads(4 as Weight)) + .saturating_add(DbWeight::get().reads((1 as Weight).saturating_mul(r as Weight))) + .saturating_add(DbWeight::get().writes(4 as Weight)) + .saturating_add(DbWeight::get().writes((1 as Weight).saturating_mul(r as Weight))) + } + fn undelegate(r: u32, ) -> Weight { + (41028000 as Weight) + .saturating_add((7810000 as Weight).saturating_mul(r as Weight)) + .saturating_add(DbWeight::get().reads(2 as Weight)) + .saturating_add(DbWeight::get().reads((1 as Weight).saturating_mul(r as Weight))) + .saturating_add(DbWeight::get().writes(2 as Weight)) + .saturating_add(DbWeight::get().writes((1 as Weight).saturating_mul(r as Weight))) + } + fn clear_public_proposals() -> Weight { + (3643000 as Weight) + .saturating_add(DbWeight::get().writes(1 as Weight)) + } + fn note_preimage(b: u32, ) -> Weight { + (46629000 as Weight) + .saturating_add((4000 as Weight).saturating_mul(b as Weight)) + .saturating_add(DbWeight::get().reads(1 as Weight)) + .saturating_add(DbWeight::get().writes(1 as Weight)) + } + fn note_imminent_preimage(b: u32, ) -> Weight { + (31147000 as Weight) + .saturating_add((3000 as Weight).saturating_mul(b as Weight)) + .saturating_add(DbWeight::get().reads(1 as Weight)) + .saturating_add(DbWeight::get().writes(1 as Weight)) + } + fn reap_preimage(b: u32, ) -> Weight { + (42848000 as Weight) + .saturating_add((3000 as Weight).saturating_mul(b as Weight)) + .saturating_add(DbWeight::get().reads(2 as Weight)) + .saturating_add(DbWeight::get().writes(1 as Weight)) + } + fn unlock_remove(r: u32, ) -> Weight { + (45333000 as Weight) + .saturating_add((171000 as Weight).saturating_mul(r as Weight)) + .saturating_add(DbWeight::get().reads(3 as Weight)) + .saturating_add(DbWeight::get().writes(3 as Weight)) + } + fn unlock_set(r: u32, ) -> Weight { + (44424000 as Weight) + .saturating_add((291000 as Weight).saturating_mul(r as Weight)) + .saturating_add(DbWeight::get().reads(3 as Weight)) + .saturating_add(DbWeight::get().writes(3 as Weight)) + } + fn remove_vote(r: u32, ) -> Weight { + (28250000 as Weight) + .saturating_add((283000 as Weight).saturating_mul(r as Weight)) + .saturating_add(DbWeight::get().reads(2 as Weight)) + .saturating_add(DbWeight::get().writes(2 as Weight)) + } + fn remove_other_vote(r: u32, ) -> Weight { + (28250000 as Weight) + .saturating_add((283000 as Weight).saturating_mul(r as Weight)) + .saturating_add(DbWeight::get().reads(2 as Weight)) + .saturating_add(DbWeight::get().writes(2 as Weight)) + } +} diff --git a/substrate/frame/democracy/src/benchmarking.rs b/substrate/frame/democracy/src/benchmarking.rs index 421eb07e32c..1fa0988fbbd 100644 --- a/substrate/frame/democracy/src/benchmarking.rs +++ b/substrate/frame/democracy/src/benchmarking.rs @@ -31,7 +31,6 @@ use crate::Module as Democracy; const SEED: u32 = 0; const MAX_REFERENDUMS: u32 = 100; -const MAX_PROPOSALS: u32 = 100; const MAX_SECONDERS: u32 = 100; const MAX_BYTES: u32 = 16_384; @@ -101,21 +100,12 @@ benchmarks! { _ { } propose { - let p in 1 .. MAX_PROPOSALS; - - // Add p proposals - for i in 0 .. p { - add_proposal::<T>(i)?; - } - - assert_eq!(Democracy::<T>::public_props().len(), p as usize, "Proposals not created."); - let caller = funded_account::<T>("caller", 0); - let proposal_hash: T::Hash = T::Hashing::hash_of(&p); + let proposal_hash: T::Hash = T::Hashing::hash_of(&0); let value = T::MinimumDeposit::get(); }: _(RawOrigin::Signed(caller), proposal_hash, value.into()) verify { - assert_eq!(Democracy::<T>::public_props().len(), (p + 1) as usize, "Proposals not created."); + assert_eq!(Democracy::<T>::public_props().len(), 1, "Proposals not created."); } second { @@ -206,18 +196,8 @@ benchmarks! { } emergency_cancel { - let r in 1 .. MAX_REFERENDUMS; let origin = T::CancellationOrigin::successful_origin(); - - // Create and cancel a bunch of referendums - for i in 0 .. r { - let ref_idx = add_referendum::<T>(i)?; - let call = Call::<T>::emergency_cancel(ref_idx); - call.dispatch_bypass_filter(origin.clone())?; - } - - // Lets now measure one more - let referendum_index = add_referendum::<T>(r)?; + let referendum_index = add_referendum::<T>(0)?; let call = Call::<T>::emergency_cancel(referendum_index); assert!(Democracy::<T>::referendum_status(referendum_index).is_ok()); }: { call.dispatch_bypass_filter(origin)? } @@ -228,11 +208,10 @@ benchmarks! { // Worst case scenario, we external propose a previously blacklisted proposal external_propose { - let p in 1 .. MAX_PROPOSALS; let v in 1 .. MAX_VETOERS as u32; let origin = T::ExternalOrigin::successful_origin(); - let proposal_hash = T::Hashing::hash_of(&p); + let proposal_hash = T::Hashing::hash_of(&0); // Add proposal to blacklist with block number 0 Blacklist::<T>::insert( proposal_hash, @@ -247,10 +226,8 @@ benchmarks! { } external_propose_majority { - let p in 1 .. MAX_PROPOSALS; - let origin = T::ExternalMajorityOrigin::successful_origin(); - let proposal_hash = T::Hashing::hash_of(&p); + let proposal_hash = T::Hashing::hash_of(&0); let call = Call::<T>::external_propose_majority(proposal_hash); }: { call.dispatch_bypass_filter(origin)? } verify { @@ -259,10 +236,8 @@ benchmarks! { } external_propose_default { - let p in 1 .. MAX_PROPOSALS; - let origin = T::ExternalDefaultOrigin::successful_origin(); - let proposal_hash = T::Hashing::hash_of(&p); + let proposal_hash = T::Hashing::hash_of(&0); let call = Call::<T>::external_propose_default(proposal_hash); }: { call.dispatch_bypass_filter(origin)? } verify { @@ -271,10 +246,8 @@ benchmarks! { } fast_track { - let p in 1 .. MAX_PROPOSALS; - let origin_propose = T::ExternalDefaultOrigin::successful_origin(); - let proposal_hash: T::Hash = T::Hashing::hash_of(&p); + let proposal_hash: T::Hash = T::Hashing::hash_of(&0); Democracy::<T>::external_propose_default(origin_propose, proposal_hash.clone())?; // NOTE: Instant origin may invoke a little bit more logic, but may not always succeed. @@ -315,24 +288,21 @@ benchmarks! { } cancel_referendum { - let r in 0 .. MAX_REFERENDUMS; - // Should have no effect on the execution time. - for i in 0..r { - add_referendum::<T>(i)?; - } - let referendum_index = add_referendum::<T>(r)?; + let referendum_index = add_referendum::<T>(0)?; }: _(RawOrigin::Root, referendum_index) cancel_queued { let r in 1 .. MAX_REFERENDUMS; - // Should have no effect on the execution time. + for i in 0..r { - add_referendum::<T>(i)?; + add_referendum::<T>(i)?; // This add one element in the scheduler } + let referendum_index = add_referendum::<T>(r)?; }: _(RawOrigin::Root, referendum_index) // Note that we have a separate benchmark for `launch_next` + #[extra] on_initialize_external { let r in 0 .. MAX_REFERENDUMS; @@ -371,6 +341,7 @@ benchmarks! { } } + #[extra] on_initialize_public { let r in 1 .. MAX_REFERENDUMS; @@ -401,7 +372,8 @@ benchmarks! { } } - on_initialize_no_launch_no_maturing { + // No launch no maturing referenda. + on_initialize_base { let r in 1 .. MAX_REFERENDUMS; for i in 0..r { @@ -526,11 +498,7 @@ benchmarks! { } clear_public_proposals { - let p in 0 .. MAX_PROPOSALS; - - for i in 0 .. p { - add_proposal::<T>(i)?; - } + add_proposal::<T>(0)?; }: _(RawOrigin::Root) @@ -687,41 +655,36 @@ benchmarks! { assert_eq!(votes.len(), (r - 1) as usize, "Vote was not removed"); } + // Worst case is when target == caller and referendum is ongoing remove_other_vote { let r in 1 .. MAX_REFERENDUMS; - let other = funded_account::<T>("other", r); + let caller = funded_account::<T>("caller", r); let account_vote = account_vote::<T>(100.into()); for i in 0 .. r { let ref_idx = add_referendum::<T>(i)?; - Democracy::<T>::vote(RawOrigin::Signed(other.clone()).into(), ref_idx, account_vote.clone())?; + Democracy::<T>::vote(RawOrigin::Signed(caller.clone()).into(), ref_idx, account_vote.clone())?; } - let votes = match VotingOf::<T>::get(&other) { + let votes = match VotingOf::<T>::get(&caller) { Voting::Direct { votes, .. } => votes, _ => return Err("Votes are not direct"), }; assert_eq!(votes.len(), r as usize, "Votes not created"); let referendum_index = r - 1; - ReferendumInfoOf::<T>::insert( - referendum_index, - ReferendumInfo::Finished { end: T::BlockNumber::zero(), approved: true } - ); - let caller = funded_account::<T>("caller", 0); - - System::<T>::set_block_number(T::EnactmentPeriod::get() * 10u32.into()); - }: _(RawOrigin::Signed(caller), other.clone(), referendum_index) + }: _(RawOrigin::Signed(caller.clone()), caller.clone(), referendum_index) verify { - let votes = match VotingOf::<T>::get(&other) { + let votes = match VotingOf::<T>::get(&caller) { Voting::Direct { votes, .. } => votes, _ => return Err("Votes are not direct"), }; assert_eq!(votes.len(), (r - 1) as usize, "Vote was not removed"); } + #[extra] enact_proposal_execute { // Num of bytes in encoded proposal let b in 0 .. MAX_BYTES; @@ -743,6 +706,7 @@ benchmarks! { assert_last_event::<T>(RawEvent::Executed(0, false).into()); } + #[extra] enact_proposal_slash { // Num of bytes in encoded proposal let b in 0 .. MAX_BYTES; @@ -788,7 +752,7 @@ mod tests { assert_ok!(test_benchmark_cancel_queued::<Test>()); assert_ok!(test_benchmark_on_initialize_external::<Test>()); assert_ok!(test_benchmark_on_initialize_public::<Test>()); - assert_ok!(test_benchmark_on_initialize_no_launch_no_maturing::<Test>()); + assert_ok!(test_benchmark_on_initialize_base::<Test>()); assert_ok!(test_benchmark_delegate::<Test>()); assert_ok!(test_benchmark_undelegate::<Test>()); assert_ok!(test_benchmark_clear_public_proposals::<Test>()); diff --git a/substrate/frame/democracy/src/default_weight.rs b/substrate/frame/democracy/src/default_weight.rs new file mode 100644 index 00000000000..2c74a4af202 --- /dev/null +++ b/substrate/frame/democracy/src/default_weight.rs @@ -0,0 +1,158 @@ +// This file is part of Substrate. + +// Copyright (C) 2020 Parity Technologies (UK) Ltd. +// SPDX-License-Identifier: Apache-2.0 + +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +//! Default weights for the Democracy Pallet +//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 2.0.0-rc5 + +use frame_support::weights::{Weight, constants::RocksDbWeight as DbWeight}; + +/// Default implementation of weight, this is just from an example return, values may change +/// depending on the runtime. This is not meant to be used in production. +impl crate::WeightInfo for () { + fn propose() -> Weight { + (49113000 as Weight) + .saturating_add(DbWeight::get().reads(2 as Weight)) + .saturating_add(DbWeight::get().writes(3 as Weight)) + } + fn second(s: u32, ) -> Weight { + (42067000 as Weight) + .saturating_add((220000 as Weight).saturating_mul(s as Weight)) + .saturating_add(DbWeight::get().reads(1 as Weight)) + .saturating_add(DbWeight::get().writes(1 as Weight)) + } + fn vote_new(r: u32, ) -> Weight { + (54159000 as Weight) + .saturating_add((252000 as Weight).saturating_mul(r as Weight)) + .saturating_add(DbWeight::get().reads(3 as Weight)) + .saturating_add(DbWeight::get().writes(3 as Weight)) + } + fn vote_existing(r: u32, ) -> Weight { + (54145000 as Weight) + .saturating_add((262000 as Weight).saturating_mul(r as Weight)) + .saturating_add(DbWeight::get().reads(3 as Weight)) + .saturating_add(DbWeight::get().writes(3 as Weight)) + } + fn emergency_cancel() -> Weight { + (31071000 as Weight) + .saturating_add(DbWeight::get().reads(2 as Weight)) + .saturating_add(DbWeight::get().writes(2 as Weight)) + } + fn external_propose(v: u32, ) -> Weight { + (14282000 as Weight) + .saturating_add((109000 as Weight).saturating_mul(v as Weight)) + .saturating_add(DbWeight::get().reads(2 as Weight)) + .saturating_add(DbWeight::get().writes(1 as Weight)) + } + fn external_propose_majority() -> Weight { + (3478000 as Weight) + .saturating_add(DbWeight::get().writes(1 as Weight)) + } + fn external_propose_default() -> Weight { + (3442000 as Weight) + .saturating_add(DbWeight::get().writes(1 as Weight)) + } + fn fast_track() -> Weight { + (30820000 as Weight) + .saturating_add(DbWeight::get().reads(2 as Weight)) + .saturating_add(DbWeight::get().writes(3 as Weight)) + } + fn veto_external(v: u32, ) -> Weight { + (30971000 as Weight) + .saturating_add((184000 as Weight).saturating_mul(v as Weight)) + .saturating_add(DbWeight::get().reads(2 as Weight)) + .saturating_add(DbWeight::get().writes(2 as Weight)) + } + fn cancel_referendum() -> Weight { + (20431000 as Weight) + .saturating_add(DbWeight::get().writes(1 as Weight)) + } + fn cancel_queued(r: u32, ) -> Weight { + (42438000 as Weight) + .saturating_add((3284000 as Weight).saturating_mul(r as Weight)) + .saturating_add(DbWeight::get().reads(2 as Weight)) + .saturating_add(DbWeight::get().writes(2 as Weight)) + } + fn on_initialize_base(r: u32, ) -> Weight { + (70826000 as Weight) + .saturating_add((10716000 as Weight).saturating_mul(r as Weight)) + .saturating_add(DbWeight::get().reads(6 as Weight)) + .saturating_add(DbWeight::get().reads((2 as Weight).saturating_mul(r as Weight))) + .saturating_add(DbWeight::get().writes(5 as Weight)) + } + fn delegate(r: u32, ) -> Weight { + (72046000 as Weight) + .saturating_add((7837000 as Weight).saturating_mul(r as Weight)) + .saturating_add(DbWeight::get().reads(4 as Weight)) + .saturating_add(DbWeight::get().reads((1 as Weight).saturating_mul(r as Weight))) + .saturating_add(DbWeight::get().writes(4 as Weight)) + .saturating_add(DbWeight::get().writes((1 as Weight).saturating_mul(r as Weight))) + } + fn undelegate(r: u32, ) -> Weight { + (41028000 as Weight) + .saturating_add((7810000 as Weight).saturating_mul(r as Weight)) + .saturating_add(DbWeight::get().reads(2 as Weight)) + .saturating_add(DbWeight::get().reads((1 as Weight).saturating_mul(r as Weight))) + .saturating_add(DbWeight::get().writes(2 as Weight)) + .saturating_add(DbWeight::get().writes((1 as Weight).saturating_mul(r as Weight))) + } + fn clear_public_proposals() -> Weight { + (3643000 as Weight) + .saturating_add(DbWeight::get().writes(1 as Weight)) + } + fn note_preimage(b: u32, ) -> Weight { + (46629000 as Weight) + .saturating_add((4000 as Weight).saturating_mul(b as Weight)) + .saturating_add(DbWeight::get().reads(1 as Weight)) + .saturating_add(DbWeight::get().writes(1 as Weight)) + } + fn note_imminent_preimage(b: u32, ) -> Weight { + (31147000 as Weight) + .saturating_add((3000 as Weight).saturating_mul(b as Weight)) + .saturating_add(DbWeight::get().reads(1 as Weight)) + .saturating_add(DbWeight::get().writes(1 as Weight)) + } + fn reap_preimage(b: u32, ) -> Weight { + (42848000 as Weight) + .saturating_add((3000 as Weight).saturating_mul(b as Weight)) + .saturating_add(DbWeight::get().reads(2 as Weight)) + .saturating_add(DbWeight::get().writes(1 as Weight)) + } + fn unlock_remove(r: u32, ) -> Weight { + (45333000 as Weight) + .saturating_add((171000 as Weight).saturating_mul(r as Weight)) + .saturating_add(DbWeight::get().reads(3 as Weight)) + .saturating_add(DbWeight::get().writes(3 as Weight)) + } + fn unlock_set(r: u32, ) -> Weight { + (44424000 as Weight) + .saturating_add((291000 as Weight).saturating_mul(r as Weight)) + .saturating_add(DbWeight::get().reads(3 as Weight)) + .saturating_add(DbWeight::get().writes(3 as Weight)) + } + fn remove_vote(r: u32, ) -> Weight { + (28250000 as Weight) + .saturating_add((283000 as Weight).saturating_mul(r as Weight)) + .saturating_add(DbWeight::get().reads(2 as Weight)) + .saturating_add(DbWeight::get().writes(2 as Weight)) + } + fn remove_other_vote(r: u32, ) -> Weight { + (28250000 as Weight) + .saturating_add((283000 as Weight).saturating_mul(r as Weight)) + .saturating_add(DbWeight::get().reads(2 as Weight)) + .saturating_add(DbWeight::get().writes(2 as Weight)) + } +} diff --git a/substrate/frame/democracy/src/lib.rs b/substrate/frame/democracy/src/lib.rs index f546b87dc60..f3a5960eb2f 100644 --- a/substrate/frame/democracy/src/lib.rs +++ b/substrate/frame/democracy/src/lib.rs @@ -173,6 +173,7 @@ mod vote_threshold; mod vote; mod conviction; mod types; +mod default_weight; pub use vote_threshold::{Approved, VoteThreshold}; pub use vote::{Vote, AccountVote, Voting}; pub use conviction::Conviction; @@ -189,7 +190,7 @@ const DEMOCRACY_ID: LockIdentifier = *b"democrac"; /// The maximum number of vetoers on a single proposal used to compute Weight. /// /// NOTE: This is not enforced by any logic. -pub const MAX_VETOERS: Weight = 100; +pub const MAX_VETOERS: u32 = 100; /// A proposal index. pub type PropIndex = u32; @@ -202,24 +203,22 @@ type NegativeImbalanceOf<T> = <<T as Trait>::Currency as Currency<<T as frame_system::Trait>::AccountId>>::NegativeImbalance; pub trait WeightInfo { - fn propose(p: u32, ) -> Weight; + fn propose() -> Weight; fn second(s: u32, ) -> Weight; fn vote_new(r: u32, ) -> Weight; fn vote_existing(r: u32, ) -> Weight; - fn emergency_cancel(r: u32, ) -> Weight; - fn external_propose(p: u32, v: u32, ) -> Weight; - fn external_propose_majority(p: u32, ) -> Weight; - fn external_propose_default(p: u32, ) -> Weight; - fn fast_track(p: u32, ) -> Weight; + fn emergency_cancel() -> Weight; + fn external_propose(v: u32, ) -> Weight; + fn external_propose_majority() -> Weight; + fn external_propose_default() -> Weight; + fn fast_track() -> Weight; fn veto_external(v: u32, ) -> Weight; - fn cancel_referendum(r: u32, ) -> Weight; + fn cancel_referendum() -> Weight; fn cancel_queued(r: u32, ) -> Weight; - fn on_initialize_external(r: u32, ) -> Weight; - fn on_initialize_public(r: u32, ) -> Weight; - fn on_initialize_no_launch_no_maturing(r: u32, ) -> Weight; + fn on_initialize_base(r: u32, ) -> Weight; fn delegate(r: u32, ) -> Weight; fn undelegate(r: u32, ) -> Weight; - fn clear_public_proposals(p: u32, ) -> Weight; + fn clear_public_proposals() -> Weight; fn note_preimage(b: u32, ) -> Weight; fn note_imminent_preimage(b: u32, ) -> Weight; fn reap_preimage(b: u32, ) -> Weight; @@ -227,38 +226,6 @@ pub trait WeightInfo { fn unlock_set(r: u32, ) -> Weight; fn remove_vote(r: u32, ) -> Weight; fn remove_other_vote(r: u32, ) -> Weight; - fn enact_proposal_execute(b: u32, ) -> Weight; - fn enact_proposal_slash(b: u32, ) -> Weight; -} - -impl WeightInfo for () { - fn propose(_p: u32, ) -> Weight { 1_000_000_000 } - fn second(_s: u32, ) -> Weight { 1_000_000_000 } - fn vote_new(_r: u32, ) -> Weight { 1_000_000_000 } - fn vote_existing(_r: u32, ) -> Weight { 1_000_000_000 } - fn emergency_cancel(_r: u32, ) -> Weight { 1_000_000_000 } - fn external_propose(_p: u32, _v: u32, ) -> Weight { 1_000_000_000 } - fn external_propose_majority(_p: u32, ) -> Weight { 1_000_000_000 } - fn external_propose_default(_p: u32, ) -> Weight { 1_000_000_000 } - fn fast_track(_p: u32, ) -> Weight { 1_000_000_000 } - fn veto_external(_v: u32, ) -> Weight { 1_000_000_000 } - fn cancel_referendum(_r: u32, ) -> Weight { 1_000_000_000 } - fn cancel_queued(_r: u32, ) -> Weight { 1_000_000_000 } - fn on_initialize_external(_r: u32, ) -> Weight { 1_000_000_000 } - fn on_initialize_public(_r: u32, ) -> Weight { 1_000_000_000 } - fn on_initialize_no_launch_no_maturing(_r: u32, ) -> Weight { 1_000_000_000 } - fn delegate(_r: u32, ) -> Weight { 1_000_000_000 } - fn undelegate(_r: u32, ) -> Weight { 1_000_000_000 } - fn clear_public_proposals(_p: u32, ) -> Weight { 1_000_000_000 } - fn note_preimage(_b: u32, ) -> Weight { 1_000_000_000 } - fn note_imminent_preimage(_b: u32, ) -> Weight { 1_000_000_000 } - fn reap_preimage(_b: u32, ) -> Weight { 1_000_000_000 } - fn unlock_remove(_r: u32, ) -> Weight { 1_000_000_000 } - fn unlock_set(_r: u32, ) -> Weight { 1_000_000_000 } - fn remove_vote(_r: u32, ) -> Weight { 1_000_000_000 } - fn remove_other_vote(_r: u32, ) -> Weight { 1_000_000_000 } - fn enact_proposal_execute(_b: u32, ) -> Weight { 1_000_000_000 } - fn enact_proposal_slash(_b: u32, ) -> Weight { 1_000_000_000 } } pub trait Trait: frame_system::Trait + Sized { @@ -578,63 +545,6 @@ decl_error! { } } -/// Functions for calcuating the weight of some dispatchables. -mod weight_for { - use frame_support::{traits::Get, weights::Weight}; - use super::Trait; - - /// Calculate the weight for `delegate`. - /// - Db reads: 2*`VotingOf`, `balances locks` - /// - Db writes: 2*`VotingOf`, `balances locks` - /// - Db reads per votes: `ReferendumInfoOf` - /// - Db writes per votes: `ReferendumInfoOf` - /// - Base Weight: 65.78 + 8.229 * R µs - // NOTE: weight must cover an incorrect voting of origin with 100 votes. - pub fn delegate<T: Trait>(votes: Weight) -> Weight { - T::DbWeight::get().reads_writes(votes.saturating_add(3), votes.saturating_add(3)) - .saturating_add(66_000_000) - .saturating_add(votes.saturating_mul(8_100_000)) - } - - /// Calculate the weight for `undelegate`. - /// - Db reads: 2*`VotingOf` - /// - Db writes: 2*`VotingOf` - /// - Db reads per votes: `ReferendumInfoOf` - /// - Db writes per votes: `ReferendumInfoOf` - /// - Base Weight: 33.29 + 8.104 * R µs - pub fn undelegate<T: Trait>(votes: Weight) -> Weight { - T::DbWeight::get().reads_writes(votes.saturating_add(2), votes.saturating_add(2)) - .saturating_add(33_000_000) - .saturating_add(votes.saturating_mul(8_000_000)) - } - - /// Calculate the weight for `note_preimage`. - /// # <weight> - /// - Complexity: `O(E)` with E size of `encoded_proposal` (protected by a required deposit). - /// - Db reads: `Preimages` - /// - Db writes: `Preimages` - /// - Base Weight: 37.93 + .004 * b µs - /// # </weight> - pub fn note_preimage<T: Trait>(encoded_proposal_len: Weight) -> Weight { - T::DbWeight::get().reads_writes(1, 1) - .saturating_add(38_000_000) - .saturating_add(encoded_proposal_len.saturating_mul(4_000)) - } - - /// Calculate the weight for `note_imminent_preimage`. - /// # <weight> - /// - Complexity: `O(E)` with E size of `encoded_proposal` (protected by a required deposit). - /// - Db reads: `Preimages` - /// - Db writes: `Preimages` - /// - Base Weight: 28.04 + .003 * b µs - /// # </weight> - pub fn note_imminent_preimage<T: Trait>(encoded_proposal_len: Weight) -> Weight { - T::DbWeight::get().reads_writes(1, 1) - .saturating_add(28_000_000) - .saturating_add(encoded_proposal_len.saturating_mul(3_000)) - } -} - decl_module! { pub struct Module<T: Trait> for enum Call where origin: T::Origin { type Error = Error<T>; @@ -683,10 +593,8 @@ decl_module! { /// - Complexity: `O(1)` /// - Db reads: `PublicPropCount`, `PublicProps` /// - Db writes: `PublicPropCount`, `PublicProps`, `DepositOf` - /// ------------------- - /// Base Weight: 42.58 + .127 * P µs with `P` the number of proposals `PublicProps` /// # </weight> - #[weight = 50_000_000 + T::DbWeight::get().reads_writes(2, 3)] + #[weight = T::WeightInfo::propose()] fn propose(origin, proposal_hash: T::Hash, #[compact] value: BalanceOf<T>) { let who = ensure_signed(origin)?; ensure!(value >= T::MinimumDeposit::get(), Error::<T>::ValueLow); @@ -715,13 +623,8 @@ decl_module! { /// - Complexity: `O(S)` where S is the number of seconds a proposal already has. /// - Db reads: `DepositOf` /// - Db writes: `DepositOf` - /// --------- - /// - Base Weight: 22.28 + .229 * S µs /// # </weight> - #[weight = 23_000_000 - .saturating_add(230_000.saturating_mul(Weight::from(*seconds_upper_bound))) - .saturating_add(T::DbWeight::get().reads_writes(1, 1)) - ] + #[weight = T::WeightInfo::second(*seconds_upper_bound)] fn second(origin, #[compact] proposal: PropIndex, #[compact] seconds_upper_bound: u32) { let who = ensure_signed(origin)?; @@ -748,12 +651,9 @@ decl_module! { /// weight is charged as if maximum votes. /// - Db reads: `ReferendumInfoOf`, `VotingOf`, `balances locks` /// - Db writes: `ReferendumInfoOf`, `VotingOf`, `balances locks` - /// -------------------- - /// - Base Weight: - /// - Vote New: 49.24 + .333 * R µs - /// - Vote Existing: 49.94 + .343 * R µs /// # </weight> - #[weight = 50_000_000 + 350_000 * Weight::from(T::MaxVotes::get()) + T::DbWeight::get().reads_writes(3, 3)] + #[weight = T::WeightInfo::vote_new(T::MaxVotes::get()) + .max(T::WeightInfo::vote_existing(T::MaxVotes::get()))] fn vote(origin, #[compact] ref_index: ReferendumIndex, vote: AccountVote<BalanceOf<T>>, @@ -773,10 +673,8 @@ decl_module! { /// - Complexity: `O(1)`. /// - Db reads: `ReferendumInfoOf`, `Cancellations` /// - Db writes: `ReferendumInfoOf`, `Cancellations` - /// ------------- - /// - Base Weight: 34.25 µs /// # </weight> - #[weight = (35_000_000 + T::DbWeight::get().reads_writes(2, 2), DispatchClass::Operational)] + #[weight = (T::WeightInfo::emergency_cancel(), DispatchClass::Operational)] fn emergency_cancel(origin, ref_index: ReferendumIndex) { T::CancellationOrigin::ensure_origin(origin)?; @@ -800,9 +698,8 @@ decl_module! { /// Decoding vec of length V. Charged as maximum /// - Db reads: `NextExternal`, `Blacklist` /// - Db writes: `NextExternal` - /// - Base Weight: 13.8 + .106 * V µs /// # </weight> - #[weight = 15_000_000 + 110_000 * MAX_VETOERS + T::DbWeight::get().reads_writes(2, 1)] + #[weight = T::WeightInfo::external_propose(MAX_VETOERS)] fn external_propose(origin, proposal_hash: T::Hash) { T::ExternalOrigin::ensure_origin(origin)?; ensure!(!<NextExternal<T>>::exists(), Error::<T>::DuplicateProposal); @@ -828,9 +725,8 @@ decl_module! { /// # <weight> /// - Complexity: `O(1)` /// - Db write: `NextExternal` - /// - Base Weight: 3.065 µs /// # </weight> - #[weight = 3_100_000 + T::DbWeight::get().writes(1)] + #[weight = T::WeightInfo::external_propose_majority()] fn external_propose_majority(origin, proposal_hash: T::Hash) { T::ExternalMajorityOrigin::ensure_origin(origin)?; <NextExternal<T>>::put((proposal_hash, VoteThreshold::SimpleMajority)); @@ -849,9 +745,8 @@ decl_module! { /// # <weight> /// - Complexity: `O(1)` /// - Db write: `NextExternal` - /// - Base Weight: 3.087 µs /// # </weight> - #[weight = 3_100_000 + T::DbWeight::get().writes(1)] + #[weight = T::WeightInfo::external_propose_default()] fn external_propose_default(origin, proposal_hash: T::Hash) { T::ExternalDefaultOrigin::ensure_origin(origin)?; <NextExternal<T>>::put((proposal_hash, VoteThreshold::SuperMajorityAgainst)); @@ -877,7 +772,7 @@ decl_module! { /// - Db writes: `NextExternal`, `ReferendumCount`, `ReferendumInfoOf` /// - Base Weight: 30.1 µs /// # </weight> - #[weight = 30_000_000 + T::DbWeight::get().reads_writes(2, 3)] + #[weight = T::WeightInfo::fast_track()] fn fast_track(origin, proposal_hash: T::Hash, voting_period: T::BlockNumber, @@ -926,9 +821,8 @@ decl_module! { /// Performs a binary search on `existing_vetoers` which should not be very large. /// - Db reads: `NextExternal`, `Blacklist` /// - Db writes: `NextExternal`, `Blacklist` - /// - Base Weight: 29.87 + .188 * V µs /// # </weight> - #[weight = 30_000_000 + 180_000 * MAX_VETOERS + T::DbWeight::get().reads_writes(2, 2)] + #[weight = T::WeightInfo::veto_external(MAX_VETOERS)] fn veto_external(origin, proposal_hash: T::Hash) { let who = T::VetoOrigin::ensure_origin(origin)?; @@ -961,9 +855,8 @@ decl_module! { /// # <weight> /// - Complexity: `O(1)`. /// - Db writes: `ReferendumInfoOf` - /// - Base Weight: 21.57 µs /// # </weight> - #[weight = (22_000_000 + T::DbWeight::get().writes(1), DispatchClass::Operational)] + #[weight = T::WeightInfo::cancel_referendum()] fn cancel_referendum(origin, #[compact] ref_index: ReferendumIndex) { ensure_root(origin)?; Self::internal_cancel_referendum(ref_index); @@ -979,9 +872,8 @@ decl_module! { /// - `O(D)` where `D` is the items in the dispatch queue. Weighted as `D = 10`. /// - Db reads: `scheduler lookup`, scheduler agenda` /// - Db writes: `scheduler lookup`, scheduler agenda` - /// - Base Weight: 36.78 + 3.277 * D µs /// # </weight> - #[weight = (68_000_000 + T::DbWeight::get().reads_writes(2, 2), DispatchClass::Operational)] + #[weight = (T::WeightInfo::cancel_queued(10), DispatchClass::Operational)] fn cancel_queued(origin, which: ReferendumIndex) { ensure_root(origin)?; T::Scheduler::cancel_named((DEMOCRACY_ID, which).encode()) @@ -1017,14 +909,14 @@ decl_module! { /// # <weight> /// - Complexity: `O(R)` where R is the number of referendums the voter delegating to has /// voted on. Weight is charged as if maximum votes. - /// - Db reads: 2*`VotingOf`, `balances locks` - /// - Db writes: 2*`VotingOf`, `balances locks` + /// - Db reads: 3*`VotingOf`, `origin account locks` + /// - Db writes: 3*`VotingOf`, `origin account locks` /// - Db reads per votes: `ReferendumInfoOf` /// - Db writes per votes: `ReferendumInfoOf` - /// - Base Weight: 65.78 + 8.229 * R µs - // NOTE: weight must cover an incorrect voting of origin with 100 votes. + // NOTE: weight must cover an incorrect voting of origin with max votes, this is ensure + // because a valid delegation cover decoding a direct voting with max votes. /// # </weight> - #[weight = weight_for::delegate::<T>(T::MaxVotes::get().into())] + #[weight = T::WeightInfo::delegate(T::MaxVotes::get())] pub fn delegate( origin, to: T::AccountId, @@ -1034,7 +926,7 @@ decl_module! { let who = ensure_signed(origin)?; let votes = Self::try_delegate(who, to, conviction, balance)?; - Ok(Some(weight_for::delegate::<T>(votes.into())).into()) + Ok(Some(T::WeightInfo::delegate(votes)).into()) } /// Undelegate the voting power of the sending account. @@ -1054,14 +946,14 @@ decl_module! { /// - Db writes: 2*`VotingOf` /// - Db reads per votes: `ReferendumInfoOf` /// - Db writes per votes: `ReferendumInfoOf` - /// - Base Weight: 33.29 + 8.104 * R µs - // NOTE: weight must cover an incorrect voting of origin with 100 votes. + // NOTE: weight must cover an incorrect voting of origin with max votes, this is ensure + // because a valid delegation cover decoding a direct voting with max votes. /// # </weight> - #[weight = weight_for::undelegate::<T>(T::MaxVotes::get().into())] + #[weight = T::WeightInfo::undelegate(T::MaxVotes::get().into())] fn undelegate(origin) -> DispatchResultWithPostInfo { let who = ensure_signed(origin)?; let votes = Self::try_undelegate(who)?; - Ok(Some(weight_for::undelegate::<T>(votes.into())).into()) + Ok(Some(T::WeightInfo::undelegate(votes)).into()) } /// Clears all public proposals. @@ -1071,9 +963,8 @@ decl_module! { /// # <weight> /// - `O(1)`. /// - Db writes: `PublicProps` - /// - Base Weight: 2.505 µs /// # </weight> - #[weight = 2_500_000 + T::DbWeight::get().writes(1)] + #[weight = T::WeightInfo::clear_public_proposals()] fn clear_public_proposals(origin) { ensure_root(origin)?; <PublicProps<T>>::kill(); @@ -1089,16 +980,18 @@ decl_module! { /// Emits `PreimageNoted`. /// /// # <weight> - /// see `weight_for::note_preimage` + /// - Complexity: `O(E)` with E size of `encoded_proposal` (protected by a required deposit). + /// - Db reads: `Preimages` + /// - Db writes: `Preimages` /// # </weight> - #[weight = weight_for::note_preimage::<T>((encoded_proposal.len() as u32).into())] + #[weight = T::WeightInfo::note_preimage(encoded_proposal.len() as u32)] fn note_preimage(origin, encoded_proposal: Vec<u8>) { Self::note_preimage_inner(ensure_signed(origin)?, encoded_proposal)?; } /// Same as `note_preimage` but origin is `OperationalPreimageOrigin`. #[weight = ( - weight_for::note_preimage::<T>((encoded_proposal.len() as u32).into()), + T::WeightInfo::note_preimage(encoded_proposal.len() as u32), DispatchClass::Operational, )] fn note_preimage_operational(origin, encoded_proposal: Vec<u8>) { @@ -1116,16 +1009,18 @@ decl_module! { /// Emits `PreimageNoted`. /// /// # <weight> - /// see `weight_for::note_preimage` + /// - Complexity: `O(E)` with E size of `encoded_proposal` (protected by a required deposit). + /// - Db reads: `Preimages` + /// - Db writes: `Preimages` /// # </weight> - #[weight = weight_for::note_imminent_preimage::<T>((encoded_proposal.len() as u32).into())] + #[weight = T::WeightInfo::note_imminent_preimage(encoded_proposal.len() as u32)] fn note_imminent_preimage(origin, encoded_proposal: Vec<u8>) { Self::note_imminent_preimage_inner(ensure_signed(origin)?, encoded_proposal)?; } /// Same as `note_imminent_preimage` but origin is `OperationalPreimageOrigin`. #[weight = ( - weight_for::note_imminent_preimage::<T>((encoded_proposal.len() as u32).into()), + T::WeightInfo::note_imminent_preimage(encoded_proposal.len() as u32), DispatchClass::Operational, )] fn note_imminent_preimage_operational(origin, encoded_proposal: Vec<u8>) { @@ -1149,12 +1044,10 @@ decl_module! { /// /// # <weight> /// - Complexity: `O(D)` where D is length of proposal. - /// - Db reads: `Preimages` - /// - Db writes: `Preimages` - /// - Base Weight: 39.31 + .003 * b µs + /// - Db reads: `Preimages`, provider account data + /// - Db writes: `Preimages` provider account data /// # </weight> - #[weight = (39_000_000 + T::DbWeight::get().reads_writes(1, 1)) - .saturating_add(3_000.saturating_mul(Weight::from(*proposal_len_upper_bound)))] + #[weight = T::WeightInfo::reap_preimage(*proposal_len_upper_bound)] fn reap_preimage(origin, proposal_hash: T::Hash, #[compact] proposal_len_upper_bound: u32) { let who = ensure_signed(origin)?; @@ -1191,12 +1084,9 @@ decl_module! { /// - Complexity `O(R)` with R number of vote of target. /// - Db reads: `VotingOf`, `balances locks`, `target account` /// - Db writes: `VotingOf`, `balances locks`, `target account` - /// - Base Weight: - /// - Unlock Remove: 42.96 + .048 * R - /// - Unlock Set: 37.63 + .327 * R /// # </weight> - #[weight = 43_000_000 + 330_000 * Weight::from(T::MaxVotes::get()) - + T::DbWeight::get().reads_writes(3, 3)] + #[weight = T::WeightInfo::unlock_set(T::MaxVotes::get()) + .max(T::WeightInfo::unlock_remove(T::MaxVotes::get()))] fn unlock(origin, target: T::AccountId) { ensure_signed(origin)?; Self::update_lock(&target); @@ -1232,9 +1122,8 @@ decl_module! { /// Weight is calculated for the maximum number of vote. /// - Db reads: `ReferendumInfoOf`, `VotingOf` /// - Db writes: `ReferendumInfoOf`, `VotingOf` - /// - Base Weight: 21.03 + .359 * R /// # </weight> - #[weight = 21_000_000 + 360_000 * Weight::from(T::MaxVotes::get()) + T::DbWeight::get().reads_writes(2, 2)] + #[weight = T::WeightInfo::remove_vote(T::MaxVotes::get())] fn remove_vote(origin, index: ReferendumIndex) -> DispatchResult { let who = ensure_signed(origin)?; Self::try_remove_vote(&who, index, UnvoteScope::Any) @@ -1258,9 +1147,8 @@ decl_module! { /// Weight is calculated for the maximum number of vote. /// - Db reads: `ReferendumInfoOf`, `VotingOf` /// - Db writes: `ReferendumInfoOf`, `VotingOf` - /// - Base Weight: 19.15 + .372 * R /// # </weight> - #[weight = 19_000_000 + 370_000 * Weight::from(T::MaxVotes::get()) + T::DbWeight::get().reads_writes(2, 2)] + #[weight = T::WeightInfo::remove_other_vote(T::MaxVotes::get())] fn remove_other_vote(origin, target: T::AccountId, index: ReferendumIndex) -> DispatchResult { let who = ensure_signed(origin)?; let scope = if target == who { UnvoteScope::Any } else { UnvoteScope::OnlyExpired }; @@ -1716,10 +1604,9 @@ impl<T: Trait> Module<T> { /// `ReferendumCount`, `LowestUnbaked` /// - Db writes: `PublicProps`, `account`, `ReferendumCount`, `DepositOf`, `ReferendumInfoOf` /// - Db reads per R: `DepositOf`, `ReferendumInfoOf` - /// - Base Weight: 58.58 + 10.9 * R µs /// # </weight> fn begin_block(now: T::BlockNumber) -> Result<Weight, DispatchError> { - let mut weight = 60_000_000 + T::DbWeight::get().reads_writes(6, 5); + let mut weight = 0; // pick out another public referendum if it's time. if (now % T::LaunchPeriod::get()).is_zero() { @@ -1729,11 +1616,11 @@ impl<T: Trait> Module<T> { weight = T::MaximumBlockWeight::get(); } - // tally up votes for any expiring referenda. let next = Self::lowest_unbaked(); let last = Self::referendum_count(); - let r = Weight::from(last.saturating_sub(next)); - weight += 11_000_000 * r + T::DbWeight::get().reads(2 * r); + let r = last.saturating_sub(next); + weight = weight.saturating_add(T::WeightInfo::on_initialize_base(r)); + // tally up votes for any expiring referenda. for (index, info) in Self::maturing_referenda_at_inner(now, next..last).into_iter() { let approved = Self::bake_referendum(now, index, info)?; ReferendumInfoOf::<T>::insert(index, ReferendumInfo::Finished { end: now, approved }); -- GitLab