Skip to content

Commit

Permalink
Rename polkadot-consensus -> polkadot-validation (paritytech#151)
Browse files Browse the repository at this point in the history
* Initial rename of consensus -> validation

* Rename crate imports

* network: rename consensus to validation

* network: rename consensus in comments and logs

* Grumbles

* Rename tests consensus -> validation
  • Loading branch information
ascjones authored and rphmeier committed Feb 21, 2019
1 parent f0d8daf commit 6088360
Show file tree
Hide file tree
Showing 21 changed files with 158 additions and 157 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
.wasm-binaries
polkadot/runtime/wasm/target/
**/._*
.idea
.vscode
polkadot.*
.DS_Store
62 changes: 31 additions & 31 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ members = [
"availability-store",
"cli",
"collator",
"consensus",
"erasure-coding",
"executor",
"network",
Expand All @@ -31,6 +30,7 @@ members = [
"service",
"statement-table",
"service",
"validation",

"test-parachains/adder",
"test-parachains/adder/collator",
Expand Down
2 changes: 1 addition & 1 deletion network/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
38 changes: 19 additions & 19 deletions network/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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;
Expand All @@ -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;

Expand All @@ -85,7 +85,7 @@ pub struct Status {

struct BlockDataRequest {
attempted_peers: HashSet<SessionKey>,
consensus_parent: Hash,
validation_session_parent: Hash,
candidate_hash: Hash,
block_data_hash: Hash,
sender: oneshot::Sender<BlockData>,
Expand Down Expand Up @@ -168,7 +168,7 @@ pub struct PolkadotProtocol {
collators: CollatorPool,
validators: HashMap<SessionKey, NodeIndex>,
local_collations: LocalCollations<Collation>,
live_consensus: LiveConsensusInstances,
live_validation_sessions: LiveValidationSessions,
in_flight: HashMap<(RequestId, NodeIndex), BlockDataRequest>,
pending: Vec<BlockDataRequest>,
extrinsic_store: Option<::av_store::Store>,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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<Block>,
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())
{
Expand All @@ -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<Block>) {
Expand All @@ -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());
Expand Down Expand Up @@ -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 {
Expand All @@ -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,
Expand Down Expand Up @@ -440,7 +440,7 @@ impl Specialization<Block> 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,
Expand Down Expand Up @@ -481,7 +481,7 @@ impl Specialization<Block> 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,
Expand Down
12 changes: 6 additions & 6 deletions network/src/router.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
Expand All @@ -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<Message>);
type IngressPairRef<'a> = (ParaId, &'a [Message]);
Expand Down Expand Up @@ -380,7 +380,7 @@ impl<P: ProvideRuntimeApi + Send, E, N, T> TableRouter for Router<P, E, N, T> wh
impl<P, E, N: NetworkService, T> Drop for Router<P, E, N, T> {
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);

{
Expand Down Expand Up @@ -481,7 +481,7 @@ impl<S> Future for ComputeIngress<S> where S: Stream<Item=IngressPair> {
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;
}

Expand Down Expand Up @@ -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();

Expand Down
Loading

0 comments on commit 6088360

Please sign in to comment.