Skip to content

Commit

Permalink
Replace free for all collation in cumulus runtimes (#1251)
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
georgepisaltu authored Sep 18, 2023
1 parent e6f5e23 commit a181ced
Show file tree
Hide file tree
Showing 12 changed files with 378 additions and 43 deletions.
14 changes: 14 additions & 0 deletions Cargo.lock

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

16 changes: 16 additions & 0 deletions cumulus/parachains/runtimes/glutton/glutton-kusama/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,13 @@ frame-system = { path = "../../../../../substrate/frame/system", default-feature
frame-system-rpc-runtime-api = { path = "../../../../../substrate/frame/system/rpc/runtime-api", default-features = false}
frame-system-benchmarking = { path = "../../../../../substrate/frame/system/benchmarking", default-features = false, optional = true}
frame-try-runtime = { path = "../../../../../substrate/frame/try-runtime", default-features = false, optional = true}
pallet-aura = { path = "../../../../../substrate/frame/aura", default-features = false}
pallet-glutton = { path = "../../../../../substrate/frame/glutton", default-features = false, optional = true}
pallet-sudo = { path = "../../../../../substrate/frame/sudo", default-features = false, optional = true}
pallet-timestamp = { path = "../../../../../substrate/frame/timestamp", default-features = false }
sp-api = { path = "../../../../../substrate/primitives/api", default-features = false}
sp-block-builder = { path = "../../../../../substrate/primitives/block-builder", default-features = false}
sp-consensus-aura = { path = "../../../../../substrate/primitives/consensus/aura", default-features = false }
sp-core = { path = "../../../../../substrate/primitives/core", default-features = false}
sp-inherents = { path = "../../../../../substrate/primitives/inherents", default-features = false}
sp-offchain = { path = "../../../../../substrate/primitives/offchain", default-features = false}
Expand All @@ -36,9 +39,11 @@ xcm-builder = { package = "staging-xcm-builder", path = "../../../../../polkadot
xcm-executor = { package = "staging-xcm-executor", path = "../../../../../polkadot/xcm/xcm-executor", default-features = false}

# Cumulus
cumulus-pallet-aura-ext = { path = "../../../../pallets/aura-ext", default-features = false }
cumulus-pallet-parachain-system = { path = "../../../../pallets/parachain-system", default-features = false, features = ["parameterized-consensus-hook",] }
cumulus-pallet-xcm = { path = "../../../../pallets/xcm", default-features = false }
cumulus-primitives-core = { path = "../../../../primitives/core", default-features = false }
cumulus-primitives-timestamp = { path = "../../../../primitives/timestamp", default-features = false }
parachain-info = { path = "../../../pallets/parachain-info", default-features = false }
parachains-common = { path = "../../../common", default-features = false }

Expand All @@ -55,30 +60,36 @@ runtime-benchmarks = [
"frame-system/runtime-benchmarks",
"pallet-glutton/runtime-benchmarks",
"pallet-sudo?/runtime-benchmarks",
"pallet-timestamp/runtime-benchmarks",
"parachains-common/runtime-benchmarks",
"sp-runtime/runtime-benchmarks",
"xcm-builder/runtime-benchmarks",
"xcm-executor/runtime-benchmarks",
]
std = [
"codec/std",
"cumulus-pallet-aura-ext/std",
"cumulus-pallet-parachain-system/std",
"cumulus-pallet-xcm/std",
"cumulus-primitives-core/std",
"cumulus-primitives-timestamp/std",
"frame-benchmarking?/std",
"frame-executive/std",
"frame-support/std",
"frame-system-benchmarking?/std",
"frame-system-rpc-runtime-api/std",
"frame-system/std",
"frame-try-runtime?/std",
"pallet-aura/std",
"pallet-glutton/std",
"pallet-sudo/std",
"pallet-timestamp/std",
"parachain-info/std",
"parachains-common/std",
"scale-info/std",
"sp-api/std",
"sp-block-builder/std",
"sp-consensus-aura/std",
"sp-core/std",
"sp-inherents/std",
"sp-offchain/std",
Expand All @@ -93,14 +104,19 @@ std = [
"xcm/std",
]
try-runtime = [
"cumulus-pallet-aura-ext/try-runtime",
"cumulus-pallet-parachain-system/try-runtime",
"cumulus-pallet-xcm/try-runtime",
"frame-executive/try-runtime",
"frame-support/try-runtime",
"frame-system/try-runtime",
"frame-try-runtime/try-runtime",
"pallet-aura/try-runtime",
"pallet-glutton/try-runtime",
"pallet-sudo/try-runtime",
"pallet-timestamp/try-runtime",
"parachain-info/try-runtime",
"sp-runtime/try-runtime",
]

experimental = [ "pallet-aura/experimental" ]
80 changes: 67 additions & 13 deletions cumulus/parachains/runtimes/glutton/glutton-kusama/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,12 @@ include!(concat!(env!("OUT_DIR"), "/wasm_binary.rs"));
pub mod weights;
pub mod xcm_config;

use cumulus_pallet_parachain_system::RelayNumberStrictlyIncreases;
use cumulus_pallet_parachain_system::RelayNumberMonotonicallyIncreases;
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},
transaction_validity::{TransactionSource, TransactionValidity},
ApplyExtrinsicResult,
Expand All @@ -64,24 +65,37 @@ pub use frame_support::{
construct_runtime,
dispatch::DispatchClass,
parameter_types,
traits::{Everything, IsInVec, Randomness},
traits::{
ConstBool, ConstU32, ConstU64, ConstU8, EitherOfDiverse, Everything, IsInVec, Randomness,
},
weights::{
constants::{
BlockExecutionWeight, ExtrinsicBaseWeight, RocksDbWeight, WEIGHT_REF_TIME_PER_SECOND,
},
IdentityFee, Weight,
},
StorageValue,
PalletId, StorageValue,
};
use frame_system::{
limits::{BlockLength, BlockWeights},
EnsureRoot,
};
use parachains_common::{AccountId, Signature};
use parachains_common::{
kusama::consensus::{
BLOCK_PROCESSING_VELOCITY, RELAY_CHAIN_SLOT_DURATION_MILLIS, UNINCLUDED_SEGMENT_CAPACITY,
},
AccountId, Signature, SLOT_DURATION,
};
#[cfg(any(feature = "std", test))]
pub use sp_runtime::BuildStorage;
pub use sp_runtime::{Perbill, Permill};

impl_opaque_keys! {
pub struct SessionKeys {
pub aura: Aura,
}
}

#[sp_version::runtime_version]
pub const VERSION: RuntimeVersion = RuntimeVersion {
spec_name: create_runtime_str!("glutton"),
Expand Down Expand Up @@ -178,12 +192,35 @@ 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_timestamp::Config for Runtime {
type Moment = u64;
type OnTimestampSet = Aura;
type MinimumPeriod = ConstU64<{ SLOT_DURATION / 2 }>;
type WeightInfo = weights::pallet_timestamp::WeightInfo<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_glutton::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type WeightInfo = weights::pallet_glutton::WeightInfo<Runtime>;
Expand All @@ -204,13 +241,18 @@ construct_runtime! {
Pallet, Call, Config<T>, Storage, Inherent, Event<T>, ValidateUnsigned,
} = 1,
ParachainInfo: parachain_info::{Pallet, Storage, Config<T>} = 2,
Timestamp: pallet_timestamp::{Pallet, Call, Storage, Inherent} = 3,

// DMP handler.
CumulusXcm: cumulus_pallet_xcm::{Pallet, Call, Storage, Event<T>, Origin} = 10,

// The main stage.
Glutton: pallet_glutton::{Pallet, Call, Storage, Event, Config<T>} = 20,

// Collator support
Aura: pallet_aura::{Pallet, Storage, Config<T>} = 30,
AuraExt: cumulus_pallet_aura_ext::{Pallet, Storage, Config<T>} = 31,

// Sudo.
Sudo: pallet_sudo::{Pallet, Call, Storage, Event<T>, Config<T>} = 255,
}
Expand Down Expand Up @@ -295,6 +337,16 @@ 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_block_builder::BlockBuilder<Block> for Runtime {
fn apply_extrinsic(
extrinsic: <Block as BlockT>::Extrinsic,
Expand Down Expand Up @@ -332,12 +384,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)
}
}

Expand Down Expand Up @@ -402,5 +456,5 @@ impl_runtime_apis! {

cumulus_pallet_parachain_system::register_validate_block! {
Runtime = Runtime,
BlockExecutor = Executive,
BlockExecutor = cumulus_pallet_aura_ext::BlockExecutor::<Runtime, Executive>,
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@
// along with Cumulus. If not, see <http://www.gnu.org/licenses/>.

pub mod pallet_glutton;
pub mod pallet_timestamp;
Loading

0 comments on commit a181ced

Please sign in to comment.