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

Commit 5ea2399

Browse files
Introduce cancel_proposal to rid us of those pesky proposals (#7111)
* Introduce `cancel_proposal` Also fix proposal weight. * Support proposal cancellation from runtime. * Fixes * Fixes * Fixes * Fixes * Fixes * Fixes * Fixes * Fix benchmarks * fix benchmark * whitelisted caller weights * fix build * Fixes * Fixes * Fixes * Fixes * Update frame/democracy/src/lib.rs Co-authored-by: Shawn Tabrizi <[email protected]> * Fixes * Fixes * Fixes * Fixes * Fixes * doc updates * new weights Co-authored-by: Shawn Tabrizi <[email protected]>
1 parent e3aecc0 commit 5ea2399

File tree

10 files changed

+423
-235
lines changed

10 files changed

+423
-235
lines changed

bin/node/runtime/src/lib.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -483,6 +483,7 @@ parameter_types! {
483483
// One cent: $10,000 / MB
484484
pub const PreimageByteDeposit: Balance = 1 * CENTS;
485485
pub const MaxVotes: u32 = 100;
486+
pub const MaxProposals: u32 = 100;
486487
}
487488

488489
impl pallet_democracy::Trait for Runtime {
@@ -508,6 +509,14 @@ impl pallet_democracy::Trait for Runtime {
508509
type FastTrackVotingPeriod = FastTrackVotingPeriod;
509510
// To cancel a proposal which has been passed, 2/3 of the council must agree to it.
510511
type CancellationOrigin = pallet_collective::EnsureProportionAtLeast<_2, _3, AccountId, CouncilCollective>;
512+
// To cancel a proposal before it has been passed, the technical committee must be unanimous or
513+
// Root must agree.
514+
type CancelProposalOrigin = EnsureOneOf<
515+
AccountId,
516+
EnsureRoot<AccountId>,
517+
pallet_collective::EnsureProportionAtLeast<_1, _1, AccountId, TechnicalCollective>,
518+
>;
519+
type BlacklistOrigin = EnsureRoot<AccountId>;
511520
// Any single technical committee member may veto a coming council proposal, however they can
512521
// only do it once and it lasts only for the cooloff period.
513522
type VetoOrigin = pallet_collective::EnsureMember<AccountId, TechnicalCollective>;
@@ -519,6 +528,7 @@ impl pallet_democracy::Trait for Runtime {
519528
type PalletsOrigin = OriginCaller;
520529
type MaxVotes = MaxVotes;
521530
type WeightInfo = weights::pallet_democracy::WeightInfo<Runtime>;
531+
type MaxProposals = MaxProposals;
522532
}
523533

524534
parameter_types! {

bin/node/runtime/src/weights/pallet_democracy.rs

Lines changed: 62 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// This file is part of Substrate.
2+
13
// Copyright (C) 2020 Parity Technologies (UK) Ltd.
24
// SPDX-License-Identifier: Apache-2.0
35

@@ -13,143 +15,158 @@
1315
// See the License for the specific language governing permissions and
1416
// limitations under the License.
1517

16-
//! Weights for the Democracy Pallet
17-
//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 2.0.0-rc5
18+
//! Weights for pallet_democracy
19+
//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 2.0.0
20+
//! DATE: 2020-09-24, STEPS: [50], REPEAT: 20, LOW RANGE: [], HIGH RANGE: []
21+
22+
#![allow(unused_parens)]
23+
#![allow(unused_imports)]
1824

1925
use frame_support::{traits::Get, weights::Weight};
2026
use sp_std::marker::PhantomData;
2127

2228
pub struct WeightInfo<T>(PhantomData<T>);
2329
impl<T: frame_system::Trait> pallet_democracy::WeightInfo for WeightInfo<T> {
2430
fn propose() -> Weight {
25-
(49113000 as Weight)
26-
.saturating_add(T::DbWeight::get().reads(2 as Weight))
31+
(96_316_000 as Weight)
32+
.saturating_add(T::DbWeight::get().reads(3 as Weight))
2733
.saturating_add(T::DbWeight::get().writes(3 as Weight))
2834
}
2935
fn second(s: u32, ) -> Weight {
30-
(42067000 as Weight)
31-
.saturating_add((220000 as Weight).saturating_mul(s as Weight))
36+
(58_386_000 as Weight)
37+
.saturating_add((259_000 as Weight).saturating_mul(s as Weight))
3238
.saturating_add(T::DbWeight::get().reads(1 as Weight))
3339
.saturating_add(T::DbWeight::get().writes(1 as Weight))
3440
}
3541
fn vote_new(r: u32, ) -> Weight {
36-
(54159000 as Weight)
37-
.saturating_add((252000 as Weight).saturating_mul(r as Weight))
42+
(70_374_000 as Weight)
43+
.saturating_add((291_000 as Weight).saturating_mul(r as Weight))
3844
.saturating_add(T::DbWeight::get().reads(3 as Weight))
3945
.saturating_add(T::DbWeight::get().writes(3 as Weight))
4046
}
4147
fn vote_existing(r: u32, ) -> Weight {
42-
(54145000 as Weight)
43-
.saturating_add((262000 as Weight).saturating_mul(r as Weight))
48+
(70_097_000 as Weight)
49+
.saturating_add((296_000 as Weight).saturating_mul(r as Weight))
4450
.saturating_add(T::DbWeight::get().reads(3 as Weight))
4551
.saturating_add(T::DbWeight::get().writes(3 as Weight))
4652
}
4753
fn emergency_cancel() -> Weight {
48-
(31071000 as Weight)
54+
(41_731_000 as Weight)
4955
.saturating_add(T::DbWeight::get().reads(2 as Weight))
5056
.saturating_add(T::DbWeight::get().writes(2 as Weight))
5157
}
58+
fn blacklist(p: u32, ) -> Weight {
59+
(117_847_000 as Weight)
60+
.saturating_add((871_000 as Weight).saturating_mul(p as Weight))
61+
.saturating_add(T::DbWeight::get().reads(5 as Weight))
62+
.saturating_add(T::DbWeight::get().writes(6 as Weight))
63+
}
5264
fn external_propose(v: u32, ) -> Weight {
53-
(14282000 as Weight)
54-
.saturating_add((109000 as Weight).saturating_mul(v as Weight))
65+
(20_972_000 as Weight)
66+
.saturating_add((114_000 as Weight).saturating_mul(v as Weight))
5567
.saturating_add(T::DbWeight::get().reads(2 as Weight))
5668
.saturating_add(T::DbWeight::get().writes(1 as Weight))
5769
}
5870
fn external_propose_majority() -> Weight {
59-
(3478000 as Weight)
71+
(5_030_000 as Weight)
6072
.saturating_add(T::DbWeight::get().writes(1 as Weight))
6173
}
6274
fn external_propose_default() -> Weight {
63-
(3442000 as Weight)
75+
(4_981_000 as Weight)
6476
.saturating_add(T::DbWeight::get().writes(1 as Weight))
6577
}
6678
fn fast_track() -> Weight {
67-
(30820000 as Weight)
79+
(42_801_000 as Weight)
6880
.saturating_add(T::DbWeight::get().reads(2 as Weight))
6981
.saturating_add(T::DbWeight::get().writes(3 as Weight))
7082
}
7183
fn veto_external(v: u32, ) -> Weight {
72-
(30971000 as Weight)
73-
.saturating_add((184000 as Weight).saturating_mul(v as Weight))
84+
(44_115_000 as Weight)
85+
.saturating_add((194_000 as Weight).saturating_mul(v as Weight))
7486
.saturating_add(T::DbWeight::get().reads(2 as Weight))
7587
.saturating_add(T::DbWeight::get().writes(2 as Weight))
7688
}
89+
fn cancel_proposal(p: u32, ) -> Weight {
90+
(73_937_000 as Weight)
91+
.saturating_add((962_000 as Weight).saturating_mul(p as Weight))
92+
.saturating_add(T::DbWeight::get().reads(3 as Weight))
93+
.saturating_add(T::DbWeight::get().writes(3 as Weight))
94+
}
7795
fn cancel_referendum() -> Weight {
78-
(20431000 as Weight)
96+
(25_233_000 as Weight)
7997
.saturating_add(T::DbWeight::get().writes(1 as Weight))
8098
}
8199
fn cancel_queued(r: u32, ) -> Weight {
82-
(42438000 as Weight)
83-
.saturating_add((3284000 as Weight).saturating_mul(r as Weight))
100+
(48_251_000 as Weight)
101+
.saturating_add((3_590_000 as Weight).saturating_mul(r as Weight))
84102
.saturating_add(T::DbWeight::get().reads(2 as Weight))
85103
.saturating_add(T::DbWeight::get().writes(2 as Weight))
86104
}
87105
fn on_initialize_base(r: u32, ) -> Weight {
88-
(70826000 as Weight)
89-
.saturating_add((10716000 as Weight).saturating_mul(r as Weight))
90-
.saturating_add(T::DbWeight::get().reads(6 as Weight))
91-
.saturating_add(T::DbWeight::get().reads((2 as Weight).saturating_mul(r as Weight)))
92-
.saturating_add(T::DbWeight::get().writes(5 as Weight))
106+
(17_597_000 as Weight)
107+
.saturating_add((7_248_000 as Weight).saturating_mul(r as Weight))
108+
.saturating_add(T::DbWeight::get().reads(5 as Weight))
109+
.saturating_add(T::DbWeight::get().reads((1 as Weight).saturating_mul(r as Weight)))
93110
}
94111
fn delegate(r: u32, ) -> Weight {
95-
(72046000 as Weight)
96-
.saturating_add((7837000 as Weight).saturating_mul(r as Weight))
112+
(93_916_000 as Weight)
113+
.saturating_add((10_794_000 as Weight).saturating_mul(r as Weight))
97114
.saturating_add(T::DbWeight::get().reads(4 as Weight))
98115
.saturating_add(T::DbWeight::get().reads((1 as Weight).saturating_mul(r as Weight)))
99116
.saturating_add(T::DbWeight::get().writes(4 as Weight))
100117
.saturating_add(T::DbWeight::get().writes((1 as Weight).saturating_mul(r as Weight)))
101118
}
102119
fn undelegate(r: u32, ) -> Weight {
103-
(41028000 as Weight)
104-
.saturating_add((7810000 as Weight).saturating_mul(r as Weight))
120+
(47_855_000 as Weight)
121+
.saturating_add((10_805_000 as Weight).saturating_mul(r as Weight))
105122
.saturating_add(T::DbWeight::get().reads(2 as Weight))
106123
.saturating_add(T::DbWeight::get().reads((1 as Weight).saturating_mul(r as Weight)))
107124
.saturating_add(T::DbWeight::get().writes(2 as Weight))
108125
.saturating_add(T::DbWeight::get().writes((1 as Weight).saturating_mul(r as Weight)))
109126
}
110127
fn clear_public_proposals() -> Weight {
111-
(3643000 as Weight)
128+
(4_864_000 as Weight)
112129
.saturating_add(T::DbWeight::get().writes(1 as Weight))
113130
}
114131
fn note_preimage(b: u32, ) -> Weight {
115-
(46629000 as Weight)
116-
.saturating_add((4000 as Weight).saturating_mul(b as Weight))
132+
(66_754_000 as Weight)
133+
.saturating_add((4_000 as Weight).saturating_mul(b as Weight))
117134
.saturating_add(T::DbWeight::get().reads(1 as Weight))
118135
.saturating_add(T::DbWeight::get().writes(1 as Weight))
119136
}
120137
fn note_imminent_preimage(b: u32, ) -> Weight {
121-
(31147000 as Weight)
122-
.saturating_add((3000 as Weight).saturating_mul(b as Weight))
138+
(44_664_000 as Weight)
139+
.saturating_add((3_000 as Weight).saturating_mul(b as Weight))
123140
.saturating_add(T::DbWeight::get().reads(1 as Weight))
124141
.saturating_add(T::DbWeight::get().writes(1 as Weight))
125142
}
126143
fn reap_preimage(b: u32, ) -> Weight {
127-
(42848000 as Weight)
128-
.saturating_add((3000 as Weight).saturating_mul(b as Weight))
144+
(59_968_000 as Weight)
145+
.saturating_add((3_000 as Weight).saturating_mul(b as Weight))
129146
.saturating_add(T::DbWeight::get().reads(2 as Weight))
130147
.saturating_add(T::DbWeight::get().writes(1 as Weight))
131148
}
132149
fn unlock_remove(r: u32, ) -> Weight {
133-
(45333000 as Weight)
134-
.saturating_add((171000 as Weight).saturating_mul(r as Weight))
150+
(58_573_000 as Weight)
151+
.saturating_add((131_000 as Weight).saturating_mul(r as Weight))
135152
.saturating_add(T::DbWeight::get().reads(3 as Weight))
136153
.saturating_add(T::DbWeight::get().writes(3 as Weight))
137154
}
138155
fn unlock_set(r: u32, ) -> Weight {
139-
(44424000 as Weight)
140-
.saturating_add((291000 as Weight).saturating_mul(r as Weight))
156+
(53_831_000 as Weight)
157+
.saturating_add((324_000 as Weight).saturating_mul(r as Weight))
141158
.saturating_add(T::DbWeight::get().reads(3 as Weight))
142159
.saturating_add(T::DbWeight::get().writes(3 as Weight))
143160
}
144161
fn remove_vote(r: u32, ) -> Weight {
145-
(28250000 as Weight)
146-
.saturating_add((283000 as Weight).saturating_mul(r as Weight))
162+
(31_846_000 as Weight)
163+
.saturating_add((327_000 as Weight).saturating_mul(r as Weight))
147164
.saturating_add(T::DbWeight::get().reads(2 as Weight))
148165
.saturating_add(T::DbWeight::get().writes(2 as Weight))
149166
}
150167
fn remove_other_vote(r: u32, ) -> Weight {
151-
(28250000 as Weight)
152-
.saturating_add((283000 as Weight).saturating_mul(r as Weight))
168+
(31_880_000 as Weight)
169+
.saturating_add((222_000 as Weight).saturating_mul(r as Weight))
153170
.saturating_add(T::DbWeight::get().reads(2 as Weight))
154171
.saturating_add(T::DbWeight::get().writes(2 as Weight))
155172
}

frame/benchmarking/src/utils.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,3 +219,12 @@ pub fn account<AccountId: Decode + Default>(name: &'static str, index: u32, seed
219219
pub fn whitelisted_caller<AccountId: Decode + Default>() -> AccountId {
220220
account::<AccountId>("whitelisted_caller", 0, 0)
221221
}
222+
223+
#[macro_export]
224+
macro_rules! whitelist_account {
225+
($acc:ident) => {
226+
frame_benchmarking::benchmarking::add_to_whitelist(
227+
frame_system::Account::<T>::hashed_key_for(&$acc).into()
228+
);
229+
}
230+
}

0 commit comments

Comments
 (0)