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

Several tweaks needed for Governance 2.0 #11124

Merged
merged 67 commits into from
May 31, 2022
Merged
Show file tree
Hide file tree
Changes from 58 commits
Commits
Show all changes
67 commits
Select commit Hold shift + click to select a range
2c7960e
Add stepped curve for referenda
gavofyork Mar 26, 2022
f756d98
Treasury SpendOrigin
gavofyork Mar 28, 2022
de49a27
Merge remote-tracking branch 'origin/master' into gav-gov2-tweaks
gavofyork Apr 4, 2022
788a85f
Add tests
gavofyork Apr 4, 2022
9b967e7
Better Origin Or-gating
gavofyork Apr 4, 2022
b84e299
Reciprocal curve
gavofyork Apr 10, 2022
c8e8a5c
Tests for reciprical and rounding in PerThings
gavofyork Apr 11, 2022
a1a4619
Tweaks and new quad curve
gavofyork Apr 12, 2022
5710058
Const derivation of reciprocal curve parameters
gavofyork Apr 12, 2022
6bde6aa
Remove some unneeded code
gavofyork Apr 12, 2022
abb8a8f
Actually useful linear curve
gavofyork Apr 12, 2022
9cecb07
Fixes
gavofyork Apr 12, 2022
31da176
Provisional curves
gavofyork Apr 12, 2022
e6c0f02
Rejig 'turnout' as 'support'
gavofyork Apr 13, 2022
7aeab6c
Merge remote-tracking branch 'origin/master' into gav-gov2-tweaks
gavofyork Apr 13, 2022
ed050ca
Use TypedGet
gavofyork Apr 13, 2022
386977a
Fixes
gavofyork Apr 13, 2022
2cd8a46
Enable curve's ceil to be configured
gavofyork Apr 13, 2022
cb567e5
Merge remote-tracking branch 'origin/master' into gav-gov2-tweaks
gavofyork Apr 27, 2022
3f424ae
Merge remote-tracking branch 'origin/master' into gav-gov2-tweaks
gavofyork May 11, 2022
485fd23
Formatting
gavofyork May 11, 2022
f5d6f45
Fixes
gavofyork May 11, 2022
7ce42e8
Fixes
gavofyork May 11, 2022
b25bc5f
Fixes
gavofyork May 11, 2022
45208e0
Remove EnsureOneOf
gavofyork May 11, 2022
35764fb
Fixes
gavofyork May 11, 2022
3b53be6
Fixes
gavofyork May 11, 2022
cbadc3e
Fixes
gavofyork May 12, 2022
940f4b3
Fixes
gavofyork May 12, 2022
a091e9d
Formatting
gavofyork May 12, 2022
73bbf7c
Fixes
gavofyork May 12, 2022
ef59083
Merge remote-tracking branch 'origin/master' into gav-gov2-tweaks
gavofyork May 12, 2022
a291d47
Merge remote-tracking branch 'origin/master' into gav-gov2-tweaks
gavofyork May 17, 2022
8019e33
Update frame/support/src/traits/dispatch.rs
gavofyork May 18, 2022
7596264
Grumbles
gavofyork May 18, 2022
2b4a20a
Merge remote-tracking branch 'origin/master' into gav-gov2-tweaks
gavofyork May 18, 2022
40ca11e
Formatting
gavofyork May 18, 2022
18c6438
Fixes
gavofyork May 18, 2022
ed23dc4
Merge remote-tracking branch 'origin/master' into gav-gov2-tweaks
gavofyork May 19, 2022
d04ebd0
APIs of VoteTally should include class
gavofyork May 19, 2022
91b1094
Fixes
gavofyork May 19, 2022
471b43a
Fix overlay prefix removal result
gavofyork May 18, 2022
92cd9a3
Second part of the overlay prefix removal fix.
gavofyork May 18, 2022
0239621
Merge remote-tracking branch 'origin/master' into gav-gov2-tweaks
gavofyork May 19, 2022
d504d70
Formatting
gavofyork May 19, 2022
cace119
Fixes
gavofyork May 19, 2022
e988654
Add some tests and make clear rounding algo
gavofyork May 19, 2022
38f14fd
Fixes
gavofyork May 20, 2022
064de3d
Formatting
gavofyork May 20, 2022
4f456f8
Revert questionable fix
gavofyork May 24, 2022
697bff5
Introduce test for kill_prefix
gavofyork May 24, 2022
d111c87
Fixes
gavofyork May 25, 2022
244c5f4
Formatting
gavofyork May 25, 2022
656baff
Fixes
gavofyork May 25, 2022
bcce142
Fix possible overflow
gavofyork May 25, 2022
af7b81e
Docs
gavofyork May 25, 2022
ad9a732
Add benchmark test
gavofyork May 25, 2022
fd5e03a
Formatting
gavofyork May 25, 2022
18c72d3
Merge remote-tracking branch 'origin/master' into gav-gov2-tweaks
gavofyork May 29, 2022
db730db
Update frame/referenda/src/types.rs
gavofyork May 30, 2022
c251948
Docs
gavofyork May 30, 2022
4088a11
Merge branch 'gav-gov2-tweaks' of github.com:paritytech/substrate int…
gavofyork May 30, 2022
9b1bd8b
Fixes
gavofyork May 30, 2022
d2730c2
Use latest API in tests
gavofyork May 30, 2022
5f7b13e
Formatting
gavofyork May 30, 2022
b58dbbc
Whitespace
gavofyork May 30, 2022
e1b00d8
Use latest API in tests
gavofyork May 30, 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
2 changes: 2 additions & 0 deletions Cargo.lock

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

