Skip to content

Commit

Permalink
Merge pull request #412 from gregdhill/refactor/kintsugi-collation
Browse files Browse the repository at this point in the history
refactor: revert collator selection & session again but keep authorship
  • Loading branch information
gregdhill authored Dec 10, 2021
2 parents 03251e4 + 8486478 commit 550af50
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 203 deletions.
2 changes: 0 additions & 2 deletions Cargo.lock

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

4 changes: 0 additions & 4 deletions parachain/runtime/kintsugi/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ pallet-society = { git = "https://github.com/paritytech/substrate", branch = "po

# Aura dependencies
pallet-authorship = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.12", default-features = false }
pallet-session = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.12", default-features = false }
pallet-aura = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.12", default-features = false }
sp-consensus-aura = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.12", default-features = false }

Expand All @@ -64,7 +63,6 @@ cumulus-primitives-utility = { git = "https://github.com/paritytech/cumulus", br
cumulus-pallet-dmp-queue = { git = "https://github.com/paritytech/cumulus", branch = "polkadot-v0.9.12", default-features = false }
cumulus-pallet-xcmp-queue = { git = "https://github.com/paritytech/cumulus", branch = "polkadot-v0.9.12", default-features = false }
cumulus-pallet-xcm = { git = "https://github.com/paritytech/cumulus", branch = "polkadot-v0.9.12", default-features = false }
pallet-collator-selection = { git = "https://github.com/paritytech/cumulus", branch = "polkadot-v0.9.12", default-features = false }

# Polkadot dependencies
polkadot-parachain = { git = "https://github.com/paritytech/polkadot", branch = "release-v0.9.12", default-features = false }
Expand Down Expand Up @@ -171,7 +169,6 @@ std = [
"pallet-society/std",

"pallet-authorship/std",
"pallet-session/std",
"pallet-aura/std",
"sp-consensus-aura/std",

Expand All @@ -183,7 +180,6 @@ std = [
"cumulus-primitives-core/std",
"cumulus-primitives-timestamp/std",
"cumulus-primitives-utility/std",
"pallet-collator-selection/std",

"polkadot-parachain/std",
"xcm/std",
Expand Down
66 changes: 16 additions & 50 deletions parachain/runtime/kintsugi/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ use bitcoin::types::H256Le;
use currency::Amount;
use frame_support::{
dispatch::{DispatchError, DispatchResult},
traits::{Contains, Currency as PalletCurrency, EnsureOrigin, ExistenceRequirement, Imbalance, OnUnbalanced},
traits::{
Contains, Currency as PalletCurrency, EnsureOrigin, ExistenceRequirement, FindAuthor, Imbalance, OnUnbalanced,
},
PalletId,
};
use frame_system::{EnsureOneOf, EnsureRoot, RawOrigin};
Expand Down Expand Up @@ -60,7 +62,7 @@ pub use primitives::{
// XCM imports
use cumulus_primitives_core::ParaId;
use orml_xcm_support::{IsNativeConcrete, MultiCurrencyAdapter, MultiNativeAsset};
use pallet_xcm::{EnsureXcm, IsMajorityOfBody, XcmPassthrough};
use pallet_xcm::XcmPassthrough;
use polkadot_parachain::primitives::Sibling;
use sp_runtime::traits::{BlockNumberProvider, Convert};
use xcm::{
Expand Down Expand Up @@ -181,7 +183,6 @@ impl Contains<Call> for BaseCallFilter {
call,
Call::System(_)
| Call::Authorship(_)
| Call::Session(_)
| Call::Timestamp(_)
| Call::ParachainSystem(_)
| Call::Sudo(_)
Expand Down Expand Up @@ -243,59 +244,26 @@ parameter_types! {
}

impl pallet_authorship::Config for Runtime {
type FindAuthor = pallet_session::FindAccountFromAuthorIndex<Self, Aura>;
type FindAuthor = AuraAccountAdapter;
type UncleGenerations = UncleGenerations;
type FilterUncle = ();
type EventHandler = (CollatorSelection,);
type EventHandler = ();
}

parameter_types! {
pub const Period: u32 = 6 * HOURS;
pub const Offset: u32 = 0;
pub const MaxAuthorities: u32 = 32;
}
pub struct AuraAccountAdapter;

impl pallet_session::Config for Runtime {
type Event = Event;
type ValidatorId = <Self as frame_system::Config>::AccountId;
// we don't have stash and controller, thus we don't need the convert as well.
type ValidatorIdOf = pallet_collator_selection::IdentityCollator;
type ShouldEndSession = pallet_session::PeriodicSessions<Period, Offset>;
type NextSessionRotation = pallet_session::PeriodicSessions<Period, Offset>;
type SessionManager = CollatorSelection;
// Essentially just Aura, but lets be pedantic.
type SessionHandler = <SessionKeys as sp_runtime::traits::OpaqueKeys>::KeyTypeIdProviders;
type Keys = SessionKeys;
type WeightInfo = ();
impl FindAuthor<AccountId> for AuraAccountAdapter {
fn find_author<'a, I>(digests: I) -> Option<AccountId>
where
I: 'a + IntoIterator<Item = (sp_runtime::ConsensusEngineId, &'a [u8])>,
{
use sp_std::convert::TryFrom;
pallet_aura::AuraAuthorId::<Runtime>::find_author(digests).and_then(|k| AccountId::try_from(k.as_ref()).ok())
}
}

parameter_types! {
pub const PotId: PalletId = PalletId(*b"PotStake");
pub const MaxCandidates: u32 = 1000;
pub const MinCandidates: u32 = 5;
pub const SessionLength: BlockNumber = 6 * HOURS;
pub const MaxInvulnerables: u32 = 100;
pub const ExecutiveBody: BodyId = BodyId::Executive;
}

/// We allow root and the Relay Chain council to execute privileged collator selection operations.
pub type CollatorSelectionUpdateOrigin =
EnsureOneOf<AccountId, EnsureRoot<AccountId>, EnsureXcm<IsMajorityOfBody<ParentLocation, ExecutiveBody>>>;

impl pallet_collator_selection::Config for Runtime {
type Event = Event;
type Currency = orml_tokens::CurrencyAdapter<Runtime, GetCollateralCurrencyId>;
type UpdateOrigin = CollatorSelectionUpdateOrigin;
type PotId = PotId;
type MaxCandidates = MaxCandidates;
type MinCandidates = MinCandidates;
type MaxInvulnerables = MaxInvulnerables;
// should be a multiple of session or things will get inconsistent
type KickThreshold = Period;
type ValidatorId = <Self as frame_system::Config>::AccountId;
type ValidatorIdOf = pallet_collator_selection::IdentityCollator;
type ValidatorRegistration = Session;
type WeightInfo = ();
pub const MaxAuthorities: u32 = 32;
}

impl pallet_aura::Config for Runtime {
Expand Down Expand Up @@ -1263,8 +1231,6 @@ construct_runtime! {
ParachainInfo: parachain_info::{Pallet, Storage, Config},

Authorship: pallet_authorship::{Pallet, Call, Storage},
CollatorSelection: pallet_collator_selection::{Pallet, Call, Storage, Event<T>, Config<T>},
Session: pallet_session::{Pallet, Call, Storage, Event, Config<T>},
Aura: pallet_aura::{Pallet, Storage, Config<T>},
AuraExt: cumulus_pallet_aura_ext::{Pallet, Storage, Config},

Expand Down
Loading

0 comments on commit 550af50

Please sign in to comment.