From 69bd6d8ef256d7cec761f912aeddefb61547de35 Mon Sep 17 00:00:00 2001 From: Gavin Wood Date: Fri, 9 Apr 2021 22:16:32 +0200 Subject: [PATCH] Introduce/integrate a collective into Rococo Relay (#2869) * Introduce a collective into Rococo runtime * Intregrate Rococo Collective into XCM * Fixes * Update runtime/rococo/src/lib.rs Co-authored-by: Robert Habermeier --- polkadot/Cargo.lock | 1 + polkadot/node/service/src/chain_spec.rs | 4 ++ polkadot/runtime/rococo/Cargo.toml | 3 ++ polkadot/runtime/rococo/src/lib.rs | 50 +++++++++++++++++++++---- polkadot/xcm/xcm-builder/src/lib.rs | 2 +- 5 files changed, 52 insertions(+), 8 deletions(-) diff --git a/polkadot/Cargo.lock b/polkadot/Cargo.lock index 82bb3111d3..b5c4f91eda 100644 --- a/polkadot/Cargo.lock +++ b/polkadot/Cargo.lock @@ -7335,6 +7335,7 @@ dependencies = [ "pallet-grandpa", "pallet-im-online", "pallet-indices", + "pallet-membership", "pallet-mmr", "pallet-mmr-primitives", "pallet-offences", diff --git a/polkadot/node/service/src/chain_spec.rs b/polkadot/node/service/src/chain_spec.rs index 37098dddbe..71b146716e 100644 --- a/polkadot/node/service/src/chain_spec.rs +++ b/polkadot/node/service/src/chain_spec.rs @@ -881,6 +881,8 @@ fn rococo_staging_testnet_config_genesis(wasm_binary: &[u8]) -> rococo_runtime:: }, pallet_grandpa: Default::default(), pallet_im_online: Default::default(), + pallet_collective: Default::default(), + pallet_membership: Default::default(), pallet_authority_discovery: rococo_runtime::AuthorityDiscoveryConfig { keys: vec![], }, @@ -1432,6 +1434,8 @@ pub fn rococo_testnet_genesis( }, pallet_grandpa: Default::default(), pallet_im_online: Default::default(), + pallet_collective: Default::default(), + pallet_membership: Default::default(), pallet_authority_discovery: rococo_runtime::AuthorityDiscoveryConfig { keys: vec![], }, diff --git a/polkadot/runtime/rococo/Cargo.toml b/polkadot/runtime/rococo/Cargo.toml index db5494d5cd..b20826861a 100644 --- a/polkadot/runtime/rococo/Cargo.toml +++ b/polkadot/runtime/rococo/Cargo.toml @@ -40,6 +40,7 @@ pallet-collective = { git = "https://github.com/paritytech/substrate", branch = pallet-grandpa = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false } pallet-im-online = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false } pallet-indices = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false } +pallet-membership = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false } pallet-mmr = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false } pallet-mmr-primitives = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false } pallet-transaction-payment = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false } @@ -87,6 +88,7 @@ std = [ "pallet-beefy/std", "pallet-grandpa/std", "pallet-sudo/std", + "pallet-membership/std", "pallet-mmr/std", "pallet-mmr-primitives/std", "pallet-indices/std", @@ -159,6 +161,7 @@ try-runtime = [ "pallet-sudo/try-runtime", "pallet-indices/try-runtime", "pallet-im-online/try-runtime", + "pallet-membership/try-runtime", "pallet-session/try-runtime", "pallet-staking/try-runtime", "pallet-offences/try-runtime", diff --git a/polkadot/runtime/rococo/src/lib.rs b/polkadot/runtime/rococo/src/lib.rs index dd3b664739..08e0fd2692 100644 --- a/polkadot/runtime/rococo/src/lib.rs +++ b/polkadot/runtime/rococo/src/lib.rs @@ -85,14 +85,10 @@ use runtime_parachains::scheduler as parachains_scheduler; pub use pallet_balances::Call as BalancesCall; use polkadot_parachain::primitives::Id as ParaId; -use xcm::v0::{MultiLocation, NetworkId}; + +use xcm::v0::{MultiLocation, NetworkId, BodyId}; use xcm_executor::XcmExecutor; -use xcm_builder::{ - AccountId32Aliases, ChildParachainConvertsVia, SovereignSignedViaLocation, - CurrencyAdapter as XcmCurrencyAdapter, ChildParachainAsNative, - SignedAccountId32AsNative, ChildSystemParachainAsSuperuser, LocationInverter, - IsConcrete, FixedWeightBounds, FixedRateOfConcreteFungible, -}; +use xcm_builder::{AccountId32Aliases, ChildParachainConvertsVia, SovereignSignedViaLocation, CurrencyAdapter as XcmCurrencyAdapter, ChildParachainAsNative, SignedAccountId32AsNative, ChildSystemParachainAsSuperuser, LocationInverter, IsConcrete, FixedWeightBounds, FixedRateOfConcreteFungible, BackingToPlurality, SignedToAccountId32}; use constants::{time::*, currency::*, fee::*}; use frame_support::traits::InstanceFilter; @@ -273,6 +269,10 @@ construct_runtime! { // Validator Manager pallet. ValidatorManager: validator_manager::{Pallet, Call, Storage, Event}, + // A "council" + Collective: pallet_collective::{Pallet, Call, Storage, Origin, Event, Config} = 80, + Membership: pallet_membership::{Pallet, Call, Storage, Event, Config} = 81, + Utility: pallet_utility::{Pallet, Call, Event} = 90, Proxy: pallet_proxy::{Pallet, Call, Storage, Event} = 91, @@ -645,9 +645,17 @@ impl xcm_executor::Config for XcmConfig { type ResponseHandler = (); } +parameter_types! { + pub const CollectiveBodyId: BodyId = BodyId::Unit; +} + /// Type to convert an `Origin` type value into a `MultiLocation` value which represents an interior location /// of this chain. pub type LocalOriginToLocation = ( + // We allow an origin from the Collective pallet to be used in XCM as a corresponding Plurality + BackingToPlurality, CollectiveBodyId>, + // And a usual Signed origin to be used in XCM as a corresponding AccountId32 + SignedToAccountId32, ); impl pallet_xcm::Config for Runtime { @@ -856,6 +864,34 @@ impl pallet_proxy::Config for Runtime { type AnnouncementDepositFactor = AnnouncementDepositFactor; } +parameter_types! { + pub const MotionDuration: BlockNumber = 5; + pub const MaxProposals: u32 = 100; + pub const MaxMembers: u32 = 100; +} + +impl pallet_collective::Config for Runtime { + type Origin = Origin; + type Proposal = Call; + type Event = Event; + type MotionDuration = MotionDuration; + type MaxProposals = MaxProposals; + type MaxMembers = MaxMembers; + type DefaultVote = pallet_collective::PrimeDefaultVote; + type WeightInfo = (); +} + +impl pallet_membership::Config for Runtime { + type Event = Event; + type AddOrigin = EnsureRoot; + type RemoveOrigin = EnsureRoot; + type SwapOrigin = EnsureRoot; + type ResetOrigin = EnsureRoot; + type PrimeOrigin = EnsureRoot; + type MembershipInitialized = Collective; + type MembershipChanged = Collective; +} + #[cfg(not(feature = "disable-runtime-api"))] sp_api::impl_runtime_apis! { impl sp_api::Core for Runtime { diff --git a/polkadot/xcm/xcm-builder/src/lib.rs b/polkadot/xcm/xcm-builder/src/lib.rs index 7620a617af..4dc63aff79 100644 --- a/polkadot/xcm/xcm-builder/src/lib.rs +++ b/polkadot/xcm/xcm-builder/src/lib.rs @@ -31,7 +31,7 @@ mod origin_conversion; pub use origin_conversion::{ SovereignSignedViaLocation, ParentAsSuperuser, ChildSystemParachainAsSuperuser, SiblingSystemParachainAsSuperuser, ChildParachainAsNative, SiblingParachainAsNative, RelayChainAsNative, SignedAccountId32AsNative, - SignedAccountKey20AsNative, EnsureXcmOrigin, SignedToAccountId32 + SignedAccountKey20AsNative, EnsureXcmOrigin, SignedToAccountId32, BackingToPlurality, }; mod barriers;