CandidateBackingSubsystem (#1312)

* Updates guide for CandidateBacking

* Move assignment types to primitives

* Initial implementation.

* More functionality

* use assert_matches

* Changes to report misbehaviors

* Some fixes after a review

* Remove a blank line

* Update guide and some types

* Adds run_job function

* Some comments and refactorings

* Fix review

* Remove warnings

* Use summary in kicking off validation

* Parallelize requests

* Validation provides local and global validation params

* Test issued validity tracking

* Nits from review
This commit is contained in:
Fedor Sakharov
2020-07-09 23:23:58 +03:00
committed by GitHub
parent 54bace2b5d
commit c119627835
14 changed files with 2638 additions and 453 deletions
+3 -4
View File
@@ -25,7 +25,7 @@ use primitives::{
parachain::{
ValidatorId, AbridgedCandidateReceipt, ValidatorIndex, Id as ParaId,
AvailabilityBitfield as AvailabilityBitfield, SignedAvailabilityBitfields, SigningContext,
BackedCandidate,
BackedCandidate, CoreIndex, GroupIndex, CoreAssignment,
},
};
use frame_support::{
@@ -38,7 +38,7 @@ use bitvec::{order::Lsb0 as BitOrderLsb0, vec::BitVec};
use sp_staking::SessionIndex;
use sp_runtime::{DispatchError, traits::{One, Saturating}};
use crate::{configuration, paras, scheduler::{CoreIndex, GroupIndex, CoreAssignment}};
use crate::{configuration, paras};
/// 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.
@@ -498,7 +498,7 @@ mod tests {
use primitives::{BlockNumber, Hash};
use primitives::parachain::{
SignedAvailabilityBitfield, CompactStatement as Statement, ValidityAttestation, CollatorId,
CandidateCommitments, SignedStatement,
CandidateCommitments, SignedStatement, AssignmentKind,
};
use frame_support::traits::{OnFinalize, OnInitialize};
use keyring::Sr25519Keyring;
@@ -510,7 +510,6 @@ mod tests {
use crate::initializer::SessionChangeNotification;
use crate::configuration::HostConfiguration;
use crate::paras::ParaGenesisArgs;
use crate::scheduler::AssignmentKind;
fn default_config() -> HostConfiguration<BlockNumber> {
let mut config = HostConfiguration::default();
+5 -89
View File
@@ -38,7 +38,10 @@
use sp_std::prelude::*;
use sp_std::convert::TryInto;
use primitives::{
parachain::{Id as ParaId, CollatorId, ValidatorIndex},
parachain::{
Id as ParaId, ValidatorIndex, CoreAssignment, CoreOccupied, CoreIndex, AssignmentKind,
GroupIndex, ParathreadClaim, ParathreadEntry,
},
};
use frame_support::{
decl_storage, decl_module, decl_error,
@@ -52,41 +55,6 @@ use rand_chacha::ChaCha20Rng;
use crate::{configuration, paras, initializer::SessionChangeNotification};
/// The unique (during session) index of a core.
#[derive(Encode, Decode, Default, PartialOrd, Ord, Eq, PartialEq, Clone, Copy)]
#[cfg_attr(test, derive(Debug))]
pub struct CoreIndex(u32);
impl From<u32> for CoreIndex {
fn from(i: u32) -> CoreIndex {
CoreIndex(i)
}
}
/// The unique (during session) index of a validator group.
#[derive(Encode, Decode, Default, Clone, Copy)]
#[cfg_attr(test, derive(PartialEq, Debug))]
pub struct GroupIndex(u32);
impl From<u32> for GroupIndex {
fn from(i: u32) -> GroupIndex {
GroupIndex(i)
}
}
/// A claim on authoring the next block for a given parathread.
#[derive(Clone, Encode, Decode, Default)]
#[cfg_attr(test, derive(PartialEq, Debug))]
pub struct ParathreadClaim(pub ParaId, pub CollatorId);
/// An entry tracking a claim to ensure it does not pass the maximum number of retries.
#[derive(Clone, Encode, Decode, Default)]
#[cfg_attr(test, derive(PartialEq, Debug))]
pub struct ParathreadEntry {
claim: ParathreadClaim,
retries: u32,
}
/// A queued parathread entry, pre-assigned to a core.
#[derive(Encode, Decode, Default)]
#[cfg_attr(test, derive(PartialEq, Debug))]
@@ -125,58 +93,6 @@ impl ParathreadClaimQueue {
}
}
/// What is occupying a specific availability core.
#[derive(Clone, Encode, Decode)]
#[cfg_attr(test, derive(PartialEq, Debug))]
pub(crate) enum CoreOccupied {
Parathread(ParathreadEntry),
Parachain,
}
/// The assignment type.
#[derive(Clone, Encode, Decode)]
#[cfg_attr(test, derive(PartialEq, Debug))]
pub enum AssignmentKind {
Parachain,
Parathread(CollatorId, u32),
}
/// How a free core is scheduled to be assigned.
#[derive(Clone, Encode, Decode)]
#[cfg_attr(test, 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(crate) fn required_collator(&self) -> Option<&CollatorId> {
match self.kind {
AssignmentKind::Parachain => None,
AssignmentKind::Parathread(ref id, _) => Some(id),
}
}
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,
}
),
}
}
}
/// Reasons a core might be freed
pub enum FreedReason {
/// The core's work concluded and the parablock assigned to it is considered available.
@@ -670,7 +586,7 @@ impl<T: Trait> Module<T> {
mod tests {
use super::*;
use primitives::{BlockNumber, parachain::ValidatorId};
use primitives::{BlockNumber, parachain::{CollatorId, ValidatorId}};
use frame_support::traits::{OnFinalize, OnInitialize};
use keyring::Sr25519Keyring;