// Copyright (C) Parity Technologies (UK) Ltd.
// This file is part of Polkadot.
// Polkadot is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// Polkadot is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with Polkadot. If not, see .
//! The Polkadot multiplexing assignment provider.
//! Provides blockspace assignments for both bulk and on demand parachains.
use frame_system::pallet_prelude::BlockNumberFor;
use primitives::{CoreIndex, Id as ParaId};
use crate::{
configuration, paras,
scheduler::common::{Assignment, AssignmentProvider, AssignmentProviderConfig},
};
pub use pallet::*;
#[frame_support::pallet]
pub mod pallet {
use super::*;
#[pallet::pallet]
#[pallet::without_storage_info]
pub struct Pallet(_);
#[pallet::config]
pub trait Config: frame_system::Config + configuration::Config + paras::Config {
type ParachainsAssignmentProvider: AssignmentProvider>;
type OnDemandAssignmentProvider: AssignmentProvider>;
}
}
// Aliases to make the impl more readable.
type ParachainAssigner = ::ParachainsAssignmentProvider;
type OnDemandAssigner = ::OnDemandAssignmentProvider;
impl Pallet {
// Helper fn for the AssignmentProvider implementation.
// Assumes that the first allocation of cores is to bulk parachains.
// This function will return false if there are no cores assigned to the bulk parachain
// assigner.
fn is_bulk_core(core_idx: &CoreIndex) -> bool {
let parachain_cores =
as AssignmentProvider>>::session_core_count();
(0..parachain_cores).contains(&core_idx.0)
}
}
impl AssignmentProvider> for Pallet {
fn session_core_count() -> u32 {
let parachain_cores =
as AssignmentProvider>>::session_core_count();
let on_demand_cores =
as AssignmentProvider>>::session_core_count();
parachain_cores.saturating_add(on_demand_cores)
}
/// Pops an `Assignment` from a specified `CoreIndex`
fn pop_assignment_for_core(
core_idx: CoreIndex,
concluded_para: Option,
) -> Option {
if Pallet::::is_bulk_core(&core_idx) {
as AssignmentProvider>>::pop_assignment_for_core(
core_idx,
concluded_para,
)
} else {
as AssignmentProvider>>::pop_assignment_for_core(
core_idx,
concluded_para,
)
}
}
fn push_assignment_for_core(core_idx: CoreIndex, assignment: Assignment) {
if Pallet::::is_bulk_core(&core_idx) {
as AssignmentProvider>>::push_assignment_for_core(
core_idx, assignment,
)
} else {
as AssignmentProvider>>::push_assignment_for_core(
core_idx, assignment,
)
}
}
fn get_provider_config(core_idx: CoreIndex) -> AssignmentProviderConfig> {
if Pallet::::is_bulk_core(&core_idx) {
as AssignmentProvider>>::get_provider_config(
core_idx,
)
} else {
as AssignmentProvider>>::get_provider_config(
core_idx,
)
}
}
}