diff --git a/node/subsystem/src/messages.rs b/node/subsystem/src/messages.rs index ddea2639e1eb..9891692a062a 100644 --- a/node/subsystem/src/messages.rs +++ b/node/subsystem/src/messages.rs @@ -33,7 +33,7 @@ use polkadot_node_primitives::{ use polkadot_primitives::v1::{ AvailableData, BackedCandidate, BlockNumber, CandidateDescriptor, CandidateEvent, CandidateReceipt, CollatorId, CommittedCandidateReceipt, - CoreAssignment, CoreOccupied, CoreState, ErasureChunk, GlobalValidationData, GroupRotationInfo, + CoreState, ErasureChunk, GlobalValidationData, GroupRotationInfo, Hash, Id as ParaId, LocalValidationData, OccupiedCoreAssumption, OmittedValidationData, PoV, SessionIndex, SignedAvailabilityBitfield, ValidationCode, ValidatorId, ValidatorIndex, ValidatorSignature, @@ -345,19 +345,6 @@ impl ChainApiMessage { } } -/// The information on scheduler assignments that some somesystems may be querying. -#[derive(Debug, Clone)] -pub struct SchedulerRoster { - /// Validator-to-groups assignments. - pub validator_groups: Vec>, - /// All scheduled paras. - pub scheduled: Vec, - /// Upcoming paras (chains and threads). - pub upcoming: Vec, - /// Occupied cores. - pub availability_cores: Vec>, -} - /// A sender for the result of a runtime API request. pub type RuntimeApiSender = oneshot::Sender>; diff --git a/primitives/src/v1.rs b/primitives/src/v1.rs index 5436100022fb..086eface3167 100644 --- a/primitives/src/v1.rs +++ b/primitives/src/v1.rs @@ -434,53 +434,6 @@ pub enum CoreOccupied { Parachain, } -/// The assignment type. -#[derive(Clone, Encode, Decode)] -#[cfg_attr(feature = "std", derive(PartialEq, Debug))] -pub enum AssignmentKind { - /// A parachain. - Parachain, - /// A parathread. - Parathread(CollatorId, u32), -} - -/// How a free core is scheduled to be assigned. -#[derive(Clone, Encode, Decode)] -#[cfg_attr(feature = "std", derive(PartialEq, Debug))] -pub struct CoreAssignment { - /// The core that is assigned. - pub core: CoreIndex, - /// The unique ID of the para that is assigned to the core. - pub para_id: Id, - /// The kind of the assignment. - pub kind: AssignmentKind, - /// The index of the validator group assigned to the core. - pub group_idx: GroupIndex, -} - -impl CoreAssignment { - /// Get the ID of a collator who is required to collate this block. - pub fn required_collator(&self) -> Option<&CollatorId> { - match self.kind { - AssignmentKind::Parachain => None, - AssignmentKind::Parathread(ref id, _) => Some(id), - } - } - - /// Get the `CoreOccupied` from this. - pub fn to_core_occupied(&self) -> CoreOccupied { - match self.kind { - AssignmentKind::Parachain => CoreOccupied::Parachain, - AssignmentKind::Parathread(ref collator, retries) => CoreOccupied::Parathread( - ParathreadEntry { - claim: ParathreadClaim(self.para_id, collator.clone()), - retries, - } - ), - } - } -} - /// Validation data omitted from most candidate descriptor structs, as it can be derived from the /// relay-parent. #[derive(Clone, Encode, Decode)] diff --git a/runtime/parachains/src/inclusion.rs b/runtime/parachains/src/inclusion.rs index 07d2df50d1ef..0050e85724bb 100644 --- a/runtime/parachains/src/inclusion.rs +++ b/runtime/parachains/src/inclusion.rs @@ -25,7 +25,7 @@ use primitives::v1::{ validation_data_hash, ValidatorId, CandidateCommitments, CandidateDescriptor, ValidatorIndex, Id as ParaId, AvailabilityBitfield as AvailabilityBitfield, SignedAvailabilityBitfields, SigningContext, - BackedCandidate, CoreIndex, GroupIndex, CoreAssignment, CommittedCandidateReceipt, + BackedCandidate, CoreIndex, GroupIndex, CommittedCandidateReceipt, CandidateReceipt, HeadData, }; use frame_support::{ @@ -37,7 +37,7 @@ use bitvec::{order::Lsb0 as BitOrderLsb0, vec::BitVec}; use sp_staking::SessionIndex; use sp_runtime::{DispatchError, traits::{One, Saturating}}; -use crate::{configuration, paras}; +use crate::{configuration, paras, scheduler::CoreAssignment}; /// A bitfield signed by a validator indicating that it is keeping its piece of the erasure-coding /// for any backed candidates referred to by a `1` bit available. @@ -668,7 +668,6 @@ mod tests { use primitives::v1::{ SignedAvailabilityBitfield, CompactStatement as Statement, ValidityAttestation, CollatorId, CandidateCommitments, SignedStatement, CandidateDescriptor, ValidationCode, - AssignmentKind, }; use frame_support::traits::{OnFinalize, OnInitialize}; use keyring::Sr25519Keyring; @@ -680,6 +679,7 @@ mod tests { use crate::initializer::SessionChangeNotification; use crate::configuration::HostConfiguration; use crate::paras::ParaGenesisArgs; + use crate::scheduler::AssignmentKind; fn default_config() -> HostConfiguration { let mut config = HostConfiguration::default(); diff --git a/runtime/parachains/src/scheduler.rs b/runtime/parachains/src/scheduler.rs index a3ed466a2c2d..455a07f94e74 100644 --- a/runtime/parachains/src/scheduler.rs +++ b/runtime/parachains/src/scheduler.rs @@ -38,7 +38,7 @@ use sp_std::prelude::*; use sp_std::convert::TryInto; use primitives::v1::{ - Id as ParaId, ValidatorIndex, CoreAssignment, CoreOccupied, CoreIndex, AssignmentKind, + Id as ParaId, ValidatorIndex, CoreOccupied, CoreIndex, CollatorId, GroupIndex, ParathreadClaim, ParathreadEntry, GroupRotationInfo, ScheduledCore, }; use frame_support::{ @@ -105,6 +105,54 @@ pub enum FreedReason { TimedOut, } + +/// The assignment type. +#[derive(Clone, Encode, Decode)] +#[cfg_attr(feature = "std", derive(PartialEq, Debug))] +pub enum AssignmentKind { + /// A parachain. + Parachain, + /// A parathread. + Parathread(CollatorId, u32), +} + +/// How a free core is scheduled to be assigned. +#[derive(Clone, Encode, Decode)] +#[cfg_attr(feature = "std", derive(PartialEq, Debug))] +pub struct CoreAssignment { + /// The core that is assigned. + pub core: CoreIndex, + /// The unique ID of the para that is assigned to the core. + pub para_id: ParaId, + /// The kind of the assignment. + pub kind: AssignmentKind, + /// The index of the validator group assigned to the core. + pub group_idx: GroupIndex, +} + +impl CoreAssignment { + /// Get the ID of a collator who is required to collate this block. + pub fn required_collator(&self) -> Option<&CollatorId> { + match self.kind { + AssignmentKind::Parachain => None, + AssignmentKind::Parathread(ref id, _) => Some(id), + } + } + + /// Get the `CoreOccupied` from this. + pub fn to_core_occupied(&self) -> CoreOccupied { + match self.kind { + AssignmentKind::Parachain => CoreOccupied::Parachain, + AssignmentKind::Parathread(ref collator, retries) => CoreOccupied::Parathread( + ParathreadEntry { + claim: ParathreadClaim(self.para_id, collator.clone()), + retries, + } + ), + } + } +} + pub trait Trait: frame_system::Trait + configuration::Trait + paras::Trait { } decl_storage! {