Skip to content

Commit

Permalink
Add Council and Tech Committee collectives (paritytech#275)
Browse files Browse the repository at this point in the history
Co-authored-by: Joshy Orndorff <[email protected]>
  • Loading branch information
nanocryk and JoshOrndorff authored Mar 30, 2021
1 parent 83d4b5d commit 44f6b4a
Show file tree
Hide file tree
Showing 4 changed files with 99 additions and 15 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

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

15 changes: 12 additions & 3 deletions node/src/chain_spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,10 @@ use bip39::{Language, Mnemonic, Seed};
use cumulus_primitives_core::ParaId;
use log::debug;
use moonbeam_runtime::{
AccountId, Balance, BalancesConfig, DemocracyConfig, EVMConfig, EthereumChainIdConfig,
EthereumConfig, GenesisConfig, InflationInfo, ParachainInfoConfig, ParachainStakingConfig,
Range, SchedulerConfig, SudoConfig, SystemConfig, GLMR, WASM_BINARY,
AccountId, Balance, BalancesConfig, CouncilCollectiveConfig, DemocracyConfig, EVMConfig,
EthereumChainIdConfig, EthereumConfig, GenesisConfig, InflationInfo, ParachainInfoConfig,
ParachainStakingConfig, Range, SchedulerConfig, SudoConfig, SystemConfig,
TechComitteeCollectiveConfig, GLMR, WASM_BINARY,
};
use sc_chain_spec::{ChainSpecExtension, ChainSpecGroup};
use sc_service::ChainType;
Expand Down Expand Up @@ -255,6 +256,14 @@ fn testnet_genesis(
stakers,
inflation_config,
},
pallet_collective_Instance1: CouncilCollectiveConfig {
phantom: Default::default(),
members: vec![], // TODO : Set members
},
pallet_collective_Instance2: TechComitteeCollectiveConfig {
phantom: Default::default(),
members: vec![], // TODO : Set members
},
}
}

Expand Down
2 changes: 2 additions & 0 deletions runtime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ fp-rpc = { default-features = false, git = "https://github.com/purestake/frontie

pallet-democracy = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "rococo-v1" }
pallet-scheduler = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "rococo-v1" }
pallet-collective = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "rococo-v1" }

moonbeam-rpc-primitives-txpool = { path = "../primitives/rpc/txpool", default-features = false }

