Skip to content

Commit

Permalink
Adjust runtime governance config (#681)
Browse files Browse the repository at this point in the history
* update democracy configuration and callFilter

* fix compile errors

* minor fix

* spaces -> tabs

* use root for a few origins
  • Loading branch information
Kailai-Wang committed Jul 5, 2022
1 parent 33a0c31 commit 188bd85
Show file tree
Hide file tree
Showing 8 changed files with 200 additions and 174 deletions.
7 changes: 7 additions & 0 deletions Cargo.lock

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

17 changes: 16 additions & 1 deletion runtime/common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,21 @@ edition = '2021'

[dependencies]

# substrate
frame-support = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.24", default-features = false }
frame-system = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.24", default-features = false }
pallet-collective = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.24", default-features = false }
pallet-membership = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.24", default-features = false }

# local
primitives = { package = "primitives", path = "../../primitives", default-features = false }

[features]
default = ["std"]
std = []
std = [
"frame-support/std",
"frame-system/std",
"pallet-collective/std",
"pallet-membership/std",
"primitives/std",
]
44 changes: 44 additions & 0 deletions runtime/common/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@
#![allow(clippy::upper_case_acronyms)]
#![cfg_attr(not(feature = "std"), no_std)]

use frame_support::traits::EnsureOneOf;
use frame_system::EnsureRoot;

pub use primitives::AccountId;

/// See https://github.com/paritytech/polkadot/blob/7096430edd116b1dc6d8337ab35b149e213cbfe9/runtime/common/src/lib.rs#L218
///
/// Macro to set a value (e.g. when using the `parameter_types` macro) to either a production value
Expand Down Expand Up @@ -50,3 +55,42 @@ macro_rules! prod_or_fast {
}
};
}

/// Instance definition for council and technical committee
pub type CouncilInstance = pallet_collective::Instance1;
pub type TechnicalCommitteeInstance = pallet_collective::Instance2;
pub type CouncilMembershipInstance = pallet_membership::Instance1;
pub type TechnicalCommitteeMembershipInstance = pallet_membership::Instance2;

/// Type definition for various proportions of council and technical committee
/// Council
pub type EnsureRootOrAllCouncil = EnsureOneOf<
EnsureRoot<AccountId>,
pallet_collective::EnsureProportionAtLeast<AccountId, CouncilInstance, 1, 1>,
>;

pub type EnsureRootOrHalfCouncil = EnsureOneOf<
EnsureRoot<AccountId>,
pallet_collective::EnsureProportionAtLeast<AccountId, CouncilInstance, 1, 2>,
>;

pub type EnsureRootOrTwoThirdsCouncil = EnsureOneOf<
EnsureRoot<AccountId>,
pallet_collective::EnsureProportionAtLeast<AccountId, CouncilInstance, 2, 3>,
>;

/// Technical Committee
pub type EnsureRootOrAllTechnicalCommittee = EnsureOneOf<
EnsureRoot<AccountId>,
pallet_collective::EnsureProportionAtLeast<AccountId, TechnicalCommitteeInstance, 1, 1>,
>;

pub type EnsureRootOrHalfTechnicalCommittee = EnsureOneOf<
EnsureRoot<AccountId>,
pallet_collective::EnsureProportionAtLeast<AccountId, TechnicalCommitteeInstance, 1, 2>,
>;

