Refactor primitives (#1383)

* create a v1 primitives module

* Improve guide on availability types

* punctuate

* new parachains runtime uses new primitives

* tests of new runtime now use new primitives

* add ErasureChunk to guide

* export erasure chunk from v1 primitives

* subsystem crate uses v1 primitives

* node-primitives uses new v1 primitives

* port overseer to new primitives

* new-proposer uses v1 primitives (no ParachainHost anymore)

* fix no-std compilation for primitives

* service-new uses v1 primitives

* network-bridge uses new primitives

* statement distribution uses v1 primitives

* PoV distribution uses v1 primitives; add PoV::hash fn

* move parachain to v0

* remove inclusion_inherent module and place into v1

* remove everything from primitives crate root

* remove some unused old types from v0 primitives

* point everything else at primitives::v0

* squanch some warns up

* add RuntimeDebug import to no-std as well

* port over statement-table and validation

* fix final errors in validation and node-primitives

* add dummy Ord impl to committed candidate receipt

* guide: update CandidateValidationMessage

* add primitive for validationoutputs

* expand CandidateValidationMessage further

* bikeshed

* add some impls to omitted-validation-data and available-data

* expand CandidateValidationMessage

* make erasure-coding generic over v1/v0

* update usages of erasure-coding

* implement commitments.hash()

* use Arc<Pov> for CandidateValidation

* improve new erasure-coding method names

* fix up candidate backing

* update docs a bit

* fix most tests and add short-circuiting to make_pov_available

* fix remainder of candidate backing tests

* squanching warns

* squanch it up

* some fallout

* overseer fallout

* free from polkadot-test-service hell
This commit is contained in:
Robert Habermeier
2020-07-09 21:23:03 -04:00
committed by GitHub
parent 6957847b6b
commit 3b13cd9a85
76 changed files with 1542 additions and 999 deletions
+2 -2
View File
@@ -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};
+2 -4
View File
@@ -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;
+2 -2
View File
@@ -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 },
+1 -1
View File
@@ -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,
+3 -3
View File
@@ -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},
@@ -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,
)?;
@@ -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<I: IntoIterator<Item=(Hash, bool)>>(candidates: I)
+36 -21
View File
@@ -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 polkadot_primitives::{Block, Hash};
use polkadot_primitives::parachain::{
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,9 +55,23 @@ struct TableContext {
validators: Vec<ValidatorId>,
}
impl table::Context for TableContext {
fn is_member_of(&self, authority: ValidatorIndex, group: &ParaId) -> bool {
let key = match self.validators.get(authority as usize) {
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,
None => return false,
};
@@ -84,7 +99,7 @@ impl TableContext {
)
}
fn sign_statement(&self, statement: table::Statement) -> Option<table::SignedStatement> {
fn sign_statement(&self, statement: table_v0::Statement) -> Option<table_v0::SignedStatement> {
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<u64>,
) -> Option<ParachainWork<
Fetch,
@@ -154,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.
@@ -216,7 +231,7 @@ impl SharedTableInner {
/// Produced after validating a candidate.
pub struct Validated {
/// A statement about the validity of the candidate.
statement: table::Statement,
statement: table_v0::Statement,
/// The result of validation.
result: Validation,
}
@@ -461,7 +476,7 @@ impl SharedTable {
pub fn import_remote_statement<Fetch>(
&self,
fetch_pov_block: impl Fn(&AbridgedCandidateReceipt) -> Fetch,
statement: table::SignedStatement,
statement: table_v0::SignedStatement,
) -> Option<ParachainWork<
Fetch,
>> {
@@ -487,7 +502,7 @@ impl SharedTable {
iterable: I,
) -> U
where
I: IntoIterator<Item=table::SignedStatement>,
I: IntoIterator<Item=table_v0::SignedStatement>,
U: ::std::iter::FromIterator<Option<ParachainWork<
Fetch,
>>>,
@@ -539,7 +554,7 @@ impl SharedTable {
/// Get a set of candidates that can be proposed.
pub fn proposed_set(&self) -> Vec<AttestedCandidate> {
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
@@ -583,7 +598,7 @@ impl SharedTable {
}
/// Get all witnessed misbehavior.
pub fn get_misbehavior(&self) -> HashMap<ValidatorIndex, table::Misbehavior> {
pub fn get_misbehavior(&self) -> HashMap<ValidatorIndex, table_v0::Misbehavior> {
self.inner.lock().table.get_misbehavior().clone()
}
@@ -615,7 +630,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};
@@ -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,
@@ -860,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,
@@ -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,
@@ -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<polkadot_primitives::DownwardMessage> {
fn downward_messages(_: ParaId) -> Vec<polkadot_primitives::v0::DownwardMessage> {
Vec::new()
}
}