From aadfd4b9a592b7154eb27d1f5bf55e8d0336fe37 Mon Sep 17 00:00:00 2001 From: Gav Wood Date: Tue, 15 Sep 2020 14:54:55 +0200 Subject: [PATCH 01/25] Introduce `cancel_proposal` Also fix proposal weight. --- frame/democracy/src/benchmarking.rs | 10 ++++ frame/democracy/src/default_weight.rs | 7 ++- frame/democracy/src/lib.rs | 52 +++++++++++++++++-- frame/democracy/src/tests.rs | 5 ++ frame/democracy/src/tests/public_proposals.rs | 31 +++++++++++ 5 files changed, 99 insertions(+), 6 deletions(-) diff --git a/frame/democracy/src/benchmarking.rs b/frame/democracy/src/benchmarking.rs index 1fa0988fbbd4d..826ffcbec28fa 100644 --- a/frame/democracy/src/benchmarking.rs +++ b/frame/democracy/src/benchmarking.rs @@ -57,6 +57,7 @@ fn add_proposal(n: u32) -> Result { RawOrigin::Signed(other).into(), proposal_hash, value.into(), + MAX_PROPOSALS, )?; Ok(proposal_hash) @@ -100,6 +101,11 @@ benchmarks! { _ { } propose { + let p in 0 .. MAX_PROPOSALS; + for i in 0..r { + add_proposal::(i)?; + } + let caller = funded_account::("caller", 0); let proposal_hash: T::Hash = T::Hashing::hash_of(&0); let value = T::MinimumDeposit::get(); @@ -287,6 +293,10 @@ benchmarks! { assert_eq!(new_vetoers.len(), (v + 1) as usize, "vetoers not added"); } + cancel_proposal { + let proposal_index = add_proposal::(r)?; + }: _(RawOrigin::Root, proposal_index) + cancel_referendum { let referendum_index = add_referendum::(0)?; }: _(RawOrigin::Root, referendum_index) diff --git a/frame/democracy/src/default_weight.rs b/frame/democracy/src/default_weight.rs index 2c74a4af2020f..441ba5e3657fc 100644 --- a/frame/democracy/src/default_weight.rs +++ b/frame/democracy/src/default_weight.rs @@ -23,8 +23,9 @@ 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 { + fn propose(p: u32, ) -> Weight { (49113000 as Weight) + .saturating_add((262000 as Weight).saturating_mul(p as Weight)) .saturating_add(DbWeight::get().reads(2 as Weight)) .saturating_add(DbWeight::get().writes(3 as Weight)) } @@ -76,6 +77,10 @@ impl crate::WeightInfo for () { .saturating_add(DbWeight::get().reads(2 as Weight)) .saturating_add(DbWeight::get().writes(2 as Weight)) } + fn cancel_proposal() -> Weight { + (20431000 as Weight) + .saturating_add(DbWeight::get().writes(1 as Weight)) + } fn cancel_referendum() -> Weight { (20431000 as Weight) .saturating_add(DbWeight::get().writes(1 as Weight)) diff --git a/frame/democracy/src/lib.rs b/frame/democracy/src/lib.rs index 9ed732d3234ea..4db5cdab36281 100644 --- a/frame/democracy/src/lib.rs +++ b/frame/democracy/src/lib.rs @@ -192,6 +192,9 @@ const DEMOCRACY_ID: LockIdentifier = *b"democrac"; /// NOTE: This is not enforced by any logic. pub const MAX_VETOERS: u32 = 100; +/// The maximum number of public proposals that can exist at any time. +pub const MAX_PROPOSALS: u32 = 1000; + /// A proposal index. pub type PropIndex = u32; @@ -203,7 +206,7 @@ type NegativeImbalanceOf = <::Currency as Currency<::AccountId>>::NegativeImbalance; pub trait WeightInfo { - fn propose() -> Weight; + fn propose(p: u32, ) -> Weight; fn second(s: u32, ) -> Weight; fn vote_new(r: u32, ) -> Weight; fn vote_existing(r: u32, ) -> Weight; @@ -214,6 +217,7 @@ pub trait WeightInfo { fn fast_track() -> Weight; fn veto_external(v: u32, ) -> Weight; fn cancel_referendum() -> Weight; + fn cancel_proposal() -> Weight; fn cancel_queued(r: u32, ) -> Weight; fn on_initialize_base(r: u32, ) -> Weight; fn delegate(r: u32, ) -> Weight; @@ -285,6 +289,9 @@ pub trait Trait: frame_system::Trait + Sized { /// Origin from which any referendum may be cancelled in an emergency. type CancellationOrigin: EnsureOrigin; + /// Origin from which a proposal may be cancelled and its backers slashed. + type CancelProposalOrigin: EnsureOrigin; + /// Origin for anyone able to veto proposals. /// /// # Warning @@ -544,6 +551,10 @@ decl_error! { WrongUpperBound, /// Maximum number of votes reached. MaxVotesReached, + /// The provided witness data is wrong. + InvalidWitness, + /// Maximum number of proposals reached. + TooManyProposals, } } @@ -596,14 +607,21 @@ decl_module! { /// - Db reads: `PublicPropCount`, `PublicProps` /// - Db writes: `PublicPropCount`, `PublicProps`, `DepositOf` /// # - #[weight = T::WeightInfo::propose()] - fn propose(origin, proposal_hash: T::Hash, #[compact] value: BalanceOf) { + #[weight = T::WeightInfo::propose(*prop_count)] + fn propose(origin, + proposal_hash: T::Hash, + #[compact] value: BalanceOf, + #[compact] prop_count: u32, + ) { let who = ensure_signed(origin)?; ensure!(value >= T::MinimumDeposit::get(), Error::::ValueLow); - T::Currency::reserve(&who, value)?; - let index = Self::public_prop_count(); + let real_prop_count = PublicProps::::decode_len().unwrap_or(0) as u32; + ensure!(real_prop_count <= prop_count, Error::::InvalidWitness); + ensure!(real_prop_count < MAX_PROPOSALS, Error::::TooManyProposals); + + T::Currency::reserve(&who, value)?; PublicPropCount::put(index + 1); >::insert(index, (&[&who][..], value)); @@ -848,6 +866,30 @@ decl_module! { >::kill(); } + /// Remove a proposal. + /// + /// The dispatch origin of this call must be _Root_. + /// + /// - `ref_index`: The index of the proposal to cancel. + /// + /// # + /// - Complexity: `O(1)`. + /// - Db writes: `ReferendumInfoOf` + /// - Base Weight: 21.57 µs + /// # + #[weight = T::WeightInfo::cancel_proposal()] + fn cancel_proposal(origin, #[compact] prop_index: PropIndex) { + T::CancelProposalOrigin::ensure_origin(origin)?; + + PublicProps::::mutate(|props| props.retain(|p| p.0 != prop_index)); + if let Some((whos, amount)) = DepositOf::::take(prop_index) { + for who in whos.into_iter() { + T::Slash::on_unbalanced(T::Currency::slash_reserved(&who, amount).0); + } + } + + } + /// Remove a referendum. /// /// The dispatch origin of this call must be _Root_. diff --git a/frame/democracy/src/tests.rs b/frame/democracy/src/tests.rs index 13c6a09a04bc1..498dfd96b7319 100644 --- a/frame/democracy/src/tests.rs +++ b/frame/democracy/src/tests.rs @@ -49,6 +49,8 @@ const NAY: Vote = Vote { aye: false, conviction: Conviction::None }; const BIG_AYE: Vote = Vote { aye: true, conviction: Conviction::Locked1x }; const BIG_NAY: Vote = Vote { aye: false, conviction: Conviction::Locked1x }; +const MAX_PROPOSALS: u32 = 100; + impl_outer_origin! { pub enum Origin for Test where system = frame_system {} } @@ -192,6 +194,7 @@ impl super::Trait for Test { type ExternalDefaultOrigin = EnsureSignedBy; type FastTrackOrigin = EnsureSignedBy; type CancellationOrigin = EnsureSignedBy; + type CancelProposalOrigin = EnsureRoot; type VetoOrigin = EnsureSignedBy; type CooloffPeriod = CooloffPeriod; type PreimageByteDeposit = PreimageByteDeposit; @@ -268,6 +271,7 @@ fn propose_set_balance(who: u64, value: u64, delay: u64) -> DispatchResult { Origin::signed(who), set_balance_proposal_hash(value), delay, + MAX_PROPOSALS, ) } @@ -276,6 +280,7 @@ fn propose_set_balance_and_note(who: u64, value: u64, delay: u64) -> DispatchRes Origin::signed(who), set_balance_proposal_hash_and_note(value), delay, + MAX_PROPOSALS, ) } diff --git a/frame/democracy/src/tests/public_proposals.rs b/frame/democracy/src/tests/public_proposals.rs index 68ec790baae86..a99728b70a530 100644 --- a/frame/democracy/src/tests/public_proposals.rs +++ b/frame/democracy/src/tests/public_proposals.rs @@ -96,6 +96,37 @@ fn invalid_seconds_upper_bound_should_not_work() { }); } +#[test] +fn invalid_max_proposals_should_fail() { + new_test_ext().execute_with(|| { + assert_ok!(Democracy::propose( + Origin::signed(1), + set_balance_proposal_hash(2), + 2, + 0, + )); + assert_noop!(Democracy::propose( + Origin::signed(1), + set_balance_proposal_hash(2), + 2, + 0, + ), Error::::InvalidWitness); + }); +} + +#[test] +fn cancel_proposal_should_work() { + new_test_ext().execute_with(|| { + System::set_block_number(0); + assert_ok!(propose_set_balance_and_note(1, 2, 2)); + assert_ok!(propose_set_balance_and_note(1, 4, 4)); + assert_noop!(Democracy::cancel_proposal(Origin::signed(1), 0), BadOrigin); + assert_ok!(Democracy::cancel_proposal(Origin::root(), 0)); + assert_eq!(Democracy::backing_for(0), None); + assert_eq!(Democracy::backing_for(1), Some(4)); + }); +} + #[test] fn runners_up_should_come_after() { new_test_ext().execute_with(|| { From a67a0180c9e0363e89273833a892c95ed7357a2b Mon Sep 17 00:00:00 2001 From: Gav Wood Date: Tue, 15 Sep 2020 14:58:21 +0200 Subject: [PATCH 02/25] Support proposal cancellation from runtime. --- bin/node/runtime/src/lib.rs | 7 +++++++ bin/node/runtime/src/weights/pallet_democracy.rs | 4 ++++ 2 files changed, 11 insertions(+) diff --git a/bin/node/runtime/src/lib.rs b/bin/node/runtime/src/lib.rs index eeac6d83b8777..490fba3e5ed77 100644 --- a/bin/node/runtime/src/lib.rs +++ b/bin/node/runtime/src/lib.rs @@ -493,6 +493,13 @@ impl pallet_democracy::Trait for Runtime { type FastTrackVotingPeriod = FastTrackVotingPeriod; // To cancel a proposal which has been passed, 2/3 of the council must agree to it. type CancellationOrigin = pallet_collective::EnsureProportionAtLeast<_2, _3, AccountId, CouncilCollective>; + // To cancel a proposal before it has been passed, the technical committee must be unanimous or + // Root must agree. + type CancelProposalOrigin = EnsureOneOf< + AccountId, + EnsureRoot, + pallet_collective::EnsureProportionAtLeast<_1, _1, AccountId, TechnicalCollective>, + >; // Any single technical committee member may veto a coming council proposal, however they can // only do it once and it lasts only for the cooloff period. type VetoOrigin = pallet_collective::EnsureMember; diff --git a/bin/node/runtime/src/weights/pallet_democracy.rs b/bin/node/runtime/src/weights/pallet_democracy.rs index 2c55a848061a3..c5710f1cba2ca 100644 --- a/bin/node/runtime/src/weights/pallet_democracy.rs +++ b/bin/node/runtime/src/weights/pallet_democracy.rs @@ -73,6 +73,10 @@ impl pallet_democracy::WeightInfo for WeightInfo { .saturating_add(DbWeight::get().reads(2 as Weight)) .saturating_add(DbWeight::get().writes(2 as Weight)) } + fn cancel_proposal() -> Weight { + (20431000 as Weight) + .saturating_add(DbWeight::get().writes(1 as Weight)) + } fn cancel_referendum() -> Weight { (20431000 as Weight) .saturating_add(DbWeight::get().writes(1 as Weight)) From bec8bad6264eaa9d82896458a2233129ddb1e2c8 Mon Sep 17 00:00:00 2001 From: Gav Wood Date: Tue, 15 Sep 2020 15:38:27 +0200 Subject: [PATCH 03/25] Fixes --- bin/node/runtime/src/weights/pallet_democracy.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/bin/node/runtime/src/weights/pallet_democracy.rs b/bin/node/runtime/src/weights/pallet_democracy.rs index c5710f1cba2ca..5bfecd127d8fc 100644 --- a/bin/node/runtime/src/weights/pallet_democracy.rs +++ b/bin/node/runtime/src/weights/pallet_democracy.rs @@ -20,8 +20,9 @@ use frame_support::weights::{Weight, constants::RocksDbWeight as DbWeight}; pub struct WeightInfo; impl pallet_democracy::WeightInfo for WeightInfo { - fn propose() -> Weight { + fn propose(p: u32, ) -> Weight { (49113000 as Weight) + .saturating_add((220000 as Weight).saturating_mul(p as Weight)) .saturating_add(DbWeight::get().reads(2 as Weight)) .saturating_add(DbWeight::get().writes(3 as Weight)) } From 06c97f25d6d1a9bb0b81e63cbb872a2769aee692 Mon Sep 17 00:00:00 2001 From: Gav Wood Date: Tue, 15 Sep 2020 17:09:32 +0200 Subject: [PATCH 04/25] Fixes --- frame/democracy/src/benchmarking.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/frame/democracy/src/benchmarking.rs b/frame/democracy/src/benchmarking.rs index 826ffcbec28fa..28949caaf6e87 100644 --- a/frame/democracy/src/benchmarking.rs +++ b/frame/democracy/src/benchmarking.rs @@ -102,7 +102,7 @@ benchmarks! { propose { let p in 0 .. MAX_PROPOSALS; - for i in 0..r { + for i in 0..p { add_proposal::(i)?; } @@ -294,7 +294,7 @@ benchmarks! { } cancel_proposal { - let proposal_index = add_proposal::(r)?; + let proposal_index = add_proposal::(0)?; }: _(RawOrigin::Root, proposal_index) cancel_referendum { From 693fc8202afe90682320703b1dc09d023b78bf80 Mon Sep 17 00:00:00 2001 From: Gav Wood Date: Tue, 15 Sep 2020 20:17:16 +0200 Subject: [PATCH 05/25] Fixes --- frame/democracy/src/benchmarking.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/frame/democracy/src/benchmarking.rs b/frame/democracy/src/benchmarking.rs index 28949caaf6e87..46d5b145a509e 100644 --- a/frame/democracy/src/benchmarking.rs +++ b/frame/democracy/src/benchmarking.rs @@ -109,7 +109,7 @@ benchmarks! { let caller = funded_account::("caller", 0); let proposal_hash: T::Hash = T::Hashing::hash_of(&0); let value = T::MinimumDeposit::get(); - }: _(RawOrigin::Signed(caller), proposal_hash, value.into()) + }: _(RawOrigin::Signed(caller), proposal_hash, value.into(), MAX_PROPOSALS) verify { assert_eq!(Democracy::::public_props().len(), 1, "Proposals not created."); } @@ -295,7 +295,7 @@ benchmarks! { cancel_proposal { let proposal_index = add_proposal::(0)?; - }: _(RawOrigin::Root, proposal_index) + }: _(RawOrigin::Root, 0) cancel_referendum { let referendum_index = add_referendum::(0)?; From bbe86b67b2ebdebee4450bf43bcef47a810324b6 Mon Sep 17 00:00:00 2001 From: Gav Wood Date: Wed, 16 Sep 2020 15:11:14 +0200 Subject: [PATCH 06/25] Fixes --- frame/democracy/src/benchmarking.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/frame/democracy/src/benchmarking.rs b/frame/democracy/src/benchmarking.rs index 46d5b145a509e..8c02636b45231 100644 --- a/frame/democracy/src/benchmarking.rs +++ b/frame/democracy/src/benchmarking.rs @@ -101,8 +101,8 @@ benchmarks! { _ { } propose { - let p in 0 .. MAX_PROPOSALS; - for i in 0..p { + let p in 1 .. MAX_PROPOSALS; + for i in 0 .. (p - 1) { add_proposal::(i)?; } @@ -111,7 +111,7 @@ benchmarks! { let value = T::MinimumDeposit::get(); }: _(RawOrigin::Signed(caller), proposal_hash, value.into(), MAX_PROPOSALS) verify { - assert_eq!(Democracy::::public_props().len(), 1, "Proposals not created."); + assert_eq!(Democracy::::public_props().len(), p as usize, "Proposals not created."); } second { From 083ba8d4bf21c91ebf423c927f62771cfe326f36 Mon Sep 17 00:00:00 2001 From: Gav Wood Date: Wed, 16 Sep 2020 17:06:00 +0200 Subject: [PATCH 07/25] Fixes --- frame/democracy/src/default_weight.rs | 5 ++ frame/democracy/src/lib.rs | 71 +++++++++++++++++-- frame/democracy/src/tests.rs | 1 + .../democracy/src/tests/external_proposing.rs | 26 +++++++ frame/democracy/src/tests/public_proposals.rs | 26 +++++++ 5 files changed, 125 insertions(+), 4 deletions(-) diff --git a/frame/democracy/src/default_weight.rs b/frame/democracy/src/default_weight.rs index 441ba5e3657fc..a5bede7dcd4c2 100644 --- a/frame/democracy/src/default_weight.rs +++ b/frame/democracy/src/default_weight.rs @@ -52,6 +52,11 @@ impl crate::WeightInfo for () { .saturating_add(DbWeight::get().reads(2 as Weight)) .saturating_add(DbWeight::get().writes(2 as Weight)) } + fn blacklist() -> 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)) diff --git a/frame/democracy/src/lib.rs b/frame/democracy/src/lib.rs index 4db5cdab36281..e630f8359e860 100644 --- a/frame/democracy/src/lib.rs +++ b/frame/democracy/src/lib.rs @@ -155,7 +155,7 @@ use sp_std::prelude::*; use sp_runtime::{ DispatchResult, DispatchError, RuntimeDebug, - traits::{Zero, Hash, Dispatchable, Saturating}, + traits::{Zero, Hash, Dispatchable, Saturating, Bounded}, }; use codec::{Encode, Decode, Input}; use frame_support::{ @@ -211,6 +211,7 @@ pub trait WeightInfo { fn vote_new(r: u32, ) -> Weight; fn vote_existing(r: u32, ) -> Weight; fn emergency_cancel() -> Weight; + fn blacklist() -> Weight; fn external_propose(v: u32, ) -> Weight; fn external_propose_majority() -> Weight; fn external_propose_default() -> Weight; @@ -289,6 +290,9 @@ pub trait Trait: frame_system::Trait + Sized { /// Origin from which any referendum may be cancelled in an emergency. type CancellationOrigin: EnsureOrigin; + /// Origin from which proposals may be blacklisted. + type BlacklistOrigin: EnsureOrigin; + /// Origin from which a proposal may be cancelled and its backers slashed. type CancelProposalOrigin: EnsureOrigin; @@ -421,8 +425,7 @@ decl_storage! { /// A record of who vetoed what. Maps proposal hash to a possible existent block number /// (until when it may not be resubmitted) and who vetoed it. - pub Blacklist get(fn blacklist): - map hasher(identity) T::Hash => Option<(T::BlockNumber, Vec)>; + pub Blacklist: map hasher(identity) T::Hash => Option<(T::BlockNumber, Vec)>; /// Record of all proposals that have been subject to emergency cancellation. pub Cancellations: map hasher(identity) T::Hash => bool; @@ -479,6 +482,8 @@ decl_event! { PreimageReaped(Hash, AccountId, Balance, AccountId), /// An \[account\] has been unlocked successfully. Unlocked(AccountId), + /// A proposal \[hash\] has been blacklisted permanently. + Blacklisted(Hash), } } @@ -621,6 +626,13 @@ decl_module! { ensure!(real_prop_count <= prop_count, Error::::InvalidWitness); ensure!(real_prop_count < MAX_PROPOSALS, Error::::TooManyProposals); + if let Some((until, _)) = >::get(proposal_hash) { + ensure!( + >::block_number() >= until, + Error::::ProposalBlacklisted, + ); + } + T::Currency::reserve(&who, value)?; PublicPropCount::put(index + 1); >::insert(index, (&[&who][..], value)); @@ -706,6 +718,58 @@ decl_module! { Self::internal_cancel_referendum(ref_index); } + /// Permanently place a proposal into the blacklist. This prevents it from ever being + /// proposed again. + /// + /// If called on an queued public or external proposal, then this will result in it being + /// removed. If the `ref_index` supplied is an active referendum with the proposal hash, + /// then it will be cancelled. + /// + /// The dispatch origin of this call must be `BlacklistOrigin`. + /// + /// - `proposal_hash`: The proposal hash to blacklist permanently. + /// - `ref_index`: An ongoing referendum whose hash is `proposal_hash`, which will be + /// cancelled. + #[weight = (T::WeightInfo::blacklist(), DispatchClass::Operational)] + fn blacklist(origin, + proposal_hash: T::Hash, + maybe_ref_index: Option, + ) { + T::BlacklistOrigin::ensure_origin(origin)?; + + // Insert the proposal into the blacklist. + let permanent = (T::BlockNumber::max_value(), Vec::::new()); + Blacklist::::insert(&proposal_hash, permanent); + + // Remove the queued proposal, if it's there. + PublicProps::::mutate(|props| { + if let Some(index) = props.iter().position(|p| p.1 == proposal_hash) { + let (prop_index, ..) = props.remove(index); + if let Some((whos, amount)) = DepositOf::::take(prop_index) { + for who in whos.into_iter() { + T::Slash::on_unbalanced(T::Currency::slash_reserved(&who, amount).0); + } + } + } + }); + + // Remove the external queued referendum, if it's there. + if matches!(NextExternal::::get(), Some((h, ..)) if h == proposal_hash) { + NextExternal::::kill(); + } + + // Remove the referendum, if it's there. + if let Some(ref_index) = maybe_ref_index { + let status = Self::referendum_status(ref_index)?; + let h = status.proposal_hash; + if h == proposal_hash { + Self::internal_cancel_referendum(ref_index); + } + } + + Self::deposit_event(RawEvent::Blacklisted(proposal_hash)); + } + /// Schedule a referendum to be tabled once it is legal to schedule an external /// referendum. /// @@ -887,7 +951,6 @@ decl_module! { T::Slash::on_unbalanced(T::Currency::slash_reserved(&who, amount).0); } } - } /// Remove a referendum. diff --git a/frame/democracy/src/tests.rs b/frame/democracy/src/tests.rs index 498dfd96b7319..d4f035176e48a 100644 --- a/frame/democracy/src/tests.rs +++ b/frame/democracy/src/tests.rs @@ -194,6 +194,7 @@ impl super::Trait for Test { type ExternalDefaultOrigin = EnsureSignedBy; type FastTrackOrigin = EnsureSignedBy; type CancellationOrigin = EnsureSignedBy; + type BlacklistOrigin = EnsureRoot; type CancelProposalOrigin = EnsureRoot; type VetoOrigin = EnsureSignedBy; type CooloffPeriod = CooloffPeriod; diff --git a/frame/democracy/src/tests/external_proposing.rs b/frame/democracy/src/tests/external_proposing.rs index 473eac81cdcb0..3f9be2137906b 100644 --- a/frame/democracy/src/tests/external_proposing.rs +++ b/frame/democracy/src/tests/external_proposing.rs @@ -79,6 +79,32 @@ fn veto_external_works() { }); } +#[test] +fn external_blacklisting_should_work() { + new_test_ext().execute_with(|| { + System::set_block_number(0); + + assert_ok!(Democracy::external_propose( + Origin::signed(2), + set_balance_proposal_hash_and_note(2), + )); + + let hash = set_balance_proposal_hash(2); + assert_ok!(Democracy::blacklist(Origin::root(), hash, None)); + + fast_forward_to(2); + assert!(Democracy::referendum_status(0).is_err()); + + assert_noop!( + Democracy::external_propose( + Origin::signed(2), + set_balance_proposal_hash_and_note(2), + ), + Error::::ProposalBlacklisted, + ); + }); +} + #[test] fn external_referendum_works() { new_test_ext().execute_with(|| { diff --git a/frame/democracy/src/tests/public_proposals.rs b/frame/democracy/src/tests/public_proposals.rs index a99728b70a530..bf7a498f3e820 100644 --- a/frame/democracy/src/tests/public_proposals.rs +++ b/frame/democracy/src/tests/public_proposals.rs @@ -127,6 +127,32 @@ fn cancel_proposal_should_work() { }); } +#[test] +fn blacklisting_should_work() { + new_test_ext().execute_with(|| { + System::set_block_number(0); + let hash = set_balance_proposal_hash(2); + + assert_ok!(propose_set_balance_and_note(1, 2, 2)); + assert_ok!(propose_set_balance_and_note(1, 4, 4)); + + assert_noop!(Democracy::blacklist(Origin::signed(1), hash.clone(), None), BadOrigin); + assert_ok!(Democracy::blacklist(Origin::root(), hash, None)); + + assert_eq!(Democracy::backing_for(0), None); + assert_eq!(Democracy::backing_for(1), Some(4)); + + assert_noop!(propose_set_balance_and_note(1, 2, 2), Error::::ProposalBlacklisted); + + fast_forward_to(2); + + let hash = set_balance_proposal_hash(4); + assert!(Democracy::referendum_status(0).is_ok()); + assert_ok!(Democracy::blacklist(Origin::root(), hash, Some(0))); + assert!(Democracy::referendum_status(0).is_err()); + }); +} + #[test] fn runners_up_should_come_after() { new_test_ext().execute_with(|| { From 3626e8e7fce69a4e90ffbb8bcf19bf4d76fa512a Mon Sep 17 00:00:00 2001 From: Gav Wood Date: Wed, 16 Sep 2020 17:30:02 +0200 Subject: [PATCH 08/25] Fixes --- bin/node/runtime/src/lib.rs | 1 + .../runtime/src/weights/pallet_democracy.rs | 5 ++++ frame/democracy/src/benchmarking.rs | 26 +++++++++++++++++++ 3 files changed, 32 insertions(+) diff --git a/bin/node/runtime/src/lib.rs b/bin/node/runtime/src/lib.rs index 490fba3e5ed77..977c099eeac90 100644 --- a/bin/node/runtime/src/lib.rs +++ b/bin/node/runtime/src/lib.rs @@ -500,6 +500,7 @@ impl pallet_democracy::Trait for Runtime { EnsureRoot, pallet_collective::EnsureProportionAtLeast<_1, _1, AccountId, TechnicalCollective>, >; + type BlacklistOrigin = EnsureRoot; // Any single technical committee member may veto a coming council proposal, however they can // only do it once and it lasts only for the cooloff period. type VetoOrigin = pallet_collective::EnsureMember; diff --git a/bin/node/runtime/src/weights/pallet_democracy.rs b/bin/node/runtime/src/weights/pallet_democracy.rs index 5bfecd127d8fc..bfec67bfc0925 100644 --- a/bin/node/runtime/src/weights/pallet_democracy.rs +++ b/bin/node/runtime/src/weights/pallet_democracy.rs @@ -49,6 +49,11 @@ impl pallet_democracy::WeightInfo for WeightInfo { .saturating_add(DbWeight::get().reads(2 as Weight)) .saturating_add(DbWeight::get().writes(2 as Weight)) } + fn blacklist() -> 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)) diff --git a/frame/democracy/src/benchmarking.rs b/frame/democracy/src/benchmarking.rs index 8c02636b45231..9e35cf20d778e 100644 --- a/frame/democracy/src/benchmarking.rs +++ b/frame/democracy/src/benchmarking.rs @@ -212,6 +212,32 @@ benchmarks! { assert!(Democracy::::referendum_status(referendum_index).is_err()); } + blacklist { + let p in 1 .. MAX_PROPOSALS; + + // Place our proposal at the end to make sure it's worst case. + for i in 1 .. p { + add_proposal::(i)?; + } + add_proposal::(0)?; + // We should really add a lot of seconds here, but we're not doing it elsewhere. + + // Place our proposal in the external queue, too. + let hash = T::Hashing::hash_of(&0); + assert_ok!(Democracy::::external_propose(T::ExternalOrigin::successful_origin(), hash.clone())) + + // Add a referendum of our proposal. + let referendum_index = add_referendum::(0)?; + assert!(Democracy::::referendum_status(referendum_index).is_ok()); + + let call = Call::::blacklist(hash, Some(referendum_index)); + let origin = T::BlacklistOrigin::successful_origin(); + }: { call.dispatch_bypass_filter(origin)? } + verify { + // Referendum has been canceled + assert!(Democracy::::referendum_status(referendum_index).is_err()); + } + // Worst case scenario, we external propose a previously blacklisted proposal external_propose { let v in 1 .. MAX_VETOERS as u32; From c93eedb4eae24e3962e4e5597ad73a603675d190 Mon Sep 17 00:00:00 2001 From: Gav Wood Date: Wed, 16 Sep 2020 17:36:34 +0200 Subject: [PATCH 09/25] Fixes --- frame/democracy/src/benchmarking.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frame/democracy/src/benchmarking.rs b/frame/democracy/src/benchmarking.rs index 9e35cf20d778e..6ff084b3aa878 100644 --- a/frame/democracy/src/benchmarking.rs +++ b/frame/democracy/src/benchmarking.rs @@ -224,7 +224,7 @@ benchmarks! { // Place our proposal in the external queue, too. let hash = T::Hashing::hash_of(&0); - assert_ok!(Democracy::::external_propose(T::ExternalOrigin::successful_origin(), hash.clone())) + assert!(Democracy::::external_propose(T::ExternalOrigin::successful_origin(), hash.clone()).is_ok()); // Add a referendum of our proposal. let referendum_index = add_referendum::(0)?; From a8e9fe8db8dc528cd05cf954d3aa192b6db82abd Mon Sep 17 00:00:00 2001 From: Shawn Tabrizi Date: Mon, 21 Sep 2020 16:52:49 +0200 Subject: [PATCH 10/25] Fix benchmarks --- .../runtime/src/weights/pallet_democracy.rs | 121 ++++++++--------- frame/benchmarking/src/utils.rs | 9 ++ frame/democracy/src/benchmarking.rs | 20 ++- frame/democracy/src/default_weight.rs | 123 +++++++++--------- frame/democracy/src/lib.rs | 8 +- .../democracy/src/tests/external_proposing.rs | 2 +- frame/democracy/src/tests/public_proposals.rs | 6 +- frame/staking/src/benchmarking.rs | 40 +++--- 8 files changed, 176 insertions(+), 153 deletions(-) diff --git a/bin/node/runtime/src/weights/pallet_democracy.rs b/bin/node/runtime/src/weights/pallet_democracy.rs index bfec67bfc0925..5ef134318302f 100644 --- a/bin/node/runtime/src/weights/pallet_democracy.rs +++ b/bin/node/runtime/src/weights/pallet_democracy.rs @@ -14,151 +14,156 @@ // limitations under the License. //! Weights for the Democracy Pallet -//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 2.0.0-rc5 +//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 2.0.0-rc6 + +#![allow(unused_parens)] +#![allow(unused_imports)] use frame_support::weights::{Weight, constants::RocksDbWeight as DbWeight}; pub struct WeightInfo; impl pallet_democracy::WeightInfo for WeightInfo { fn propose(p: u32, ) -> Weight { - (49113000 as Weight) - .saturating_add((220000 as Weight).saturating_mul(p as Weight)) - .saturating_add(DbWeight::get().reads(2 as Weight)) - .saturating_add(DbWeight::get().writes(3 as Weight)) + (173882000 as Weight) + .saturating_add((58000 as Weight).saturating_mul(p as Weight)) + .saturating_add(DbWeight::get().reads(4 as Weight)) + .saturating_add(DbWeight::get().writes(4 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)) + (111076000 as Weight) + .saturating_add((551000 as Weight).saturating_mul(s as Weight)) + .saturating_add(DbWeight::get().reads(2 as Weight)) + .saturating_add(DbWeight::get().writes(2 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)) + (150748000 as Weight) + .saturating_add((396000 as Weight).saturating_mul(r as Weight)) + .saturating_add(DbWeight::get().reads(4 as Weight)) + .saturating_add(DbWeight::get().writes(4 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)) + (118820000 as Weight) + .saturating_add((1193000 as Weight).saturating_mul(r as Weight)) + .saturating_add(DbWeight::get().reads(4 as Weight)) + .saturating_add(DbWeight::get().writes(4 as Weight)) } fn emergency_cancel() -> Weight { - (31071000 as Weight) + (43278000 as Weight) .saturating_add(DbWeight::get().reads(2 as Weight)) .saturating_add(DbWeight::get().writes(2 as Weight)) } - fn blacklist() -> Weight { - (31071000 as Weight) - .saturating_add(DbWeight::get().reads(2 as Weight)) - .saturating_add(DbWeight::get().writes(2 as Weight)) + fn blacklist(p: u32, ) -> Weight { + (442525000 as Weight) + .saturating_add((515000 as Weight).saturating_mul(p as Weight)) + .saturating_add(DbWeight::get().reads(5 as Weight)) + .saturating_add(DbWeight::get().writes(6 as Weight)) } fn external_propose(v: u32, ) -> Weight { - (14282000 as Weight) - .saturating_add((109000 as Weight).saturating_mul(v as Weight)) + (20349000 as Weight) + .saturating_add((114000 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) + (4889000 as Weight) .saturating_add(DbWeight::get().writes(1 as Weight)) } fn external_propose_default() -> Weight { - (3442000 as Weight) + (4875000 as Weight) .saturating_add(DbWeight::get().writes(1 as Weight)) } fn fast_track() -> Weight { - (30820000 as Weight) + (41326000 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)) + (42518000 as Weight) + .saturating_add((191000 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_proposal() -> Weight { - (20431000 as Weight) - .saturating_add(DbWeight::get().writes(1 as Weight)) + (65871000 as Weight) + .saturating_add(DbWeight::get().reads(3 as Weight)) + .saturating_add(DbWeight::get().writes(3 as Weight)) } fn cancel_referendum() -> Weight { - (20431000 as Weight) + (26151000 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)) + (0 as Weight) + .saturating_add((8246000 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)) + (302489000 as Weight) + .saturating_add((21766000 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)) + (178766000 as Weight) + .saturating_add((19805000 as Weight).saturating_mul(r as Weight)) + .saturating_add(DbWeight::get().reads(5 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(5 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)) + (163433000 as Weight) + .saturating_add((8980000 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) + (4854000 as Weight) .saturating_add(DbWeight::get().writes(1 as Weight)) } fn note_preimage(b: u32, ) -> Weight { - (46629000 as Weight) + (63227000 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)) + .saturating_add(DbWeight::get().reads(2 as Weight)) + .saturating_add(DbWeight::get().writes(2 as Weight)) } fn note_imminent_preimage(b: u32, ) -> Weight { - (31147000 as Weight) - .saturating_add((3000 as Weight).saturating_mul(b as Weight)) + (42569000 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 reap_preimage(b: u32, ) -> Weight { - (42848000 as Weight) + (57894000 as Weight) .saturating_add((3000 as Weight).saturating_mul(b as Weight)) - .saturating_add(DbWeight::get().reads(2 as Weight)) + .saturating_add(DbWeight::get().reads(3 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)) + (57008000 as Weight) + .saturating_add((275000 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)) + (53179000 as Weight) + .saturating_add((460000 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)) + (31536000 as Weight) + .saturating_add((445000 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)) + (31418000 as Weight) + .saturating_add((446000 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/frame/benchmarking/src/utils.rs b/frame/benchmarking/src/utils.rs index 347334e24d5f6..042f4b707aef4 100644 --- a/frame/benchmarking/src/utils.rs +++ b/frame/benchmarking/src/utils.rs @@ -219,3 +219,12 @@ pub fn account(name: &'static str, index: u32, seed pub fn whitelisted_caller() -> AccountId { account::("whitelisted_caller", 0, 0) } + +#[macro_export] +macro_rules! whitelist_account { + ($acc:ident) => { + frame_benchmarking::benchmarking::add_to_whitelist( + frame_system::Account::::hashed_key_for(&$acc).into() + ); + } +} diff --git a/frame/democracy/src/benchmarking.rs b/frame/democracy/src/benchmarking.rs index 6ff084b3aa878..55bde79ca5964 100644 --- a/frame/democracy/src/benchmarking.rs +++ b/frame/democracy/src/benchmarking.rs @@ -19,7 +19,7 @@ use super::*; -use frame_benchmarking::{benchmarks, account}; +use frame_benchmarking::{benchmarks, account, whitelist_account}; use frame_support::{ IterableStorageMap, traits::{Currency, Get, EnsureOrigin, OnInitialize, UnfilteredDispatchable, schedule::DispatchTime}, @@ -109,6 +109,7 @@ benchmarks! { let caller = funded_account::("caller", 0); let proposal_hash: T::Hash = T::Hashing::hash_of(&0); let value = T::MinimumDeposit::get(); + whitelist_account!(caller); }: _(RawOrigin::Signed(caller), proposal_hash, value.into(), MAX_PROPOSALS) verify { assert_eq!(Democracy::::public_props().len(), p as usize, "Proposals not created."); @@ -128,6 +129,7 @@ benchmarks! { let deposits = Democracy::::deposit_of(0).ok_or("Proposal not created")?; assert_eq!(deposits.0.len(), (s + 1) as usize, "Seconds not recorded"); + whitelist_account!(caller); }: _(RawOrigin::Signed(caller), 0, u32::max_value()) verify { let deposits = Democracy::::deposit_of(0).ok_or("Proposal not created")?; @@ -152,7 +154,7 @@ benchmarks! { assert_eq!(votes.len(), r as usize, "Votes were not recorded."); let referendum_index = add_referendum::(r)?; - + whitelist_account!(caller); }: vote(RawOrigin::Signed(caller.clone()), referendum_index, account_vote) verify { let votes = match VotingOf::::get(&caller) { @@ -185,6 +187,7 @@ benchmarks! { let referendum_index = Democracy::::referendum_count() - 1; // This tests when a user changes a vote + whitelist_account!(caller); }: vote(RawOrigin::Signed(caller.clone()), referendum_index, new_vote) verify { let votes = match VotingOf::::get(&caller) { @@ -230,7 +233,7 @@ benchmarks! { let referendum_index = add_referendum::(0)?; assert!(Democracy::::referendum_status(referendum_index).is_ok()); - let call = Call::::blacklist(hash, Some(referendum_index)); + let call = Call::::blacklist(hash, Some(referendum_index), p); let origin = T::BlacklistOrigin::successful_origin(); }: { call.dispatch_bypass_filter(origin)? } verify { @@ -473,6 +476,7 @@ benchmarks! { _ => return Err("Votes are not direct"), }; assert_eq!(votes.len(), r as usize, "Votes were not recorded."); + whitelist_account!(caller); }: _(RawOrigin::Signed(caller.clone()), new_delegate.clone(), Conviction::Locked1x, delegated_balance) verify { let (target, balance) = match VotingOf::::get(&caller) { @@ -524,6 +528,7 @@ benchmarks! { _ => return Err("Votes are not direct"), }; assert_eq!(votes.len(), r as usize, "Votes were not recorded."); + whitelist_account!(caller); }: _(RawOrigin::Signed(caller.clone())) verify { // Voting should now be direct @@ -544,6 +549,7 @@ benchmarks! { let caller = funded_account::("caller", 0); let encoded_proposal = vec![1; b as usize]; + whitelist_account!(caller); }: _(RawOrigin::Signed(caller), encoded_proposal.clone()) verify { let proposal_hash = T::Hashing::hash(&encoded_proposal[..]); @@ -565,6 +571,7 @@ benchmarks! { let caller = funded_account::("caller", 0); let encoded_proposal = vec![1; b as usize]; + whitelist_account!(caller); }: _(RawOrigin::Signed(caller), encoded_proposal.clone()) verify { let proposal_hash = T::Hashing::hash(&encoded_proposal[..]); @@ -591,6 +598,7 @@ benchmarks! { assert!(Preimages::::contains_key(proposal_hash)); let caller = funded_account::("caller", 0); + whitelist_account!(caller); }: _(RawOrigin::Signed(caller), proposal_hash.clone(), u32::max_value()) verify { let proposal_hash = T::Hashing::hash(&encoded_proposal[..]); @@ -613,6 +621,7 @@ benchmarks! { } let caller = funded_account::("caller", 0); + whitelist_account!(caller); }: unlock(RawOrigin::Signed(caller), locker.clone()) verify { // Note that we may want to add a `get_lock` api to actually verify @@ -650,6 +659,7 @@ benchmarks! { Democracy::::remove_vote(RawOrigin::Signed(locker.clone()).into(), referendum_index)?; let caller = funded_account::("caller", 0); + whitelist_account!(caller); }: unlock(RawOrigin::Signed(caller), locker.clone()) verify { let votes = match VotingOf::::get(&locker) { @@ -681,7 +691,7 @@ benchmarks! { assert_eq!(votes.len(), r as usize, "Votes not created"); let referendum_index = r - 1; - + whitelist_account!(caller); }: _(RawOrigin::Signed(caller.clone()), referendum_index) verify { let votes = match VotingOf::::get(&caller) { @@ -710,7 +720,7 @@ benchmarks! { assert_eq!(votes.len(), r as usize, "Votes not created"); let referendum_index = r - 1; - + whitelist_account!(caller); }: _(RawOrigin::Signed(caller.clone()), caller.clone(), referendum_index) verify { let votes = match VotingOf::::get(&caller) { diff --git a/frame/democracy/src/default_weight.rs b/frame/democracy/src/default_weight.rs index a5bede7dcd4c2..5c761b81c205d 100644 --- a/frame/democracy/src/default_weight.rs +++ b/frame/democracy/src/default_weight.rs @@ -16,152 +16,155 @@ // 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 +//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 2.0.0-rc6 + +#![allow(unused_parens)] +#![allow(unused_imports)] 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(p: u32, ) -> Weight { - (49113000 as Weight) - .saturating_add((262000 as Weight).saturating_mul(p as Weight)) - .saturating_add(DbWeight::get().reads(2 as Weight)) - .saturating_add(DbWeight::get().writes(3 as Weight)) + (173882000 as Weight) + .saturating_add((58000 as Weight).saturating_mul(p as Weight)) + .saturating_add(DbWeight::get().reads(4 as Weight)) + .saturating_add(DbWeight::get().writes(4 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)) + (111076000 as Weight) + .saturating_add((551000 as Weight).saturating_mul(s as Weight)) + .saturating_add(DbWeight::get().reads(2 as Weight)) + .saturating_add(DbWeight::get().writes(2 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)) + (150748000 as Weight) + .saturating_add((396000 as Weight).saturating_mul(r as Weight)) + .saturating_add(DbWeight::get().reads(4 as Weight)) + .saturating_add(DbWeight::get().writes(4 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)) + (118820000 as Weight) + .saturating_add((1193000 as Weight).saturating_mul(r as Weight)) + .saturating_add(DbWeight::get().reads(4 as Weight)) + .saturating_add(DbWeight::get().writes(4 as Weight)) } fn emergency_cancel() -> Weight { - (31071000 as Weight) + (43278000 as Weight) .saturating_add(DbWeight::get().reads(2 as Weight)) .saturating_add(DbWeight::get().writes(2 as Weight)) } - fn blacklist() -> Weight { - (31071000 as Weight) - .saturating_add(DbWeight::get().reads(2 as Weight)) - .saturating_add(DbWeight::get().writes(2 as Weight)) + fn blacklist(p: u32, ) -> Weight { + (442525000 as Weight) + .saturating_add((515000 as Weight).saturating_mul(p as Weight)) + .saturating_add(DbWeight::get().reads(5 as Weight)) + .saturating_add(DbWeight::get().writes(6 as Weight)) } fn external_propose(v: u32, ) -> Weight { - (14282000 as Weight) - .saturating_add((109000 as Weight).saturating_mul(v as Weight)) + (20349000 as Weight) + .saturating_add((114000 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) + (4889000 as Weight) .saturating_add(DbWeight::get().writes(1 as Weight)) } fn external_propose_default() -> Weight { - (3442000 as Weight) + (4875000 as Weight) .saturating_add(DbWeight::get().writes(1 as Weight)) } fn fast_track() -> Weight { - (30820000 as Weight) + (41326000 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)) + (42518000 as Weight) + .saturating_add((191000 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_proposal() -> Weight { - (20431000 as Weight) - .saturating_add(DbWeight::get().writes(1 as Weight)) + (65871000 as Weight) + .saturating_add(DbWeight::get().reads(3 as Weight)) + .saturating_add(DbWeight::get().writes(3 as Weight)) } fn cancel_referendum() -> Weight { - (20431000 as Weight) + (26151000 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)) + (0 as Weight) + .saturating_add((8246000 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)) + (302489000 as Weight) + .saturating_add((21766000 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)) + (178766000 as Weight) + .saturating_add((19805000 as Weight).saturating_mul(r as Weight)) + .saturating_add(DbWeight::get().reads(5 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(5 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)) + (163433000 as Weight) + .saturating_add((8980000 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) + (4854000 as Weight) .saturating_add(DbWeight::get().writes(1 as Weight)) } fn note_preimage(b: u32, ) -> Weight { - (46629000 as Weight) + (63227000 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)) + .saturating_add(DbWeight::get().reads(2 as Weight)) + .saturating_add(DbWeight::get().writes(2 as Weight)) } fn note_imminent_preimage(b: u32, ) -> Weight { - (31147000 as Weight) - .saturating_add((3000 as Weight).saturating_mul(b as Weight)) + (42569000 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 reap_preimage(b: u32, ) -> Weight { - (42848000 as Weight) + (57894000 as Weight) .saturating_add((3000 as Weight).saturating_mul(b as Weight)) - .saturating_add(DbWeight::get().reads(2 as Weight)) + .saturating_add(DbWeight::get().reads(3 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)) + (57008000 as Weight) + .saturating_add((275000 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)) + (53179000 as Weight) + .saturating_add((460000 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)) + (31536000 as Weight) + .saturating_add((445000 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)) + (31418000 as Weight) + .saturating_add((446000 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/frame/democracy/src/lib.rs b/frame/democracy/src/lib.rs index e630f8359e860..036d12db9f760 100644 --- a/frame/democracy/src/lib.rs +++ b/frame/democracy/src/lib.rs @@ -211,7 +211,7 @@ pub trait WeightInfo { fn vote_new(r: u32, ) -> Weight; fn vote_existing(r: u32, ) -> Weight; fn emergency_cancel() -> Weight; - fn blacklist() -> Weight; + fn blacklist(p: u32, ) -> Weight; fn external_propose(v: u32, ) -> Weight; fn external_propose_majority() -> Weight; fn external_propose_default() -> Weight; @@ -730,13 +730,17 @@ decl_module! { /// - `proposal_hash`: The proposal hash to blacklist permanently. /// - `ref_index`: An ongoing referendum whose hash is `proposal_hash`, which will be /// cancelled. - #[weight = (T::WeightInfo::blacklist(), DispatchClass::Operational)] + #[weight = (T::WeightInfo::blacklist(*prop_count), DispatchClass::Operational)] fn blacklist(origin, proposal_hash: T::Hash, maybe_ref_index: Option, + #[compact] prop_count: u32, ) { T::BlacklistOrigin::ensure_origin(origin)?; + let real_prop_count = PublicProps::::decode_len().unwrap_or(0) as u32; + ensure!(real_prop_count <= prop_count, Error::::InvalidWitness); + // Insert the proposal into the blacklist. let permanent = (T::BlockNumber::max_value(), Vec::::new()); Blacklist::::insert(&proposal_hash, permanent); diff --git a/frame/democracy/src/tests/external_proposing.rs b/frame/democracy/src/tests/external_proposing.rs index 3f9be2137906b..7710a411d86c2 100644 --- a/frame/democracy/src/tests/external_proposing.rs +++ b/frame/democracy/src/tests/external_proposing.rs @@ -90,7 +90,7 @@ fn external_blacklisting_should_work() { )); let hash = set_balance_proposal_hash(2); - assert_ok!(Democracy::blacklist(Origin::root(), hash, None)); + assert_ok!(Democracy::blacklist(Origin::root(), hash, None, 1)); fast_forward_to(2); assert!(Democracy::referendum_status(0).is_err()); diff --git a/frame/democracy/src/tests/public_proposals.rs b/frame/democracy/src/tests/public_proposals.rs index bf7a498f3e820..aac49770702d9 100644 --- a/frame/democracy/src/tests/public_proposals.rs +++ b/frame/democracy/src/tests/public_proposals.rs @@ -136,8 +136,8 @@ fn blacklisting_should_work() { assert_ok!(propose_set_balance_and_note(1, 2, 2)); assert_ok!(propose_set_balance_and_note(1, 4, 4)); - assert_noop!(Democracy::blacklist(Origin::signed(1), hash.clone(), None), BadOrigin); - assert_ok!(Democracy::blacklist(Origin::root(), hash, None)); + assert_noop!(Democracy::blacklist(Origin::signed(1), hash.clone(), None, 1), BadOrigin); + assert_ok!(Democracy::blacklist(Origin::root(), hash, None, 2)); assert_eq!(Democracy::backing_for(0), None); assert_eq!(Democracy::backing_for(1), Some(4)); @@ -148,7 +148,7 @@ fn blacklisting_should_work() { let hash = set_balance_proposal_hash(4); assert!(Democracy::referendum_status(0).is_ok()); - assert_ok!(Democracy::blacklist(Origin::root(), hash, Some(0))); + assert_ok!(Democracy::blacklist(Origin::root(), hash, Some(0), 1)); assert!(Democracy::referendum_status(0).is_err()); }); } diff --git a/frame/staking/src/benchmarking.rs b/frame/staking/src/benchmarking.rs index afda58db4672f..9cef7be1cec1d 100644 --- a/frame/staking/src/benchmarking.rs +++ b/frame/staking/src/benchmarking.rs @@ -23,20 +23,12 @@ use testing_utils::*; use sp_runtime::traits::One; use frame_system::RawOrigin; -pub use frame_benchmarking::{benchmarks, account, whitelisted_caller}; +pub use frame_benchmarking::{benchmarks, account, whitelisted_caller, whitelist_account}; const SEED: u32 = 0; const MAX_SPANS: u32 = 100; const MAX_VALIDATORS: u32 = 1000; const MAX_SLASHES: u32 = 1000; -macro_rules! do_whitelist { - ($acc:ident) => { - frame_benchmarking::benchmarking::add_to_whitelist( - frame_system::Account::::hashed_key_for(&$acc).into() - ); - } -} - // Add slashing spans to a user account. Not relevant for actual use, only to benchmark // read and write operations. fn add_slashing_spans(who: &T::AccountId, spans: u32) { @@ -120,7 +112,7 @@ benchmarks! { let controller_lookup: ::Source = T::Lookup::unlookup(controller.clone()); let reward_destination = RewardDestination::Staked; let amount = T::Currency::minimum_balance() * 10.into(); - do_whitelist!(stash); + whitelist_account!(stash); }: _(RawOrigin::Signed(stash.clone()), controller_lookup, amount, reward_destination) verify { assert!(Bonded::::contains_key(stash)); @@ -132,7 +124,7 @@ benchmarks! { let max_additional = T::Currency::minimum_balance() * 10.into(); let ledger = Ledger::::get(&controller).ok_or("ledger not created before")?; let original_bonded: BalanceOf = ledger.active; - do_whitelist!(stash); + whitelist_account!(stash); }: _(RawOrigin::Signed(stash), max_additional) verify { let ledger = Ledger::::get(&controller).ok_or("ledger not created after")?; @@ -145,7 +137,7 @@ benchmarks! { let amount = T::Currency::minimum_balance() * 10.into(); let ledger = Ledger::::get(&controller).ok_or("ledger not created before")?; let original_bonded: BalanceOf = ledger.active; - do_whitelist!(controller); + whitelist_account!(controller); }: _(RawOrigin::Signed(controller.clone()), amount) verify { let ledger = Ledger::::get(&controller).ok_or("ledger not created after")?; @@ -164,7 +156,7 @@ benchmarks! { CurrentEra::put(EraIndex::max_value()); let ledger = Ledger::::get(&controller).ok_or("ledger not created before")?; let original_total: BalanceOf = ledger.total; - do_whitelist!(controller); + whitelist_account!(controller); }: withdraw_unbonded(RawOrigin::Signed(controller.clone()), s) verify { let ledger = Ledger::::get(&controller).ok_or("ledger not created after")?; @@ -183,7 +175,7 @@ benchmarks! { CurrentEra::put(EraIndex::max_value()); let ledger = Ledger::::get(&controller).ok_or("ledger not created before")?; let original_total: BalanceOf = ledger.total; - do_whitelist!(controller); + whitelist_account!(controller); }: withdraw_unbonded(RawOrigin::Signed(controller.clone()), s) verify { assert!(!Ledger::::contains_key(controller)); @@ -192,7 +184,7 @@ benchmarks! { validate { let (stash, controller) = create_stash_controller::(USER_SEED, 100, Default::default())?; let prefs = ValidatorPrefs::default(); - do_whitelist!(controller); + whitelist_account!(controller); }: _(RawOrigin::Signed(controller), prefs) verify { assert!(Validators::::contains_key(stash)); @@ -203,7 +195,7 @@ benchmarks! { let n in 1 .. MAX_NOMINATIONS as u32; let (stash, controller) = create_stash_controller::(n + 1, 100, Default::default())?; let validators = create_validators::(n, 100)?; - do_whitelist!(controller); + whitelist_account!(controller); }: _(RawOrigin::Signed(controller), validators) verify { assert!(Nominators::::contains_key(stash)); @@ -211,13 +203,13 @@ benchmarks! { chill { let (_, controller) = create_stash_controller::(USER_SEED, 100, Default::default())?; - do_whitelist!(controller); + whitelist_account!(controller); }: _(RawOrigin::Signed(controller)) set_payee { let (stash, controller) = create_stash_controller::(USER_SEED, 100, Default::default())?; assert_eq!(Payee::::get(&stash), RewardDestination::Staked); - do_whitelist!(controller); + whitelist_account!(controller); }: _(RawOrigin::Signed(controller), RewardDestination::Controller) verify { assert_eq!(Payee::::get(&stash), RewardDestination::Controller); @@ -227,7 +219,7 @@ benchmarks! { let (stash, _) = create_stash_controller::(USER_SEED, 100, Default::default())?; let new_controller = create_funded_user::("new_controller", USER_SEED, 100); let new_controller_lookup = T::Lookup::unlookup(new_controller.clone()); - do_whitelist!(stash); + whitelist_account!(stash); }: _(RawOrigin::Signed(stash), new_controller_lookup) verify { assert!(Ledger::::contains_key(&new_controller)); @@ -350,7 +342,7 @@ benchmarks! { } Ledger::::insert(controller.clone(), staking_ledger.clone()); let original_bonded: BalanceOf = staking_ledger.active; - do_whitelist!(controller); + whitelist_account!(controller); }: _(RawOrigin::Signed(controller.clone()), (l + 100).into()) verify { let ledger = Ledger::::get(&controller).ok_or("ledger not created after")?; @@ -381,7 +373,7 @@ benchmarks! { let (stash, controller) = create_stash_controller::(0, 100, Default::default())?; add_slashing_spans::(&stash, s); T::Currency::make_free_balance_be(&stash, 0.into()); - do_whitelist!(controller); + whitelist_account!(controller); }: _(RawOrigin::Signed(controller), stash.clone(), s) verify { assert!(!Bonded::::contains_key(&stash)); @@ -516,7 +508,7 @@ benchmarks! { let era = >::current_era().unwrap_or(0); let caller: T::AccountId = account("caller", n, SEED); - do_whitelist!(caller); + whitelist_account!(caller); }: { let result = >::submit_election_solution( RawOrigin::Signed(caller.clone()).into(), @@ -584,7 +576,7 @@ benchmarks! { let era = >::current_era().unwrap_or(0); let caller: T::AccountId = account("caller", n, SEED); - do_whitelist!(caller); + whitelist_account!(caller); // submit a very bad solution on-chain { @@ -638,7 +630,7 @@ benchmarks! { >::put(ElectionStatus::Open(T::BlockNumber::from(1u32))); let era = >::current_era().unwrap_or(0); let caller: T::AccountId = account("caller", n, SEED); - do_whitelist!(caller); + whitelist_account!(caller); // submit a seq-phragmen with all the good stuff on chain. { From 764ea77483e24938d53c41886be8b4e4c4e9ac7b Mon Sep 17 00:00:00 2001 From: Shawn Tabrizi Date: Mon, 21 Sep 2020 17:06:00 +0200 Subject: [PATCH 11/25] fix benchmark --- frame/democracy/src/benchmarking.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/frame/democracy/src/benchmarking.rs b/frame/democracy/src/benchmarking.rs index 55bde79ca5964..ef46529d38934 100644 --- a/frame/democracy/src/benchmarking.rs +++ b/frame/democracy/src/benchmarking.rs @@ -219,10 +219,9 @@ benchmarks! { let p in 1 .. MAX_PROPOSALS; // Place our proposal at the end to make sure it's worst case. - for i in 1 .. p { + for i in 0 .. p - 1 { add_proposal::(i)?; } - add_proposal::(0)?; // We should really add a lot of seconds here, but we're not doing it elsewhere. // Place our proposal in the external queue, too. @@ -811,6 +810,8 @@ mod tests { assert_ok!(test_benchmark_remove_other_vote::()); assert_ok!(test_benchmark_enact_proposal_execute::()); assert_ok!(test_benchmark_enact_proposal_slash::()); + assert_ok!(test_benchmark_blacklist::()); + assert_ok!(test_benchmark_cancel_proposal::()); }); } } From a5dfded020558765702a76d17d5359779e5adee8 Mon Sep 17 00:00:00 2001 From: Shawn Tabrizi Date: Mon, 21 Sep 2020 17:17:04 +0200 Subject: [PATCH 12/25] whitelisted caller weights --- .../runtime/src/weights/pallet_democracy.rs | 108 ++++++++--------- frame/democracy/src/default_weight.rs | 111 +++++++++--------- 2 files changed, 110 insertions(+), 109 deletions(-) diff --git a/bin/node/runtime/src/weights/pallet_democracy.rs b/bin/node/runtime/src/weights/pallet_democracy.rs index 5ef134318302f..054322bff57c6 100644 --- a/bin/node/runtime/src/weights/pallet_democracy.rs +++ b/bin/node/runtime/src/weights/pallet_democracy.rs @@ -24,146 +24,146 @@ use frame_support::weights::{Weight, constants::RocksDbWeight as DbWeight}; pub struct WeightInfo; impl pallet_democracy::WeightInfo for WeightInfo { fn propose(p: u32, ) -> Weight { - (173882000 as Weight) - .saturating_add((58000 as Weight).saturating_mul(p as Weight)) - .saturating_add(DbWeight::get().reads(4 as Weight)) - .saturating_add(DbWeight::get().writes(4 as Weight)) + (82728000 as Weight) + .saturating_add((11000 as Weight).saturating_mul(p as Weight)) + .saturating_add(DbWeight::get().reads(3 as Weight)) + .saturating_add(DbWeight::get().writes(3 as Weight)) } fn second(s: u32, ) -> Weight { - (111076000 as Weight) - .saturating_add((551000 as Weight).saturating_mul(s as Weight)) - .saturating_add(DbWeight::get().reads(2 as Weight)) - .saturating_add(DbWeight::get().writes(2 as Weight)) + (54903000 as Weight) + .saturating_add((254000 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 { - (150748000 as Weight) - .saturating_add((396000 as Weight).saturating_mul(r as Weight)) - .saturating_add(DbWeight::get().reads(4 as Weight)) - .saturating_add(DbWeight::get().writes(4 as Weight)) + (67070000 as Weight) + .saturating_add((452000 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 { - (118820000 as Weight) - .saturating_add((1193000 as Weight).saturating_mul(r as Weight)) - .saturating_add(DbWeight::get().reads(4 as Weight)) - .saturating_add(DbWeight::get().writes(4 as Weight)) + (66675000 as Weight) + .saturating_add((456000 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 { - (43278000 as Weight) + (41152000 as Weight) .saturating_add(DbWeight::get().reads(2 as Weight)) .saturating_add(DbWeight::get().writes(2 as Weight)) } fn blacklist(p: u32, ) -> Weight { - (442525000 as Weight) - .saturating_add((515000 as Weight).saturating_mul(p as Weight)) + (131046000 as Weight) + .saturating_add((694000 as Weight).saturating_mul(p as Weight)) .saturating_add(DbWeight::get().reads(5 as Weight)) .saturating_add(DbWeight::get().writes(6 as Weight)) } fn external_propose(v: u32, ) -> Weight { - (20349000 as Weight) - .saturating_add((114000 as Weight).saturating_mul(v as Weight)) + (19552000 as Weight) + .saturating_add((112000 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 { - (4889000 as Weight) + (4582000 as Weight) .saturating_add(DbWeight::get().writes(1 as Weight)) } fn external_propose_default() -> Weight { - (4875000 as Weight) + (4587000 as Weight) .saturating_add(DbWeight::get().writes(1 as Weight)) } fn fast_track() -> Weight { - (41326000 as Weight) + (39833000 as Weight) .saturating_add(DbWeight::get().reads(2 as Weight)) .saturating_add(DbWeight::get().writes(3 as Weight)) } fn veto_external(v: u32, ) -> Weight { - (42518000 as Weight) - .saturating_add((191000 as Weight).saturating_mul(v as Weight)) + (40935000 as Weight) + .saturating_add((188000 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_proposal() -> Weight { - (65871000 as Weight) + (64238000 as Weight) .saturating_add(DbWeight::get().reads(3 as Weight)) .saturating_add(DbWeight::get().writes(3 as Weight)) } fn cancel_referendum() -> Weight { - (26151000 as Weight) + (25280000 as Weight) .saturating_add(DbWeight::get().writes(1 as Weight)) } fn cancel_queued(r: u32, ) -> Weight { - (0 as Weight) - .saturating_add((8246000 as Weight).saturating_mul(r as Weight)) + (48033000 as Weight) + .saturating_add((3610000 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 { - (302489000 as Weight) - .saturating_add((21766000 as Weight).saturating_mul(r as Weight)) + (92992000 as Weight) + .saturating_add((14292000 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 { - (178766000 as Weight) - .saturating_add((19805000 as Weight).saturating_mul(r as Weight)) - .saturating_add(DbWeight::get().reads(5 as Weight)) + (87374000 as Weight) + .saturating_add((10516000 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(5 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 { - (163433000 as Weight) - .saturating_add((8980000 as Weight).saturating_mul(r as Weight)) + (45044000 as Weight) + .saturating_add((10474000 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 { - (4854000 as Weight) + (4538000 as Weight) .saturating_add(DbWeight::get().writes(1 as Weight)) } fn note_preimage(b: u32, ) -> Weight { - (63227000 as Weight) + (61563000 as Weight) .saturating_add((4000 as Weight).saturating_mul(b as Weight)) - .saturating_add(DbWeight::get().reads(2 as Weight)) - .saturating_add(DbWeight::get().writes(2 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 { - (42569000 as Weight) - .saturating_add((4000 as Weight).saturating_mul(b as Weight)) + (41681000 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 { - (57894000 as Weight) + (56686000 as Weight) .saturating_add((3000 as Weight).saturating_mul(b as Weight)) - .saturating_add(DbWeight::get().reads(3 as Weight)) + .saturating_add(DbWeight::get().reads(2 as Weight)) .saturating_add(DbWeight::get().writes(1 as Weight)) } fn unlock_remove(r: u32, ) -> Weight { - (57008000 as Weight) - .saturating_add((275000 as Weight).saturating_mul(r as Weight)) + (56202000 as Weight) + .saturating_add((263000 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 { - (53179000 as Weight) - .saturating_add((460000 as Weight).saturating_mul(r as Weight)) + (51945000 as Weight) + .saturating_add((453000 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 { - (31536000 as Weight) - .saturating_add((445000 as Weight).saturating_mul(r as Weight)) + (31147000 as Weight) + .saturating_add((446000 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 { - (31418000 as Weight) - .saturating_add((446000 as Weight).saturating_mul(r as Weight)) + (30785000 as Weight) + .saturating_add((214000 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/frame/democracy/src/default_weight.rs b/frame/democracy/src/default_weight.rs index 5c761b81c205d..f64bd43ba3fc4 100644 --- a/frame/democracy/src/default_weight.rs +++ b/frame/democracy/src/default_weight.rs @@ -23,148 +23,149 @@ use frame_support::weights::{Weight, constants::RocksDbWeight as DbWeight}; -impl crate::WeightInfo for () { +pub struct WeightInfo; +impl pallet_democracy::WeightInfo for WeightInfo { fn propose(p: u32, ) -> Weight { - (173882000 as Weight) - .saturating_add((58000 as Weight).saturating_mul(p as Weight)) - .saturating_add(DbWeight::get().reads(4 as Weight)) - .saturating_add(DbWeight::get().writes(4 as Weight)) + (82728000 as Weight) + .saturating_add((11000 as Weight).saturating_mul(p as Weight)) + .saturating_add(DbWeight::get().reads(3 as Weight)) + .saturating_add(DbWeight::get().writes(3 as Weight)) } fn second(s: u32, ) -> Weight { - (111076000 as Weight) - .saturating_add((551000 as Weight).saturating_mul(s as Weight)) - .saturating_add(DbWeight::get().reads(2 as Weight)) - .saturating_add(DbWeight::get().writes(2 as Weight)) + (54903000 as Weight) + .saturating_add((254000 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 { - (150748000 as Weight) - .saturating_add((396000 as Weight).saturating_mul(r as Weight)) - .saturating_add(DbWeight::get().reads(4 as Weight)) - .saturating_add(DbWeight::get().writes(4 as Weight)) + (67070000 as Weight) + .saturating_add((452000 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 { - (118820000 as Weight) - .saturating_add((1193000 as Weight).saturating_mul(r as Weight)) - .saturating_add(DbWeight::get().reads(4 as Weight)) - .saturating_add(DbWeight::get().writes(4 as Weight)) + (66675000 as Weight) + .saturating_add((456000 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 { - (43278000 as Weight) + (41152000 as Weight) .saturating_add(DbWeight::get().reads(2 as Weight)) .saturating_add(DbWeight::get().writes(2 as Weight)) } fn blacklist(p: u32, ) -> Weight { - (442525000 as Weight) - .saturating_add((515000 as Weight).saturating_mul(p as Weight)) + (131046000 as Weight) + .saturating_add((694000 as Weight).saturating_mul(p as Weight)) .saturating_add(DbWeight::get().reads(5 as Weight)) .saturating_add(DbWeight::get().writes(6 as Weight)) } fn external_propose(v: u32, ) -> Weight { - (20349000 as Weight) - .saturating_add((114000 as Weight).saturating_mul(v as Weight)) + (19552000 as Weight) + .saturating_add((112000 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 { - (4889000 as Weight) + (4582000 as Weight) .saturating_add(DbWeight::get().writes(1 as Weight)) } fn external_propose_default() -> Weight { - (4875000 as Weight) + (4587000 as Weight) .saturating_add(DbWeight::get().writes(1 as Weight)) } fn fast_track() -> Weight { - (41326000 as Weight) + (39833000 as Weight) .saturating_add(DbWeight::get().reads(2 as Weight)) .saturating_add(DbWeight::get().writes(3 as Weight)) } fn veto_external(v: u32, ) -> Weight { - (42518000 as Weight) - .saturating_add((191000 as Weight).saturating_mul(v as Weight)) + (40935000 as Weight) + .saturating_add((188000 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_proposal() -> Weight { - (65871000 as Weight) + (64238000 as Weight) .saturating_add(DbWeight::get().reads(3 as Weight)) .saturating_add(DbWeight::get().writes(3 as Weight)) } fn cancel_referendum() -> Weight { - (26151000 as Weight) + (25280000 as Weight) .saturating_add(DbWeight::get().writes(1 as Weight)) } fn cancel_queued(r: u32, ) -> Weight { - (0 as Weight) - .saturating_add((8246000 as Weight).saturating_mul(r as Weight)) + (48033000 as Weight) + .saturating_add((3610000 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 { - (302489000 as Weight) - .saturating_add((21766000 as Weight).saturating_mul(r as Weight)) + (92992000 as Weight) + .saturating_add((14292000 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 { - (178766000 as Weight) - .saturating_add((19805000 as Weight).saturating_mul(r as Weight)) - .saturating_add(DbWeight::get().reads(5 as Weight)) + (87374000 as Weight) + .saturating_add((10516000 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(5 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 { - (163433000 as Weight) - .saturating_add((8980000 as Weight).saturating_mul(r as Weight)) + (45044000 as Weight) + .saturating_add((10474000 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 { - (4854000 as Weight) + (4538000 as Weight) .saturating_add(DbWeight::get().writes(1 as Weight)) } fn note_preimage(b: u32, ) -> Weight { - (63227000 as Weight) + (61563000 as Weight) .saturating_add((4000 as Weight).saturating_mul(b as Weight)) - .saturating_add(DbWeight::get().reads(2 as Weight)) - .saturating_add(DbWeight::get().writes(2 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 { - (42569000 as Weight) - .saturating_add((4000 as Weight).saturating_mul(b as Weight)) + (41681000 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 { - (57894000 as Weight) + (56686000 as Weight) .saturating_add((3000 as Weight).saturating_mul(b as Weight)) - .saturating_add(DbWeight::get().reads(3 as Weight)) + .saturating_add(DbWeight::get().reads(2 as Weight)) .saturating_add(DbWeight::get().writes(1 as Weight)) } fn unlock_remove(r: u32, ) -> Weight { - (57008000 as Weight) - .saturating_add((275000 as Weight).saturating_mul(r as Weight)) + (56202000 as Weight) + .saturating_add((263000 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 { - (53179000 as Weight) - .saturating_add((460000 as Weight).saturating_mul(r as Weight)) + (51945000 as Weight) + .saturating_add((453000 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 { - (31536000 as Weight) - .saturating_add((445000 as Weight).saturating_mul(r as Weight)) + (31147000 as Weight) + .saturating_add((446000 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 { - (31418000 as Weight) - .saturating_add((446000 as Weight).saturating_mul(r as Weight)) + (30785000 as Weight) + .saturating_add((214000 as Weight).saturating_mul(r as Weight)) .saturating_add(DbWeight::get().reads(2 as Weight)) .saturating_add(DbWeight::get().writes(2 as Weight)) } From a36189f5210bd19acc37fc871426f0ab97338836 Mon Sep 17 00:00:00 2001 From: Shawn Tabrizi Date: Tue, 22 Sep 2020 14:51:04 +0200 Subject: [PATCH 13/25] fix build --- frame/democracy/src/default_weight.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/frame/democracy/src/default_weight.rs b/frame/democracy/src/default_weight.rs index f64bd43ba3fc4..725c1578b73bf 100644 --- a/frame/democracy/src/default_weight.rs +++ b/frame/democracy/src/default_weight.rs @@ -23,8 +23,7 @@ use frame_support::weights::{Weight, constants::RocksDbWeight as DbWeight}; -pub struct WeightInfo; -impl pallet_democracy::WeightInfo for WeightInfo { +impl crate::WeightInfo for () { fn propose(p: u32, ) -> Weight { (82728000 as Weight) .saturating_add((11000 as Weight).saturating_mul(p as Weight)) From f60ccccec9d2bef67dd4cd4120021a3614530301 Mon Sep 17 00:00:00 2001 From: Gav Wood Date: Wed, 23 Sep 2020 15:18:59 +0200 Subject: [PATCH 14/25] Fixes --- frame/democracy/src/benchmarking.rs | 17 +- frame/democracy/src/lib.rs | 286 ++++++------------ frame/democracy/src/tests.rs | 2 + .../democracy/src/tests/external_proposing.rs | 2 +- frame/democracy/src/tests/public_proposals.rs | 6 +- 5 files changed, 115 insertions(+), 198 deletions(-) diff --git a/frame/democracy/src/benchmarking.rs b/frame/democracy/src/benchmarking.rs index ef46529d38934..e08d9cf229fd6 100644 --- a/frame/democracy/src/benchmarking.rs +++ b/frame/democracy/src/benchmarking.rs @@ -30,7 +30,7 @@ use sp_runtime::traits::{Bounded, One}; use crate::Module as Democracy; const SEED: u32 = 0; -const MAX_REFERENDUMS: u32 = 100; +const MAX_REFERENDUMS: u32 = 99; const MAX_SECONDERS: u32 = 100; const MAX_BYTES: u32 = 16_384; @@ -57,14 +57,14 @@ fn add_proposal(n: u32) -> Result { RawOrigin::Signed(other).into(), proposal_hash, value.into(), - MAX_PROPOSALS, + T::MaxProposals::get(), )?; Ok(proposal_hash) } fn add_referendum(n: u32) -> Result { - let proposal_hash = add_proposal::(n)?; + let proposal_hash: T::Hash = T::Hashing::hash_of(&n); let vote_threshold = VoteThreshold::SimpleMajority; Democracy::::inject_referendum( @@ -101,7 +101,7 @@ benchmarks! { _ { } propose { - let p in 1 .. MAX_PROPOSALS; + let p in 1 .. T::MaxProposals::get(); for i in 0 .. (p - 1) { add_proposal::(i)?; } @@ -110,7 +110,7 @@ benchmarks! { let proposal_hash: T::Hash = T::Hashing::hash_of(&0); let value = T::MinimumDeposit::get(); whitelist_account!(caller); - }: _(RawOrigin::Signed(caller), proposal_hash, value.into(), MAX_PROPOSALS) + }: _(RawOrigin::Signed(caller), proposal_hash, value.into(), T::MaxProposals::get()) verify { assert_eq!(Democracy::::public_props().len(), p as usize, "Proposals not created."); } @@ -216,7 +216,7 @@ benchmarks! { } blacklist { - let p in 1 .. MAX_PROPOSALS; + let p in 1 .. T::MaxProposals::get(); // Place our proposal at the end to make sure it's worst case. for i in 0 .. p - 1 { @@ -232,7 +232,7 @@ benchmarks! { let referendum_index = add_referendum::(0)?; assert!(Democracy::::referendum_status(referendum_index).is_ok()); - let call = Call::::blacklist(hash, Some(referendum_index), p); + let call = Call::::blacklist(hash, Some(referendum_index)); let origin = T::BlacklistOrigin::successful_origin(); }: { call.dispatch_bypass_filter(origin)? } verify { @@ -390,6 +390,7 @@ benchmarks! { assert_eq!(Democracy::::referendum_count(), r, "referenda not created"); // Launch public + assert!(add_proposal::(r).is_ok(), "proposal not created"); LastTabledWasExternal::put(true); let block_number = T::LaunchPeriod::get(); @@ -397,7 +398,7 @@ benchmarks! { }: { Democracy::::on_initialize(block_number) } verify { // One extra because of next public - assert_eq!(Democracy::::referendum_count(), r + 1, "referenda not created"); + assert_eq!(Democracy::::referendum_count(), r + 1, "proposal not accepted"); // All should be finished for i in 0 .. r { diff --git a/frame/democracy/src/lib.rs b/frame/democracy/src/lib.rs index 036d12db9f760..21a3e595872fa 100644 --- a/frame/democracy/src/lib.rs +++ b/frame/democracy/src/lib.rs @@ -192,9 +192,6 @@ const DEMOCRACY_ID: LockIdentifier = *b"democrac"; /// NOTE: This is not enforced by any logic. pub const MAX_VETOERS: u32 = 100; -/// The maximum number of public proposals that can exist at any time. -pub const MAX_PROPOSALS: u32 = 1000; - /// A proposal index. pub type PropIndex = u32; @@ -330,6 +327,9 @@ pub trait Trait: frame_system::Trait + Sized { /// Weight information for extrinsics in this pallet. type WeightInfo: WeightInfo; + + /// The maximum number of public proposals that can exist at any time. + type MaxProposals: Get; } #[derive(Clone, Encode, Decode, RuntimeDebug)] @@ -604,14 +604,11 @@ decl_module! { /// /// - `proposal_hash`: The hash of the proposal preimage. /// - `value`: The amount of deposit (must be at least `MinimumDeposit`). + /// - `prop_count`: Witness data which must be at least `PublicProps::::decode_len()` /// /// Emits `Proposed`. /// - /// # - /// - Complexity: `O(1)` - /// - Db reads: `PublicPropCount`, `PublicProps` - /// - Db writes: `PublicPropCount`, `PublicProps`, `DepositOf` - /// # + /// Weight: `O(p)` #[weight = T::WeightInfo::propose(*prop_count)] fn propose(origin, proposal_hash: T::Hash, @@ -624,7 +621,8 @@ decl_module! { let index = Self::public_prop_count(); let real_prop_count = PublicProps::::decode_len().unwrap_or(0) as u32; ensure!(real_prop_count <= prop_count, Error::::InvalidWitness); - ensure!(real_prop_count < MAX_PROPOSALS, Error::::TooManyProposals); + let max_proposals = T::MaxProposals::get(); + ensure!(real_prop_count < max_proposals, Error::::TooManyProposals); if let Some((until, _)) = >::get(proposal_hash) { ensure!( @@ -651,11 +649,7 @@ decl_module! { /// - `seconds_upper_bound`: an upper bound on the current number of seconds on this /// proposal. Extrinsic is weighted according to this value with no refund. /// - /// # - /// - Complexity: `O(S)` where S is the number of seconds a proposal already has. - /// - Db reads: `DepositOf` - /// - Db writes: `DepositOf` - /// # + /// Weight: `O(S)` where S is the number of seconds a proposal already has. #[weight = T::WeightInfo::second(*seconds_upper_bound)] fn second(origin, #[compact] proposal: PropIndex, #[compact] seconds_upper_bound: u32) { let who = ensure_signed(origin)?; @@ -678,12 +672,7 @@ decl_module! { /// - `ref_index`: The index of the referendum to vote for. /// - `vote`: The vote configuration. /// - /// # - /// - Complexity: `O(R)` where R is the number of referendums the voter has voted on. - /// weight is charged as if maximum votes. - /// - Db reads: `ReferendumInfoOf`, `VotingOf`, `balances locks` - /// - Db writes: `ReferendumInfoOf`, `VotingOf`, `balances locks` - /// # + /// Weight: `O(R)` where R is the number of referendums the voter has voted on. #[weight = T::WeightInfo::vote_new(T::MaxVotes::get()) .max(T::WeightInfo::vote_existing(T::MaxVotes::get()))] fn vote(origin, @@ -701,11 +690,7 @@ decl_module! { /// /// -`ref_index`: The index of the referendum to cancel. /// - /// # - /// - Complexity: `O(1)`. - /// - Db reads: `ReferendumInfoOf`, `Cancellations` - /// - Db writes: `ReferendumInfoOf`, `Cancellations` - /// # + /// Weight: `O(1)`. #[weight = (T::WeightInfo::emergency_cancel(), DispatchClass::Operational)] fn emergency_cancel(origin, ref_index: ReferendumIndex) { T::CancellationOrigin::ensure_origin(origin)?; @@ -718,62 +703,6 @@ decl_module! { Self::internal_cancel_referendum(ref_index); } - /// Permanently place a proposal into the blacklist. This prevents it from ever being - /// proposed again. - /// - /// If called on an queued public or external proposal, then this will result in it being - /// removed. If the `ref_index` supplied is an active referendum with the proposal hash, - /// then it will be cancelled. - /// - /// The dispatch origin of this call must be `BlacklistOrigin`. - /// - /// - `proposal_hash`: The proposal hash to blacklist permanently. - /// - `ref_index`: An ongoing referendum whose hash is `proposal_hash`, which will be - /// cancelled. - #[weight = (T::WeightInfo::blacklist(*prop_count), DispatchClass::Operational)] - fn blacklist(origin, - proposal_hash: T::Hash, - maybe_ref_index: Option, - #[compact] prop_count: u32, - ) { - T::BlacklistOrigin::ensure_origin(origin)?; - - let real_prop_count = PublicProps::::decode_len().unwrap_or(0) as u32; - ensure!(real_prop_count <= prop_count, Error::::InvalidWitness); - - // Insert the proposal into the blacklist. - let permanent = (T::BlockNumber::max_value(), Vec::::new()); - Blacklist::::insert(&proposal_hash, permanent); - - // Remove the queued proposal, if it's there. - PublicProps::::mutate(|props| { - if let Some(index) = props.iter().position(|p| p.1 == proposal_hash) { - let (prop_index, ..) = props.remove(index); - if let Some((whos, amount)) = DepositOf::::take(prop_index) { - for who in whos.into_iter() { - T::Slash::on_unbalanced(T::Currency::slash_reserved(&who, amount).0); - } - } - } - }); - - // Remove the external queued referendum, if it's there. - if matches!(NextExternal::::get(), Some((h, ..)) if h == proposal_hash) { - NextExternal::::kill(); - } - - // Remove the referendum, if it's there. - if let Some(ref_index) = maybe_ref_index { - let status = Self::referendum_status(ref_index)?; - let h = status.proposal_hash; - if h == proposal_hash { - Self::internal_cancel_referendum(ref_index); - } - } - - Self::deposit_event(RawEvent::Blacklisted(proposal_hash)); - } - /// Schedule a referendum to be tabled once it is legal to schedule an external /// referendum. /// @@ -781,12 +710,8 @@ decl_module! { /// /// - `proposal_hash`: The preimage hash of the proposal. /// - /// # - /// - Complexity `O(V)` with V number of vetoers in the blacklist of proposal. + /// Weight: `O(V)` with V number of vetoers in the blacklist of proposal. /// Decoding vec of length V. Charged as maximum - /// - Db reads: `NextExternal`, `Blacklist` - /// - Db writes: `NextExternal` - /// # #[weight = T::WeightInfo::external_propose(MAX_VETOERS)] fn external_propose(origin, proposal_hash: T::Hash) { T::ExternalOrigin::ensure_origin(origin)?; @@ -810,10 +735,7 @@ decl_module! { /// Unlike `external_propose`, blacklisting has no effect on this and it may replace a /// pre-scheduled `external_propose` call. /// - /// # - /// - Complexity: `O(1)` - /// - Db write: `NextExternal` - /// # + /// Weight: `O(1)` #[weight = T::WeightInfo::external_propose_majority()] fn external_propose_majority(origin, proposal_hash: T::Hash) { T::ExternalMajorityOrigin::ensure_origin(origin)?; @@ -830,10 +752,7 @@ decl_module! { /// Unlike `external_propose`, blacklisting has no effect on this and it may replace a /// pre-scheduled `external_propose` call. /// - /// # - /// - Complexity: `O(1)` - /// - Db write: `NextExternal` - /// # + /// Weight: `O(1)` #[weight = T::WeightInfo::external_propose_default()] fn external_propose_default(origin, proposal_hash: T::Hash) { T::ExternalDefaultOrigin::ensure_origin(origin)?; @@ -854,12 +773,7 @@ decl_module! { /// /// Emits `Started`. /// - /// # - /// - Complexity: `O(1)` - /// - Db reads: `NextExternal`, `ReferendumCount` - /// - Db writes: `NextExternal`, `ReferendumCount`, `ReferendumInfoOf` - /// - Base Weight: 30.1 µs - /// # + /// Weight: `O(1)` #[weight = T::WeightInfo::fast_track()] fn fast_track(origin, proposal_hash: T::Hash, @@ -904,12 +818,7 @@ decl_module! { /// /// Emits `Vetoed`. /// - /// # - /// - Complexity: `O(V + log(V))` where V is number of `existing vetoers` - /// Performs a binary search on `existing_vetoers` which should not be very large. - /// - Db reads: `NextExternal`, `Blacklist` - /// - Db writes: `NextExternal`, `Blacklist` - /// # + /// Weight: `O(V + log(V))` where V is number of `existing vetoers` #[weight = T::WeightInfo::veto_external(MAX_VETOERS)] fn veto_external(origin, proposal_hash: T::Hash) { let who = T::VetoOrigin::ensure_origin(origin)?; @@ -934,39 +843,13 @@ decl_module! { >::kill(); } - /// Remove a proposal. - /// - /// The dispatch origin of this call must be _Root_. - /// - /// - `ref_index`: The index of the proposal to cancel. - /// - /// # - /// - Complexity: `O(1)`. - /// - Db writes: `ReferendumInfoOf` - /// - Base Weight: 21.57 µs - /// # - #[weight = T::WeightInfo::cancel_proposal()] - fn cancel_proposal(origin, #[compact] prop_index: PropIndex) { - T::CancelProposalOrigin::ensure_origin(origin)?; - - PublicProps::::mutate(|props| props.retain(|p| p.0 != prop_index)); - if let Some((whos, amount)) = DepositOf::::take(prop_index) { - for who in whos.into_iter() { - T::Slash::on_unbalanced(T::Currency::slash_reserved(&who, amount).0); - } - } - } - /// Remove a referendum. /// /// The dispatch origin of this call must be _Root_. /// /// - `ref_index`: The index of the referendum to cancel. /// - /// # - /// - Complexity: `O(1)`. - /// - Db writes: `ReferendumInfoOf` - /// # + /// # Weight: `O(1)`. #[weight = T::WeightInfo::cancel_referendum()] fn cancel_referendum(origin, #[compact] ref_index: ReferendumIndex) { ensure_root(origin)?; @@ -979,11 +862,7 @@ decl_module! { /// /// - `which`: The index of the referendum to cancel. /// - /// # - /// - `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` - /// # + /// Weight: `O(D)` where `D` is the items in the dispatch queue. Weighted as `D = 10`. #[weight = (T::WeightInfo::cancel_queued(10), DispatchClass::Operational)] fn cancel_queued(origin, which: ReferendumIndex) { ensure_root(origin)?; @@ -1017,16 +896,10 @@ decl_module! { /// /// Emits `Delegated`. /// - /// # - /// - Complexity: `O(R)` where R is the number of referendums the voter delegating to has + /// Weight: `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: 3*`VotingOf`, `origin account locks` - /// - Db writes: 3*`VotingOf`, `origin account locks` - /// - Db reads per votes: `ReferendumInfoOf` - /// - Db writes per votes: `ReferendumInfoOf` // 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 = T::WeightInfo::delegate(T::MaxVotes::get())] pub fn delegate( origin, @@ -1050,16 +923,10 @@ decl_module! { /// /// Emits `Undelegated`. /// - /// # - /// - Complexity: `O(R)` where R is the number of referendums the voter delegating to has + /// Weight: `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` - /// - Db writes: 2*`VotingOf` - /// - Db reads per votes: `ReferendumInfoOf` - /// - Db writes per votes: `ReferendumInfoOf` // 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 = T::WeightInfo::undelegate(T::MaxVotes::get().into())] fn undelegate(origin) -> DispatchResultWithPostInfo { let who = ensure_signed(origin)?; @@ -1071,10 +938,7 @@ decl_module! { /// /// The dispatch origin of this call must be _Root_. /// - /// # - /// - `O(1)`. - /// - Db writes: `PublicProps` - /// # + /// Weight: `O(1)`. #[weight = T::WeightInfo::clear_public_proposals()] fn clear_public_proposals(origin) { ensure_root(origin)?; @@ -1090,11 +954,7 @@ decl_module! { /// /// Emits `PreimageNoted`. /// - /// # - /// - Complexity: `O(E)` with E size of `encoded_proposal` (protected by a required deposit). - /// - Db reads: `Preimages` - /// - Db writes: `Preimages` - /// # + /// Weight: `O(E)` with E size of `encoded_proposal` (protected by a required deposit). #[weight = T::WeightInfo::note_preimage(encoded_proposal.len() as u32)] fn note_preimage(origin, encoded_proposal: Vec) { Self::note_preimage_inner(ensure_signed(origin)?, encoded_proposal)?; @@ -1121,11 +981,7 @@ decl_module! { /// /// Emits `PreimageNoted`. /// - /// # - /// - Complexity: `O(E)` with E size of `encoded_proposal` (protected by a required deposit). - /// - Db reads: `Preimages` - /// - Db writes: `Preimages` - /// # + /// Weight: `O(E)` with E size of `encoded_proposal` (protected by a required deposit). #[weight = T::WeightInfo::note_imminent_preimage(encoded_proposal.len() as u32)] fn note_imminent_preimage(origin, encoded_proposal: Vec) -> DispatchResultWithPostInfo { Self::note_imminent_preimage_inner(ensure_signed(origin)?, encoded_proposal)?; @@ -1161,11 +1017,7 @@ decl_module! { /// /// Emits `PreimageReaped`. /// - /// # - /// - Complexity: `O(D)` where D is length of proposal. - /// - Db reads: `Preimages`, provider account data - /// - Db writes: `Preimages` provider account data - /// # + /// Weight: `O(D)` where D is length of proposal. #[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)?; @@ -1199,11 +1051,7 @@ decl_module! { /// /// - `target`: The account to remove the lock on. /// - /// # - /// - Complexity `O(R)` with R number of vote of target. - /// - Db reads: `VotingOf`, `balances locks`, `target account` - /// - Db writes: `VotingOf`, `balances locks`, `target account` - /// # + /// Weight: `O(R)` with R number of vote of target. #[weight = T::WeightInfo::unlock_set(T::MaxVotes::get()) .max(T::WeightInfo::unlock_remove(T::MaxVotes::get()))] fn unlock(origin, target: T::AccountId) { @@ -1236,12 +1084,8 @@ decl_module! { /// /// - `index`: The index of referendum of the vote to be removed. /// - /// # - /// - `O(R + log R)` where R is the number of referenda that `target` has voted on. + /// Weight: `O(R + log R)` where R is the number of referenda that `target` has voted on. /// Weight is calculated for the maximum number of vote. - /// - Db reads: `ReferendumInfoOf`, `VotingOf` - /// - Db writes: `ReferendumInfoOf`, `VotingOf` - /// # #[weight = T::WeightInfo::remove_vote(T::MaxVotes::get())] fn remove_vote(origin, index: ReferendumIndex) -> DispatchResult { let who = ensure_signed(origin)?; @@ -1261,12 +1105,8 @@ decl_module! { /// referendum `index`. /// - `index`: The index of referendum of the vote to be removed. /// - /// # - /// - `O(R + log R)` where R is the number of referenda that `target` has voted on. + /// Weight: `O(R + log R)` where R is the number of referenda that `target` has voted on. /// Weight is calculated for the maximum number of vote. - /// - Db reads: `ReferendumInfoOf`, `VotingOf` - /// - Db writes: `ReferendumInfoOf`, `VotingOf` - /// # #[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)?; @@ -1281,6 +1121,80 @@ decl_module! { ensure_root(origin)?; Self::do_enact_proposal(proposal_hash, index) } + + /// Permanently place a proposal into the blacklist. This prevents it from ever being + /// proposed again. + /// + /// If called on an queued public or external proposal, then this will result in it being + /// removed. If the `ref_index` supplied is an active referendum with the proposal hash, + /// then it will be cancelled. + /// + /// The dispatch origin of this call must be `BlacklistOrigin`. + /// + /// - `proposal_hash`: The proposal hash to blacklist permanently. + /// - `ref_index`: An ongoing referendum whose hash is `proposal_hash`, which will be + /// cancelled. + /// + /// Weight: `O(p)` (though as this is an high-privilege dispatch, we assume it has a + /// reasonable value). + #[weight = (T::WeightInfo::blacklist(T::MaxProposals::get()), DispatchClass::Operational)] + fn blacklist(origin, + proposal_hash: T::Hash, + maybe_ref_index: Option, + ) { + T::BlacklistOrigin::ensure_origin(origin)?; + + // Insert the proposal into the blacklist. + let permanent = (T::BlockNumber::max_value(), Vec::::new()); + Blacklist::::insert(&proposal_hash, permanent); + + // Remove the queued proposal, if it's there. + PublicProps::::mutate(|props| { + if let Some(index) = props.iter().position(|p| p.1 == proposal_hash) { + let (prop_index, ..) = props.remove(index); + if let Some((whos, amount)) = DepositOf::::take(prop_index) { + for who in whos.into_iter() { + T::Slash::on_unbalanced(T::Currency::slash_reserved(&who, amount).0); + } + } + } + }); + + // Remove the external queued referendum, if it's there. + if matches!(NextExternal::::get(), Some((h, ..)) if h == proposal_hash) { + NextExternal::::kill(); + } + + // Remove the referendum, if it's there. + if let Some(ref_index) = maybe_ref_index { + let status = Self::referendum_status(ref_index)?; + let h = status.proposal_hash; + if h == proposal_hash { + Self::internal_cancel_referendum(ref_index); + } + } + + Self::deposit_event(RawEvent::Blacklisted(proposal_hash)); + } + + /// Remove a proposal. + /// + /// The dispatch origin of this call must be _Root_. + /// + /// - `prop_index`: The index of the proposal to cancel. + /// + /// Weight: `O(p)` where `p = PublicProps::::decode_len()` + #[weight = T::WeightInfo::cancel_proposal()] + fn cancel_proposal(origin, #[compact] prop_index: PropIndex) { + T::CancelProposalOrigin::ensure_origin(origin)?; + + PublicProps::::mutate(|props| props.retain(|p| p.0 != prop_index)); + if let Some((whos, amount)) = DepositOf::::take(prop_index) { + for who in whos.into_iter() { + T::Slash::on_unbalanced(T::Currency::slash_reserved(&who, amount).0); + } + } + } } } diff --git a/frame/democracy/src/tests.rs b/frame/democracy/src/tests.rs index 283cc720d9af4..0a2cc4c965f72 100644 --- a/frame/democracy/src/tests.rs +++ b/frame/democracy/src/tests.rs @@ -153,6 +153,7 @@ parameter_types! { pub const EnactmentPeriod: u64 = 2; pub const CooloffPeriod: u64 = 2; pub const MaxVotes: u32 = 100; + pub const MaxProposals: u32 = MAX_PROPOSALS; } ord_parameter_types! { pub const One: u64 = 1; @@ -209,6 +210,7 @@ impl super::Trait for Test { type OperationalPreimageOrigin = EnsureSignedBy; type PalletsOrigin = OriginCaller; type WeightInfo = (); + type MaxProposals = MaxProposals; } pub fn new_test_ext() -> sp_io::TestExternalities { diff --git a/frame/democracy/src/tests/external_proposing.rs b/frame/democracy/src/tests/external_proposing.rs index 7710a411d86c2..3f9be2137906b 100644 --- a/frame/democracy/src/tests/external_proposing.rs +++ b/frame/democracy/src/tests/external_proposing.rs @@ -90,7 +90,7 @@ fn external_blacklisting_should_work() { )); let hash = set_balance_proposal_hash(2); - assert_ok!(Democracy::blacklist(Origin::root(), hash, None, 1)); + assert_ok!(Democracy::blacklist(Origin::root(), hash, None)); fast_forward_to(2); assert!(Democracy::referendum_status(0).is_err()); diff --git a/frame/democracy/src/tests/public_proposals.rs b/frame/democracy/src/tests/public_proposals.rs index aac49770702d9..bf7a498f3e820 100644 --- a/frame/democracy/src/tests/public_proposals.rs +++ b/frame/democracy/src/tests/public_proposals.rs @@ -136,8 +136,8 @@ fn blacklisting_should_work() { assert_ok!(propose_set_balance_and_note(1, 2, 2)); assert_ok!(propose_set_balance_and_note(1, 4, 4)); - assert_noop!(Democracy::blacklist(Origin::signed(1), hash.clone(), None, 1), BadOrigin); - assert_ok!(Democracy::blacklist(Origin::root(), hash, None, 2)); + assert_noop!(Democracy::blacklist(Origin::signed(1), hash.clone(), None), BadOrigin); + assert_ok!(Democracy::blacklist(Origin::root(), hash, None)); assert_eq!(Democracy::backing_for(0), None); assert_eq!(Democracy::backing_for(1), Some(4)); @@ -148,7 +148,7 @@ fn blacklisting_should_work() { let hash = set_balance_proposal_hash(4); assert!(Democracy::referendum_status(0).is_ok()); - assert_ok!(Democracy::blacklist(Origin::root(), hash, Some(0), 1)); + assert_ok!(Democracy::blacklist(Origin::root(), hash, Some(0))); assert!(Democracy::referendum_status(0).is_err()); }); } From 13cace0713b215a1181ca4dd23b482b282779686 Mon Sep 17 00:00:00 2001 From: Gav Wood Date: Wed, 23 Sep 2020 15:23:46 +0200 Subject: [PATCH 15/25] Fixes --- bin/node/runtime/src/weights/pallet_democracy.rs | 3 ++- frame/democracy/src/benchmarking.rs | 7 ++++++- frame/democracy/src/default_weight.rs | 3 ++- frame/democracy/src/lib.rs | 4 ++-- 4 files changed, 12 insertions(+), 5 deletions(-) diff --git a/bin/node/runtime/src/weights/pallet_democracy.rs b/bin/node/runtime/src/weights/pallet_democracy.rs index 054322bff57c6..650ebb215dbe3 100644 --- a/bin/node/runtime/src/weights/pallet_democracy.rs +++ b/bin/node/runtime/src/weights/pallet_democracy.rs @@ -83,8 +83,9 @@ impl pallet_democracy::WeightInfo for WeightInfo { .saturating_add(DbWeight::get().reads(2 as Weight)) .saturating_add(DbWeight::get().writes(2 as Weight)) } - fn cancel_proposal() -> Weight { + fn cancel_proposal(p: u32, ) -> Weight { (64238000 as Weight) + .saturating_add((694000 as Weight).saturating_mul(p as Weight)) .saturating_add(DbWeight::get().reads(3 as Weight)) .saturating_add(DbWeight::get().writes(3 as Weight)) } diff --git a/frame/democracy/src/benchmarking.rs b/frame/democracy/src/benchmarking.rs index e08d9cf229fd6..5e492296227b3 100644 --- a/frame/democracy/src/benchmarking.rs +++ b/frame/democracy/src/benchmarking.rs @@ -322,7 +322,12 @@ benchmarks! { } cancel_proposal { - let proposal_index = add_proposal::(0)?; + let p in 1 .. T::MaxProposals::get(); + + // Place our proposal at the end to make sure it's worst case. + for i in 0 .. p { + add_proposal::(i)?; + } }: _(RawOrigin::Root, 0) cancel_referendum { diff --git a/frame/democracy/src/default_weight.rs b/frame/democracy/src/default_weight.rs index 725c1578b73bf..297dbc8c9c2f3 100644 --- a/frame/democracy/src/default_weight.rs +++ b/frame/democracy/src/default_weight.rs @@ -84,8 +84,9 @@ impl crate::WeightInfo for () { .saturating_add(DbWeight::get().reads(2 as Weight)) .saturating_add(DbWeight::get().writes(2 as Weight)) } - fn cancel_proposal() -> Weight { + fn cancel_proposal(p: u32, ) -> Weight { (64238000 as Weight) + .saturating_add((694000 as Weight).saturating_mul(p as Weight)) .saturating_add(DbWeight::get().reads(3 as Weight)) .saturating_add(DbWeight::get().writes(3 as Weight)) } diff --git a/frame/democracy/src/lib.rs b/frame/democracy/src/lib.rs index 21a3e595872fa..06c93300204f3 100644 --- a/frame/democracy/src/lib.rs +++ b/frame/democracy/src/lib.rs @@ -215,7 +215,7 @@ pub trait WeightInfo { fn fast_track() -> Weight; fn veto_external(v: u32, ) -> Weight; fn cancel_referendum() -> Weight; - fn cancel_proposal() -> Weight; + fn cancel_proposal(p: u32, ) -> Weight; fn cancel_queued(r: u32, ) -> Weight; fn on_initialize_base(r: u32, ) -> Weight; fn delegate(r: u32, ) -> Weight; @@ -1184,7 +1184,7 @@ decl_module! { /// - `prop_index`: The index of the proposal to cancel. /// /// Weight: `O(p)` where `p = PublicProps::::decode_len()` - #[weight = T::WeightInfo::cancel_proposal()] + #[weight = T::WeightInfo::cancel_proposal(T::MaxProposals::get())] fn cancel_proposal(origin, #[compact] prop_index: PropIndex) { T::CancelProposalOrigin::ensure_origin(origin)?; From 02e4fe8c9edecaf9bc92c16caa5abee3b8a47a99 Mon Sep 17 00:00:00 2001 From: Gav Wood Date: Wed, 23 Sep 2020 15:50:18 +0200 Subject: [PATCH 16/25] Fixes --- bin/node/runtime/src/lib.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/bin/node/runtime/src/lib.rs b/bin/node/runtime/src/lib.rs index 30e0d640a2adb..73d13bd3a17c7 100644 --- a/bin/node/runtime/src/lib.rs +++ b/bin/node/runtime/src/lib.rs @@ -483,6 +483,7 @@ parameter_types! { // One cent: $10,000 / MB pub const PreimageByteDeposit: Balance = 1 * CENTS; pub const MaxVotes: u32 = 100; + pub const MaxProposals: u32 = 100; } impl pallet_democracy::Trait for Runtime { @@ -527,6 +528,7 @@ impl pallet_democracy::Trait for Runtime { type PalletsOrigin = OriginCaller; type MaxVotes = MaxVotes; type WeightInfo = weights::pallet_democracy::WeightInfo; + type MaxProposals = MaxProposals; } parameter_types! { From 88dc626d0fbab3da70b56efbc20fb398cce88999 Mon Sep 17 00:00:00 2001 From: Gav Wood Date: Wed, 23 Sep 2020 15:51:30 +0200 Subject: [PATCH 17/25] Fixes --- frame/democracy/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frame/democracy/src/lib.rs b/frame/democracy/src/lib.rs index 06c93300204f3..e25cd6ba2c3f8 100644 --- a/frame/democracy/src/lib.rs +++ b/frame/democracy/src/lib.rs @@ -1125,7 +1125,7 @@ decl_module! { /// Permanently place a proposal into the blacklist. This prevents it from ever being /// proposed again. /// - /// If called on an queued public or external proposal, then this will result in it being + /// If called on a queued public or external proposal, then this will result in it being /// removed. If the `ref_index` supplied is an active referendum with the proposal hash, /// then it will be cancelled. /// From 775b637fd698823c0e8f242fcc4ac9a028cefca0 Mon Sep 17 00:00:00 2001 From: Gavin Wood Date: Thu, 24 Sep 2020 11:46:51 +0200 Subject: [PATCH 18/25] Update frame/democracy/src/lib.rs Co-authored-by: Shawn Tabrizi --- frame/democracy/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frame/democracy/src/lib.rs b/frame/democracy/src/lib.rs index e25cd6ba2c3f8..3b65cbc94d6f4 100644 --- a/frame/democracy/src/lib.rs +++ b/frame/democracy/src/lib.rs @@ -1179,7 +1179,7 @@ decl_module! { /// Remove a proposal. /// - /// The dispatch origin of this call must be _Root_. + /// The dispatch origin of this call must be `CancelProposalOrigin`. /// /// - `prop_index`: The index of the proposal to cancel. /// From 9c0cf8dd02ecd9878e1f7af4d9b75f9737d1ca2b Mon Sep 17 00:00:00 2001 From: Gav Wood Date: Thu, 24 Sep 2020 11:57:41 +0200 Subject: [PATCH 19/25] Fixes --- bin/node/runtime/src/weights/pallet_democracy.rs | 3 +-- frame/democracy/src/benchmarking.rs | 6 ++---- frame/democracy/src/default_weight.rs | 3 +-- frame/democracy/src/lib.rs | 6 ++---- frame/democracy/src/tests.rs | 2 -- frame/democracy/src/tests/public_proposals.rs | 2 -- 6 files changed, 6 insertions(+), 16 deletions(-) diff --git a/bin/node/runtime/src/weights/pallet_democracy.rs b/bin/node/runtime/src/weights/pallet_democracy.rs index 013b41ee8a2f9..4adada3868204 100644 --- a/bin/node/runtime/src/weights/pallet_democracy.rs +++ b/bin/node/runtime/src/weights/pallet_democracy.rs @@ -24,9 +24,8 @@ use sp_std::marker::PhantomData; pub struct WeightInfo(PhantomData); impl pallet_democracy::WeightInfo for WeightInfo { - fn propose(p: u32, ) -> Weight { + fn propose() -> Weight { (49113000 as Weight) - .saturating_add((11000 as Weight).saturating_mul(p as Weight)) .saturating_add(T::DbWeight::get().reads(2 as Weight)) .saturating_add(T::DbWeight::get().writes(3 as Weight)) } diff --git a/frame/democracy/src/benchmarking.rs b/frame/democracy/src/benchmarking.rs index 5e492296227b3..9748213eb7947 100644 --- a/frame/democracy/src/benchmarking.rs +++ b/frame/democracy/src/benchmarking.rs @@ -57,7 +57,6 @@ fn add_proposal(n: u32) -> Result { RawOrigin::Signed(other).into(), proposal_hash, value.into(), - T::MaxProposals::get(), )?; Ok(proposal_hash) @@ -101,8 +100,7 @@ benchmarks! { _ { } propose { - let p in 1 .. T::MaxProposals::get(); - for i in 0 .. (p - 1) { + for i in 0 .. (T::MaxProposals::get() - 1) { add_proposal::(i)?; } @@ -110,7 +108,7 @@ benchmarks! { let proposal_hash: T::Hash = T::Hashing::hash_of(&0); let value = T::MinimumDeposit::get(); whitelist_account!(caller); - }: _(RawOrigin::Signed(caller), proposal_hash, value.into(), T::MaxProposals::get()) + }: _(RawOrigin::Signed(caller), proposal_hash, value.into()) verify { assert_eq!(Democracy::::public_props().len(), p as usize, "Proposals not created."); } diff --git a/frame/democracy/src/default_weight.rs b/frame/democracy/src/default_weight.rs index 297dbc8c9c2f3..2b75b1c50f847 100644 --- a/frame/democracy/src/default_weight.rs +++ b/frame/democracy/src/default_weight.rs @@ -24,9 +24,8 @@ use frame_support::weights::{Weight, constants::RocksDbWeight as DbWeight}; impl crate::WeightInfo for () { - fn propose(p: u32, ) -> Weight { + fn propose() -> Weight { (82728000 as Weight) - .saturating_add((11000 as Weight).saturating_mul(p as Weight)) .saturating_add(DbWeight::get().reads(3 as Weight)) .saturating_add(DbWeight::get().writes(3 as Weight)) } diff --git a/frame/democracy/src/lib.rs b/frame/democracy/src/lib.rs index e25cd6ba2c3f8..b5357fbe52f76 100644 --- a/frame/democracy/src/lib.rs +++ b/frame/democracy/src/lib.rs @@ -203,7 +203,7 @@ type NegativeImbalanceOf = <::Currency as Currency<::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; @@ -609,18 +609,16 @@ decl_module! { /// Emits `Proposed`. /// /// Weight: `O(p)` - #[weight = T::WeightInfo::propose(*prop_count)] + #[weight = T::WeightInfo::propose()] fn propose(origin, proposal_hash: T::Hash, #[compact] value: BalanceOf, - #[compact] prop_count: u32, ) { let who = ensure_signed(origin)?; ensure!(value >= T::MinimumDeposit::get(), Error::::ValueLow); let index = Self::public_prop_count(); let real_prop_count = PublicProps::::decode_len().unwrap_or(0) as u32; - ensure!(real_prop_count <= prop_count, Error::::InvalidWitness); let max_proposals = T::MaxProposals::get(); ensure!(real_prop_count < max_proposals, Error::::TooManyProposals); diff --git a/frame/democracy/src/tests.rs b/frame/democracy/src/tests.rs index 0a2cc4c965f72..bcc7099bb34a4 100644 --- a/frame/democracy/src/tests.rs +++ b/frame/democracy/src/tests.rs @@ -276,7 +276,6 @@ fn propose_set_balance(who: u64, value: u64, delay: u64) -> DispatchResult { Origin::signed(who), set_balance_proposal_hash(value), delay, - MAX_PROPOSALS, ) } @@ -285,7 +284,6 @@ fn propose_set_balance_and_note(who: u64, value: u64, delay: u64) -> DispatchRes Origin::signed(who), set_balance_proposal_hash_and_note(value), delay, - MAX_PROPOSALS, ) } diff --git a/frame/democracy/src/tests/public_proposals.rs b/frame/democracy/src/tests/public_proposals.rs index bf7a498f3e820..58b558d2b3a1c 100644 --- a/frame/democracy/src/tests/public_proposals.rs +++ b/frame/democracy/src/tests/public_proposals.rs @@ -103,13 +103,11 @@ fn invalid_max_proposals_should_fail() { Origin::signed(1), set_balance_proposal_hash(2), 2, - 0, )); assert_noop!(Democracy::propose( Origin::signed(1), set_balance_proposal_hash(2), 2, - 0, ), Error::::InvalidWitness); }); } From 2ba9cdd1999cabeb6a3b985684836bb7be479c94 Mon Sep 17 00:00:00 2001 From: Gav Wood Date: Thu, 24 Sep 2020 11:59:35 +0200 Subject: [PATCH 20/25] Fixes --- frame/democracy/src/lib.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/frame/democracy/src/lib.rs b/frame/democracy/src/lib.rs index b5357fbe52f76..fb5e8785ca267 100644 --- a/frame/democracy/src/lib.rs +++ b/frame/democracy/src/lib.rs @@ -1165,10 +1165,10 @@ decl_module! { // Remove the referendum, if it's there. if let Some(ref_index) = maybe_ref_index { - let status = Self::referendum_status(ref_index)?; - let h = status.proposal_hash; - if h == proposal_hash { - Self::internal_cancel_referendum(ref_index); + if let Ok(status) = Self::referendum_status(ref_index) { + if status.proposal_hash == proposal_hash { + Self::internal_cancel_referendum(ref_index); + } } } From 4ecbddf47eb5f3a2e992cf9731f45d795b2bf976 Mon Sep 17 00:00:00 2001 From: Gav Wood Date: Thu, 24 Sep 2020 12:00:36 +0200 Subject: [PATCH 21/25] Fixes --- frame/democracy/src/tests/public_proposals.rs | 16 ---------------- 1 file changed, 16 deletions(-) diff --git a/frame/democracy/src/tests/public_proposals.rs b/frame/democracy/src/tests/public_proposals.rs index 58b558d2b3a1c..d862aa98e7880 100644 --- a/frame/democracy/src/tests/public_proposals.rs +++ b/frame/democracy/src/tests/public_proposals.rs @@ -96,22 +96,6 @@ fn invalid_seconds_upper_bound_should_not_work() { }); } -#[test] -fn invalid_max_proposals_should_fail() { - new_test_ext().execute_with(|| { - assert_ok!(Democracy::propose( - Origin::signed(1), - set_balance_proposal_hash(2), - 2, - )); - assert_noop!(Democracy::propose( - Origin::signed(1), - set_balance_proposal_hash(2), - 2, - ), Error::::InvalidWitness); - }); -} - #[test] fn cancel_proposal_should_work() { new_test_ext().execute_with(|| { From 2f84c91e7aeeec6bf9ccf3a3bf8594b4b71bdf21 Mon Sep 17 00:00:00 2001 From: Gav Wood Date: Thu, 24 Sep 2020 12:02:00 +0200 Subject: [PATCH 22/25] Fixes --- frame/democracy/src/benchmarking.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/frame/democracy/src/benchmarking.rs b/frame/democracy/src/benchmarking.rs index 9748213eb7947..1a81a94aa4fe1 100644 --- a/frame/democracy/src/benchmarking.rs +++ b/frame/democracy/src/benchmarking.rs @@ -110,6 +110,7 @@ benchmarks! { whitelist_account!(caller); }: _(RawOrigin::Signed(caller), proposal_hash, value.into()) verify { + let p = T::MaxProposals::get(); assert_eq!(Democracy::::public_props().len(), p as usize, "Proposals not created."); } From 42b909373c54cfd804c62887aac1b650799cb8d0 Mon Sep 17 00:00:00 2001 From: Gav Wood Date: Thu, 24 Sep 2020 13:18:51 +0200 Subject: [PATCH 23/25] Fixes --- frame/democracy/src/lib.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/frame/democracy/src/lib.rs b/frame/democracy/src/lib.rs index 47205272b7814..6aeb518f72f29 100644 --- a/frame/democracy/src/lib.rs +++ b/frame/democracy/src/lib.rs @@ -604,7 +604,6 @@ decl_module! { /// /// - `proposal_hash`: The hash of the proposal preimage. /// - `value`: The amount of deposit (must be at least `MinimumDeposit`). - /// - `prop_count`: Witness data which must be at least `PublicProps::::decode_len()` /// /// Emits `Proposed`. /// From 97af8114b298deb4b18614777a3bab87b872585a Mon Sep 17 00:00:00 2001 From: Shawn Tabrizi Date: Thu, 24 Sep 2020 22:18:57 +0200 Subject: [PATCH 24/25] doc updates --- frame/democracy/src/benchmarking.rs | 10 +++++++--- frame/democracy/src/lib.rs | 2 +- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/frame/democracy/src/benchmarking.rs b/frame/democracy/src/benchmarking.rs index 1a81a94aa4fe1..0b822e885989e 100644 --- a/frame/democracy/src/benchmarking.rs +++ b/frame/democracy/src/benchmarking.rs @@ -100,7 +100,9 @@ benchmarks! { _ { } propose { - for i in 0 .. (T::MaxProposals::get() - 1) { + let p = T::MaxProposals::get(); + + for i in 0 .. (p - 1) { add_proposal::(i)?; } @@ -110,7 +112,6 @@ benchmarks! { whitelist_account!(caller); }: _(RawOrigin::Signed(caller), proposal_hash, value.into()) verify { - let p = T::MaxProposals::get(); assert_eq!(Democracy::::public_props().len(), p as usize, "Proposals not created."); } @@ -343,7 +344,8 @@ benchmarks! { let referendum_index = add_referendum::(r)?; }: _(RawOrigin::Root, referendum_index) - // Note that we have a separate benchmark for `launch_next` + // This measures the path of `launch_next` external. Not currently used as we simply + // assume the weight is `MaxBlockWeight` when executing. #[extra] on_initialize_external { let r in 0 .. MAX_REFERENDUMS; @@ -383,6 +385,8 @@ benchmarks! { } } + // This measures the path of `launch_next` public. Not currently used as we simply + // assume the weight is `MaxBlockWeight` when executing. #[extra] on_initialize_public { let r in 1 .. MAX_REFERENDUMS; diff --git a/frame/democracy/src/lib.rs b/frame/democracy/src/lib.rs index 6aeb518f72f29..884106a63b321 100644 --- a/frame/democracy/src/lib.rs +++ b/frame/democracy/src/lib.rs @@ -1628,7 +1628,7 @@ impl Module { /// /// /// # - /// If a referendum is launched or maturing take full block weight. Otherwise: + /// If a referendum is launched or maturing, this will take full block weight. Otherwise: /// - Complexity: `O(R)` where `R` is the number of unbaked referenda. /// - Db reads: `LastTabledWasExternal`, `NextExternal`, `PublicProps`, `account`, /// `ReferendumCount`, `LowestUnbaked` From b466e1fb98fbb6ef0aededeb661a964792c4204b Mon Sep 17 00:00:00 2001 From: Shawn Tabrizi Date: Thu, 24 Sep 2020 22:35:28 +0200 Subject: [PATCH 25/25] new weights --- .../runtime/src/weights/pallet_democracy.rs | 100 +++++++++--------- frame/democracy/src/default_weight.rs | 96 ++++++++--------- 2 files changed, 99 insertions(+), 97 deletions(-) diff --git a/bin/node/runtime/src/weights/pallet_democracy.rs b/bin/node/runtime/src/weights/pallet_democracy.rs index 4adada3868204..51eca2855a384 100644 --- a/bin/node/runtime/src/weights/pallet_democracy.rs +++ b/bin/node/runtime/src/weights/pallet_democracy.rs @@ -1,3 +1,5 @@ +// This file is part of Substrate. + // Copyright (C) 2020 Parity Technologies (UK) Ltd. // SPDX-License-Identifier: Apache-2.0 @@ -13,8 +15,9 @@ // 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-rc6 +//! Weights for pallet_democracy +//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 2.0.0 +//! DATE: 2020-09-24, STEPS: [50], REPEAT: 20, LOW RANGE: [], HIGH RANGE: [] #![allow(unused_parens)] #![allow(unused_imports)] @@ -25,146 +28,145 @@ use sp_std::marker::PhantomData; pub struct WeightInfo(PhantomData); impl pallet_democracy::WeightInfo for WeightInfo { fn propose() -> Weight { - (49113000 as Weight) - .saturating_add(T::DbWeight::get().reads(2 as Weight)) + (96_316_000 as Weight) + .saturating_add(T::DbWeight::get().reads(3 as Weight)) .saturating_add(T::DbWeight::get().writes(3 as Weight)) } fn second(s: u32, ) -> Weight { - (42067000 as Weight) - .saturating_add((220000 as Weight).saturating_mul(s as Weight)) + (58_386_000 as Weight) + .saturating_add((259_000 as Weight).saturating_mul(s as Weight)) .saturating_add(T::DbWeight::get().reads(1 as Weight)) .saturating_add(T::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)) + (70_374_000 as Weight) + .saturating_add((291_000 as Weight).saturating_mul(r as Weight)) .saturating_add(T::DbWeight::get().reads(3 as Weight)) .saturating_add(T::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)) + (70_097_000 as Weight) + .saturating_add((296_000 as Weight).saturating_mul(r as Weight)) .saturating_add(T::DbWeight::get().reads(3 as Weight)) .saturating_add(T::DbWeight::get().writes(3 as Weight)) } fn emergency_cancel() -> Weight { - (31071000 as Weight) + (41_731_000 as Weight) .saturating_add(T::DbWeight::get().reads(2 as Weight)) .saturating_add(T::DbWeight::get().writes(2 as Weight)) } fn blacklist(p: u32, ) -> Weight { - (131046000 as Weight) - .saturating_add((694000 as Weight).saturating_mul(p as Weight)) + (117_847_000 as Weight) + .saturating_add((871_000 as Weight).saturating_mul(p as Weight)) .saturating_add(T::DbWeight::get().reads(5 as Weight)) .saturating_add(T::DbWeight::get().writes(6 as Weight)) } fn external_propose(v: u32, ) -> Weight { - (14282000 as Weight) - .saturating_add((109000 as Weight).saturating_mul(v as Weight)) + (20_972_000 as Weight) + .saturating_add((114_000 as Weight).saturating_mul(v as Weight)) .saturating_add(T::DbWeight::get().reads(2 as Weight)) .saturating_add(T::DbWeight::get().writes(1 as Weight)) } fn external_propose_majority() -> Weight { - (3478000 as Weight) + (5_030_000 as Weight) .saturating_add(T::DbWeight::get().writes(1 as Weight)) } fn external_propose_default() -> Weight { - (3442000 as Weight) + (4_981_000 as Weight) .saturating_add(T::DbWeight::get().writes(1 as Weight)) } fn fast_track() -> Weight { - (30820000 as Weight) + (42_801_000 as Weight) .saturating_add(T::DbWeight::get().reads(2 as Weight)) .saturating_add(T::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)) + (44_115_000 as Weight) + .saturating_add((194_000 as Weight).saturating_mul(v as Weight)) .saturating_add(T::DbWeight::get().reads(2 as Weight)) .saturating_add(T::DbWeight::get().writes(2 as Weight)) } fn cancel_proposal(p: u32, ) -> Weight { - (64238000 as Weight) - .saturating_add((694000 as Weight).saturating_mul(p as Weight)) + (73_937_000 as Weight) + .saturating_add((962_000 as Weight).saturating_mul(p as Weight)) .saturating_add(T::DbWeight::get().reads(3 as Weight)) .saturating_add(T::DbWeight::get().writes(3 as Weight)) } fn cancel_referendum() -> Weight { - (20431000 as Weight) + (25_233_000 as Weight) .saturating_add(T::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)) + (48_251_000 as Weight) + .saturating_add((3_590_000 as Weight).saturating_mul(r as Weight)) .saturating_add(T::DbWeight::get().reads(2 as Weight)) .saturating_add(T::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(T::DbWeight::get().reads(6 as Weight)) - .saturating_add(T::DbWeight::get().reads((2 as Weight).saturating_mul(r as Weight))) - .saturating_add(T::DbWeight::get().writes(5 as Weight)) + (17_597_000 as Weight) + .saturating_add((7_248_000 as Weight).saturating_mul(r as Weight)) + .saturating_add(T::DbWeight::get().reads(5 as Weight)) + .saturating_add(T::DbWeight::get().reads((1 as Weight).saturating_mul(r as Weight))) } fn delegate(r: u32, ) -> Weight { - (72046000 as Weight) - .saturating_add((7837000 as Weight).saturating_mul(r as Weight)) + (93_916_000 as Weight) + .saturating_add((10_794_000 as Weight).saturating_mul(r as Weight)) .saturating_add(T::DbWeight::get().reads(4 as Weight)) .saturating_add(T::DbWeight::get().reads((1 as Weight).saturating_mul(r as Weight))) .saturating_add(T::DbWeight::get().writes(4 as Weight)) .saturating_add(T::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)) + (47_855_000 as Weight) + .saturating_add((10_805_000 as Weight).saturating_mul(r as Weight)) .saturating_add(T::DbWeight::get().reads(2 as Weight)) .saturating_add(T::DbWeight::get().reads((1 as Weight).saturating_mul(r as Weight))) .saturating_add(T::DbWeight::get().writes(2 as Weight)) .saturating_add(T::DbWeight::get().writes((1 as Weight).saturating_mul(r as Weight))) } fn clear_public_proposals() -> Weight { - (3643000 as Weight) + (4_864_000 as Weight) .saturating_add(T::DbWeight::get().writes(1 as Weight)) } fn note_preimage(b: u32, ) -> Weight { - (61563000 as Weight) - .saturating_add((4000 as Weight).saturating_mul(b as Weight)) + (66_754_000 as Weight) + .saturating_add((4_000 as Weight).saturating_mul(b as Weight)) .saturating_add(T::DbWeight::get().reads(1 as Weight)) .saturating_add(T::DbWeight::get().writes(1 as Weight)) } fn note_imminent_preimage(b: u32, ) -> Weight { - (41681000 as Weight) - .saturating_add((3000 as Weight).saturating_mul(b as Weight)) + (44_664_000 as Weight) + .saturating_add((3_000 as Weight).saturating_mul(b as Weight)) .saturating_add(T::DbWeight::get().reads(1 as Weight)) .saturating_add(T::DbWeight::get().writes(1 as Weight)) } fn reap_preimage(b: u32, ) -> Weight { - (56686000 as Weight) - .saturating_add((3000 as Weight).saturating_mul(b as Weight)) + (59_968_000 as Weight) + .saturating_add((3_000 as Weight).saturating_mul(b as Weight)) .saturating_add(T::DbWeight::get().reads(2 as Weight)) .saturating_add(T::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)) + (58_573_000 as Weight) + .saturating_add((131_000 as Weight).saturating_mul(r as Weight)) .saturating_add(T::DbWeight::get().reads(3 as Weight)) .saturating_add(T::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)) + (53_831_000 as Weight) + .saturating_add((324_000 as Weight).saturating_mul(r as Weight)) .saturating_add(T::DbWeight::get().reads(3 as Weight)) .saturating_add(T::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)) + (31_846_000 as Weight) + .saturating_add((327_000 as Weight).saturating_mul(r as Weight)) .saturating_add(T::DbWeight::get().reads(2 as Weight)) .saturating_add(T::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)) + (31_880_000 as Weight) + .saturating_add((222_000 as Weight).saturating_mul(r as Weight)) .saturating_add(T::DbWeight::get().reads(2 as Weight)) .saturating_add(T::DbWeight::get().writes(2 as Weight)) } diff --git a/frame/democracy/src/default_weight.rs b/frame/democracy/src/default_weight.rs index 2b75b1c50f847..28aa45ae2d603 100644 --- a/frame/democracy/src/default_weight.rs +++ b/frame/democracy/src/default_weight.rs @@ -15,8 +15,9 @@ // 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-rc6 +//! Weights for pallet_democracy +//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 2.0.0 +//! DATE: 2020-09-24, STEPS: [50], REPEAT: 20, LOW RANGE: [], HIGH RANGE: [] #![allow(unused_parens)] #![allow(unused_imports)] @@ -25,146 +26,145 @@ use frame_support::weights::{Weight, constants::RocksDbWeight as DbWeight}; impl crate::WeightInfo for () { fn propose() -> Weight { - (82728000 as Weight) + (96_316_000 as Weight) .saturating_add(DbWeight::get().reads(3 as Weight)) .saturating_add(DbWeight::get().writes(3 as Weight)) } fn second(s: u32, ) -> Weight { - (54903000 as Weight) - .saturating_add((254000 as Weight).saturating_mul(s as Weight)) + (58_386_000 as Weight) + .saturating_add((259_000 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 { - (67070000 as Weight) - .saturating_add((452000 as Weight).saturating_mul(r as Weight)) + (70_374_000 as Weight) + .saturating_add((291_000 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 { - (66675000 as Weight) - .saturating_add((456000 as Weight).saturating_mul(r as Weight)) + (70_097_000 as Weight) + .saturating_add((296_000 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 { - (41152000 as Weight) + (41_731_000 as Weight) .saturating_add(DbWeight::get().reads(2 as Weight)) .saturating_add(DbWeight::get().writes(2 as Weight)) } fn blacklist(p: u32, ) -> Weight { - (131046000 as Weight) - .saturating_add((694000 as Weight).saturating_mul(p as Weight)) + (117_847_000 as Weight) + .saturating_add((871_000 as Weight).saturating_mul(p as Weight)) .saturating_add(DbWeight::get().reads(5 as Weight)) .saturating_add(DbWeight::get().writes(6 as Weight)) } fn external_propose(v: u32, ) -> Weight { - (19552000 as Weight) - .saturating_add((112000 as Weight).saturating_mul(v as Weight)) + (20_972_000 as Weight) + .saturating_add((114_000 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 { - (4582000 as Weight) + (5_030_000 as Weight) .saturating_add(DbWeight::get().writes(1 as Weight)) } fn external_propose_default() -> Weight { - (4587000 as Weight) + (4_981_000 as Weight) .saturating_add(DbWeight::get().writes(1 as Weight)) } fn fast_track() -> Weight { - (39833000 as Weight) + (42_801_000 as Weight) .saturating_add(DbWeight::get().reads(2 as Weight)) .saturating_add(DbWeight::get().writes(3 as Weight)) } fn veto_external(v: u32, ) -> Weight { - (40935000 as Weight) - .saturating_add((188000 as Weight).saturating_mul(v as Weight)) + (44_115_000 as Weight) + .saturating_add((194_000 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_proposal(p: u32, ) -> Weight { - (64238000 as Weight) - .saturating_add((694000 as Weight).saturating_mul(p as Weight)) + (73_937_000 as Weight) + .saturating_add((962_000 as Weight).saturating_mul(p as Weight)) .saturating_add(DbWeight::get().reads(3 as Weight)) .saturating_add(DbWeight::get().writes(3 as Weight)) } fn cancel_referendum() -> Weight { - (25280000 as Weight) + (25_233_000 as Weight) .saturating_add(DbWeight::get().writes(1 as Weight)) } fn cancel_queued(r: u32, ) -> Weight { - (48033000 as Weight) - .saturating_add((3610000 as Weight).saturating_mul(r as Weight)) + (48_251_000 as Weight) + .saturating_add((3_590_000 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 { - (92992000 as Weight) - .saturating_add((14292000 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)) + (17_597_000 as Weight) + .saturating_add((7_248_000 as Weight).saturating_mul(r as Weight)) + .saturating_add(DbWeight::get().reads(5 as Weight)) + .saturating_add(DbWeight::get().reads((1 as Weight).saturating_mul(r as Weight))) } fn delegate(r: u32, ) -> Weight { - (87374000 as Weight) - .saturating_add((10516000 as Weight).saturating_mul(r as Weight)) + (93_916_000 as Weight) + .saturating_add((10_794_000 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 { - (45044000 as Weight) - .saturating_add((10474000 as Weight).saturating_mul(r as Weight)) + (47_855_000 as Weight) + .saturating_add((10_805_000 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 { - (4538000 as Weight) + (4_864_000 as Weight) .saturating_add(DbWeight::get().writes(1 as Weight)) } fn note_preimage(b: u32, ) -> Weight { - (61563000 as Weight) - .saturating_add((4000 as Weight).saturating_mul(b as Weight)) + (66_754_000 as Weight) + .saturating_add((4_000 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 { - (41681000 as Weight) - .saturating_add((3000 as Weight).saturating_mul(b as Weight)) + (44_664_000 as Weight) + .saturating_add((3_000 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 { - (56686000 as Weight) - .saturating_add((3000 as Weight).saturating_mul(b as Weight)) + (59_968_000 as Weight) + .saturating_add((3_000 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 { - (56202000 as Weight) - .saturating_add((263000 as Weight).saturating_mul(r as Weight)) + (58_573_000 as Weight) + .saturating_add((131_000 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 { - (51945000 as Weight) - .saturating_add((453000 as Weight).saturating_mul(r as Weight)) + (53_831_000 as Weight) + .saturating_add((324_000 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 { - (31147000 as Weight) - .saturating_add((446000 as Weight).saturating_mul(r as Weight)) + (31_846_000 as Weight) + .saturating_add((327_000 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 { - (30785000 as Weight) - .saturating_add((214000 as Weight).saturating_mul(r as Weight)) + (31_880_000 as Weight) + .saturating_add((222_000 as Weight).saturating_mul(r as Weight)) .saturating_add(DbWeight::get().reads(2 as Weight)) .saturating_add(DbWeight::get().writes(2 as Weight)) }