pub type EnsureRootOrTwoThirdsTechnicalCommittee = EnsureOneOf<
EnsureRoot<AccountId>,
pallet_collective::EnsureProportionAtLeast<AccountId, TechnicalCommitteeInstance, 2, 3>,
>;
88 changes: 35 additions & 53 deletions runtime/litentry/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,7 @@ use sp_version::RuntimeVersion;
use codec::{Decode, Encode, MaxEncodedLen};
use frame_support::{
construct_runtime, parameter_types,
traits::{
ConstU16, ConstU32, ConstU64, ConstU8, Contains, EnsureOneOf, Everything, InstanceFilter,
},
traits::{ConstU16, ConstU32, ConstU64, ConstU8, Contains, Everything, InstanceFilter},
weights::{
constants::{BlockExecutionWeight, ExtrinsicBaseWeight, RocksDbWeight, WEIGHT_PER_SECOND},
ConstantMultiplier, DispatchClass, IdentityFee, Weight,
Expand All @@ -69,7 +67,12 @@ use frame_system::{
limits::{BlockLength, BlockWeights},
EnsureRoot,
};
use runtime_common::prod_or_fast;
use runtime_common::{
prod_or_fast, CouncilInstance, CouncilMembershipInstance, EnsureRootOrAllCouncil,
EnsureRootOrAllTechnicalCommittee, EnsureRootOrHalfCouncil, EnsureRootOrHalfTechnicalCommittee,
EnsureRootOrTwoThirdsCouncil, EnsureRootOrTwoThirdsTechnicalCommittee,
TechnicalCommitteeInstance, TechnicalCommitteeMembershipInstance,
};
pub use sp_consensus_aura::sr25519::AuthorityId as AuraId;
pub use sp_runtime::{MultiAddress, Perbill, Percent, Permill};

Expand Down Expand Up @@ -118,7 +121,7 @@ pub type Executive = frame_executive::Executive<
// see https://github.com/paritytech/substrate/pull/10043
//
// With this type the hooks of pallets will be executed
// in the order that they are declared in `constrcut_runtime!`.
// in the order that they are declared in `construct_runtime!`.
// It was reverse order before.
// See the comment before collation related pallets too.
AllPalletsWithSystem,
Expand Down Expand Up @@ -463,39 +466,30 @@ impl pallet_democracy::Config for Runtime {
type VoteLockingPeriod = EnactmentPeriod; // Same as EnactmentPeriod
type MinimumDeposit = MinimumDeposit;
/// A straight majority of the council can decide what their next motion is.
type ExternalOrigin =
pallet_collective::EnsureProportionAtLeast<AccountId, CouncilCollective, 1, 2>;
type ExternalOrigin = EnsureRootOrHalfCouncil;
/// A super-majority can have the next scheduled referendum be a straight majority-carries vote.
type ExternalMajorityOrigin =
pallet_collective::EnsureProportionAtLeast<AccountId, CouncilCollective, 3, 4>;
type ExternalMajorityOrigin = EnsureRootOrTwoThirdsCouncil;
/// A unanimous council can have the next scheduled referendum be a straight default-carries
/// (NTB) vote.
type ExternalDefaultOrigin =
pallet_collective::EnsureProportionAtLeast<AccountId, CouncilCollective, 1, 1>;
type ExternalDefaultOrigin = EnsureRootOrAllCouncil;
/// Two thirds of the technical committee can have an ExternalMajority/ExternalDefault vote
/// be tabled immediately and with a shorter voting/enactment period.
type FastTrackOrigin =
pallet_collective::EnsureProportionAtLeast<AccountId, TechnicalCollective, 2, 3>;
type InstantOrigin =
pallet_collective::EnsureProportionAtLeast<AccountId, TechnicalCollective, 1, 1>;
type FastTrackOrigin = EnsureRootOrTwoThirdsTechnicalCommittee;
type InstantOrigin = EnsureRootOrAllTechnicalCommittee;
type InstantAllowed = InstantAllowed;
type FastTrackVotingPeriod = FastTrackVotingPeriod;
// To cancel a proposal which has been passed, 2/3 of the council must agree to it.
type CancellationOrigin =
pallet_collective::EnsureProportionAtLeast<AccountId, CouncilCollective, 2, 3>;
type CancellationOrigin = EnsureRootOrTwoThirdsCouncil;
// To cancel a proposal before it has been passed, the technical committee must be unanimous or
// Root must agree.
type CancelProposalOrigin = EnsureOneOf<
EnsureRoot<AccountId>,
pallet_collective::EnsureProportionAtLeast<AccountId, TechnicalCollective, 1, 1>,
>;
type CancelProposalOrigin = EnsureRootOrAllTechnicalCommittee;
type BlacklistOrigin = EnsureRoot<AccountId>;
// Any single technical committee member may veto a coming council proposal, however they can
// only do it once and it lasts only for the cool-off period.
type VetoOrigin = pallet_collective::EnsureMember<AccountId, TechnicalCollective>;
type VetoOrigin = pallet_collective::EnsureMember<AccountId, TechnicalCommitteeInstance>;
type CooloffPeriod = CooloffPeriod;
type PreimageByteDeposit = PreimageByteDeposit;
type OperationalPreimageOrigin = pallet_collective::EnsureMember<AccountId, CouncilCollective>;
type OperationalPreimageOrigin = pallet_collective::EnsureMember<AccountId, CouncilInstance>;
type Slash = Treasury;
type Scheduler = Scheduler;
type PalletsOrigin = OriginCaller;
Expand All @@ -508,8 +502,7 @@ parameter_types! {
pub const CouncilMotionDuration: BlockNumber = 3 * DAYS;
}

type CouncilCollective = pallet_collective::Instance1;
impl pallet_collective::Config<CouncilCollective> for Runtime {
impl pallet_collective::Config<CouncilInstance> for Runtime {
type Origin = Origin;
type Proposal = Call;
type Event = Event;
Expand All @@ -520,17 +513,13 @@ impl pallet_collective::Config<CouncilCollective> for Runtime {
type WeightInfo = weights::pallet_collective::WeightInfo<Runtime>;
}

type EnsureRootOrHalfCouncil = EnsureOneOf<
EnsureRoot<AccountId>,
pallet_collective::EnsureProportionMoreThan<AccountId, CouncilCollective, 1, 2>,
>;
impl pallet_membership::Config<pallet_membership::Instance1> for Runtime {
impl pallet_membership::Config<CouncilMembershipInstance> for Runtime {
type Event = Event;
type AddOrigin = EnsureRootOrHalfCouncil;
type RemoveOrigin = EnsureRootOrHalfCouncil;
type SwapOrigin = EnsureRootOrHalfCouncil;
type ResetOrigin = EnsureRootOrHalfCouncil;
type PrimeOrigin = EnsureRootOrHalfCouncil;
type AddOrigin = EnsureRootOrTwoThirdsCouncil;
type RemoveOrigin = EnsureRootOrTwoThirdsCouncil;
type SwapOrigin = EnsureRootOrTwoThirdsCouncil;
type ResetOrigin = EnsureRootOrTwoThirdsCouncil;
type PrimeOrigin = EnsureRootOrTwoThirdsCouncil;
type MembershipInitialized = Council;
type MembershipChanged = Council;
type MaxMembers = ConstU32<100>;
Expand All @@ -541,8 +530,7 @@ parameter_types! {
pub const TechnicalMotionDuration: BlockNumber = 3 * DAYS;
}

type TechnicalCollective = pallet_collective::Instance2;
impl pallet_collective::Config<TechnicalCollective> for Runtime {
impl pallet_collective::Config<TechnicalCommitteeInstance> for Runtime {
type Origin = Origin;
type Proposal = Call;
type Event = Event;
Expand All @@ -553,13 +541,13 @@ impl pallet_collective::Config<TechnicalCollective> for Runtime {
type WeightInfo = weights::pallet_collective::WeightInfo<Runtime>;
}

impl pallet_membership::Config<pallet_membership::Instance2> for Runtime {
impl pallet_membership::Config<TechnicalCommitteeMembershipInstance> for Runtime {
type Event = Event;
type AddOrigin = EnsureRootOrHalfCouncil;
type RemoveOrigin = EnsureRootOrHalfCouncil;
type SwapOrigin = EnsureRootOrHalfCouncil;
type ResetOrigin = EnsureRootOrHalfCouncil;
type PrimeOrigin = EnsureRootOrHalfCouncil;
type AddOrigin = EnsureRootOrTwoThirdsCouncil;
type RemoveOrigin = EnsureRootOrTwoThirdsCouncil;
type SwapOrigin = EnsureRootOrTwoThirdsCouncil;
type ResetOrigin = EnsureRootOrTwoThirdsCouncil;
type PrimeOrigin = EnsureRootOrTwoThirdsCouncil;
type MembershipInitialized = TechnicalCommittee;
type MembershipChanged = TechnicalCommittee;
type MaxMembers = ConstU32<100>;
Expand All @@ -578,14 +566,8 @@ parameter_types! {
impl pallet_treasury::Config for Runtime {
type PalletId = TreasuryPalletId;
type Currency = Balances;
type ApproveOrigin = EnsureOneOf<
EnsureRoot<AccountId>,
pallet_collective::EnsureProportionAtLeast<AccountId, CouncilCollective, 3, 5>,
>;
type RejectOrigin = EnsureOneOf<
EnsureRoot<AccountId>,
pallet_collective::EnsureProportionMoreThan<AccountId, CouncilCollective, 1, 2>,
>;
type ApproveOrigin = EnsureRootOrTwoThirdsCouncil;
type RejectOrigin = EnsureRootOrHalfCouncil;
type Event = Event;
type OnSlash = ();
type ProposalBond = ProposalBond;
Expand Down Expand Up @@ -675,7 +657,7 @@ parameter_types! {
impl pallet_collator_selection::Config for Runtime {
type Event = Event;
type Currency = Balances;
type UpdateOrigin = EnsureRoot<AccountId>;
type UpdateOrigin = EnsureRootOrHalfCouncil;
type PotId = PotId;
type MaxCandidates = ConstU32<100>;
type MinCandidates = ConstU32<0>;
Expand Down Expand Up @@ -746,7 +728,7 @@ impl pallet_drop3::Config for Runtime {

impl pallet_extrinsic_filter::Config for Runtime {
type Event = Event;
type UpdateOrigin = EnsureRootOrHalfCouncil;
type UpdateOrigin = EnsureRootOrHalfTechnicalCommittee;
type NormalModeFilter = NormalModeFilter;
type SafeModeFilter = SafeModeFilter;
type TestModeFilter = Everything;
Expand Down
4 changes: 2 additions & 2 deletions runtime/litmus/src/asset_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use frame_support::{
parameter_types,
traits::{ConstU32, Contains},
};
use frame_system::EnsureRoot;
use runtime_common::EnsureRootOrHalfCouncil;
use sp_runtime::traits::AccountIdConversion;
use sp_std::prelude::*;

Expand Down Expand Up @@ -50,7 +50,7 @@ impl pallet_asset_manager::Config for Runtime {
type Balance = Balance;
type AssetId = AssetId;
type ForeignAssetType = CurrencyId;
type ForeignAssetModifierOrigin = EnsureRoot<AccountId>;
type ForeignAssetModifierOrigin = EnsureRootOrHalfCouncil;
type Currency = Balances;
type WeightInfo = weights::pallet_asset_manager::WeightInfo<Runtime>;
}

0 comments on commit 188bd85

Please sign in to comment.