Use same fmt and clippy configs as in Substrate (#7611)

* Use same rustfmt.toml as Substrate

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* format format file

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Format with new config

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Add Substrate Clippy config

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Print Clippy version in CI

Otherwise its difficult to reproduce locally.

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Make fmt happy

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Update node/core/pvf/src/error.rs

Co-authored-by: Tsvetomir Dimitrov <tsvetomir@parity.io>

* Update node/core/pvf/src/error.rs

Co-authored-by: Tsvetomir Dimitrov <tsvetomir@parity.io>

---------

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>
Co-authored-by: Tsvetomir Dimitrov <tsvetomir@parity.io>
This commit is contained in:
Oliver Tale-Yazdi
2023-08-14 16:29:29 +02:00
committed by GitHub
parent ac435c96cf
commit 342d720573
203 changed files with 1880 additions and 1504 deletions
+51 -43
View File
@@ -21,19 +21,20 @@
//! - Scheduling parachains and parathreads
//!
//! It aims to achieve these tasks with these goals in mind:
//! - It should be possible to know at least a block ahead-of-time, ideally more,
//! which validators are going to be assigned to which parachains.
//! - Parachains that have a candidate pending availability in this fork of the chain
//! should not be assigned.
//! - It should be possible to know at least a block ahead-of-time, ideally more, which validators
//! are going to be assigned to which parachains.
//! - Parachains that have a candidate pending availability in this fork of the chain should not be
//! assigned.
//! - Validator assignments should not be gameable. Malicious cartels should not be able to
//! manipulate the scheduler to assign themselves as desired.
//! - High or close to optimal throughput of parachains and parathreads. Work among validator groups should be balanced.
//! - High or close to optimal throughput of parachains and parathreads. Work among validator groups
//! should be balanced.
//!
//! The Scheduler manages resource allocation using the concept of "Availability Cores".
//! There will be one availability core for each parachain, and a fixed number of cores
//! used for multiplexing parathreads. Validators will be partitioned into groups, with the same
//! number of groups as availability cores. Validator groups will be assigned to different availability cores
//! over time.
//! number of groups as availability cores. Validator groups will be assigned to different
//! availability cores over time.
use frame_support::pallet_prelude::*;
use frame_system::pallet_prelude::BlockNumberFor;
@@ -169,8 +170,9 @@ pub mod pallet {
/// broader set of Polkadot validators, but instead just the subset used for parachains during
/// this session.
///
/// Bound: The number of cores is the sum of the numbers of parachains and parathread multiplexers.
/// Reasonably, 100-1000. The dominant factor is the number of validators: safe upper bound at 10k.
/// Bound: The number of cores is the sum of the numbers of parachains and parathread
/// multiplexers. Reasonably, 100-1000. The dominant factor is the number of validators: safe
/// upper bound at 10k.
#[pallet::storage]
#[pallet::getter(fn validator_groups)]
pub(crate) type ValidatorGroups<T> = StorageValue<_, Vec<Vec<ValidatorIndex>>, ValueQuery>;
@@ -182,8 +184,8 @@ pub mod pallet {
#[pallet::storage]
pub(crate) type ParathreadQueue<T> = StorageValue<_, ParathreadClaimQueue, ValueQuery>;
/// One entry for each availability core. Entries are `None` if the core is not currently occupied. Can be
/// temporarily `Some` if scheduled but not occupied.
/// One entry for each availability core. Entries are `None` if the core is not currently
/// occupied. Can be temporarily `Some` if scheduled but not occupied.
/// The i'th parachain belongs to the i'th core, with the remaining cores all being
/// parathread-multiplexers.
///
@@ -197,11 +199,13 @@ pub mod pallet {
/// An index used to ensure that only one claim on a parathread exists in the queue or is
/// currently being handled by an occupied core.
///
/// Bounded by the number of parathread cores and scheduling lookahead. Reasonably, 10 * 50 = 500.
/// Bounded by the number of parathread cores and scheduling lookahead. Reasonably, 10 * 50 =
/// 500.
#[pallet::storage]
pub(crate) type ParathreadClaimIndex<T> = StorageValue<_, Vec<ParaId>, ValueQuery>;
/// The block number where the session start occurred. Used to track how many group rotations have occurred.
/// The block number where the session start occurred. Used to track how many group rotations
/// have occurred.
///
/// Note that in the context of parachains modules the session change is signaled during
/// the block and enacted at the end of the block (at the finalization stage, to be exact).
@@ -215,8 +219,8 @@ pub mod pallet {
///
/// Bounded by the number of cores: one for each parachain and parathread multiplexer.
///
/// The value contained here will not be valid after the end of a block. Runtime APIs should be used to determine scheduled cores/
/// for the upcoming block.
/// The value contained here will not be valid after the end of a block. Runtime APIs should be
/// used to determine scheduled cores/ for the upcoming block.
#[pallet::storage]
#[pallet::getter(fn scheduled)]
pub(crate) type Scheduled<T> = StorageValue<_, Vec<CoreAssignment>, ValueQuery>;
@@ -380,8 +384,9 @@ impl<T: Config> Pallet<T> {
})
}
/// Free unassigned cores. Provide a list of cores that should be considered newly-freed along with the reason
/// for them being freed. The list is assumed to be sorted in ascending order by core index.
/// Free unassigned cores. Provide a list of cores that should be considered newly-freed along
/// with the reason for them being freed. The list is assumed to be sorted in ascending order by
/// core index.
pub(crate) fn free_cores(just_freed_cores: impl IntoIterator<Item = (CoreIndex, FreedReason)>) {
let config = <configuration::Pallet<T>>::config();
@@ -403,8 +408,8 @@ impl<T: Config> Pallet<T> {
})
},
FreedReason::TimedOut => {
// If a parathread candidate times out, it's not the collator's fault,
// so we don't increment retries.
// If a parathread candidate times out, it's not the collator's
// fault, so we don't increment retries.
ParathreadQueue::<T>::mutate(|queue| {
queue.enqueue_entry(entry, config.parathread_cores);
})
@@ -417,9 +422,9 @@ impl<T: Config> Pallet<T> {
})
}
/// Schedule all unassigned cores, where possible. Provide a list of cores that should be considered
/// newly-freed along with the reason for them being freed. The list is assumed to be sorted in
/// ascending order by core index.
/// Schedule all unassigned cores, where possible. Provide a list of cores that should be
/// considered newly-freed along with the reason for them being freed. The list is assumed to be
/// sorted in ascending order by core index.
pub(crate) fn schedule(
just_freed_cores: impl IntoIterator<Item = (CoreIndex, FreedReason)>,
now: BlockNumberFor<T>,
@@ -455,10 +460,10 @@ impl<T: Config> Pallet<T> {
// check the first entry already scheduled with core index >= than the one we
// are looking at. 3 cases:
// 1. No such entry, clearly this core is not scheduled, so we need to schedule and put at the end.
// 2. Entry exists and has same index as the core we are inspecting. do not schedule again.
// 3. Entry exists and has higher index than the core we are inspecting. schedule and note
// insertion position.
// 1. No such entry, clearly this core is not scheduled, so we need to schedule
// and put at the end. 2. Entry exists and has same index as the core we are
// inspecting. do not schedule again. 3. Entry exists and has higher index than
// the core we are inspecting. schedule and note insertion position.
prev_scheduled_in_order.peek().map_or(
Some(scheduled.len()),
|(idx_in_scheduled, assign)| {
@@ -509,8 +514,9 @@ impl<T: Config> Pallet<T> {
}
}
// at this point, because `Scheduled` is guaranteed to be sorted and we navigated unassigned
// core indices in ascending order, we can enact the updates prepared by the previous actions.
// at this point, because `Scheduled` is guaranteed to be sorted and we navigated
// unassigned core indices in ascending order, we can enact the updates prepared by the
// previous actions.
//
// while inserting, we have to account for the amount of insertions already done.
//
@@ -522,20 +528,20 @@ impl<T: Config> Pallet<T> {
scheduled.insert(insert_at, to_insert);
}
// scheduled is guaranteed to be sorted after this point because it was sorted before, and we
// applied sorted updates at their correct positions, accounting for the offsets of previous
// insertions.
// scheduled is guaranteed to be sorted after this point because it was sorted before,
// and we applied sorted updates at their correct positions, accounting for the offsets
// of previous insertions.
}
Scheduled::<T>::set(scheduled);
ParathreadQueue::<T>::set(parathread_queue);
}
/// Note that the given cores have become occupied. Behavior undefined if any of the given cores were not scheduled
/// or the slice is not sorted ascending by core index.
/// Note that the given cores have become occupied. Behavior undefined if any of the given cores
/// were not scheduled or the slice is not sorted ascending by core index.
///
/// Complexity: O(n) in the number of scheduled cores, which is capped at the number of total cores.
/// This is efficient in the case that most scheduled cores are occupied.
/// Complexity: O(n) in the number of scheduled cores, which is capped at the number of total
/// cores. This is efficient in the case that most scheduled cores are occupied.
pub(crate) fn occupied(now_occupied: &[CoreIndex]) {
if now_occupied.is_empty() {
return
@@ -568,8 +574,8 @@ impl<T: Config> Pallet<T> {
AvailabilityCores::<T>::set(availability_cores);
}
/// Get the para (chain or thread) ID assigned to a particular core or index, if any. Core indices
/// out of bounds will return `None`, as will indices of unassigned cores.
/// Get the para (chain or thread) ID assigned to a particular core or index, if any. Core
/// indices out of bounds will return `None`, as will indices of unassigned cores.
pub(crate) fn core_para(core_index: CoreIndex) -> Option<ParaId> {
let cores = AvailabilityCores::<T>::get();
match cores.get(core_index.0 as usize).and_then(|c| c.as_ref()) {
@@ -587,8 +593,9 @@ impl<T: Config> Pallet<T> {
ValidatorGroups::<T>::get().get(group_index.0 as usize).map(|g| g.clone())
}
/// Get the group assigned to a specific core by index at the current block number. Result undefined if the core index is unknown
/// or the block number is less than the session start index.
/// Get the group assigned to a specific core by index at the current block number. Result
/// undefined if the core index is unknown or the block number is less than the session start
/// index.
pub(crate) fn group_assigned_to_core(
core: CoreIndex,
at: BlockNumberFor<T>,
@@ -622,10 +629,11 @@ impl<T: Config> Pallet<T> {
/// Returns an optional predicate that should be used for timing out occupied cores.
///
/// If `None`, no timing-out should be done. The predicate accepts the index of the core, and the
/// block number since which it has been occupied, and the respective parachain and parathread
/// timeouts, i.e. only within `max(config.chain_availability_period, config.thread_availability_period)`
/// of the last rotation would this return `Some`, unless there are no rotations.
/// If `None`, no timing-out should be done. The predicate accepts the index of the core, and
/// the block number since which it has been occupied, and the respective parachain and
/// parathread timeouts, i.e. only within `max(config.chain_availability_period,
/// config.thread_availability_period)` of the last rotation would this return `Some`, unless
/// there are no rotations.
///
/// This really should not be a box, but is working around a compiler limitation filed here:
/// https://github.com/rust-lang/rust/issues/73226