Skip to content

Commit ec9bc8f

Browse files
gavofyorkkianenigmaKiChjang
authored andcommitted
Several tweaks needed for Governance 2.0 (paritytech#11124)
* Add stepped curve for referenda * Treasury SpendOrigin * Add tests * Better Origin Or-gating * Reciprocal curve * Tests for reciprical and rounding in PerThings * Tweaks and new quad curve * Const derivation of reciprocal curve parameters * Remove some unneeded code * Actually useful linear curve * Fixes * Provisional curves * Rejig 'turnout' as 'support' * Use TypedGet * Fixes * Enable curve's ceil to be configured * Formatting * Fixes * Fixes * Fixes * Remove EnsureOneOf * Fixes * Fixes * Fixes * Formatting * Fixes * Update frame/support/src/traits/dispatch.rs Co-authored-by: Kian Paimani <[email protected]> * Grumbles * Formatting * Fixes * APIs of VoteTally should include class * Fixes * Fix overlay prefix removal result * Second part of the overlay prefix removal fix. * Formatting * Fixes * Add some tests and make clear rounding algo * Fixes * Formatting * Revert questionable fix * Introduce test for kill_prefix * Fixes * Formatting * Fixes * Fix possible overflow * Docs * Add benchmark test * Formatting * Update frame/referenda/src/types.rs Co-authored-by: Keith Yeung <[email protected]> * Docs * Fixes * Use latest API in tests * Formatting * Whitespace * Use latest API in tests Co-authored-by: Kian Paimani <[email protected]> Co-authored-by: Keith Yeung <[email protected]>
1 parent b78136e commit ec9bc8f

File tree

34 files changed

+2047
-336
lines changed

34 files changed

+2047
-336
lines changed

Cargo.lock

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

bin/node/runtime/src/lib.rs

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ use frame_support::{
3131
pallet_prelude::Get,
3232
parameter_types,
3333
traits::{
34-
AsEnsureOriginWithArg, ConstU128, ConstU16, ConstU32, Currency, EnsureOneOf,
34+
AsEnsureOriginWithArg, ConstU128, ConstU16, ConstU32, Currency, EitherOfDiverse,
3535
EqualPrivilegeOnly, Everything, Imbalance, InstanceFilter, KeyOwnerProofSystem,
3636
LockIdentifier, Nothing, OnUnbalanced, U128CurrencyToVote,
3737
},
@@ -550,7 +550,7 @@ impl pallet_staking::Config for Runtime {
550550
type BondingDuration = BondingDuration;
551551
type SlashDeferDuration = SlashDeferDuration;
552552
/// A super-majority of the council can cancel the slash.
553-
type SlashCancelOrigin = EnsureOneOf<
553+
type SlashCancelOrigin = EitherOfDiverse<
554554
EnsureRoot<AccountId>,
555555
pallet_collective::EnsureProportionAtLeast<AccountId, CouncilCollective, 3, 4>,
556556
>;
@@ -794,12 +794,14 @@ impl pallet_referenda::TracksInfo<Balance, BlockNumber> for TracksInfo {
794794
confirm_period: 2,
795795
min_enactment_period: 4,
796796
min_approval: pallet_referenda::Curve::LinearDecreasing {
797-
begin: Perbill::from_percent(100),
798-
delta: Perbill::from_percent(50),
797+
length: Perbill::from_percent(100),
798+
floor: Perbill::from_percent(50),
799+
ceil: Perbill::from_percent(100),
799800
},
800-
min_turnout: pallet_referenda::Curve::LinearDecreasing {
801-
begin: Perbill::from_percent(100),
802-
delta: Perbill::from_percent(100),
801+
min_support: pallet_referenda::Curve::LinearDecreasing {
802+
length: Perbill::from_percent(100),
803+
floor: Perbill::from_percent(0),
804+
ceil: Perbill::from_percent(100),
803805
},
804806
},
805807
)];
@@ -882,7 +884,7 @@ impl pallet_democracy::Config for Runtime {
882884
pallet_collective::EnsureProportionAtLeast<AccountId, CouncilCollective, 2, 3>;
883885
// To cancel a proposal before it has been passed, the technical committee must be unanimous or
884886
// Root must agree.
885-
type CancelProposalOrigin = EnsureOneOf<
887+
type CancelProposalOrigin = EitherOfDiverse<
886888
EnsureRoot<AccountId>,
887889
pallet_collective::EnsureProportionAtLeast<AccountId, TechnicalCollective, 1, 1>,
888890
>;
@@ -972,7 +974,7 @@ impl pallet_collective::Config<TechnicalCollective> for Runtime {
972974
type WeightInfo = pallet_collective::weights::SubstrateWeight<Runtime>;
973975
}
974976

975-
type EnsureRootOrHalfCouncil = EnsureOneOf<
977+
type EnsureRootOrHalfCouncil = EitherOfDiverse<
976978
EnsureRoot<AccountId>,
977979
pallet_collective::EnsureProportionMoreThan<AccountId, CouncilCollective, 1, 2>,
978980
>;
@@ -1006,11 +1008,11 @@ parameter_types! {
10061008
impl pallet_treasury::Config for Runtime {
10071009
type PalletId = TreasuryPalletId;
10081010
type Currency = Balances;
1009-
type ApproveOrigin = EnsureOneOf<
1011+
type ApproveOrigin = EitherOfDiverse<
10101012
EnsureRoot<AccountId>,
10111013
pallet_collective::EnsureProportionAtLeast<AccountId, CouncilCollective, 3, 5>,
10121014
>;
1013-
type RejectOrigin = EnsureOneOf<
1015+
type RejectOrigin = EitherOfDiverse<
10141016
EnsureRoot<AccountId>,
10151017
pallet_collective::EnsureProportionMoreThan<AccountId, CouncilCollective, 1, 2>,
10161018
>;
@@ -1025,6 +1027,7 @@ impl pallet_treasury::Config for Runtime {
10251027
type SpendFunds = Bounties;
10261028
type WeightInfo = pallet_treasury::weights::SubstrateWeight<Runtime>;
10271029
type MaxApprovals = MaxApprovals;
1030+
type SpendOrigin = frame_support::traits::NeverEnsureOrigin<u128>;
10281031
}
10291032

10301033
parameter_types! {

docs/Upgrading-2.0-to-3.0.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ Democracy brings three new settings with this release, all to allow for better i
290290
type CancellationOrigin = pallet_collective::EnsureProportionAtLeast<_2, _3, AccountId, CouncilCollective>;
291291
+ // To cancel a proposal before it has been passed, the technical committee must be unanimous or
292292
+ // Root must agree.
293-
+ type CancelProposalOrigin = EnsureOneOf<
293+
+ type CancelProposalOrigin = EitherOfDiverse<
294294
+ AccountId,
295295
+ EnsureRoot<AccountId>,
296296
+ pallet_collective::EnsureProportionAtLeast<_1, _1, AccountId, TechnicalCollective>,

frame/bounties/src/tests.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,6 @@ parameter_types! {
109109
pub const TreasuryPalletId: PalletId = PalletId(*b"py/trsry");
110110
}
111111

112-
// impl pallet_treasury::Config for Test {
113112
impl pallet_treasury::Config for Test {
114113
type PalletId = TreasuryPalletId;
115114
type Currency = pallet_balances::Pallet<Test>;
@@ -126,6 +125,7 @@ impl pallet_treasury::Config for Test {
126125
type WeightInfo = ();
127126
type SpendFunds = Bounties;
128127
type MaxApprovals = ConstU32<100>;
128+
type SpendOrigin = frame_support::traits::NeverEnsureOrigin<u64>;
129129
}
130130

131131
parameter_types! {

frame/child-bounties/src/tests.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ impl pallet_treasury::Config for Test {
130130
type WeightInfo = ();
131131
type SpendFunds = Bounties;
132132
type MaxApprovals = ConstU32<100>;
133+
type SpendOrigin = frame_support::traits::NeverEnsureOrigin<u64>;
133134
}
134135
parameter_types! {
135136
// This will be 50% of the bounty fee.

frame/conviction-voting/src/tests.rs

Lines changed: 45 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ use std::collections::BTreeMap;
2121

2222
use frame_support::{
2323
assert_noop, assert_ok, parameter_types,
24-
traits::{ConstU32, ConstU64, Contains, Polling},
24+
traits::{ConstU32, ConstU64, Contains, Polling, VoteTally},
2525
};
2626
use sp_core::H256;
2727
use sp_runtime::{
@@ -166,7 +166,7 @@ impl Polling<TallyOf<Test>> for TestPolls {
166166
fn create_ongoing(class: Self::Class) -> Result<Self::Index, ()> {
167167
let mut polls = Polls::get();
168168
let i = polls.keys().rev().next().map_or(0, |x| x + 1);
169-
polls.insert(i, Ongoing(Tally::default(), class));
169+
polls.insert(i, Ongoing(Tally::new(0), class));
170170
Polls::set(polls);
171171
Ok(i)
172172
}
@@ -271,19 +271,19 @@ fn basic_voting_works() {
271271
assert_ok!(Voting::vote(Origin::signed(1), 3, aye(2, 5)));
272272
assert_eq!(tally(3), Tally::from_parts(10, 0, 2));
273273
assert_ok!(Voting::vote(Origin::signed(1), 3, nay(2, 5)));
274-
assert_eq!(tally(3), Tally::from_parts(0, 10, 2));
274+
assert_eq!(tally(3), Tally::from_parts(0, 10, 0));
275275
assert_eq!(Balances::usable_balance(1), 8);
276276

277277
assert_ok!(Voting::vote(Origin::signed(1), 3, aye(5, 1)));
278278
assert_eq!(tally(3), Tally::from_parts(5, 0, 5));
279279
assert_ok!(Voting::vote(Origin::signed(1), 3, nay(5, 1)));
280-
assert_eq!(tally(3), Tally::from_parts(0, 5, 5));
280+
assert_eq!(tally(3), Tally::from_parts(0, 5, 0));
281281
assert_eq!(Balances::usable_balance(1), 5);
282282

283283
assert_ok!(Voting::vote(Origin::signed(1), 3, aye(10, 0)));
284284
assert_eq!(tally(3), Tally::from_parts(1, 0, 10));
285285
assert_ok!(Voting::vote(Origin::signed(1), 3, nay(10, 0)));
286-
assert_eq!(tally(3), Tally::from_parts(0, 1, 10));
286+
assert_eq!(tally(3), Tally::from_parts(0, 1, 0));
287287
assert_eq!(Balances::usable_balance(1), 0);
288288

289289
assert_ok!(Voting::remove_vote(Origin::signed(1), None, 3));
@@ -300,19 +300,19 @@ fn voting_balance_gets_locked() {
300300
assert_ok!(Voting::vote(Origin::signed(1), 3, aye(2, 5)));
301301
assert_eq!(tally(3), Tally::from_parts(10, 0, 2));
302302
assert_ok!(Voting::vote(Origin::signed(1), 3, nay(2, 5)));
303-
assert_eq!(tally(3), Tally::from_parts(0, 10, 2));
303+
assert_eq!(tally(3), Tally::from_parts(0, 10, 0));
304304
assert_eq!(Balances::usable_balance(1), 8);
305305

306306
assert_ok!(Voting::vote(Origin::signed(1), 3, aye(5, 1)));
307307
assert_eq!(tally(3), Tally::from_parts(5, 0, 5));
308308
assert_ok!(Voting::vote(Origin::signed(1), 3, nay(5, 1)));
309-
assert_eq!(tally(3), Tally::from_parts(0, 5, 5));
309+
assert_eq!(tally(3), Tally::from_parts(0, 5, 0));
310310
assert_eq!(Balances::usable_balance(1), 5);
311311

312312
assert_ok!(Voting::vote(Origin::signed(1), 3, aye(10, 0)));
313313
assert_eq!(tally(3), Tally::from_parts(1, 0, 10));
314314
assert_ok!(Voting::vote(Origin::signed(1), 3, nay(10, 0)));
315-
assert_eq!(tally(3), Tally::from_parts(0, 1, 10));
315+
assert_eq!(tally(3), Tally::from_parts(0, 1, 0));
316316
assert_eq!(Balances::usable_balance(1), 0);
317317

318318
assert_ok!(Voting::remove_vote(Origin::signed(1), None, 3));
@@ -376,10 +376,10 @@ fn classwise_delegation_works() {
376376
new_test_ext().execute_with(|| {
377377
Polls::set(
378378
vec![
379-
(0, Ongoing(Tally::default(), 0)),
380-
(1, Ongoing(Tally::default(), 1)),
381-
(2, Ongoing(Tally::default(), 2)),
382-
(3, Ongoing(Tally::default(), 2)),
379+
(0, Ongoing(Tally::new(0), 0)),
380+
(1, Ongoing(Tally::new(0), 1)),
381+
(2, Ongoing(Tally::new(0), 2)),
382+
(3, Ongoing(Tally::new(0), 2)),
383383
]
384384
.into_iter()
385385
.collect(),
@@ -403,9 +403,9 @@ fn classwise_delegation_works() {
403403
assert_eq!(
404404
Polls::get(),
405405
vec![
406-
(0, Ongoing(Tally::from_parts(6, 2, 35), 0)),
407-
(1, Ongoing(Tally::from_parts(6, 2, 35), 1)),
408-
(2, Ongoing(Tally::from_parts(6, 2, 35), 2)),
406+
(0, Ongoing(Tally::from_parts(6, 2, 15), 0)),
407+
(1, Ongoing(Tally::from_parts(6, 2, 15), 1)),
408+
(2, Ongoing(Tally::from_parts(6, 2, 15), 2)),
409409
(3, Ongoing(Tally::from_parts(0, 0, 0), 2)),
410410
]
411411
.into_iter()
@@ -417,10 +417,10 @@ fn classwise_delegation_works() {
417417
assert_eq!(
418418
Polls::get(),
419419
vec![
420-
(0, Ongoing(Tally::from_parts(6, 2, 35), 0)),
421-
(1, Ongoing(Tally::from_parts(6, 2, 35), 1)),
422-
(2, Ongoing(Tally::from_parts(6, 2, 35), 2)),
423-
(3, Ongoing(Tally::from_parts(0, 6, 15), 2)),
420+
(0, Ongoing(Tally::from_parts(6, 2, 15), 0)),
421+
(1, Ongoing(Tally::from_parts(6, 2, 15), 1)),
422+
(2, Ongoing(Tally::from_parts(6, 2, 15), 2)),
423+
(3, Ongoing(Tally::from_parts(0, 6, 0), 2)),
424424
]
425425
.into_iter()
426426
.collect()
@@ -432,10 +432,10 @@ fn classwise_delegation_works() {
432432
assert_eq!(
433433
Polls::get(),
434434
vec![
435-
(0, Ongoing(Tally::from_parts(6, 2, 35), 0)),
436-
(1, Ongoing(Tally::from_parts(6, 2, 35), 1)),
437-
(2, Ongoing(Tally::from_parts(1, 7, 35), 2)),
438-
(3, Ongoing(Tally::from_parts(0, 1, 10), 2)),
435+
(0, Ongoing(Tally::from_parts(6, 2, 15), 0)),
436+
(1, Ongoing(Tally::from_parts(6, 2, 15), 1)),
437+
(2, Ongoing(Tally::from_parts(1, 7, 10), 2)),
438+
(3, Ongoing(Tally::from_parts(0, 1, 0), 2)),
439439
]
440440
.into_iter()
441441
.collect()
@@ -451,10 +451,10 @@ fn classwise_delegation_works() {
451451
assert_eq!(
452452
Polls::get(),
453453
vec![
454-
(0, Ongoing(Tally::from_parts(4, 2, 33), 0)),
455-
(1, Ongoing(Tally::from_parts(4, 2, 33), 1)),
456-
(2, Ongoing(Tally::from_parts(4, 2, 33), 2)),
457-
(3, Ongoing(Tally::from_parts(0, 4, 13), 2)),
454+
(0, Ongoing(Tally::from_parts(4, 2, 13), 0)),
455+
(1, Ongoing(Tally::from_parts(4, 2, 13), 1)),
456+
(2, Ongoing(Tally::from_parts(4, 2, 13), 2)),
457+
(3, Ongoing(Tally::from_parts(0, 4, 0), 2)),
458458
]
459459
.into_iter()
460460
.collect()
@@ -483,10 +483,10 @@ fn classwise_delegation_works() {
483483
assert_eq!(
484484
Polls::get(),
485485
vec![
486-
(0, Ongoing(Tally::from_parts(7, 2, 36), 0)),
487-
(1, Ongoing(Tally::from_parts(8, 2, 37), 1)),
488-
(2, Ongoing(Tally::from_parts(9, 2, 38), 2)),
489-
(3, Ongoing(Tally::from_parts(0, 9, 18), 2)),
486+
(0, Ongoing(Tally::from_parts(7, 2, 16), 0)),
487+
(1, Ongoing(Tally::from_parts(8, 2, 17), 1)),
488+
(2, Ongoing(Tally::from_parts(9, 2, 18), 2)),
489+
(3, Ongoing(Tally::from_parts(0, 9, 0), 2)),
490490
]
491491
.into_iter()
492492
.collect()
@@ -497,7 +497,7 @@ fn classwise_delegation_works() {
497497
#[test]
498498
fn redelegation_after_vote_ending_should_keep_lock() {
499499
new_test_ext().execute_with(|| {
500-
Polls::set(vec![(0, Ongoing(Tally::default(), 0))].into_iter().collect());
500+
Polls::set(vec![(0, Ongoing(Tally::new(0), 0))].into_iter().collect());
501501
assert_ok!(Voting::delegate(Origin::signed(1), 0, 2, Conviction::Locked1x, 5));
502502
assert_ok!(Voting::vote(Origin::signed(2), 0, aye(10, 1)));
503503
Polls::set(vec![(0, Completed(1, true))].into_iter().collect());
@@ -515,9 +515,9 @@ fn lock_amalgamation_valid_with_multiple_removed_votes() {
515515
new_test_ext().execute_with(|| {
516516
Polls::set(
517517
vec![
518-
(0, Ongoing(Tally::default(), 0)),
519-
(1, Ongoing(Tally::default(), 0)),
520-
(2, Ongoing(Tally::default(), 0)),
518+
(0, Ongoing(Tally::new(0), 0)),
519+
(1, Ongoing(Tally::new(0), 0)),
520+
(2, Ongoing(Tally::new(0), 0)),
521521
]
522522
.into_iter()
523523
.collect(),
@@ -587,7 +587,7 @@ fn lock_amalgamation_valid_with_multiple_delegations() {
587587
#[test]
588588
fn lock_amalgamation_valid_with_move_roundtrip_to_delegation() {
589589
new_test_ext().execute_with(|| {
590-
Polls::set(vec![(0, Ongoing(Tally::default(), 0))].into_iter().collect());
590+
Polls::set(vec![(0, Ongoing(Tally::new(0), 0))].into_iter().collect());
591591
assert_ok!(Voting::vote(Origin::signed(1), 0, aye(5, 1)));
592592
Polls::set(vec![(0, Completed(1, true))].into_iter().collect());
593593
assert_ok!(Voting::remove_vote(Origin::signed(1), Some(0), 0));
@@ -599,7 +599,7 @@ fn lock_amalgamation_valid_with_move_roundtrip_to_delegation() {
599599
assert_ok!(Voting::unlock(Origin::signed(1), 0, 1));
600600
assert_eq!(Balances::usable_balance(1), 0);
601601

602-
Polls::set(vec![(1, Ongoing(Tally::default(), 0))].into_iter().collect());
602+
Polls::set(vec![(1, Ongoing(Tally::new(0), 0))].into_iter().collect());
603603
assert_ok!(Voting::vote(Origin::signed(1), 1, aye(5, 2)));
604604
Polls::set(vec![(1, Completed(1, true))].into_iter().collect());
605605
assert_ok!(Voting::remove_vote(Origin::signed(1), Some(0), 1));
@@ -627,7 +627,7 @@ fn lock_amalgamation_valid_with_move_roundtrip_to_casting() {
627627
assert_ok!(Voting::unlock(Origin::signed(1), 0, 1));
628628
assert_eq!(Balances::usable_balance(1), 5);
629629

630-
Polls::set(vec![(0, Ongoing(Tally::default(), 0))].into_iter().collect());
630+
Polls::set(vec![(0, Ongoing(Tally::new(0), 0))].into_iter().collect());
631631
assert_ok!(Voting::vote(Origin::signed(1), 0, aye(10, 1)));
632632
Polls::set(vec![(0, Completed(1, true))].into_iter().collect());
633633
assert_ok!(Voting::remove_vote(Origin::signed(1), Some(0), 0));
@@ -688,9 +688,9 @@ fn lock_aggregation_over_different_classes_with_casting_works() {
688688
new_test_ext().execute_with(|| {
689689
Polls::set(
690690
vec![
691-
(0, Ongoing(Tally::default(), 0)),
692-
(1, Ongoing(Tally::default(), 1)),
693-
(2, Ongoing(Tally::default(), 2)),
691+
(0, Ongoing(Tally::new(0), 0)),
692+
(1, Ongoing(Tally::new(0), 1)),
693+
(2, Ongoing(Tally::new(0), 2)),
694694
]
695695
.into_iter()
696696
.collect(),
@@ -747,10 +747,10 @@ fn errors_with_vote_work() {
747747
assert_ok!(Voting::undelegate(Origin::signed(1), 0));
748748
Polls::set(
749749
vec![
750-
(0, Ongoing(Tally::default(), 0)),
751-
(1, Ongoing(Tally::default(), 0)),
752-
(2, Ongoing(Tally::default(), 0)),
753-
(3, Ongoing(Tally::default(), 0)),
750+
(0, Ongoing(Tally::new(0), 0)),
751+
(1, Ongoing(Tally::new(0), 0)),
752+
(2, Ongoing(Tally::new(0), 0)),
753+
(3, Ongoing(Tally::new(0), 0)),
754754
]
755755
.into_iter()
756756
.collect(),

0 commit comments

Comments
 (0)