Skip to content

Commit

Permalink
Coretime Feature branch (relay chain) (paritytech#1694)
Browse files Browse the repository at this point in the history
Also fixes: paritytech#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 baff0d7 commit 4ca9099
Show file tree
Hide file tree
Showing 9 changed files with 29 additions and 40 deletions.
10 changes: 0 additions & 10 deletions substrate/bin/node/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1993,7 +1993,6 @@ impl OnUnbalanced<Credit<AccountId, Balances>> for IntoAuthor {
}

parameter_types! {
pub storage CoreCount: Option<CoreIndex> = None;
pub storage CoretimeRevenue: Option<(BlockNumber, Balance)> = None;
}

Expand All @@ -2012,21 +2011,12 @@ impl CoretimeInterface for CoretimeProvider {
_end_hint: Option<u32>,
) {
}
fn check_notify_core_count() -> Option<u16> {
let count = CoreCount::get();
CoreCount::set(&None);
count
}
fn check_notify_revenue_info() -> Option<(u32, 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: u32, revenue: Self::Balance) {
CoretimeRevenue::set(&Some((when, revenue)));
}
Expand Down
4 changes: 1 addition & 3 deletions substrate/client/chain-spec/src/chain_spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -784,9 +784,7 @@ fn json_eval_value_at_key(
path: &mut VecDeque<&str>,
fun: &dyn Fn(&json::Value) -> bool,
) -> bool {
let Some(key) = path.pop_front() else {
return false;
};
let Some(key) = path.pop_front() else { return false };

if path.is_empty() {
doc.as_object().map_or(false, |o| o.get(key).map_or(false, |v| fun(v)))
Expand Down
2 changes: 1 addition & 1 deletion substrate/frame/broker/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -705,7 +705,7 @@ mod benches {

let core_count = n.try_into().unwrap();

<T::Coretime as CoretimeInterface>::ensure_notify_core_count(core_count);
CoreCountInbox::<T>::put(core_count);

let mut status = Status::<T>::get().ok_or(BenchmarkError::Weightless)?;

Expand Down
16 changes: 0 additions & 16 deletions substrate/frame/broker/src/coretime_interface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,11 +107,6 @@ pub trait CoretimeInterface {
end_hint: Option<RCBlockNumberOf<Self>>,
);

/// Indicate that from this block onwards, the range of acceptable values of the `core`
/// parameter of `assign_core` message is `[0, count)`. `assign_core` will be a no-op if
/// provided with a value for `core` outside of this range.
fn check_notify_core_count() -> Option<u16>;

/// Provide the amount of revenue accumulated from Instantaneous Coretime Sales from Relay-chain
/// block number `last_until` to `until`, not including `until` itself. `last_until` is defined
/// as being the `until` argument of the last `notify_revenue` message sent, or zero for the
Expand All @@ -123,12 +118,6 @@ pub trait CoretimeInterface {
/// single revenue information destination exists.
fn check_notify_revenue_info() -> Option<(RCBlockNumberOf<Self>, Self::Balance)>;

/// Ensure that core count is updated to the provided value.
///
/// This is only used for benchmarking.
#[cfg(feature = "runtime-benchmarks")]
fn ensure_notify_core_count(count: u16);

/// Ensure that revenue information is updated to the provided value.
///
/// This is only used for benchmarking.
Expand All @@ -151,14 +140,9 @@ impl CoretimeInterface for () {
_end_hint: Option<RCBlockNumberOf<Self>>,
) {
}
fn check_notify_core_count() -> Option<u16> {
None
}
fn check_notify_revenue_info() -> Option<(RCBlockNumberOf<Self>, Self::Balance)> {
None
}
#[cfg(feature = "runtime-benchmarks")]
fn ensure_notify_core_count(_count: u16) {}
#[cfg(feature = "runtime-benchmarks")]
fn ensure_notify_revenue_info(_when: RCBlockNumberOf<Self>, _revenue: Self::Balance) {}
}
5 changes: 5 additions & 0 deletions substrate/frame/broker/src/dispatchable_impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ impl<T: Config> Pallet<T> {
Ok(())
}

pub(crate) fn do_notify_core_count(core_count: CoreIndex) -> DispatchResult {
CoreCountInbox::<T>::put(core_count);
Ok(())
}

pub(crate) fn do_reserve(workload: Schedule) -> DispatchResult {
let mut r = Reservations::<T>::get();
let index = r.len() as u32;
Expand Down
12 changes: 12 additions & 0 deletions substrate/frame/broker/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,10 @@ pub mod pallet {
pub type InstaPoolHistory<T> =
StorageMap<_, Blake2_128Concat, Timeslice, InstaPoolHistoryRecordOf<T>>;

/// Received core count change from the relay chain.
#[pallet::storage]
pub type CoreCountInbox<T> = StorageValue<_, CoreIndex, OptionQuery>;

#[pallet::event]
#[pallet::generate_deposit(pub(super) fn deposit_event)]
pub enum Event<T: Config> {
Expand Down Expand Up @@ -774,5 +778,13 @@ pub mod pallet {
Self::do_request_core_count(core_count)?;
Ok(())
}

#[pallet::call_index(19)]
#[pallet::weight(T::WeightInfo::notify_core_count())]
pub fn notify_core_count(origin: OriginFor<T>, core_count: CoreIndex) -> DispatchResult {
T::AdminOrigin::ensure_origin_or_root(origin)?;
Self::do_notify_core_count(core_count)?;
Ok(())
}
}
}
10 changes: 1 addition & 9 deletions substrate/frame/broker/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ parameter_types! {
pub static CoretimeWorkplan: BTreeMap<(u32, CoreIndex), Vec<(CoreAssignment, PartsOf57600)>> = Default::default();
pub static CoretimeUsage: BTreeMap<CoreIndex, Vec<(CoreAssignment, PartsOf57600)>> = Default::default();
pub static CoretimeInPool: CoreMaskBitCount = 0;
pub static NotifyCoreCount: Vec<u16> = Default::default();
pub static NotifyRevenueInfo: Vec<(u32, u64)> = Default::default();
}

Expand All @@ -80,7 +79,7 @@ impl CoretimeInterface for TestCoretimeProvider {
type Balance = u64;
type RealyChainBlockNumberProvider = System;
fn request_core_count(count: CoreIndex) {
NotifyCoreCount::mutate(|s| s.insert(0, count));
CoreCountInbox::<Test>::put(count);
}
fn request_revenue_info_at(when: RCBlockNumberOf<Self>) {
if when > RCBlockNumberProviderOf::<Self>::current_block_number() {
Expand Down Expand Up @@ -126,17 +125,10 @@ impl CoretimeInterface for TestCoretimeProvider {
);
CoretimeTrace::mutate(|v| v.push(item));
}
fn check_notify_core_count() -> Option<u16> {
NotifyCoreCount::mutate(|s| s.pop())
}
fn check_notify_revenue_info() -> Option<(RCBlockNumberOf<Self>, Self::Balance)> {
NotifyRevenueInfo::mutate(|s| s.pop()).map(|v| (v.0 as _, v.1))
}
#[cfg(feature = "runtime-benchmarks")]
fn ensure_notify_core_count(count: u16) {
NotifyCoreCount::mutate(|s| s.insert(0, count));
}
#[cfg(feature = "runtime-benchmarks")]
fn ensure_notify_revenue_info(when: RCBlockNumberOf<Self>, revenue: Self::Balance) {
NotifyRevenueInfo::mutate(|s| s.push((when as u32, revenue)));
}
Expand Down
2 changes: 1 addition & 1 deletion substrate/frame/broker/src/tick_impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ impl<T: Config> Pallet<T> {
}

pub(crate) fn process_core_count(status: &mut StatusRecord) -> bool {
if let Some(core_count) = T::Coretime::check_notify_core_count() {
if let Some(core_count) = CoreCountInbox::<T>::take() {
status.core_count = core_count;
Self::deposit_event(Event::<T>::CoreCountChanged { core_count });
return true
Expand Down
8 changes: 8 additions & 0 deletions substrate/frame/broker/src/weights.rs

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

0 comments on commit 4ca9099

Please sign in to comment.