From d0aac4ce7a94cb2d4c41d80d7debbfcc78afb8c5 Mon Sep 17 00:00:00 2001 From: Robert Habermeier Date: Wed, 8 Jul 2020 20:14:12 -0400 Subject: [PATCH 01/46] create a v1 primitives module --- core-primitives/src/lib.rs | 5 + primitives/src/lib.rs | 1 + primitives/src/parachain.rs | 81 --------- primitives/src/v1.rs | 330 ++++++++++++++++++++++++++++++++++++ 4 files changed, 336 insertions(+), 81 deletions(-) create mode 100644 primitives/src/v1.rs diff --git a/core-primitives/src/lib.rs b/core-primitives/src/lib.rs index d91ed3cfc197..ffb346467d9e 100644 --- a/core-primitives/src/lib.rs +++ b/core-primitives/src/lib.rs @@ -94,3 +94,8 @@ pub enum DownwardMessage { /// XCMP message for the Parachain. XCMPMessage(sp_std::vec::Vec), } + +/// V1 primitives. +pub mod v1 { + pub use super::*; +} diff --git a/primitives/src/lib.rs b/primitives/src/lib.rs index 6f0a0986c933..075891fec483 100644 --- a/primitives/src/lib.rs +++ b/primitives/src/lib.rs @@ -25,6 +25,7 @@ pub use polkadot_core_primitives::*; pub mod inclusion_inherent; pub mod parachain; +pub mod v1; pub use parity_scale_codec::Compact; diff --git a/primitives/src/parachain.rs b/primitives/src/parachain.rs index d0d3dce558c9..af68cc1eae82 100644 --- a/primitives/src/parachain.rs +++ b/primitives/src/parachain.rs @@ -752,87 +752,6 @@ impl FeeSchedule { } } -/// A bitfield concerning availability of backed candidates. -#[derive(PartialEq, Eq, Clone, Encode, Decode)] -#[cfg_attr(feature = "std", derive(Debug))] -pub struct AvailabilityBitfield(pub BitVec); - -impl From> for AvailabilityBitfield { - fn from(inner: BitVec) -> Self { - AvailabilityBitfield(inner) - } -} - -/// A bitfield signed by a particular validator about the availability of pending candidates. -pub type SignedAvailabilityBitfield = Signed; - -/// A set of signed availability bitfields. Should be sorted by validator index, ascending. -pub type SignedAvailabilityBitfields = Vec; - -/// A backed (or backable, depending on context) candidate. -// TODO: yes, this is roughly the same as AttestedCandidate. -// After https://github.com/paritytech/polkadot/issues/1250 -// they should be unified to this type. -#[derive(Encode, Decode, Clone, PartialEq, Eq, RuntimeDebug)] -pub struct BackedCandidate { - /// The candidate referred to. - pub candidate: AbridgedCandidateReceipt, - /// The validity votes themselves, expressed as signatures. - pub validity_votes: Vec, - /// The indices of the validators within the group, expressed as a bitfield. - pub validator_indices: BitVec, -} - -/// Verify the backing of the given candidate. -/// -/// Provide a lookup from the index of a validator within the group assigned to this para, -/// as opposed to the index of the validator within the overall validator set, as well as -/// the number of validators in the group. -/// -/// Also provide the signing context. -/// -/// Returns either an error, indicating that one of the signatures was invalid or that the index -/// was out-of-bounds, or the number of signatures checked. -pub fn check_candidate_backing + Encode>( - backed: &BackedCandidate, - signing_context: &SigningContext, - group_len: usize, - validator_lookup: impl Fn(usize) -> Option, -) -> Result { - if backed.validator_indices.len() != group_len { - return Err(()) - } - - if backed.validity_votes.len() > group_len { - return Err(()) - } - - // this is known, even in runtime, to be blake2-256. - let hash: Hash = backed.candidate.hash(); - - let mut signed = 0; - for ((val_in_group_idx, _), attestation) in backed.validator_indices.iter().enumerate() - .filter(|(_, signed)| **signed) - .zip(backed.validity_votes.iter()) - { - let validator_id = validator_lookup(val_in_group_idx).ok_or(())?; - let payload = attestation.signed_payload(hash.clone(), signing_context); - let sig = attestation.signature(); - - if sig.verify(&payload[..], &validator_id) { - signed += 1; - } else { - return Err(()) - } - } - - if signed != backed.validity_votes.len() { - return Err(()) - } - - Ok(signed) -} - sp_api::decl_runtime_apis! { /// The API for querying the state of parachains on-chain. #[api_version(3)] diff --git a/primitives/src/v1.rs b/primitives/src/v1.rs new file mode 100644 index 000000000000..c9add2ce88bc --- /dev/null +++ b/primitives/src/v1.rs @@ -0,0 +1,330 @@ +// Copyright 2017-2020 Parity Technologies (UK) Ltd. +// This file is part of Polkadot. + +// Polkadot is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// Polkadot is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with Polkadot. If not, see . + +//! V1 Primitives. + +use sp_std::prelude::*; +use sp_std::cmp::Ordering; +use parity_scale_codec::{Encode, Decode}; +use bitvec::vec::BitVec; + +#[cfg(feature = "std")] +use serde::{Serialize, Deserialize}; + +#[cfg(feature = "std")] +use primitives::{bytes, crypto::Pair}; +use primitives::RuntimeDebug; +use runtime_primitives::traits::{AppVerify, Block as BlockT}; +use inherents::InherentIdentifier; +use application_crypto::KeyTypeId; + +use runtime_primitives::traits::{BlakeTwo256, Hash as HashT}; + +// Export some core primitives. +pub use polkadot_core_primitives::v1::{ + BlockNumber, Moment, Signature, AccountPublic, AccountId, AccountIndex, + ChainId, Hash, Nonce, Balance, Header, Block, BlockId, UncheckedExtrinsic, + Remark, DownwardMessage, +}; + +// Export some polkadot-parachain primitives +pub use polkadot_parachain::primitives::{ + Id, ParachainDispatchOrigin, LOWEST_USER_ID, UpwardMessage, HeadData, BlockData, + ValidationCode, +}; + +// Export some basic parachain primitives from v0. +pub use crate::parachain::{ + CollatorId, CollatorSignature, PARACHAIN_KEY_TYPE_ID, ValidatorId, ValidatorIndex, + ValidatorPair, ValidatorSignature, SigningContext, Signed, ValidityAttestation, + CompactStatement, SignedStatement. +}; + +// More exports for std. +#[cfg(feature = "std")] +pub use crate::parachain::CollatorPair; + +/// Get a collator signature payload on a relay-parent, block-data combo. +pub fn collator_signature_payload>( + relay_parent: &H, + para_id: &Id, + pov_hash: &H, +) -> [u8; 68] { + // 32-byte hash length is protected in a test below. + let mut payload = [0u8; 68]; + + payload[0..32].copy_from_slice(relay_parent.as_ref()); + u32::from(*para_id).using_encoded(|s| payload[32..32 + s.len()].copy_from_slice(s)); + payload[36..68].copy_from_slice(pov_hash.as_ref()); + + payload +} + +fn check_collator_signature>( + relay_parent: &H, + para_id: &Id, + pov_hash: &H, + collator: &CollatorId, + signature: &CollatorSignature, +) -> Result<(),()> { + let payload = collator_signature_payload(relay_parent, para_id, pov_hash); + if signature.verify(&payload[..], collator) { + Ok(()) + } else { + Err(()) + } +} + +/// A unique descriptor of the candidate receipt. +#[derive(PartialEq, Eq, Clone, Encode, Decode)] +#[cfg_attr(feature = "std", derive(Debug, Default))] +pub struct CandidateDescriptor { + /// The ID of the para this is a candidate for. + pub para_id: Id, + /// The hash of the relay-chain block this is executed in the context of. + pub relay_parent: H, + /// The collator's sr25519 public key. + pub collator: CollatorId, + /// Signature on blake2-256 of components of this receipt: + /// The parachain index, the relay parent, and the pov_hash. + pub signature: CollatorSignature, + /// The blake2-256 hash of the pov. + pub pov_hash: Hash, +} + +impl CandidateDescriptor { + /// Check the signature of the collator within this descriptor. + pub fn check_collator_signature(&self) -> Result<(), ()> { + check_collator_signature( + &self.relay_parent, + &self.para_id, + &self.pov_hash, + &self.collator, + &self.signature, + ) + } +} + +/// A candidate-receipt. +#[derive(PartialEq, Eq, Clone, Encode, Decode)] +#[cfg_attr(feature = "std", derive(Debug, Default))] +pub struct CandidateReceipt { + /// The descriptor of the candidate. + pub descriptor: CandidateDescriptor, + /// The hash of the encoded commitments made as a result of candidate execution. + pub commitments_hash: Hash, +} + +impl CandidateReceipt { + /// Get a reference to the candidate descriptor. + pub fn descriptor(&self) -> &CandidateDescriptor { + &self.descriptor + } + + /// Computes the blake2-256 hash of the receipt. + pub fn hash(&self) -> Hash where H: Encode { + BlakeTwo256::hash_of(self) + } +} + +/// All data pertaining to the execution of a para candidate. +#[derive(PartialEq, Eq, Clone, Encode, Decode)] +#[cfg_attr(feature = "std", derive(Debug, Default))] +pub struct FullCandidateReceipt { + /// The inner candidate receipt. + pub inner: CandidateReceipt, + /// The global validation schedule. + pub global_validation: GlobalValidationSchedule, + /// The local validation data. + pub local_validation: LocalValidationData, +} + +/// A candidate-receipt with commitments directly included. +#[derive(PartialEq, Eq, Clone, Encode, Decode)] +#[cfg_attr(feature = "std", derive(Debug, Default))] +pub struct CommittedCandidateReceipt { + /// The descriptor of the candidate. + pub descriptor: CandidateDescriptor, + /// The commitments of the candidate receipt. + pub commitments: CandidateCommitments, +} + +impl CommittedCandidateReceipt { + /// Get a reference to the candidate descriptor. + pub fn descriptor(&self) -> &CandidateDescriptor { + &self.descriptor + } +} + +impl CommittedCandidateReceipt { + /// Transforms this into a plain CandidateReceipt. + pub fn to_plain(&self) -> CandidateReceipt { + CandidateReceipt { + descriptor: self.descriptor.clone(), + commitments_hash: BlakeTwo256::hash_of(&self.commitments), + } + } + + /// Computes the hash of the committed candidate receipt. + /// + /// This computes the canonical hash, not the hash of the directly encoded data. + /// Thus this is a shortcut for `candidate.to_plain().hash()`. + pub fn hash(&self) -> Hash where H: Encode { + self.to_plain().hash() + } +} + +/// Extra data that is needed along with the other fields in a `CandidateReceipt` +/// to fully validate the candidate. These fields are parachain-specific. +#[derive(PartialEq, Eq, Clone, Encode, Decode)] +#[cfg_attr(feature = "std", derive(Debug, Default))] +pub struct LocalValidationData { + /// The parent head-data. + pub parent_head: HeadData, + /// The balance of the parachain at the moment of validation. + pub balance: Balance, + /// The blake2-256 hash of the validation code used to execute the candidate. + pub validation_code_hash: Hash, + /// Whether the parachain is allowed to upgrade its validation code. + /// + /// This is `Some` if so, and contains the number of the minimum relay-chain + /// height at which the upgrade will be applied, if an upgrade is signaled + /// now. + /// + /// A parachain should enact its side of the upgrade at the end of the first + /// parablock executing in the context of a relay-chain block with at least this + /// height. This may be equal to the current perceived relay-chain block height, in + /// which case the code upgrade should be applied at the end of the signaling + /// block. + pub code_upgrade_allowed: Option, +} + +/// Extra data that is needed along with the other fields in a `CandidateReceipt` +/// to fully validate the candidate. +/// +/// These are global parameters that apply to all candidates in a block. +#[derive(PartialEq, Eq, Clone, Encode, Decode)] +#[cfg_attr(feature = "std", derive(Debug, Default))] +pub struct GlobalValidationSchedule { + /// The maximum code size permitted, in bytes. + pub max_code_size: u32, + /// The maximum head-data size permitted, in bytes. + pub max_head_data_size: u32, + /// The relay-chain block number this is in the context of. + pub block_number: BlockNumber, +} + +/// Commitments made in a `CandidateReceipt`. Many of these are outputs of validation. +#[derive(PartialEq, Eq, Clone, Encode, Decode)] +#[cfg_attr(feature = "std", derive(Debug, Default))] +pub struct CandidateCommitments { + /// Fees paid from the chain to the relay chain validators. + pub fees: Balance, + /// Messages destined to be interpreted by the Relay chain itself. + pub upward_messages: Vec, + /// The root of a block's erasure encoding Merkle tree. + pub erasure_root: Hash, + /// New validation code. + pub new_validation_code: Option, + /// The head-data produced as a result of execution. + pub head_data: HeadData, +} + +/// A Proof-of-Validity +#[derive(PartialEq, Eq, Clone, Encode, Decode)] +#[cfg_attr(feature = "std", derive(Debug))] +pub struct PoV { + /// The block witness data. + pub block_data: BlockData, +} + +/// A bitfield concerning availability of backed candidates. +#[derive(PartialEq, Eq, Clone, Encode, Decode)] +#[cfg_attr(feature = "std", derive(Debug))] +pub struct AvailabilityBitfield(pub BitVec); + +impl From> for AvailabilityBitfield { + fn from(inner: BitVec) -> Self { + AvailabilityBitfield(inner) + } +} + +/// A bitfield signed by a particular validator about the availability of pending candidates. +pub type SignedAvailabilityBitfield = Signed; + +/// A set of signed availability bitfields. Should be sorted by validator index, ascending. +pub type SignedAvailabilityBitfields = Vec; + +/// A backed (or backable, depending on context) candidate. +#[derive(Encode, Decode, Clone, PartialEq, Eq, RuntimeDebug)] +pub struct BackedCandidate { + /// The candidate referred to. + pub candidate: CommittedCandidateReceipt, + /// The validity votes themselves, expressed as signatures. + pub validity_votes: Vec, + /// The indices of the validators within the group, expressed as a bitfield. + pub validator_indices: BitVec, +} + +/// Verify the backing of the given candidate. +/// +/// Provide a lookup from the index of a validator within the group assigned to this para, +/// as opposed to the index of the validator within the overall validator set, as well as +/// the number of validators in the group. +/// +/// Also provide the signing context. +/// +/// Returns either an error, indicating that one of the signatures was invalid or that the index +/// was out-of-bounds, or the number of signatures checked. +pub fn check_candidate_backing + Clone + Encode>( + backed: &BackedCandidate, + signing_context: &SigningContext, + group_len: usize, + validator_lookup: impl Fn(usize) -> Option, +) -> Result { + if backed.validator_indices.len() != group_len { + return Err(()) + } + + if backed.validity_votes.len() > group_len { + return Err(()) + } + + // this is known, even in runtime, to be blake2-256. + let hash: Hash = backed.candidate.hash(); + + let mut signed = 0; + for ((val_in_group_idx, _), attestation) in backed.validator_indices.iter().enumerate() + .filter(|(_, signed)| **signed) + .zip(backed.validity_votes.iter()) + { + let validator_id = validator_lookup(val_in_group_idx).ok_or(())?; + let payload = attestation.signed_payload(hash.clone(), signing_context); + let sig = attestation.signature(); + + if sig.verify(&payload[..], &validator_id) { + signed += 1; + } else { + return Err(()) + } + } + + if signed != backed.validity_votes.len() { + return Err(()) + } + + Ok(signed) +} From db8a5de1818f9d2aa869257d781d6f430b25450a Mon Sep 17 00:00:00 2001 From: Robert Habermeier Date: Wed, 8 Jul 2020 20:37:15 -0400 Subject: [PATCH 02/46] Improve guide on availability types --- .../src/types/availability.md | 31 +++++++++++++++++++ .../implementers-guide/src/types/candidate.md | 1 + 2 files changed, 32 insertions(+) diff --git a/roadmap/implementers-guide/src/types/availability.md b/roadmap/implementers-guide/src/types/availability.md index 3362908d6b63..dac155e19381 100644 --- a/roadmap/implementers-guide/src/types/availability.md +++ b/roadmap/implementers-guide/src/types/availability.md @@ -21,3 +21,34 @@ Often referred to as PoV, this is a type-safe wrapper around bytes (`Vec`) w ```rust struct PoV(Vec); ``` + +## Omitted Validation Data + +Validation data that is often omitted from types describing candidates as it can be derived from the relay-parent of the candidate. However, with the expectation of state pruning, these are best kept available elsewhere as well. + +This contains the [`GlobalValidationSchedule`](candidate.md#globalvalidationschedule) and [`LocalValidationData`](candidate.md#localvalidationdata) + +```rust +struct OmittedValidationData { + /// The global validation schedule. + pub global_validation: GlobalValidationSchedule, + /// The local validation data. + pub local_validation: LocalValidationData, +} +``` + + +## Available Data + +This is the data we want to keep available for each [candidate](candidate.md) included in the relay chain. + +```rust +struct AvailableData { + /// The Proof-of-Validation of the candidate. + pub pov: PoV, + /// The omitted validation data. + pub omitted_validation: OmittedValidationData, +} +``` + +> TODO: With XCMP, we also need to keep available the outgoing messages as a result of para-validation. diff --git a/roadmap/implementers-guide/src/types/candidate.md b/roadmap/implementers-guide/src/types/candidate.md index fdba6919e57c..7c9b4dd921e5 100644 --- a/roadmap/implementers-guide/src/types/candidate.md +++ b/roadmap/implementers-guide/src/types/candidate.md @@ -1,6 +1,7 @@ # Candidate Types Para candidates are some of the most common types, both within the runtime and on the Node-side. +Candidates are the fundamental datatype for advancing parachains and parathreads, encapsulating the collator's signature, the context of the parablock, the commitments to the output, and a commitment to the data which proves it valid. In a way, this entire guide is about these candidates: how they are scheduled, constructed, backed, included, and challenged. From 13120931b8326a5885e5f9f67a0d7e87cc59df06 Mon Sep 17 00:00:00 2001 From: Robert Habermeier Date: Wed, 8 Jul 2020 20:45:53 -0400 Subject: [PATCH 03/46] punctuate --- primitives/src/v1.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/primitives/src/v1.rs b/primitives/src/v1.rs index c9add2ce88bc..4ba329a8a1a2 100644 --- a/primitives/src/v1.rs +++ b/primitives/src/v1.rs @@ -50,7 +50,7 @@ pub use polkadot_parachain::primitives::{ pub use crate::parachain::{ CollatorId, CollatorSignature, PARACHAIN_KEY_TYPE_ID, ValidatorId, ValidatorIndex, ValidatorPair, ValidatorSignature, SigningContext, Signed, ValidityAttestation, - CompactStatement, SignedStatement. + CompactStatement, SignedStatement, }; // More exports for std. From cbd848adb3fc70d1a83eb9ea262d7e94b175f574 Mon Sep 17 00:00:00 2001 From: Robert Habermeier Date: Wed, 8 Jul 2020 20:57:49 -0400 Subject: [PATCH 04/46] new parachains runtime uses new primitives --- primitives/src/v1.rs | 13 ++- runtime/parachains/src/configuration.rs | 4 +- runtime/parachains/src/inclusion.rs | 85 ++++++++++---------- runtime/parachains/src/inclusion_inherent.rs | 2 +- runtime/parachains/src/initializer.rs | 4 +- runtime/parachains/src/mock.rs | 5 +- runtime/parachains/src/paras.rs | 6 +- runtime/parachains/src/scheduler.rs | 6 +- 8 files changed, 64 insertions(+), 61 deletions(-) diff --git a/primitives/src/v1.rs b/primitives/src/v1.rs index 4ba329a8a1a2..aa241f233043 100644 --- a/primitives/src/v1.rs +++ b/primitives/src/v1.rs @@ -61,7 +61,7 @@ pub use crate::parachain::CollatorPair; pub fn collator_signature_payload>( relay_parent: &H, para_id: &Id, - pov_hash: &H, + pov_hash: &Hash, ) -> [u8; 68] { // 32-byte hash length is protected in a test below. let mut payload = [0u8; 68]; @@ -76,7 +76,7 @@ pub fn collator_signature_payload>( fn check_collator_signature>( relay_parent: &H, para_id: &Id, - pov_hash: &H, + pov_hash: &Hash, collator: &CollatorId, signature: &CollatorSignature, ) -> Result<(),()> { @@ -105,7 +105,7 @@ pub struct CandidateDescriptor { pub pov_hash: Hash, } -impl CandidateDescriptor { +impl> CandidateDescriptor { /// Check the signature of the collator within this descriptor. pub fn check_collator_signature(&self) -> Result<(), ()> { check_collator_signature( @@ -279,6 +279,13 @@ pub struct BackedCandidate { pub validator_indices: BitVec, } +impl BackedCandidate { + /// Get a reference to the descriptor of the para. + pub fn descriptor(&self) -> &CandidateDescriptor { + &self.candidate.descriptor + } +} + /// Verify the backing of the given candidate. /// /// Provide a lookup from the index of a validator within the group assigned to this para, diff --git a/runtime/parachains/src/configuration.rs b/runtime/parachains/src/configuration.rs index 792dfe89a7b2..40688041b265 100644 --- a/runtime/parachains/src/configuration.rs +++ b/runtime/parachains/src/configuration.rs @@ -19,9 +19,7 @@ //! Configuration can change only at session boundaries and is buffered until then. use sp_std::prelude::*; -use primitives::{ - parachain::{ValidatorId}, -}; +use primitives::v1::ValidatorId; use frame_support::{ decl_storage, decl_module, decl_error, dispatch::DispatchResult, diff --git a/runtime/parachains/src/inclusion.rs b/runtime/parachains/src/inclusion.rs index 5819e3a06c47..582aede674bd 100644 --- a/runtime/parachains/src/inclusion.rs +++ b/runtime/parachains/src/inclusion.rs @@ -21,12 +21,10 @@ //! to included. use sp_std::prelude::*; -use primitives::{ - parachain::{ - ValidatorId, AbridgedCandidateReceipt, ValidatorIndex, Id as ParaId, - AvailabilityBitfield as AvailabilityBitfield, SignedAvailabilityBitfields, SigningContext, - BackedCandidate, - }, +use primitives::v1::{ + ValidatorId, CommittedCandidateReceipt, ValidatorIndex, Id as ParaId, + AvailabilityBitfield as AvailabilityBitfield, SignedAvailabilityBitfields, SigningContext, + BackedCandidate, }; use frame_support::{ decl_storage, decl_module, decl_error, ensure, dispatch::DispatchResult, IterableStorageMap, @@ -53,13 +51,15 @@ pub struct AvailabilityBitfieldRecord { } /// A backed candidate pending availability. +// TODO: split this type and change this to hold a plain `CandidateReceipt`. +// https://github.com/paritytech/polkadot/issues/1357 #[derive(Encode, Decode, PartialEq)] #[cfg_attr(test, derive(Debug))] pub struct CandidatePendingAvailability { /// The availability core this is assigned to. core: CoreIndex, /// The candidate receipt itself. - receipt: AbridgedCandidateReceipt, + receipt: CommittedCandidateReceipt, /// The received availability votes. One bit per validator. availability_votes: BitVec, /// The block number of the relay-parent of the receipt. @@ -213,7 +213,10 @@ impl Module { let validator_public = &validators[signed_bitfield.validator_index() as usize]; - signed_bitfield.check_signature(&signing_context, validator_public).map_err(|_| Error::::InvalidBitfieldSignature)?; + signed_bitfield.check_signature( + &signing_context, + validator_public, + ).map_err(|_| Error::::InvalidBitfieldSignature)?; last_index = Some(signed_bitfield.validator_index()); } @@ -331,11 +334,11 @@ impl Module { // list. 'a: for candidate in &candidates { - let para_id = candidate.candidate.parachain_index; + let para_id = candidate.descriptor().para_id; // we require that the candidate is in the context of the parent block. ensure!( - candidate.candidate.relay_parent == parent_hash, + candidate.descriptor().relay_parent == parent_hash, Error::::CandidateNotInParentContext, ); @@ -348,17 +351,17 @@ impl Module { ensure!(code_upgrade_allowed, Error::::PrematureCodeUpgrade); ensure!( - candidate.candidate.check_signature().is_ok(), + candidate.descriptor().check_collator_signature().is_ok(), Error::::NotCollatorSigned, ); for (i, assignment) in scheduled[skip..].iter().enumerate() { check_assignment_in_order(assignment)?; - if candidate.candidate.parachain_index == assignment.para_id { + if candidate.descriptor().para_id == assignment.para_id { if let Some(required_collator) = assignment.required_collator() { ensure!( - required_collator == &candidate.candidate.collator, + required_collator == &candidate.descriptor().collator, Error::::WrongCollator, ); } @@ -377,7 +380,7 @@ impl Module { // check the signatures in the backing and that it is a majority. { let maybe_amount_validated - = primitives::parachain::check_candidate_backing( + = primitives::v1::check_candidate_backing( &candidate, &signing_context, group_vals.len(), @@ -419,7 +422,7 @@ impl Module { // one more sweep for actually writing to storage. for (candidate, core) in candidates.into_iter().zip(core_indices.iter().cloned()) { - let para_id = candidate.candidate.parachain_index; + let para_id = candidate.descriptor().para_id; // initialize all availability votes to 0. let availability_votes: BitVec @@ -438,7 +441,7 @@ impl Module { fn enact_candidate( relay_parent_number: T::BlockNumber, - receipt: AbridgedCandidateReceipt, + receipt: CommittedCandidateReceipt, ) -> Weight { let commitments = receipt.commitments; let config = >::config(); @@ -447,15 +450,15 @@ impl Module { let mut weight = T::DbWeight::get().reads_writes(1, 0); if let Some(new_code) = commitments.new_validation_code { weight += >::schedule_code_upgrade( - receipt.parachain_index, + receipt.descriptor.para_id, new_code, relay_parent_number + config.validation_upgrade_delay, ); } weight + >::note_new_head( - receipt.parachain_index, - receipt.head_data, + receipt.descriptor.para_id, + commitments.head_data, relay_parent_number, ) } @@ -495,8 +498,8 @@ const fn availability_threshold(n_validators: usize) -> usize { mod tests { use super::*; - use primitives::{BlockNumber, Hash}; - use primitives::parachain::{ + use primitives::v1::{BlockNumber, Hash}; + use primitives::v1::{ SignedAvailabilityBitfield, CompactStatement as Statement, ValidityAttestation, CollatorId, CandidateCommitments, SignedStatement, }; @@ -546,22 +549,22 @@ mod tests { fn collator_sign_candidate( collator: Sr25519Keyring, - candidate: &mut AbridgedCandidateReceipt, + candidate: &mut CommittedCandidateReceipt, ) { candidate.collator = collator.public().into(); - let payload = primitives::parachain::collator_signature_payload( + let payload = primitives::v1::collator_signature_payload( &candidate.relay_parent, - &candidate.parachain_index, + &candidate.para_id, &candidate.pov_block_hash, ); candidate.signature = collator.sign(&payload[..]).into(); - assert!(candidate.check_signature().is_ok()); + assert!(candidate.check_collator_signature().is_ok()); } fn back_candidate( - candidate: AbridgedCandidateReceipt, + candidate: CommittedCandidateReceipt, validators: &[Sr25519Keyring], group: &[ValidatorIndex], signing_context: &SigningContext, @@ -604,7 +607,7 @@ mod tests { BackingKind::Lacking => false, }; - let successfully_backed = primitives::parachain::check_candidate_backing( + let successfully_backed = primitives::v1::check_candidate_backing( &backed, signing_context, group.len(), @@ -896,7 +899,7 @@ mod tests { >::insert(chain_a, CandidatePendingAvailability { core: CoreIndex::from(0), - receipt: AbridgedCandidateReceipt { + receipt: CommittedCandidateReceipt { parachain_index: chain_a, head_data: vec![1, 2, 3, 4].into(), ..Default::default() @@ -908,7 +911,7 @@ mod tests { >::insert(chain_b, CandidatePendingAvailability { core: CoreIndex::from(1), - receipt: AbridgedCandidateReceipt { + receipt: CommittedCandidateReceipt { parachain_index: chain_b, head_data: vec![5, 6, 7, 8].into(), ..Default::default() @@ -1044,7 +1047,7 @@ mod tests { // unscheduled candidate. { - let mut candidate = AbridgedCandidateReceipt { + let mut candidate = CommittedCandidateReceipt { parachain_index: chain_a, relay_parent: System::parent_hash(), pov_block_hash: Hash::from([1; 32]), @@ -1072,13 +1075,13 @@ mod tests { // candidates out of order. { - let mut candidate_a = AbridgedCandidateReceipt { + let mut candidate_a = CommittedCandidateReceipt { parachain_index: chain_a, relay_parent: System::parent_hash(), pov_block_hash: Hash::from([1; 32]), ..Default::default() }; - let mut candidate_b = AbridgedCandidateReceipt { + let mut candidate_b = CommittedCandidateReceipt { parachain_index: chain_b, relay_parent: System::parent_hash(), pov_block_hash: Hash::from([2; 32]), @@ -1120,7 +1123,7 @@ mod tests { // candidate not backed. { - let mut candidate = AbridgedCandidateReceipt { + let mut candidate = CommittedCandidateReceipt { parachain_index: chain_a, relay_parent: System::parent_hash(), pov_block_hash: Hash::from([1; 32]), @@ -1151,7 +1154,7 @@ mod tests { let wrong_parent_hash = Hash::from([222; 32]); assert!(System::parent_hash() != wrong_parent_hash); - let mut candidate = AbridgedCandidateReceipt { + let mut candidate = CommittedCandidateReceipt { parachain_index: chain_a, relay_parent: wrong_parent_hash, pov_block_hash: Hash::from([1; 32]), @@ -1179,7 +1182,7 @@ mod tests { // candidate has wrong collator. { - let mut candidate = AbridgedCandidateReceipt { + let mut candidate = CommittedCandidateReceipt { parachain_index: thread_a, relay_parent: System::parent_hash(), pov_block_hash: Hash::from([1; 32]), @@ -1213,7 +1216,7 @@ mod tests { // candidate not well-signed by collator. { - let mut candidate = AbridgedCandidateReceipt { + let mut candidate = CommittedCandidateReceipt { parachain_index: thread_a, relay_parent: System::parent_hash(), pov_block_hash: Hash::from([1; 32]), @@ -1245,7 +1248,7 @@ mod tests { // para occupied - reject. { - let mut candidate = AbridgedCandidateReceipt { + let mut candidate = CommittedCandidateReceipt { parachain_index: chain_a, relay_parent: System::parent_hash(), pov_block_hash: Hash::from([1; 32]), @@ -1284,7 +1287,7 @@ mod tests { // interfering code upgrade - reject { - let mut candidate = AbridgedCandidateReceipt { + let mut candidate = CommittedCandidateReceipt { parachain_index: chain_a, relay_parent: System::parent_hash(), pov_block_hash: Hash::from([1; 32]), @@ -1382,7 +1385,7 @@ mod tests { group_idx: GroupIndex::from(2), }; - let mut candidate_a = AbridgedCandidateReceipt { + let mut candidate_a = CommittedCandidateReceipt { parachain_index: chain_a, relay_parent: System::parent_hash(), pov_block_hash: Hash::from([1; 32]), @@ -1393,7 +1396,7 @@ mod tests { &mut candidate_a, ); - let mut candidate_b = AbridgedCandidateReceipt { + let mut candidate_b = CommittedCandidateReceipt { parachain_index: chain_b, relay_parent: System::parent_hash(), pov_block_hash: Hash::from([2; 32]), @@ -1404,7 +1407,7 @@ mod tests { &mut candidate_b, ); - let mut candidate_c = AbridgedCandidateReceipt { + let mut candidate_c = CommittedCandidateReceipt { parachain_index: thread_a, relay_parent: System::parent_hash(), pov_block_hash: Hash::from([3; 32]), diff --git a/runtime/parachains/src/inclusion_inherent.rs b/runtime/parachains/src/inclusion_inherent.rs index 282b6f3b8a21..6ce93feab3f1 100644 --- a/runtime/parachains/src/inclusion_inherent.rs +++ b/runtime/parachains/src/inclusion_inherent.rs @@ -24,7 +24,7 @@ use sp_std::prelude::*; use primitives::{ inclusion_inherent, - parachain::{BackedCandidate, SignedAvailabilityBitfields}, + v1::{BackedCandidate, SignedAvailabilityBitfields}, }; use frame_support::{ decl_error, decl_module, decl_storage, ensure, diff --git a/runtime/parachains/src/initializer.rs b/runtime/parachains/src/initializer.rs index 0f7f4b74eccf..79096e0925c0 100644 --- a/runtime/parachains/src/initializer.rs +++ b/runtime/parachains/src/initializer.rs @@ -21,9 +21,7 @@ use sp_std::prelude::*; use frame_support::weights::Weight; -use primitives::{ - parachain::{ValidatorId}, -}; +use primitives::v1::ValidatorId; use frame_support::{ decl_storage, decl_module, decl_error, traits::Randomness, }; diff --git a/runtime/parachains/src/mock.rs b/runtime/parachains/src/mock.rs index 9cc9f2329b8f..8eb45359da48 100644 --- a/runtime/parachains/src/mock.rs +++ b/runtime/parachains/src/mock.rs @@ -24,10 +24,7 @@ use sp_runtime::{ BlakeTwo256, IdentityLookup, }, }; -use primitives::{ - BlockNumber, - Header, -}; +use primitives::v1::{BlockNumber, Header}; use frame_support::{ impl_outer_origin, impl_outer_dispatch, parameter_types, weights::Weight, traits::Randomness as RandomnessT, diff --git a/runtime/parachains/src/paras.rs b/runtime/parachains/src/paras.rs index 8c095751b3f6..0117089f1106 100644 --- a/runtime/parachains/src/paras.rs +++ b/runtime/parachains/src/paras.rs @@ -26,8 +26,8 @@ use sp_std::prelude::*; use sp_std::marker::PhantomData; use sp_runtime::traits::One; -use primitives::{ - parachain::{Id as ParaId, ValidationCode, HeadData}, +use primitives::v1::{ + Id as ParaId, ValidationCode, HeadData, }; use frame_support::{ decl_storage, decl_module, decl_error, @@ -541,7 +541,7 @@ impl Module { #[cfg(test)] mod tests { use super::*; - use primitives::BlockNumber; + use primitives::v1::BlockNumber; use frame_support::traits::{OnFinalize, OnInitialize}; use crate::mock::{new_test_ext, Paras, System, GenesisConfig as MockGenesisConfig}; diff --git a/runtime/parachains/src/scheduler.rs b/runtime/parachains/src/scheduler.rs index 212c782d6463..1231c37ecb45 100644 --- a/runtime/parachains/src/scheduler.rs +++ b/runtime/parachains/src/scheduler.rs @@ -37,8 +37,8 @@ use sp_std::prelude::*; use sp_std::convert::TryInto; -use primitives::{ - parachain::{Id as ParaId, CollatorId, ValidatorIndex}, +use primitives::v1::{ + Id as ParaId, CollatorId, ValidatorIndex, }; use frame_support::{ decl_storage, decl_module, decl_error, @@ -670,7 +670,7 @@ impl Module { mod tests { use super::*; - use primitives::{BlockNumber, parachain::ValidatorId}; + use primitives::v1::{BlockNumber, ValidatorId}; use frame_support::traits::{OnFinalize, OnInitialize}; use keyring::Sr25519Keyring; From 14425bd2c95847e6950ef22d1063c653f9239648 Mon Sep 17 00:00:00 2001 From: Robert Habermeier Date: Wed, 8 Jul 2020 21:11:23 -0400 Subject: [PATCH 05/46] tests of new runtime now use new primitives --- runtime/parachains/src/inclusion.rs | 157 ++++++++++++++++------------ 1 file changed, 91 insertions(+), 66 deletions(-) diff --git a/runtime/parachains/src/inclusion.rs b/runtime/parachains/src/inclusion.rs index 582aede674bd..aec31f1bf646 100644 --- a/runtime/parachains/src/inclusion.rs +++ b/runtime/parachains/src/inclusion.rs @@ -501,7 +501,7 @@ mod tests { use primitives::v1::{BlockNumber, Hash}; use primitives::v1::{ SignedAvailabilityBitfield, CompactStatement as Statement, ValidityAttestation, CollatorId, - CandidateCommitments, SignedStatement, + CandidateCommitments, SignedStatement, CandidateDescriptor, HeadData, ValidationCode, }; use frame_support::traits::{OnFinalize, OnInitialize}; use keyring::Sr25519Keyring; @@ -551,16 +551,16 @@ mod tests { collator: Sr25519Keyring, candidate: &mut CommittedCandidateReceipt, ) { - candidate.collator = collator.public().into(); + candidate.descriptor.collator = collator.public().into(); let payload = primitives::v1::collator_signature_payload( - &candidate.relay_parent, - &candidate.para_id, - &candidate.pov_block_hash, + &candidate.descriptor.relay_parent, + &candidate.descriptor.para_id, + &candidate.descriptor.pov_hash, ); - candidate.signature = collator.sign(&payload[..]).into(); - assert!(candidate.check_collator_signature().is_ok()); + candidate.descriptor.signature = collator.sign(&payload[..]).into(); + assert!(candidate.descriptor().check_collator_signature().is_ok()); } fn back_candidate( @@ -678,6 +678,33 @@ mod tests { ) } + #[derive(Default)] + struct TestCandidateBuilder { + para_id: ParaId, + head_data: HeadData, + pov_hash: Hash, + relay_parent: Hash, + new_validation_code: Option, + } + + impl TestCandidateBuilder { + fn build(self) -> CommittedCandidateReceipt { + CommittedCandidateReceipt { + descriptor: CandidateDescriptor { + para_id: self.para_id, + pov_hash: self.pov_hash, + relay_parent: self.relay_parent, + ..Default::default() + }, + commitments: CandidateCommitments { + head_data: self.head_data, + new_validation_code: self.new_validation_code, + ..Default::default() + }, + } + } + } + #[test] fn collect_pending_cleans_up_pending() { let chain_a = ParaId::from(1); @@ -899,11 +926,11 @@ mod tests { >::insert(chain_a, CandidatePendingAvailability { core: CoreIndex::from(0), - receipt: CommittedCandidateReceipt { - parachain_index: chain_a, + receipt: TestCandidateBuilder { + para_id: chain_a, head_data: vec![1, 2, 3, 4].into(), ..Default::default() - }, + }.build(), availability_votes: default_availability_votes(), relay_parent_number: 0, backed_in_number: 0, @@ -911,11 +938,11 @@ mod tests { >::insert(chain_b, CandidatePendingAvailability { core: CoreIndex::from(1), - receipt: CommittedCandidateReceipt { - parachain_index: chain_b, + receipt: TestCandidateBuilder { + para_id: chain_b, head_data: vec![5, 6, 7, 8].into(), ..Default::default() - }, + }.build(), availability_votes: default_availability_votes(), relay_parent_number: 0, backed_in_number: 0, @@ -1047,12 +1074,12 @@ mod tests { // unscheduled candidate. { - let mut candidate = CommittedCandidateReceipt { - parachain_index: chain_a, + let mut candidate = TestCandidateBuilder { + para_id: chain_a, relay_parent: System::parent_hash(), - pov_block_hash: Hash::from([1; 32]), + pov_hash: Hash::from([1; 32]), ..Default::default() - }; + }.build(); collator_sign_candidate( Sr25519Keyring::One, &mut candidate, @@ -1075,18 +1102,18 @@ mod tests { // candidates out of order. { - let mut candidate_a = CommittedCandidateReceipt { - parachain_index: chain_a, + let mut candidate_a = TestCandidateBuilder { + para_id: chain_a, relay_parent: System::parent_hash(), - pov_block_hash: Hash::from([1; 32]), + pov_hash: Hash::from([1; 32]), ..Default::default() - }; - let mut candidate_b = CommittedCandidateReceipt { - parachain_index: chain_b, + }.build(); + let mut candidate_b = TestCandidateBuilder { + para_id: chain_b, relay_parent: System::parent_hash(), - pov_block_hash: Hash::from([2; 32]), + pov_hash: Hash::from([2; 32]), ..Default::default() - }; + }.build(); collator_sign_candidate( Sr25519Keyring::One, @@ -1123,12 +1150,12 @@ mod tests { // candidate not backed. { - let mut candidate = CommittedCandidateReceipt { - parachain_index: chain_a, + let mut candidate = TestCandidateBuilder { + para_id: chain_a, relay_parent: System::parent_hash(), - pov_block_hash: Hash::from([1; 32]), + pov_hash: Hash::from([1; 32]), ..Default::default() - }; + }.build(); collator_sign_candidate( Sr25519Keyring::One, &mut candidate, @@ -1154,12 +1181,12 @@ mod tests { let wrong_parent_hash = Hash::from([222; 32]); assert!(System::parent_hash() != wrong_parent_hash); - let mut candidate = CommittedCandidateReceipt { - parachain_index: chain_a, + let mut candidate = TestCandidateBuilder { + para_id: chain_a, relay_parent: wrong_parent_hash, - pov_block_hash: Hash::from([1; 32]), + pov_hash: Hash::from([1; 32]), ..Default::default() - }; + }.build(); collator_sign_candidate( Sr25519Keyring::One, &mut candidate, @@ -1182,12 +1209,12 @@ mod tests { // candidate has wrong collator. { - let mut candidate = CommittedCandidateReceipt { - parachain_index: thread_a, + let mut candidate = TestCandidateBuilder { + para_id: thread_a, relay_parent: System::parent_hash(), - pov_block_hash: Hash::from([1; 32]), + pov_hash: Hash::from([1; 32]), ..Default::default() - }; + }.build(); assert!(CollatorId::from(Sr25519Keyring::One.public()) != thread_collator); collator_sign_candidate( @@ -1216,12 +1243,12 @@ mod tests { // candidate not well-signed by collator. { - let mut candidate = CommittedCandidateReceipt { - parachain_index: thread_a, + let mut candidate = TestCandidateBuilder { + para_id: thread_a, relay_parent: System::parent_hash(), - pov_block_hash: Hash::from([1; 32]), + pov_hash: Hash::from([1; 32]), ..Default::default() - }; + }.build(); assert_eq!(CollatorId::from(Sr25519Keyring::Two.public()), thread_collator); collator_sign_candidate( @@ -1229,7 +1256,8 @@ mod tests { &mut candidate, ); - candidate.pov_block_hash = Hash::from([2; 32]); + // change the candidate after signing. + candidate.descriptor.pov_hash = Hash::from([2; 32]); let backed = back_candidate( candidate, @@ -1248,12 +1276,12 @@ mod tests { // para occupied - reject. { - let mut candidate = CommittedCandidateReceipt { - parachain_index: chain_a, + let mut candidate = TestCandidateBuilder { + para_id: chain_a, relay_parent: System::parent_hash(), - pov_block_hash: Hash::from([1; 32]), + pov_hash: Hash::from([1; 32]), ..Default::default() - }; + }.build(); collator_sign_candidate( Sr25519Keyring::One, @@ -1287,16 +1315,13 @@ mod tests { // interfering code upgrade - reject { - let mut candidate = CommittedCandidateReceipt { - parachain_index: chain_a, + let mut candidate = TestCandidateBuilder { + para_id: chain_a, relay_parent: System::parent_hash(), - pov_block_hash: Hash::from([1; 32]), - commitments: CandidateCommitments { - new_validation_code: Some(vec![5, 6, 7, 8].into()), - ..Default::default() - }, + pov_hash: Hash::from([1; 32]), + new_validation_code: Some(vec![5, 6, 7, 8].into()), ..Default::default() - }; + }.build(); collator_sign_candidate( Sr25519Keyring::One, @@ -1385,34 +1410,34 @@ mod tests { group_idx: GroupIndex::from(2), }; - let mut candidate_a = CommittedCandidateReceipt { - parachain_index: chain_a, + let mut candidate_a = TestCandidateBuilder { + para_id: chain_a, relay_parent: System::parent_hash(), - pov_block_hash: Hash::from([1; 32]), + pov_hash: Hash::from([1; 32]), ..Default::default() - }; + }.build(); collator_sign_candidate( Sr25519Keyring::One, &mut candidate_a, ); - let mut candidate_b = CommittedCandidateReceipt { - parachain_index: chain_b, + let mut candidate_b = TestCandidateBuilder { + para_id: chain_b, relay_parent: System::parent_hash(), - pov_block_hash: Hash::from([2; 32]), + pov_hash: Hash::from([2; 32]), ..Default::default() - }; + }.build(); collator_sign_candidate( Sr25519Keyring::One, &mut candidate_b, ); - let mut candidate_c = CommittedCandidateReceipt { - parachain_index: thread_a, + let mut candidate_c = TestCandidateBuilder { + para_id: thread_a, relay_parent: System::parent_hash(), - pov_block_hash: Hash::from([3; 32]), + pov_hash: Hash::from([3; 32]), ..Default::default() - }; + }.build(); collator_sign_candidate( Sr25519Keyring::Two, &mut candidate_c, From 8313f467dacfacbdd0f93ce645aecc34f5ffda3d Mon Sep 17 00:00:00 2001 From: Robert Habermeier Date: Wed, 8 Jul 2020 21:20:13 -0400 Subject: [PATCH 06/46] add ErasureChunk to guide --- .../src/types/availability.md | 30 ++++++++++++++----- 1 file changed, 23 insertions(+), 7 deletions(-) diff --git a/roadmap/implementers-guide/src/types/availability.md b/roadmap/implementers-guide/src/types/availability.md index dac155e19381..be42c7a9278a 100644 --- a/roadmap/implementers-guide/src/types/availability.md +++ b/roadmap/implementers-guide/src/types/availability.md @@ -9,7 +9,7 @@ A bitfield [signed](backing.md#signed-wrapper) by a particular validator about t ```rust -pub type SignedAvailabilityBitfield = Signed; +type SignedAvailabilityBitfield = Signed; struct Bitfields(Vec<(SignedAvailabilityBitfield)>), // bitfields sorted by validator index, ascending ``` @@ -31,9 +31,9 @@ This contains the [`GlobalValidationSchedule`](candidate.md#globalvalidationsche ```rust struct OmittedValidationData { /// The global validation schedule. - pub global_validation: GlobalValidationSchedule, + global_validation: GlobalValidationSchedule, /// The local validation data. - pub local_validation: LocalValidationData, + local_validation: LocalValidationData, } ``` @@ -44,11 +44,27 @@ This is the data we want to keep available for each [candidate](candidate.md) in ```rust struct AvailableData { - /// The Proof-of-Validation of the candidate. - pub pov: PoV, - /// The omitted validation data. - pub omitted_validation: OmittedValidationData, + /// The Proof-of-Validation of the candidate. + pov: PoV, + /// The omitted validation data. + omitted_validation: OmittedValidationData, } ``` > TODO: With XCMP, we also need to keep available the outgoing messages as a result of para-validation. + +## Erasure Chunk + +The [`AvailableData`](#availabledata) is split up into an erasure-coding as part of the availability process. Each validator gets a chunk. This describes one of those chunks, along with its proof against a merkle root hash, which should be apparent from context, and is the `erasure_root` field of a [`CandidateDescriptor`](candidate.md#candidatedescriptor). + + +```rust +struct ErasureChunk { + /// The erasure-encoded chunk of data belonging to the candidate block. + chunk: Vec, + /// The index of this erasure-encoded chunk of data. + index: u32, + /// Proof for this chunk's branch in the Merkle tree. + proof: Vec>, +} +``` From 7794af4429d73b9f9d76aeb6c6b2f40ce6bced26 Mon Sep 17 00:00:00 2001 From: Robert Habermeier Date: Wed, 8 Jul 2020 21:20:21 -0400 Subject: [PATCH 07/46] export erasure chunk from v1 primitives --- primitives/src/v1.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/primitives/src/v1.rs b/primitives/src/v1.rs index aa241f233043..803fa5d4d2d9 100644 --- a/primitives/src/v1.rs +++ b/primitives/src/v1.rs @@ -50,7 +50,7 @@ pub use polkadot_parachain::primitives::{ pub use crate::parachain::{ CollatorId, CollatorSignature, PARACHAIN_KEY_TYPE_ID, ValidatorId, ValidatorIndex, ValidatorPair, ValidatorSignature, SigningContext, Signed, ValidityAttestation, - CompactStatement, SignedStatement, + CompactStatement, SignedStatement, ErasureChunk, }; // More exports for std. From 888fee0a53edfffffd95dca8c8f7c6591a4e4718 Mon Sep 17 00:00:00 2001 From: Robert Habermeier Date: Wed, 8 Jul 2020 21:20:32 -0400 Subject: [PATCH 08/46] subsystem crate uses v1 primitives --- node/subsystem/src/lib.rs | 2 +- node/subsystem/src/messages.rs | 26 +++++++++++++------------- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/node/subsystem/src/lib.rs b/node/subsystem/src/lib.rs index fd32d7cfdbc9..baeef6b7b285 100644 --- a/node/subsystem/src/lib.rs +++ b/node/subsystem/src/lib.rs @@ -26,7 +26,7 @@ use futures::prelude::*; use futures::channel::{mpsc, oneshot}; use futures::future::BoxFuture; -use polkadot_primitives::Hash; +use polkadot_primitives::v1::Hash; use async_trait::async_trait; use crate::messages::AllMessages; diff --git a/node/subsystem/src/messages.rs b/node/subsystem/src/messages.rs index 73371e28fd9b..ec65de9335a7 100644 --- a/node/subsystem/src/messages.rs +++ b/node/subsystem/src/messages.rs @@ -24,11 +24,11 @@ use futures::channel::{mpsc, oneshot}; -use polkadot_primitives::{BlockNumber, Hash, Signature}; -use polkadot_primitives::parachain::{ - AbridgedCandidateReceipt, PoVBlock, ErasureChunk, BackedCandidate, Id as ParaId, +use polkadot_primitives::v1::{ + BlockNumber, Hash, + CandidateReceipt, PoV, ErasureChunk, BackedCandidate, Id as ParaId, SignedAvailabilityBitfield, SigningContext, ValidatorId, ValidationCode, ValidatorIndex, - CandidateDescriptor, + CandidateDescriptor, ValidatorSignature, }; use polkadot_node_primitives::{ MisbehaviorReport, SignedFullStatement, View, ProtocolId, @@ -47,7 +47,7 @@ pub struct NewBackedCandidate(pub BackedCandidate); pub enum CandidateSelectionMessage { /// We recommended a particular candidate to be seconded, but it was invalid; penalize the collator. /// The hash is the relay parent. - Invalid(Hash, AbridgedCandidateReceipt), + Invalid(Hash, CandidateReceipt), } /// Messages received by the Candidate Backing subsystem. @@ -58,7 +58,7 @@ pub enum CandidateBackingMessage { RegisterBackingWatcher(Hash, mpsc::Sender), /// Note that the Candidate Backing subsystem should second the given candidate in the context of the /// given relay-parent (ref. by hash). This candidate must be validated. - Second(Hash, AbridgedCandidateReceipt), + Second(Hash, CandidateReceipt), /// Note a validator's statement about a particular candidate. Disagreements about validity must be escalated /// to a broader check by Misbehavior Arbitration. Agreements are simply tallied until a quorum is reached. Statement(Hash, SignedFullStatement), @@ -77,8 +77,8 @@ pub enum CandidateValidationMessage { /// and the PoV. Validate( Hash, - AbridgedCandidateReceipt, - PoVBlock, + CandidateReceipt, + PoV, oneshot::Sender>, ), } @@ -141,8 +141,8 @@ pub enum BitfieldDistributionMessage { /// Availability store subsystem message. #[derive(Debug)] pub enum AvailabilityStoreMessage { - /// Query a `PoVBlock` from the AV store. - QueryPoV(Hash, oneshot::Sender>), + /// Query a `PoV` from the AV store. + QueryPoV(Hash, oneshot::Sender>), /// Query an `ErasureChunk` from the AV store. QueryChunk(Hash, ValidatorIndex, oneshot::Sender), @@ -191,7 +191,7 @@ pub enum ProvisionableData { /// Misbehavior reports are self-contained proofs of validator misbehavior. MisbehaviorReport(Hash, MisbehaviorReport), /// Disputes trigger a broad dispute resolution process. - Dispute(Hash, Signature), + Dispute(Hash, ValidatorSignature), } /// This data needs to make its way from the provisioner into the InherentData. @@ -224,10 +224,10 @@ pub enum PoVDistributionMessage { /// /// This `CandidateDescriptor` should correspond to a candidate seconded under the provided /// relay-parent hash. - FetchPoV(Hash, CandidateDescriptor, oneshot::Sender>), + FetchPoV(Hash, CandidateDescriptor, oneshot::Sender>), /// Distribute a PoV for the given relay-parent and CandidateDescriptor. /// The PoV should correctly hash to the PoV hash mentioned in the CandidateDescriptor - DistributePoV(Hash, CandidateDescriptor, Arc), + DistributePoV(Hash, CandidateDescriptor, Arc), /// An update from the network bridge. NetworkBridgeUpdate(NetworkBridgeEvent), } From 25e7acf07ffb46f9b05b4aaa9723522a2edc4787 Mon Sep 17 00:00:00 2001 From: Robert Habermeier Date: Wed, 8 Jul 2020 21:24:07 -0400 Subject: [PATCH 09/46] node-primitives uses new v1 primitives --- node/primitives/src/lib.rs | 17 +++++++++++------ primitives/src/v1.rs | 2 +- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/node/primitives/src/lib.rs b/node/primitives/src/lib.rs index 921f620ea9dc..8a3368b3e24f 100644 --- a/node/primitives/src/lib.rs +++ b/node/primitives/src/lib.rs @@ -21,19 +21,22 @@ //! there. use parity_scale_codec::{Decode, Encode}; -use polkadot_primitives::{Hash, - parachain::{ - AbridgedCandidateReceipt, CandidateReceipt, CompactStatement, - EncodeAs, Signed, - } +use polkadot_primitives::v1::{ + Hash, CommittedCandidateReceipt, CandidateReceipt, CompactStatement, + EncodeAs, Signed, }; /// A statement, where the candidate receipt is included in the `Seconded` variant. +/// +/// This is the committed candidate receipt instead of the bare candidate receipt. As such, +/// it gives access to the commitments to validators who have not executed the candidate. This +/// is necessary to allow a block-producing validator to include candidates from outside of the para +/// it is assigned to. #[derive(Debug, Clone, PartialEq, Eq, Encode, Decode)] pub enum Statement { /// A statement that a validator seconds a candidate. #[codec(index = "1")] - Seconded(AbridgedCandidateReceipt), + Seconded(CommittedCandidateReceipt), /// A statement that a validator has deemed a candidate valid. #[codec(index = "2")] Valid(Hash), @@ -43,6 +46,8 @@ pub enum Statement { } impl Statement { + /// Transform this statement into its compact version, which references only the hash + /// of the candidate. pub fn to_compact(&self) -> CompactStatement { match *self { Statement::Seconded(ref c) => CompactStatement::Candidate(c.hash()), diff --git a/primitives/src/v1.rs b/primitives/src/v1.rs index 803fa5d4d2d9..10d0e7a6f6d4 100644 --- a/primitives/src/v1.rs +++ b/primitives/src/v1.rs @@ -50,7 +50,7 @@ pub use polkadot_parachain::primitives::{ pub use crate::parachain::{ CollatorId, CollatorSignature, PARACHAIN_KEY_TYPE_ID, ValidatorId, ValidatorIndex, ValidatorPair, ValidatorSignature, SigningContext, Signed, ValidityAttestation, - CompactStatement, SignedStatement, ErasureChunk, + CompactStatement, SignedStatement, ErasureChunk, EncodeAs, }; // More exports for std. From 3872d3e4cf232cac810fa63538aacc2673aada6d Mon Sep 17 00:00:00 2001 From: Robert Habermeier Date: Wed, 8 Jul 2020 21:28:43 -0400 Subject: [PATCH 10/46] port overseer to new primitives --- node/overseer/examples/minimal-example.rs | 4 ++-- node/overseer/src/lib.rs | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/node/overseer/examples/minimal-example.rs b/node/overseer/examples/minimal-example.rs index cdef0340d04f..fd5148d7c374 100644 --- a/node/overseer/examples/minimal-example.rs +++ b/node/overseer/examples/minimal-example.rs @@ -27,7 +27,7 @@ use futures::{ use futures_timer::Delay; use kv_log_macro as log; -use polkadot_primitives::parachain::{BlockData, PoVBlock}; +use polkadot_primitives::v1::{BlockData, PoV}; use polkadot_overseer::Overseer; use polkadot_subsystem::{Subsystem, SubsystemContext, SpawnedSubsystem, FromOverseer}; @@ -61,7 +61,7 @@ impl Subsystem1 { CandidateValidationMessage::Validate( Default::default(), Default::default(), - PoVBlock { + PoV { block_data: BlockData(Vec::new()), }, tx, diff --git a/node/overseer/src/lib.rs b/node/overseer/src/lib.rs index 70de3c1d86f8..90c373d6345f 100644 --- a/node/overseer/src/lib.rs +++ b/node/overseer/src/lib.rs @@ -72,7 +72,7 @@ use futures::{ use futures_timer::Delay; use streamunordered::{StreamYield, StreamUnordered}; -use polkadot_primitives::{Block, BlockNumber, Hash}; +use polkadot_primitives::v1::{Block, BlockNumber, Hash}; use client::{BlockImportNotification, BlockchainEvents, FinalityNotification}; use polkadot_subsystem::messages::{ @@ -682,7 +682,7 @@ fn spawn( mod tests { use futures::{executor, pin_mut, select, channel::mpsc, FutureExt}; - use polkadot_primitives::parachain::{BlockData, PoVBlock}; + use polkadot_primitives::v1::{BlockData, PoV}; use super::*; struct TestSubsystem1(mpsc::Sender); @@ -728,7 +728,7 @@ mod tests { CandidateValidationMessage::Validate( Default::default(), Default::default(), - PoVBlock { + PoV { block_data: BlockData(Vec::new()), }, tx, From 53cd37f044c86cfe763266b7f3a5cc6138120d0b Mon Sep 17 00:00:00 2001 From: Robert Habermeier Date: Wed, 8 Jul 2020 21:30:19 -0400 Subject: [PATCH 11/46] new-proposer uses v1 primitives (no ParachainHost anymore) --- node/core/proposer/src/lib.rs | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/node/core/proposer/src/lib.rs b/node/core/proposer/src/lib.rs index b53ac5729fa9..1a0f1a9f8507 100644 --- a/node/core/proposer/src/lib.rs +++ b/node/core/proposer/src/lib.rs @@ -4,8 +4,7 @@ use polkadot_node_subsystem::{messages::{AllMessages, ProvisionerInherentData, P use polkadot_overseer::OverseerHandler; use polkadot_primitives::{ inclusion_inherent, - parachain::ParachainHost, - Block, Hash, Header, + v1::{Block, Hash, Header}, }; use sc_block_builder::{BlockBuilderApi, BlockBuilderProvider}; use sp_api::{ApiExt, ProvideRuntimeApi}; @@ -53,7 +52,7 @@ where + Send + Sync, Client::Api: - ParachainHost + BlockBuilderApi + ApiExt, + BlockBuilderApi + ApiExt, Backend: 'static + sc_client_api::Backend>, // Rust bug: https://github.com/rust-lang/rust/issues/24159 @@ -104,7 +103,7 @@ where + Send + Sync, Client::Api: - ParachainHost + BlockBuilderApi + ApiExt, + BlockBuilderApi + ApiExt, Backend: 'static + sc_client_api::Backend>, // Rust bug: https://github.com/rust-lang/rust/issues/24159 @@ -155,7 +154,7 @@ where + Send + Sync, Client::Api: - ParachainHost + BlockBuilderApi + ApiExt, + BlockBuilderApi + ApiExt, Backend: 'static + sc_client_api::Backend>, // Rust bug: https://github.com/rust-lang/rust/issues/24159 From 072c5fe097912e477e7dec9969c02188f13be7f8 Mon Sep 17 00:00:00 2001 From: Robert Habermeier Date: Wed, 8 Jul 2020 21:42:45 -0400 Subject: [PATCH 12/46] fix no-std compilation for primitives --- primitives/src/v1.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/primitives/src/v1.rs b/primitives/src/v1.rs index 10d0e7a6f6d4..1247d8dc712d 100644 --- a/primitives/src/v1.rs +++ b/primitives/src/v1.rs @@ -49,13 +49,13 @@ pub use polkadot_parachain::primitives::{ // Export some basic parachain primitives from v0. pub use crate::parachain::{ CollatorId, CollatorSignature, PARACHAIN_KEY_TYPE_ID, ValidatorId, ValidatorIndex, - ValidatorPair, ValidatorSignature, SigningContext, Signed, ValidityAttestation, + ValidatorSignature, SigningContext, Signed, ValidityAttestation, CompactStatement, SignedStatement, ErasureChunk, EncodeAs, }; // More exports for std. #[cfg(feature = "std")] -pub use crate::parachain::CollatorPair; +pub use crate::parachain::{ValidatorPair, CollatorPair}; /// Get a collator signature payload on a relay-parent, block-data combo. pub fn collator_signature_payload>( From 5dc4aa7026364db4ecd1eac2c40741a343c525d3 Mon Sep 17 00:00:00 2001 From: Robert Habermeier Date: Wed, 8 Jul 2020 21:45:31 -0400 Subject: [PATCH 13/46] service-new uses v1 primitives --- node/service/src/chain_spec.rs | 6 +++--- node/service/src/grandpa_support.rs | 4 ++-- node/service/src/lib.rs | 14 ++++++-------- 3 files changed, 11 insertions(+), 13 deletions(-) diff --git a/node/service/src/chain_spec.rs b/node/service/src/chain_spec.rs index 0659d0808301..db9d9c5dded9 100644 --- a/node/service/src/chain_spec.rs +++ b/node/service/src/chain_spec.rs @@ -17,7 +17,7 @@ //! Polkadot chain configurations. use sp_core::{Pair, Public, crypto::UncheckedInto, sr25519}; -use polkadot_primitives::{AccountId, AccountPublic, parachain::ValidatorId}; +use polkadot_primitives::v1::{AccountId, AccountPublic, ValidatorId}; use polkadot_runtime as polkadot; use kusama_runtime as kusama; use westend_runtime as westend; @@ -48,9 +48,9 @@ const DEFAULT_PROTOCOL_ID: &str = "dot"; #[serde(rename_all = "camelCase")] pub struct Extensions { /// Block numbers with known hashes. - pub fork_blocks: sc_client_api::ForkBlocks, + pub fork_blocks: sc_client_api::ForkBlocks, /// Known bad block hashes. - pub bad_blocks: sc_client_api::BadBlocks, + pub bad_blocks: sc_client_api::BadBlocks, } /// The `ChainSpec parametrised for polkadot runtime`. diff --git a/node/service/src/grandpa_support.rs b/node/service/src/grandpa_support.rs index a875c4b45a37..d851ba2f7b80 100644 --- a/node/service/src/grandpa_support.rs +++ b/node/service/src/grandpa_support.rs @@ -16,7 +16,7 @@ //! Polkadot-specific GRANDPA integration utilities. -use polkadot_primitives::Hash; +use polkadot_primitives::v1::Hash; use sp_runtime::traits::{Block as BlockT, NumberFor}; /// A custom GRANDPA voting rule that "pauses" voting (i.e. keeps voting for the @@ -98,7 +98,7 @@ impl grandpa::VotingRule for PauseAfterBlockFor Vec<( grandpa_primitives::SetId, - (Hash, polkadot_primitives::BlockNumber), + (Hash, polkadot_primitives::v1::BlockNumber), grandpa_primitives::AuthorityList, )> { use sp_core::crypto::Ss58Codec; diff --git a/node/service/src/lib.rs b/node/service/src/lib.rs index 23a6dbfd4192..21feaee0749c 100644 --- a/node/service/src/lib.rs +++ b/node/service/src/lib.rs @@ -22,7 +22,7 @@ mod client; use std::sync::Arc; use std::time::Duration; -use polkadot_primitives::{parachain, AccountId, Nonce, Balance}; +use polkadot_primitives::v1::{AccountId, Nonce, Balance}; #[cfg(feature = "full-node")] use service::{error::Error as ServiceError, ServiceBuilder}; use grandpa::{self, FinalityProofProvider as GrandpaFinalityProofProvider}; @@ -48,7 +48,7 @@ pub use sc_consensus::LongestChain; pub use sp_api::{ApiRef, Core as CoreApi, ConstructRuntimeApi, ProvideRuntimeApi, StateBackend}; pub use sp_runtime::traits::{DigestFor, HashFor, NumberFor}; pub use consensus_common::{Proposal, SelectChain, BlockImport, RecordProof, block_validation::Chain}; -pub use polkadot_primitives::parachain::{CollatorId, ParachainHost}; +pub use polkadot_primitives::v1::{CollatorId, Id as ParaId}; pub use polkadot_primitives::{Block, BlockId}; pub use sp_runtime::traits::{Block as BlockT, self as runtime_traits, BlakeTwo256}; pub use chain_spec::{PolkadotChainSpec, KusamaChainSpec, WestendChainSpec}; @@ -87,7 +87,6 @@ pub trait RuntimeApiCollection: + sp_api::ApiExt + babe_primitives::BabeApi + grandpa_primitives::GrandpaApi - + ParachainHost + sp_block_builder::BlockBuilder + system_rpc_runtime_api::AccountNonceApi + pallet_transaction_payment_rpc_runtime_api::TransactionPaymentApi @@ -107,7 +106,6 @@ where + sp_api::ApiExt + babe_primitives::BabeApi + grandpa_primitives::GrandpaApi - + ParachainHost + sp_block_builder::BlockBuilder + system_rpc_runtime_api::AccountNonceApi + pallet_transaction_payment_rpc_runtime_api::TransactionPaymentApi @@ -589,7 +587,7 @@ macro_rules! new_light { /// Builds a new object suitable for chain operations. pub fn new_chain_ops(mut config: Configuration) -> Result< ( - Arc>, + Arc>, Arc>, consensus_common::import_queue::BasicQueue>, TaskManager, @@ -612,7 +610,7 @@ where #[cfg(feature = "full-node")] pub fn polkadot_new_full( mut config: Configuration, - collating_for: Option<(CollatorId, parachain::Id)>, + collating_for: Option<(CollatorId, ParaId)>, _max_block_data_size: Option, _authority_discovery_enabled: bool, _slot_duration: u64, @@ -644,7 +642,7 @@ pub fn polkadot_new_full( #[cfg(feature = "full-node")] pub fn kusama_new_full( mut config: Configuration, - collating_for: Option<(CollatorId, parachain::Id)>, + collating_for: Option<(CollatorId, ParaId)>, _max_block_data_size: Option, _authority_discovery_enabled: bool, _slot_duration: u64, @@ -676,7 +674,7 @@ pub fn kusama_new_full( #[cfg(feature = "full-node")] pub fn westend_new_full( mut config: Configuration, - collating_for: Option<(CollatorId, parachain::Id)>, + collating_for: Option<(CollatorId, ParaId)>, _max_block_data_size: Option, _authority_discovery_enabled: bool, _slot_duration: u64, From e0b0a317ad97c26930e21783e372696913e8c3e9 Mon Sep 17 00:00:00 2001 From: Robert Habermeier Date: Wed, 8 Jul 2020 21:45:58 -0400 Subject: [PATCH 14/46] network-bridge uses new primitives --- node/network/bridge/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/node/network/bridge/src/lib.rs b/node/network/bridge/src/lib.rs index 6f90779afe62..46b9dbd84024 100644 --- a/node/network/bridge/src/lib.rs +++ b/node/network/bridge/src/lib.rs @@ -33,7 +33,7 @@ use polkadot_subsystem::{ }; use polkadot_subsystem::messages::{NetworkBridgeEvent, NetworkBridgeMessage, AllMessages}; use node_primitives::{ProtocolId, View}; -use polkadot_primitives::{Block, Hash}; +use polkadot_primitives::v1::{Block, Hash}; use std::collections::btree_map::{BTreeMap, Entry as BEntry}; use std::collections::hash_map::{HashMap, Entry as HEntry}; From d066d3ee24531736f58116e6733d86890463f9e8 Mon Sep 17 00:00:00 2001 From: Robert Habermeier Date: Wed, 8 Jul 2020 21:46:32 -0400 Subject: [PATCH 15/46] statement distribution uses v1 primitives --- .../network/statement-distribution/src/lib.rs | 37 +++++++++---------- 1 file changed, 18 insertions(+), 19 deletions(-) diff --git a/node/network/statement-distribution/src/lib.rs b/node/network/statement-distribution/src/lib.rs index f3d2653266f7..cef499eae98b 100644 --- a/node/network/statement-distribution/src/lib.rs +++ b/node/network/statement-distribution/src/lib.rs @@ -29,9 +29,8 @@ use polkadot_subsystem::messages::{ RuntimeApiRequest, }; use node_primitives::{ProtocolId, View, SignedFullStatement}; -use polkadot_primitives::Hash; -use polkadot_primitives::parachain::{ - CompactStatement, ValidatorIndex, ValidatorId, SigningContext, ValidatorSignature, +use polkadot_primitives::v1::{ + Hash, CompactStatement, ValidatorIndex, ValidatorId, SigningContext, ValidatorSignature, }; use parity_scale_codec::{Encode, Decode}; @@ -891,7 +890,7 @@ mod tests { use super::*; use sp_keyring::Sr25519Keyring; use node_primitives::Statement; - use polkadot_primitives::parachain::{AbridgedCandidateReceipt}; + use polkadot_primitives::v1::CommittedCandidateReceipt; use assert_matches::assert_matches; use futures::executor::{self, ThreadPool}; @@ -911,23 +910,23 @@ mod tests { }; let candidate_a = { - let mut c = AbridgedCandidateReceipt::default(); - c.relay_parent = parent_hash; - c.parachain_index = 1.into(); + let mut c = CommittedCandidateReceipt::default(); + c.descriptor.relay_parent = parent_hash; + c.descriptor.para_id = 1.into(); c }; let candidate_b = { - let mut c = AbridgedCandidateReceipt::default(); - c.relay_parent = parent_hash; - c.parachain_index = 2.into(); + let mut c = CommittedCandidateReceipt::default(); + c.descriptor.relay_parent = parent_hash; + c.descriptor.para_id = 2.into(); c }; let candidate_c = { - let mut c = AbridgedCandidateReceipt::default(); - c.relay_parent = parent_hash; - c.parachain_index = 3.into(); + let mut c = CommittedCandidateReceipt::default(); + c.descriptor.relay_parent = parent_hash; + c.descriptor.para_id = 3.into(); c }; @@ -1140,9 +1139,9 @@ mod tests { let hash_c = [3; 32].into(); let candidate = { - let mut c = AbridgedCandidateReceipt::default(); - c.relay_parent = hash_c; - c.parachain_index = 1.into(); + let mut c = CommittedCandidateReceipt::default(); + c.descriptor.relay_parent = hash_c; + c.descriptor.para_id = 1.into(); c }; let candidate_hash = candidate.hash(); @@ -1275,9 +1274,9 @@ mod tests { let hash_c = [3; 32].into(); let candidate = { - let mut c = AbridgedCandidateReceipt::default(); - c.relay_parent = hash_b; - c.parachain_index = 1.into(); + let mut c = CommittedCandidateReceipt::default(); + c.descriptor.relay_parent = hash_b; + c.descriptor.para_id = 1.into(); c }; From 09c81f8faf07e6c450fd3b84892e15008eec50cc Mon Sep 17 00:00:00 2001 From: Robert Habermeier Date: Wed, 8 Jul 2020 21:47:43 -0400 Subject: [PATCH 16/46] PoV distribution uses v1 primitives; add PoV::hash fn --- node/network/pov-distribution/src/lib.rs | 5 ++--- primitives/src/v1.rs | 8 ++++++++ 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/node/network/pov-distribution/src/lib.rs b/node/network/pov-distribution/src/lib.rs index 589e33fde0d6..84d6e803d2c7 100644 --- a/node/network/pov-distribution/src/lib.rs +++ b/node/network/pov-distribution/src/lib.rs @@ -19,8 +19,7 @@ //! This is a gossip implementation of code that is responsible for distributing PoVs //! among validators. -use polkadot_primitives::Hash; -use polkadot_primitives::parachain::{PoVBlock as PoV, CandidateDescriptor}; +use polkadot_primitives::v1::{Hash, PoV, CandidateDescriptor}; use polkadot_subsystem::{ OverseerSignal, SubsystemContext, Subsystem, SubsystemResult, FromOverseer, SpawnedSubsystem, }; @@ -550,7 +549,7 @@ async fn run( mod tests { use super::*; use futures::executor::{self, ThreadPool}; - use polkadot_primitives::parachain::BlockData; + use polkadot_primitives::v1::BlockData; use assert_matches::assert_matches; fn make_pov(data: Vec) -> PoV { diff --git a/primitives/src/v1.rs b/primitives/src/v1.rs index 1247d8dc712d..eee241da9721 100644 --- a/primitives/src/v1.rs +++ b/primitives/src/v1.rs @@ -251,6 +251,14 @@ pub struct PoV { pub block_data: BlockData, } +impl PoV { + /// Get the blake2-256 hash of the PoV. + #[cfg(feature = "std")] + pub fn hash(&self) -> Hash { + BlakeTwo256::hash_of(self) + } +} + /// A bitfield concerning availability of backed candidates. #[derive(PartialEq, Eq, Clone, Encode, Decode)] #[cfg_attr(feature = "std", derive(Debug))] From 438474fe2c2b0d171ce17581cc32b5e377b70e12 Mon Sep 17 00:00:00 2001 From: Robert Habermeier Date: Wed, 8 Jul 2020 21:50:40 -0400 Subject: [PATCH 17/46] move parachain to v0 --- primitives/src/{parachain.rs => v0.rs} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename primitives/src/{parachain.rs => v0.rs} (100%) diff --git a/primitives/src/parachain.rs b/primitives/src/v0.rs similarity index 100% rename from primitives/src/parachain.rs rename to primitives/src/v0.rs From 6189c4c73b56873d2298adb1bcf8c83e8b8ad532 Mon Sep 17 00:00:00 2001 From: Robert Habermeier Date: Wed, 8 Jul 2020 21:51:52 -0400 Subject: [PATCH 18/46] remove inclusion_inherent module and place into v1 --- primitives/src/inclusion_inherent.rs | 23 ----------------------- primitives/src/lib.rs | 3 +-- primitives/src/v1.rs | 9 ++++++--- 3 files changed, 7 insertions(+), 28 deletions(-) delete mode 100644 primitives/src/inclusion_inherent.rs diff --git a/primitives/src/inclusion_inherent.rs b/primitives/src/inclusion_inherent.rs deleted file mode 100644 index ca3f5ec23a16..000000000000 --- a/primitives/src/inclusion_inherent.rs +++ /dev/null @@ -1,23 +0,0 @@ -// Copyright 2017-2020 Parity Technologies (UK) Ltd. -// This file is part of Polkadot. - -// Polkadot is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// Polkadot is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with Polkadot. If not, see . - -//! Inclusion Inherent primitives define types and constants which can be imported -//! without needing to import the entire inherent module. - -use inherents::InherentIdentifier; - -/// Unique identifier for the Inclusion Inherent -pub const INHERENT_IDENTIFIER: InherentIdentifier = *b"inclusn0"; diff --git a/primitives/src/lib.rs b/primitives/src/lib.rs index 075891fec483..9131f9a65b62 100644 --- a/primitives/src/lib.rs +++ b/primitives/src/lib.rs @@ -23,8 +23,7 @@ pub use runtime_primitives::traits::{BlakeTwo256, Hash as HashT, Verify, IdentifyAccount}; pub use polkadot_core_primitives::*; -pub mod inclusion_inherent; -pub mod parachain; +pub mod v0; pub mod v1; pub use parity_scale_codec::Compact; diff --git a/primitives/src/v1.rs b/primitives/src/v1.rs index eee241da9721..12f2bea1e953 100644 --- a/primitives/src/v1.rs +++ b/primitives/src/v1.rs @@ -47,15 +47,18 @@ pub use polkadot_parachain::primitives::{ }; // Export some basic parachain primitives from v0. -pub use crate::parachain::{ +pub use crate::v0::{ CollatorId, CollatorSignature, PARACHAIN_KEY_TYPE_ID, ValidatorId, ValidatorIndex, ValidatorSignature, SigningContext, Signed, ValidityAttestation, CompactStatement, SignedStatement, ErasureChunk, EncodeAs, }; -// More exports for std. +// More exports from v0 for std. #[cfg(feature = "std")] -pub use crate::parachain::{ValidatorPair, CollatorPair}; +pub use crate::v0::{ValidatorPair, CollatorPair}; + +/// Unique identifier for the Inclusion Inherent +pub const INHERENT_IDENTIFIER: InherentIdentifier = *b"inclusn0"; /// Get a collator signature payload on a relay-parent, block-data combo. pub fn collator_signature_payload>( From 0aeee53c8e858d6bff55a8358599363a2629c76b Mon Sep 17 00:00:00 2001 From: Robert Habermeier Date: Wed, 8 Jul 2020 21:53:41 -0400 Subject: [PATCH 19/46] remove everything from primitives crate root --- primitives/src/lib.rs | 53 ------------------------------------------ primitives/src/v0.rs | 54 ++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 53 insertions(+), 54 deletions(-) diff --git a/primitives/src/lib.rs b/primitives/src/lib.rs index 9131f9a65b62..82a5e7ca2e03 100644 --- a/primitives/src/lib.rs +++ b/primitives/src/lib.rs @@ -20,58 +20,5 @@ #![cfg_attr(not(feature = "std"), no_std)] -pub use runtime_primitives::traits::{BlakeTwo256, Hash as HashT, Verify, IdentifyAccount}; -pub use polkadot_core_primitives::*; - pub mod v0; pub mod v1; - -pub use parity_scale_codec::Compact; - -/// Custom validity errors used in Polkadot while validating transactions. -#[repr(u8)] -pub enum ValidityError { - /// The Ethereum signature is invalid. - InvalidEthereumSignature = 0, - /// The signer has no claim. - SignerHasNoClaim = 1, - /// No permission to execute the call. - NoPermission = 2, - /// An invalid statement was made for a claim. - InvalidStatement = 3, -} - -impl From for u8 { - fn from(err: ValidityError) -> Self { - err as u8 - } -} - -/// App-specific crypto used for reporting equivocation/misbehavior in BABE, -/// GRANDPA and Parachains, described in the white paper as the fisherman role. -/// Any rewards for misbehavior reporting will be paid out to this account. -pub mod fisherman { - use super::{Signature, Verify}; - use primitives::crypto::KeyTypeId; - - /// Key type for the reporting module. Used for reporting BABE, GRANDPA - /// and Parachain equivocations. - pub const KEY_TYPE: KeyTypeId = KeyTypeId(*b"fish"); - - mod app { - use application_crypto::{app_crypto, sr25519}; - app_crypto!(sr25519, super::KEY_TYPE); - } - - /// Identity of the equivocation/misbehavior reporter. - pub type FishermanId = app::Public; - - /// An `AppCrypto` type to allow submitting signed transactions using the fisherman - /// application key as signer. - pub struct FishermanAppCrypto; - impl frame_system::offchain::AppCrypto<::Signer, Signature> for FishermanAppCrypto { - type RuntimeAppPublic = FishermanId; - type GenericSignature = primitives::sr25519::Signature; - type GenericPublic = primitives::sr25519::Public; - } -} diff --git a/primitives/src/v0.rs b/primitives/src/v0.rs index af68cc1eae82..5bbb9bfca64c 100644 --- a/primitives/src/v0.rs +++ b/primitives/src/v0.rs @@ -21,7 +21,6 @@ use sp_std::prelude::*; use sp_std::cmp::Ordering; use parity_scale_codec::{Encode, Decode}; use bitvec::vec::BitVec; -use super::{Hash, Balance, BlockNumber}; #[cfg(feature = "std")] use serde::{Serialize, Deserialize}; @@ -34,6 +33,10 @@ use inherents::InherentIdentifier; use application_crypto::KeyTypeId; use polkadot_core_primitives::DownwardMessage; +pub use runtime_primitives::traits::{BlakeTwo256, Hash as HashT, Verify, IdentifyAccount}; +pub use polkadot_core_primitives::*; +pub use parity_scale_codec::Compact; + pub use polkadot_parachain::primitives::{ Id, ParachainDispatchOrigin, LOWEST_USER_ID, UpwardMessage, HeadData, BlockData, ValidationCode, @@ -894,6 +897,55 @@ impl, RealPayload: Encode> Signed for u8 { + fn from(err: ValidityError) -> Self { + err as u8 + } +} + +/// App-specific crypto used for reporting equivocation/misbehavior in BABE, +/// GRANDPA and Parachains, described in the white paper as the fisherman role. +/// Any rewards for misbehavior reporting will be paid out to this account. +pub mod fisherman { + use super::{Signature, Verify}; + use primitives::crypto::KeyTypeId; + + /// Key type for the reporting module. Used for reporting BABE, GRANDPA + /// and Parachain equivocations. + pub const KEY_TYPE: KeyTypeId = KeyTypeId(*b"fish"); + + mod app { + use application_crypto::{app_crypto, sr25519}; + app_crypto!(sr25519, super::KEY_TYPE); + } + + /// Identity of the equivocation/misbehavior reporter. + pub type FishermanId = app::Public; + + /// An `AppCrypto` type to allow submitting signed transactions using the fisherman + /// application key as signer. + pub struct FishermanAppCrypto; + impl frame_system::offchain::AppCrypto<::Signer, Signature> for FishermanAppCrypto { + type RuntimeAppPublic = FishermanId; + type GenericSignature = primitives::sr25519::Signature; + type GenericPublic = primitives::sr25519::Public; + } +} + + #[cfg(test)] mod tests { use super::*; From 9cb6238f907f647952c9551ad527fcbfa0c36671 Mon Sep 17 00:00:00 2001 From: Robert Habermeier Date: Wed, 8 Jul 2020 22:34:34 -0400 Subject: [PATCH 20/46] remove some unused old types from v0 primitives --- primitives/src/v0.rs | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/primitives/src/v0.rs b/primitives/src/v0.rs index 5bbb9bfca64c..afcf4c414d40 100644 --- a/primitives/src/v0.rs +++ b/primitives/src/v0.rs @@ -31,7 +31,6 @@ use primitives::RuntimeDebug; use runtime_primitives::traits::{AppVerify, Block as BlockT}; use inherents::InherentIdentifier; use application_crypto::KeyTypeId; -use polkadot_core_primitives::DownwardMessage; pub use runtime_primitives::traits::{BlakeTwo256, Hash as HashT, Verify, IdentifyAccount}; pub use polkadot_core_primitives::*; @@ -617,16 +616,6 @@ pub struct ErasureChunk { pub proof: Vec>, } -/// Parachain header raw bytes wrapper type. -#[derive(PartialEq, Eq)] -#[cfg_attr(feature = "std", derive(Serialize, Deserialize, Debug))] -pub struct Header(#[cfg_attr(feature = "std", serde(with="bytes"))] pub Vec); - -/// Activity bit field. -#[derive(PartialEq, Eq, Clone, Default, Encode, Decode)] -#[cfg_attr(feature = "std", derive(Serialize, Deserialize, Debug))] -pub struct Activity(#[cfg_attr(feature = "std", serde(with="bytes"))] pub Vec); - /// Statements that can be made about parachain candidates. These are the /// actual values that are signed. #[derive(Clone, PartialEq, Eq, Encode, Decode, Hash)] From 55956a875261f52b5438b5b9cb9d9403a98bf6db Mon Sep 17 00:00:00 2001 From: Robert Habermeier Date: Wed, 8 Jul 2020 23:01:05 -0400 Subject: [PATCH 21/46] point everything else at primitives::v0 --- availability-store/src/lib.rs | 8 ++--- availability-store/src/store.rs | 9 ++--- availability-store/src/worker.rs | 4 +-- collator/src/lib.rs | 21 ++++++------ erasure-coding/src/lib.rs | 5 ++- network/src/legacy/collator_pool.rs | 5 ++- network/src/legacy/gossip/attestation.rs | 2 +- network/src/legacy/gossip/mod.rs | 6 ++-- network/src/legacy/local_collations.rs | 4 +-- network/src/legacy/mod.rs | 2 +- network/src/lib.rs | 2 +- network/src/protocol/mod.rs | 8 ++--- network/src/protocol/tests.rs | 6 ++-- node/core/proposer/src/lib.rs | 7 ++-- node/service/src/lib.rs | 3 +- .../adder/collator/src/main.rs | 4 +-- primitives/src/v1.rs | 7 ++-- rpc/src/lib.rs | 2 +- runtime/common/src/attestations.rs | 2 +- runtime/common/src/claims.rs | 2 +- runtime/common/src/crowdfund.rs | 4 +-- runtime/common/src/impls.rs | 4 +-- runtime/common/src/lib.rs | 2 +- runtime/common/src/parachains.rs | 34 ++++++++----------- runtime/common/src/registrar.rs | 16 ++++----- runtime/common/src/slots.rs | 5 ++- runtime/kusama/src/constants.rs | 6 ++-- runtime/kusama/src/lib.rs | 13 +++---- runtime/parachains/src/inclusion_inherent.rs | 7 ++-- runtime/polkadot/src/constants.rs | 6 ++-- runtime/polkadot/src/lib.rs | 13 +++---- runtime/polkadot/tests/weights.rs | 2 +- runtime/test-runtime/client/src/lib.rs | 2 +- runtime/test-runtime/src/constants.rs | 6 ++-- runtime/test-runtime/src/lib.rs | 11 +++--- runtime/westend/src/constants.rs | 6 ++-- runtime/westend/src/lib.rs | 13 +++---- service/src/chain_spec.rs | 6 ++-- service/src/grandpa_support.rs | 4 +-- service/src/lib.rs | 7 ++-- statement-table/src/lib.rs | 4 +-- validation/src/block_production.rs | 4 +-- validation/src/collation.rs | 6 ++-- validation/src/error.rs | 4 +-- validation/src/lib.rs | 2 +- validation/src/pipeline.rs | 4 +-- validation/src/shared_table/includable.rs | 2 +- validation/src/shared_table/mod.rs | 8 ++--- validation/src/validation_service/mod.rs | 8 ++--- 49 files changed, 148 insertions(+), 170 deletions(-) diff --git a/availability-store/src/lib.rs b/availability-store/src/lib.rs index 7abc444758f7..4b973c7d0271 100644 --- a/availability-store/src/lib.rs +++ b/availability-store/src/lib.rs @@ -25,12 +25,10 @@ use futures::prelude::*; use futures::channel::{mpsc, oneshot}; use keystore::KeyStorePtr; -use polkadot_primitives::{ +use polkadot_primitives::v0::{ Hash, Block, - parachain::{ - PoVBlock, AbridgedCandidateReceipt, ErasureChunk, - ParachainHost, AvailableData, OmittedValidationData, - }, + PoVBlock, AbridgedCandidateReceipt, ErasureChunk, + ParachainHost, AvailableData, OmittedValidationData, }; use sp_runtime::traits::HashFor; use sp_blockchain::Result as ClientResult; diff --git a/availability-store/src/store.rs b/availability-store/src/store.rs index 851beabc6ac8..ddba02d2bd9c 100644 --- a/availability-store/src/store.rs +++ b/availability-store/src/store.rs @@ -19,11 +19,8 @@ use kvdb_rocksdb::{Database, DatabaseConfig}; use kvdb::{KeyValueDB, DBTransaction}; use codec::{Encode, Decode}; use polkadot_erasure_coding as erasure; -use polkadot_primitives::{ - Hash, - parachain::{ - ErasureChunk, AvailableData, AbridgedCandidateReceipt, - }, +use polkadot_primitives::v0::{ + Hash, ErasureChunk, AvailableData, AbridgedCandidateReceipt, }; use parking_lot::Mutex; @@ -390,7 +387,7 @@ impl Store { mod tests { use super::*; use polkadot_erasure_coding::{self as erasure}; - use polkadot_primitives::parachain::{ + use polkadot_primitives::v0::{ Id as ParaId, BlockData, AvailableData, PoVBlock, OmittedValidationData, }; diff --git a/availability-store/src/worker.rs b/availability-store/src/worker.rs index 8a3898579f54..a7cf7ec41dae 100644 --- a/availability-store/src/worker.rs +++ b/availability-store/src/worker.rs @@ -33,8 +33,8 @@ use consensus_common::{ import_queue::CacheKeyId, }; use sp_core::traits::SpawnNamed; -use polkadot_primitives::{Block, BlockId, Hash}; -use polkadot_primitives::parachain::{ +use polkadot_primitives::v0::{ + Block, BlockId, Hash, ParachainHost, ValidatorId, AbridgedCandidateReceipt, AvailableData, ValidatorPair, ErasureChunk, }; diff --git a/collator/src/lib.rs b/collator/src/lib.rs index 0215b33ee6a1..663cb825bfc1 100644 --- a/collator/src/lib.rs +++ b/collator/src/lib.rs @@ -55,12 +55,11 @@ use log::warn; use sc_client_api::{StateBackend, BlockchainEvents}; use sp_blockchain::HeaderBackend; use sp_core::Pair; -use polkadot_primitives::{ +use polkadot_primitives::v0::{ BlockId, Hash, Block, DownwardMessage, - parachain::{ - self, BlockData, DutyRoster, HeadData, Id as ParaId, - PoVBlock, ValidatorId, CollatorPair, LocalValidationData, GlobalValidationSchedule, - } + BlockData, DutyRoster, HeadData, Id as ParaId, + PoVBlock, ValidatorId, CollatorPair, LocalValidationData, GlobalValidationSchedule, + Collation, CollationInfo, collator_signature_payload, }; use polkadot_cli::{ ProvideRuntimeApi, ParachainHost, IdentifyVariant, @@ -69,7 +68,7 @@ use polkadot_cli::{ pub use polkadot_cli::service::Configuration; pub use polkadot_cli::Cli; pub use polkadot_validation::SignedStatement; -pub use polkadot_primitives::parachain::CollatorId; +pub use polkadot_primitives::v0::CollatorId; pub use sc_network::PeerId; pub use service::RuntimeApiCollection; pub use sc_cli::SubstrateCli; @@ -164,7 +163,7 @@ pub async fn collate

( downward_messages: Vec, mut para_context: P, key: Arc, -) -> Option +) -> Option where P: ParachainContext, P::ProduceCandidate: Send, @@ -181,13 +180,13 @@ pub async fn collate

