Skip to content

Commit

Permalink
Coretime Feature branch (relay chain) (#1694)
Browse files Browse the repository at this point in the history
Also fixes: #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 <>
  • Loading branch information
9 people authored Dec 21, 2023
1 parent 18d53db commit 69434d9
Show file tree
Hide file tree
Showing 71 changed files with 4,052 additions and 1,206 deletions.
3 changes: 3 additions & 0 deletions Cargo.lock

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

Original file line number Diff line number Diff line change
Expand Up @@ -199,23 +199,12 @@ impl CoretimeInterface for CoretimeAllocator {
}
}

fn check_notify_core_count() -> Option<u16> {
let count = CoreCount::get();
CoreCount::set(&None);
count
}

fn check_notify_revenue_info() -> Option<(RCBlockNumberOf<Self>, Self::Balance)> {
let revenue = CoretimeRevenue::get();
CoretimeRevenue::set(&None);
revenue
}

#[cfg(feature = "runtime-benchmarks")]
fn ensure_notify_core_count(count: u16) {
CoreCount::set(&Some(count));
}

#[cfg(feature = "runtime-benchmarks")]
fn ensure_notify_revenue_info(when: RCBlockNumberOf<Self>, revenue: Self::Balance) {
CoretimeRevenue::set(&Some((when, revenue)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
spec_name: create_runtime_str!("coretime-rococo"),
impl_name: create_runtime_str!("coretime-rococo"),
authoring_version: 1,
spec_version: 1_005_000,
spec_version: 1_005_001,
impl_version: 0,
apis: RUNTIME_API_VERSIONS,
transaction_version: 0,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -463,6 +463,9 @@ impl<T: frame_system::Config> pallet_broker::WeightInfo for WeightInfo<T> {
.saturating_add(T::DbWeight::get().reads(5))
.saturating_add(T::DbWeight::get().writes(2))
}
fn notify_core_count() -> Weight {
T::DbWeight::get().reads_writes(1, 1)
}
/// Storage: `Broker::Status` (r:1 w:1)
/// Proof: `Broker::Status` (`max_values`: Some(1), `max_size`: Some(18), added: 513, mode: `MaxEncodedLen`)
/// Storage: `Broker::Configuration` (r:1 w:0)
Expand Down
5 changes: 2 additions & 3 deletions polkadot/node/core/prospective-parachains/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,8 @@ fn test_harness<T: Future<Output = VirtualOverseer>>(

let mut view = View::new();
let subsystem = async move {
match run_iteration(&mut context, &mut view, &Metrics(None)).await {
Ok(()) => {},
Err(e) => panic!("{:?}", e),
if let Err(e) = run_iteration(&mut context, &mut view, &Metrics(None)).await {
panic!("{:?}", e);
}

view
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,7 @@ struct CoreAssignment {
core: CoreIndex,
para_id: ParaId,
kind: AssignmentKind,
group_idx: GroupIndex,
}
// reasons a core might be freed.
enum FreedReason {
Expand Down
4 changes: 4 additions & 0 deletions polkadot/runtime/common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ sp-npos-elections = { path = "../../../substrate/primitives/npos-elections", def

pallet-authorship = { path = "../../../substrate/frame/authorship", default-features = false }
pallet-balances = { path = "../../../substrate/frame/balances", default-features = false }
pallet-broker = { path = "../../../substrate/frame/broker", default-features = false }
pallet-fast-unstake = { path = "../../../substrate/frame/fast-unstake", default-features = false }
pallet-identity = { path = "../../../substrate/frame/identity", default-features = false }
pallet-session = { path = "../../../substrate/frame/session", default-features = false }
Expand Down Expand Up @@ -87,6 +88,7 @@ std = [
"pallet-asset-rate?/std",
"pallet-authorship/std",
"pallet-balances/std",
"pallet-broker/std",
"pallet-election-provider-multi-phase/std",
"pallet-fast-unstake/std",
"pallet-identity/std",
Expand Down Expand Up @@ -127,6 +129,7 @@ runtime-benchmarks = [
"pallet-asset-rate/runtime-benchmarks",
"pallet-babe/runtime-benchmarks",
"pallet-balances/runtime-benchmarks",
"pallet-broker/runtime-benchmarks",
"pallet-election-provider-multi-phase/runtime-benchmarks",
"pallet-fast-unstake/runtime-benchmarks",
"pallet-identity/runtime-benchmarks",
Expand All @@ -151,6 +154,7 @@ try-runtime = [
"pallet-authorship/try-runtime",
"pallet-babe?/try-runtime",
"pallet-balances/try-runtime",
"pallet-broker/try-runtime",
"pallet-election-provider-multi-phase/try-runtime",
"pallet-fast-unstake/try-runtime",
"pallet-identity/try-runtime",
Expand Down
1 change: 1 addition & 0 deletions polkadot/runtime/common/src/assigned_slots/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -743,6 +743,7 @@ mod tests {
type QueueFootprinter = ();
type NextSessionRotation = crate::mock::TestNextSessionRotation;
type OnNewHead = ();
type AssignCoretime = ();
}

impl parachains_shared::Config for Test {}
Expand Down
1 change: 1 addition & 0 deletions polkadot/runtime/common/src/integration_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,7 @@ impl paras::Config for Test {
type QueueFootprinter = ();
type NextSessionRotation = crate::mock::TestNextSessionRotation;
type OnNewHead = ();
type AssignCoretime = ();
}

parameter_types! {
Expand Down
1 change: 1 addition & 0 deletions polkadot/runtime/common/src/paras_registrar/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -814,6 +814,7 @@ mod tests {
type QueueFootprinter = ();
type NextSessionRotation = crate::mock::TestNextSessionRotation;
type OnNewHead = ();
type AssignCoretime = ();
}

impl configuration::Config for Test {
Expand Down
11 changes: 10 additions & 1 deletion polkadot/runtime/common/src/paras_sudo_wrapper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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]
Expand All @@ -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(
Expand All @@ -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(())
}

Expand Down
20 changes: 14 additions & 6 deletions polkadot/runtime/common/src/slots/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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> {
Expand Down Expand Up @@ -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(
Expand Down
6 changes: 6 additions & 0 deletions polkadot/runtime/parachains/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,13 @@ sp-core = { path = "../../../substrate/primitives/core", default-features = fals
sp-keystore = { path = "../../../substrate/primitives/keystore", optional = true }
sp-application-crypto = { path = "../../../substrate/primitives/application-crypto", default-features = false, optional = true }
sp-tracing = { path = "../../../substrate/primitives/tracing", default-features = false, optional = true }
sp-arithmetic = { path = "../../../substrate/primitives/arithmetic", default-features = false }

pallet-authority-discovery = { path = "../../../substrate/frame/authority-discovery", default-features = false }
pallet-authorship = { path = "../../../substrate/frame/authorship", default-features = false }
pallet-balances = { path = "../../../substrate/frame/balances", default-features = false }
pallet-babe = { path = "../../../substrate/frame/babe", default-features = false }
pallet-broker = { path = "../../../substrate/frame/broker", default-features = false }
pallet-message-queue = { path = "../../../substrate/frame/message-queue", default-features = false }
pallet-session = { path = "../../../substrate/frame/session", default-features = false }
pallet-staking = { path = "../../../substrate/frame/staking", default-features = false }
Expand Down Expand Up @@ -82,6 +84,7 @@ std = [
"pallet-authorship/std",
"pallet-babe/std",
"pallet-balances/std",
"pallet-broker/std",
"pallet-message-queue/std",
"pallet-session/std",
"pallet-staking/std",
Expand All @@ -99,6 +102,7 @@ std = [
"serde/std",
"sp-api/std",
"sp-application-crypto?/std",
"sp-arithmetic/std",
"sp-core/std",
"sp-io/std",
"sp-keystore",
Expand All @@ -115,6 +119,7 @@ runtime-benchmarks = [
"frame-system/runtime-benchmarks",
"pallet-babe/runtime-benchmarks",
"pallet-balances/runtime-benchmarks",
"pallet-broker/runtime-benchmarks",
"pallet-message-queue/runtime-benchmarks",
"pallet-staking/runtime-benchmarks",
"pallet-timestamp/runtime-benchmarks",
Expand All @@ -135,6 +140,7 @@ try-runtime = [
"pallet-authorship/try-runtime",
"pallet-babe/try-runtime",
"pallet-balances/try-runtime",
"pallet-broker/try-runtime",
"pallet-message-queue/try-runtime",
"pallet-session/try-runtime",
"pallet-staking/try-runtime",
Expand Down
112 changes: 0 additions & 112 deletions polkadot/runtime/parachains/src/assigner.rs

This file was deleted.

Loading

0 comments on commit 69434d9

Please sign in to comment.