diff --git a/.gitignore b/.gitignore index 3ab8eb0be7285..1b9aecc6b4fea 100644 --- a/.gitignore +++ b/.gitignore @@ -4,6 +4,7 @@ .wasm-binaries polkadot/runtime/wasm/target/ **/._* +.idea .vscode polkadot.* .DS_Store diff --git a/Cargo.lock b/Cargo.lock index 33cb9d58cc2c2..95416920d40e8 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2204,35 +2204,6 @@ dependencies = [ "tokio 0.1.15 (registry+https://github.com/rust-lang/crates.io-index)", ] -[[package]] -name = "polkadot-consensus" -version = "0.1.0" -dependencies = [ - "error-chain 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)", - "exit-future 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", - "futures 0.1.25 (registry+https://github.com/rust-lang/crates.io-index)", - "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", - "parity-codec 3.0.0 (registry+https://github.com/rust-lang/crates.io-index)", - "parking_lot 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)", - "polkadot-availability-store 0.1.0", - "polkadot-parachain 0.1.0", - "polkadot-primitives 0.1.0", - "polkadot-runtime 0.1.0", - "polkadot-statement-table 0.1.0", - "sr-primitives 0.1.0 (git+https://github.com/paritytech/substrate)", - "srml-aura 0.1.0 (git+https://github.com/paritytech/substrate)", - "substrate-client 0.1.0 (git+https://github.com/paritytech/substrate)", - "substrate-consensus-aura 0.1.0 (git+https://github.com/paritytech/substrate)", - "substrate-consensus-common 0.1.0 (git+https://github.com/paritytech/substrate)", - "substrate-finality-grandpa 0.1.0 (git+https://github.com/paritytech/substrate)", - "substrate-inherents 0.1.0 (git+https://github.com/paritytech/substrate)", - "substrate-keyring 0.1.0 (git+https://github.com/paritytech/substrate)", - "substrate-primitives 0.1.0 (git+https://github.com/paritytech/substrate)", - "substrate-transaction-pool 0.1.0 (git+https://github.com/paritytech/substrate)", - "substrate-trie 0.4.0 (git+https://github.com/paritytech/substrate)", - "tokio 0.1.15 (registry+https://github.com/rust-lang/crates.io-index)", -] - [[package]] name = "polkadot-erasure-coding" version = "0.1.0" @@ -2264,8 +2235,8 @@ dependencies = [ "parity-codec-derive 3.0.0 (registry+https://github.com/rust-lang/crates.io-index)", "parking_lot 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)", "polkadot-availability-store 0.1.0", - "polkadot-consensus 0.1.0", "polkadot-primitives 0.1.0", + "polkadot-validation 0.1.0", "slice-group-by 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", "sr-primitives 0.1.0 (git+https://github.com/paritytech/substrate)", "substrate-client 0.1.0 (git+https://github.com/paritytech/substrate)", @@ -2361,11 +2332,11 @@ dependencies = [ "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", "parking_lot 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)", "polkadot-availability-store 0.1.0", - "polkadot-consensus 0.1.0", "polkadot-executor 0.1.0", "polkadot-network 0.1.0", "polkadot-primitives 0.1.0", "polkadot-runtime 0.1.0", + "polkadot-validation 0.1.0", "slog 2.4.1 (registry+https://github.com/rust-lang/crates.io-index)", "sr-io 0.1.0 (git+https://github.com/paritytech/substrate)", "sr-primitives 0.1.0 (git+https://github.com/paritytech/substrate)", @@ -2390,6 +2361,35 @@ dependencies = [ "substrate-primitives 0.1.0 (git+https://github.com/paritytech/substrate)", ] +[[package]] +name = "polkadot-validation" +version = "0.1.0" +dependencies = [ + "error-chain 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)", + "exit-future 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", + "futures 0.1.25 (registry+https://github.com/rust-lang/crates.io-index)", + "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-codec 3.0.0 (registry+https://github.com/rust-lang/crates.io-index)", + "parking_lot 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)", + "polkadot-availability-store 0.1.0", + "polkadot-parachain 0.1.0", + "polkadot-primitives 0.1.0", + "polkadot-runtime 0.1.0", + "polkadot-statement-table 0.1.0", + "sr-primitives 0.1.0 (git+https://github.com/paritytech/substrate)", + "srml-aura 0.1.0 (git+https://github.com/paritytech/substrate)", + "substrate-client 0.1.0 (git+https://github.com/paritytech/substrate)", + "substrate-consensus-aura 0.1.0 (git+https://github.com/paritytech/substrate)", + "substrate-consensus-common 0.1.0 (git+https://github.com/paritytech/substrate)", + "substrate-finality-grandpa 0.1.0 (git+https://github.com/paritytech/substrate)", + "substrate-inherents 0.1.0 (git+https://github.com/paritytech/substrate)", + "substrate-keyring 0.1.0 (git+https://github.com/paritytech/substrate)", + "substrate-primitives 0.1.0 (git+https://github.com/paritytech/substrate)", + "substrate-transaction-pool 0.1.0 (git+https://github.com/paritytech/substrate)", + "substrate-trie 0.4.0 (git+https://github.com/paritytech/substrate)", + "tokio 0.1.15 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "pretty_assertions" version = "0.5.1" diff --git a/Cargo.toml b/Cargo.toml index 90cf42e787751..0127b82bb9841 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -22,7 +22,6 @@ members = [ "availability-store", "cli", "collator", - "consensus", "erasure-coding", "executor", "network", @@ -31,6 +30,7 @@ members = [ "service", "statement-table", "service", + "validation", "test-parachains/adder", "test-parachains/adder/collator", diff --git a/network/Cargo.toml b/network/Cargo.toml index 3ab6274dc1e18..16a54b8592786 100644 --- a/network/Cargo.toml +++ b/network/Cargo.toml @@ -8,7 +8,7 @@ description = "Polkadot-specific networking protocol" arrayvec = "0.4" parking_lot = "0.7.1" polkadot-availability-store = { path = "../availability-store" } -polkadot-consensus = { path = "../consensus" } +polkadot-validation = { path = "../validation" } polkadot-primitives = { path = "../primitives" } parity-codec = "3.0" parity-codec-derive = "3.0" diff --git a/network/src/lib.rs b/network/src/lib.rs index 1d2a9f734f8a9..77610f6fcb6e4 100644 --- a/network/src/lib.rs +++ b/network/src/lib.rs @@ -24,7 +24,7 @@ extern crate substrate_network; extern crate substrate_primitives; extern crate sr_primitives; -extern crate polkadot_consensus; +extern crate polkadot_validation; extern crate polkadot_availability_store as av_store; extern crate polkadot_primitives; @@ -49,7 +49,7 @@ extern crate substrate_keyring; mod collator_pool; mod local_collations; mod router; -pub mod consensus; +pub mod validation; use codec::{Decode, Encode}; use futures::sync::oneshot; @@ -59,7 +59,7 @@ use substrate_network::{NodeIndex, RequestId, Context, Severity}; use substrate_network::{message, generic_message}; use substrate_network::specialization::NetworkSpecialization as Specialization; use substrate_network::StatusMessage as GenericFullStatus; -use self::consensus::{LiveConsensusInstances, RecentSessionKeys, InsertedRecentKey}; +use self::validation::{LiveValidationSessions, RecentSessionKeys, InsertedRecentKey}; use self::collator_pool::{CollatorPool, Role, Action}; use self::local_collations::LocalCollations; @@ -85,7 +85,7 @@ pub struct Status { struct BlockDataRequest { attempted_peers: HashSet, - consensus_parent: Hash, + validation_session_parent: Hash, candidate_hash: Hash, block_data_hash: Hash, sender: oneshot::Sender, @@ -168,7 +168,7 @@ pub struct PolkadotProtocol { collators: CollatorPool, validators: HashMap, local_collations: LocalCollations, - live_consensus: LiveConsensusInstances, + live_validation_sessions: LiveValidationSessions, in_flight: HashMap<(RequestId, NodeIndex), BlockDataRequest>, pending: Vec, extrinsic_store: Option<::av_store::Store>, @@ -184,7 +184,7 @@ impl PolkadotProtocol { collating_for, validators: HashMap::new(), local_collations: LocalCollations::new(), - live_consensus: LiveConsensusInstances::new(), + live_validation_sessions: LiveValidationSessions::new(), in_flight: HashMap::new(), pending: Vec::new(), extrinsic_store: None, @@ -198,7 +198,7 @@ impl PolkadotProtocol { self.pending.push(BlockDataRequest { attempted_peers: Default::default(), - consensus_parent: relay_parent, + validation_session_parent: relay_parent, candidate_hash: candidate.hash(), block_data_hash: candidate.block_data_hash, sender: tx, @@ -208,14 +208,14 @@ impl PolkadotProtocol { rx } - /// Note new consensus session. - fn new_consensus( + /// Note new validation session. + fn new_validation_session( &mut self, ctx: &mut Context, parent_hash: Hash, - consensus: consensus::CurrentConsensus, + session: validation::ValidationSession, ) { - if let Some(new_local) = self.live_consensus.new_consensus(parent_hash, consensus) { + if let Some(new_local) = self.live_validation_sessions.new_validation_session(parent_hash, session) { for (id, peer_data) in self.peers.iter_mut() .filter(|&(_, ref info)| info.should_send_key()) { @@ -228,8 +228,8 @@ impl PolkadotProtocol { } } - fn remove_consensus(&mut self, parent_hash: &Hash) { - self.live_consensus.remove(parent_hash); + fn remove_validation_session(&mut self, parent_hash: &Hash) { + self.live_validation_sessions.remove(parent_hash); } fn dispatch_pending_requests(&mut self, ctx: &mut Context) { @@ -239,10 +239,10 @@ impl PolkadotProtocol { let in_flight = &mut self.in_flight; for mut pending in ::std::mem::replace(&mut self.pending, Vec::new()) { - let parent = pending.consensus_parent; + let parent = pending.validation_session_parent; let c_hash = pending.candidate_hash; - let still_pending = self.live_consensus.with_block_data(&parent, &c_hash, |x| match x { + let still_pending = self.live_validation_sessions.with_block_data(&parent, &c_hash, |x| match x { Ok(data @ &_) => { // answer locally. let _ = pending.sender.send(data.clone()); @@ -272,7 +272,7 @@ impl PolkadotProtocol { Some(pending) } } - Err(None) => None, // no such known consensus session. prune out. + Err(None) => None, // no such known validation session. prune out. }); if let Some(pending) = still_pending { @@ -288,7 +288,7 @@ impl PolkadotProtocol { match msg { Message::SessionKey(key) => self.on_session_key(ctx, who, key), Message::RequestBlockData(req_id, relay_parent, candidate_hash) => { - let block_data = self.live_consensus + let block_data = self.live_validation_sessions .with_block_data( &relay_parent, &candidate_hash, @@ -440,7 +440,7 @@ impl Specialization for PolkadotProtocol { // send session keys. if peer_info.should_send_key() { - for local_session_key in self.live_consensus.recent_keys() { + for local_session_key in self.live_validation_sessions.recent_keys() { peer_info.collator_state.send_key(*local_session_key, |msg| send_polkadot_message( ctx, who, @@ -481,7 +481,7 @@ impl Specialization for PolkadotProtocol { let (sender, _) = oneshot::channel(); pending.push(::std::mem::replace(val, BlockDataRequest { attempted_peers: Default::default(), - consensus_parent: Default::default(), + validation_session_parent: Default::default(), candidate_hash: Default::default(), block_data_hash: Default::default(), sender, diff --git a/network/src/router.rs b/network/src/router.rs index d2e9d901d812e..74e03ebe6faaf 100644 --- a/network/src/router.rs +++ b/network/src/router.rs @@ -19,11 +19,11 @@ //! During the consensus process, validators exchange statements on validity and availability //! of parachain candidates. //! The `Router` in this file hooks into the underlying network to fulfill -//! the `TableRouter` trait from `polkadot-consensus`, which is expected to call into a shared statement table +//! the `TableRouter` trait from `polkadot-validation`, which is expected to call into a shared statement table //! and dispatch evaluation work as necessary when new statements come in. use sr_primitives::traits::{ProvideRuntimeApi, BlakeTwo256, Hash as HashT}; -use polkadot_consensus::{ +use polkadot_validation::{ SharedTable, TableRouter, SignedStatement, GenericStatement, ParachainWork, Incoming, Validated, Outgoing, }; @@ -41,7 +41,7 @@ use std::collections::{hash_map::{Entry, HashMap}, HashSet}; use std::{io, mem}; use std::sync::Arc; -use consensus::{NetworkService, Knowledge, Executor}; +use validation::{NetworkService, Knowledge, Executor}; type IngressPair = (ParaId, Vec); type IngressPairRef<'a> = (ParaId, &'a [Message]); @@ -380,7 +380,7 @@ impl TableRouter for Router wh impl Drop for Router { fn drop(&mut self) { let parent_hash = self.parent_hash.clone(); - self.network.with_spec(move |spec, _| spec.remove_consensus(&parent_hash)); + self.network.with_spec(move |spec, _| spec.remove_validation_session(&parent_hash)); self.network.drop_gossip(self.attestation_topic); { @@ -481,7 +481,7 @@ impl Future for ComputeIngress where S: Stream { Entry::Occupied(occupied) => { let canon_root = occupied.get().clone(); let messages = messages.iter().map(|m| &m.0[..]); - if ::polkadot_consensus::message_queue_root(messages) != canon_root { + if ::polkadot_validation::message_queue_root(messages) != canon_root { continue; } @@ -572,7 +572,7 @@ mod tests { let roots: HashMap<_, _> = actual_messages.iter() .map(|&(para_id, ref messages)| ( para_id, - ::polkadot_consensus::message_queue_root(messages.iter().map(|m| &m.0)), + ::polkadot_validation::message_queue_root(messages.iter().map(|m| &m.0)), )) .collect(); diff --git a/network/src/tests/mod.rs b/network/src/tests/mod.rs index 60cd03f7dffdb..165d3aeb35967 100644 --- a/network/src/tests/mod.rs +++ b/network/src/tests/mod.rs @@ -14,13 +14,13 @@ // You should have received a copy of the GNU General Public License // along with Polkadot. If not, see . -//! Tests for polkadot and consensus network. +//! Tests for polkadot and validation network. use super::{PolkadotProtocol, Status, Message, FullStatus}; -use consensus::{CurrentConsensus, Knowledge}; +use validation::{ValidationSession, Knowledge}; use parking_lot::Mutex; -use polkadot_consensus::GenericStatement; +use polkadot_validation::GenericStatement; use polkadot_primitives::{Block, SessionKey}; use polkadot_primitives::parachain::{CandidateReceipt, HeadData, BlockData}; use substrate_primitives::H512; @@ -34,7 +34,7 @@ use substrate_network::{ use std::sync::Arc; use futures::Future; -mod consensus; +mod validation; #[derive(Default)] struct TestContext { @@ -87,9 +87,9 @@ fn make_status(status: &Status, roles: Roles) -> FullStatus { } } -fn make_consensus(local_key: SessionKey) -> (CurrentConsensus, Arc>) { +fn make_validation_session(local_key: SessionKey) -> (ValidationSession, Arc>) { let knowledge = Arc::new(Mutex::new(Knowledge::new())); - let c = CurrentConsensus::new(knowledge.clone(), local_key); + let c = ValidationSession::new(knowledge.clone(), local_key); (c, knowledge) } @@ -119,8 +119,8 @@ fn sends_session_key() { { let mut ctx = TestContext::default(); - let (consensus, _knowledge) = make_consensus(local_key); - protocol.new_consensus(&mut ctx, parent_hash, consensus); + let (session, _knowledge) = make_validation_session(local_key); + protocol.new_validation_session(&mut ctx, parent_hash, session); assert!(ctx.has_message(peer_a, Message::SessionKey(local_key))); } @@ -159,8 +159,8 @@ fn fetches_from_those_with_knowledge() { let status = Status { collating_for: None }; - let (consensus, knowledge) = make_consensus(local_key); - protocol.new_consensus(&mut TestContext::default(), parent_hash, consensus); + let (session, knowledge) = make_validation_session(local_key); + protocol.new_validation_session(&mut TestContext::default(), parent_hash, session); knowledge.lock().note_statement(a_key, &GenericStatement::Valid(candidate_hash)); let recv = protocol.fetch_block_data(&mut TestContext::default(), &candidate_receipt, parent_hash); @@ -289,13 +289,13 @@ fn many_session_keys() { let local_key_a = [3; 32].into(); let local_key_b = [4; 32].into(); - let (consensus_a, _knowledge_a) = make_consensus(local_key_a); - let (consensus_b, _knowledge_b) = make_consensus(local_key_b); + let (session_a, _knowledge_a) = make_validation_session(local_key_a); + let (session_b, _knowledge_b) = make_validation_session(local_key_b); - protocol.new_consensus(&mut TestContext::default(), parent_a, consensus_a); - protocol.new_consensus(&mut TestContext::default(), parent_b, consensus_b); + protocol.new_validation_session(&mut TestContext::default(), parent_a, session_a); + protocol.new_validation_session(&mut TestContext::default(), parent_b, session_b); - assert_eq!(protocol.live_consensus.recent_keys(), &[local_key_a, local_key_b]); + assert_eq!(protocol.live_validation_sessions.recent_keys(), &[local_key_a, local_key_b]); let peer_a = 1; @@ -312,7 +312,7 @@ fn many_session_keys() { let peer_b = 2; - protocol.remove_consensus(&parent_a); + protocol.remove_validation_session(&parent_a); { let mut ctx = TestContext::default(); diff --git a/network/src/tests/consensus.rs b/network/src/tests/validation.rs similarity index 96% rename from network/src/tests/consensus.rs rename to network/src/tests/validation.rs index 990238d84e1dc..41819d87a0c52 100644 --- a/network/src/tests/consensus.rs +++ b/network/src/tests/validation.rs @@ -14,15 +14,15 @@ // You should have received a copy of the GNU General Public License // along with Polkadot. If not, see . -//! Tests and helpers for consensus networking. +//! Tests and helpers for validation networking. -use consensus::NetworkService; +use validation::NetworkService; use substrate_network::{consensus_gossip::ConsensusMessage, Context as NetContext}; use substrate_primitives::{Ed25519AuthorityId, NativeOrEncoded}; use substrate_keyring::Keyring; use {PolkadotProtocol}; -use polkadot_consensus::{SharedTable, MessagesFrom, Network, TableRouter}; +use polkadot_validation::{SharedTable, MessagesFrom, Network, TableRouter}; use polkadot_primitives::{AccountId, Block, Hash, Header, BlockId}; use polkadot_primitives::parachain::{Id as ParaId, Chain, DutyRoster, ParachainHost, OutgoingMessage}; use parking_lot::Mutex; @@ -298,7 +298,7 @@ impl ParachainHost for RuntimeApi { } } -type TestConsensusNetwork = ::consensus::ConsensusNetwork< +type TestValidationNetwork = ::validation::ValidationNetwork< TestApi, NeverExit, TestNetwork, @@ -308,7 +308,7 @@ type TestConsensusNetwork = ::consensus::ConsensusNetwork< struct Built { gossip: GossipRouter, api_handle: Arc>, - networks: Vec, + networks: Vec, } fn build_network(n: usize, executor: TaskExecutor) -> Built { @@ -322,7 +322,7 @@ fn build_network(n: usize, executor: TaskExecutor) -> Built { gossip: gossip_handle.clone(), }); - TestConsensusNetwork::new( + TestValidationNetwork::new( net, NeverExit, runtime_api.clone(), @@ -356,7 +356,7 @@ impl IngressBuilder { let mut map = HashMap::new(); for ((source, target), messages) in self.egress { map.entry(target).or_insert_with(Vec::new) - .push((source, polkadot_consensus::message_queue_root(&messages))); + .push((source, polkadot_validation::message_queue_root(&messages))); } for roots in map.values_mut() { @@ -372,7 +372,7 @@ fn make_table(data: &ApiData, local_key: &Keyring, parent_hash: Hash) -> Arc = data.validators.iter().map(|v| v.to_fixed_bytes().into()).collect(); - let (group_info, _) = ::polkadot_consensus::make_group_info( + let (group_info, _) = ::polkadot_validation::make_group_info( DutyRoster { validator_duty: data.duties.clone() }, &authorities, local_key.to_raw_public().into() diff --git a/network/src/consensus.rs b/network/src/validation.rs similarity index 86% rename from network/src/consensus.rs rename to network/src/validation.rs index 3f62995aff30f..bbd08a54bcafe 100644 --- a/network/src/consensus.rs +++ b/network/src/validation.rs @@ -14,14 +14,14 @@ // You should have received a copy of the GNU General Public License // along with Polkadot. If not, see . -//! The "consensus" networking code built on top of the base network service. +//! The "validation session" networking code built on top of the base network service. //! -//! This fulfills the `polkadot_consensus::Network` trait, providing a hook to be called -//! each time consensus begins on a new chain head. +//! This fulfills the `polkadot_validation::Network` trait, providing a hook to be called +//! each time a validation session begins on a new chain head. use sr_primitives::traits::ProvideRuntimeApi; use substrate_network::{consensus_gossip::ConsensusMessage, Context as NetContext}; -use polkadot_consensus::{Network as ParachainNetwork, SharedTable, Collators, Statement, GenericStatement}; +use polkadot_validation::{Network as ParachainNetwork, SharedTable, Collators, Statement, GenericStatement}; use polkadot_primitives::{AccountId, Block, Hash, SessionKey}; use polkadot_primitives::parachain::{Id as ParaId, Collation, Extrinsic, ParachainHost, BlockData}; use codec::Decode; @@ -53,7 +53,7 @@ impl Executor for WrappedExecutor { fn spawn + Send + 'static>(&self, f: F) { if let Err(e) = self.0.execute(Box::new(f)) { - warn!(target: "consensus", "could not spawn consensus task: {:?}", e); + warn!(target: "validation", "could not spawn consensus task: {:?}", e); } } } @@ -128,11 +128,11 @@ impl MessageProcessTask where T: Clone + Executor + Send + 'static, { fn process_message(&self, msg: ConsensusMessage) -> Option> { - use polkadot_consensus::SignedStatement; + use polkadot_validation::SignedStatement; - debug!(target: "consensus", "Processing consensus statement for live consensus"); + debug!(target: "validation", "Processing validation statement for live session"); if let Some(statement) = SignedStatement::decode(&mut msg.as_slice()) { - if ::polkadot_consensus::check_statement( + if ::polkadot_validation::check_statement( &statement.statement, &statement.signature, statement.sender, @@ -171,23 +171,23 @@ impl Future for MessageProcessTask where } /// Wrapper around the network service -pub struct ConsensusNetwork { +pub struct ValidationNetwork { network: Arc, api: Arc

, executor: T, exit: E, } -impl ConsensusNetwork { - /// Create a new consensus networking object. +impl ValidationNetwork { + /// Create a new validation session networking object. pub fn new(network: Arc, exit: E, api: Arc

, executor: T) -> Self { - ConsensusNetwork { network, exit, api, executor } + ValidationNetwork { network, exit, api, executor } } } -impl Clone for ConsensusNetwork { +impl Clone for ValidationNetwork { fn clone(&self) -> Self { - ConsensusNetwork { + ValidationNetwork { network: self.network.clone(), exit: self.exit.clone(), api: self.api.clone(), @@ -197,7 +197,7 @@ impl Clone for ConsensusNetwork { } /// A long-lived network which can create parachain statement routing processes on demand. -impl ParachainNetwork for ConsensusNetwork where +impl ParachainNetwork for ValidationNetwork where P: ProvideRuntimeApi + Send + Sync + 'static, P::Api: ParachainHost, E: Clone + Future + Send + 'static, @@ -209,7 +209,7 @@ impl ParachainNetwork for ConsensusNetwork where fn communication_for( &self, table: Arc, - outgoing: polkadot_consensus::Outgoing, + outgoing: polkadot_validation::Outgoing, ) -> Self::TableRouter { let parent_hash = table.consensus_parent_hash().clone(); @@ -238,7 +238,7 @@ impl ParachainNetwork for ConsensusNetwork where let inner_stream = self.network.gossip_messages_for(attestation_topic); self.network .with_spec(move |spec, ctx| { - spec.new_consensus(ctx, parent_hash, CurrentConsensus { + spec.new_validation_session(ctx, parent_hash, ValidationSession { knowledge, local_session_key, }); @@ -284,7 +284,7 @@ impl Future for AwaitingCollation { } } -impl Collators for ConsensusNetwork where +impl Collators for ValidationNetwork where P: ProvideRuntimeApi + Send + Sync + 'static, P::Api: ParachainHost, N: NetworkService, @@ -359,16 +359,16 @@ impl Knowledge { } } -/// A current consensus instance. -pub(crate) struct CurrentConsensus { +/// A current validation session instance. +pub(crate) struct ValidationSession { knowledge: Arc>, local_session_key: SessionKey, } -impl CurrentConsensus { +impl ValidationSession { #[cfg(test)] pub(crate) fn new(knowledge: Arc>, local_session_key: SessionKey) -> Self { - CurrentConsensus { + ValidationSession { knowledge, local_session_key } @@ -434,50 +434,50 @@ impl RecentSessionKeys { } } -/// Manages requests and session keys for live consensus instances. -pub(crate) struct LiveConsensusInstances { +/// Manages requests and keys for live validation session instances. +pub(crate) struct LiveValidationSessions { // recent local session keys. recent: RecentSessionKeys, - // live consensus instances, on `parent_hash`. - live_instances: HashMap, + // live validation session instances, on `parent_hash`. + live_instances: HashMap, } -impl LiveConsensusInstances { - /// Create a new `LiveConsensusInstances` +impl LiveValidationSessions { + /// Create a new `LiveValidationSessions` pub(crate) fn new() -> Self { - LiveConsensusInstances { + LiveValidationSessions { recent: Default::default(), live_instances: HashMap::new(), } } - /// Note new consensus session. If the used session key is new, + /// Note new validation session. If the used session key is new, /// it returns it to be broadcasted to peers. - pub(crate) fn new_consensus( + pub(crate) fn new_validation_session( &mut self, parent_hash: Hash, - consensus: CurrentConsensus, + session: ValidationSession, ) -> Option { - let inserted_key = self.recent.insert(consensus.local_session_key); + let inserted_key = self.recent.insert(session.local_session_key); let maybe_new = if let InsertedRecentKey::New(_) = inserted_key { - Some(consensus.local_session_key) + Some(session.local_session_key) } else { None }; - self.live_instances.insert(parent_hash, consensus); + self.live_instances.insert(parent_hash, session); maybe_new } - /// Remove consensus session. + /// Remove validation session. pub(crate) fn remove(&mut self, parent_hash: &Hash) { - if let Some(consensus) = self.live_instances.remove(parent_hash) { + if let Some(validation_session) = self.live_instances.remove(parent_hash) { let key_still_used = self.live_instances.values() - .any(|c| c.local_session_key == consensus.local_session_key); + .any(|c| c.local_session_key == validation_session.local_session_key); if !key_still_used { - self.recent.remove(&consensus.local_session_key) + self.recent.remove(&validation_session.local_session_key) } } } @@ -487,7 +487,7 @@ impl LiveConsensusInstances { self.recent.as_slice() } - /// Call a closure with block data from consensus session at parent hash. + /// Call a closure with block data from validation session at parent hash. /// /// This calls the closure with `Some(data)` where the session and data are live, /// `Err(Some(keys))` when the session is live but the data unknown, with a list of keys diff --git a/service/Cargo.toml b/service/Cargo.toml index 1fb76271a4c00..f73cdb18381c1 100644 --- a/service/Cargo.toml +++ b/service/Cargo.toml @@ -12,7 +12,7 @@ slog = "^2" tokio = "0.1.7" hex-literal = "0.1" polkadot-availability-store = { path = "../availability-store" } -polkadot-consensus = { path = "../consensus" } +polkadot-validation = { path = "../validation" } polkadot-primitives = { path = "../primitives" } polkadot-runtime = { path = "../runtime" } polkadot-executor = { path = "../executor" } diff --git a/service/src/lib.rs b/service/src/lib.rs index 5e88853891339..ac96a3b71fdd6 100644 --- a/service/src/lib.rs +++ b/service/src/lib.rs @@ -19,7 +19,7 @@ //! Polkadot service. Specialized wrapper over substrate service. extern crate polkadot_availability_store as av_store; -extern crate polkadot_consensus as consensus; +extern crate polkadot_validation as consensus; extern crate polkadot_primitives; extern crate polkadot_runtime; extern crate polkadot_executor; @@ -169,7 +169,7 @@ construct_service_factory! { FullComponents::::new(config, executor) } }, AuthoritySetup = { |mut service: Self::FullService, executor: TaskExecutor, key: Option>| { - use polkadot_network::consensus::ConsensusNetwork; + use polkadot_network::validation::ValidationNetwork; let (block_import, link_half) = service.config.custom.grandpa_import_setup.take() .expect("Link Half and Block Import are present for Full Services or setup failed before. qed"); @@ -211,8 +211,8 @@ construct_service_factory! { let client = service.client(); - // collator connections and consensus network both fulfilled by this - let consensus_network = ConsensusNetwork::new( + // collator connections and validation network both fulfilled by this + let validation_network = ValidationNetwork::new( service.network(), service.on_exit(), service.client(), @@ -220,8 +220,8 @@ construct_service_factory! { ); let proposer_factory = ::consensus::ProposerFactory::new( client.clone(), - consensus_network.clone(), - consensus_network, + validation_network.clone(), + validation_network, service.transaction_pool(), executor.clone(), key.clone(), diff --git a/consensus/Cargo.toml b/validation/Cargo.toml similarity index 97% rename from consensus/Cargo.toml rename to validation/Cargo.toml index f4404db705880..a5ac4601bf1fe 100644 --- a/consensus/Cargo.toml +++ b/validation/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "polkadot-consensus" +name = "polkadot-validation" version = "0.1.0" authors = ["Parity Technologies "] diff --git a/consensus/README.adoc b/validation/README.adoc similarity index 63% rename from consensus/README.adoc rename to validation/README.adoc index a3ac5f631c38c..699991c8afc26 100644 --- a/consensus/README.adoc +++ b/validation/README.adoc @@ -1,5 +1,5 @@ -= Polkadot Consensus += Polkadot Validation placeholder //TODO Write content :) diff --git a/consensus/src/attestation_service.rs b/validation/src/attestation_service.rs similarity index 94% rename from consensus/src/attestation_service.rs rename to validation/src/attestation_service.rs index 9ed584642ab77..74b67ed778d01 100644 --- a/consensus/src/attestation_service.rs +++ b/validation/src/attestation_service.rs @@ -88,7 +88,7 @@ fn prune_unneeded_availability

(client: Arc

, extrinsic_store: ExtrinsicStor }; if let Err(e) = extrinsic_store.candidates_finalized(parent_hash, candidate_hashes) { - warn!(target: "consensus", "Failed to prune unneeded available data: {:?}", e); + warn!(target: "validation", "Failed to prune unneeded available data: {:?}", e); } Ok(()) @@ -104,7 +104,7 @@ pub(crate) struct ServiceHandle { /// Create and start a new instance of the attestation service. pub(crate) fn start( client: Arc

, - parachain_consensus: Arc<::ParachainConsensus>, + parachain_validation: Arc<::ParachainValidation>, thread_pool: TaskExecutor, key: Arc, extrinsic_store: ExtrinsicStore, @@ -127,7 +127,7 @@ pub(crate) fn start( let mut runtime = LocalRuntime::new().expect("Could not create local runtime"); let notifications = { let client = client.clone(); - let consensus = parachain_consensus.clone(); + let validation = parachain_validation.clone(); let key = key.clone(); client.import_notification_stream() @@ -139,7 +139,7 @@ pub(crate) fn start( .authorities(&BlockId::hash(parent_hash)) .map_err(Into::into) .and_then(|authorities| { - consensus.get_or_instantiate( + validation.get_or_instantiate( parent_hash, notification.header.parent_hash().clone(), &authorities, @@ -148,7 +148,7 @@ pub(crate) fn start( }); if let Err(e) = res { - warn!("Unable to start parachain consensus on top of {:?}: {}", + warn!("Unable to start parachain validation on top of {:?}: {}", parent_hash, e); } } @@ -168,7 +168,7 @@ pub(crate) fn start( interval .for_each(move |_| match client.leaves() { Ok(leaves) => { - parachain_consensus.retain(|h| leaves.contains(h)); + parachain_validation.retain(|h| leaves.contains(h)); Ok(()) } Err(e) => { diff --git a/consensus/src/collation.rs b/validation/src/collation.rs similarity index 100% rename from consensus/src/collation.rs rename to validation/src/collation.rs diff --git a/consensus/src/dynamic_inclusion.rs b/validation/src/dynamic_inclusion.rs similarity index 100% rename from consensus/src/dynamic_inclusion.rs rename to validation/src/dynamic_inclusion.rs diff --git a/consensus/src/error.rs b/validation/src/error.rs similarity index 97% rename from consensus/src/error.rs rename to validation/src/error.rs index e3bdc3e6dfb2a..409017b8cbb0e 100644 --- a/consensus/src/error.rs +++ b/validation/src/error.rs @@ -14,7 +14,7 @@ // You should have received a copy of the GNU General Public License // along with Polkadot. If not, see . -//! Errors that can occur during the consensus process. +//! Errors that can occur during the validation process. use primitives::Ed25519AuthorityId as AuthorityId; use runtime_primitives::RuntimeString; diff --git a/consensus/src/evaluation.rs b/validation/src/evaluation.rs similarity index 100% rename from consensus/src/evaluation.rs rename to validation/src/evaluation.rs diff --git a/consensus/src/lib.rs b/validation/src/lib.rs similarity index 96% rename from consensus/src/lib.rs rename to validation/src/lib.rs index 0722675b42eb7..e6b10c6ea6dbc 100644 --- a/consensus/src/lib.rs +++ b/validation/src/lib.rs @@ -258,7 +258,7 @@ pub fn make_group_info( } /// Constructs parachain-agreement instances. -struct ParachainConsensus { +struct ParachainValidation { /// The client instance. client: Arc

, /// The backing network handle. @@ -274,7 +274,7 @@ struct ParachainConsensus { live_instances: Mutex>>, } -impl ParachainConsensus where +impl ParachainValidation where C: Collators + Send + 'static, N: Network, P: ProvideRuntimeApi + HeaderBackend + BlockBody + Send + Sync + 'static, @@ -316,11 +316,11 @@ impl ParachainConsensus where let outgoing: Vec<_> = { // extract all extrinsic data that we have and propagate to peers. - live_instances.get(&grandparent_hash).map(|parent_consensus| { + live_instances.get(&grandparent_hash).map(|parent_validation| { parent_candidates.iter().filter_map(|c| { let para_id = c.parachain_index; let hash = c.hash(); - parent_consensus.table.extrinsic_data(&hash).map(|ex| MessagesFrom { + parent_validation.table.extrinsic_data(&hash).map(|ex| MessagesFrom { from: para_id, messages: ex, }) @@ -341,7 +341,7 @@ impl ParachainConsensus where let active_parachains = self.client.runtime_api().active_parachains(&id)?; - debug!(target: "consensus", "Active parachains: {:?}", active_parachains); + debug!(target: "validation", "Active parachains: {:?}", active_parachains); let table = Arc::new(SharedTable::new(group_info, sign_with.clone(), parent_hash, self.extrinsic_store.clone())); let router = self.network.communication_for( @@ -369,7 +369,7 @@ impl ParachainConsensus where Ok(tracker) } - /// Retain consensus sessions matching predicate. + /// Retain validation sessions matching predicate. fn retain bool>(&self, mut pred: F) { self.live_instances.lock().retain(|k, _| pred(k)) } @@ -422,7 +422,7 @@ impl ParachainConsensus where router.local_candidate(collation.receipt, collation.block_data, extrinsic) } Err(e) => warn!( - target: "consensus", + target: "validation", "Failed to make collation data available: {:?}", e, ), @@ -431,7 +431,7 @@ impl ParachainConsensus where Ok(()) } Err(e) => { - warn!(target: "consensus", "Failed to collate candidate: {}", e); + warn!(target: "validation", "Failed to collate candidate: {}", e); Ok(()) } }); @@ -444,7 +444,7 @@ impl ParachainConsensus where } } -/// Parachain consensus for a single block. +/// Parachain validation for a single block. struct AttestationTracker { _drop_signal: Option, table: Arc, @@ -453,7 +453,7 @@ struct AttestationTracker { /// Polkadot proposer factory. pub struct ProposerFactory { - parachain_consensus: Arc>, + parachain_validation: Arc>, transaction_pool: Arc>, key: Arc, _service_handle: ServiceHandle, @@ -482,7 +482,7 @@ impl ProposerFactory where extrinsic_store: ExtrinsicStore, aura_slot_duration: SlotDuration, ) -> Self { - let parachain_consensus = Arc::new(ParachainConsensus { + let parachain_validation = Arc::new(ParachainValidation { client: client.clone(), network, collators, @@ -493,14 +493,14 @@ impl ProposerFactory where let service_handle = ::attestation_service::start( client, - parachain_consensus.clone(), + parachain_validation.clone(), thread_pool, key.clone(), extrinsic_store, ); ProposerFactory { - parachain_consensus, + parachain_validation, transaction_pool, key, _service_handle: service_handle, @@ -530,7 +530,7 @@ impl consensus::Environment for ProposerFactory consensus::Environment for ProposerFactory CreateProposal where for ready in self.transaction_pool.ready() { if Instant::now() > self.deadline { - debug!("Consensus deadline reached when pushing block transactions, proceeding with proposing."); + debug!("Validation deadline reached when pushing block transactions, proceeding with proposing."); break; } diff --git a/consensus/src/shared_table/includable.rs b/validation/src/shared_table/includable.rs similarity index 100% rename from consensus/src/shared_table/includable.rs rename to validation/src/shared_table/includable.rs diff --git a/consensus/src/shared_table/mod.rs b/validation/src/shared_table/mod.rs similarity index 99% rename from consensus/src/shared_table/mod.rs rename to validation/src/shared_table/mod.rs index 829ad76642748..7b1e057d6754c 100644 --- a/consensus/src/shared_table/mod.rs +++ b/validation/src/shared_table/mod.rs @@ -157,7 +157,7 @@ impl SharedTableInner { digest, ); - warn!(target: "consensus", "{}", message); + warn!(target: "validation", "{}", message); self.validated.insert(digest.clone(), ValidationWork::Error(message)); None } @@ -276,7 +276,7 @@ impl ParachainWork { match res { Ok(e) => Ok(e), Err(e) => { - debug!(target: "consensus", "Encountered bad collation: {}", e); + debug!(target: "validation", "Encountered bad collation: {}", e); Err(()) } } @@ -326,7 +326,7 @@ impl Future for PrimedParachainWork let candidate_hash = candidate.hash(); - debug!(target: "consensus", "Making validity statement about candidate {}: is_good? {:?}", + debug!(target: "validation", "Making validity statement about candidate {}: is_good? {:?}", candidate_hash, validation_res.is_ok()); let (validity_statement, result) = match validation_res {