Expand Down Expand Up @@ -102,6 +103,7 @@ std = [
"pallet-ethereum-chain-id/std",
"pallet-democracy/std",
"pallet-scheduler/std",
"pallet-collective/std",
"author-inherent/std",
"parachain-info/std",
"cumulus-pallet-parachain-system/std",
Expand Down
96 changes: 84 additions & 12 deletions runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ use frame_support::{
traits::{Get, Randomness},
weights::{constants::WEIGHT_PER_SECOND, IdentityFee, Weight},
};
use frame_system::{EnsureNever, EnsureRoot, EnsureSigned};
use frame_system::{EnsureOneOf, EnsureRoot};
use pallet_ethereum::Call::transact;
use pallet_evm::{
Account as EVMAccount, EnsureAddressNever, EnsureAddressSame, FeeCalculator,
Expand All @@ -46,7 +46,7 @@ use pallet_transaction_payment::CurrencyAdapter;
pub use parachain_staking::{InflationInfo, Range};
use parity_scale_codec::{Decode, Encode};
use sp_api::impl_runtime_apis;
use sp_core::{OpaqueMetadata, H160, H256, U256};
use sp_core::{u32_trait::*, OpaqueMetadata, H160, H256, U256};
use sp_runtime::{
create_runtime_str, generic, impl_opaque_keys,
traits::{BlakeTwo256, Block as BlockT, IdentifyAccount, IdentityLookup, Verify},
Expand Down Expand Up @@ -110,7 +110,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
spec_name: create_runtime_str!("moonbeam"),
impl_name: create_runtime_str!("moonbeam"),
authoring_version: 3,
spec_version: 28,
spec_version: 29,
impl_version: 1,
apis: RUNTIME_API_VERSIONS,
transaction_version: 2,
Expand Down Expand Up @@ -283,6 +283,49 @@ impl pallet_scheduler::Config for Runtime {
type WeightInfo = ();
}

parameter_types! {
/// The maximum amount of time (in blocks) for council members to vote on motions.
/// Motions may end in fewer blocks if enough votes are cast to determine the result.
pub const CouncilMotionDuration: BlockNumber = 100;
/// The maximum number of Proposlas that can be open in the council at once.
pub const CouncilMaxProposals: u32 = 100;
/// The maximum number of council members.
pub const CouncilMaxMembers: u32 = 100;

/// The maximum amount of time (in blocks) for technical committee members to vote on motions.
/// Motions may end in fewer blocks if enough votes are cast to determine the result.
pub const TechComitteeMotionDuration: BlockNumber = 100;
/// The maximum number of Proposlas that can be open in the technical committee at once.
pub const TechComitteeMaxProposals: u32 = 100;
/// The maximum number of technical committee members.
pub const TechComitteeMaxMembers: u32 = 100;
}

type CouncilInstance = pallet_collective::Instance1;
type TechCommitteeInstance = pallet_collective::Instance2;

impl pallet_collective::Config<CouncilInstance> for Runtime {
type Origin = Origin;
type Event = Event;
type Proposal = Call;
type MotionDuration = CouncilMotionDuration;
type MaxProposals = CouncilMaxProposals;
type MaxMembers = CouncilMaxMembers;
type DefaultVote = pallet_collective::MoreThanMajorityThenPrimeDefaultVote;
type WeightInfo = (); // TODO : Better Weight Info ?
}

impl pallet_collective::Config<TechCommitteeInstance> for Runtime {
type Origin = Origin;
type Event = Event;
type Proposal = Call;
type MotionDuration = TechComitteeMotionDuration;
type MaxProposals = TechComitteeMaxProposals;
type MaxMembers = TechComitteeMaxMembers;
type DefaultVote = pallet_collective::MoreThanMajorityThenPrimeDefaultVote;
type WeightInfo = (); // TODO : Better Weight Info ?
}

const BLOCKS_PER_DAY: BlockNumber = 24 * 60 * 10;

parameter_types! {
Expand All @@ -308,22 +351,47 @@ impl pallet_democracy::Config for Runtime {
type VotingPeriod = VotingPeriod;
type FastTrackVotingPeriod = FastTrackVotingPeriod;
type MinimumDeposit = MinimumDeposit;
type ExternalOrigin = EnsureRoot<AccountId>;
type ExternalMajorityOrigin = EnsureRoot<AccountId>;
type ExternalDefaultOrigin = EnsureRoot<AccountId>;
type FastTrackOrigin = EnsureRoot<AccountId>;
type CancellationOrigin = EnsureRoot<AccountId>;
/// A straight majority of the council can decide what their next motion is.
type ExternalOrigin =
pallet_collective::EnsureProportionAtLeast<_1, _2, AccountId, CouncilInstance>;
/// A majority can have the next scheduled referendum be a straight majority-carries vote.
type ExternalMajorityOrigin =
pallet_collective::EnsureProportionAtLeast<_1, _2, AccountId, CouncilInstance>;
/// A unanimous council can have the next scheduled referendum be a straight default-carries
/// (NTB) vote.
type ExternalDefaultOrigin =
pallet_collective::EnsureProportionAtLeast<_1, _1, AccountId, CouncilInstance>;
/// 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<_2, _3, AccountId, TechCommitteeInstance>;
/// Instant is currently not allowed.
type InstantOrigin =
pallet_collective::EnsureProportionAtLeast<_1, _1, AccountId, TechCommitteeInstance>;
// To cancel a proposal which has been passed, 2/3 of the council must agree to it.
type CancellationOrigin = EnsureOneOf<
AccountId,
EnsureRoot<AccountId>,
pallet_collective::EnsureProportionAtLeast<_2, _3, AccountId, CouncilInstance>,
>;
// To cancel a proposal before it has been passed, the technical committee must be unanimous or
// Root must agree.
type CancelProposalOrigin = EnsureOneOf<
AccountId,
EnsureRoot<AccountId>,
pallet_collective::EnsureProportionAtLeast<_1, _1, AccountId, TechCommitteeInstance>,
>;
type BlacklistOrigin = EnsureRoot<AccountId>;
type CancelProposalOrigin = EnsureRoot<AccountId>;
type VetoOrigin = EnsureNever<AccountId>; // (root not possible)
// Any single technical committee 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, TechCommitteeInstance>;
type CooloffPeriod = CooloffPeriod;
type PreimageByteDeposit = PreimageByteDeposit;
type Slash = ();
type InstantOrigin = EnsureRoot<AccountId>;
type InstantAllowed = InstantAllowed;
type Scheduler = Scheduler;
type MaxVotes = MaxVotes;
type OperationalPreimageOrigin = EnsureSigned<AccountId>;
type OperationalPreimageOrigin = pallet_collective::EnsureMember<AccountId, CouncilInstance>;
type PalletsOrigin = OriginCaller;
type WeightInfo = ();
type MaxProposals = MaxProposals;
Expand Down Expand Up @@ -450,6 +518,10 @@ construct_runtime! {
ParachainStaking: parachain_staking::{Pallet, Call, Storage, Event<T>, Config<T>},
Scheduler: pallet_scheduler::{Pallet, Storage, Config, Event<T>, Call},
Democracy: pallet_democracy::{Pallet, Storage, Config, Event<T>, Call},
CouncilCollective:
pallet_collective::<Instance1>::{Pallet, Call, Event<T>, Origin<T>, Config<T>},
TechComitteeCollective:
pallet_collective::<Instance2>::{Pallet, Call, Event<T>, Origin<T>, Config<T>},
// The order matters here. Inherents will be included in the order specified here.
// Concretely we need the author inherent to come after the parachain_upgrade inherent.
AuthorInherent: author_inherent::{Pallet, Call, Storage, Inherent},
Expand Down

0 comments on commit 44f6b4a

Please sign in to comment.