Skip to content

Commit 118bf11

Browse files
gavofyorkParity Botshawntabrizi
authored andcommitted
Referenda and Conviction Voting pallets (paritytech#10195)
* Initial draft of new referendum state machine. * Docs * Fixes * Fixes * Add conviction-voting pallet * Basic build * Building * Some TODOs * Tests building * Add missing file * Basic lifecycle test * Add couple of tests * Another test * More tests * Fixes * Fixes * Formatting * Fixes * Tests * Fixes * Fixes * More tests * Formatting * First few benchmarks * First few benchmarks * Defered queue servicing * More testing * Benchmarks * Fiddly benchmark * Final nudge benchmarks * Formatting * Formatting * Finished up benchmarks * cargo run --quiet --release --features=runtime-benchmarks --manifest-path=bin/node/cli/Cargo.toml -- benchmark --chain=dev --steps=50 --repeat=20 --pallet=pallet_referenda --extrinsic=* --execution=wasm --wasm-execution=compiled --heap-pages=4096 --output=./frame/referenda/src/weights.rs --template=./.maintain/frame-weight-template.hbs * Events finished * Missing file * No GenesisConfig for Referenda * Formatting * Docs * Docs * Docs * Per-class conviction voting * New test & mock utils * More tests * Tests * Tests finished 🎉 * Benchmarking stuff * Fixes * Test harness * Test harness * Benchmarks for Conviction=Voting * Benchmarking pipeline complete * Docs * Formatting * Remove unneeded warning * Fix UI tests * cargo run --quiet --release --features=runtime-benchmarks --manifest-path=bin/node/cli/Cargo.toml -- benchmark --chain=dev --steps=50 --repeat=20 --pallet=pallet_conviction_voting --extrinsic=* --execution=wasm --wasm-execution=compiled --heap-pages=4096 --output=./frame/conviction-voting/src/weights.rs --template=./.maintain/frame-weight-template.hbs * Docs * Update frame/conviction-voting/src/vote.rs Co-authored-by: Shawn Tabrizi <shawntabrizi@gmail.com> * update sp-runtime version * MEL Fixes for Referenda and Conviction Voting (paritytech#10725) * free maxencodedlen * more maxencodedlen * more MEL * more mel * disable storage info * More Referenda Patches (paritytech#10760) * basic fixes * fix benchmarking * fix license * prevent panic in curve math * fmt * bump crate versions * Update mock.rs Co-authored-by: Parity Bot <admin@parity.io> Co-authored-by: Shawn Tabrizi <shawntabrizi@gmail.com>
1 parent f075ce1 commit 118bf11

File tree

34 files changed

+6542
-106
lines changed

34 files changed

+6542
-106
lines changed

Cargo.lock

Lines changed: 41 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,9 @@ members = [
6767
"frame/authority-discovery",
6868
"frame/authorship",
6969
"frame/babe",
70+
"frame/bags-list",
71+
"frame/bags-list/fuzzer",
72+
"frame/bags-list/remote-tests",
7073
"frame/balances",
7174
"frame/beefy",
7275
"frame/beefy-mmr",
@@ -78,6 +81,7 @@ members = [
7881
"frame/contracts",
7982
"frame/contracts/rpc",
8083
"frame/contracts/rpc/runtime-api",
84+
"frame/conviction-voting",
8185
"frame/democracy",
8286
"frame/try-runtime",
8387
"frame/election-provider-multi-phase",
@@ -104,6 +108,7 @@ members = [
104108
"frame/proxy",
105109
"frame/randomness-collective-flip",
106110
"frame/recovery",
111+
"frame/referenda",
107112
"frame/scheduler",
108113
"frame/scored-pool",
109114
"frame/session",
@@ -133,9 +138,6 @@ members = [
133138
"frame/uniques",
134139
"frame/utility",
135140
"frame/vesting",
136-
"frame/bags-list",
137-
"frame/bags-list/remote-tests",
138-
"frame/bags-list/fuzzer",
139141
"primitives/api",
140142
"primitives/api/proc-macro",
141143
"primitives/api/test",

bin/node/runtime/Cargo.toml

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ pallet-collective = { version = "4.0.0-dev", default-features = false, path = ".
6464
pallet-contracts = { version = "4.0.0-dev", default-features = false, path = "../../../frame/contracts" }
6565
pallet-contracts-primitives = { version = "5.0.0", default-features = false, path = "../../../frame/contracts/common/" }
6666
pallet-contracts-rpc-runtime-api = { version = "4.0.0-dev", default-features = false, path = "../../../frame/contracts/rpc/runtime-api/" }
67+
pallet-conviction-voting = { version = "4.0.0-dev", default-features = false, path = "../../../frame/conviction-voting" }
6768
pallet-democracy = { version = "4.0.0-dev", default-features = false, path = "../../../frame/democracy" }
6869
pallet-election-provider-multi-phase = { version = "4.0.0-dev", default-features = false, path = "../../../frame/election-provider-multi-phase" }
6970
pallet-elections-phragmen = { version = "5.0.0-dev", default-features = false, path = "../../../frame/elections-phragmen" }
@@ -82,9 +83,8 @@ pallet-preimage = { version = "4.0.0-dev", default-features = false, path = "../
8283
pallet-proxy = { version = "4.0.0-dev", default-features = false, path = "../../../frame/proxy" }
8384
pallet-randomness-collective-flip = { version = "4.0.0-dev", default-features = false, path = "../../../frame/randomness-collective-flip" }
8485
pallet-recovery = { version = "4.0.0-dev", default-features = false, path = "../../../frame/recovery" }
85-
pallet-session = { version = "4.0.0-dev", features = [
86-
"historical",
87-
], path = "../../../frame/session", default-features = false }
86+
pallet-referenda = { version = "4.0.0-dev", default-features = false, path = "../../../frame/referenda" }
87+
pallet-session = { version = "4.0.0-dev", features = [ "historical" ], path = "../../../frame/session", default-features = false }
8888
pallet-session-benchmarking = { version = "4.0.0-dev", path = "../../../frame/session/benchmarking", default-features = false, optional = true }
8989
pallet-staking = { version = "4.0.0-dev", default-features = false, path = "../../../frame/staking" }
9090
pallet-staking-reward-curve = { version = "4.0.0-dev", default-features = false, path = "../../../frame/staking/reward-curve" }
@@ -125,6 +125,7 @@ std = [
125125
"pallet-contracts/std",
126126
"pallet-contracts-primitives/std",
127127
"pallet-contracts-rpc-runtime-api/std",
128+
"pallet-conviction-voting/std",
128129
"pallet-democracy/std",
129130
"pallet-elections-phragmen/std",
130131
"frame-executive/std",
@@ -170,6 +171,7 @@ std = [
170171
"pallet-utility/std",
171172
"sp-version/std",
172173
"pallet-society/std",
174+
"pallet-referenda/std",
173175
"pallet-recovery/std",
174176
"pallet-uniques/std",
175177
"pallet-vesting/std",
@@ -183,7 +185,6 @@ runtime-benchmarks = [
183185
"frame-benchmarking/runtime-benchmarks",
184186
"frame-support/runtime-benchmarks",
185187
"frame-system/runtime-benchmarks",
186-
"pallet-election-provider-multi-phase/runtime-benchmarks",
187188
"sp-runtime/runtime-benchmarks",
188189
"pallet-assets/runtime-benchmarks",
189190
"pallet-babe/runtime-benchmarks",
@@ -193,7 +194,9 @@ runtime-benchmarks = [
193194
"pallet-child-bounties/runtime-benchmarks",
194195
"pallet-collective/runtime-benchmarks",
195196
"pallet-contracts/runtime-benchmarks",
197+
"pallet-conviction-voting/runtime-benchmarks",
196198
"pallet-democracy/runtime-benchmarks",
199+
"pallet-election-provider-multi-phase/runtime-benchmarks",
197200
"pallet-elections-phragmen/runtime-benchmarks",
198201
"pallet-gilt/runtime-benchmarks",
199202
"pallet-grandpa/runtime-benchmarks",
@@ -204,9 +207,12 @@ runtime-benchmarks = [
204207
"pallet-membership/runtime-benchmarks",
205208
"pallet-mmr/runtime-benchmarks",
206209
"pallet-multisig/runtime-benchmarks",
210+
"pallet-offences-benchmarking",
207211
"pallet-preimage/runtime-benchmarks",
208212
"pallet-proxy/runtime-benchmarks",
209213
"pallet-scheduler/runtime-benchmarks",
214+
"pallet-referenda/runtime-benchmarks",
215+
"pallet-session-benchmarking",
210216
"pallet-society/runtime-benchmarks",
211217
"pallet-staking/runtime-benchmarks",
212218
"pallet-timestamp/runtime-benchmarks",
@@ -216,8 +222,6 @@ runtime-benchmarks = [
216222
"pallet-utility/runtime-benchmarks",
217223
"pallet-uniques/runtime-benchmarks",
218224
"pallet-vesting/runtime-benchmarks",
219-
"pallet-offences-benchmarking",
220-
"pallet-session-benchmarking",
221225
"frame-system-benchmarking",
222226
"hex-literal",
223227
]
@@ -234,35 +238,37 @@ try-runtime = [
234238
"pallet-child-bounties/try-runtime",
235239
"pallet-collective/try-runtime",
236240
"pallet-contracts/try-runtime",
241+
"pallet-conviction-voting/try-runtime",
237242
"pallet-democracy/try-runtime",
243+
"pallet-election-provider-multi-phase/try-runtime",
238244
"pallet-elections-phragmen/try-runtime",
245+
"pallet-gilt/try-runtime",
239246
"pallet-grandpa/try-runtime",
247+
"pallet-identity/try-runtime",
240248
"pallet-im-online/try-runtime",
241249
"pallet-indices/try-runtime",
242250
"pallet-lottery/try-runtime",
243251
"pallet-membership/try-runtime",
244252
"pallet-mmr/try-runtime",
245253
"pallet-multisig/try-runtime",
246-
"pallet-identity/try-runtime",
247-
"pallet-scheduler/try-runtime",
248254
"pallet-offences/try-runtime",
249255
"pallet-preimage/try-runtime",
250256
"pallet-proxy/try-runtime",
251257
"pallet-randomness-collective-flip/try-runtime",
258+
"pallet-recovery/try-runtime",
259+
"pallet-referenda/try-runtime",
260+
"pallet-scheduler/try-runtime",
252261
"pallet-session/try-runtime",
262+
"pallet-society/try-runtime",
253263
"pallet-staking/try-runtime",
254264
"pallet-sudo/try-runtime",
255-
"pallet-election-provider-multi-phase/try-runtime",
256265
"pallet-timestamp/try-runtime",
257266
"pallet-tips/try-runtime",
258267
"pallet-transaction-payment/try-runtime",
259268
"pallet-treasury/try-runtime",
260-
"pallet-utility/try-runtime",
261-
"pallet-society/try-runtime",
262-
"pallet-recovery/try-runtime",
263269
"pallet-uniques/try-runtime",
270+
"pallet-utility/try-runtime",
264271
"pallet-vesting/try-runtime",
265-
"pallet-gilt/try-runtime",
266272
]
267273
# Make contract callable functions marked as __unstable__ available. Do not enable
268274
# on live chains as those are subject to change.

bin/node/runtime/src/lib.rs

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -698,6 +698,83 @@ impl pallet_bags_list::Config for Runtime {
698698
type BagThresholds = BagThresholds;
699699
}
700700

701+
parameter_types! {
702+
pub const VoteLockingPeriod: BlockNumber = 30 * DAYS;
703+
}
704+
705+
impl pallet_conviction_voting::Config for Runtime {
706+
type WeightInfo = pallet_conviction_voting::weights::SubstrateWeight<Self>;
707+
type Event = Event;
708+
type Currency = Balances;
709+
type VoteLockingPeriod = VoteLockingPeriod;
710+
type MaxVotes = ConstU32<512>;
711+
type MaxTurnout = frame_support::traits::TotalIssuanceOf<Balances, Self::AccountId>;
712+
type Polls = Referenda;
713+
}
714+
715+
parameter_types! {
716+
pub const AlarmInterval: BlockNumber = 1;
717+
pub const SubmissionDeposit: Balance = 100 * DOLLARS;
718+
pub const UndecidingTimeout: BlockNumber = 28 * DAYS;
719+
}
720+
721+
pub struct TracksInfo;
722+
impl pallet_referenda::TracksInfo<Balance, BlockNumber> for TracksInfo {
723+
type Id = u8;
724+
type Origin = <Origin as frame_support::traits::OriginTrait>::PalletsOrigin;
725+
fn tracks() -> &'static [(Self::Id, pallet_referenda::TrackInfo<Balance, BlockNumber>)] {
726+
static DATA: [(u8, pallet_referenda::TrackInfo<Balance, BlockNumber>); 1] = [(
727+
0u8,
728+
pallet_referenda::TrackInfo {
729+
name: "root",
730+
max_deciding: 1,
731+
decision_deposit: 10,
732+
prepare_period: 4,
733+
decision_period: 4,
734+
confirm_period: 2,
735+
min_enactment_period: 4,
736+
min_approval: pallet_referenda::Curve::LinearDecreasing {
737+
begin: Perbill::from_percent(100),
738+
delta: Perbill::from_percent(50),
739+
},
740+
min_turnout: pallet_referenda::Curve::LinearDecreasing {
741+
begin: Perbill::from_percent(100),
742+
delta: Perbill::from_percent(100),
743+
},
744+
},
745+
)];
746+
&DATA[..]
747+
}
748+
fn track_for(id: &Self::Origin) -> Result<Self::Id, ()> {
749+
if let Ok(system_origin) = frame_system::RawOrigin::try_from(id.clone()) {
750+
match system_origin {
751+
frame_system::RawOrigin::Root => Ok(0),
752+
_ => Err(()),
753+
}
754+
} else {
755+
Err(())
756+
}
757+
}
758+
}
759+
760+
impl pallet_referenda::Config for Runtime {
761+
type WeightInfo = pallet_referenda::weights::SubstrateWeight<Self>;
762+
type Call = Call;
763+
type Event = Event;
764+
type Scheduler = Scheduler;
765+
type Currency = pallet_balances::Pallet<Self>;
766+
type CancelOrigin = EnsureRoot<AccountId>;
767+
type KillOrigin = EnsureRoot<AccountId>;
768+
type Slash = ();
769+
type Votes = pallet_conviction_voting::VotesOf<Runtime>;
770+
type Tally = pallet_conviction_voting::TallyOf<Runtime>;
771+
type SubmissionDeposit = SubmissionDeposit;
772+
type MaxQueued = ConstU32<100>;
773+
type UndecidingTimeout = UndecidingTimeout;
774+
type AlarmInterval = AlarmInterval;
775+
type Tracks = TracksInfo;
776+
}
777+
701778
parameter_types! {
702779
pub const LaunchPeriod: BlockNumber = 28 * 24 * 60 * MINUTES;
703780
pub const VotingPeriod: BlockNumber = 28 * 24 * 60 * MINUTES;
@@ -1336,6 +1413,8 @@ construct_runtime!(
13361413
TransactionStorage: pallet_transaction_storage,
13371414
BagsList: pallet_bags_list,
13381415
ChildBounties: pallet_child_bounties,
1416+
Referenda: pallet_referenda,
1417+
ConvictionVoting: pallet_conviction_voting,
13391418
}
13401419
);
13411420

@@ -1405,6 +1484,7 @@ mod benches {
14051484
[pallet_bounties, Bounties]
14061485
[pallet_child_bounties, ChildBounties]
14071486
[pallet_collective, Council]
1487+
[pallet_conviction_voting, ConvictionVoting]
14081488
[pallet_contracts, Contracts]
14091489
[pallet_democracy, Democracy]
14101490
[pallet_election_provider_multi_phase, ElectionProviderMultiPhase]
@@ -1421,6 +1501,7 @@ mod benches {
14211501
[pallet_offences, OffencesBench::<Runtime>]
14221502
[pallet_preimage, Preimage]
14231503
[pallet_proxy, Proxy]
1504+
[pallet_referenda, Referenda]
14241505
[pallet_scheduler, Scheduler]
14251506
[pallet_session, SessionBench::<Runtime>]
14261507
[pallet_staking, Staking]

frame/balances/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1517,7 +1517,7 @@ where
15171517
.map_err(|_| Error::<T, I>::LiquidityRestrictions)?;
15181518

15191519
// TODO: This is over-conservative. There may now be other providers, and
1520-
// this pallet may not even be a provider.
1520+
// this pallet may not even be a provider.
15211521
let allow_death = existence_requirement == ExistenceRequirement::AllowDeath;
15221522
let allow_death =
15231523
allow_death && system::Pallet::<T>::can_dec_provider(transactor);

frame/conviction-voting/Cargo.toml

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
[package]
2+
name = "pallet-conviction-voting"
3+
version = "4.0.0-dev"
4+
authors = ["Parity Technologies <admin@parity.io>"]
5+
edition = "2018"
6+
license = "Apache-2.0"
7+
homepage = "https://substrate.io"
8+
repository = "https://github.com/paritytech/substrate/"
9+
description = "FRAME pallet for conviction voting in referenda"
10+
readme = "README.md"
11+
12+
[package.metadata.docs.rs]
13+
targets = ["x86_64-unknown-linux-gnu"]
14+
15+
[dependencies]
16+
serde = { version = "1.0.126", optional = true, features = ["derive"] }
17+
codec = { package = "parity-scale-codec", version = "2.0.0", default-features = false, features = [
18+
"derive",
19+
] }
20+
scale-info = { version = "1.0", default-features = false, features = ["derive"] }
21+
sp-std = { version = "4.0.0-dev", default-features = false, path = "../../primitives/std" }
22+
sp-io = { version = "5.0.0", default-features = false, path = "../../primitives/io" }
23+
sp-runtime = { version = "5.0.0", default-features = false, path = "../../primitives/runtime" }
24+
frame-benchmarking = { version = "4.0.0-dev", default-features = false, path = "../benchmarking", optional = true }
25+
frame-support = { version = "4.0.0-dev", default-features = false, path = "../support" }
26+
frame-system = { version = "4.0.0-dev", default-features = false, path = "../system" }
27+
assert_matches = "1.3.0"
28+
29+
[dev-dependencies]
30+
sp-core = { version = "5.0.0", path = "../../primitives/core" }
31+
pallet-balances = { version = "4.0.0-dev", path = "../balances" }
32+
pallet-scheduler = { version = "4.0.0-dev", path = "../scheduler" }
33+
34+
[features]
35+
default = ["std"]
36+
std = [
37+
"serde",
38+
"codec/std",
39+
"scale-info/std",
40+
"sp-std/std",
41+
"sp-io/std",
42+
"frame-benchmarking/std",
43+
"frame-support/std",
44+
"sp-runtime/std",
45+
"frame-system/std",
46+
]
47+
runtime-benchmarks = [
48+
"frame-benchmarking",
49+
"frame-system/runtime-benchmarks",
50+
"frame-support/runtime-benchmarks",
51+
"sp-runtime/runtime-benchmarks",
52+
]
53+
try-runtime = ["frame-support/try-runtime"]

0 commit comments

Comments
 (0)