Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

implement statement gossip subsystem #1301

Closed
wants to merge 18 commits into from
Closed
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
27 changes: 27 additions & 0 deletions Cargo.lock

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

3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,13 @@ members = [
"validation",

"node/messages",
"node/network/statement-distribution",
"node/overseer",
"node/primitives",
"node/service",

"node/network/bridge",

"parachain/test-parachains",
"parachain/test-parachains/adder",
"parachain/test-parachains/adder/collator",
Expand Down
49 changes: 29 additions & 20 deletions node/messages/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,18 @@

use futures::channel::{mpsc, oneshot};

use sc_network::{ObservedRole, ReputationChange, PeerId, config::ProtocolId};
use sc_network::{ObservedRole, PeerId};
use polkadot_primitives::{BlockNumber, Hash, Signature};
use polkadot_primitives::parachain::{
AbridgedCandidateReceipt, PoVBlock, ErasureChunk, BackedCandidate, Id as ParaId,
SignedAvailabilityBitfield, SigningContext, ValidatorId, ValidationCode, ValidatorIndex,
};
use polkadot_node_primitives::{
MisbehaviorReport, SignedFullStatement,
MisbehaviorReport, ProtocolId, SignedFullStatement, View,
};

pub type Bytes = Vec<u8>;

/// Signals sent by an overseer to a subsystem.
#[derive(PartialEq, Clone, Debug)]
pub enum OverseerSignal {
Expand Down Expand Up @@ -90,42 +92,42 @@ pub enum CandidateValidationMessage {
),
}

/// Chain heads.
///
/// Up to `N` (5?) chain heads.
pub struct View(pub Vec<Hash>);

/// Events from network.
#[derive(Debug, Clone)]
pub enum NetworkBridgeEvent {
/// A peer has connected.
/// A peer with given ID is now connected.
PeerConnected(PeerId, ObservedRole),

/// A peer has disconnected.
/// A peer with given ID is now disconnected.
PeerDisconnected(PeerId),

/// Peer has sent a message.
PeerMessage(PeerId, Vec<u8>),
/// We received a message from the given peer. Protocol ID should be apparent from context.
PeerMessage(PeerId, Bytes),

/// Peer's `View` has changed.
/// The given peer has updated its description of its view.
///
/// This is guaranteed to come after the `PeerConnected` event for a given peer.
PeerViewChange(PeerId, View),

/// Our `View` has changed.
/// We have posted the given view update to all connected peers.
OurViewChange(View),
}

/// Messages received by the network bridge subsystem.
pub enum NetworkBridgeSubsystemMessage {
/// Register an event producer on startup.
RegisterEventProducer(ProtocolId, fn(NetworkBridgeEvent) -> AllMessages),
pub enum NetworkBridgeMessage {
/// Register an event producer with the network bridge. This should be done early and cannot
/// be de-registered.
RegisterEventProducer(ProtocolId, Box<dyn Fn(NetworkBridgeEvent) -> AllMessages>),

/// Report a peer for their actions.
ReportPeer(PeerId, ReputationChange),
/// Report a cost or benefit of a peer. Negative values are costs, positive are benefits.
ReportPeer(PeerId, i32),

/// Send a message to multiple peers.
SendMessage(Vec<PeerId>, ProtocolId, Vec<u8>),
/// Send a message to one or more peers on the given protocol ID.
SendMessage(Vec<PeerId>, ProtocolId, Bytes),
}

/// Availability Distribution Message.
#[derive(Debug)]
pub enum AvailabilityDistributionMessage {
/// Distribute an availability chunk to other validators.
DistributeChunk(Hash, ErasureChunk),
Expand All @@ -138,6 +140,7 @@ pub enum AvailabilityDistributionMessage {
}

/// Bitfield distribution message.
#[derive(Debug)]
pub enum BitfieldDistributionMessage {
/// Distribute a bitfield via gossip to other validators.
DistributeBitfield(Hash, SignedAvailabilityBitfield),
Expand All @@ -147,6 +150,7 @@ pub enum BitfieldDistributionMessage {
}

/// Availability store subsystem message.
#[derive(Debug)]
pub enum AvailabilityStoreMessage {
/// Query a `PoVBlock` from the AV store.
QueryPoV(Hash, oneshot::Sender<Option<PoVBlock>>),
Expand All @@ -159,6 +163,7 @@ pub enum AvailabilityStoreMessage {
}

/// A request to the Runtime API subsystem.
#[derive(Debug)]
pub enum RuntimeApiRequest {
/// Get the current validator set.
Validators(oneshot::Sender<Vec<ValidatorId>>),
Expand All @@ -171,19 +176,22 @@ pub enum RuntimeApiRequest {
}

/// A message to the Runtime API subsystem.
#[derive(Debug)]
pub enum RuntimeApiMessage {
/// Make a request of the runtime API against the post-state of the given relay-parent.
Request(Hash, RuntimeApiRequest),
}

/// Statement distribution message.
#[derive(Debug)]
pub enum StatementDistributionMessage {
/// We have originated a signed statement in the context of
/// given relay-parent hash and it should be distributed to other validators.
Share(Hash, SignedFullStatement),
}

/// This data becomes intrinsics or extrinsics which should be included in a future relay chain block.
#[derive(Debug)]
pub enum ProvisionableData {
/// This bitfield indicates the availability of various candidate blocks.
Bitfield(Hash, SignedAvailabilityBitfield),
Expand All @@ -198,6 +206,7 @@ pub enum ProvisionableData {
/// Message to the Provisioner.
///
/// In all cases, the Hash is that of the relay parent.
#[derive(Debug)]
pub enum ProvisionerMessage {
/// This message allows potential block authors to be kept updated with all new authorship data
/// as it becomes available.
Expand Down
18 changes: 18 additions & 0 deletions node/network/bridge/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
[package]
name = "polkadot-network-bridge"
version = "0.1.0"
authors = ["Parity Technologies <[email protected]>"]
edition = "2018"

[dependencies]
futures = "0.3.5"
log = "0.4.8"
futures-timer = "3.0.2"
streamunordered = "0.5.1"
polkadot-primitives = { path = "../../../primitives" }
node-primitives = { package = "polkadot-node-primitives", path = "../../primitives" }
messages = { package = "polkadot-node-messages", path = "../../messages" }
parity-scale-codec = "1.3.0"
overseer = { package = "polkadot-overseer", path = "../../overseer" }
sc-network = { git = "https://github.com/paritytech/substrate", branch = "master" }
sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "master" }
Loading