Skip to content
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

fix collator selection #294

Merged
merged 2 commits into from
Jun 4, 2024
Merged
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
55 changes: 54 additions & 1 deletion polkadot-parachains/integritee-runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -944,6 +944,50 @@ impl pallet_assets::Config<PoolAssetsInstance> for Runtime {
type BenchmarkHelper = ();
}

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

parameter_types! {
pub const Period: u32 = 6 * HOURS;
pub const Offset: u32 = 0;
}
impl pallet_session::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
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 let's be pedantic.
type SessionHandler = <SessionKeys as sp_runtime::traits::OpaqueKeys>::KeyTypeIdProviders;
type Keys = SessionKeys;
type WeightInfo = weights::pallet_session::WeightInfo<Runtime>;
}

parameter_types! {
pub const PotId: PalletId = PalletId(*b"PotStake");
pub const SessionLength: BlockNumber = 6 * HOURS;
}

impl pallet_collator_selection::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type Currency = Balances;
type UpdateOrigin = EnsureRootOrMoreThanHalfCouncil;
type PotId = PotId;
type MaxCandidates = ConstU32<100>;
type MinEligibleCollators = ConstU32<4>;
type MaxInvulnerables = ConstU32<20>;
// 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 = weights::pallet_collator_selection::WeightInfo<Runtime>;
}

