Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ members = [
"substrate/client",
"substrate/client/db",
"substrate/codec",
"substrate/codec/derive",
"substrate/environmental",
"substrate/executor",
"substrate/extrinsic-pool",
Expand Down
19 changes: 16 additions & 3 deletions demo/runtime/wasm/Cargo.lock

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

Binary file not shown.
Binary file not shown.
1 change: 1 addition & 0 deletions polkadot/network/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ polkadot-consensus = { path = "../consensus" }
polkadot-primitives = { path = "../primitives" }
substrate-bft = { path = "../../substrate/bft" }
substrate-codec = { path = "../../substrate/codec" }
substrate-codec-derive = { path = "../../substrate/codec/derive" }
substrate-network = { path = "../../substrate/network" }
substrate-primitives = { path = "../../substrate/primitives" }
ed25519 = { path = "../../substrate/ed25519" }
Expand Down
19 changes: 1 addition & 18 deletions polkadot/network/src/collator_pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

use polkadot_primitives::{AccountId, Hash};
use polkadot_primitives::parachain::{Id as ParaId, Collation};
use codec;

use futures::sync::oneshot;

Expand All @@ -28,30 +27,14 @@ use std::time::{Duration, Instant};
const COLLATION_LIFETIME: Duration = Duration::from_secs(60 * 5);

/// The role of the collator. Whether they're the primary or backup for this parachain.
#[derive(PartialEq, Debug, Clone, Copy)]
#[derive(PartialEq, Debug, Clone, Copy, Encode, Decode)]
pub enum Role {
/// Primary collators should send collations whenever it's time.
Primary = 0,
/// Backup collators should not.
Backup = 1,
}

impl codec::Encode for Role {
fn encode_to<T: codec::Output>(&self, dest: &mut T) {
dest.push_byte(*self as u8);
}
}

impl codec::Decode for Role {
fn decode<I: codec::Input>(input: &mut I) -> Option<Self> {
match input.read_byte()? {
x if x == Role::Primary as u8 => Some(Role::Primary),
x if x == Role::Backup as u8 => Some(Role::Backup),
_ => None,
}
}
}

/// A maintenance action for the collator set.
#[derive(PartialEq, Debug)]
#[allow(dead_code)]
Expand Down
86 changes: 5 additions & 81 deletions polkadot/network/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,15 @@ extern crate rhododendron;

#[macro_use]
extern crate log;
#[macro_use]
extern crate substrate_codec_derive;

mod collator_pool;
mod local_collations;
mod router;
pub mod consensus;

use codec::{Decode, Encode, Input, Output};
use codec::{Decode, Encode};
use futures::sync::oneshot;
use parking_lot::Mutex;
use polkadot_consensus::{Statement, SignedStatement, GenericStatement};
Expand Down Expand Up @@ -74,36 +76,11 @@ type FullStatus = GenericFullStatus<Block>;
pub type NetworkService = ::substrate_network::Service<Block, PolkadotProtocol>;

/// Status of a Polkadot node.
#[derive(Debug, PartialEq, Eq, Clone)]
#[derive(Debug, PartialEq, Eq, Clone, Encode, Decode)]
pub struct Status {
collating_for: Option<(AccountId, ParaId)>,
}

impl Encode for Status {
fn encode_to<T: codec::Output>(&self, dest: &mut T) {
match self.collating_for {
Some(ref details) => {
dest.push_byte(1);
dest.push(details);
}
None => {
dest.push_byte(0);
}
}
}
}

impl Decode for Status {
fn decode<I: codec::Input>(input: &mut I) -> Option<Self> {
let collating_for = match input.read_byte()? {
0 => None,
1 => Some(Decode::decode(input)?),
_ => return None,
};
Some(Status { collating_for })
}
}

struct BlockDataRequest {
attempted_peers: HashSet<SessionKey>,
consensus_parent: Hash,
Expand Down Expand Up @@ -207,7 +184,7 @@ impl CurrentConsensus {
}

/// Polkadot-specific messages.
#[derive(Debug)]
#[derive(Debug, Encode, Decode)]
pub enum Message {
/// signed statement and localized parent hash.
Statement(Hash, SignedStatement),
Expand All @@ -224,59 +201,6 @@ pub enum Message {
Collation(Hash, Collation),
}

impl Encode for Message {
fn encode_to<T: Output>(&self, dest: &mut T) {
match *self {
Message::Statement(ref h, ref s) => {
dest.push_byte(0);
dest.push(h);
dest.push(s);
}
Message::SessionKey(ref k) => {
dest.push_byte(1);
dest.push(k);
}
Message::RequestBlockData(ref id, ref r, ref d) => {
dest.push_byte(2);
dest.push(id);
dest.push(r);
dest.push(d);
}
Message::BlockData(ref id, ref d) => {
dest.push_byte(3);
dest.push(id);
dest.push(d);
}
Message::CollatorRole(ref r) => {
dest.push_byte(4);
dest.push(r);
}
Message::Collation(ref h, ref c) => {
dest.push_byte(5);
dest.push(h);
dest.push(c);
}
}
}
}

impl Decode for Message {
fn decode<I: Input>(input: &mut I) -> Option<Self> {
match input.read_byte()? {
0 => Some(Message::Statement(Decode::decode(input)?, Decode::decode(input)?)),
1 => Some(Message::SessionKey(Decode::decode(input)?)),
2 => {
let x: (_, _, _) = Decode::decode(input)?;
Some(Message::RequestBlockData(x.0, x.1, x.2))
}
3 => Some(Message::BlockData(Decode::decode(input)?, Decode::decode(input)?)),
4 => Some(Message::CollatorRole(Decode::decode(input)?)),
5 => Some(Message::Collation(Decode::decode(input)?, Decode::decode(input)?)),
_ => None,
}
}
}

fn send_polkadot_message(ctx: &mut Context<Block>, to: NodeIndex, message: Message) {
trace!(target: "p_net", "Sending polkadot message to {}: {:?}", to, message);
let encoded = message.encode();
Expand Down
1 change: 1 addition & 0 deletions polkadot/parachain/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ description = "Types and utilities for creating and working with parachains"

[dependencies]
substrate-codec = { path = "../../substrate/codec", default-features = false }
substrate-codec-derive = { path = "../../substrate/codec/derive", default-features = false }
wasmi = { version = "0.4", optional = true }
error-chain = { version = "0.12", optional = true }

Expand Down
Loading