diff --git a/polkadot-parachains/integritee-runtime/src/lib.rs b/polkadot-parachains/integritee-runtime/src/lib.rs index fc25e344..7cea2d6e 100644 --- a/polkadot-parachains/integritee-runtime/src/lib.rs +++ b/polkadot-parachains/integritee-runtime/src/lib.rs @@ -944,6 +944,50 @@ impl pallet_assets::Config for Runtime { type BenchmarkHelper = (); } +impl pallet_authorship::Config for Runtime { + type FindAuthor = pallet_session::FindAccountFromAuthorIndex; + 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 = ::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; + type NextSessionRotation = pallet_session::PeriodicSessions; + type SessionManager = CollatorSelection; + // Essentially just Aura, but let's be pedantic. + type SessionHandler = ::KeyTypeIdProviders; + type Keys = SessionKeys; + type WeightInfo = weights::pallet_session::WeightInfo; +} + +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 = ::AccountId; + type ValidatorIdOf = pallet_collator_selection::IdentityCollator; + type ValidatorRegistration = Session; + type WeightInfo = weights::pallet_collator_selection::WeightInfo; +} + construct_runtime!( pub enum Runtime { @@ -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, @@ -1027,6 +1074,7 @@ pub type BlockId = generic::BlockId; /// Migrations to apply on runtime upgrade. pub type Migrations = ( migrations::scheduler::v4::PurgeV4Agenda, + migrations::collator_selection_init::v0::InitInvulnerables, cumulus_pallet_xcmp_queue::migration::v4::MigrationToV4, ); @@ -1055,6 +1103,7 @@ 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] @@ -1062,6 +1111,7 @@ mod benches { [pallet_preimage, Preimage] [pallet_proxy, Proxy] [pallet_scheduler, Scheduler] + [pallet_session, SessionBench::] [pallet_sidechain, Sidechain] [pallet_teeracle, Teeracle] [pallet_teerex, Teerex] @@ -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::::new(); list_benchmarks!(list, extra); @@ -1260,8 +1311,10 @@ impl_runtime_apis! { ) -> Result, 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) -> Result<(), BenchmarkError> { ParachainSystem::initialize_for_set_code_benchmark(code.len() as u32); diff --git a/polkadot-parachains/src/chain_spec.rs b/polkadot-parachains/src/chain_spec.rs index 5f309c21..2c326023 100644 --- a/polkadot-parachains/src/chain_spec.rs +++ b/polkadot-parachains/src/chain_spec.rs @@ -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}; @@ -82,7 +83,7 @@ impl WellKnownKeys { vec![Alice.to_account_id(), Bob.to_account_id()] } - fn authorities() -> Vec { + fn authorities() -> Vec { vec![Dave.public().into(), Eve.public().into()] } } @@ -93,7 +94,7 @@ impl IntegriteeKeys { fn root() -> AccountId { pub_sr25519("2JcYbKMfEGidntYP1LpPWsCMxFvUbjaPyipRViat4Sn5nuqm").into() } - fn authorities() -> Vec { + fn authorities() -> Vec { vec![ pub_sr25519("5GZJjbPPD9u6NDgK1ApYmbyGs7EBX4HeEz2y2CD38YJxjvQH").into(), pub_sr25519("5CcSd1GZus6Jw7rP47LLqMMmtr2KeXCH6W11ZKk1LbCQ9dPY").into(), @@ -110,7 +111,7 @@ impl IntegriteeDevKeys { fn root() -> AccountId { pub_sr25519("5DMCERPw2yC6LBWNKzswHKLCtuYdtmgKssLJAsPGPVp6fuMY").into() } - fn authorities() -> Vec { + fn authorities() -> Vec { vec![ pub_sr25519("5GZJjbPPD9u6NDgK1ApYmbyGs7EBX4HeEz2y2CD38YJxjvQH").into(), pub_sr25519("5CcSd1GZus6Jw7rP47LLqMMmtr2KeXCH6W11ZKk1LbCQ9dPY").into(), @@ -206,12 +207,26 @@ pub fn integritee_chain_spec( fn integritee_genesis_config( root_key: AccountId, endowed_accounts: Vec, - initial_authorities: Vec, + invulnerables: Vec, 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::>(), @@ -238,12 +253,17 @@ fn integritee_genesis_config( fn shell_genesis_config( root_key: AccountId, endowed_accounts: Vec, - initial_authorities: Vec, + initial_authorities: Vec, 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::>(), }, "balances": { "balances": endowed_accounts.iter().cloned().map(|k| (k, 100 * TEER)).collect::>(),