( }; let pov_block_hash = pov_block.hash(); - let signature = key.sign(¶chain::collator_signature_payload( + let signature = key.sign(&collator_signature_payload( &relay_parent, &local_id, &pov_block_hash, )); - let info = parachain::CollationInfo { + let info = CollationInfo { parachain_index: local_id, relay_parent, collator: key.public(), @@ -196,7 +195,7 @@ pub async fn collate

( pov_block_hash, }; - let collation = parachain::Collation { + let collation = Collation { info, pov: pov_block, }; @@ -456,7 +455,7 @@ where #[cfg(not(feature = "service-rewr"))] fn compute_targets(para_id: ParaId, session_keys: &[ValidatorId], roster: DutyRoster) -> HashSet { - use polkadot_primitives::parachain::Chain; + use polkadot_primitives::v0::Chain; roster.validator_duty.iter().enumerate() .filter(|&(_, c)| c == &Chain::Parachain(para_id)) diff --git a/erasure-coding/src/lib.rs b/erasure-coding/src/lib.rs index 98a2776d8848..c5f18bfe276c 100644 --- a/erasure-coding/src/lib.rs +++ b/erasure-coding/src/lib.rs @@ -26,8 +26,7 @@ use codec::{Encode, Decode}; use reed_solomon::galois_16::{self, ReedSolomon}; -use primitives::{Hash as H256, BlakeTwo256, HashT}; -use primitives::parachain::AvailableData; +use primitives::v0::{Hash as H256, BlakeTwo256, HashT, AvailableData}; use sp_core::Blake2Hasher; use trie::{EMPTY_PREFIX, MemoryDB, Trie, TrieMut, trie_types::{TrieDBMut, TrieDB}}; @@ -343,7 +342,7 @@ impl<'a, I: Iterator> codec::Input for ShardInput<'a, I> { #[cfg(test)] mod tests { use super::*; - use primitives::parachain::{BlockData, PoVBlock}; + use primitives::v0::{BlockData, PoVBlock}; #[test] fn field_order_is_right_size() { diff --git a/network/src/legacy/collator_pool.rs b/network/src/legacy/collator_pool.rs index a0c0a0458e90..f2b168e0f592 100644 --- a/network/src/legacy/collator_pool.rs +++ b/network/src/legacy/collator_pool.rs @@ -17,8 +17,7 @@ //! Bridge between the network and consensus service for getting collations to it. use codec::{Encode, Decode}; -use polkadot_primitives::Hash; -use polkadot_primitives::parachain::{CollatorId, Id as ParaId, Collation}; +use polkadot_primitives::v0::{Hash, CollatorId, Id as ParaId, Collation}; use sc_network::PeerId; use futures::channel::oneshot; @@ -236,7 +235,7 @@ impl CollatorPool { mod tests { use super::*; use sp_core::crypto::UncheckedInto; - use polkadot_primitives::parachain::{CollationInfo, BlockData, PoVBlock}; + use polkadot_primitives::v0::{CollationInfo, BlockData, PoVBlock}; use futures::executor::block_on; fn make_pov(block_data: Vec) -> PoVBlock { diff --git a/network/src/legacy/gossip/attestation.rs b/network/src/legacy/gossip/attestation.rs index a47f75288bf4..2d20ce63b995 100644 --- a/network/src/legacy/gossip/attestation.rs +++ b/network/src/legacy/gossip/attestation.rs @@ -33,7 +33,7 @@ use sc_network_gossip::{ValidationResult as GossipValidationResult}; use sc_network::ReputationChange; use polkadot_validation::GenericStatement; -use polkadot_primitives::Hash; +use polkadot_primitives::v0::Hash; use std::collections::HashMap; diff --git a/network/src/legacy/gossip/mod.rs b/network/src/legacy/gossip/mod.rs index 7dea99656667..9e18d7ce2171 100644 --- a/network/src/legacy/gossip/mod.rs +++ b/network/src/legacy/gossip/mod.rs @@ -58,8 +58,8 @@ use sc_network_gossip::{ ValidatorContext, MessageIntent, }; use polkadot_validation::{SignedStatement}; -use polkadot_primitives::{Block, Hash}; -use polkadot_primitives::parachain::{ +use polkadot_primitives::v0::{ + Block, Hash, ParachainHost, ValidatorId, ErasureChunk as PrimitiveChunk, SigningContext, PoVBlock, }; use polkadot_erasure_coding::{self as erasure}; @@ -755,7 +755,7 @@ mod tests { use sc_network_gossip::Validator as ValidatorT; use std::sync::mpsc; use parking_lot::Mutex; - use polkadot_primitives::parachain::{AbridgedCandidateReceipt, BlockData}; + use polkadot_primitives::v0::{AbridgedCandidateReceipt, BlockData}; use sp_core::sr25519::Signature as Sr25519Signature; use polkadot_validation::GenericStatement; diff --git a/network/src/legacy/local_collations.rs b/network/src/legacy/local_collations.rs index 6bc9b985a7c1..d85911548613 100644 --- a/network/src/legacy/local_collations.rs +++ b/network/src/legacy/local_collations.rs @@ -19,7 +19,7 @@ //! Collations are attempted to be repropagated when a new validator connects, //! a validator changes his session key, or when they are generated. -use polkadot_primitives::{Hash, parachain::{ValidatorId}}; +use polkadot_primitives::v0::{Hash, ValidatorId}; use crate::legacy::collator_pool::Role; use std::collections::{HashMap, HashSet}; use std::time::Duration; @@ -144,7 +144,7 @@ impl LocalCollations { mod tests { use super::*; use sp_core::crypto::UncheckedInto; - use polkadot_primitives::parachain::ValidatorId; + use polkadot_primitives::v0::ValidatorId; #[test] fn add_validator_with_ready_collation() { diff --git a/network/src/legacy/mod.rs b/network/src/legacy/mod.rs index 28ea77a6bdc1..42698657c053 100644 --- a/network/src/legacy/mod.rs +++ b/network/src/legacy/mod.rs @@ -25,7 +25,7 @@ pub mod gossip; use codec::Decode; use futures::prelude::*; -use polkadot_primitives::Hash; +use polkadot_primitives::v0::Hash; use sc_network::PeerId; use sc_network_gossip::TopicNotification; use log::debug; diff --git a/network/src/lib.rs b/network/src/lib.rs index 5048f09adaf5..eaed7b34d2cb 100644 --- a/network/src/lib.rs +++ b/network/src/lib.rs @@ -21,7 +21,7 @@ #![recursion_limit="256"] -use polkadot_primitives::{Block, Hash, BlakeTwo256, HashT}; +use polkadot_primitives::v0::{Block, Hash, BlakeTwo256, HashT}; pub mod legacy; pub mod protocol; diff --git a/network/src/protocol/mod.rs b/network/src/protocol/mod.rs index c36dbf1945ee..50a77ece04c6 100644 --- a/network/src/protocol/mod.rs +++ b/network/src/protocol/mod.rs @@ -30,12 +30,10 @@ use futures::task::{Context, Poll}; use futures::stream::{FuturesUnordered, StreamFuture}; use log::{debug, trace}; -use polkadot_primitives::{ +use polkadot_primitives::v0::{ Hash, Block, - parachain::{ - PoVBlock, ValidatorId, ValidatorIndex, Collation, AbridgedCandidateReceipt, - ErasureChunk, ParachainHost, Id as ParaId, CollatorId, - }, + PoVBlock, ValidatorId, ValidatorIndex, Collation, AbridgedCandidateReceipt, + ErasureChunk, ParachainHost, Id as ParaId, CollatorId, }; use polkadot_validation::{ SharedTable, TableRouter, Network as ParachainNetwork, Validated, GenericStatement, Collators, diff --git a/network/src/protocol/tests.rs b/network/src/protocol/tests.rs index 049af3f5aca7..711906797be4 100644 --- a/network/src/protocol/tests.rs +++ b/network/src/protocol/tests.rs @@ -17,8 +17,8 @@ use super::*; use crate::legacy::gossip::GossipPoVBlock; use parking_lot::Mutex; -use polkadot_primitives::Block; -use polkadot_primitives::parachain::{ +use polkadot_primitives::v0::{ + Block, Id as ParaId, Chain, DutyRoster, ParachainHost, ValidatorId, Retriable, CollatorId, AbridgedCandidateReceipt, GlobalValidationSchedule, LocalValidationData, ErasureChunk, SigningContext, @@ -198,7 +198,7 @@ sp_api::mock_impl_runtime_apis! { parent_hash: Default::default(), } } - fn downward_messages(_: ParaId) -> Vec { + fn downward_messages(_: ParaId) -> Vec { Vec::new() } } diff --git a/node/core/proposer/src/lib.rs b/node/core/proposer/src/lib.rs index 1a0f1a9f8507..d43810227ba4 100644 --- a/node/core/proposer/src/lib.rs +++ b/node/core/proposer/src/lib.rs @@ -2,9 +2,8 @@ use futures::prelude::*; use futures::select; use polkadot_node_subsystem::{messages::{AllMessages, ProvisionerInherentData, ProvisionerMessage}, SubsystemError}; use polkadot_overseer::OverseerHandler; -use polkadot_primitives::{ - inclusion_inherent, - v1::{Block, Hash, Header}, +use polkadot_primitives::v1::{ + Block, Hash, Header, }; use sc_block_builder::{BlockBuilderApi, BlockBuilderProvider}; use sp_api::{ApiExt, ProvideRuntimeApi}; @@ -185,7 +184,7 @@ where }; inherent_data.put_data( - inclusion_inherent::INHERENT_IDENTIFIER, + polkadot_primitives::v1::INCLUSION_INHERENT_IDENTIFIER, &provisioner_data, )?; diff --git a/node/service/src/lib.rs b/node/service/src/lib.rs index 21feaee0749c..6a40e788e85c 100644 --- a/node/service/src/lib.rs +++ b/node/service/src/lib.rs @@ -48,8 +48,7 @@ pub use sc_consensus::LongestChain; pub use sp_api::{ApiRef, Core as CoreApi, ConstructRuntimeApi, ProvideRuntimeApi, StateBackend}; pub use sp_runtime::traits::{DigestFor, HashFor, NumberFor}; pub use consensus_common::{Proposal, SelectChain, BlockImport, RecordProof, block_validation::Chain}; -pub use polkadot_primitives::v1::{CollatorId, Id as ParaId}; -pub use polkadot_primitives::{Block, BlockId}; +pub use polkadot_primitives::v1::{Block, BlockId, CollatorId, Id as ParaId}; pub use sp_runtime::traits::{Block as BlockT, self as runtime_traits, BlakeTwo256}; pub use chain_spec::{PolkadotChainSpec, KusamaChainSpec, WestendChainSpec}; #[cfg(feature = "full-node")] diff --git a/parachain/test-parachains/adder/collator/src/main.rs b/parachain/test-parachains/adder/collator/src/main.rs index 42c3c824004a..ec5b626883c1 100644 --- a/parachain/test-parachains/adder/collator/src/main.rs +++ b/parachain/test-parachains/adder/collator/src/main.rs @@ -22,9 +22,9 @@ use std::sync::Arc; use adder::{HeadData as AdderHead, BlockData as AdderBody}; use sp_core::Pair; use codec::{Encode, Decode}; -use primitives::{ +use primitives::v0::{ Hash, DownwardMessage, - parachain::{HeadData, BlockData, Id as ParaId, LocalValidationData, GlobalValidationSchedule}, + HeadData, BlockData, Id as ParaId, LocalValidationData, GlobalValidationSchedule, }; use collator::{ParachainContext, Network, BuildParachainContext, Cli, SubstrateCli}; use parking_lot::Mutex; diff --git a/primitives/src/v1.rs b/primitives/src/v1.rs index 12f2bea1e953..26c402cdad21 100644 --- a/primitives/src/v1.rs +++ b/primitives/src/v1.rs @@ -25,11 +25,10 @@ use bitvec::vec::BitVec; use serde::{Serialize, Deserialize}; #[cfg(feature = "std")] -use primitives::{bytes, crypto::Pair}; +use primitives::{bytes}; use primitives::RuntimeDebug; -use runtime_primitives::traits::{AppVerify, Block as BlockT}; +use runtime_primitives::traits::AppVerify; use inherents::InherentIdentifier; -use application_crypto::KeyTypeId; use runtime_primitives::traits::{BlakeTwo256, Hash as HashT}; @@ -58,7 +57,7 @@ pub use crate::v0::{ pub use crate::v0::{ValidatorPair, CollatorPair}; /// Unique identifier for the Inclusion Inherent -pub const INHERENT_IDENTIFIER: InherentIdentifier = *b"inclusn0"; +pub const INCLUSION_INHERENT_IDENTIFIER: InherentIdentifier = *b"inclusn0"; /// Get a collator signature payload on a relay-parent, block-data combo. pub fn collator_signature_payload>( diff --git a/rpc/src/lib.rs b/rpc/src/lib.rs index 6bddc8ad8daf..c73b478329ee 100644 --- a/rpc/src/lib.rs +++ b/rpc/src/lib.rs @@ -20,7 +20,7 @@ use std::sync::Arc; -use polkadot_primitives::{Block, BlockNumber, AccountId, Nonce, Balance, Hash}; +use polkadot_primitives::v0::{Block, BlockNumber, AccountId, Nonce, Balance, Hash}; use sp_api::ProvideRuntimeApi; use txpool_api::TransactionPool; use sp_blockchain::{HeaderBackend, HeaderMetadata, Error as BlockChainError}; diff --git a/runtime/common/src/attestations.rs b/runtime/common/src/attestations.rs index f27874117aaa..e7a6854bbb13 100644 --- a/runtime/common/src/attestations.rs +++ b/runtime/common/src/attestations.rs @@ -28,7 +28,7 @@ use frame_support::{ weights::DispatchClass, }; -use primitives::{Hash, parachain::{AttestedCandidate, AbridgedCandidateReceipt, Id as ParaId}}; +use primitives::v0::{Hash, AttestedCandidate, AbridgedCandidateReceipt, Id as ParaId}; use sp_runtime::RuntimeDebug; use sp_staking::SessionIndex; diff --git a/runtime/common/src/claims.rs b/runtime/common/src/claims.rs index fd8c1c1c880a..6efc3d31d75d 100644 --- a/runtime/common/src/claims.rs +++ b/runtime/common/src/claims.rs @@ -35,7 +35,7 @@ use sp_runtime::{ TransactionSource, TransactionValidityError, }, }; -use primitives::ValidityError; +use primitives::v0::ValidityError; type CurrencyOf = <::VestingSchedule as VestingSchedule<::AccountId>>::Currency; type BalanceOf = as Currency<::AccountId>>::Balance; diff --git a/runtime/common/src/crowdfund.rs b/runtime/common/src/crowdfund.rs index ee2b740745b7..fc233d107abe 100644 --- a/runtime/common/src/crowdfund.rs +++ b/runtime/common/src/crowdfund.rs @@ -79,7 +79,7 @@ use sp_runtime::{ModuleId, use crate::slots; use codec::{Encode, Decode}; use sp_std::vec::Vec; -use primitives::parachain::{Id as ParaId, HeadData}; +use primitives::v0::{Id as ParaId, HeadData}; pub type BalanceOf = <::Currency as Currency<::AccountId>>::Balance; @@ -568,7 +568,7 @@ mod tests { }; use frame_support::traits::{Contains, ContainsLengthBound}; use sp_core::H256; - use primitives::parachain::{Info as ParaInfo, Id as ParaId, Scheduling, ValidationCode}; + use primitives::v0::{Info as ParaInfo, Id as ParaId, Scheduling, ValidationCode}; // The testing primitives are very useful for avoiding having to work with signatures // or public keys. `u64` is used as the `AccountId` and no `Signature`s are requried. use sp_runtime::{ diff --git a/runtime/common/src/impls.rs b/runtime/common/src/impls.rs index 543e2c739adb..7e3b6d917f77 100644 --- a/runtime/common/src/impls.rs +++ b/runtime/common/src/impls.rs @@ -26,8 +26,8 @@ pub struct ToAuthor(sp_std::marker::PhantomData); impl OnUnbalanced> for ToAuthor where R: balances::Trait + authorship::Trait, - ::AccountId: From, - ::AccountId: Into, + ::AccountId: From, + ::AccountId: Into, ::Event: From::AccountId, ::Balance, diff --git a/runtime/common/src/lib.rs b/runtime/common/src/lib.rs index da6fc5fcc27b..d32db38e05be 100644 --- a/runtime/common/src/lib.rs +++ b/runtime/common/src/lib.rs @@ -27,7 +27,7 @@ pub mod slots; pub mod crowdfund; pub mod impls; -use primitives::BlockNumber; +use primitives::v0::BlockNumber; use sp_runtime::{Perquintill, Perbill, FixedPointNumber, traits::Saturating}; use frame_support::{ parameter_types, traits::{Currency}, diff --git a/runtime/common/src/parachains.rs b/runtime/common/src/parachains.rs index 25d93b6fde78..b0228a5a53c8 100644 --- a/runtime/common/src/parachains.rs +++ b/runtime/common/src/parachains.rs @@ -37,16 +37,13 @@ use frame_support::{ dispatch::IsSubType, weights::{DispatchClass, Weight}, }; -use primitives::{ - Balance, - BlockNumber, - parachain::{ - Id as ParaId, Chain, DutyRoster, AttestedCandidate, CompactStatement as Statement, ParachainDispatchOrigin, - UpwardMessage, ValidatorId, ActiveParas, CollatorId, Retriable, OmittedValidationData, - CandidateReceipt, GlobalValidationSchedule, AbridgedCandidateReceipt, - LocalValidationData, Scheduling, ValidityAttestation, NEW_HEADS_IDENTIFIER, PARACHAIN_KEY_TYPE_ID, - ValidatorSignature, SigningContext, HeadData, ValidationCode, - }, +use primitives::v0::{ + Balance, BlockNumber, + Id as ParaId, Chain, DutyRoster, AttestedCandidate, CompactStatement as Statement, ParachainDispatchOrigin, + UpwardMessage, ValidatorId, ActiveParas, CollatorId, Retriable, OmittedValidationData, + CandidateReceipt, GlobalValidationSchedule, AbridgedCandidateReceipt, + LocalValidationData, Scheduling, ValidityAttestation, NEW_HEADS_IDENTIFIER, PARACHAIN_KEY_TYPE_ID, + ValidatorSignature, SigningContext, HeadData, ValidationCode, Remark, DownwardMessage }; use frame_support::{ @@ -329,7 +326,7 @@ pub trait Trait: CreateSignedTransaction> + attestations::Trait + ses >; /// A type that converts the opaque hash type to exact one. - type BlockHashConversion: Convert; + type BlockHashConversion: Convert; } /// Origin for the parachains module. @@ -1681,13 +1678,10 @@ mod tests { }, testing::TestXt, }; - use primitives::{ - parachain::{ - CandidateReceipt, ValidityAttestation, ValidatorId, Info as ParaInfo, - Scheduling, CandidateCommitments, - }, - BlockNumber, - Header, + use primitives::v0::{ + CandidateReceipt, ValidityAttestation, ValidatorId, Info as ParaInfo, + Scheduling, CandidateCommitments, + BlockNumber, Header, }; use keyring::Sr25519Keyring; use frame_support::{ @@ -1819,7 +1813,7 @@ mod tests { } mod time { - use primitives::{Moment, BlockNumber}; + use primitives::v0::{Moment, BlockNumber}; pub const MILLISECS_PER_BLOCK: Moment = 6000; pub const EPOCH_DURATION_IN_BLOCKS: BlockNumber = 1 * HOURS; // These time units are defined in number of blocks. @@ -2246,7 +2240,7 @@ mod tests { println!("session index {}", i); Staking::on_finalize(System::block_number()); System::set_block_number((i + 1).into()); - Timestamp::set_timestamp(System::block_number() as primitives::Moment * 6000); + Timestamp::set_timestamp(System::block_number() as primitives::v0::Moment * 6000); // In order to be able to use `System::parent_hash()` in the tests // we need to first get it via `System::finalize` and then set it diff --git a/runtime/common/src/registrar.rs b/runtime/common/src/registrar.rs index de152d9379b5..d7b9cb40caf9 100644 --- a/runtime/common/src/registrar.rs +++ b/runtime/common/src/registrar.rs @@ -34,7 +34,7 @@ use frame_support::{ weights::{DispatchClass, Weight}, }; use system::{self, ensure_root, ensure_signed}; -use primitives::parachain::{ +use primitives::v0::{ Id as ParaId, CollatorId, Scheduling, LOWEST_USER_ID, SwapAux, Info as ParaInfo, ActiveParas, Retriable, ValidationCode, HeadData, }; @@ -213,7 +213,7 @@ fn build(config: &GenesisConfig) { Parachains::put(&only_ids); for (id, code, genesis) in p { - Paras::insert(id, &primitives::parachain::PARACHAIN_INFO); + Paras::insert(id, &primitives::v0::PARACHAIN_INFO); // no ingress -- a chain cannot be routed to until it is live. ::insert(&id, &code); ::insert(&id, &genesis); @@ -670,12 +670,10 @@ mod tests { AccountIdConversion, Extrinsic as ExtrinsicT, }, testing::{UintAuthorityId, TestXt}, KeyTypeId, Perbill, curve::PiecewiseLinear, }; - use primitives::{ - parachain::{ - ValidatorId, Info as ParaInfo, Scheduling, LOWEST_USER_ID, AttestedCandidate, - CandidateReceipt, HeadData, ValidityAttestation, CompactStatement as Statement, Chain, - CollatorPair, CandidateCommitments, - }, + use primitives::v0::{ + ValidatorId, Info as ParaInfo, Scheduling, LOWEST_USER_ID, AttestedCandidate, + CandidateReceipt, HeadData, ValidityAttestation, CompactStatement as Statement, Chain, + CollatorPair, CandidateCommitments, Balance, BlockNumber, Header, Signature, }; use frame_support::{ @@ -869,7 +867,7 @@ mod tests { // This is needed for a custom `AccountId` type which is `u64` in testing here. pub mod test_keys { use sp_core::{crypto::KeyTypeId, sr25519}; - use primitives::Signature; + use primitives::v0::Signature; pub const KEY_TYPE: KeyTypeId = KeyTypeId(*b"test"); diff --git a/runtime/common/src/slots.rs b/runtime/common/src/slots.rs index 5618a680c5a0..eb0a7aff7d72 100644 --- a/runtime/common/src/slots.rs +++ b/runtime/common/src/slots.rs @@ -28,7 +28,7 @@ use frame_support::{ traits::{Currency, ReservableCurrency, WithdrawReason, ExistenceRequirement, Get, Randomness}, weights::{DispatchClass, Weight}, }; -use primitives::parachain::{ +use primitives::v0::{ SwapAux, PARACHAIN_INFO, Id as ParaId, ValidationCode, HeadData, }; use system::{ensure_signed, ensure_root}; @@ -890,8 +890,7 @@ mod tests { traits::{OnInitialize, OnFinalize} }; use balances; - use primitives::{BlockNumber, Header}; - use primitives::parachain::{Id as ParaId, Info as ParaInfo, Scheduling}; + use primitives::v0::{BlockNumber, Header, Id as ParaId, Info as ParaInfo, Scheduling}; impl_outer_origin! { pub enum Origin for Test {} diff --git a/runtime/kusama/src/constants.rs b/runtime/kusama/src/constants.rs index e06325d1bb95..560d83347d9b 100644 --- a/runtime/kusama/src/constants.rs +++ b/runtime/kusama/src/constants.rs @@ -16,7 +16,7 @@ /// Money matters. pub mod currency { - use primitives::Balance; + use primitives::v0::Balance; pub const DOTS: Balance = 1_000_000_000_000; pub const DOLLARS: Balance = DOTS / 6; @@ -30,7 +30,7 @@ pub mod currency { /// Time and blocks. pub mod time { - use primitives::{Moment, BlockNumber}; + use primitives::v0::{Moment, BlockNumber}; // Kusama & mainnet pub const MILLISECS_PER_BLOCK: Moment = 6000; // Testnet @@ -55,7 +55,7 @@ pub mod time { /// Fee-related. pub mod fee { pub use sp_runtime::Perbill; - use primitives::Balance; + use primitives::v0::Balance; use runtime_common::ExtrinsicBaseWeight; use frame_support::weights::{ WeightToFeePolynomial, WeightToFeeCoefficient, WeightToFeeCoefficients, diff --git a/runtime/kusama/src/lib.rs b/runtime/kusama/src/lib.rs index ee25e8961dec..569d055ccafe 100644 --- a/runtime/kusama/src/lib.rs +++ b/runtime/kusama/src/lib.rs @@ -23,9 +23,10 @@ use sp_std::prelude::*; use sp_core::u32_trait::{_1, _2, _3, _4, _5}; use codec::{Encode, Decode}; -use primitives::{ +use primitives::v0::{ + self as parachain, AccountId, AccountIndex, Balance, BlockNumber, Hash, Nonce, Signature, Moment, - parachain::{self, ActiveParas, AbridgedCandidateReceipt, SigningContext}, + ActiveParas, AbridgedCandidateReceipt, SigningContext, }; use runtime_common::{ attestations, claims, parachains, registrar, slots, SlowAdjustingFeeUpdate, @@ -560,7 +561,7 @@ impl grandpa::Trait for Runtime { type HandleEquivocation = grandpa::EquivocationHandler< Self::KeyOwnerIdentification, - primitives::fisherman::FishermanAppCrypto, + primitives::v0::fisherman::FishermanAppCrypto, Runtime, Offences, >; @@ -596,7 +597,7 @@ parameter_types! { } impl parachains::Trait for Runtime { - type AuthorityId = primitives::fisherman::FishermanAppCrypto; + type AuthorityId = primitives::v0::fisherman::FishermanAppCrypto; type Origin = Origin; type Call = Call; type ParachainCurrency = Balances; @@ -939,7 +940,7 @@ impl frame_support::traits::OnRuntimeUpgrade for CustomOnRuntimeUpgrade { construct_runtime! { pub enum Runtime where Block = Block, - NodeBlock = primitives::Block, + NodeBlock = primitives::v0::Block, UncheckedExtrinsic = UncheckedExtrinsic { // Basic stuff; balances is uncallable initially. @@ -1147,7 +1148,7 @@ sp_api::impl_runtime_apis! { fn signing_context() -> SigningContext { Parachains::signing_context() } - fn downward_messages(id: parachain::Id) -> Vec { + fn downward_messages(id: parachain::Id) -> Vec { Parachains::downward_messages(id) } } diff --git a/runtime/parachains/src/inclusion_inherent.rs b/runtime/parachains/src/inclusion_inherent.rs index 6ce93feab3f1..6d06961b461a 100644 --- a/runtime/parachains/src/inclusion_inherent.rs +++ b/runtime/parachains/src/inclusion_inherent.rs @@ -22,9 +22,8 @@ //! this module. use sp_std::prelude::*; -use primitives::{ - inclusion_inherent, - v1::{BackedCandidate, SignedAvailabilityBitfields}, +use primitives::v1::{ + BackedCandidate, SignedAvailabilityBitfields, INCLUSION_INHERENT_IDENTIFIER, }; use frame_support::{ decl_error, decl_module, decl_storage, ensure, @@ -127,7 +126,7 @@ decl_module! { impl ProvideInherent for Module { type Call = Call; type Error = MakeFatalError<()>; - const INHERENT_IDENTIFIER: InherentIdentifier = inclusion_inherent::INHERENT_IDENTIFIER; + const INHERENT_IDENTIFIER: InherentIdentifier = INCLUSION_INHERENT_IDENTIFIER; fn create_inherent(data: &InherentData) -> Option { data.get_data(&Self::INHERENT_IDENTIFIER) diff --git a/runtime/polkadot/src/constants.rs b/runtime/polkadot/src/constants.rs index 331d97f364cf..8ad5478bcab8 100644 --- a/runtime/polkadot/src/constants.rs +++ b/runtime/polkadot/src/constants.rs @@ -16,7 +16,7 @@ /// Money matters. pub mod currency { - use primitives::Balance; + use primitives::v0::Balance; pub const DOTS: Balance = 1_000_000_000_000; pub const DOLLARS: Balance = DOTS / 100; // 10_000_000_000 @@ -30,7 +30,7 @@ pub mod currency { /// Time and blocks. pub mod time { - use primitives::{Moment, BlockNumber}; + use primitives::v0::{Moment, BlockNumber}; pub const MILLISECS_PER_BLOCK: Moment = 6000; pub const SLOT_DURATION: Moment = MILLISECS_PER_BLOCK; pub const EPOCH_DURATION_IN_BLOCKS: BlockNumber = 4 * HOURS; @@ -47,7 +47,7 @@ pub mod time { /// Fee-related. pub mod fee { pub use sp_runtime::Perbill; - use primitives::Balance; + use primitives::v0::Balance; use runtime_common::ExtrinsicBaseWeight; use frame_support::weights::{ WeightToFeePolynomial, WeightToFeeCoefficient, WeightToFeeCoefficients, diff --git a/runtime/polkadot/src/lib.rs b/runtime/polkadot/src/lib.rs index abd9687164c2..258a7b4781b4 100644 --- a/runtime/polkadot/src/lib.rs +++ b/runtime/polkadot/src/lib.rs @@ -31,9 +31,10 @@ use runtime_common::{ use sp_std::prelude::*; use sp_core::u32_trait::{_1, _2, _3, _4, _5}; use codec::{Encode, Decode}; -use primitives::{ +use primitives::v0::{ + self as parachain, AccountId, AccountIndex, Balance, BlockNumber, Hash, Nonce, Signature, Moment, - parachain::{self, ActiveParas, AbridgedCandidateReceipt, SigningContext}, + ActiveParas, AbridgedCandidateReceipt, SigningContext, }; use sp_runtime::{ create_runtime_str, generic, impl_opaque_keys, ModuleId, @@ -629,7 +630,7 @@ impl grandpa::Trait for Runtime { type HandleEquivocation = grandpa::EquivocationHandler< Self::KeyOwnerIdentification, - primitives::fisherman::FishermanAppCrypto, + primitives::v0::fisherman::FishermanAppCrypto, Runtime, Offences, >; @@ -666,7 +667,7 @@ parameter_types! { } impl parachains::Trait for Runtime { - type AuthorityId = primitives::fisherman::FishermanAppCrypto; + type AuthorityId = primitives::v0::fisherman::FishermanAppCrypto; type Origin = Origin; type Call = Call; type ParachainCurrency = Balances; @@ -943,7 +944,7 @@ impl frame_support::traits::OnRuntimeUpgrade for CustomOnRuntimeUpgrade { construct_runtime! { pub enum Runtime where Block = Block, - NodeBlock = primitives::Block, + NodeBlock = primitives::v0::Block, UncheckedExtrinsic = UncheckedExtrinsic { // Basic stuff; balances is uncallable initially. @@ -1147,7 +1148,7 @@ sp_api::impl_runtime_apis! { fn signing_context() -> SigningContext { Parachains::signing_context() } - fn downward_messages(id: parachain::Id) -> Vec { + fn downward_messages(id: parachain::Id) -> Vec { Parachains::downward_messages(id) } } diff --git a/runtime/polkadot/tests/weights.rs b/runtime/polkadot/tests/weights.rs index 533783a4e491..3cdb71995801 100644 --- a/runtime/polkadot/tests/weights.rs +++ b/runtime/polkadot/tests/weights.rs @@ -29,7 +29,7 @@ use frame_support::{ use keyring::AccountKeyring; use polkadot_runtime::constants::currency::*; use polkadot_runtime::{self, Runtime}; -use primitives::AccountId; +use primitives::v0::AccountId; use runtime_common::MaximumBlockWeight; use democracy::Call as DemocracyCall; diff --git a/runtime/test-runtime/client/src/lib.rs b/runtime/test-runtime/client/src/lib.rs index 2e026647195f..5417d30ee897 100644 --- a/runtime/test-runtime/client/src/lib.rs +++ b/runtime/test-runtime/client/src/lib.rs @@ -323,7 +323,7 @@ pub fn new_native_executor() -> sc_executor::NativeExecutor { } /// Extrinsics that must be included in each block. -pub fn needed_extrinsics(heads: Vec) -> Vec { +pub fn needed_extrinsics(heads: Vec) -> Vec { use polkadot_runtime_common::parachains; vec![ diff --git a/runtime/test-runtime/src/constants.rs b/runtime/test-runtime/src/constants.rs index b0431e55f268..ac90417b214c 100644 --- a/runtime/test-runtime/src/constants.rs +++ b/runtime/test-runtime/src/constants.rs @@ -16,7 +16,7 @@ /// Money matters. pub mod currency { - use primitives::Balance; + use primitives::v0::Balance; pub const DOTS: Balance = 1_000_000_000_000; pub const DOLLARS: Balance = DOTS; @@ -26,7 +26,7 @@ pub mod currency { /// Time and blocks. pub mod time { - use primitives::{Moment, BlockNumber}; + use primitives::v0::{Moment, BlockNumber}; // Testnet pub const MILLISECS_PER_BLOCK: Moment = 1000; pub const SLOT_DURATION: Moment = MILLISECS_PER_BLOCK; @@ -45,7 +45,7 @@ pub mod time { /// Fee-related. pub mod fee { pub use sp_runtime::Perbill; - use primitives::Balance; + use primitives::v0::Balance; use runtime_common::ExtrinsicBaseWeight; use frame_support::weights::{ WeightToFeePolynomial, WeightToFeeCoefficient, WeightToFeeCoefficients, diff --git a/runtime/test-runtime/src/lib.rs b/runtime/test-runtime/src/lib.rs index 31b17002fe6f..93a488c9d97d 100644 --- a/runtime/test-runtime/src/lib.rs +++ b/runtime/test-runtime/src/lib.rs @@ -22,9 +22,10 @@ use rstd::prelude::*; use codec::{Encode, Decode}; -use primitives::{ +use primitives::v0::{ + self as parachain, AccountId, AccountIndex, Balance, BlockNumber, Hash as HashT, Nonce, Signature, Moment, - parachain::{self, ActiveParas, AbridgedCandidateReceipt, SigningContext}, ValidityError, + ActiveParas, AbridgedCandidateReceipt, SigningContext, ValidityError, }; use runtime_common::{ attestations, claims, parachains, registrar, slots, SlowAdjustingFeeUpdate, @@ -375,7 +376,7 @@ parameter_types! { } impl parachains::Trait for Runtime { - type AuthorityId = primitives::fisherman::FishermanAppCrypto; + type AuthorityId = primitives::v0::fisherman::FishermanAppCrypto; type Origin = Origin; type Call = Call; type ParachainCurrency = Balances; @@ -514,7 +515,7 @@ impl vesting::Trait for Runtime { construct_runtime! { pub enum Runtime where Block = Block, - NodeBlock = primitives::Block, + NodeBlock = primitives::v0::Block, UncheckedExtrinsic = UncheckedExtrinsic { // Basic stuff; balances is uncallable initially. @@ -679,7 +680,7 @@ sp_api::impl_runtime_apis! { fn signing_context() -> SigningContext { Parachains::signing_context() } - fn downward_messages(id: parachain::Id) -> Vec { + fn downward_messages(id: parachain::Id) -> Vec { Parachains::downward_messages(id) } } diff --git a/runtime/westend/src/constants.rs b/runtime/westend/src/constants.rs index ac25d621d856..f59a384fba8b 100644 --- a/runtime/westend/src/constants.rs +++ b/runtime/westend/src/constants.rs @@ -16,7 +16,7 @@ /// Money matters. pub mod currency { - use primitives::Balance; + use primitives::v0::Balance; pub const DOTS: Balance = 1_000_000_000_000; pub const DOLLARS: Balance = DOTS; @@ -30,7 +30,7 @@ pub mod currency { /// Time and blocks. pub mod time { - use primitives::{Moment, BlockNumber}; + use primitives::v0::{Moment, BlockNumber}; pub const MILLISECS_PER_BLOCK: Moment = 6000; pub const SLOT_DURATION: Moment = MILLISECS_PER_BLOCK; pub const EPOCH_DURATION_IN_BLOCKS: BlockNumber = 1 * HOURS; @@ -47,7 +47,7 @@ pub mod time { /// Fee-related. pub mod fee { pub use sp_runtime::Perbill; - use primitives::Balance; + use primitives::v0::Balance; use runtime_common::ExtrinsicBaseWeight; use frame_support::weights::{ WeightToFeePolynomial, WeightToFeeCoefficient, WeightToFeeCoefficients, diff --git a/runtime/westend/src/lib.rs b/runtime/westend/src/lib.rs index 41613bbb0118..a40c4e3dd5a7 100644 --- a/runtime/westend/src/lib.rs +++ b/runtime/westend/src/lib.rs @@ -22,9 +22,10 @@ use sp_std::prelude::*; use codec::{Encode, Decode}; -use primitives::{ +use primitives::v0::{ + self as parachain, AccountId, AccountIndex, Balance, BlockNumber, Hash, Nonce, Signature, Moment, - parachain::{self, ActiveParas, AbridgedCandidateReceipt, SigningContext}, + ActiveParas, AbridgedCandidateReceipt, SigningContext, }; use runtime_common::{ attestations, parachains, registrar, SlowAdjustingFeeUpdate, @@ -385,7 +386,7 @@ impl grandpa::Trait for Runtime { type HandleEquivocation = grandpa::EquivocationHandler< Self::KeyOwnerIdentification, - primitives::fisherman::FishermanAppCrypto, + primitives::v0::fisherman::FishermanAppCrypto, Runtime, Offences, >; @@ -421,7 +422,7 @@ parameter_types! { } impl parachains::Trait for Runtime { - type AuthorityId = primitives::fisherman::FishermanAppCrypto; + type AuthorityId = primitives::v0::fisherman::FishermanAppCrypto; type Origin = Origin; type Call = Call; type ParachainCurrency = Balances; @@ -698,7 +699,7 @@ impl proxy::Trait for Runtime { construct_runtime! { pub enum Runtime where Block = Block, - NodeBlock = primitives::Block, + NodeBlock = primitives::v0::Block, UncheckedExtrinsic = UncheckedExtrinsic { // Basic stuff; balances is uncallable initially. @@ -887,7 +888,7 @@ sp_api::impl_runtime_apis! { fn signing_context() -> SigningContext { Parachains::signing_context() } - fn downward_messages(id: parachain::Id) -> Vec { + fn downward_messages(id: parachain::Id) -> Vec { Parachains::downward_messages(id) } } diff --git a/service/src/chain_spec.rs b/service/src/chain_spec.rs index 5e1bfbbdbab0..fe8d98d0553f 100644 --- a/service/src/chain_spec.rs +++ b/service/src/chain_spec.rs @@ -17,7 +17,7 @@ //! Polkadot chain configurations. use sp_core::{Pair, Public, crypto::UncheckedInto, sr25519}; -use polkadot_primitives::{AccountId, AccountPublic, parachain::ValidatorId}; +use polkadot_primitives::v0::{AccountId, AccountPublic, ValidatorId}; use polkadot_runtime as polkadot; use kusama_runtime as kusama; use westend_runtime as westend; @@ -48,9 +48,9 @@ const DEFAULT_PROTOCOL_ID: &str = "dot"; #[serde(rename_all = "camelCase")] pub struct Extensions { /// Block numbers with known hashes. - pub fork_blocks: sc_client_api::ForkBlocks, + pub fork_blocks: sc_client_api::ForkBlocks, /// Known bad block hashes. - pub bad_blocks: sc_client_api::BadBlocks, + pub bad_blocks: sc_client_api::BadBlocks, } /// The `ChainSpec parametrised for polkadot runtime`. diff --git a/service/src/grandpa_support.rs b/service/src/grandpa_support.rs index a875c4b45a37..60ab0434f72d 100644 --- a/service/src/grandpa_support.rs +++ b/service/src/grandpa_support.rs @@ -16,7 +16,7 @@ //! Polkadot-specific GRANDPA integration utilities. -use polkadot_primitives::Hash; +use polkadot_primitives::v0::Hash; use sp_runtime::traits::{Block as BlockT, NumberFor}; /// A custom GRANDPA voting rule that "pauses" voting (i.e. keeps voting for the @@ -98,7 +98,7 @@ impl grandpa::VotingRule for PauseAfterBlockFor Vec<( grandpa_primitives::SetId, - (Hash, polkadot_primitives::BlockNumber), + (Hash, polkadot_primitives::v0::BlockNumber), grandpa_primitives::AuthorityList, )> { use sp_core::crypto::Ss58Codec; diff --git a/service/src/lib.rs b/service/src/lib.rs index 33d02f53154a..1841e320aa45 100644 --- a/service/src/lib.rs +++ b/service/src/lib.rs @@ -22,7 +22,7 @@ mod client; use std::sync::Arc; use std::time::Duration; -use polkadot_primitives::{parachain, Hash, BlockId, AccountId, Nonce, Balance}; +use polkadot_primitives::v0::{self as parachain, Hash, BlockId, AccountId, Nonce, Balance}; #[cfg(feature = "full-node")] use polkadot_network::{legacy::gossip::Known, protocol as network_protocol}; use service::{error::Error as ServiceError, ServiceBuilder}; @@ -42,8 +42,7 @@ pub use sc_consensus::LongestChain; pub use sp_api::{Core as CoreApi, ConstructRuntimeApi, ProvideRuntimeApi, StateBackend}; pub use sp_runtime::traits::{HashFor, NumberFor}; pub use consensus_common::{SelectChain, BlockImport, block_validation::Chain}; -pub use polkadot_primitives::parachain::{CollatorId, ParachainHost}; -pub use polkadot_primitives::Block; +pub use polkadot_primitives::v0::{Block, CollatorId, ParachainHost}; pub use sp_runtime::traits::{Block as BlockT, self as runtime_traits, BlakeTwo256}; pub use chain_spec::{PolkadotChainSpec, KusamaChainSpec, WestendChainSpec}; #[cfg(feature = "full-node")] @@ -646,7 +645,7 @@ macro_rules! new_light { /// Builds a new object suitable for chain operations. pub fn new_chain_ops(mut config: Configuration) -> Result< ( - Arc>, + Arc>, Arc>, consensus_common::import_queue::BasicQueue>, TaskManager, diff --git a/statement-table/src/lib.rs b/statement-table/src/lib.rs index 97d0cda76344..1d2854faffde 100644 --- a/statement-table/src/lib.rs +++ b/statement-table/src/lib.rs @@ -18,10 +18,10 @@ pub mod generic; pub use generic::Table; -use primitives::parachain::{ +use primitives::v0::{ + Hash, Id, AbridgedCandidateReceipt, CompactStatement as PrimitiveStatement, ValidatorSignature, ValidatorIndex, }; -use primitives::Hash; /// Statements about candidates on the network. pub type Statement = generic::Statement; diff --git a/validation/src/block_production.rs b/validation/src/block_production.rs index 30b7ac3ccd46..4804ba230c96 100644 --- a/validation/src/block_production.rs +++ b/validation/src/block_production.rs @@ -28,8 +28,8 @@ use std::{ use sp_blockchain::HeaderBackend; use block_builder::{BlockBuilderApi, BlockBuilderProvider}; use consensus::{Proposal, RecordProof}; -use polkadot_primitives::{Block, Header}; -use polkadot_primitives::parachain::{ +use polkadot_primitives::v0::{Block, Header}; +use polkadot_primitives::v0::{ ParachainHost, NEW_HEADS_IDENTIFIER, }; use runtime_primitives::traits::{DigestFor, HashFor}; diff --git a/validation/src/collation.rs b/validation/src/collation.rs index a2e682a066d6..b79b049b225f 100644 --- a/validation/src/collation.rs +++ b/validation/src/collation.rs @@ -21,11 +21,9 @@ use std::sync::Arc; -use polkadot_primitives::{ +use polkadot_primitives::v0::{ BlakeTwo256, Block, Hash, HashT, - parachain::{ - CollatorId, ParachainHost, Id as ParaId, Collation, ErasureChunk, CollationInfo, - }, + CollatorId, ParachainHost, Id as ParaId, Collation, ErasureChunk, CollationInfo, }; use polkadot_erasure_coding as erasure; use sp_api::ProvideRuntimeApi; diff --git a/validation/src/error.rs b/validation/src/error.rs index 83b51ed23670..5fd990a07133 100644 --- a/validation/src/error.rs +++ b/validation/src/error.rs @@ -16,7 +16,7 @@ //! Errors that can occur during the validation process. -use polkadot_primitives::{parachain::ValidatorId, Hash}; +use polkadot_primitives::v0::{ValidatorId, Hash}; /// Error type for validation #[derive(Debug, derive_more::Display, derive_more::From)] @@ -77,7 +77,7 @@ pub enum Error { CommitmentsMismatch, /// The parachain for which validation work is being done is not active. #[display(fmt = "Parachain {:?} is not active", _0)] - InactiveParachain(polkadot_primitives::parachain::Id), + InactiveParachain(polkadot_primitives::v0::Id), /// Block data is too big #[display(fmt = "Block data is too big (maximum allowed size: {}, actual size: {})", size, max_size)] BlockDataTooBig { size: u64, max_size: u64 }, diff --git a/validation/src/lib.rs b/validation/src/lib.rs index 667f66e275a9..a5b1c1d5c2df 100644 --- a/validation/src/lib.rs +++ b/validation/src/lib.rs @@ -34,7 +34,7 @@ use std::{ sync::Arc, }; use codec::Encode; -use polkadot_primitives::parachain::{ +use polkadot_primitives::v0::{ Id as ParaId, Chain, DutyRoster, AbridgedCandidateReceipt, CompactStatement as PrimitiveStatement, PoVBlock, ErasureChunk, ValidatorSignature, ValidatorIndex, diff --git a/validation/src/pipeline.rs b/validation/src/pipeline.rs index b29285716dd3..621939c79b92 100644 --- a/validation/src/pipeline.rs +++ b/validation/src/pipeline.rs @@ -19,12 +19,12 @@ use codec::Encode; use polkadot_erasure_coding as erasure; -use polkadot_primitives::parachain::{ +use polkadot_primitives::v0::{ CollationInfo, PoVBlock, LocalValidationData, GlobalValidationSchedule, OmittedValidationData, AvailableData, FeeSchedule, CandidateCommitments, ErasureChunk, ParachainHost, Id as ParaId, AbridgedCandidateReceipt, ValidationCode, }; -use polkadot_primitives::{Block, BlockId, Balance, Hash}; +use polkadot_primitives::v0::{Block, BlockId, Balance, Hash}; use parachain::{ wasm_executor::{self, ExecutionMode}, primitives::{UpwardMessage, ValidationParams}, diff --git a/validation/src/shared_table/includable.rs b/validation/src/shared_table/includable.rs index 1396f66c5967..317b9e0f7bfe 100644 --- a/validation/src/shared_table/includable.rs +++ b/validation/src/shared_table/includable.rs @@ -18,7 +18,7 @@ use std::collections::HashMap; use futures::channel::oneshot; -use polkadot_primitives::Hash; +use polkadot_primitives::v0::Hash; /// Track includability of a set of candidates, pub(super) fn track>(candidates: I) diff --git a/validation/src/shared_table/mod.rs b/validation/src/shared_table/mod.rs index fd6702a7e640..284f96a261d1 100644 --- a/validation/src/shared_table/mod.rs +++ b/validation/src/shared_table/mod.rs @@ -22,8 +22,8 @@ use std::sync::Arc; use availability_store::{Store as AvailabilityStore}; use table::{self, Table, Context as TableContextTrait}; -use polkadot_primitives::{Block, Hash}; -use polkadot_primitives::parachain::{ +use polkadot_primitives::v0::{ + Block, Hash, Id as ParaId, AbridgedCandidateReceipt, ValidatorPair, ValidatorId, AttestedCandidate, ParachainHost, PoVBlock, ValidatorIndex, SigningContext, }; @@ -539,7 +539,7 @@ impl SharedTable { /// Get a set of candidates that can be proposed. pub fn proposed_set(&self) -> Vec { use table::generic::{ValidityAttestation as GAttestation}; - use polkadot_primitives::parachain::ValidityAttestation; + use polkadot_primitives::v0::ValidityAttestation; // we transform the types of the attestations gathered from the table // into the type expected by the runtime. This may do signature @@ -615,7 +615,7 @@ impl SharedTable { mod tests { use super::*; use sp_keyring::Sr25519Keyring; - use polkadot_primitives::parachain::{ + use polkadot_primitives::v0::{ BlockData, ErasureChunk, AvailableData, }; use polkadot_erasure_coding::{self as erasure}; diff --git a/validation/src/validation_service/mod.rs b/validation/src/validation_service/mod.rs index d84b1be078ad..7f332f4c0d1a 100644 --- a/validation/src/validation_service/mod.rs +++ b/validation/src/validation_service/mod.rs @@ -32,8 +32,8 @@ use crate::pipeline::FullOutput; use sc_client_api::{BlockchainEvents, BlockBackend}; use consensus::SelectChain; use futures::prelude::*; -use polkadot_primitives::{Block, Hash, BlockId}; -use polkadot_primitives::parachain::{ +use polkadot_primitives::v0::{ + Block, Hash, BlockId, Chain, ParachainHost, Id as ParaId, ValidatorIndex, ValidatorId, ValidatorPair, CollationInfo, SigningContext, }; @@ -545,7 +545,7 @@ mod tests { use super::*; use futures::{executor, future::ready, channel::mpsc}; use availability_store::ErasureNetworking; - use polkadot_primitives::parachain::{ + use polkadot_primitives::v0::{ PoVBlock, AbridgedCandidateReceipt, ErasureChunk, ValidatorIndex, CollationInfo, DutyRoster, GlobalValidationSchedule, LocalValidationData, Retriable, CollatorId, BlockData, Chain, AvailableData, SigningContext, ValidationCode, @@ -706,7 +706,7 @@ mod tests { fn signing_context() -> SigningContext { Default::default() } - fn downward_messages(_: ParaId) -> Vec { + fn downward_messages(_: ParaId) -> Vec { Vec::new() } } From 25719ce7496adba7a73136c52b9ea57d456b7104 Mon Sep 17 00:00:00 2001 From: Robert Habermeier Date: Wed, 8 Jul 2020 23:04:16 -0400 Subject: [PATCH 22/46] squanch some warns up --- primitives/src/v0.rs | 4 +--- primitives/src/v1.rs | 5 ----- 2 files changed, 1 insertion(+), 8 deletions(-) diff --git a/primitives/src/v0.rs b/primitives/src/v0.rs index afcf4c414d40..468383e472d0 100644 --- a/primitives/src/v0.rs +++ b/primitives/src/v0.rs @@ -26,7 +26,7 @@ use bitvec::vec::BitVec; use serde::{Serialize, Deserialize}; #[cfg(feature = "std")] -use primitives::{bytes, crypto::Pair}; +use primitives::crypto::Pair; use primitives::RuntimeDebug; use runtime_primitives::traits::{AppVerify, Block as BlockT}; use inherents::InherentIdentifier; @@ -404,7 +404,6 @@ impl + Encode> AbridgedCandidateReceipt { /// the relay-chain block in which context it should be executed, which implies /// any blockchain state that must be referenced. pub fn hash(&self) -> Hash { - use runtime_primitives::traits::{BlakeTwo256, Hash}; BlakeTwo256::hash_of(self) } } @@ -587,7 +586,6 @@ impl PoVBlock { /// Compute hash of block data. #[cfg(feature = "std")] pub fn hash(&self) -> Hash { - use runtime_primitives::traits::{BlakeTwo256, Hash}; BlakeTwo256::hash_of(&self) } } diff --git a/primitives/src/v1.rs b/primitives/src/v1.rs index 26c402cdad21..40bbd3c970f7 100644 --- a/primitives/src/v1.rs +++ b/primitives/src/v1.rs @@ -17,15 +17,10 @@ //! V1 Primitives. use sp_std::prelude::*; -use sp_std::cmp::Ordering; use parity_scale_codec::{Encode, Decode}; use bitvec::vec::BitVec; #[cfg(feature = "std")] -use serde::{Serialize, Deserialize}; - -#[cfg(feature = "std")] -use primitives::{bytes}; use primitives::RuntimeDebug; use runtime_primitives::traits::AppVerify; use inherents::InherentIdentifier; From e5cf5000e7a182a44d94615aba4957c6bb9d6c21 Mon Sep 17 00:00:00 2001 From: Robert Habermeier Date: Wed, 8 Jul 2020 23:15:37 -0400 Subject: [PATCH 23/46] add RuntimeDebug import to no-std as well --- primitives/src/v1.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/primitives/src/v1.rs b/primitives/src/v1.rs index 40bbd3c970f7..491627bb74ef 100644 --- a/primitives/src/v1.rs +++ b/primitives/src/v1.rs @@ -20,7 +20,6 @@ use sp_std::prelude::*; use parity_scale_codec::{Encode, Decode}; use bitvec::vec::BitVec; -#[cfg(feature = "std")] use primitives::RuntimeDebug; use runtime_primitives::traits::AppVerify; use inherents::InherentIdentifier; From 0d3013f3bac44380f7a671c25020939048808764 Mon Sep 17 00:00:00 2001 From: Robert Habermeier Date: Thu, 9 Jul 2020 17:11:32 -0400 Subject: [PATCH 24/46] port over statement-table and validation --- node/primitives/src/lib.rs | 2 +- statement-table/src/generic.rs | 2 +- statement-table/src/lib.rs | 144 ++++++++++++++++------------- validation/src/shared_table/mod.rs | 41 +++++--- 4 files changed, 108 insertions(+), 81 deletions(-) diff --git a/node/primitives/src/lib.rs b/node/primitives/src/lib.rs index f3f3155b229c..a059d89860eb 100644 --- a/node/primitives/src/lib.rs +++ b/node/primitives/src/lib.rs @@ -30,7 +30,7 @@ use polkadot_statement_table::{ ValidityDoubleVote as TableValidityDoubleVote, MultipleCandidates as TableMultipleCandidates, }, - Misbehavior as TableMisbehavior, + v1::Misbehavior as TableMisbehavior, }; /// A statement, where the candidate receipt is included in the `Seconded` variant. diff --git a/statement-table/src/generic.rs b/statement-table/src/generic.rs index 11c6a3c02478..cb95d74d6223 100644 --- a/statement-table/src/generic.rs +++ b/statement-table/src/generic.rs @@ -28,7 +28,7 @@ use std::collections::hash_map::{HashMap, Entry}; use std::hash::Hash; use std::fmt::Debug; -use primitives::parachain::{ValidityAttestation as PrimitiveValidityAttestation, ValidatorSignature}; +use primitives::v1::{ValidityAttestation as PrimitiveValidityAttestation, ValidatorSignature}; use codec::{Encode, Decode}; diff --git a/statement-table/src/lib.rs b/statement-table/src/lib.rs index 1d2854faffde..fed60ded0da2 100644 --- a/statement-table/src/lib.rs +++ b/statement-table/src/lib.rs @@ -16,75 +16,87 @@ pub mod generic; -pub use generic::Table; - -use primitives::v0::{ - Hash, - Id, AbridgedCandidateReceipt, CompactStatement as PrimitiveStatement, ValidatorSignature, ValidatorIndex, -}; - -/// Statements about candidates on the network. -pub type Statement = generic::Statement; - -/// Signed statements about candidates. -pub type SignedStatement = generic::SignedStatement< - AbridgedCandidateReceipt, - Hash, - ValidatorIndex, - ValidatorSignature, ->; - -/// Kinds of misbehavior, along with proof. -pub type Misbehavior = generic::Misbehavior< - AbridgedCandidateReceipt, - Hash, - ValidatorIndex, - ValidatorSignature, ->; - -/// A summary of import of a statement. -pub type Summary = generic::Summary; - -/// Context necessary to construct a table. -pub trait Context { - /// Whether a authority is a member of a group. - /// Members are meant to submit candidates and vote on validity. - fn is_member_of(&self, authority: ValidatorIndex, group: &Id) -> bool; - - /// requisite number of votes for validity from a group. - fn requisite_votes(&self, group: &Id) -> usize; -} - -impl generic::Context for C { - type AuthorityId = ValidatorIndex; - type Digest = Hash; - type GroupId = Id; - type Signature = ValidatorSignature; - type Candidate = AbridgedCandidateReceipt; - - fn candidate_digest(candidate: &AbridgedCandidateReceipt) -> Hash { - candidate.hash() - } - - fn candidate_group(candidate: &AbridgedCandidateReceipt) -> Id { - candidate.parachain_index.clone() - } - - fn is_member_of(&self, authority: &Self::AuthorityId, group: &Id) -> bool { - Context::is_member_of(self, *authority, group) - } - - fn requisite_votes(&self, group: &Id) -> usize { - Context::requisite_votes(self, group) +pub use generic::{Table, Context}; + +/// Concrete instantiations suitable for v0 primitives. +pub mod v0 { + use crate::generic; + use primitives::v0::{ + Hash, + Id, AbridgedCandidateReceipt, CompactStatement as PrimitiveStatement, ValidatorSignature, ValidatorIndex, + }; + + /// Statements about candidates on the network. + pub type Statement = generic::Statement; + + /// Signed statements about candidates. + pub type SignedStatement = generic::SignedStatement< + AbridgedCandidateReceipt, + Hash, + ValidatorIndex, + ValidatorSignature, + >; + + /// Kinds of misbehavior, along with proof. + pub type Misbehavior = generic::Misbehavior< + AbridgedCandidateReceipt, + Hash, + ValidatorIndex, + ValidatorSignature, + >; + + /// A summary of import of a statement. + pub type Summary = generic::Summary; + + impl<'a> From<&'a Statement> for PrimitiveStatement { + fn from(s: &'a Statement) -> PrimitiveStatement { + match *s { + generic::Statement::Valid(s) => PrimitiveStatement::Valid(s), + generic::Statement::Invalid(s) => PrimitiveStatement::Invalid(s), + generic::Statement::Candidate(ref s) => PrimitiveStatement::Candidate(s.hash()), + } + } } } -impl<'a> From<&'a Statement> for PrimitiveStatement { - fn from(s: &'a Statement) -> PrimitiveStatement { - match *s { - generic::Statement::Valid(s) => PrimitiveStatement::Valid(s), - generic::Statement::Invalid(s) => PrimitiveStatement::Invalid(s), - generic::Statement::Candidate(ref s) => PrimitiveStatement::Candidate(s.hash()), +/// Concrete instantiations suitable for v1 primitives. +pub mod v1 { + use crate::generic; + use primitives::v1::{ + Hash, + Id, CommittedCandidateReceipt, CompactStatement as PrimitiveStatement, + ValidatorSignature, ValidatorIndex, + }; + + /// Statements about candidates on the network. + pub type Statement = generic::Statement; + + /// Signed statements about candidates. + pub type SignedStatement = generic::SignedStatement< + CommittedCandidateReceipt, + Hash, + ValidatorIndex, + ValidatorSignature, + >; + + /// Kinds of misbehavior, along with proof. + pub type Misbehavior = generic::Misbehavior< + CommittedCandidateReceipt, + Hash, + ValidatorIndex, + ValidatorSignature, + >; + + /// A summary of import of a statement. + pub type Summary = generic::Summary; + + impl<'a> From<&'a Statement> for PrimitiveStatement { + fn from(s: &'a Statement) -> PrimitiveStatement { + match *s { + generic::Statement::Valid(s) => PrimitiveStatement::Valid(s), + generic::Statement::Invalid(s) => PrimitiveStatement::Invalid(s), + generic::Statement::Candidate(ref s) => PrimitiveStatement::Candidate(s.hash()), + } } } } diff --git a/validation/src/shared_table/mod.rs b/validation/src/shared_table/mod.rs index 284f96a261d1..ffbfdcfe34eb 100644 --- a/validation/src/shared_table/mod.rs +++ b/validation/src/shared_table/mod.rs @@ -21,11 +21,12 @@ use std::collections::hash_map::{HashMap, Entry}; use std::sync::Arc; use availability_store::{Store as AvailabilityStore}; -use table::{self, Table, Context as TableContextTrait}; +use table::{v0 as table_v0, Table, Context as TableContextTrait}; use polkadot_primitives::v0::{ Block, Hash, Id as ParaId, AbridgedCandidateReceipt, ValidatorPair, ValidatorId, AttestedCandidate, ParachainHost, PoVBlock, ValidatorIndex, SigningContext, + ValidatorSignature, }; use parking_lot::Mutex; @@ -44,7 +45,7 @@ use crate::Error; mod includable; -pub use table::{SignedStatement, Statement}; +pub use table_v0::{SignedStatement, Statement}; pub use table::generic::Statement as GenericStatement; struct TableContext { @@ -54,7 +55,21 @@ struct TableContext { validators: Vec, } -impl table::Context for TableContext { +impl TableContextTrait for TableContext { + type AuthorityId = ValidatorIndex; + type Digest = Hash; + type GroupId = ParaId; + type Signature = ValidatorSignature; + type Candidate = AbridgedCandidateReceipt; + + fn candidate_digest(candidate: &AbridgedCandidateReceipt) -> Hash { + candidate.hash() + } + + fn candidate_group(candidate: &AbridgedCandidateReceipt) -> ParaId { + candidate.parachain_index + } + fn is_member_of(&self, authority: ValidatorIndex, group: &ParaId) -> bool { let key = match self.validators.get(authority as usize) { Some(val) => val, @@ -84,7 +99,7 @@ impl TableContext { ) } - fn sign_statement(&self, statement: table::Statement) -> Option { + fn sign_statement(&self, statement: table_v0::Statement) -> Option { self.local_index().and_then(move |sender| self.key.as_ref() .map(|key| crate::sign_table_statement( @@ -93,7 +108,7 @@ impl TableContext { &self.signing_context, ).into() ) - .map(move |signature| table::SignedStatement { statement, signature, sender }) + .map(move |signature| table_v0::SignedStatement { statement, signature, sender }) ) } } @@ -145,7 +160,7 @@ impl SharedTableInner { &mut self, context: &TableContext, fetch_pov_block: impl Fn(&AbridgedCandidateReceipt) -> Fetch, - statement: table::SignedStatement, + statement: table_v0::SignedStatement, max_block_data_size: Option, ) -> Option( &self, fetch_pov_block: impl Fn(&AbridgedCandidateReceipt) -> Fetch, - statement: table::SignedStatement, + statement: table_v0::SignedStatement, ) -> Option> { @@ -487,7 +502,7 @@ impl SharedTable { iterable: I, ) -> U where - I: IntoIterator, + I: IntoIterator, U: ::std::iter::FromIterator>>, @@ -583,7 +598,7 @@ impl SharedTable { } /// Get all witnessed misbehavior. - pub fn get_misbehavior(&self) -> HashMap { + pub fn get_misbehavior(&self) -> HashMap { self.inner.lock().table.get_misbehavior().clone() } @@ -706,7 +721,7 @@ mod tests { &validity_other_key.into(), &signing_context, ); - let signed_statement = ::table::generic::SignedStatement { + let signed_statement = table::generic::SignedStatement { statement: candidate_statement, signature: signature.into(), sender: validity_other_index, @@ -763,7 +778,7 @@ mod tests { &validity_other_key.into(), &signing_context, ); - let signed_statement = ::table::generic::SignedStatement { + let signed_statement = table::generic::SignedStatement { statement: candidate_statement, signature: signature.into(), sender: validity_other_index, @@ -947,7 +962,7 @@ mod tests { &validity_other_key.into(), &signing_context, ); - let signed_statement = ::table::generic::SignedStatement { + let signed_statement = table::generic::SignedStatement { statement: candidate_statement, signature: signature.into(), sender: validity_other_index, From 8c2403fdd5db9dc2b770408dbb0a9b98c4e70cd8 Mon Sep 17 00:00:00 2001 From: Robert Habermeier Date: Thu, 9 Jul 2020 17:14:01 -0400 Subject: [PATCH 25/46] fix final errors in validation and node-primitives --- node/primitives/src/lib.rs | 6 +++--- validation/src/shared_table/mod.rs | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/node/primitives/src/lib.rs b/node/primitives/src/lib.rs index a059d89860eb..9b7e53dede8c 100644 --- a/node/primitives/src/lib.rs +++ b/node/primitives/src/lib.rs @@ -141,7 +141,7 @@ impl std::convert::TryFrom for MisbehaviorReport { &f.key, ).ok_or(())?; - Ok(MisbehaviorReport::SelfContradiction(receipt, signed_1, signed_2)) + Ok(MisbehaviorReport::SelfContradiction(receipt.to_plain(), signed_1, signed_2)) } TableMisbehavior::ValidityDoubleVote( TableValidityDoubleVote::IssuedAndInvalidity((c, s1), (d, s2)) @@ -162,7 +162,7 @@ impl std::convert::TryFrom for MisbehaviorReport { &f.key, ).ok_or(())?; - Ok(MisbehaviorReport::SelfContradiction(receipt, signed_1, signed_2)) + Ok(MisbehaviorReport::SelfContradiction(receipt.to_plain(), signed_1, signed_2)) } TableMisbehavior::ValidityDoubleVote( TableValidityDoubleVote::ValidityAndInvalidity(c, s1, s2) @@ -182,7 +182,7 @@ impl std::convert::TryFrom for MisbehaviorReport { &f.key, ).ok_or(())?; - Ok(MisbehaviorReport::SelfContradiction(c, signed_1, signed_2)) + Ok(MisbehaviorReport::SelfContradiction(c.to_plain(), signed_1, signed_2)) } TableMisbehavior::MultipleCandidates( TableMultipleCandidates { diff --git a/validation/src/shared_table/mod.rs b/validation/src/shared_table/mod.rs index ffbfdcfe34eb..15d28e82b55c 100644 --- a/validation/src/shared_table/mod.rs +++ b/validation/src/shared_table/mod.rs @@ -70,7 +70,7 @@ impl TableContextTrait for TableContext { candidate.parachain_index } - fn is_member_of(&self, authority: ValidatorIndex, group: &ParaId) -> bool { + fn is_member_of(&self, authority: &ValidatorIndex, group: &ParaId) -> bool { let key = match self.validators.get(authority as usize) { Some(val) => val, None => return false, @@ -99,7 +99,7 @@ impl TableContext { ) } - fn sign_statement(&self, statement: table_v0::Statement) -> Option { + fn sign_statement(&self, statement: table_v0::Statement) -> Option { self.local_index().and_then(move |sender| self.key.as_ref() .map(|key| crate::sign_table_statement( @@ -169,7 +169,7 @@ impl SharedTableInner { self.update_trackers(&summary.candidate, context); let local_index = context.local_index()?; - let para_member = context.is_member_of(local_index, &summary.group_id); + let para_member = context.is_member_of(&local_index, &summary.group_id); let digest = &summary.candidate; // TODO: consider a strategy based on the number of candidate votes as well. From 3347e7ffec3e48aa8320f442478d766c88ea7113 Mon Sep 17 00:00:00 2001 From: Robert Habermeier Date: Thu, 9 Jul 2020 17:20:00 -0400 Subject: [PATCH 26/46] add dummy Ord impl to committed candidate receipt --- primitives/src/v1.rs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/primitives/src/v1.rs b/primitives/src/v1.rs index 73258f5fb482..738b8bcaba97 100644 --- a/primitives/src/v1.rs +++ b/primitives/src/v1.rs @@ -183,6 +183,21 @@ impl CommittedCandidateReceipt { } } +impl PartialOrd for CommittedCandidateReceipt { + fn partial_cmp(&self, other: &Self) -> Option { + Some(self.cmp(other)) + } +} + +impl Ord for CommittedCandidateReceipt { + fn cmp(&self, other: &Self) -> sp_std::cmp::Ordering { + // TODO: compare signatures or something more sane + // https://github.com/paritytech/polkadot/issues/222 + self.descriptor().para_id.cmp(&other.descriptor().para_id) + .then_with(|| self.commitments.head_data.cmp(&other.commitments.head_data)) + } +} + /// Extra data that is needed along with the other fields in a `CandidateReceipt` /// to fully validate the candidate. These fields are parachain-specific. #[derive(PartialEq, Eq, Clone, Encode, Decode)] From b241140ef646b900138f5ddd3a2700d975218c57 Mon Sep 17 00:00:00 2001 From: Robert Habermeier Date: Thu, 9 Jul 2020 18:07:54 -0400 Subject: [PATCH 27/46] guide: update CandidateValidationMessage --- .../implementers-guide/src/types/candidate.md | 21 +++++++++++++++++++ .../src/types/overseer-protocol.md | 19 ++++++++--------- 2 files changed, 30 insertions(+), 10 deletions(-) diff --git a/roadmap/implementers-guide/src/types/candidate.md b/roadmap/implementers-guide/src/types/candidate.md index 7c9b4dd921e5..0ed38590a733 100644 --- a/roadmap/implementers-guide/src/types/candidate.md +++ b/roadmap/implementers-guide/src/types/candidate.md @@ -180,3 +180,24 @@ struct SigningContext { session_index: SessionIndex, } ``` + +## Validation Outputs + +This struct encapsulates the outputs of candidate validation. + +```rust +struct ValidationOutputs { + /// The head-data produced by validation. + head_data: HeadData, + /// The global validation schedule. + global_validation_schedule: GlobalValidationSchedule, + /// The local validation data. + local_validation_data: LocalValidationData, + /// Upwards messages to the relay chain. + upwards_messages: Vec, + /// Fees paid to the validators of the relay-chain. + fees: Balance, + /// The new validation code submitted by the execution, if any. + new_validation_code: Option, +} +``` diff --git a/roadmap/implementers-guide/src/types/overseer-protocol.md b/roadmap/implementers-guide/src/types/overseer-protocol.md index 1e59eedff8db..64fd295f898c 100644 --- a/roadmap/implementers-guide/src/types/overseer-protocol.md +++ b/roadmap/implementers-guide/src/types/overseer-protocol.md @@ -282,29 +282,28 @@ enum StatementDistributionMessage { ## Validation Request Type -Various modules request that the [Candidate Validation subsystem](../node/utility/candidate-validation.md) validate a block with this message +Various modules request that the [Candidate Validation subsystem](../node/utility/candidate-validation.md) validate a block with this message. It returns [`ValidationOutputs`](candidate.md#validationoutputs) for successful validation. ```rust /// Result of the validation of the candidate. enum ValidationResult { - /// Candidate is valid. - Valid, + /// Candidate is valid, and here are the outputs. In practice, this should be a shared type + /// so that validation caching can be done. + Valid(ValidationOutputs), /// Candidate is invalid. Invalid, } enum CandidateValidationMessage { /// Validate a candidate with provided parameters. Returns `Err` if an only if an internal - /// error is encountered. + /// error is encountered. The first hash is the relay-parent whose + /// /// In case no internal error was encontered it returns a tuple containing the result of /// validation and `GlobalValidationSchedule` and `LocalValidationData` structures that /// may be used by the caller to make the candidate available. - /// A bad candidate will return `Ok((ValidationResult::Invalid, _, _)`, while a good one will - /// return `Ok((ValidationResult::Valid, _, _))`. - Validate( - Hash, CandidateReceipt, HeadData, PoV, ResponseChannel< - Result<(ValidationResult, GlobalValidationSchedule, LocalValidationData)> - >), + /// A bad candidate will return `Ok((ValidationResult::Invalid)`, while a good one will + /// return `Ok((ValidationResult::Valid(_)))`. + Validate(Hash, CandidateDescriptor, PoV, ResponseChannel>), } ``` From c70badd8db29e531ea169a35fd93144a01084c3e Mon Sep 17 00:00:00 2001 From: Robert Habermeier Date: Thu, 9 Jul 2020 18:13:20 -0400 Subject: [PATCH 28/46] add primitive for validationoutputs --- node/primitives/src/lib.rs | 23 +++++++++++++++++++++-- primitives/src/v1.rs | 17 +++++++++++++++++ 2 files changed, 38 insertions(+), 2 deletions(-) diff --git a/node/primitives/src/lib.rs b/node/primitives/src/lib.rs index 9b7e53dede8c..f29be5737450 100644 --- a/node/primitives/src/lib.rs +++ b/node/primitives/src/lib.rs @@ -24,6 +24,8 @@ use parity_scale_codec::{Decode, Encode}; use polkadot_primitives::v1::{ Hash, CommittedCandidateReceipt, CandidateReceipt, CompactStatement, EncodeAs, Signed, SigningContext, ValidatorIndex, ValidatorId, + UpwardMessage, Balance, ValidationCode, GlobalValidationSchedule, LocalValidationData, + HeadData, }; use polkadot_statement_table::{ generic::{ @@ -108,11 +110,28 @@ pub struct FromTableMisbehavior { pub key: ValidatorId, } +/// Outputs of validating a candidate. +#[derive(Debug)] +pub struct ValidationOutputs { + /// The head-data produced by validation. + pub head_data: HeadData, + /// The global validation schedule. + pub global_validation_schedule: GlobalValidationSchedule, + /// The local validation data. + pub local_validation_data: LocalValidationData, + /// Upward messages to the relay chain. + pub upward_messages: Vec, + /// Fees paid to the validators of the relay-chain. + pub fees: Balance, + /// The new validation code submitted by the execution, if any. + pub new_validation_code: Option, +} + /// Result of the validation of the candidate. #[derive(Debug)] pub enum ValidationResult { - /// Candidate is valid. - Valid, + /// Candidate is valid. The validation process yields these outputs. + Valid(ValidationOutputs), /// Candidate is invalid. Invalid, } diff --git a/primitives/src/v1.rs b/primitives/src/v1.rs index 738b8bcaba97..5658822124ea 100644 --- a/primitives/src/v1.rs +++ b/primitives/src/v1.rs @@ -448,3 +448,20 @@ impl CoreAssignment { } } } + +/// Validation data omitted from most candidate descriptor structs, as it can be derived from the +/// relay-parent. +pub struct OmittedValidationData { + /// The global validation schedule. + pub global_validation: GlobalValidationSchedule, + /// The local validation data. + pub local_validation: LocalValidationData, +} + +/// This is the data we keep available for each candidate included in the relay chain. +pub struct AvailableData { + /// The Proof-of-Validation of the candidate. + pub pov: PoV, + /// The omitted validation data. + pub omitted_validation: OmittedValidationData, +} From 43e8e30d2ce5e95cd43f39b154f51a6a5552680d Mon Sep 17 00:00:00 2001 From: Robert Habermeier Date: Thu, 9 Jul 2020 18:21:45 -0400 Subject: [PATCH 29/46] expand CandidateValidationMessage further --- .../src/types/overseer-protocol.md | 31 +++++++++++++------ 1 file changed, 22 insertions(+), 9 deletions(-) diff --git a/roadmap/implementers-guide/src/types/overseer-protocol.md b/roadmap/implementers-guide/src/types/overseer-protocol.md index 64fd295f898c..1198bb198136 100644 --- a/roadmap/implementers-guide/src/types/overseer-protocol.md +++ b/roadmap/implementers-guide/src/types/overseer-protocol.md @@ -295,15 +295,28 @@ enum ValidationResult { Invalid, } +/// Messages issued to the candidate validation subsystem. +/// +/// ## Validation Requests +/// +/// Validation requests made to the subsystem should return an error only on internal error. +/// Otherwise, they should return either `Ok(ValidationResult::Valid(_))` or `Ok(ValidationResult::Invalid)`. enum CandidateValidationMessage { - /// Validate a candidate with provided parameters. Returns `Err` if an only if an internal - /// error is encountered. The first hash is the relay-parent whose - /// - /// In case no internal error was encontered it returns a tuple containing the result of - /// validation and `GlobalValidationSchedule` and `LocalValidationData` structures that - /// may be used by the caller to make the candidate available. - /// A bad candidate will return `Ok((ValidationResult::Invalid)`, while a good one will - /// return `Ok((ValidationResult::Valid(_)))`. - Validate(Hash, CandidateDescriptor, PoV, ResponseChannel>), + /// Validate a candidate with provided parameters. This will implicitly attempt to gather the + /// `OmittedValidationData` and `ValidationCode` from the runtime API of the chain, + /// based on the `relay_parent` of the `CandidateDescriptor`. + /// If there is no state available which can provide this data, an error is returned. + ValidateFromChainState(CandidateDescriptor, PoV, ResponseChannel>), + + /// Validate a candidate with provided parameters. Explicitly provide the `OmittedValidationData` + /// and `ValidationCode` so this can do full validation without needing to access the state of + /// the relay-chain. + ValidateFromFull( + OmittedValidationData, + ValidationCode, + CandidateDescriptor, + PoV, + ResponseChannel>, + ), } ``` From 935d5366a4e7d50707f5475ab2bf4bbfff14b988 Mon Sep 17 00:00:00 2001 From: Robert Habermeier Date: Thu, 9 Jul 2020 18:24:02 -0400 Subject: [PATCH 30/46] bikeshed --- roadmap/implementers-guide/src/types/overseer-protocol.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/roadmap/implementers-guide/src/types/overseer-protocol.md b/roadmap/implementers-guide/src/types/overseer-protocol.md index 1198bb198136..90b9cd43eee2 100644 --- a/roadmap/implementers-guide/src/types/overseer-protocol.md +++ b/roadmap/implementers-guide/src/types/overseer-protocol.md @@ -311,7 +311,7 @@ enum CandidateValidationMessage { /// Validate a candidate with provided parameters. Explicitly provide the `OmittedValidationData` /// and `ValidationCode` so this can do full validation without needing to access the state of /// the relay-chain. - ValidateFromFull( + ValidateFromExhaustive( OmittedValidationData, ValidationCode, CandidateDescriptor, From 3ec9437c987bebb006bf115cd6647ff4cb17708c Mon Sep 17 00:00:00 2001 From: Robert Habermeier Date: Thu, 9 Jul 2020 18:25:54 -0400 Subject: [PATCH 31/46] add some impls to omitted-validation-data and available-data --- primitives/src/v1.rs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/primitives/src/v1.rs b/primitives/src/v1.rs index 5658822124ea..7d02f00b9fbe 100644 --- a/primitives/src/v1.rs +++ b/primitives/src/v1.rs @@ -451,6 +451,8 @@ impl CoreAssignment { /// Validation data omitted from most candidate descriptor structs, as it can be derived from the /// relay-parent. +#[derive(Clone, Encode, Decode)] +#[cfg_attr(feature = "std", derive(PartialEq, Debug))] pub struct OmittedValidationData { /// The global validation schedule. pub global_validation: GlobalValidationSchedule, @@ -459,6 +461,8 @@ pub struct OmittedValidationData { } /// This is the data we keep available for each candidate included in the relay chain. +#[derive(Clone, Encode, Decode)] +#[cfg_attr(feature = "std", derive(PartialEq, Debug))] pub struct AvailableData { /// The Proof-of-Validation of the candidate. pub pov: PoV, From 821c556e80bd3448ed1af2dd3ee44d676c501751 Mon Sep 17 00:00:00 2001 From: Robert Habermeier Date: Thu, 9 Jul 2020 18:26:04 -0400 Subject: [PATCH 32/46] expand CandidateValidationMessage --- node/subsystem/src/messages.rs | 42 ++++++++++++++++++++++------------ 1 file changed, 28 insertions(+), 14 deletions(-) diff --git a/node/subsystem/src/messages.rs b/node/subsystem/src/messages.rs index 2ae12fb0dab4..7cee5d31ab64 100644 --- a/node/subsystem/src/messages.rs +++ b/node/subsystem/src/messages.rs @@ -28,8 +28,8 @@ use polkadot_primitives::v1::{ BlockNumber, Hash, CandidateReceipt, PoV, ErasureChunk, BackedCandidate, Id as ParaId, SignedAvailabilityBitfield, SigningContext, ValidatorId, ValidationCode, ValidatorIndex, - CoreAssignment, CoreOccupied, HeadData, CandidateDescriptor, GlobalValidationSchedule, - LocalValidationData, ValidatorSignature, + CoreAssignment, CoreOccupied, HeadData, CandidateDescriptor, + ValidatorSignature, OmittedValidationData, }; use polkadot_node_primitives::{ MisbehaviorReport, SignedFullStatement, View, ProtocolId, ValidationResult, @@ -69,22 +69,36 @@ pub enum CandidateBackingMessage { #[derive(Debug)] pub struct ValidationFailed; -/// Messages received by the Validation subsystem +/// Messages received by the Validation subsystem. +/// +/// ## Validation Requests +/// +/// Validation requests made to the subsystem should return an error only on internal error. +/// Otherwise, they should return either `Ok(ValidationResult::Valid(_))` +/// or `Ok(ValidationResult::Invalid)`. #[derive(Debug)] pub enum CandidateValidationMessage { - /// Validate a candidate, sending a side-channel response of valid or invalid. + /// Validate a candidate with provided parameters using relay-chain state. + /// + /// This will implicitly attempt to gather the `OmittedValidationData` and `ValidationCode` + /// from the runtime API of the chain, based on the `relay_parent` + /// of the `CandidateDescriptor`. + /// If there is no state available which can provide this data, an error is returned. + ValidateFromChainState( + CandidateDescriptor, + PoV, + oneshot::Sender>, + ), + /// Validate a candidate with provided, exhaustive parameters for validation. /// - /// Provide the relay-parent in whose context this should be validated, the full candidate receipt, - /// and the PoV. - Validate( - Hash, - CandidateReceipt, - HeadData, + /// Explicitly provide the `OmittedValidationData` and `ValidationCode` so this can do full + /// validation without needing to access the state of the relay-chain. + ValidateFromExhaustive( + OmittedValidationData, + ValidationCode, + CandidateDescriptor, PoV, - oneshot::Sender>, + oneshot::Sender>, ), } From dc7cd081efc4ecd73134f3e19587705dc9254db9 Mon Sep 17 00:00:00 2001 From: Robert Habermeier Date: Thu, 9 Jul 2020 18:35:11 -0400 Subject: [PATCH 33/46] make erasure-coding generic over v1/v0 --- erasure-coding/src/lib.rs | 62 ++++++++++++++++++++++++++++++++++----- 1 file changed, 54 insertions(+), 8 deletions(-) diff --git a/erasure-coding/src/lib.rs b/erasure-coding/src/lib.rs index c5f18bfe276c..c4e7ba18d2ff 100644 --- a/erasure-coding/src/lib.rs +++ b/erasure-coding/src/lib.rs @@ -26,7 +26,8 @@ use codec::{Encode, Decode}; use reed_solomon::galois_16::{self, ReedSolomon}; -use primitives::v0::{Hash as H256, BlakeTwo256, HashT, AvailableData}; +use primitives::v0::{self, Hash as H256, BlakeTwo256, HashT}; +use primitives::v1; use sp_core::Blake2Hasher; use trie::{EMPTY_PREFIX, MemoryDB, Trie, TrieMut, trie_types::{TrieDBMut, TrieDB}}; @@ -123,14 +124,32 @@ fn code_params(n_validators: usize) -> Result { }) } +/// Obtain erasure-coded chunks for v0 `AvailableData`, one for each validator. +/// +/// Works only up to 65536 validators, and `n_validators` must be non-zero. +pub fn obtain_availability_chunks_v0(n_validators: usize, data: &v0::AvailableData) + -> Result>, Error> +{ + obtain_chunks(n_validators, data) +} + +/// Obtain erasure-coded chunks for v1 `AvailableData`, one for each validator. +/// +/// Works only up to 65536 validators, and `n_validators` must be non-zero. +pub fn obtain_availability_chunks_v1(n_validators: usize, data: &v1::AvailableData) + -> Result>, Error> +{ + obtain_chunks(n_validators, data) +} + /// Obtain erasure-coded chunks, one for each validator. /// /// Works only up to 65536 validators, and `n_validators` must be non-zero. -pub fn obtain_chunks(n_validators: usize, available_data: &AvailableData) +fn obtain_chunks(n_validators: usize, data: &T) -> Result>, Error> { let params = code_params(n_validators)?; - let encoded = available_data.encode(); + let encoded = data.encode(); if encoded.is_empty() { return Err(Error::BadPayload); @@ -144,15 +163,42 @@ pub fn obtain_chunks(n_validators: usize, available_data: &AvailableData) Ok(shards.into_iter().map(|w| w.into_inner()).collect()) } -/// Reconstruct the block data from a set of chunks. +/// Reconstruct the v0 available data from a set of chunks. +/// +/// Provide an iterator containing chunk data and the corresponding index. +/// The indices of the present chunks must be indicated. If too few chunks +/// are provided, recovery is not possible. +/// +/// Works only up to 65536 validators, and `n_validators` must be non-zero. +pub fn reconstruct_v0<'a, I: 'a>(n_validators: usize, chunks: I) + -> Result + where I: IntoIterator +{ + reconstruct(n_validators, chunks) +} + +/// Reconstruct the v1 available data from a set of chunks. +/// +/// Provide an iterator containing chunk data and the corresponding index. +/// The indices of the present chunks must be indicated. If too few chunks +/// are provided, recovery is not possible. +/// +/// Works only up to 65536 validators, and `n_validators` must be non-zero. +pub fn reconstruct_v1<'a, I: 'a>(n_validators: usize, chunks: I) + -> Result + where I: IntoIterator +{ + reconstruct(n_validators, chunks) +} + +/// Reconstruct decodable data from a set of chunks. /// /// Provide an iterator containing chunk data and the corresponding index. /// The indices of the present chunks must be indicated. If too few chunks /// are provided, recovery is not possible. /// /// Works only up to 65536 validators, and `n_validators` must be non-zero. -pub fn reconstruct<'a, I: 'a>(n_validators: usize, chunks: I) - -> Result +fn reconstruct<'a, I: 'a, T: Decode>(n_validators: usize, chunks: I) -> Result where I: IntoIterator { let params = code_params(n_validators)?; @@ -342,7 +388,7 @@ impl<'a, I: Iterator> codec::Input for ShardInput<'a, I> { #[cfg(test)] mod tests { use super::*; - use primitives::v0::{BlockData, PoVBlock}; + use primitives::v0::{AvailableData, BlockData, PoVBlock}; #[test] fn field_order_is_right_size() { @@ -419,7 +465,7 @@ mod tests { assert_eq!(chunks.len(), 10); // any 4 chunks should work. - let reconstructed = reconstruct( + let reconstructed: AvailableData = reconstruct( 10, [ (&*chunks[1], 1), From 6306116e2ff817cf68d2fa8e8f3bb565ac1f070a Mon Sep 17 00:00:00 2001 From: Robert Habermeier Date: Thu, 9 Jul 2020 18:36:13 -0400 Subject: [PATCH 34/46] update usages of erasure-coding --- availability-store/src/store.rs | 4 +- node/core/backing/src/lib.rs | 90 ++++++++++++++++++------------ validation/src/pipeline.rs | 2 +- validation/src/shared_table/mod.rs | 2 +- 4 files changed, 58 insertions(+), 40 deletions(-) diff --git a/availability-store/src/store.rs b/availability-store/src/store.rs index ddba02d2bd9c..cd76de5d44ad 100644 --- a/availability-store/src/store.rs +++ b/availability-store/src/store.rs @@ -270,7 +270,7 @@ impl Store { // If there are no block data in the store at this point, // check that they can be reconstructed now and add them to store if they can. if self.execution_data(&candidate_hash).is_none() { - if let Ok(available_data) = erasure::reconstruct( + if let Ok(available_data) = erasure::reconstruct_v0( n_validators as usize, v.iter().map(|chunk| (chunk.chunk.as_ref(), chunk.index as usize)), ) @@ -486,7 +486,7 @@ mod tests { let available_data = available_data(&[42; 8]); let n_validators = 5; - let erasure_chunks = erasure::obtain_chunks( + let erasure_chunks = erasure::obtain_chunks_v0( n_validators, &available_data, ).unwrap(); diff --git a/node/core/backing/src/lib.rs b/node/core/backing/src/lib.rs index db04ad991b70..3a36e9223edf 100644 --- a/node/core/backing/src/lib.rs +++ b/node/core/backing/src/lib.rs @@ -38,9 +38,9 @@ use primitives::Pair; use keystore::KeyStorePtr; use polkadot_primitives::v1::{ CommittedCandidateReceipt, BackedCandidate, Id as ParaId, ValidatorPair, ValidatorId, - ValidatorIndex, HeadData, SigningContext, PoVBlock, OmittedValidationData, + ValidatorIndex, HeadData, SigningContext, PoV, OmittedValidationData, CandidateDescriptor, LocalValidationData, GlobalValidationSchedule, AvailableData, - ErasureChunk, + ErasureChunk, ValidatorSignature, Hash, CandidateReceipt, }; use polkadot_node_primitives::{ FromTableMisbehavior, Statement, SignedFullStatement, MisbehaviorReport, ValidationResult, @@ -56,8 +56,12 @@ use polkadot_subsystem::messages::{ }; use statement_table::{ generic::AttestedCandidate as TableAttestedCandidate, - Table, Context as TableContextTrait, Statement as TableStatement, - SignedStatement as TableSignedStatement, Summary as TableSummary, + Context as TableContextTrait, + Table, + v1::{ + Statement as TableStatement, + SignedStatement as TableSignedStatement, Summary as TableSummary, + }, }; #[derive(Debug, derive_more::From)] @@ -115,7 +119,21 @@ struct TableContext { } impl TableContextTrait for TableContext { - fn is_member_of(&self, authority: ValidatorIndex, group: &ParaId) -> bool { + type AuthorityId = ValidatorIndex; + type Digest = Hash; + type GroupId = ParaId; + type Signature = ValidatorSignature; + type Candidate = CommittedCandidateReceipt; + + fn candidate_digest(candidate: &CommittedCandidateReceipt) -> Hash { + candidate.hash() + } + + fn candidate_group(candidate: &CommittedCandidateReceipt) -> ParaId { + candidate.descriptor().para_id + } + + fn is_member_of(&self, authority: &ValidatorIndex, group: &ParaId) -> bool { self.groups.get(group).map_or(false, |g| g.iter().position(|&a| a == authority).is_some()) } @@ -221,7 +239,7 @@ impl CandidateBackingJob { candidate: CommittedCandidateReceipt, ) -> Result<(), Error> { self.tx_from.send(FromJob::CandidateSelection( - CandidateSelectionMessage::Invalid(self.parent, candidate) + CandidateSelectionMessage::Invalid(self.parent, candidate.to_plain()) )).await?; Ok(()) @@ -230,8 +248,8 @@ impl CandidateBackingJob { /// Validate the candidate that is requested to be `Second`ed and distribute validation result. async fn validate_and_second( &mut self, - candidate: CommittedCandidateReceipt, - pov: PoVBlock, + candidate: CandidateReceipt, + pov: PoV, ) -> Result { let valid = self.request_candidate_validation(candidate.clone(), pov.clone()).await?; let statement = match valid.0 { @@ -475,7 +493,7 @@ impl CandidateBackingJob { async fn request_pov_from_distribution( &mut self, descriptor: CandidateDescriptor, - ) -> Result { + ) -> Result { let (tx, rx) = oneshot::channel(); self.tx_from.send(FromJob::PoVDistribution( @@ -489,7 +507,7 @@ impl CandidateBackingJob { async fn request_candidate_validation( &mut self, candidate: CommittedCandidateReceipt, - pov: PoVBlock, + pov: PoV, ) -> Result<(ValidationResult, GlobalValidationSchedule, LocalValidationData), Error> { let (tx, rx) = oneshot::channel(); @@ -522,7 +540,7 @@ impl CandidateBackingJob { async fn make_pov_available( &mut self, - pov_block: PoVBlock, + pov: PoV, global_validation: GlobalValidationSchedule, local_validation: LocalValidationData, ) -> Result<(), Error> { @@ -532,11 +550,11 @@ impl CandidateBackingJob { }; let available_data = AvailableData { - pov_block, + pov, omitted_validation, }; - let chunks = erasure_coding::obtain_chunks( + let chunks = erasure_coding::obtain_chunks_v1( self.table_context.validators.len(), &available_data, )?; @@ -907,8 +925,9 @@ mod tests { use std::collections::HashMap; use std::sync::Arc; use sp_keyring::Sr25519Keyring; - use polkadot_primitives::parachain::{ + use polkadot_primitives::v1::{ AssignmentKind, CollatorId, CoreAssignment, BlockData, CoreIndex, GroupIndex, ValidityAttestation, + CandidateCommitments, }; use assert_matches::assert_matches; @@ -1053,7 +1072,6 @@ mod tests { head_data: HeadData, pov_hash: Hash, relay_parent: Hash, - new_validation_code: Option, } impl TestCandidateBuilder { @@ -1135,11 +1153,11 @@ mod tests { test_startup(&mut virtual_overseer, &test_state).await; - let pov_block = PoVBlock { + let pov = PoV { block_data: BlockData(vec![42, 43, 44]), }; - let pov_hash = pov_block.hash(); + let pov_hash = pov.hash(); let candidate = TestCandidateBuilder { para_id: test_state.chain_ids[0], relay_parent: test_state.relay_parent, @@ -1150,7 +1168,7 @@ mod tests { let second = CandidateBackingMessage::Second( test_state.relay_parent, candidate.clone(), - pov_block.clone(), + pov.clone(), ); virtual_overseer.send(FromOverseer::Communication{ msg: second }).await; @@ -1168,7 +1186,7 @@ mod tests { tx, ) ) if parent_hash == test_state.relay_parent && - pov == pov_block && c == candidate => { + pov == pov && c == candidate => { assert_eq!(head_data, *expected_head_data); tx.send(Ok(( ValidationResult::Valid, @@ -1217,11 +1235,11 @@ mod tests { test_startup(&mut virtual_overseer, &test_state).await; - let pov_block = PoVBlock { + let pov = PoV { block_data: BlockData(vec![1, 2, 3]), }; - let pov_hash = pov_block.hash(); + let pov_hash = pov.hash(); let candidate_a = TestCandidateBuilder { para_id: test_state.chain_ids[0], @@ -1251,14 +1269,14 @@ mod tests { virtual_overseer.send(FromOverseer::Communication{ msg: statement }).await; // Sending a `Statement::Seconded` for our assignment will start - // validation process. The first thing requested is PoVBlock from the + // validation process. The first thing requested is PoV from the // `PoVDistribution`. assert_matches!( virtual_overseer.recv().await, AllMessages::PoVDistribution( PoVDistributionMessage::FetchPoV(relay_parent, _, tx) ) if relay_parent == test_state.relay_parent => { - tx.send(Arc::new(pov_block.clone())).unwrap(); + tx.send(Arc::new(pov.clone())).unwrap(); } ); @@ -1278,7 +1296,7 @@ mod tests { ) ) if relay_parent == test_state.relay_parent && candidate == candidate_a => { assert_eq!(head_data, *expected_head_data); - assert_eq!(pov, pov_block); + assert_eq!(pov, pov); tx.send(Ok(( ValidationResult::Valid, test_state.global_validation_schedule, @@ -1333,11 +1351,11 @@ mod tests { test_startup(&mut virtual_overseer, &test_state).await; - let pov_block = PoVBlock { + let pov = PoV { block_data: BlockData(vec![1, 2, 3]), }; - let pov_hash = pov_block.hash(); + let pov_hash = pov.hash(); let candidate_a = TestCandidateBuilder { para_id: test_state.chain_ids[0], relay_parent: test_state.relay_parent, @@ -1377,7 +1395,7 @@ mod tests { AllMessages::PoVDistribution( PoVDistributionMessage::FetchPoV(relay_parent, _, tx) ) if relay_parent == test_state.relay_parent => { - tx.send(Arc::new(pov_block.clone())).unwrap(); + tx.send(Arc::new(pov.clone())).unwrap(); } ); @@ -1394,7 +1412,7 @@ mod tests { tx, ) ) if relay_parent == test_state.relay_parent && candidate == candidate_a => { - assert_eq!(pov, pov_block); + assert_eq!(pov, pov); assert_eq!(head_data, *expected_head_data); tx.send(Ok(( ValidationResult::Valid, @@ -1464,11 +1482,11 @@ mod tests { test_startup(&mut virtual_overseer, &test_state).await; - let pov_block_a = PoVBlock { + let pov_block_a = PoV { block_data: BlockData(vec![42, 43, 44]), }; - let pov_block_b = PoVBlock { + let pov_block_b = PoV { block_data: BlockData(vec![45, 46, 47]), }; @@ -1614,11 +1632,11 @@ mod tests { test_startup(&mut virtual_overseer, &test_state).await; - let pov_block = PoVBlock { + let pov = PoV { block_data: BlockData(vec![42, 43, 44]), }; - let pov_hash = pov_block.hash(); + let pov_hash = pov.hash(); let candidate = TestCandidateBuilder { para_id: test_state.chain_ids[0], @@ -1651,7 +1669,7 @@ mod tests { PoVDistributionMessage::FetchPoV(relay_parent, _, tx) ) => { assert_eq!(relay_parent, test_state.relay_parent); - tx.send(Arc::new(pov_block.clone())).unwrap(); + tx.send(Arc::new(pov.clone())).unwrap(); } ); @@ -1672,7 +1690,7 @@ mod tests { assert_eq!(relay_parent, test_state.relay_parent); assert_eq!(candidate_recvd, candidate); assert_eq!(head_data, *expected_head_data); - assert_eq!(pov, pov_block); + assert_eq!(pov, pov); tx.send(Ok(( ValidationResult::Invalid, test_state.global_validation_schedule, @@ -1704,12 +1722,12 @@ mod tests { let second = CandidateBackingMessage::Second( test_state.relay_parent, candidate.clone(), - pov_block.clone(), + pov.clone(), ); virtual_overseer.send(FromOverseer::Communication{ msg: second }).await; - let pov_to_second = PoVBlock { + let pov_to_second = PoV { block_data: BlockData(vec![3, 2, 1]), }; diff --git a/validation/src/pipeline.rs b/validation/src/pipeline.rs index 621939c79b92..f2a705ba101d 100644 --- a/validation/src/pipeline.rs +++ b/validation/src/pipeline.rs @@ -125,7 +125,7 @@ impl<'a> ValidatedCandidate<'a> { omitted_validation, }; - let erasure_chunks = erasure::obtain_chunks( + let erasure_chunks = erasure::obtain_chunks_v0( n_validators, &available_data, )?; diff --git a/validation/src/shared_table/mod.rs b/validation/src/shared_table/mod.rs index 15d28e82b55c..21046cdd5592 100644 --- a/validation/src/shared_table/mod.rs +++ b/validation/src/shared_table/mod.rs @@ -875,7 +875,7 @@ mod tests { omitted_validation: Default::default(), }; - let chunks = erasure::obtain_chunks(n_validators, &available_data).unwrap(); + let chunks = erasure::obtain_chunks_v0(n_validators, &available_data).unwrap(); store.note_validator_index_and_n_validators( &relay_parent, From 1bd4809cc2ec226a8cb74c3ea0dbc490e0c2b16d Mon Sep 17 00:00:00 2001 From: Robert Habermeier Date: Thu, 9 Jul 2020 18:37:39 -0400 Subject: [PATCH 35/46] implement commitments.hash() --- primitives/src/v1.rs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/primitives/src/v1.rs b/primitives/src/v1.rs index 7d02f00b9fbe..9fb3d1662ec7 100644 --- a/primitives/src/v1.rs +++ b/primitives/src/v1.rs @@ -170,7 +170,7 @@ impl CommittedCandidateReceipt { pub fn to_plain(&self) -> CandidateReceipt { CandidateReceipt { descriptor: self.descriptor.clone(), - commitments_hash: BlakeTwo256::hash_of(&self.commitments), + commitments_hash: self.commitments.hash(), } } @@ -254,6 +254,13 @@ pub struct CandidateCommitments { pub head_data: HeadData, } +impl CandidateCommitments { + /// Compute the blake2-256 hash of the commitments. + pub fn hash(&self) -> Hash { + BlakeTwo256::hash_of(self) + } +} + /// A Proof-of-Validity #[derive(PartialEq, Eq, Clone, Encode, Decode)] #[cfg_attr(feature = "std", derive(Debug))] From afd20ddd33b13144a18033efd2643db753fe66a6 Mon Sep 17 00:00:00 2001 From: Robert Habermeier Date: Thu, 9 Jul 2020 18:39:25 -0400 Subject: [PATCH 36/46] use Arc for CandidateValidation --- node/subsystem/src/messages.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/node/subsystem/src/messages.rs b/node/subsystem/src/messages.rs index 7cee5d31ab64..10c861f1410c 100644 --- a/node/subsystem/src/messages.rs +++ b/node/subsystem/src/messages.rs @@ -86,7 +86,7 @@ pub enum CandidateValidationMessage { /// If there is no state available which can provide this data, an error is returned. ValidateFromChainState( CandidateDescriptor, - PoV, + Arc, oneshot::Sender>, ), /// Validate a candidate with provided, exhaustive parameters for validation. @@ -97,7 +97,7 @@ pub enum CandidateValidationMessage { OmittedValidationData, ValidationCode, CandidateDescriptor, - PoV, + Arc, oneshot::Sender>, ), } From 0fbbc42bfc6a24e670db20f809c1aabe9c1ed499 Mon Sep 17 00:00:00 2001 From: Robert Habermeier Date: Thu, 9 Jul 2020 19:24:48 -0400 Subject: [PATCH 37/46] improve new erasure-coding method names --- erasure-coding/src/lib.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/erasure-coding/src/lib.rs b/erasure-coding/src/lib.rs index c4e7ba18d2ff..708a167d6276 100644 --- a/erasure-coding/src/lib.rs +++ b/erasure-coding/src/lib.rs @@ -127,7 +127,7 @@ fn code_params(n_validators: usize) -> Result { /// Obtain erasure-coded chunks for v0 `AvailableData`, one for each validator. /// /// Works only up to 65536 validators, and `n_validators` must be non-zero. -pub fn obtain_availability_chunks_v0(n_validators: usize, data: &v0::AvailableData) +pub fn obtain_chunks_v0(n_validators: usize, data: &v0::AvailableData) -> Result>, Error> { obtain_chunks(n_validators, data) @@ -136,7 +136,7 @@ pub fn obtain_availability_chunks_v0(n_validators: usize, data: &v0::AvailableDa /// Obtain erasure-coded chunks for v1 `AvailableData`, one for each validator. /// /// Works only up to 65536 validators, and `n_validators` must be non-zero. -pub fn obtain_availability_chunks_v1(n_validators: usize, data: &v1::AvailableData) +pub fn obtain_chunks_v1(n_validators: usize, data: &v1::AvailableData) -> Result>, Error> { obtain_chunks(n_validators, data) From beb0dc4f7d7c32c48e29a794a00b7e7db2469abd Mon Sep 17 00:00:00 2001 From: Robert Habermeier Date: Thu, 9 Jul 2020 19:24:54 -0400 Subject: [PATCH 38/46] fix up candidate backing --- node/core/backing/src/lib.rs | 165 +++++++++++++++++++---------------- 1 file changed, 88 insertions(+), 77 deletions(-) diff --git a/node/core/backing/src/lib.rs b/node/core/backing/src/lib.rs index 3a36e9223edf..fe6bfe904bac 100644 --- a/node/core/backing/src/lib.rs +++ b/node/core/backing/src/lib.rs @@ -21,6 +21,7 @@ use std::collections::{HashMap, HashSet}; use std::convert::TryFrom; use std::pin::Pin; +use std::sync::Arc; use std::time::Duration; use bitvec::vec::BitVec; @@ -38,12 +39,13 @@ use primitives::Pair; use keystore::KeyStorePtr; use polkadot_primitives::v1::{ CommittedCandidateReceipt, BackedCandidate, Id as ParaId, ValidatorPair, ValidatorId, - ValidatorIndex, HeadData, SigningContext, PoV, OmittedValidationData, - CandidateDescriptor, LocalValidationData, GlobalValidationSchedule, AvailableData, - ErasureChunk, ValidatorSignature, Hash, CandidateReceipt, + ValidatorIndex, SigningContext, PoV, OmittedValidationData, + CandidateDescriptor, AvailableData, ErasureChunk, ValidatorSignature, Hash, CandidateReceipt, + CandidateCommitments, }; use polkadot_node_primitives::{ FromTableMisbehavior, Statement, SignedFullStatement, MisbehaviorReport, ValidationResult, + ValidationOutputs, }; use polkadot_subsystem::{ FromOverseer, OverseerSignal, Subsystem, SubsystemContext, SpawnedSubsystem, @@ -91,8 +93,6 @@ struct CandidateBackingJob { /// Outbound message channel sending part. tx_from: mpsc::Sender, - /// `HeadData`s of the parachains that this validator is assigned to. - head_data: HeadData, /// The `ParaId`s assigned to this validator. assignment: ParaId, /// We issued `Valid` or `Invalid` statements on about these candidates. @@ -134,7 +134,7 @@ impl TableContextTrait for TableContext { } fn is_member_of(&self, authority: &ValidatorIndex, group: &ParaId) -> bool { - self.groups.get(group).map_or(false, |g| g.iter().position(|&a| a == authority).is_some()) + self.groups.get(group).map_or(false, |g| g.iter().position(|a| a == authority).is_some()) } fn requisite_votes(&self, group: &ParaId) -> usize { @@ -236,44 +236,61 @@ impl CandidateBackingJob { async fn issue_candidate_invalid_message( &mut self, - candidate: CommittedCandidateReceipt, + candidate: CandidateReceipt, ) -> Result<(), Error> { self.tx_from.send(FromJob::CandidateSelection( - CandidateSelectionMessage::Invalid(self.parent, candidate.to_plain()) + CandidateSelectionMessage::Invalid(self.parent, candidate) )).await?; Ok(()) } /// Validate the candidate that is requested to be `Second`ed and distribute validation result. + /// + /// Returns `Ok(true)` if we issued a `Seconded` statement about this candidate. async fn validate_and_second( &mut self, - candidate: CandidateReceipt, + candidate: &CandidateReceipt, pov: PoV, - ) -> Result { - let valid = self.request_candidate_validation(candidate.clone(), pov.clone()).await?; - let statement = match valid.0 { - ValidationResult::Valid => { + ) -> Result { + let valid = self.request_candidate_validation( + candidate.descriptor().clone(), + Arc::new(pov.clone()), + ).await?; + + let candidate_hash = candidate.hash(); + + let (was_valid, statement) = match valid { + ValidationResult::Valid(outputs) => { // make PoV available for later distribution. Send data to the availability // store to keep. Sign and dispatch `valid` statement to network if we // have not seconded the given candidate. - self.make_pov_available(pov, valid.1, valid.2).await?; - self.issued_statements.insert(candidate.hash()); - Statement::Seconded(candidate) + let commitments = self.make_pov_available(pov, outputs).await?; + + let candidate = CommittedCandidateReceipt { + descriptor: candidate.descriptor.clone(), + commitments, + }; + (true, Some(Statement::Seconded(candidate))) } ValidationResult::Invalid => { - let candidate_hash = candidate.hash(); - self.issue_candidate_invalid_message(candidate).await?; - Statement::Invalid(candidate_hash) + // no need to issue a statement about this if we aren't seconding it. + // + // there's an infinite amount of garbage out there. no need to acknowledge + // all of it. + self.issue_candidate_invalid_message(candidate.clone()).await?; + (false, None) } }; - if let Some(signed_statement) = self.sign_statement(statement) { + self.issued_statements.insert(candidate_hash); + + if let Some(signed_statement) = statement.and_then(|s| self.sign_statement(s)) { self.import_statement(&signed_statement).await?; self.distribute_signed_statement(signed_statement).await?; } - Ok(valid.0) + Ok(was_valid) } fn get_backed(&self) -> Vec { @@ -382,8 +399,8 @@ impl CandidateBackingJob { let candidate_hash = candidate.hash(); if !self.issued_statements.contains(&candidate_hash) { - if let Ok(ValidationResult::Valid) = self.validate_and_second( - candidate, + if let Ok(true) = self.validate_and_second( + &candidate, pov, ).await { self.seconded = Some(candidate_hash); @@ -412,17 +429,32 @@ impl CandidateBackingJob { async fn kick_off_validation_work( &mut self, summary: TableSummary, - ) -> Result { - let candidate = self.table.get_candidate(&summary.candidate).ok_or(Error::CandidateNotFound)?; - let candidate = candidate.clone(); - let descriptor = candidate.to_descriptor(); - let candidate_hash = candidate.hash(); - let pov = self.request_pov_from_distribution(descriptor).await?; - let v = self.request_candidate_validation(candidate, pov).await?; + ) -> Result<(), Error> { + let candidate_hash = summary.candidate.clone(); - let statement = match v.0 { - ValidationResult::Valid => { - Statement::Valid(candidate_hash) + if self.issued_statements.contains(&candidate_hash) { + return Ok(()) + } + + // We clone the commitments here because there are borrowck + // errors relating to this being a struct and methods borrowing the entirety of self + // and not just those things that the function uses. + let candidate = self.table.get_candidate(&candidate_hash).ok_or(Error::CandidateNotFound)?; + let expected_commitments = candidate.commitments.clone(); + + let descriptor = candidate.descriptor().clone(); + let pov = self.request_pov_from_distribution(descriptor.clone()).await?; + let v = self.request_candidate_validation(descriptor, pov.clone()).await?; + + let statement = match v { + ValidationResult::Valid(outputs) => { + // If validation produces a new set of commitments, we vote the candidate as invalid. + let commitments = self.make_pov_available((&*pov).clone(), outputs).await?; + if commitments != expected_commitments { + Statement::Invalid(candidate_hash) + } else { + Statement::Valid(candidate_hash) + } } ValidationResult::Invalid => { Statement::Invalid(candidate_hash) @@ -435,7 +467,7 @@ impl CandidateBackingJob { self.distribute_signed_statement(signed_statement).await?; } - Ok(v.0) + Ok(()) } /// Import the statement and kick off validation work if it is a part of our assignment. @@ -493,29 +525,26 @@ impl CandidateBackingJob { async fn request_pov_from_distribution( &mut self, descriptor: CandidateDescriptor, - ) -> Result { + ) -> Result, Error> { let (tx, rx) = oneshot::channel(); self.tx_from.send(FromJob::PoVDistribution( PoVDistributionMessage::FetchPoV(self.parent, descriptor, tx) )).await?; - let pov = rx.await?; - Ok((*pov).clone()) + Ok(rx.await?) } async fn request_candidate_validation( &mut self, - candidate: CommittedCandidateReceipt, - pov: PoV, - ) -> Result<(ValidationResult, GlobalValidationSchedule, LocalValidationData), Error> { + candidate: CandidateDescriptor, + pov: Arc, + ) -> Result { let (tx, rx) = oneshot::channel(); self.tx_from.send(FromJob::CandidateValidation( - CandidateValidationMessage::Validate( - self.parent, + CandidateValidationMessage::ValidateFromChainState( candidate, - self.head_data.clone(), pov, tx, ) @@ -541,12 +570,11 @@ impl CandidateBackingJob { async fn make_pov_available( &mut self, pov: PoV, - global_validation: GlobalValidationSchedule, - local_validation: LocalValidationData, - ) -> Result<(), Error> { + outputs: ValidationOutputs, + ) -> Result { let omitted_validation = OmittedValidationData { - global_validation, - local_validation, + global_validation: outputs.global_validation_schedule, + local_validation: outputs.local_validation_data, }; let available_data = AvailableData { @@ -560,10 +588,11 @@ impl CandidateBackingJob { )?; let branches = erasure_coding::branches(chunks.as_ref()); + let erasure_root = branches.root(); - for (index, (chunk, proof)) in chunks.iter().zip(branches.map(|(proof, _)| proof)).enumerate() { + for (index, (proof, chunk)) in branches.enumerate() { let chunk = ErasureChunk { - chunk: chunk.clone(), + chunk: chunk.to_vec(), index: index as u32, proof, }; @@ -571,7 +600,13 @@ impl CandidateBackingJob { self.store_chunk(index as ValidatorIndex, chunk).await?; } - Ok(()) + Ok(CandidateCommitments { + fees: outputs.fees, + upward_messages: outputs.upward_messages, + erasure_root, + new_validation_code: outputs.new_validation_code, + head_data: outputs.head_data, + }) } async fn distribute_signed_statement(&mut self, s: SignedFullStatement) -> Result<(), Error> { @@ -650,13 +685,7 @@ async fn run_job( } } - let ( - head_data, - signing_context, - ) = futures::try_join!( - request_head_data(parent, &mut tx_from, assignment).await?, - request_signing_context(parent, &mut tx_from).await?, - )?; + let signing_context = request_signing_context(parent, &mut tx_from).await?.await?; let table_context = TableContext { signing_context, @@ -669,7 +698,6 @@ async fn run_job( parent, rx_to, tx_from, - head_data, assignment, issued_statements: HashSet::new(), seconded: None, @@ -729,23 +757,6 @@ async fn request_signing_context( Ok(rx) } -/// Request `HeadData` for some `ParaId` from `RuntimeApi`. -async fn request_head_data( - parent: Hash, - s: &mut mpsc::Sender, - id: ParaId, -) -> Result, Error> { - let (tx, rx) = oneshot::channel(); - - s.send(FromJob::RuntimeApiMessage(RuntimeApiMessage::Request( - parent, - RuntimeApiRequest::HeadData(id, tx), - ) - )).await?; - - Ok(rx) -} - impl Jobs { fn new(spawner: S) -> Self { Self { @@ -927,7 +938,7 @@ mod tests { use sp_keyring::Sr25519Keyring; use polkadot_primitives::v1::{ AssignmentKind, CollatorId, CoreAssignment, BlockData, CoreIndex, GroupIndex, ValidityAttestation, - CandidateCommitments, + CandidateCommitments, LocalValidationData, GlobalValidationSchedule, HeadData, }; use assert_matches::assert_matches; From d69770cd750dfe3a2c2ca331f8dcb9622a12974e Mon Sep 17 00:00:00 2001 From: Robert Habermeier Date: Thu, 9 Jul 2020 20:01:42 -0400 Subject: [PATCH 39/46] update docs a bit --- roadmap/implementers-guide/src/types/overseer-protocol.md | 1 + 1 file changed, 1 insertion(+) diff --git a/roadmap/implementers-guide/src/types/overseer-protocol.md b/roadmap/implementers-guide/src/types/overseer-protocol.md index 90b9cd43eee2..b822508f4a3e 100644 --- a/roadmap/implementers-guide/src/types/overseer-protocol.md +++ b/roadmap/implementers-guide/src/types/overseer-protocol.md @@ -91,6 +91,7 @@ enum CandidateBackingMessage { GetBackedCandidates(Hash, ResponseChannel>), /// Note that the Candidate Backing subsystem should second the given candidate in the context of the /// given relay-parent (ref. by hash). This candidate must be validated using the provided PoV. + /// The PoV is expected to match the `pov_hash` in the descriptor. Second(Hash, CandidateReceipt, PoV), /// Note a peer validator's statement about a particular candidate. Disagreements about validity must be escalated /// to a broader check by Misbehavior Arbitration. Agreements are simply tallied until a quorum is reached. From bbc2ea127a0d805377bac60e875b36596f1b456f Mon Sep 17 00:00:00 2001 From: Robert Habermeier Date: Thu, 9 Jul 2020 20:12:08 -0400 Subject: [PATCH 40/46] fix most tests and add short-circuiting to make_pov_available --- node/core/backing/src/lib.rs | 295 +++++++++++++++++++++-------------- 1 file changed, 174 insertions(+), 121 deletions(-) diff --git a/node/core/backing/src/lib.rs b/node/core/backing/src/lib.rs index fe6bfe904bac..e3ba12a4b392 100644 --- a/node/core/backing/src/lib.rs +++ b/node/core/backing/src/lib.rs @@ -260,18 +260,37 @@ impl CandidateBackingJob { let candidate_hash = candidate.hash(); - let (was_valid, statement) = match valid { + let statement = match valid { ValidationResult::Valid(outputs) => { // make PoV available for later distribution. Send data to the availability // store to keep. Sign and dispatch `valid` statement to network if we // have not seconded the given candidate. - let commitments = self.make_pov_available(pov, outputs).await?; - - let candidate = CommittedCandidateReceipt { - descriptor: candidate.descriptor.clone(), - commitments, - }; - (true, Some(Statement::Seconded(candidate))) + // + // If the commitments hash produced by validation is not the same as given by + // the collator, do not make available and report the collator. + let commitments_check = self.make_pov_available( + pov, + outputs, + |commitments| if commitments.hash() == candidate.commitments_hash { + Ok(CommittedCandidateReceipt { + descriptor: candidate.descriptor().clone(), + commitments, + }) + } else { + Err(()) + }, + ).await?; + + match commitments_check { + Ok(candidate) => { + self.issued_statements.insert(candidate_hash); + Some(Statement::Seconded(candidate)) + } + Err(()) => { + self.issue_candidate_invalid_message(candidate.clone()).await?; + None + } + } } ValidationResult::Invalid => { // no need to issue a statement about this if we aren't seconding it. @@ -279,18 +298,17 @@ impl CandidateBackingJob { // there's an infinite amount of garbage out there. no need to acknowledge // all of it. self.issue_candidate_invalid_message(candidate.clone()).await?; - (false, None) + None } }; - self.issued_statements.insert(candidate_hash); - + let issued_statement = statement.is_some(); if let Some(signed_statement) = statement.and_then(|s| self.sign_statement(s)) { self.import_statement(&signed_statement).await?; self.distribute_signed_statement(signed_statement).await?; } - Ok(was_valid) + Ok(issued_statement) } fn get_backed(&self) -> Vec { @@ -449,11 +467,19 @@ impl CandidateBackingJob { let statement = match v { ValidationResult::Valid(outputs) => { // If validation produces a new set of commitments, we vote the candidate as invalid. - let commitments = self.make_pov_available((&*pov).clone(), outputs).await?; - if commitments != expected_commitments { - Statement::Invalid(candidate_hash) - } else { - Statement::Valid(candidate_hash) + let commitments_check = self.make_pov_available( + (&*pov).clone(), + outputs, + |commitments| if commitments == expected_commitments { + Ok(()) + } else { + Err(()) + } + ).await?; + + match commitments_check { + Ok(()) => Statement::Valid(candidate_hash), + Err(()) => Statement::Invalid(candidate_hash), } } ValidationResult::Invalid => { @@ -567,11 +593,17 @@ impl CandidateBackingJob { Ok(()) } - async fn make_pov_available( + // Compute the erasure-coding and make it available. + // + // This calls an inspection function before making the PoV available for any last checks + // that need to be done. If the inspection function returns an error, this function returns + // early without making the PoV available. + async fn make_pov_available( &mut self, pov: PoV, outputs: ValidationOutputs, - ) -> Result { + with_commitments: impl FnOnce(CandidateCommitments) -> Result, + ) -> Result, Error> { let omitted_validation = OmittedValidationData { global_validation: outputs.global_validation_schedule, local_validation: outputs.local_validation_data, @@ -590,6 +622,19 @@ impl CandidateBackingJob { let branches = erasure_coding::branches(chunks.as_ref()); let erasure_root = branches.root(); + let commitments = CandidateCommitments { + fees: outputs.fees, + upward_messages: outputs.upward_messages, + erasure_root, + new_validation_code: outputs.new_validation_code, + head_data: outputs.head_data, + }; + + let res = match with_commitments(commitments) { + Ok(x) => x, + Err(e) => return Ok(Err(e)), + }; + for (index, (proof, chunk)) in branches.enumerate() { let chunk = ErasureChunk { chunk: chunk.to_vec(), @@ -600,13 +645,7 @@ impl CandidateBackingJob { self.store_chunk(index as ValidatorIndex, chunk).await?; } - Ok(CandidateCommitments { - fees: outputs.fees, - upward_messages: outputs.upward_messages, - erasure_root, - new_validation_code: outputs.new_validation_code, - head_data: outputs.head_data, - }) + Ok(Ok(res)) } async fn distribute_signed_statement(&mut self, s: SignedFullStatement) -> Result<(), Error> { @@ -1033,6 +1072,7 @@ mod tests { parent_head: HeadData(vec![7, 8, 9]), balance: Default::default(), code_upgrade_allowed: None, + validation_code_hash: Default::default(), }; let global_validation_schedule = GlobalValidationSchedule { @@ -1077,12 +1117,28 @@ mod tests { executor::block_on(future::select(test_fut, subsystem)); } + fn make_erasure_root(test: &TestState, pov: PoV) -> Hash { + let omitted_validation = OmittedValidationData { + global_validation: test.global_validation_schedule.clone(), + local_validation: test.local_validation_data.clone(), + }; + + let available_data = AvailableData { + omitted_validation, + pov, + }; + + let chunks = erasure_coding::obtain_chunks_v1(test.validators.len(), &available_data).unwrap(); + erasure_coding::branches(&chunks).root() + } + #[derive(Default)] struct TestCandidateBuilder { para_id: ParaId, head_data: HeadData, pov_hash: Hash, relay_parent: Hash, + erasure_root: Hash, } impl TestCandidateBuilder { @@ -1096,7 +1152,7 @@ mod tests { }, commitments: CandidateCommitments { head_data: self.head_data, - new_validation_code: self.new_validation_code, + erasure_root: self.erasure_root, ..Default::default() }, } @@ -1133,16 +1189,6 @@ mod tests { } ); - // Check that subsystem job issues a request for the head data. - assert_matches!( - virtual_overseer.recv().await, - AllMessages::RuntimeApi( - RuntimeApiMessage::Request(parent, RuntimeApiRequest::HeadData(id, tx)) - ) if parent == test_state.relay_parent => { - tx.send(test_state.head_data.get(&id).unwrap().clone()).unwrap(); - } - ); - // Check that subsystem job issues a request for the signing context. assert_matches!( virtual_overseer.recv().await, @@ -1168,42 +1214,45 @@ mod tests { block_data: BlockData(vec![42, 43, 44]), }; + let expected_head_data = test_state.head_data.get(&test_state.chain_ids[0]).unwrap(); + let pov_hash = pov.hash(); let candidate = TestCandidateBuilder { para_id: test_state.chain_ids[0], relay_parent: test_state.relay_parent, pov_hash, + head_data: expected_head_data.clone(), ..Default::default() }.build(); let second = CandidateBackingMessage::Second( test_state.relay_parent, - candidate.clone(), + candidate.to_plain(), pov.clone(), ); virtual_overseer.send(FromOverseer::Communication{ msg: second }).await; - let expected_head_data = test_state.head_data.get(&test_state.chain_ids[0]).unwrap(); assert_matches!( virtual_overseer.recv().await, AllMessages::CandidateValidation( - CandidateValidationMessage::Validate( - parent_hash, + CandidateValidationMessage::ValidateFromChainState( c, - head_data, pov, tx, ) - ) if parent_hash == test_state.relay_parent && - pov == pov && c == candidate => { - assert_eq!(head_data, *expected_head_data); - tx.send(Ok(( - ValidationResult::Valid, - test_state.global_validation_schedule, - test_state.local_validation_data, - ))).unwrap(); + ) if pov == pov && &c == candidate.descriptor() => { + tx.send(Ok( + ValidationResult::Valid(ValidationOutputs { + global_validation_schedule: test_state.global_validation_schedule, + local_validation_data: test_state.local_validation_data, + head_data: expected_head_data.clone(), + upward_messages: Vec::new(), + fees: Default::default(), + new_validation_code: None, + }), + )).unwrap(); } ); @@ -1252,10 +1301,13 @@ mod tests { let pov_hash = pov.hash(); + let expected_head_data = test_state.head_data.get(&test_state.chain_ids[0]).unwrap(); + let candidate_a = TestCandidateBuilder { para_id: test_state.chain_ids[0], relay_parent: test_state.relay_parent, pov_hash, + head_data: expected_head_data.clone(), ..Default::default() }.build(); @@ -1291,28 +1343,27 @@ mod tests { } ); - let expected_head_data = test_state.head_data.get(&test_state.chain_ids[0]).unwrap(); - // The next step is the actual request to Validation subsystem // to validate the `Seconded` candidate. assert_matches!( virtual_overseer.recv().await, AllMessages::CandidateValidation( - CandidateValidationMessage::Validate( - relay_parent, - candidate, - head_data, + CandidateValidationMessage::ValidateFromChainState( + c, pov, tx, ) - ) if relay_parent == test_state.relay_parent && candidate == candidate_a => { - assert_eq!(head_data, *expected_head_data); - assert_eq!(pov, pov); - tx.send(Ok(( - ValidationResult::Valid, - test_state.global_validation_schedule, - test_state.local_validation_data, - ))).unwrap(); + ) if pov == pov && &c == candidate_a.descriptor() => { + tx.send(Ok( + ValidationResult::Valid(ValidationOutputs { + global_validation_schedule: test_state.global_validation_schedule, + local_validation_data: test_state.local_validation_data, + head_data: expected_head_data.clone(), + upward_messages: Vec::new(), + fees: Default::default(), + new_validation_code: None, + }), + )).unwrap(); } ); @@ -1367,10 +1418,15 @@ mod tests { }; let pov_hash = pov.hash(); + + let expected_head_data = test_state.head_data.get(&test_state.chain_ids[0]).unwrap(); + let candidate_a = TestCandidateBuilder { para_id: test_state.chain_ids[0], relay_parent: test_state.relay_parent, pov_hash, + erasure_root: make_erasure_root(&test_state, pov.clone()), + head_data: expected_head_data.clone(), ..Default::default() }.build(); @@ -1410,29 +1466,37 @@ mod tests { } ); - let expected_head_data = test_state.head_data.get(&test_state.chain_ids[0]).unwrap(); - assert_matches!( virtual_overseer.recv().await, AllMessages::CandidateValidation( - CandidateValidationMessage::Validate( - relay_parent, - candidate, - head_data, + CandidateValidationMessage::ValidateFromChainState( + c, pov, tx, ) - ) if relay_parent == test_state.relay_parent && candidate == candidate_a => { - assert_eq!(pov, pov); - assert_eq!(head_data, *expected_head_data); - tx.send(Ok(( - ValidationResult::Valid, - test_state.global_validation_schedule, - test_state.local_validation_data, - ))).unwrap(); + ) if pov == pov && &c == candidate_a.descriptor() => { + tx.send(Ok( + ValidationResult::Valid(ValidationOutputs { + global_validation_schedule: test_state.global_validation_schedule, + local_validation_data: test_state.local_validation_data, + head_data: expected_head_data.clone(), + upward_messages: Vec::new(), + fees: Default::default(), + new_validation_code: None, + }), + )).unwrap(); } ); + for _ in 0..test_state.validators.len() { + assert_matches!( + virtual_overseer.recv().await, + AllMessages::AvailabilityStore( + AvailabilityStoreMessage::StoreChunk(parent_hash, _, _) + ) if parent_hash == test_state.relay_parent + ); + } + assert_matches!( virtual_overseer.recv().await, AllMessages::StatementDistribution( @@ -1522,7 +1586,7 @@ mod tests { let second = CandidateBackingMessage::Second( test_state.relay_parent, - candidate_a.clone(), + candidate_a.to_plain(), pov_block_a.clone(), ); @@ -1533,21 +1597,22 @@ mod tests { assert_matches!( virtual_overseer.recv().await, AllMessages::CandidateValidation( - CandidateValidationMessage::Validate( - parent_hash, + CandidateValidationMessage::ValidateFromChainState( c, - head_data, pov, tx, ) - ) if parent_hash == test_state.relay_parent && - pov == pov_block_a && c == candidate_a => { - assert_eq!(head_data, *expected_head_data); - tx.send(Ok(( - ValidationResult::Invalid, - test_state.global_validation_schedule.clone(), - test_state.local_validation_data.clone(), - ))).unwrap(); + ) if pov == pov && &c == candidate_a.descriptor() => { + tx.send(Ok( + ValidationResult::Valid(ValidationOutputs { + global_validation_schedule: test_state.global_validation_schedule, + local_validation_data: test_state.local_validation_data, + head_data: expected_head_data.clone(), + upward_messages: Vec::new(), + fees: Default::default(), + new_validation_code: None, + }), + )).unwrap(); } ); @@ -1583,21 +1648,22 @@ mod tests { assert_matches!( virtual_overseer.recv().await, AllMessages::CandidateValidation( - CandidateValidationMessage::Validate( - parent_hash, + CandidateValidationMessage::ValidateFromChainState( c, - head_data, pov, tx, ) - ) if parent_hash == test_state.relay_parent && - pov == pov_block_b && c == candidate_b => { - assert_eq!(head_data, *expected_head_data); - tx.send(Ok(( - ValidationResult::Valid, - test_state.global_validation_schedule, - test_state.local_validation_data, - ))).unwrap(); + ) if pov == pov && &c == candidate_b.descriptor() => { + tx.send(Ok( + ValidationResult::Valid(ValidationOutputs { + global_validation_schedule: test_state.global_validation_schedule, + local_validation_data: test_state.local_validation_data, + head_data: expected_head_data.clone(), + upward_messages: Vec::new(), + fees: Default::default(), + new_validation_code: None, + }), + )).unwrap(); } ); @@ -1690,23 +1756,13 @@ mod tests { assert_matches!( virtual_overseer.recv().await, AllMessages::CandidateValidation( - CandidateValidationMessage::Validate( - relay_parent, - candidate_recvd, - head_data, + CandidateValidationMessage::ValidateFromChainState( + c, pov, tx, ) - ) => { - assert_eq!(relay_parent, test_state.relay_parent); - assert_eq!(candidate_recvd, candidate); - assert_eq!(head_data, *expected_head_data); - assert_eq!(pov, pov); - tx.send(Ok(( - ValidationResult::Invalid, - test_state.global_validation_schedule, - test_state.local_validation_data, - ))).unwrap(); + ) if pov == pov && &c == candidate.descriptor() => { + tx.send(Ok(ValidationResult::Invalid)).unwrap(); } ); @@ -1765,15 +1821,12 @@ mod tests { assert_matches!( virtual_overseer.recv().await, AllMessages::CandidateValidation( - CandidateValidationMessage::Validate( - relay_parent, - _, - _, + CandidateValidationMessage::ValidateFromChainState( + c, pov, - _, + tx, ) ) => { - assert_eq!(relay_parent, test_state.relay_parent); assert_eq!(pov, pov_to_second); } ); From 40152713f330982c43c7ca905c9e175347ed5e28 Mon Sep 17 00:00:00 2001 From: Robert Habermeier Date: Thu, 9 Jul 2020 20:21:18 -0400 Subject: [PATCH 41/46] fix remainder of candidate backing tests --- node/core/backing/src/lib.rs | 44 +++++++++++++----------------------- 1 file changed, 16 insertions(+), 28 deletions(-) diff --git a/node/core/backing/src/lib.rs b/node/core/backing/src/lib.rs index e3ba12a4b392..3c52aeb80292 100644 --- a/node/core/backing/src/lib.rs +++ b/node/core/backing/src/lib.rs @@ -1222,6 +1222,7 @@ mod tests { relay_parent: test_state.relay_parent, pov_hash, head_data: expected_head_data.clone(), + erasure_root: make_erasure_root(&test_state, pov.clone()), ..Default::default() }.build(); @@ -1308,6 +1309,7 @@ mod tests { relay_parent: test_state.relay_parent, pov_hash, head_data: expected_head_data.clone(), + erasure_root: make_erasure_root(&test_state, pov.clone()), ..Default::default() }.build(); @@ -1568,10 +1570,13 @@ mod tests { let pov_hash_a = pov_block_a.hash(); let pov_hash_b = pov_block_b.hash(); + let expected_head_data = test_state.head_data.get(&test_state.chain_ids[0]).unwrap(); + let candidate_a = TestCandidateBuilder { para_id: test_state.chain_ids[0], relay_parent: test_state.relay_parent, pov_hash: pov_hash_a, + erasure_root: make_erasure_root(&test_state, pov_block_a.clone()), ..Default::default() }.build(); @@ -1581,6 +1586,8 @@ mod tests { para_id: test_state.chain_ids[0], relay_parent: test_state.relay_parent, pov_hash: pov_hash_b, + erasure_root: make_erasure_root(&test_state, pov_block_b.clone()), + head_data: expected_head_data.clone(), ..Default::default() }.build(); @@ -1603,41 +1610,20 @@ mod tests { tx, ) ) if pov == pov && &c == candidate_a.descriptor() => { - tx.send(Ok( - ValidationResult::Valid(ValidationOutputs { - global_validation_schedule: test_state.global_validation_schedule, - local_validation_data: test_state.local_validation_data, - head_data: expected_head_data.clone(), - upward_messages: Vec::new(), - fees: Default::default(), - new_validation_code: None, - }), - )).unwrap(); + tx.send(Ok(ValidationResult::Invalid)).unwrap(); } ); assert_matches!( virtual_overseer.recv().await, AllMessages::CandidateSelection( - CandidateSelectionMessage::Invalid(parent_hash, candidate) - ) if parent_hash == test_state.relay_parent && candidate == candidate_a - ); - - assert_matches!( - virtual_overseer.recv().await, - AllMessages::StatementDistribution( - StatementDistributionMessage::Share( - relay_parent, - statement, - ) - ) if relay_parent == test_state.relay_parent => { - assert_eq!(*statement.payload(), Statement::Invalid(candidate_a_hash)); - } + CandidateSelectionMessage::Invalid(parent_hash, c) + ) if parent_hash == test_state.relay_parent && c == candidate_a.to_plain() ); let second = CandidateBackingMessage::Second( test_state.relay_parent, - candidate_b.clone(), + candidate_b.to_plain(), pov_block_b.clone(), ); @@ -1719,6 +1705,7 @@ mod tests { para_id: test_state.chain_ids[0], relay_parent: test_state.relay_parent, pov_hash, + erasure_root: make_erasure_root(&test_state, pov.clone()), ..Default::default() }.build(); @@ -1788,7 +1775,7 @@ mod tests { // This should emit no actions from subsystem. let second = CandidateBackingMessage::Second( test_state.relay_parent, - candidate.clone(), + candidate.to_plain(), pov.clone(), ); @@ -1804,12 +1791,13 @@ mod tests { para_id: test_state.chain_ids[0], relay_parent: test_state.relay_parent, pov_hash, + erasure_root: make_erasure_root(&test_state, pov_to_second.clone()), ..Default::default() }.build(); let second = CandidateBackingMessage::Second( test_state.relay_parent, - candidate_to_second.clone(), + candidate_to_second.to_plain(), pov_to_second.clone(), ); @@ -1827,7 +1815,7 @@ mod tests { tx, ) ) => { - assert_eq!(pov, pov_to_second); + assert_eq!(&*pov, &pov_to_second); } ); }); From c8b0af40a0757d08492fa5ef6d950715bd4312e1 Mon Sep 17 00:00:00 2001 From: Robert Habermeier Date: Thu, 9 Jul 2020 20:22:52 -0400 Subject: [PATCH 42/46] squanching warns --- node/core/backing/src/lib.rs | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/node/core/backing/src/lib.rs b/node/core/backing/src/lib.rs index 3c52aeb80292..281147847e19 100644 --- a/node/core/backing/src/lib.rs +++ b/node/core/backing/src/lib.rs @@ -1580,8 +1580,6 @@ mod tests { ..Default::default() }.build(); - let candidate_a_hash = candidate_a.hash(); - let candidate_b = TestCandidateBuilder { para_id: test_state.chain_ids[0], relay_parent: test_state.relay_parent, @@ -1599,7 +1597,6 @@ mod tests { virtual_overseer.send(FromOverseer::Communication{ msg: second }).await; - let expected_head_data = test_state.head_data.get(&test_state.chain_ids[0]).unwrap(); assert_matches!( virtual_overseer.recv().await, @@ -1737,7 +1734,6 @@ mod tests { } ); - let expected_head_data = test_state.head_data.get(&test_state.chain_ids[0]).unwrap(); // Tell subsystem that this candidate is invalid. assert_matches!( @@ -1810,9 +1806,9 @@ mod tests { virtual_overseer.recv().await, AllMessages::CandidateValidation( CandidateValidationMessage::ValidateFromChainState( - c, + _, pov, - tx, + _, ) ) => { assert_eq!(&*pov, &pov_to_second); From 8e5e35d80806d4dbfb752c218ba948281d7b77d3 Mon Sep 17 00:00:00 2001 From: Robert Habermeier Date: Thu, 9 Jul 2020 20:23:25 -0400 Subject: [PATCH 43/46] squanch it up --- runtime/parachains/src/scheduler.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/runtime/parachains/src/scheduler.rs b/runtime/parachains/src/scheduler.rs index ade1c2da40df..fe5c27016115 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, CollatorId, ValidatorIndex, CoreAssignment, CoreOccupied, CoreIndex, AssignmentKind, + Id as ParaId, ValidatorIndex, CoreAssignment, CoreOccupied, CoreIndex, AssignmentKind, GroupIndex, ParathreadClaim, ParathreadEntry, }; use frame_support::{ From 5d352ccb8a468023d1e8113fcf69dd22e441d802 Mon Sep 17 00:00:00 2001 From: Robert Habermeier Date: Thu, 9 Jul 2020 20:25:47 -0400 Subject: [PATCH 44/46] some fallout --- runtime/parachains/src/scheduler.rs | 2 +- validation/src/shared_table/mod.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/runtime/parachains/src/scheduler.rs b/runtime/parachains/src/scheduler.rs index fe5c27016115..9cc2bd72bd81 100644 --- a/runtime/parachains/src/scheduler.rs +++ b/runtime/parachains/src/scheduler.rs @@ -584,7 +584,7 @@ impl Module { mod tests { use super::*; - use primitives::v1::{BlockNumber, ValidatorId}; + use primitives::v1::{BlockNumber, ValidatorId, CollatorId}; use frame_support::traits::{OnFinalize, OnInitialize}; use keyring::Sr25519Keyring; diff --git a/validation/src/shared_table/mod.rs b/validation/src/shared_table/mod.rs index 21046cdd5592..d42c9b7e561c 100644 --- a/validation/src/shared_table/mod.rs +++ b/validation/src/shared_table/mod.rs @@ -71,7 +71,7 @@ impl TableContextTrait for TableContext { } fn is_member_of(&self, authority: &ValidatorIndex, group: &ParaId) -> bool { - let key = match self.validators.get(authority as usize) { + let key = match self.validators.get(*authority as usize) { Some(val) => val, None => return false, }; From 9370455c208eef149ba19c62fe2fc878dcb38019 Mon Sep 17 00:00:00 2001 From: Robert Habermeier Date: Thu, 9 Jul 2020 20:28:15 -0400 Subject: [PATCH 45/46] overseer fallout --- node/overseer/examples/minimal-example.rs | 6 ++---- node/overseer/src/lib.rs | 6 ++---- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/node/overseer/examples/minimal-example.rs b/node/overseer/examples/minimal-example.rs index 40b92c0cfe34..d5f7f043ff43 100644 --- a/node/overseer/examples/minimal-example.rs +++ b/node/overseer/examples/minimal-example.rs @@ -61,13 +61,11 @@ impl Subsystem1 { let (tx, _) = oneshot::channel(); ctx.send_message(AllMessages::CandidateValidation( - CandidateValidationMessage::Validate( - Default::default(), - Default::default(), + CandidateValidationMessage::ValidateFromChainState( Default::default(), PoV { block_data: BlockData(Vec::new()), - }, + }.into(), tx, ) )).await.unwrap(); diff --git a/node/overseer/src/lib.rs b/node/overseer/src/lib.rs index 15a01b242f92..91fceb0d3bb0 100644 --- a/node/overseer/src/lib.rs +++ b/node/overseer/src/lib.rs @@ -977,13 +977,11 @@ mod tests { let (tx, _) = oneshot::channel(); ctx.send_message( AllMessages::CandidateValidation( - CandidateValidationMessage::Validate( - Default::default(), - Default::default(), + CandidateValidationMessage::ValidateFromChainState( Default::default(), PoV { block_data: BlockData(Vec::new()), - }, + }.into(), tx, ) ) From 60c3bb0a9cd7e41d8c86dda79a009359363dbd55 Mon Sep 17 00:00:00 2001 From: Robert Habermeier Date: Thu, 9 Jul 2020 20:37:42 -0400 Subject: [PATCH 46/46] free from polkadot-test-service hell --- node/test-service/src/chain_spec.rs | 2 +- node/test-service/src/lib.rs | 9 ++++----- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/node/test-service/src/chain_spec.rs b/node/test-service/src/chain_spec.rs index cbb08c470f07..e81050afdbbe 100644 --- a/node/test-service/src/chain_spec.rs +++ b/node/test-service/src/chain_spec.rs @@ -17,7 +17,7 @@ use babe_primitives::AuthorityId as BabeId; use grandpa::AuthorityId as GrandpaId; use pallet_staking::Forcing; -use polkadot_primitives::{parachain::ValidatorId, AccountId}; +use polkadot_primitives::v0::{ValidatorId, AccountId}; use polkadot_service::chain_spec::{get_account_id_from_seed, get_from_seed, Extensions}; use polkadot_test_runtime::constants::currency::DOTS; use sc_chain_spec::{ChainSpec, ChainType}; diff --git a/node/test-service/src/lib.rs b/node/test-service/src/lib.rs index 7fc75d9f3719..751373265fc3 100644 --- a/node/test-service/src/lib.rs +++ b/node/test-service/src/lib.rs @@ -26,9 +26,8 @@ use futures::future::Future; use grandpa::FinalityProofProvider as GrandpaFinalityProofProvider; use log::info; use polkadot_network::{legacy::gossip::Known, protocol as network_protocol}; -use polkadot_primitives::{ - parachain::{self, CollatorId}, - Block, BlockId, Hash, +use polkadot_primitives::v0::{ + Block, BlockId, Hash, CollatorId, Id as ParaId, }; use polkadot_runtime_common::{parachains, registrar, BlockHashCount}; use polkadot_service::{ @@ -68,7 +67,7 @@ native_executor_instance!( /// Create a new Polkadot test service for a full node. pub fn polkadot_test_new_full( config: Configuration, - collating_for: Option<(CollatorId, parachain::Id)>, + collating_for: Option<(CollatorId, ParaId)>, max_block_data_size: Option, authority_discovery_enabled: bool, slot_duration: u64, @@ -287,7 +286,7 @@ where let extrinsic = polkadot_test_runtime::UncheckedExtrinsic::new_signed( function.clone(), polkadot_test_runtime::Address::Id(caller.public().into()), - polkadot_primitives::Signature::Sr25519(signature.clone()), + polkadot_primitives::v0::Signature::Sr25519(signature.clone()), extra.clone(), );