Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
Open
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
b6b9f8e
Undo v4 changes, move them to vstaging
Apr 19, 2023
c76ce40
Merge branch 'alex/parathreads_review' into alex/parathreads_vstaging
Apr 19, 2023
e2d5869
minor
Apr 19, 2023
fc276d6
Merge branch 'alex/parathreads_review' into alex/parathreads_vstaging
Apr 25, 2023
7baa04f
Merge branch 'alex/parathreads_review' into alex/parathreads_vstaging
May 19, 2023
94d24d5
Fix imports
May 19, 2023
f943c1a
Merge branch 'alex/parathreads_review' into alex/parathreads_vstaging
May 19, 2023
59f6bc2
Merge branch 'alex/parathreads_review' into alex/parathreads_vstaging
May 29, 2023
d65d96e
include version dispatch on availablity_cores() call
May 30, 2023
cbfa7a1
ifmt
May 30, 2023
2471334
Fix test-runtime
May 30, 2023
678b1d8
fix node runtime api test
May 30, 2023
13fa655
Undo RuntimeDebug -> Debug changes in v4
May 30, 2023
2cf57a8
runtime-api tests fix
May 30, 2023
4d01e65
Merge branch 'alex/parathreads_review' into alex/parathreads_vstaging
May 31, 2023
af57dd0
Fix removing api version by accident
May 31, 2023
b413cc7
Merge branch 'alex/parathreads_review' into alex/parathreads_vstaging
Jun 1, 2023
6fae5a3
Remove naked unwrap()s
Jun 1, 2023
a665df0
Add availability_cores_on_demand to mock and use that in tests
Jun 1, 2023
42bc527
Merge branch 'alex/parathreads_review' into alex/parathreads_vstaging
Jun 2, 2023
ea8a0c6
Merge branch 'alex/parathreads_review' into alex/parathreads_vstaging
Jun 5, 2023
a198b95
Merge branch 'alex/parathreads_review' into alex/parathreads_vstaging
Jun 6, 2023
918243e
Address PR comments
Jun 8, 2023
49ebc7d
Rename availability_cores_on_demand to ..._vstaging
Jun 8, 2023
c49582c
pebkac
Jun 8, 2023
6273880
minor refactor
Jun 8, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions node/network/collator-protocol/src/validator_side/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ use polkadot_node_subsystem::messages::{AllMessages, RuntimeApiMessage, RuntimeA
use polkadot_node_subsystem_test_helpers as test_helpers;
use polkadot_node_subsystem_util::TimeoutExt;
use polkadot_primitives::{
v4::CollatorRestrictionKind, vstaging::CollatorRestrictions, CollatorPair, CoreState,
GroupIndex, GroupRotationInfo, OccupiedCore, ScheduledCore, ValidatorId, ValidatorIndex,
CollatorPair, CollatorRestrictionKind, CollatorRestrictions, CoreState, GroupIndex,
GroupRotationInfo, OccupiedCore, ScheduledCore, ValidatorId, ValidatorIndex,
};
use polkadot_primitives_test_helpers::{
dummy_candidate_descriptor, dummy_candidate_receipt_bad_sig, dummy_hash,
Expand Down
20 changes: 12 additions & 8 deletions primitives/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,23 +41,27 @@ pub use v4::{
CandidateCommitments, CandidateDescriptor, CandidateEvent, CandidateHash, CandidateIndex,
CandidateReceipt, CheckedDisputeStatementSet, CheckedMultiDisputeStatementSet, CollatorId,
CollatorSignature, CommittedCandidateReceipt, CompactStatement, ConsensusLog, CoreIndex,
CoreOccupied, CoreState, DisputeState, DisputeStatement, DisputeStatementSet, DownwardMessage,
EncodeAs, ExecutorParam, ExecutorParams, ExecutorParamsHash, ExplicitDisputeStatement,
GroupIndex, GroupRotationInfo, Hash, HashT, HeadData, Header, HrmpChannelId, Id,
InboundDownwardMessage, InboundHrmpMessage, IndexedVec, InherentData,
InvalidDisputeStatementKind, Moment, MultiDisputeStatementSet, Nonce, OccupiedCore,
DisputeState, DisputeStatement, DisputeStatementSet, DownwardMessage, EncodeAs, ExecutorParam,
ExecutorParams, ExecutorParamsHash, ExplicitDisputeStatement, GroupIndex, GroupRotationInfo,
Hash, HashT, HeadData, Header, HrmpChannelId, Id, InboundDownwardMessage, InboundHrmpMessage,
IndexedVec, InherentData, InvalidDisputeStatementKind, Moment, MultiDisputeStatementSet, Nonce,
OccupiedCoreAssumption, OutboundHrmpMessage, ParathreadClaim, ParathreadEntry,
PersistedValidationData, PvfCheckStatement, PvfExecTimeoutKind, PvfPrepTimeoutKind,
RuntimeMetricLabel, RuntimeMetricLabelValue, RuntimeMetricLabelValues, RuntimeMetricLabels,
RuntimeMetricOp, RuntimeMetricUpdate, ScheduledCore, ScrapedOnChainVotes, SessionIndex,
SessionInfo, Signature, Signed, SignedAvailabilityBitfield, SignedAvailabilityBitfields,
SignedStatement, SigningContext, Slot, UncheckedSigned, UncheckedSignedAvailabilityBitfield,
RuntimeMetricOp, RuntimeMetricUpdate, ScrapedOnChainVotes, SessionIndex, SessionInfo,
Signature, Signed, SignedAvailabilityBitfield, SignedAvailabilityBitfields, SignedStatement,
SigningContext, Slot, UncheckedSigned, UncheckedSignedAvailabilityBitfield,
UncheckedSignedAvailabilityBitfields, UncheckedSignedStatement, UpgradeGoAhead,
UpgradeRestriction, UpwardMessage, ValidDisputeStatementKind, ValidationCode,
ValidationCodeHash, ValidatorId, ValidatorIndex, ValidatorSignature, ValidityAttestation,
ValidityError, ASSIGNMENT_KEY_TYPE_ID, LOWEST_PUBLIC_ID, MAX_CODE_SIZE, MAX_HEAD_DATA_SIZE,
MAX_POV_SIZE, PARACHAINS_INHERENT_IDENTIFIER, PARACHAIN_KEY_TYPE_ID,
};

pub use vstaging::{
CollatorRestrictionKind, CollatorRestrictions, CoreOccupied, CoreState, OccupiedCore,
ScheduledCore,
};

#[cfg(feature = "std")]
pub use v4::{AssignmentPair, CollatorPair, ValidatorPair};
10 changes: 5 additions & 5 deletions primitives/src/runtime_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,10 +111,10 @@
//! from the stable primitives.

use crate::{
BlockNumber, CandidateCommitments, CandidateEvent, CandidateHash, CommittedCandidateReceipt,
CoreState, DisputeState, ExecutorParams, GroupRotationInfo, OccupiedCoreAssumption,
PersistedValidationData, PvfCheckStatement, ScrapedOnChainVotes, SessionIndex, SessionInfo,
ValidatorId, ValidatorIndex, ValidatorSignature,
vstaging::CoreState, BlockNumber, CandidateCommitments, CandidateEvent, CandidateHash,
CommittedCandidateReceipt, DisputeState, ExecutorParams, GroupRotationInfo,
OccupiedCoreAssumption, PersistedValidationData, PvfCheckStatement, ScrapedOnChainVotes,
SessionIndex, SessionInfo, ValidatorId, ValidatorIndex, ValidatorSignature,
};
use parity_scale_codec::{Decode, Encode};
use polkadot_core_primitives as pcp;
Expand All @@ -123,7 +123,7 @@ use sp_std::{collections::btree_map::BTreeMap, prelude::*};

sp_api::decl_runtime_apis! {
/// The API for querying the state of parachains on-chain.
#[api_version(4)]
#[api_version(5)]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is good. You also need to add (can't leave a comment at the right):

#[changed_in(5)]
fn availability_cores() -> Vec<CoreState<H, N>>;

This way you can have two implementations - old and new ones. The intention of changed_in is to change the method signature. I'm not sure if it will work in the case 'same signature, different implementation'.

If this is the case - you can just add another function and handle the right one in the client code. This one breaks the semantics a little but imo it's fine. If pick this approach, you shouldn't touch base version here and just add another method:

#[api_version(5)]
fn availability_cores_with_parathreads() -> Vec<CoreState<H, N>>;

pub trait ParachainHost<H: Encode + Decode = pcp::v2::Hash, N: Encode + Decode = pcp::v2::BlockNumber> {
/// Get the current validators.
fn validators() -> Vec<ValidatorId>;
Expand Down
129 changes: 7 additions & 122 deletions primitives/src/v4/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ use bitvec::vec::BitVec;
use parity_scale_codec::{Decode, Encode};
use scale_info::TypeInfo;
use sp_std::{
collections::btree_set::BTreeSet,
marker::PhantomData,
prelude::*,
slice::{Iter, IterMut},
Expand All @@ -29,7 +28,7 @@ use sp_std::{

use application_crypto::KeyTypeId;
use inherents::InherentIdentifier;
use primitives::{OpaquePeerId, RuntimeDebug};
use primitives::RuntimeDebug;
use runtime_primitives::traits::{AppVerify, Header as HeaderT};
use sp_arithmetic::traits::{BaseArithmetic, Saturating};

Expand All @@ -51,9 +50,6 @@ pub use polkadot_parachain::primitives::{
#[cfg(feature = "std")]
use serde::{Deserialize, Serialize};

#[cfg(feature = "std")]
use sc_network::PeerId;

pub use sp_authority_discovery::AuthorityId as AuthorityDiscoveryId;
pub use sp_consensus_slots::Slot;
pub use sp_staking::SessionIndex;
Expand Down Expand Up @@ -800,124 +796,14 @@ pub struct ParathreadEntry {
pub retries: u32,
}

/// An Assignemnt for a paras going to produce a paras block.
#[derive(Clone, Encode, Decode, PartialEq, TypeInfo)]
#[cfg_attr(feature = "std", derive(Debug))]
pub struct Assignment {
/// Assignment's ParaId
pub para_id: Id,
/// Assignment's CollatorRestrictions
pub collator_restrictions: CollatorRestrictions,
}

impl Assignment {
/// Create a new `Assignment`.
pub fn new(para_id: Id, collator_restrictions: CollatorRestrictions) -> Self {
Assignment { para_id, collator_restrictions }
}
}

/// Restrictions on collators for a specific paras block.
#[derive(Clone, Encode, Decode, PartialEq, TypeInfo)]
#[cfg_attr(feature = "std", derive(Debug))]
pub struct CollatorRestrictions {
/// Collators to prefer/allow.
/// Empty set means no restrictions.
collator_peer_ids: BTreeSet<OpaquePeerId>,
restriction_kind: CollatorRestrictionKind,
}

impl CollatorRestrictions {
/// Specialised new function for parachains.
pub fn none() -> Self {
CollatorRestrictions {
collator_peer_ids: BTreeSet::new(),
restriction_kind: CollatorRestrictionKind::Preferred,
}
}

/// Create a new `CollatorRestrictions`.
pub fn new(
collator_peer_ids: BTreeSet<OpaquePeerId>,
restriction_kind: CollatorRestrictionKind,
) -> Self {
CollatorRestrictions { collator_peer_ids, restriction_kind }
}

/// Is peer_id allowed to collate?
#[cfg(feature = "std")]
pub fn can_collate(&self, peer_id: &PeerId) -> bool {
self.collator_peer_ids.is_empty() ||
match self.restriction_kind {
CollatorRestrictionKind::Preferred => true,
CollatorRestrictionKind::Required => {
let peer_id = OpaquePeerId(peer_id.to_bytes());
self.collator_peer_ids.contains(&peer_id)
},
}
}
}

/// How to apply the collator restrictions.
#[derive(Clone, Encode, Decode, PartialEq, TypeInfo)]
#[cfg_attr(feature = "std", derive(Debug))]
pub enum CollatorRestrictionKind {
/// peer ids mentioned will be preferred in connections, but others are still allowed.
Preferred,
/// Any collator with a `PeerId` not in the set of `CollatorRestrictions` will be rejected.
Required,
}

/// An entry tracking a paras
#[derive(Clone, Encode, Decode, TypeInfo, PartialEq, RuntimeDebug)]
pub struct ParasEntry {
/// The `Assignment`
pub assignment: Assignment,
/// Number of times this has been retried.
pub retries: u32,
}

impl From<Assignment> for ParasEntry {
fn from(assignment: Assignment) -> Self {
ParasEntry { assignment, retries: 0 }
}
}

impl ParasEntry {
/// Create a new `ParasEntry`.
pub fn new(assignment: Assignment) -> Self {
ParasEntry { assignment, retries: 0 }
}

/// Return `Id` from the underlying `Assignment`.
pub fn para_id(&self) -> Id {
self.assignment.para_id
}

/// Return `CollatorRestrictions` from the underlying `Assignment`.
pub fn collator_restrictions(&self) -> &CollatorRestrictions {
&self.assignment.collator_restrictions
}
}

/// What is occupying a specific availability core.
#[derive(Clone, Encode, Decode, TypeInfo, RuntimeDebug)]
#[cfg_attr(feature = "std", derive(PartialEq))]
pub enum CoreOccupied {
/// The core is not occupied.
Free,
/// A paras.
Paras(ParasEntry),
}

impl CoreOccupied {
/// Is core free?
pub fn is_free(&self) -> bool {
match self {
Self::Free => true,
Self::Paras(_) => false,
}
}
/// A parathread.
Parathread(ParathreadEntry),
/// A parachain.
Parachain,
}

/// A helper data-type for tracking validator-group rotations.
Expand Down Expand Up @@ -1047,11 +933,10 @@ impl<H, N> OccupiedCore<H, N> {
#[derive(Clone, Encode, Decode, TypeInfo, RuntimeDebug)]
#[cfg_attr(feature = "std", derive(PartialEq))]
pub struct ScheduledCore {
// TODO: Is the same as Assignment
/// The ID of a para scheduled.
pub para_id: Id,
/// The collator restrictions.
pub collator_restrictions: CollatorRestrictions,
/// The collator required to author the block, if any.
pub collator: Option<CollatorId>,
}

/// The state of a particular availability core.
Expand Down
Loading