construct_runtime!(
pub enum Runtime
{
Expand Down Expand Up @@ -974,6 +1018,9 @@ construct_runtime!(
ChildBounties: pallet_child_bounties = 19,

// Consensus.
Authorship: pallet_authorship = 20,
CollatorSelection: pallet_collator_selection = 21,
Session: pallet_session = 22,
Aura: pallet_aura = 23,
AuraExt: cumulus_pallet_aura_ext = 24,

Expand Down Expand Up @@ -1027,6 +1074,7 @@ pub type BlockId = generic::BlockId<Block>;
/// Migrations to apply on runtime upgrade.
pub type Migrations = (
migrations::scheduler::v4::PurgeV4Agenda<Runtime>,
migrations::collator_selection_init::v0::InitInvulnerables<Runtime>,
cumulus_pallet_xcmp_queue::migration::v4::MigrationToV4<Runtime>,
);

Expand Down Expand Up @@ -1055,13 +1103,15 @@ mod benches {
[pallet_bounties, Bounties]
[pallet_child_bounties, ChildBounties]
[pallet_claims, Claims]
[pallet_collator_selection, CollatorSelection]
[pallet_collective, Council]
[pallet_democracy, Democracy]
[pallet_message_queue, MessageQueue]
[pallet_multisig, Multisig]
[pallet_preimage, Preimage]
[pallet_proxy, Proxy]
[pallet_scheduler, Scheduler]
[pallet_session, SessionBench::<Runtime>]
[pallet_sidechain, Sidechain]
[pallet_teeracle, Teeracle]
[pallet_teerex, Teerex]
Expand Down Expand Up @@ -1247,6 +1297,7 @@ impl_runtime_apis! {
use frame_benchmarking::{Benchmarking, BenchmarkList};
use frame_support::traits::StorageInfoTrait;
use frame_system_benchmarking::Pallet as SystemBench;
use cumulus_pallet_session_benchmarking::Pallet as SessionBench;

let mut list = Vec::<BenchmarkList>::new();
list_benchmarks!(list, extra);
Expand All @@ -1260,8 +1311,10 @@ impl_runtime_apis! {
) -> Result<Vec<frame_benchmarking::BenchmarkBatch>, sp_runtime::RuntimeString> {
use frame_benchmarking::{Benchmarking, BenchmarkBatch, BenchmarkError};
use sp_storage::TrackedStorageKey;

use frame_system_benchmarking::Pallet as SystemBench;
use cumulus_pallet_session_benchmarking::Pallet as SessionBench;
impl cumulus_pallet_session_benchmarking::Config for Runtime {}

impl frame_system_benchmarking::Config for Runtime {
fn setup_set_code_requirements(code: &sp_std::vec::Vec<u8>) -> Result<(), BenchmarkError> {
ParachainSystem::initialize_for_set_code_benchmark(code.len() as u32);
Expand Down
34 changes: 27 additions & 7 deletions polkadot-parachains/src/chain_spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
use cumulus_primitives_core::ParaId;
use integritee_parachains_common::{AccountId, AuraId};
use integritee_runtime::TEER;
use parity_scale_codec::{Decode, Encode};
use sc_chain_spec::{ChainSpecExtension, ChainSpecGroup};
use sc_service::ChainType;
use serde::{Deserialize, Serialize};
Expand Down Expand Up @@ -82,7 +83,7 @@ impl WellKnownKeys {
vec![Alice.to_account_id(), Bob.to_account_id()]
}

fn authorities() -> Vec<AuraId> {
fn authorities() -> Vec<AccountId> {
vec![Dave.public().into(), Eve.public().into()]
}
}
Expand All @@ -93,7 +94,7 @@ impl IntegriteeKeys {
fn root() -> AccountId {
pub_sr25519("2JcYbKMfEGidntYP1LpPWsCMxFvUbjaPyipRViat4Sn5nuqm").into()
}
fn authorities() -> Vec<AuraId> {
fn authorities() -> Vec<AccountId> {
vec![
pub_sr25519("5GZJjbPPD9u6NDgK1ApYmbyGs7EBX4HeEz2y2CD38YJxjvQH").into(),
pub_sr25519("5CcSd1GZus6Jw7rP47LLqMMmtr2KeXCH6W11ZKk1LbCQ9dPY").into(),
Expand All @@ -110,7 +111,7 @@ impl IntegriteeDevKeys {
fn root() -> AccountId {
pub_sr25519("5DMCERPw2yC6LBWNKzswHKLCtuYdtmgKssLJAsPGPVp6fuMY").into()
}
fn authorities() -> Vec<AuraId> {
fn authorities() -> Vec<AccountId> {
vec![
pub_sr25519("5GZJjbPPD9u6NDgK1ApYmbyGs7EBX4HeEz2y2CD38YJxjvQH").into(),
pub_sr25519("5CcSd1GZus6Jw7rP47LLqMMmtr2KeXCH6W11ZKk1LbCQ9dPY").into(),
Expand Down Expand Up @@ -206,12 +207,26 @@ pub fn integritee_chain_spec(
fn integritee_genesis_config(
root_key: AccountId,
endowed_accounts: Vec<AccountId>,
initial_authorities: Vec<AuraId>,
invulnerables: Vec<AccountId>,
parachain_id: ParaId,
) -> serde_json::Value {
serde_json::json!({
"aura": {
"authorities": initial_authorities
"collatorSelection": integritee_runtime::CollatorSelectionConfig {
invulnerables: invulnerables.clone(),
candidacy_bond: 500 * TEER,
..Default::default()
},
"session": integritee_runtime::SessionConfig {
keys: invulnerables
.into_iter()
.map(|acc| {
(
acc.clone(), // account id
acc.clone(), // validator id
integritee_runtime::SessionKeys { aura: Decode::decode(&mut acc.encode().as_ref()).unwrap() }, // session keys
)
})
.collect(),
},
"balances": {
"balances": endowed_accounts.iter().cloned().map(|k| (k, 1_000 * TEER)).collect::<Vec<_>>(),
Expand All @@ -238,12 +253,17 @@ fn integritee_genesis_config(
fn shell_genesis_config(
root_key: AccountId,
endowed_accounts: Vec<AccountId>,
initial_authorities: Vec<AuraId>,
initial_authorities: Vec<AccountId>,
parachain_id: ParaId,
) -> serde_json::Value {
serde_json::json!({
"aura": {
"authorities": initial_authorities
.into_iter()
.map(|acc| {
Decode::decode(&mut acc.encode().as_ref()).unwrap() }, // session keys
)
.collect::<Vec<AuraId>>(),
},
"balances": {
"balances": endowed_accounts.iter().cloned().map(|k| (k, 100 * TEER)).collect::<Vec<_>>(),
Expand Down
Loading