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

Referenda and Conviction Voting pallets #10195

Merged
merged 79 commits into from
Feb 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
79 commits
Select commit Hold shift + click to select a range
b7103be
Initial draft of new referendum state machine.
gavofyork Nov 5, 2021
e18562e
Docs
gavofyork Nov 5, 2021
a79ceb1
Fixes
gavofyork Nov 5, 2021
a13df25
Fixes
gavofyork Nov 6, 2021
4413936
Add conviction-voting pallet
gavofyork Nov 8, 2021
cef2d82
Basic build
gavofyork Nov 8, 2021
fdf3220
Building
gavofyork Nov 10, 2021
d785cc8
Some TODOs
gavofyork Nov 10, 2021
7d6a01b
Tests building
gavofyork Nov 11, 2021
cddd737
Add missing file
gavofyork Nov 11, 2021
9d1ffb6
Basic lifecycle test
gavofyork Nov 12, 2021
ab23a80
Add couple of tests
gavofyork Nov 22, 2021
b09c292
Another test
gavofyork Nov 22, 2021
a7139e2
More tests
gavofyork Nov 23, 2021
59d5b62
Merge branch 'master' into gav-referenda
gavofyork Dec 12, 2021
d77afbf
Fixes
gavofyork Dec 12, 2021
6b98d2d
Fixes
gavofyork Dec 13, 2021
505c075
Formatting
gavofyork Dec 13, 2021
bfbce8f
Fixes
gavofyork Dec 13, 2021
c04ca08
Tests
gavofyork Dec 13, 2021
7d99c7d
Fixes
gavofyork Dec 14, 2021
c17ee4b
Fixes
gavofyork Dec 14, 2021
fd57564
More tests
gavofyork Dec 14, 2021
24b438e
Formatting
gavofyork Dec 14, 2021
e9de7f5
First few benchmarks
gavofyork Dec 15, 2021
92d1989
First few benchmarks
gavofyork Dec 15, 2021
52a3da5
Defered queue servicing
gavofyork Dec 15, 2021
6149ed4
More testing
gavofyork Dec 18, 2021
46c5c41
Benchmarks
gavofyork Dec 18, 2021
2d4b6ff
Fiddly benchmark
gavofyork Dec 18, 2021
95f3d23
Merge remote-tracking branch 'origin/master' into gav-referenda
gavofyork Dec 18, 2021
df78dce
Final nudge benchmarks
gavofyork Dec 18, 2021
c2d9dc5
Formatting
gavofyork Dec 18, 2021
213c320
Formatting
gavofyork Dec 19, 2021
fcf11e2
Finished up benchmarks
gavofyork Dec 19, 2021
91ad256
Merge branch 'master' of https://github.com/paritytech/substrate into…
Dec 19, 2021
a3d67ee
cargo run --quiet --release --features=runtime-benchmarks --manifest-…
Dec 19, 2021
72193b3
Events finished
gavofyork Dec 19, 2021
e855625
Merge branch 'gav-referenda' of github.com:paritytech/substrate into …
gavofyork Dec 19, 2021
d785347
Missing file
gavofyork Dec 19, 2021
5e55764
No GenesisConfig for Referenda
gavofyork Dec 19, 2021
8315533
Formatting
gavofyork Dec 19, 2021
54210df
Docs
gavofyork Dec 19, 2021
633ca15
Docs
gavofyork Dec 20, 2021
72fbcff
Docs
gavofyork Dec 20, 2021
400fda1
Merge remote-tracking branch 'origin/master' into gav-referenda
gavofyork Jan 3, 2022
b2c9c79
Per-class conviction voting
gavofyork Jan 4, 2022
65296a6
New test & mock utils
gavofyork Jan 4, 2022
37d8c75
More tests
gavofyork Jan 6, 2022
1ed4444
Tests
gavofyork Jan 6, 2022
382439b
Tests finished 🎉
gavofyork Jan 7, 2022
4857198
Merge branch 'master' into gav-referenda
gavofyork Jan 7, 2022
0936fec
Benchmarking stuff
gavofyork Jan 7, 2022
0880fdc
Fixes
gavofyork Jan 8, 2022
b7a8ebe
Test harness
gavofyork Jan 8, 2022
d9fb550
Test harness
gavofyork Jan 9, 2022
6f9e9d6
Benchmarks for Conviction=Voting
gavofyork Jan 9, 2022
61d22ff
Benchmarking pipeline complete
gavofyork Jan 9, 2022
5dcf899
Docs
gavofyork Jan 9, 2022
1df78f5
Formatting
gavofyork Jan 9, 2022
01b81ad
Merge remote-tracking branch 'origin/master' into gav-referenda
gavofyork Jan 9, 2022
b9a8b38
Remove unneeded warning
gavofyork Jan 9, 2022
497f404
Fix UI tests
gavofyork Jan 9, 2022
28c679f
cargo run --quiet --release --features=runtime-benchmarks --manifest-…
Jan 9, 2022
976cb47
Merge branch 'master' into gav-referenda
shawntabrizi Jan 14, 2022
f8c5ad8
Merge branch 'master' into gav-referenda
gavofyork Jan 17, 2022
aa0ed61
Merge branch 'master' into gav-referenda
shawntabrizi Jan 17, 2022
6102564
Docs
gavofyork Jan 18, 2022
c6c9a29
Update frame/conviction-voting/src/vote.rs
gavofyork Jan 20, 2022
22d8457
Merge branch 'master' into gav-referenda
shawntabrizi Jan 24, 2022
98a72f1
update sp-runtime version
shawntabrizi Jan 24, 2022
5e5f314
MEL Fixes for Referenda and Conviction Voting (#10725)
shawntabrizi Jan 28, 2022
85cf285
Merge branch 'master' into gav-referenda
shawntabrizi Jan 28, 2022
6f4acf3
More Referenda Patches (#10760)
shawntabrizi Feb 1, 2022
0c4df94
prevent panic in curve math
shawntabrizi Feb 5, 2022
808f947
Merge branch 'master' into gav-referenda
shawntabrizi Feb 5, 2022
dfc6faf
fmt
shawntabrizi Feb 5, 2022
4db9db5
bump crate versions
shawntabrizi Feb 5, 2022
6a1a45d
Update mock.rs
shawntabrizi Feb 5, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 5 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@ members = [
"frame/authority-discovery",
"frame/authorship",
"frame/babe",
"frame/bags-list",
"frame/bags-list/fuzzer",
"frame/bags-list/remote-tests",
"frame/balances",
"frame/beefy",
"frame/beefy-mmr",
Expand All @@ -78,6 +81,7 @@ members = [
"frame/contracts",
"frame/contracts/rpc",
"frame/contracts/rpc/runtime-api",
"frame/conviction-voting",
"frame/democracy",
"frame/try-runtime",
"frame/election-provider-multi-phase",
Expand All @@ -104,6 +108,7 @@ members = [
"frame/proxy",
"frame/randomness-collective-flip",
"frame/recovery",
"frame/referenda",
"frame/scheduler",
"frame/scored-pool",
"frame/session",
Expand Down Expand Up @@ -133,9 +138,6 @@ members = [
"frame/uniques",
"frame/utility",
"frame/vesting",
"frame/bags-list",
"frame/bags-list/remote-tests",
"frame/bags-list/fuzzer",
"primitives/api",
"primitives/api/proc-macro",
"primitives/api/test",
Expand Down
32 changes: 19 additions & 13 deletions bin/node/runtime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ pallet-collective = { version = "4.0.0-dev", default-features = false, path = ".
pallet-contracts = { version = "4.0.0-dev", default-features = false, path = "../../../frame/contracts" }
pallet-contracts-primitives = { version = "5.0.0", default-features = false, path = "../../../frame/contracts/common/" }
pallet-contracts-rpc-runtime-api = { version = "4.0.0-dev", default-features = false, path = "../../../frame/contracts/rpc/runtime-api/" }
pallet-conviction-voting = { version = "4.0.0-dev", default-features = false, path = "../../../frame/conviction-voting" }
pallet-democracy = { version = "4.0.0-dev", default-features = false, path = "../../../frame/democracy" }
pallet-election-provider-multi-phase = { version = "4.0.0-dev", default-features = false, path = "../../../frame/election-provider-multi-phase" }
pallet-elections-phragmen = { version = "5.0.0-dev", default-features = false, path = "../../../frame/elections-phragmen" }
Expand All @@ -82,9 +83,8 @@ pallet-preimage = { version = "4.0.0-dev", default-features = false, path = "../
pallet-proxy = { version = "4.0.0-dev", default-features = false, path = "../../../frame/proxy" }
pallet-randomness-collective-flip = { version = "4.0.0-dev", default-features = false, path = "../../../frame/randomness-collective-flip" }
pallet-recovery = { version = "4.0.0-dev", default-features = false, path = "../../../frame/recovery" }
pallet-session = { version = "4.0.0-dev", features = [
"historical",
], path = "../../../frame/session", default-features = false }
pallet-referenda = { version = "4.0.0-dev", default-features = false, path = "../../../frame/referenda" }
pallet-session = { version = "4.0.0-dev", features = [ "historical" ], path = "../../../frame/session", default-features = false }
pallet-session-benchmarking = { version = "4.0.0-dev", path = "../../../frame/session/benchmarking", default-features = false, optional = true }
pallet-staking = { version = "4.0.0-dev", default-features = false, path = "../../../frame/staking" }
pallet-staking-reward-curve = { version = "4.0.0-dev", default-features = false, path = "../../../frame/staking/reward-curve" }
Expand Down Expand Up @@ -125,6 +125,7 @@ std = [
"pallet-contracts/std",
"pallet-contracts-primitives/std",
"pallet-contracts-rpc-runtime-api/std",
"pallet-conviction-voting/std",
"pallet-democracy/std",
"pallet-elections-phragmen/std",
"frame-executive/std",
Expand Down Expand Up @@ -170,6 +171,7 @@ std = [
"pallet-utility/std",
"sp-version/std",
"pallet-society/std",
"pallet-referenda/std",
"pallet-recovery/std",
"pallet-uniques/std",
"pallet-vesting/std",
Expand All @@ -183,7 +185,6 @@ runtime-benchmarks = [
"frame-benchmarking/runtime-benchmarks",
"frame-support/runtime-benchmarks",
"frame-system/runtime-benchmarks",
"pallet-election-provider-multi-phase/runtime-benchmarks",
"sp-runtime/runtime-benchmarks",
"pallet-assets/runtime-benchmarks",
"pallet-babe/runtime-benchmarks",
Expand All @@ -193,7 +194,9 @@ runtime-benchmarks = [
"pallet-child-bounties/runtime-benchmarks",
"pallet-collective/runtime-benchmarks",
"pallet-contracts/runtime-benchmarks",
"pallet-conviction-voting/runtime-benchmarks",
"pallet-democracy/runtime-benchmarks",
"pallet-election-provider-multi-phase/runtime-benchmarks",
"pallet-elections-phragmen/runtime-benchmarks",
"pallet-gilt/runtime-benchmarks",
"pallet-grandpa/runtime-benchmarks",
Expand All @@ -204,9 +207,12 @@ runtime-benchmarks = [
"pallet-membership/runtime-benchmarks",
"pallet-mmr/runtime-benchmarks",
"pallet-multisig/runtime-benchmarks",
"pallet-offences-benchmarking",
"pallet-preimage/runtime-benchmarks",
"pallet-proxy/runtime-benchmarks",
"pallet-scheduler/runtime-benchmarks",
"pallet-referenda/runtime-benchmarks",
"pallet-session-benchmarking",
"pallet-society/runtime-benchmarks",
"pallet-staking/runtime-benchmarks",
"pallet-timestamp/runtime-benchmarks",
Expand All @@ -216,8 +222,6 @@ runtime-benchmarks = [
"pallet-utility/runtime-benchmarks",
"pallet-uniques/runtime-benchmarks",
"pallet-vesting/runtime-benchmarks",
"pallet-offences-benchmarking",
"pallet-session-benchmarking",
"frame-system-benchmarking",
"hex-literal",
]
Expand All @@ -234,35 +238,37 @@ try-runtime = [
"pallet-child-bounties/try-runtime",
"pallet-collective/try-runtime",
"pallet-contracts/try-runtime",
"pallet-conviction-voting/try-runtime",
"pallet-democracy/try-runtime",
"pallet-election-provider-multi-phase/try-runtime",
"pallet-elections-phragmen/try-runtime",
"pallet-gilt/try-runtime",
"pallet-grandpa/try-runtime",
"pallet-identity/try-runtime",
"pallet-im-online/try-runtime",
"pallet-indices/try-runtime",
"pallet-lottery/try-runtime",
"pallet-membership/try-runtime",
"pallet-mmr/try-runtime",
"pallet-multisig/try-runtime",
"pallet-identity/try-runtime",
"pallet-scheduler/try-runtime",
"pallet-offences/try-runtime",
"pallet-preimage/try-runtime",
"pallet-proxy/try-runtime",
"pallet-randomness-collective-flip/try-runtime",
"pallet-recovery/try-runtime",
"pallet-referenda/try-runtime",
"pallet-scheduler/try-runtime",
"pallet-session/try-runtime",
"pallet-society/try-runtime",
"pallet-staking/try-runtime",
"pallet-sudo/try-runtime",
"pallet-election-provider-multi-phase/try-runtime",
"pallet-timestamp/try-runtime",
"pallet-tips/try-runtime",
"pallet-transaction-payment/try-runtime",
"pallet-treasury/try-runtime",
"pallet-utility/try-runtime",
"pallet-society/try-runtime",
"pallet-recovery/try-runtime",
"pallet-uniques/try-runtime",
"pallet-utility/try-runtime",
"pallet-vesting/try-runtime",
"pallet-gilt/try-runtime",
]
# Make contract callable functions marked as __unstable__ available. Do not enable
# on live chains as those are subject to change.
Expand Down
81 changes: 81 additions & 0 deletions bin/node/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -698,6 +698,83 @@ impl pallet_bags_list::Config for Runtime {
type BagThresholds = BagThresholds;
}

parameter_types! {
pub const VoteLockingPeriod: BlockNumber = 30 * DAYS;
}

impl pallet_conviction_voting::Config for Runtime {
type WeightInfo = pallet_conviction_voting::weights::SubstrateWeight<Self>;
type Event = Event;
type Currency = Balances;
type VoteLockingPeriod = VoteLockingPeriod;
type MaxVotes = ConstU32<512>;
type MaxTurnout = frame_support::traits::TotalIssuanceOf<Balances, Self::AccountId>;
type Polls = Referenda;
}

parameter_types! {
pub const AlarmInterval: BlockNumber = 1;
pub const SubmissionDeposit: Balance = 100 * DOLLARS;
pub const UndecidingTimeout: BlockNumber = 28 * DAYS;
}

pub struct TracksInfo;
impl pallet_referenda::TracksInfo<Balance, BlockNumber> for TracksInfo {
type Id = u8;
type Origin = <Origin as frame_support::traits::OriginTrait>::PalletsOrigin;
fn tracks() -> &'static [(Self::Id, pallet_referenda::TrackInfo<Balance, BlockNumber>)] {
static DATA: [(u8, pallet_referenda::TrackInfo<Balance, BlockNumber>); 1] = [(
0u8,
pallet_referenda::TrackInfo {
name: "root",
max_deciding: 1,
decision_deposit: 10,
prepare_period: 4,
decision_period: 4,
confirm_period: 2,
min_enactment_period: 4,
min_approval: pallet_referenda::Curve::LinearDecreasing {
begin: Perbill::from_percent(100),
delta: Perbill::from_percent(50),
},
min_turnout: pallet_referenda::Curve::LinearDecreasing {
begin: Perbill::from_percent(100),
delta: Perbill::from_percent(100),
},
},
)];
&DATA[..]
}
fn track_for(id: &Self::Origin) -> Result<Self::Id, ()> {
if let Ok(system_origin) = frame_system::RawOrigin::try_from(id.clone()) {
match system_origin {
frame_system::RawOrigin::Root => Ok(0),
_ => Err(()),
}
} else {
Err(())
}
}
}

impl pallet_referenda::Config for Runtime {
type WeightInfo = pallet_referenda::weights::SubstrateWeight<Self>;
type Call = Call;
type Event = Event;
type Scheduler = Scheduler;
type Currency = pallet_balances::Pallet<Self>;
type CancelOrigin = EnsureRoot<AccountId>;
type KillOrigin = EnsureRoot<AccountId>;
type Slash = ();
type Votes = pallet_conviction_voting::VotesOf<Runtime>;
type Tally = pallet_conviction_voting::TallyOf<Runtime>;
type SubmissionDeposit = SubmissionDeposit;
type MaxQueued = ConstU32<100>;
type UndecidingTimeout = UndecidingTimeout;
type AlarmInterval = AlarmInterval;
type Tracks = TracksInfo;
}

parameter_types! {
pub const LaunchPeriod: BlockNumber = 28 * 24 * 60 * MINUTES;
pub const VotingPeriod: BlockNumber = 28 * 24 * 60 * MINUTES;
Expand Down Expand Up @@ -1336,6 +1413,8 @@ construct_runtime!(
TransactionStorage: pallet_transaction_storage,
BagsList: pallet_bags_list,
ChildBounties: pallet_child_bounties,
Referenda: pallet_referenda,
ConvictionVoting: pallet_conviction_voting,
}
);

Expand Down Expand Up @@ -1405,6 +1484,7 @@ mod benches {
[pallet_bounties, Bounties]
[pallet_child_bounties, ChildBounties]
[pallet_collective, Council]
[pallet_conviction_voting, ConvictionVoting]
[pallet_contracts, Contracts]
[pallet_democracy, Democracy]
[pallet_election_provider_multi_phase, ElectionProviderMultiPhase]
Expand All @@ -1421,6 +1501,7 @@ mod benches {
[pallet_offences, OffencesBench::<Runtime>]
[pallet_preimage, Preimage]
[pallet_proxy, Proxy]
[pallet_referenda, Referenda]
[pallet_scheduler, Scheduler]
[pallet_session, SessionBench::<Runtime>]
[pallet_staking, Staking]
Expand Down
2 changes: 1 addition & 1 deletion frame/balances/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1517,7 +1517,7 @@ where
.map_err(|_| Error::<T, I>::LiquidityRestrictions)?;

// TODO: This is over-conservative. There may now be other providers, and
// this pallet may not even be a provider.
// this pallet may not even be a provider.
let allow_death = existence_requirement == ExistenceRequirement::AllowDeath;
let allow_death =
allow_death && system::Pallet::<T>::can_dec_provider(transactor);
Expand Down
53 changes: 53 additions & 0 deletions frame/conviction-voting/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
[package]
name = "pallet-conviction-voting"
version = "4.0.0-dev"
authors = ["Parity Technologies <admin@parity.io>"]
edition = "2018"
license = "Apache-2.0"
homepage = "https://substrate.io"
repository = "https://github.com/paritytech/substrate/"
description = "FRAME pallet for conviction voting in referenda"
readme = "README.md"

[package.metadata.docs.rs]
targets = ["x86_64-unknown-linux-gnu"]

[dependencies]
serde = { version = "1.0.126", optional = true, features = ["derive"] }
codec = { package = "parity-scale-codec", version = "2.0.0", default-features = false, features = [
"derive",
] }
scale-info = { version = "1.0", default-features = false, features = ["derive"] }
sp-std = { version = "4.0.0-dev", default-features = false, path = "../../primitives/std" }
sp-io = { version = "5.0.0", default-features = false, path = "../../primitives/io" }
sp-runtime = { version = "5.0.0", default-features = false, path = "../../primitives/runtime" }
frame-benchmarking = { version = "4.0.0-dev", default-features = false, path = "../benchmarking", optional = true }
frame-support = { version = "4.0.0-dev", default-features = false, path = "../support" }
frame-system = { version = "4.0.0-dev", default-features = false, path = "../system" }
assert_matches = "1.3.0"

[dev-dependencies]
sp-core = { version = "5.0.0", path = "../../primitives/core" }
pallet-balances = { version = "4.0.0-dev", path = "../balances" }
pallet-scheduler = { version = "4.0.0-dev", path = "../scheduler" }

[features]
default = ["std"]
std = [
"serde",
"codec/std",
"scale-info/std",
"sp-std/std",
"sp-io/std",
"frame-benchmarking/std",
"frame-support/std",
"sp-runtime/std",
"frame-system/std",
]
runtime-benchmarks = [
"frame-benchmarking",
"frame-system/runtime-benchmarks",
"frame-support/runtime-benchmarks",
"sp-runtime/runtime-benchmarks",
]
try-runtime = ["frame-support/try-runtime"]
Loading