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

Introduce Fellowship into Collectives #2186

Merged
merged 26 commits into from
Mar 21, 2023
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
29a3125
Fellowship into Collectives
muharem Feb 15, 2023
11bad7b
Merge remote-tracking branch 'origin/master' into muharem-collectives…
muharem Feb 15, 2023
2d6f124
cargo.lock
muharem Feb 15, 2023
2ccb3d7
tracks alias
muharem Feb 15, 2023
a1332a9
allow to send Fellows origin over XCM
muharem Feb 15, 2023
63d799c
update todos, remove duplication of type
muharem Feb 15, 2023
916997a
use Collectives location for Fellows body
muharem Feb 15, 2023
7b772d2
alias for ranks constants
muharem Feb 16, 2023
97f6629
benchmarks
muharem Feb 16, 2023
1f9cfdd
proxy for Fellowship
muharem Feb 16, 2023
34a7bd3
docs
muharem Feb 16, 2023
6ece4f3
correct copyright date
muharem Feb 20, 2023
7213d57
Apply suggestions from code review
muharem Feb 25, 2023
ea0abd1
Merge remote-tracking branch 'origin/master' into muharem-collectives…
muharem Feb 25, 2023
0b82eaf
rustfmt
muharem Feb 25, 2023
03f5c87
remove council, update origins
muharem Feb 25, 2023
73a2f36
renames
muharem Feb 25, 2023
58c986e
remove tech committee from promote origin
muharem Feb 25, 2023
c0fe803
renames
muharem Feb 26, 2023
8127b8f
doc nits
joepetrowski Mar 6, 2023
9499e4f
Merge remote-tracking branch 'origin/master' into muharem-collectives…
muharem Mar 6, 2023
45a5976
weights with new api
muharem Mar 6, 2023
ed4b336
sane weights for pallet_scheduler
muharem Mar 10, 2023
63796bd
XCM tweaks for OpenGov (#2305)
muharem Mar 12, 2023
b860a02
Merge remote-tracking branch 'origin/master' into muharem-collectives…
muharem Mar 21, 2023
930bca8
remove match arm duplication
muharem Mar 21, 2023
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
5 changes: 5 additions & 0 deletions Cargo.lock

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

27 changes: 21 additions & 6 deletions parachains/runtimes/assets/statemint/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,13 +93,13 @@ use parachains_common::{
Signature, StatemintAuraId as AuraId, AVERAGE_ON_INITIALIZE_RATIO, HOURS, MAXIMUM_BLOCK_WEIGHT,
NORMAL_DISPATCH_RATIO, SLOT_DURATION,
};
use xcm_config::{DotLocation, XcmConfig, XcmOriginToTransactDispatchOrigin};
use xcm_config::{CollectivesLocation, DotLocation, XcmConfig, XcmOriginToTransactDispatchOrigin};

#[cfg(any(feature = "std", test))]
pub use sp_runtime::BuildStorage;

// Polkadot imports
use pallet_xcm::{EnsureXcm, IsMajorityOfBody};
use pallet_xcm::{EnsureXcm, IsMajorityOfBody, IsVoiceOfBody};
use polkadot_runtime_common::{BlockHashCount, SlowAdjustingFeeUpdate};
use xcm::latest::BodyId;
use xcm_executor::XcmExecutor;
Expand Down Expand Up @@ -470,6 +470,11 @@ impl parachain_info::Config for Runtime {}

impl cumulus_pallet_aura_ext::Config for Runtime {}

parameter_types! {
// Fellows pluralistic body.
pub const FellowsBodyId: BodyId = BodyId::Technical;
}

impl cumulus_pallet_xcmp_queue::Config for Runtime {
type WeightInfo = weights::cumulus_pallet_xcmp_queue::WeightInfo<Runtime>;
type RuntimeEvent = RuntimeEvent;
Expand All @@ -479,7 +484,10 @@ impl cumulus_pallet_xcmp_queue::Config for Runtime {
type ExecuteOverweightOrigin = EnsureRoot<AccountId>;
type ControllerOrigin = EitherOfDiverse<
EnsureRoot<AccountId>,
EnsureXcm<IsMajorityOfBody<DotLocation, ExecutiveBody>>,
EnsureXcm<(
IsMajorityOfBody<DotLocation, ExecutiveBody>,
muharem marked this conversation as resolved.
Show resolved Hide resolved
IsVoiceOfBody<CollectivesLocation, FellowsBodyId>,
)>,
>;
type ControllerOriginConverter = XcmOriginToTransactDispatchOrigin;
type PriceForSiblingDelivery = ();
Expand Down Expand Up @@ -522,11 +530,18 @@ parameter_types! {
pub const MinCandidates: u32 = 5;
pub const SessionLength: BlockNumber = 6 * HOURS;
pub const MaxInvulnerables: u32 = 100;
// StakingAdmin pluralistic body.
joepetrowski marked this conversation as resolved.
Show resolved Hide resolved
pub const StakingAdminBodyId: BodyId = BodyId::Defense;
}

/// We allow root and the Relay Chain council to execute privileged collator selection operations.
pub type CollatorSelectionUpdateOrigin =
EitherOfDiverse<EnsureRoot<AccountId>, EnsureXcm<IsMajorityOfBody<DotLocation, ExecutiveBody>>>;
/// We allow root, the Relay Chain council and the StakingAdmin to execute privileged collator selection operations.
pub type CollatorSelectionUpdateOrigin = EitherOfDiverse<
EnsureRoot<AccountId>,
EnsureXcm<(
IsMajorityOfBody<DotLocation, ExecutiveBody>,
muharem marked this conversation as resolved.
Show resolved Hide resolved
IsVoiceOfBody<DotLocation, StakingAdminBodyId>,
)>,
>;

impl pallet_collator_selection::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
Expand Down
1 change: 1 addition & 0 deletions parachains/runtimes/assets/statemint/src/xcm_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ parameter_types! {
pub TrustBackedAssetsPalletLocation: MultiLocation =
PalletInstance(<Assets as PalletInfoAccess>::index() as u8).into();
pub CheckingAccount: AccountId = PolkadotXcm::check_account();
pub CollectivesLocation: MultiLocation = MultiLocation::new(1, Parachain(1001));
}

/// Type for specifying how a `MultiLocation` can be converted into an `AccountId`. This is used
Expand Down
17 changes: 17 additions & 0 deletions parachains/runtimes/collectives/collectives-polkadot/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,18 @@ pallet-authorship = { git = "https://github.com/paritytech/substrate", default-f
pallet-balances = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "master" }
pallet-collective = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "master" }
pallet-multisig = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "master" }
pallet-preimage = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }
pallet-proxy = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "master" }
pallet-scheduler = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }
pallet-session = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "master" }
pallet-timestamp = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "master" }
pallet-transaction-payment = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "master" }
pallet-transaction-payment-rpc-runtime-api = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "master" }
pallet-utility = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "master" }
pallet-referenda = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "master" }
pallet-ranked-collective = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "master" }
sp-api = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "master" }
sp-arithmetic = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "master" }
sp-block-builder = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "master" }
sp-consensus-aura = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "master" }
sp-core = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "master" }
Expand Down Expand Up @@ -95,6 +100,10 @@ runtime-benchmarks = [
"cumulus-pallet-session-benchmarking/runtime-benchmarks",
"pallet-collator-selection/runtime-benchmarks",
"cumulus-pallet-xcmp-queue/runtime-benchmarks",
"pallet-scheduler/runtime-benchmarks",
"pallet-preimage/runtime-benchmarks",
"pallet-referenda/runtime-benchmarks",
"pallet-ranked-collective/runtime-benchmarks",
]
try-runtime = [
"cumulus-pallet-aura-ext/try-runtime",
Expand All @@ -119,6 +128,10 @@ try-runtime = [
"pallet-utility/try-runtime",
"pallet-xcm/try-runtime",
"parachain-info/try-runtime",
"pallet-scheduler/try-runtime",
"pallet-preimage/try-runtime",
"pallet-referenda/try-runtime",
"pallet-ranked-collective/try-runtime",
]
std = [
"codec/std",
Expand Down Expand Up @@ -170,4 +183,8 @@ std = [
"pallet-collator-selection/std",
"parachain-info/std",
"parachains-common/std",
"pallet-scheduler/std",
"pallet-preimage/std",
"pallet-referenda/std",
"pallet-ranked-collective/std",
]
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,17 @@

pub mod account {
use frame_support::PalletId;
use sp_runtime::AccountId32;

/// Relay Chain treasury pallet id, used to convert into AccountId
pub const RELAY_TREASURY_PALL_ID: PalletId = PalletId(*b"py/trsry");
muharem marked this conversation as resolved.
Show resolved Hide resolved
/// account used to temporarily deposit slashed imbalance before teleporting
pub const SLASHED_IMBALANCE_ACC_ID: AccountId32 = AccountId32::new([7u8; 32]);
/// Alliance pallet id.
/// It is used as a temporarily place to deposit a slashed imbalance
/// before the teleport to the treasury.
pub const ALLIANCE_PALLET_ID: PalletId = PalletId(*b"py/allia");
/// Referenda pallet id.
/// It is used as a temporarily place to deposit a slashed imbalance
/// before the teleport to the treasury.
joepetrowski marked this conversation as resolved.
Show resolved Hide resolved
pub const REFERENDA_PALLET_ID: PalletId = PalletId(*b"py/refer");
}

pub mod currency {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
// Copyright 2023 Parity Technologies (UK) Ltd.
// This file is part of Cumulus.

// Cumulus is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.

// Cumulus is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License
// along with Cumulus. If not, see <http://www.gnu.org/licenses/>.

//! The Polkadot Fellowship.
muharem marked this conversation as resolved.
Show resolved Hide resolved

mod origins;
mod tracks;
pub use origins::{
pallet_origins as pallet_fellowship_origins, Fellows, FellowshipExperts, FellowshipInitiates,
FellowshipMasters,
};

use crate::{
constants, impls::ToParentTreasury, weights, AccountId, Balance, Balances, BlockNumber,
DotLocation, FellowshipReferenda, Preimage, Runtime, RuntimeCall, RuntimeEvent, Scheduler,
DAYS,
};
use frame_support::{
parameter_types,
traits::{EitherOf, MapSuccess, TryMapSuccess},
};
use pallet_xcm::{EnsureXcm, IsMajorityOfBody, IsVoiceOfBody};
use polkadot_runtime_constants::xcm::body::FELLOWSHIP_ADMIN_INDEX;
use sp_arithmetic::traits::CheckedSub;
use sp_core::ConstU32;
use sp_runtime::{
morph_types,
traits::{AccountIdConversion, ConstU16, Replace, TypedGet},
};
use xcm::latest::BodyId;

use self::origins::EnsureFellowship;

/// The Fellowship members' ranks.
pub mod ranks {
use pallet_ranked_collective::Rank;

pub const INITIATES: Rank = 0;
muharem marked this conversation as resolved.
Show resolved Hide resolved
pub const DAN_1: Rank = 1;
pub const DAN_2: Rank = 2;
pub const DAN_3: Rank = 3; // aka Fellows.
pub const DAN_4: Rank = 4;
pub const DAN_5: Rank = 5; // aka Experts.
pub const DAN_6: Rank = 6;
pub const DAN_7: Rank = 7; // aka Masters.
pub const DAN_8: Rank = 8;
pub const DAN_9: Rank = 9;
}

parameter_types! {
pub const AlarmInterval: BlockNumber = 1;
pub const SubmissionDeposit: Balance = 0;
pub const UndecidingTimeout: BlockNumber = 7 * DAYS;
pub const TechnicalCommittee: BodyId = BodyId::Technical;
// Referenda pallet account, used to temporarily deposit slashed imbalance before teleporting.
pub ReferendaPalletAccId: AccountId = constants::account::REFERENDA_PALLET_ID.into_account_truncating();
pub RelayTreasuryAccId: AccountId = constants::account::RELAY_TREASURY_PALL_ID.into_account_truncating();
muharem marked this conversation as resolved.
Show resolved Hide resolved
pub const FellowshipAdminBodyId: BodyId = BodyId::Index(FELLOWSHIP_ADMIN_INDEX);
}

impl pallet_fellowship_origins::Config for Runtime {}

pub type FellowshipReferendaInstance = pallet_referenda::Instance1;

impl pallet_referenda::Config<FellowshipReferendaInstance> for Runtime {
type WeightInfo = weights::pallet_referenda::WeightInfo<Runtime>;
type RuntimeCall = RuntimeCall;
type RuntimeEvent = RuntimeEvent;
type Scheduler = Scheduler;
type Currency = Balances;
type SubmitOrigin =
pallet_ranked_collective::EnsureMember<Runtime, FellowshipCollectiveInstance, 1>;
type CancelOrigin = FellowshipExperts;
type KillOrigin = FellowshipMasters;
type Slash = ToParentTreasury<RelayTreasuryAccId, ReferendaPalletAccId, Runtime>;
muharem marked this conversation as resolved.
Show resolved Hide resolved
type Votes = pallet_ranked_collective::Votes;
type Tally = pallet_ranked_collective::TallyOf<Runtime, FellowshipCollectiveInstance>;
type SubmissionDeposit = SubmissionDeposit;
type MaxQueued = ConstU32<100>;
type UndecidingTimeout = UndecidingTimeout;
type AlarmInterval = AlarmInterval;
type Tracks = tracks::TracksInfo;
type Preimages = Preimage;
}

pub type FellowshipCollectiveInstance = pallet_ranked_collective::Instance1;

morph_types! {
/// A `TryMorph` implementation to reduce a scalar by a particular amount, checking for
/// underflow.
pub type CheckedReduceBy<N: TypedGet>: TryMorph = |r: N::Type| -> Result<N::Type, ()> {
r.checked_sub(&N::get()).ok_or(())
} where N::Type: CheckedSub;
}

// IsMajorityOfBody<KsmLocation, ExecutiveBody>,

impl pallet_ranked_collective::Config<FellowshipCollectiveInstance> for Runtime {
type WeightInfo = weights::pallet_ranked_collective::WeightInfo<Runtime>;
type RuntimeEvent = RuntimeEvent;
// Promotion is by any of:
// - Root can demote arbitrarily.
// - the FellowshipAdmin origin (i.e. token holder referendum);
// - a vote by the rank *above* the new rank.
muharem marked this conversation as resolved.
Show resolved Hide resolved
type PromoteOrigin = EitherOf<
EitherOf<
frame_system::EnsureRootWithSuccess<Self::AccountId, ConstU16<65535>>,
MapSuccess<
EnsureXcm<IsMajorityOfBody<DotLocation, TechnicalCommittee>>,
muharem marked this conversation as resolved.
Show resolved Hide resolved
Replace<ConstU16<6>>,
>,
>,
EitherOf<
MapSuccess<
EnsureXcm<IsVoiceOfBody<DotLocation, FellowshipAdminBodyId>>,
muharem marked this conversation as resolved.
Show resolved Hide resolved
Replace<ConstU16<9>>,
>,
TryMapSuccess<EnsureFellowship, CheckedReduceBy<ConstU16<1>>>,
>,
>;
// Demotion is by any of:
// - Root can demote arbitrarily.
// - the FellowshipAdmin origin (i.e. token holder referendum);
// - a vote by the rank two above the current rank.
type DemoteOrigin = EitherOf<
frame_system::EnsureRootWithSuccess<Self::AccountId, ConstU16<65535>>,
EitherOf<
MapSuccess<
EnsureXcm<IsVoiceOfBody<DotLocation, FellowshipAdminBodyId>>,
muharem marked this conversation as resolved.
Show resolved Hide resolved
Replace<ConstU16<9>>,
>,
TryMapSuccess<EnsureFellowship, CheckedReduceBy<ConstU16<2>>>,
>,
>;
type Polls = FellowshipReferenda;
type MinRankOfClass = sp_runtime::traits::Identity;
type VoteWeight = pallet_ranked_collective::Geometric;
}
Loading