25 changes: 14 additions & 11 deletions bin/node/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ use frame_support::{
pallet_prelude::Get,
parameter_types,
traits::{
AsEnsureOriginWithArg, ConstU128, ConstU16, ConstU32, Currency, EnsureOneOf,
AsEnsureOriginWithArg, ConstU128, ConstU16, ConstU32, Currency, EitherOfDiverse,
EqualPrivilegeOnly, Everything, Imbalance, InstanceFilter, KeyOwnerProofSystem,
LockIdentifier, Nothing, OnUnbalanced, U128CurrencyToVote,
},
Expand Down Expand Up @@ -550,7 +550,7 @@ impl pallet_staking::Config for Runtime {
type BondingDuration = BondingDuration;
type SlashDeferDuration = SlashDeferDuration;
/// A super-majority of the council can cancel the slash.
type SlashCancelOrigin = EnsureOneOf<
type SlashCancelOrigin = EitherOfDiverse<
EnsureRoot<AccountId>,
pallet_collective::EnsureProportionAtLeast<AccountId, CouncilCollective, 3, 4>,
>;
Expand Down Expand Up @@ -794,12 +794,14 @@ impl pallet_referenda::TracksInfo<Balance, BlockNumber> for TracksInfo {
confirm_period: 2,
min_enactment_period: 4,
min_approval: pallet_referenda::Curve::LinearDecreasing {
begin: Perbill::from_percent(100),
delta: Perbill::from_percent(50),
length: Perbill::from_percent(100),
floor: Perbill::from_percent(50),
ceil: Perbill::from_percent(100),
},
min_turnout: pallet_referenda::Curve::LinearDecreasing {
begin: Perbill::from_percent(100),
delta: Perbill::from_percent(100),
min_support: pallet_referenda::Curve::LinearDecreasing {
length: Perbill::from_percent(100),
floor: Perbill::from_percent(0),
ceil: Perbill::from_percent(100),
},
},
)];
Expand Down Expand Up @@ -882,7 +884,7 @@ impl pallet_democracy::Config for Runtime {
pallet_collective::EnsureProportionAtLeast<AccountId, CouncilCollective, 2, 3>;
// To cancel a proposal before it has been passed, the technical committee must be unanimous or
// Root must agree.
type CancelProposalOrigin = EnsureOneOf<
type CancelProposalOrigin = EitherOfDiverse<
EnsureRoot<AccountId>,
pallet_collective::EnsureProportionAtLeast<AccountId, TechnicalCollective, 1, 1>,
>;
Expand Down Expand Up @@ -972,7 +974,7 @@ impl pallet_collective::Config<TechnicalCollective> for Runtime {
type WeightInfo = pallet_collective::weights::SubstrateWeight<Runtime>;
}

type EnsureRootOrHalfCouncil = EnsureOneOf<
type EnsureRootOrHalfCouncil = EitherOfDiverse<
EnsureRoot<AccountId>,
pallet_collective::EnsureProportionMoreThan<AccountId, CouncilCollective, 1, 2>,
>;
Expand Down Expand Up @@ -1006,11 +1008,11 @@ parameter_types! {
impl pallet_treasury::Config for Runtime {
type PalletId = TreasuryPalletId;
type Currency = Balances;
type ApproveOrigin = EnsureOneOf<
type ApproveOrigin = EitherOfDiverse<
EnsureRoot<AccountId>,
pallet_collective::EnsureProportionAtLeast<AccountId, CouncilCollective, 3, 5>,
>;
type RejectOrigin = EnsureOneOf<
type RejectOrigin = EitherOfDiverse<
EnsureRoot<AccountId>,
pallet_collective::EnsureProportionMoreThan<AccountId, CouncilCollective, 1, 2>,
>;
Expand All @@ -1025,6 +1027,7 @@ impl pallet_treasury::Config for Runtime {
type SpendFunds = Bounties;
type WeightInfo = pallet_treasury::weights::SubstrateWeight<Runtime>;
type MaxApprovals = MaxApprovals;
type SpendOrigin = frame_support::traits::NeverEnsureOrigin<u128>;
}

parameter_types! {
Expand Down
2 changes: 1 addition & 1 deletion docs/Upgrading-2.0-to-3.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ Democracy brings three new settings with this release, all to allow for better i
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<
+ type CancelProposalOrigin = EitherOfDiverse<
+ AccountId,
+ EnsureRoot<AccountId>,
+ pallet_collective::EnsureProportionAtLeast<_1, _1, AccountId, TechnicalCollective>,
Expand Down
2 changes: 1 addition & 1 deletion frame/bounties/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,6 @@ parameter_types! {
pub const TreasuryPalletId: PalletId = PalletId(*b"py/trsry");
}

// impl pallet_treasury::Config for Test {
impl pallet_treasury::Config for Test {
type PalletId = TreasuryPalletId;
type Currency = pallet_balances::Pallet<Test>;
Expand All @@ -126,6 +125,7 @@ impl pallet_treasury::Config for Test {
type WeightInfo = ();
type SpendFunds = Bounties;
type MaxApprovals = ConstU32<100>;
type SpendOrigin = frame_support::traits::NeverEnsureOrigin<u64>;
}

parameter_types! {
Expand Down
1 change: 1 addition & 0 deletions frame/child-bounties/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ impl pallet_treasury::Config for Test {
type WeightInfo = ();
type SpendFunds = Bounties;
type MaxApprovals = ConstU32<100>;
type SpendOrigin = frame_support::traits::NeverEnsureOrigin<u64>;
}
parameter_types! {
// This will be 50% of the bounty fee.
Expand Down
90 changes: 45 additions & 45 deletions frame/conviction-voting/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use std::collections::BTreeMap;

use frame_support::{
assert_noop, assert_ok, parameter_types,
traits::{ConstU32, ConstU64, Contains, Polling},
traits::{ConstU32, ConstU64, Contains, Polling, VoteTally},
};
use sp_core::H256;
use sp_runtime::{
Expand Down Expand Up @@ -166,7 +166,7 @@ impl Polling<TallyOf<Test>> for TestPolls {
fn create_ongoing(class: Self::Class) -> Result<Self::Index, ()> {
let mut polls = Polls::get();
let i = polls.keys().rev().next().map_or(0, |x| x + 1);
polls.insert(i, Ongoing(Tally::default(), class));
polls.insert(i, Ongoing(Tally::new(0), class));
Polls::set(polls);
Ok(i)
}
Expand Down Expand Up @@ -271,19 +271,19 @@ fn basic_voting_works() {
assert_ok!(Voting::vote(Origin::signed(1), 3, aye(2, 5)));
assert_eq!(tally(3), Tally::from_parts(10, 0, 2));
assert_ok!(Voting::vote(Origin::signed(1), 3, nay(2, 5)));
assert_eq!(tally(3), Tally::from_parts(0, 10, 2));
assert_eq!(tally(3), Tally::from_parts(0, 10, 0));
assert_eq!(Balances::usable_balance(1), 8);

assert_ok!(Voting::vote(Origin::signed(1), 3, aye(5, 1)));
assert_eq!(tally(3), Tally::from_parts(5, 0, 5));
assert_ok!(Voting::vote(Origin::signed(1), 3, nay(5, 1)));
assert_eq!(tally(3), Tally::from_parts(0, 5, 5));
assert_eq!(tally(3), Tally::from_parts(0, 5, 0));
assert_eq!(Balances::usable_balance(1), 5);

assert_ok!(Voting::vote(Origin::signed(1), 3, aye(10, 0)));
assert_eq!(tally(3), Tally::from_parts(1, 0, 10));
assert_ok!(Voting::vote(Origin::signed(1), 3, nay(10, 0)));
assert_eq!(tally(3), Tally::from_parts(0, 1, 10));
assert_eq!(tally(3), Tally::from_parts(0, 1, 0));
assert_eq!(Balances::usable_balance(1), 0);

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

assert_ok!(Voting::vote(Origin::signed(1), 3, aye(5, 1)));
assert_eq!(tally(3), Tally::from_parts(5, 0, 5));
assert_ok!(Voting::vote(Origin::signed(1), 3, nay(5, 1)));
assert_eq!(tally(3), Tally::from_parts(0, 5, 5));
assert_eq!(tally(3), Tally::from_parts(0, 5, 0));
assert_eq!(Balances::usable_balance(1), 5);

assert_ok!(Voting::vote(Origin::signed(1), 3, aye(10, 0)));
assert_eq!(tally(3), Tally::from_parts(1, 0, 10));
assert_ok!(Voting::vote(Origin::signed(1), 3, nay(10, 0)));
assert_eq!(tally(3), Tally::from_parts(0, 1, 10));
assert_eq!(tally(3), Tally::from_parts(0, 1, 0));
assert_eq!(Balances::usable_balance(1), 0);

assert_ok!(Voting::remove_vote(Origin::signed(1), None, 3));
Expand Down Expand Up @@ -376,10 +376,10 @@ fn classwise_delegation_works() {
new_test_ext().execute_with(|| {
Polls::set(
vec![
(0, Ongoing(Tally::default(), 0)),
(1, Ongoing(Tally::default(), 1)),
(2, Ongoing(Tally::default(), 2)),
(3, Ongoing(Tally::default(), 2)),
(0, Ongoing(Tally::new(0), 0)),
(1, Ongoing(Tally::new(0), 1)),
(2, Ongoing(Tally::new(0), 2)),
(3, Ongoing(Tally::new(0), 2)),
]
.into_iter()
.collect(),
Expand All @@ -403,9 +403,9 @@ fn classwise_delegation_works() {
assert_eq!(
Polls::get(),
vec![
(0, Ongoing(Tally::from_parts(6, 2, 35), 0)),
(1, Ongoing(Tally::from_parts(6, 2, 35), 1)),
(2, Ongoing(Tally::from_parts(6, 2, 35), 2)),
(0, Ongoing(Tally::from_parts(6, 2, 15), 0)),
(1, Ongoing(Tally::from_parts(6, 2, 15), 1)),
(2, Ongoing(Tally::from_parts(6, 2, 15), 2)),
(3, Ongoing(Tally::from_parts(0, 0, 0), 2)),
]
.into_iter()
Expand All @@ -417,10 +417,10 @@ fn classwise_delegation_works() {
assert_eq!(
Polls::get(),
vec![
(0, Ongoing(Tally::from_parts(6, 2, 35), 0)),
(1, Ongoing(Tally::from_parts(6, 2, 35), 1)),
(2, Ongoing(Tally::from_parts(6, 2, 35), 2)),
(3, Ongoing(Tally::from_parts(0, 6, 15), 2)),
(0, Ongoing(Tally::from_parts(6, 2, 15), 0)),
(1, Ongoing(Tally::from_parts(6, 2, 15), 1)),
(2, Ongoing(Tally::from_parts(6, 2, 15), 2)),
(3, Ongoing(Tally::from_parts(0, 6, 0), 2)),
]
.into_iter()
.collect()
Expand All @@ -432,10 +432,10 @@ fn classwise_delegation_works() {
assert_eq!(
Polls::get(),
vec![
(0, Ongoing(Tally::from_parts(6, 2, 35), 0)),
(1, Ongoing(Tally::from_parts(6, 2, 35), 1)),
(2, Ongoing(Tally::from_parts(1, 7, 35), 2)),
(3, Ongoing(Tally::from_parts(0, 1, 10), 2)),
(0, Ongoing(Tally::from_parts(6, 2, 15), 0)),
(1, Ongoing(Tally::from_parts(6, 2, 15), 1)),
(2, Ongoing(Tally::from_parts(1, 7, 10), 2)),
(3, Ongoing(Tally::from_parts(0, 1, 0), 2)),
]
.into_iter()
.collect()
Expand All @@ -451,10 +451,10 @@ fn classwise_delegation_works() {
assert_eq!(
Polls::get(),
vec![
(0, Ongoing(Tally::from_parts(4, 2, 33), 0)),
(1, Ongoing(Tally::from_parts(4, 2, 33), 1)),
(2, Ongoing(Tally::from_parts(4, 2, 33), 2)),
(3, Ongoing(Tally::from_parts(0, 4, 13), 2)),
(0, Ongoing(Tally::from_parts(4, 2, 13), 0)),
(1, Ongoing(Tally::from_parts(4, 2, 13), 1)),
(2, Ongoing(Tally::from_parts(4, 2, 13), 2)),
(3, Ongoing(Tally::from_parts(0, 4, 0), 2)),
]
.into_iter()
.collect()
Expand Down Expand Up @@ -483,10 +483,10 @@ fn classwise_delegation_works() {
assert_eq!(
Polls::get(),
vec![
(0, Ongoing(Tally::from_parts(7, 2, 36), 0)),
(1, Ongoing(Tally::from_parts(8, 2, 37), 1)),
(2, Ongoing(Tally::from_parts(9, 2, 38), 2)),
(3, Ongoing(Tally::from_parts(0, 9, 18), 2)),
(0, Ongoing(Tally::from_parts(7, 2, 16), 0)),
(1, Ongoing(Tally::from_parts(8, 2, 17), 1)),
(2, Ongoing(Tally::from_parts(9, 2, 18), 2)),
(3, Ongoing(Tally::from_parts(0, 9, 0), 2)),
]
.into_iter()
.collect()
Expand All @@ -497,7 +497,7 @@ fn classwise_delegation_works() {
#[test]
fn redelegation_after_vote_ending_should_keep_lock() {
new_test_ext().execute_with(|| {
Polls::set(vec![(0, Ongoing(Tally::default(), 0))].into_iter().collect());
Polls::set(vec![(0, Ongoing(Tally::new(0), 0))].into_iter().collect());
assert_ok!(Voting::delegate(Origin::signed(1), 0, 2, Conviction::Locked1x, 5));
assert_ok!(Voting::vote(Origin::signed(2), 0, aye(10, 1)));
Polls::set(vec![(0, Completed(1, true))].into_iter().collect());
Expand All @@ -515,9 +515,9 @@ fn lock_amalgamation_valid_with_multiple_removed_votes() {
new_test_ext().execute_with(|| {
Polls::set(
vec![
(0, Ongoing(Tally::default(), 0)),
(1, Ongoing(Tally::default(), 0)),
(2, Ongoing(Tally::default(), 0)),
(0, Ongoing(Tally::new(0), 0)),
(1, Ongoing(Tally::new(0), 0)),
(2, Ongoing(Tally::new(0), 0)),
]
.into_iter()
.collect(),
Expand Down Expand Up @@ -587,7 +587,7 @@ fn lock_amalgamation_valid_with_multiple_delegations() {
#[test]
fn lock_amalgamation_valid_with_move_roundtrip_to_delegation() {
new_test_ext().execute_with(|| {
Polls::set(vec![(0, Ongoing(Tally::default(), 0))].into_iter().collect());
Polls::set(vec![(0, Ongoing(Tally::new(0), 0))].into_iter().collect());
assert_ok!(Voting::vote(Origin::signed(1), 0, aye(5, 1)));
Polls::set(vec![(0, Completed(1, true))].into_iter().collect());
assert_ok!(Voting::remove_vote(Origin::signed(1), Some(0), 0));
Expand All @@ -599,7 +599,7 @@ fn lock_amalgamation_valid_with_move_roundtrip_to_delegation() {
assert_ok!(Voting::unlock(Origin::signed(1), 0, 1));
assert_eq!(Balances::usable_balance(1), 0);

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

Polls::set(vec![(0, Ongoing(Tally::default(), 0))].into_iter().collect());
Polls::set(vec![(0, Ongoing(Tally::new(0), 0))].into_iter().collect());
assert_ok!(Voting::vote(Origin::signed(1), 0, aye(10, 1)));
Polls::set(vec![(0, Completed(1, true))].into_iter().collect());
assert_ok!(Voting::remove_vote(Origin::signed(1), Some(0), 0));
Expand Down Expand Up @@ -688,9 +688,9 @@ fn lock_aggregation_over_different_classes_with_casting_works() {
new_test_ext().execute_with(|| {
Polls::set(
vec![
(0, Ongoing(Tally::default(), 0)),
(1, Ongoing(Tally::default(), 1)),
(2, Ongoing(Tally::default(), 2)),
(0, Ongoing(Tally::new(0), 0)),
(1, Ongoing(Tally::new(0), 1)),
(2, Ongoing(Tally::new(0), 2)),
]
.into_iter()
.collect(),
Expand Down Expand Up @@ -747,10 +747,10 @@ fn errors_with_vote_work() {
assert_ok!(Voting::undelegate(Origin::signed(1), 0));
Polls::set(
vec![
(0, Ongoing(Tally::default(), 0)),
(1, Ongoing(Tally::default(), 0)),
(2, Ongoing(Tally::default(), 0)),
(3, Ongoing(Tally::default(), 0)),
(0, Ongoing(Tally::new(0), 0)),
(1, Ongoing(Tally::new(0), 0)),
(2, Ongoing(Tally::new(0), 0)),
(3, Ongoing(Tally::new(0), 0)),
]
.into_iter()
.collect(),
Expand Down
Loading