Replace free for all collation in cumulus runtimes (#1251)

Partially fixes #103 

This PR removes instances of "free for all" collation in the `glutton`,
`shell`, and `seedling` runtimes and replaces them with Aura instances.
Aura is configured without a session manager, so the initial authority
set cannot be changed later on.

---------

Signed-off-by: georgepisaltu <george.pisaltu@parity.io>
This commit is contained in:
georgepisaltu
2023-09-18 18:17:14 +03:00
committed by GitHub
parent e6f5e23b0f
commit a181ced46b
12 changed files with 378 additions and 43 deletions
@@ -32,13 +32,14 @@ include!(concat!(env!("OUT_DIR"), "/wasm_binary.rs"));
pub mod xcm_config;
use codec::{Decode, Encode};
use cumulus_pallet_parachain_system::RelayNumberStrictlyIncreases;
use cumulus_pallet_parachain_system::RelayNumberMonotonicallyIncreases;
use frame_support::unsigned::TransactionValidityError;
use scale_info::TypeInfo;
use sp_api::impl_runtime_apis;
use sp_core::OpaqueMetadata;
pub use sp_consensus_aura::sr25519::AuthorityId as AuraId;
use sp_core::{crypto::KeyTypeId, OpaqueMetadata};
use sp_runtime::{
create_runtime_str, generic,
create_runtime_str, generic, impl_opaque_keys,
traits::{AccountIdLookup, BlakeTwo256, Block as BlockT, DispatchInfoOf},
transaction_validity::{TransactionSource, TransactionValidity},
ApplyExtrinsicResult,
@@ -53,7 +54,7 @@ pub use frame_support::{
construct_runtime,
dispatch::DispatchClass,
parameter_types,
traits::{Everything, IsInVec, Randomness},
traits::{ConstBool, ConstU32, ConstU64, ConstU8, EitherOfDiverse, IsInVec, Randomness},
weights::{
constants::{
BlockExecutionWeight, ExtrinsicBaseWeight, RocksDbWeight, WEIGHT_REF_TIME_PER_SECOND,
@@ -68,6 +69,12 @@ use parachains_common::{AccountId, Signature};
pub use sp_runtime::BuildStorage;
pub use sp_runtime::{Perbill, Permill};
impl_opaque_keys! {
pub struct SessionKeys {
pub aura: Aura,
}
}
/// This runtime version.
#[sp_version::runtime_version]
pub const VERSION: RuntimeVersion = RuntimeVersion {
@@ -87,6 +94,15 @@ pub fn native_version() -> NativeVersion {
NativeVersion { runtime_version: VERSION, can_author_with: Default::default() }
}
/// Maximum number of blocks simultaneously accepted by the Runtime, not yet included
/// into the relay chain.
const UNINCLUDED_SEGMENT_CAPACITY: u32 = 1;
/// How many parachain blocks are processed by the relay chain per parent. Limits the
/// number of blocks authored per slot.
const BLOCK_PROCESSING_VELOCITY: u32 = 1;
/// Relay chain slot duration, in milliseconds.
const RELAY_CHAIN_SLOT_DURATION_MILLIS: u32 = 6000;
/// We assume that ~10% of the block weight is consumed by `on_initialize` handlers.
/// This is used to limit the maximal weight of a single extrinsic.
const AVERAGE_ON_INITIALIZE_RATIO: Perbill = Perbill::from_percent(10);
@@ -177,16 +193,41 @@ impl cumulus_pallet_parachain_system::Config for Runtime {
type ReservedDmpWeight = ReservedDmpWeight;
type XcmpMessageHandler = ();
type ReservedXcmpWeight = ();
type CheckAssociatedRelayNumber = RelayNumberStrictlyIncreases;
type ConsensusHook = cumulus_pallet_parachain_system::consensus_hook::ExpectParentIncluded;
type CheckAssociatedRelayNumber = RelayNumberMonotonicallyIncreases;
type ConsensusHook = cumulus_pallet_aura_ext::FixedVelocityConsensusHook<
Runtime,
RELAY_CHAIN_SLOT_DURATION_MILLIS,
BLOCK_PROCESSING_VELOCITY,
UNINCLUDED_SEGMENT_CAPACITY,
>;
}
impl parachain_info::Config for Runtime {}
impl cumulus_pallet_aura_ext::Config for Runtime {}
impl pallet_aura::Config for Runtime {
type AuthorityId = AuraId;
type DisabledValidators = ();
type MaxAuthorities = ConstU32<100_000>;
type AllowMultipleBlocksPerSlot = ConstBool<false>;
#[cfg(feature = "experimental")]
type SlotDuration = pallet_aura::MinimumPeriodTimesTwo<Self>;
}
impl pallet_timestamp::Config for Runtime {
type Moment = u64;
type OnTimestampSet = Aura;
type MinimumPeriod = ConstU64<0>;
type WeightInfo = ();
}
construct_runtime! {
pub enum Runtime
{
System: frame_system::{Pallet, Call, Storage, Config<T>, Event<T>},
Timestamp: pallet_timestamp::{Pallet, Call, Storage, Inherent},
ParachainSystem: cumulus_pallet_parachain_system::{
Pallet, Call, Config<T>, Storage, Inherent, Event<T>, ValidateUnsigned,
},
@@ -194,6 +235,9 @@ construct_runtime! {
// DMP handler.
CumulusXcm: cumulus_pallet_xcm::{Pallet, Call, Storage, Event<T>, Origin},
Aura: pallet_aura::{Pallet, Storage, Config<T>},
AuraExt: cumulus_pallet_aura_ext::{Pallet, Storage, Config<T>},
}
}
@@ -263,6 +307,16 @@ pub type Executive = frame_executive::Executive<
>;
impl_runtime_apis! {
impl sp_consensus_aura::AuraApi<Block, AuraId> for Runtime {
fn slot_duration() -> sp_consensus_aura::SlotDuration {
sp_consensus_aura::SlotDuration::from_millis(Aura::slot_duration())
}
fn authorities() -> Vec<AuraId> {
Aura::authorities().into_inner()
}
}
impl sp_api::Core<Block> for Runtime {
fn version() -> RuntimeVersion {
VERSION
@@ -328,12 +382,14 @@ impl_runtime_apis! {
}
impl sp_session::SessionKeys<Block> for Runtime {
fn decode_session_keys(_: Vec<u8>) -> Option<Vec<(Vec<u8>, sp_core::crypto::KeyTypeId)>> {
Some(Vec::new())
fn generate_session_keys(seed: Option<Vec<u8>>) -> Vec<u8> {
SessionKeys::generate(seed)
}
fn generate_session_keys(_: Option<Vec<u8>>) -> Vec<u8> {
Vec::new()
fn decode_session_keys(
encoded: Vec<u8>,
) -> Option<Vec<(Vec<u8>, KeyTypeId)>> {
SessionKeys::decode_into_raw_public_keys(&encoded)
}
}
@@ -346,5 +402,5 @@ impl_runtime_apis! {
cumulus_pallet_parachain_system::register_validate_block! {
Runtime = Runtime,
BlockExecutor = Executive,
BlockExecutor = cumulus_pallet_aura_ext::BlockExecutor::<Runtime, Executive>,
}