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 <>
This commit is contained in:
eskimor
2023-12-21 19:06:58 +01:00
committed by GitHub
parent 18d53dbf91
commit 69434d9a32
71 changed files with 4059 additions and 1213 deletions
@@ -743,6 +743,7 @@ mod tests {
type QueueFootprinter = ();
type NextSessionRotation = crate::mock::TestNextSessionRotation;
type OnNewHead = ();
type AssignCoretime = ();
}
impl parachains_shared::Config for Test {}
@@ -212,6 +212,7 @@ impl paras::Config for Test {
type QueueFootprinter = ();
type NextSessionRotation = crate::mock::TestNextSessionRotation;
type OnNewHead = ();
type AssignCoretime = ();
}
parameter_types! {
@@ -814,6 +814,7 @@ mod tests {
type QueueFootprinter = ();
type NextSessionRotation = crate::mock::TestNextSessionRotation;
type OnNewHead = ();
type AssignCoretime = ();
}
impl configuration::Config for Test {
@@ -23,7 +23,7 @@ use parity_scale_codec::Encode;
use primitives::Id as ParaId;
use runtime_parachains::{
configuration, dmp, hrmp,
paras::{self, ParaGenesisArgs},
paras::{self, AssignCoretime, ParaGenesisArgs},
ParaLifecycle,
};
use sp_std::boxed::Box;
@@ -58,6 +58,8 @@ pub mod pallet {
CannotUpgrade,
/// Cannot downgrade lease holding parachain to on-demand.
CannotDowngrade,
/// There are more cores than supported by the runtime.
TooManyCores,
}
#[pallet::hooks]
@@ -66,6 +68,10 @@ pub mod pallet {
#[pallet::call]
impl<T: Config> Pallet<T> {
/// Schedule a para to be initialized at the start of the next session.
///
/// This should only be used for TESTING and not on PRODUCTION chains. It automatically
/// assigns Coretime to the chain and increases the number of cores. Thus, there is no
/// running coretime chain required.
#[pallet::call_index(0)]
#[pallet::weight((1_000, DispatchClass::Operational))]
pub fn sudo_schedule_para_initialize(
@@ -76,6 +82,9 @@ pub mod pallet {
ensure_root(origin)?;
runtime_parachains::schedule_para_initialize::<T>(id, genesis)
.map_err(|_| Error::<T>::ParaAlreadyExists)?;
T::AssignCoretime::assign_coretime(id)?;
Ok(())
}
+14 -6
View File
@@ -326,6 +326,18 @@ impl<T: Config> Pallet<T> {
tracker.into_iter().collect()
}
/// Current lease index and how many blocks we are already in.
pub fn lease_period_index_plus_progress(
b: BlockNumberFor<T>,
) -> Option<(<Self as Leaser<BlockNumberFor<T>>>::LeasePeriod, BlockNumberFor<T>)> {
// Note that blocks before `LeaseOffset` do not count as any lease period.
let offset_block_now = b.checked_sub(&T::LeaseOffset::get())?;
let lease_period = offset_block_now / T::LeasePeriod::get();
let in_lease = offset_block_now % T::LeasePeriod::get();
Some((lease_period, in_lease))
}
}
impl<T: Config> crate::traits::OnSwap for Pallet<T> {
@@ -449,12 +461,8 @@ impl<T: Config> Leaser<BlockNumberFor<T>> for Pallet<T> {
}
fn lease_period_index(b: BlockNumberFor<T>) -> Option<(Self::LeasePeriod, bool)> {
// Note that blocks before `LeaseOffset` do not count as any lease period.
let offset_block_now = b.checked_sub(&T::LeaseOffset::get())?;
let lease_period = offset_block_now / T::LeasePeriod::get();
let first_block = (offset_block_now % T::LeasePeriod::get()).is_zero();
Some((lease_period, first_block))
Self::lease_period_index_plus_progress(b)
.map(|(period, progress)| (period, progress.is_zero()))
}
fn already_leased(