mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-31 05:11:02 +00:00
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:
@@ -17,12 +17,17 @@
|
||||
//! Mocks for all the traits.
|
||||
|
||||
use crate::{
|
||||
assigner, assigner_on_demand, assigner_parachains, configuration, disputes, dmp, hrmp,
|
||||
assigner_coretime, assigner_on_demand, assigner_parachains, configuration, coretime, disputes,
|
||||
dmp, hrmp,
|
||||
inclusion::{self, AggregateMessageOrigin, UmpQueueId},
|
||||
initializer, origin, paras,
|
||||
paras::ParaKind,
|
||||
paras_inherent, scheduler, session_info, shared, ParaId,
|
||||
paras_inherent, scheduler,
|
||||
scheduler::common::{AssignmentProvider, AssignmentProviderConfig},
|
||||
session_info, shared, ParaId,
|
||||
};
|
||||
use frame_support::pallet_prelude::*;
|
||||
use primitives::CoreIndex;
|
||||
|
||||
use frame_support::{
|
||||
assert_ok, derive_impl, parameter_types,
|
||||
@@ -45,7 +50,9 @@ use sp_runtime::{
|
||||
transaction_validity::TransactionPriority,
|
||||
BuildStorage, FixedU128, Perbill, Permill,
|
||||
};
|
||||
use sp_std::collections::vec_deque::VecDeque;
|
||||
use std::{cell::RefCell, collections::HashMap};
|
||||
use xcm::v3::{MultiAssets, MultiLocation, SendError, SendResult, SendXcm, Xcm, XcmHash};
|
||||
|
||||
type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic<Test>;
|
||||
type Block = frame_system::mocking::MockBlockU32<Test>;
|
||||
@@ -62,9 +69,11 @@ frame_support::construct_runtime!(
|
||||
ParaInclusion: inclusion,
|
||||
ParaInherent: paras_inherent,
|
||||
Scheduler: scheduler,
|
||||
Assigner: assigner,
|
||||
OnDemandAssigner: assigner_on_demand,
|
||||
MockAssigner: mock_assigner,
|
||||
ParachainsAssigner: assigner_parachains,
|
||||
OnDemandAssigner: assigner_on_demand,
|
||||
CoretimeAssigner: assigner_coretime,
|
||||
Coretime: coretime,
|
||||
Initializer: initializer,
|
||||
Dmp: dmp,
|
||||
Hrmp: hrmp,
|
||||
@@ -178,6 +187,7 @@ impl crate::initializer::Config for Test {
|
||||
type Randomness = TestRandomness<Self>;
|
||||
type ForceOrigin = frame_system::EnsureRoot<u64>;
|
||||
type WeightInfo = ();
|
||||
type CoretimeOnNewSession = Coretime;
|
||||
}
|
||||
|
||||
impl crate::configuration::Config for Test {
|
||||
@@ -217,6 +227,7 @@ impl crate::paras::Config for Test {
|
||||
type QueueFootprinter = ParaInclusion;
|
||||
type NextSessionRotation = TestNextSessionRotation;
|
||||
type OnNewHead = ();
|
||||
type AssignCoretime = ();
|
||||
}
|
||||
|
||||
impl crate::dmp::Config for Test {}
|
||||
@@ -288,7 +299,7 @@ impl crate::disputes::SlashingHandler<BlockNumber> for Test {
|
||||
}
|
||||
|
||||
impl crate::scheduler::Config for Test {
|
||||
type AssignmentProvider = Assigner;
|
||||
type AssignmentProvider = MockAssigner;
|
||||
}
|
||||
|
||||
pub struct TestMessageQueueWeight;
|
||||
@@ -342,17 +353,12 @@ impl pallet_message_queue::Config for Test {
|
||||
type ServiceWeight = MessageQueueServiceWeight;
|
||||
}
|
||||
|
||||
impl assigner::Config for Test {
|
||||
type ParachainsAssignmentProvider = ParachainsAssigner;
|
||||
type OnDemandAssignmentProvider = OnDemandAssigner;
|
||||
}
|
||||
|
||||
impl assigner_parachains::Config for Test {}
|
||||
|
||||
parameter_types! {
|
||||
pub const OnDemandTrafficDefaultValue: FixedU128 = FixedU128::from_u32(1);
|
||||
}
|
||||
|
||||
impl assigner_parachains::Config for Test {}
|
||||
|
||||
impl assigner_on_demand::Config for Test {
|
||||
type RuntimeEvent = RuntimeEvent;
|
||||
type Currency = Balances;
|
||||
@@ -360,6 +366,37 @@ impl assigner_on_demand::Config for Test {
|
||||
type WeightInfo = crate::assigner_on_demand::TestWeightInfo;
|
||||
}
|
||||
|
||||
impl assigner_coretime::Config for Test {}
|
||||
|
||||
parameter_types! {
|
||||
pub const BrokerId: u32 = 10u32;
|
||||
}
|
||||
|
||||
impl coretime::Config for Test {
|
||||
type RuntimeOrigin = RuntimeOrigin;
|
||||
type RuntimeEvent = RuntimeEvent;
|
||||
type Currency = pallet_balances::Pallet<Test>;
|
||||
type BrokerId = BrokerId;
|
||||
type WeightInfo = crate::coretime::TestWeightInfo;
|
||||
type SendXcm = DummyXcmSender;
|
||||
}
|
||||
|
||||
pub struct DummyXcmSender;
|
||||
impl SendXcm for DummyXcmSender {
|
||||
type Ticket = ();
|
||||
fn validate(
|
||||
_: &mut Option<MultiLocation>,
|
||||
_: &mut Option<Xcm<()>>,
|
||||
) -> SendResult<Self::Ticket> {
|
||||
Ok(((), MultiAssets::new()))
|
||||
}
|
||||
|
||||
/// Actually carry out the delivery operation for a previously validated message sending.
|
||||
fn deliver(_ticket: Self::Ticket) -> Result<XcmHash, SendError> {
|
||||
Ok([0u8; 32])
|
||||
}
|
||||
}
|
||||
|
||||
impl crate::inclusion::Config for Test {
|
||||
type WeightInfo = ();
|
||||
type RuntimeEvent = RuntimeEvent;
|
||||
@@ -390,6 +427,104 @@ impl ValidatorSetWithIdentification<AccountId> for MockValidatorSet {
|
||||
type IdentificationOf = FoolIdentificationOf;
|
||||
}
|
||||
|
||||
/// A mock assigner which acts as the scheduler's `AssignmentProvider` for tests. The mock
|
||||
/// assigner provides bare minimum functionality to test scheduler internals. Since they
|
||||
/// have no direct effect on scheduler state, AssignmentProvider functions such as
|
||||
/// `push_back_assignment` can be left empty.
|
||||
pub mod mock_assigner {
|
||||
use crate::scheduler::common::Assignment;
|
||||
|
||||
use super::*;
|
||||
pub use pallet::*;
|
||||
|
||||
#[frame_support::pallet]
|
||||
pub mod pallet {
|
||||
use super::*;
|
||||
|
||||
#[pallet::pallet]
|
||||
#[pallet::without_storage_info]
|
||||
pub struct Pallet<T>(_);
|
||||
|
||||
#[pallet::config]
|
||||
pub trait Config: frame_system::Config + configuration::Config + paras::Config {}
|
||||
|
||||
#[pallet::storage]
|
||||
pub(super) type MockAssignmentQueue<T: Config> =
|
||||
StorageValue<_, VecDeque<Assignment>, ValueQuery>;
|
||||
|
||||
#[pallet::storage]
|
||||
pub(super) type MockProviderConfig<T: Config> =
|
||||
StorageValue<_, AssignmentProviderConfig<BlockNumber>, OptionQuery>;
|
||||
|
||||
#[pallet::storage]
|
||||
pub(super) type MockCoreCount<T: Config> = StorageValue<_, u32, OptionQuery>;
|
||||
}
|
||||
|
||||
impl<T: Config> Pallet<T> {
|
||||
/// Adds a claim to the `MockAssignmentQueue` this claim can later be popped by the
|
||||
/// scheduler when filling the claim queue for tests.
|
||||
pub fn add_test_assignment(assignment: Assignment) {
|
||||
MockAssignmentQueue::<T>::mutate(|queue| queue.push_back(assignment));
|
||||
}
|
||||
|
||||
// This configuration needs to be customized to service `get_provider_config` in
|
||||
// scheduler tests.
|
||||
pub fn set_assignment_provider_config(config: AssignmentProviderConfig<BlockNumber>) {
|
||||
MockProviderConfig::<T>::set(Some(config));
|
||||
}
|
||||
|
||||
// Allows for customized core count in scheduler tests, rather than a core count
|
||||
// derived from on-demand config + parachain count.
|
||||
pub fn set_core_count(count: u32) {
|
||||
MockCoreCount::<T>::set(Some(count));
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: Config> AssignmentProvider<BlockNumber> for Pallet<T> {
|
||||
// With regards to popping_assignments, the scheduler just needs to be tested under
|
||||
// the following two conditions:
|
||||
// 1. An assignment is provided
|
||||
// 2. No assignment is provided
|
||||
// A simple assignment queue populated to fit each test fulfills these needs.
|
||||
fn pop_assignment_for_core(_core_idx: CoreIndex) -> Option<Assignment> {
|
||||
let mut queue: VecDeque<Assignment> = MockAssignmentQueue::<T>::get();
|
||||
let front = queue.pop_front();
|
||||
// Write changes to storage.
|
||||
MockAssignmentQueue::<T>::set(queue);
|
||||
front
|
||||
}
|
||||
|
||||
// We don't care about core affinity in the test assigner
|
||||
fn report_processed(_assignment: Assignment) {}
|
||||
|
||||
// The results of this are tested in assigner_on_demand tests. No need to represent it
|
||||
// in the mock assigner.
|
||||
fn push_back_assignment(_assignment: Assignment) {}
|
||||
|
||||
// Gets the provider config we set earlier using `set_assignment_provider_config`, falling
|
||||
// back to the on demand parachain configuration if none was set.
|
||||
fn get_provider_config(_core_idx: CoreIndex) -> AssignmentProviderConfig<BlockNumber> {
|
||||
match MockProviderConfig::<T>::get() {
|
||||
Some(config) => config,
|
||||
None => AssignmentProviderConfig {
|
||||
max_availability_timeouts: 1,
|
||||
ttl: BlockNumber::from(5u32),
|
||||
},
|
||||
}
|
||||
}
|
||||
#[cfg(any(feature = "runtime-benchmarks", test))]
|
||||
fn get_mock_assignment(_: CoreIndex, para_id: ParaId) -> Assignment {
|
||||
Assignment::Bulk(para_id)
|
||||
}
|
||||
|
||||
fn session_core_count() -> u32 {
|
||||
MockCoreCount::<T>::get().unwrap_or(5)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl mock_assigner::pallet::Config for Test {}
|
||||
|
||||
pub struct FoolIdentificationOf;
|
||||
impl sp_runtime::traits::Convert<AccountId, Option<()>> for FoolIdentificationOf {
|
||||
fn convert(_: AccountId) -> Option<()> {
|
||||
|
||||
Reference in New Issue
Block a user