Files
pezkuwi-subxt/polkadot/runtime/parachains/src/scheduler/common.rs
T
eskimor 69434d9a32 Coretime Feature branch (relay chain) (#1694)
Also fixes: https://github.com/paritytech/polkadot-sdk/issues/1417

- [x] CoreIndex -> AssignmentProvider mapping will be able to change any
time.
- [x] Implement
- [x] Provide Migrations
- [x] Add and fix tests
- [x] Implement bulk assigner logic
- [x] bulk assigner tests
- [x] Port over current assigner to use bulk designer (+ share on-demand
with bulk): top-level assigner has core ranges: legacy, bulk
- [x] Adjust migrations to reflect new assigner structure
- [x] Move migration code to Assignment code directly and make it
recursive (make it possible to skip releases) -> follow up ticket.
- [x] Test migrations
- [x] Add migration PR to runtimes repo -> follow up ticket.
- [x] Wire up with actual UMP messages
- [x] Write PR docs

---------

Co-authored-by: eskimor <eskimor@no-such-url.com>
Co-authored-by: Bradley Olson <34992650+BradleyOlson64@users.noreply.github.com>
Co-authored-by: BradleyOlson64 <lotrftw9@gmail.com>
Co-authored-by: Anton Vilhelm Ásgeirsson <antonva@users.noreply.github.com>
Co-authored-by: antonva <anton.asgeirsson@parity.io>
Co-authored-by: Bastian Köcher <git@kchr.de>
Co-authored-by: Marcin S. <marcin@realemail.net>
Co-authored-by: Bastian Köcher <info@kchr.de>
Co-authored-by: command-bot <>
2023-12-21 19:06:58 +01:00

103 lines
3.6 KiB
Rust

// 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 <http://www.gnu.org/licenses/>.
//! Common traits and types used by the scheduler and assignment providers.
use scale_info::TypeInfo;
use sp_runtime::{
codec::{Decode, Encode},
RuntimeDebug,
};
use primitives::{CoreIndex, Id as ParaId};
/// Assignment (ParaId -> CoreIndex).
#[derive(Encode, Decode, TypeInfo, RuntimeDebug, Clone, PartialEq)]
pub enum Assignment {
/// A pool assignment.
Pool {
/// The assigned para id.
para_id: ParaId,
/// The core index the para got assigned to.
core_index: CoreIndex,
},
/// A bulk assignment.
Bulk(ParaId),
}
impl Assignment {
/// Returns the [`ParaId`] this assignment is associated to.
pub fn para_id(&self) -> ParaId {
match self {
Self::Pool { para_id, .. } => *para_id,
Self::Bulk(para_id) => *para_id,
}
}
}
#[derive(Encode, Decode, TypeInfo)]
/// A set of variables required by the scheduler in order to operate.
pub struct AssignmentProviderConfig<BlockNumber> {
/// How many times a collation can time out on availability.
/// Zero timeouts still means that a collation can be provided as per the slot auction
/// assignment provider.
pub max_availability_timeouts: u32,
/// How long the collator has to provide a collation to the backing group before being dropped.
pub ttl: BlockNumber,
}
pub trait AssignmentProvider<BlockNumber> {
/// Pops an [`Assignment`] from the provider for a specified [`CoreIndex`].
///
/// This is where assignments come into existance.
fn pop_assignment_for_core(core_idx: CoreIndex) -> Option<Assignment>;
/// A previously popped `Assignment` has been fully processed.
///
/// Report back to the assignment provider that an assignment is done and no longer present in
/// the scheduler.
///
/// This is one way of the life of an assignment coming to an end.
fn report_processed(assignment: Assignment);
/// Push back a previously popped assignment.
///
/// If the assignment could not be processed within the current session, it can be pushed back
/// to the assignment provider in order to be poppped again later.
///
/// This is the second way the life of an assignment can come to an end.
fn push_back_assignment(assignment: Assignment);
/// Returns a set of variables needed by the scheduler
fn get_provider_config(core_idx: CoreIndex) -> AssignmentProviderConfig<BlockNumber>;
/// Push some assignment for mocking/benchmarks purposes.
///
/// Useful for benchmarks and testing. The returned assignment is "valid" and can if need be
/// passed into `report_processed` for example.
#[cfg(any(feature = "runtime-benchmarks", test))]
fn get_mock_assignment(core_idx: CoreIndex, para_id: ParaId) -> Assignment;
/// How many cores are allocated to this provider.
///
/// As the name suggests the core count has to be session buffered:
///
/// - Core count has to be predetermined for the next session in the current session.
/// - Core count must not change during a session.
fn session_core_count() -> u32;
}