Skip to content

feat: use FRAME collective and council impls #459

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
6 changes: 6 additions & 0 deletions Cargo.lock

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

8 changes: 8 additions & 0 deletions runtime/common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ scale-info = { version = "1.0", default-features = false, features = ["derive"]
frame-support = { git = 'https://github.com/paritytech/substrate', branch = 'polkadot-v0.9.12', default-features = false }
frame-system = { git = 'https://github.com/paritytech/substrate', branch = 'polkadot-v0.9.12', default-features = false }
sp-std = { git = 'https://github.com/paritytech/substrate', branch = 'polkadot-v0.9.12', default-features = false }
sp-core = { git = 'https://github.com/paritytech/substrate', branch = 'polkadot-v0.9.12', default-features = false }

pallet-collective = { git = 'https://github.com/paritytech/substrate', branch = 'polkadot-v0.9.12', default-features = false }
pallet-membership = { git = 'https://github.com/paritytech/substrate', branch = 'polkadot-v0.9.12', default-features = false }


# xcm
xcm = { git = 'https://github.com/paritytech/polkadot', branch = 'release-v0.9.12', default-features = false }
Expand Down Expand Up @@ -43,7 +48,10 @@ std = [
"frame-support/std",
'frame-system/std',
'sp-std/std',
'sp-core/std',
'scale-info/std',
'pallet-collective/std',
'pallet-membership/std',

"xcm/std",
"xcm-calls/std",
Expand Down
27 changes: 27 additions & 0 deletions runtime/common/src/governance.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// Copyright 2021 ChainSafe Systems
// SPDX-License-Identifier: LGPL-3.0-only

//! Governance related commonly used config types

use frame_system::{EnsureOneOf, EnsureRoot};
use primitives::AccountId;
use sp_core::u32_trait::{_1, _2};

pub type CommitteeInstance = pallet_collective::Instance1;
pub type CouncilInstance = pallet_collective::Instance2;

pub type CouncilMembershipInstance = pallet_membership::Instance1;
pub type ConstituentMembershipInstance = pallet_membership::Instance2;

// General Council
pub type EnsureRootOrAllGeneralCouncil = EnsureOneOf<
AccountId,
EnsureRoot<AccountId>,
pallet_collective::EnsureProportionAtLeast<_1, _1, AccountId, CouncilInstance>,
>;

pub type EnsureRootOrHalfGeneralCouncil = EnsureOneOf<
AccountId,
EnsureRoot<AccountId>,
pallet_collective::EnsureProportionAtLeast<_1, _2, AccountId, CouncilInstance>,
>;
1 change: 1 addition & 0 deletions runtime/common/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

#![cfg_attr(not(feature = "std"), no_std)]
pub mod constants;
pub mod governance;
pub mod payment;
pub mod traits;
pub mod types;
Expand Down
13 changes: 12 additions & 1 deletion runtime/dev/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ pallet-sudo = { git = 'https://github.com/paritytech/substrate', branch = 'polka
pallet-timestamp = { git = 'https://github.com/paritytech/substrate', branch = 'polkadot-v0.9.12', default-features = false }
pallet-transaction-payment = { git = 'https://github.com/paritytech/substrate', branch = 'polkadot-v0.9.12', default-features = false }
pallet-transaction-payment-rpc-runtime-api = { git = 'https://github.com/paritytech/substrate', branch = 'polkadot-v0.9.12', default-features = false }
pallet-democracy = { git = 'https://github.com/paritytech/substrate', branch = 'polkadot-v0.9.12', default-features = false }
pallet-membership = { git = 'https://github.com/paritytech/substrate', branch = 'polkadot-v0.9.12', default-features = false }
pallet-treasury = { git = 'https://github.com/paritytech/substrate', branch = 'polkadot-v0.9.12', default-features = false }

# Cumulus Dependencies
pallet-collator-selection = { git = 'https://github.com/paritytech/cumulus', branch = 'polkadot-v0.9.12', default-features = false }
Expand Down Expand Up @@ -119,7 +122,11 @@ runtime-benchmarks = [
'pallet-collator-selection/runtime-benchmarks',
'pallet-balances/runtime-benchmarks',
'pallet-timestamp/runtime-benchmarks',

'pallet-democracy/runtime-benchmarks',
'pallet-collective/runtime-benchmarks',
'pallet-membership/runtime-benchmarks',
'pallet-treasury/runtime-benchmarks',

'pallet-asset-index/runtime-benchmarks',
'pallet-price-feed/runtime-benchmarks',
'pallet-local-treasury/runtime-benchmarks',
Expand Down Expand Up @@ -167,6 +174,10 @@ std = [
'pallet-transaction-payment/std',
'pallet-xcm/std',
'pallet-asset-tx-payment/std',
'pallet-democracy/std',
'pallet-collective/std',
'pallet-membership/std',
'pallet-treasury/std',

'parachain-info/std',
'cumulus-pallet-aura-ext/std',
Expand Down
91 changes: 89 additions & 2 deletions runtime/dev/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,17 @@ use xcm_builder::{
use xcm_executor::XcmExecutor;

use frame_support::traits::{Everything, Nothing};
use frame_system::EnsureRoot;
use pallet_committee::EnsureMember;

use pint_runtime_common::payment::BalanceToAssetBalance;
pub use pint_runtime_common::{constants::*, types::*, weights};
use pint_runtime_common::{
governance::{
CommitteeInstance, ConstituentMembershipInstance, CouncilInstance, EnsureRootOrAllGeneralCouncil,
EnsureRootOrHalfGeneralCouncil,
},
payment::BalanceToAssetBalance,
};
use primitives::traits::MultiAssetRegistry;
pub use primitives::*;
use xcm_calls::{
Expand Down Expand Up @@ -220,6 +227,79 @@ impl pallet_sudo::Config for Runtime {
type Call = Call;
}

parameter_types! {
pub const GeneralCouncilMotionDuration: BlockNumber = 3 * DAYS;
pub const GeneralCouncilMaxProposals: u32 = 20;
pub const GeneralCouncilMaxMembers: u32 = 7;
}

impl pallet_collective::Config<CommitteeInstance> for Runtime {
type Origin = Origin;
type Proposal = Call;
type Event = Event;
type MotionDuration = GeneralCouncilMotionDuration;
type MaxProposals = GeneralCouncilMaxProposals;
type MaxMembers = GeneralCouncilMaxMembers;
type DefaultVote = pallet_collective::PrimeDefaultVote;
type WeightInfo = ();
}

parameter_types! {
pub const LaunchPeriod: BlockNumber = 5 * DAYS;
pub const VotingPeriod: BlockNumber = 5 * DAYS;
pub const FastTrackVotingPeriod: BlockNumber = 3 * HOURS;
pub MinimumDeposit: Balance = 100 * dollar(KAR);
pub const EnactmentPeriod: BlockNumber = 2 * DAYS;
pub const VoteLockingPeriod: BlockNumber = 7 * DAYS;
pub const CooloffPeriod: BlockNumber = 7 * DAYS;
pub PreimageByteDeposit: Balance = deposit(0, 1);
pub const InstantAllowed: bool = true;
pub const MaxVotes: u32 = 100;
pub const MaxProposals: u32 = 100;
}

impl pallet_democracy::Config for Runtime {
type Proposal = Call;
type Event = Event;
type Currency = Balances;
type EnactmentPeriod = EnactmentPeriod;
type LaunchPeriod = LaunchPeriod;
type VotingPeriod = VotingPeriod;
type VoteLockingPeriod = VoteLockingPeriod;
type MinimumDeposit = MinimumDeposit;
/// A straight majority of the council can decide what their next motion is.
type ExternalOrigin = EnsureRootOrHalfGeneralCouncil;
/// A majority can have the next scheduled referendum be a straight majority-carries vote.
type ExternalMajorityOrigin = EnsureRootOrHalfGeneralCouncil;
/// A unanimous council can have the next scheduled referendum be a straight default-carries
/// (NTB) vote.
type ExternalDefaultOrigin = EnsureRootOrAllGeneralCouncil;
/// Two thirds of the technical committee can have an ExternalMajority/ExternalDefault vote
/// be tabled immediately and with a shorter voting/enactment period.
type FastTrackOrigin = EnsureRootOrAllGeneralCouncil;
type InstantOrigin = EnsureRootOrAllGeneralCouncil;
type InstantAllowed = InstantAllowed;
type FastTrackVotingPeriod = FastTrackVotingPeriod;
// To cancel a proposal which has been passed, 1/2 of the council must agree to it.
type CancellationOrigin = EnsureRootOrHalfGeneralCouncil;
type BlacklistOrigin = EnsureRoot<AccountId>;
// To cancel a proposal before it has been passed, the council must be unanimous
// Root must agree.
type CancelProposalOrigin = EnsureRootOrHalfGeneralCouncil;
// Any single constituent member may veto a coming council proposal, however they can
// only do it once and it lasts only for the cooloff period.
type VetoOrigin = pallet_collective::EnsureMember<AccountId, ConstituentMembershipInstance>;
type CooloffPeriod = CooloffPeriod;
type PreimageByteDeposit = PreimageByteDeposit;
type OperationalPreimageOrigin = pallet_collective::EnsureMember<AccountId, CouncilInstance>;
type Slash = Treasury;
type Scheduler = Scheduler;
type PalletsOrigin = OriginCaller;
type MaxVotes = MaxVotes;
type WeightInfo = pallet_democracy::weights::SubstrateWeight<Runtime>;
type MaxProposals = MaxProposals;
}

impl cumulus_pallet_parachain_system::Config for Runtime {
type Event = Event;
type OnValidationData = ();
Expand Down Expand Up @@ -753,7 +833,14 @@ construct_runtime!(
XcmpQueue: cumulus_pallet_xcmp_queue::{Pallet, Call, Storage, Event<T>} = 100,
DmpQueue: cumulus_pallet_dmp_queue::{Pallet, Call, Storage, Event<T>} = 101,
PolkadotXcm: pallet_xcm::{Pallet, Storage, Call, Event<T>, Origin, Config} = 102,
CumulusXcm: cumulus_pallet_xcm::{Pallet, Event<T>, Origin} = 103
CumulusXcm: cumulus_pallet_xcm::{Pallet, Event<T>, Origin} = 103,

// Governance
GeneralCommittee: pallet_collective::<Instance1>::{Pallet, Call, Storage, Origin<T>, Event<T>, Config<T>} = 110,
// CouncilMembership: pallet_membership::<Instance1>::{Pallet, Call, Storage, Event<T>, Config<T>} = 111,
// ConstituentMembership: pallet_membership::<Instance2>::{Pallet, Call, Storage, Event<T>, Config<T>} = 112,
// Democracy: pallet_democracy::{Pallet, Call, Storage, Config<T>, Event<T>} = 113,

}
);

Expand Down