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

Dispute distribution implementation #3282

Merged
merged 67 commits into from
Jul 9, 2021
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
Show all changes
67 commits
Select commit Hold shift + click to select a range
8c83835
Dispute protocol.
eskimor Jun 14, 2021
125dd32
Dispute distribution protocol.
eskimor Jun 15, 2021
2c395e5
Get network requests routed.
eskimor Jun 15, 2021
7c53c69
WIP: Basic dispute sender logic.
eskimor Jun 15, 2021
0bd8713
Basic validator determination logic.
eskimor Jun 15, 2021
608f84c
WIP: Getting things to typecheck.
eskimor Jun 15, 2021
a78fbc9
Slightly larger timeout.
eskimor Jun 15, 2021
53f0c15
More typechecking stuff.
eskimor Jun 16, 2021
6abf1f3
Cleanup.
eskimor Jun 16, 2021
b541062
Finished most of the sending logic.
eskimor Jun 17, 2021
5883c08
Handle active leaves updates
eskimor Jun 17, 2021
4c4e3a7
Pass sessions in already.
eskimor Jun 17, 2021
bd8bb95
Startup dispute sending.
eskimor Jun 17, 2021
4ebe127
Provide incoming decoding facilities
eskimor Jun 18, 2021
95351bd
Relaxed runtime util requirements.
eskimor Jun 18, 2021
863b1d9
Better usability of incoming requests.
eskimor Jun 18, 2021
35d2cad
Add basic receiver functionality.
eskimor Jun 18, 2021
da8abac
Cleanup + fixes for sender.
eskimor Jun 18, 2021
c997aed
One more sender fix.
eskimor Jun 18, 2021
06770db
Start receiver.
eskimor Jun 18, 2021
2378c7e
Make sure to send responses back.
eskimor Jun 19, 2021
3910cf4
WIP: Exposed authority discovery
eskimor Jun 21, 2021
840a046
Merge branch 'master' into rk-dispute-distribution-impl
eskimor Jun 21, 2021
5b10c78
Make tests pass.
eskimor Jun 21, 2021
d2aa4ff
Fully featured receiver.
eskimor Jun 21, 2021
da4955d
Decrease cost of `NotAValidator`.
eskimor Jun 22, 2021
1fc9740
Make `RuntimeInfo` LRU cache size configurable.
eskimor Jun 22, 2021
9397e35
Cache more sessions.
eskimor Jun 22, 2021
ccbab3f
Fix collator protocol.
eskimor Jun 22, 2021
5db60d3
Disable metrics for now.
eskimor Jun 22, 2021
da20774
Make dispute-distribution a proper subsystem.
eskimor Jun 22, 2021
f9da3ae
Fix naming.
eskimor Jun 22, 2021
2231dc3
Code style fixes.
eskimor Jun 23, 2021
41c2801
Factored out 4x copied mock function.
eskimor Jun 23, 2021
3e91427
WIP: Tests.
eskimor Jun 23, 2021
8a3da18
Whitespace cleanup.
eskimor Jun 24, 2021
0b188cd
Accessor functions.
eskimor Jun 24, 2021
2637c1b
More testing.
eskimor Jun 24, 2021
3d09d48
More Debug instances.
eskimor Jun 25, 2021
def8772
Fix busy loop.
eskimor Jun 25, 2021
c7cdca9
Working tests.
eskimor Jun 29, 2021
b9f20c2
More tests.
eskimor Jun 30, 2021
6f7da40
Merge branch 'master' into rk-dispute-distribution-impl
eskimor Jun 30, 2021
b3c7427
Cleanup.
eskimor Jun 30, 2021
c01d8d1
Fix build.
eskimor Jun 30, 2021
4f616d6
Basic receiving test.
eskimor Jun 30, 2021
a3ff6ae
Non validator message gets dropped.
eskimor Jun 30, 2021
217bd7e
More receiving tests.
eskimor Jun 30, 2021
26b8b00
Test nested and subsequent imports.
eskimor Jun 30, 2021
5dd7c84
Fix spaces.
eskimor Jun 30, 2021
488fb47
Better formatted imports.
eskimor Jun 30, 2021
92ff4be
Import cleanup.
eskimor Jul 1, 2021
7d5f416
Metrics.
eskimor Jul 2, 2021
04f91e9
Message -> MuxedMessage
eskimor Jul 2, 2021
d43fb5f
Message -> MuxedMessage
eskimor Jul 2, 2021
dc6d0f1
Merge branch 'master' into rk-dispute-distribution-impl
eskimor Jul 2, 2021
fc6a612
More review remarks.
eskimor Jul 2, 2021
2907a53
Add missing metrics.rs.
eskimor Jul 2, 2021
1f7ce88
Fix flaky test.
eskimor Jul 2, 2021
cd66550
Dispute coordinator - deliver confirmations.
eskimor Jul 6, 2021
fd920a1
Send out `DisputeMessage` on issue local statement.
eskimor Jul 6, 2021
90b46f4
Merge branch 'master' into rk-dispute-distribution-impl
eskimor Jul 8, 2021
210b853
Unwire dispute distribution.
eskimor Jul 8, 2021
58b1bee
Review remarks.
eskimor Jul 8, 2021
59c76c8
Review remarks.
eskimor Jul 8, 2021
3cd91cb
Better docs.
eskimor Jul 8, 2021
dedbaa8
Merge branch 'master' into rk-dispute-distribution-impl
eskimor Jul 8, 2021
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
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ members = [
"node/network/availability-recovery",
"node/network/collator-protocol",
"node/network/gossip-support",
"node/network/dispute-distribution",
"node/overseer",
"node/primitives",
"node/service",
Expand Down
8 changes: 8 additions & 0 deletions node/network/bridge/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ use parity_scale_codec::{Encode, Decode};
use parking_lot::Mutex;
use futures::prelude::*;
use futures::stream::BoxStream;
use polkadot_subsystem::messages::DisputeDistributionMessage;
use sc_network::Event as NetworkEvent;
use sp_consensus::SyncOracle;

Expand Down Expand Up @@ -852,6 +853,10 @@ where
.get_statement_fetching()
.expect("Gets initialized, must be `Some` on startup. qed.");

let dispute_receiver = request_multiplexer
.get_dispute_sending()
.expect("Gets initialized, must be `Some` on startup. qed.");

let (remote, network_event_handler) = handle_network_messages(
ctx.sender().clone(),
network_service.clone(),
Expand All @@ -867,6 +872,9 @@ where
ctx.send_message(AllMessages::StatementDistribution(
StatementDistributionMessage::StatementFetchingReceiver(statement_receiver)
)).await;
ctx.send_message(AllMessages::DisputeDistribution(
DisputeDistributionMessage::DisputeSendingReceiver(dispute_receiver)
)).await;

let subsystem_event_handler = handle_subsystem_messages(
ctx,
Expand Down
25 changes: 24 additions & 1 deletion node/network/bridge/src/multiplexer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ use polkadot_subsystem::messages::AllMessages;
pub struct RequestMultiplexer {
receivers: Vec<(Protocol, mpsc::Receiver<network::IncomingRequest>)>,
statement_fetching: Option<mpsc::Receiver<network::IncomingRequest>>,
dispute_sending: Option<mpsc::Receiver<network::IncomingRequest>>,
next_poll: usize,
}

Expand All @@ -68,19 +69,31 @@ impl RequestMultiplexer {
})
.unzip();

// Ok this code is ugly as hell, it is also a hack, see #2842. But it works and is executed
eskimor marked this conversation as resolved.
Show resolved Hide resolved
// on startup so, if anything is wrong here it will be noticed immediately.
let index = receivers.iter().enumerate().find_map(|(i, (p, _))|
if let Protocol::StatementFetching = p {
Some(i)
} else {
None
}
).expect("Statement fetching must be registered. qed.");
).expect("Statement fetching must be registered.");
eskimor marked this conversation as resolved.
Show resolved Hide resolved
let statement_fetching = Some(receivers.remove(index).1);

let index = receivers.iter().enumerate().find_map(|(i, (p, _))|
if let Protocol::DisputeSending = p {
Some(i)
} else {
None
}
).expect("Dispute sending must be registered.");
eskimor marked this conversation as resolved.
Show resolved Hide resolved
eskimor marked this conversation as resolved.
Show resolved Hide resolved
let dispute_sending = Some(receivers.remove(index).1);

(
Self {
receivers,
statement_fetching,
dispute_sending,
next_poll: 0,
},
cfgs,
Expand All @@ -93,6 +106,13 @@ impl RequestMultiplexer {
pub fn get_statement_fetching(&mut self) -> Option<mpsc::Receiver<network::IncomingRequest>> {
std::mem::take(&mut self.statement_fetching)
}

/// Get the receiver for handling dispute sending requests.
///
/// This function will only return `Some` once.
pub fn get_dispute_sending(&mut self) -> Option<mpsc::Receiver<network::IncomingRequest>> {
std::mem::take(&mut self.dispute_sending)
}
}

impl Stream for RequestMultiplexer {
Expand Down Expand Up @@ -174,6 +194,9 @@ fn multiplex_single(
Protocol::StatementFetching => {
panic!("Statement fetching requests are handled directly. qed.");
}
Protocol::DisputeSending => {
panic!("Dispute sending request are handled directly. qed.");
eskimor marked this conversation as resolved.
Show resolved Hide resolved
}
};
Ok(r)
}
Expand Down
35 changes: 35 additions & 0 deletions node/network/dispute-distribution/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
[package]
name = "polkadot-dispute-distribution"
version = "0.1.0"
authors = ["Parity Technologies <admin@parity.io>"]
edition = "2018"

[dependencies]
futures = "0.3.15"
tracing = "0.1.26"
parity-scale-codec = { version = "2.0.0", features = ["std"] }
polkadot-primitives = { path = "../../../primitives" }
polkadot-erasure-coding = { path = "../../../erasure-coding" }
polkadot-subsystem = { package = "polkadot-node-subsystem", path = "../../subsystem" }
polkadot-node-network-protocol = { path = "../../network/protocol" }
polkadot-node-subsystem-util = { path = "../../subsystem-util" }
polkadot-node-primitives = { path = "../../primitives" }
polkadot-node-core-runtime-api = { path = "../../core/runtime-api" }
sp-application-crypto = { git = "/~https://github.com/paritytech/substrate", branch = "master" }
sp-core = { git = "/~https://github.com/paritytech/substrate", branch = "master", features = ["std"] }
sp-keystore = { git = "/~https://github.com/paritytech/substrate", branch = "master" }
thiserror = "1.0.23"
rand = "0.8.3"
lru = "0.6.5"

[dev-dependencies]
polkadot-subsystem-testhelpers = { package = "polkadot-node-subsystem-test-helpers", path = "../../subsystem-test-helpers" }
sp-core = { git = "/~https://github.com/paritytech/substrate", branch = "master", features = ["std"] }
sp-keyring = { git = "/~https://github.com/paritytech/substrate", branch = "master" }
sp-tracing = { git = "/~https://github.com/paritytech/substrate", branch = "master" }
sc-keystore = { git = "/~https://github.com/paritytech/substrate", branch = "master" }
sc-network = {git = "/~https://github.com/paritytech/substrate", branch = "master" }
futures-timer = "3.0.2"
assert_matches = "1.4.0"
maplit = "1.0"
smallvec = "1.6.1"
104 changes: 104 additions & 0 deletions node/network/dispute-distribution/src/error.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
// Copyright 2021 Parity Technologies (UK) Ltd.
// This file is part of Polkadot.

// Polkadot is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.

// Polkadot is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License
// along with Polkadot. If not, see <http://www.gnu.org/licenses/>.
//

//! Error handling related code and Error/Result definitions.

use thiserror::Error;

use polkadot_node_subsystem_util::{Fault, runtime, unwrap_non_fatal};
use polkadot_subsystem::SubsystemError;

use crate::LOG_TARGET;
use crate::sender;

#[derive(Debug, Error)]
#[error(transparent)]
pub struct Error(pub Fault<NonFatal, Fatal>);
eskimor marked this conversation as resolved.
Show resolved Hide resolved

impl From<NonFatal> for Error {
fn from(e: NonFatal) -> Self {
Self(Fault::from_non_fatal(e))
}
}

impl From<Fatal> for Error {
fn from(f: Fatal) -> Self {
Self(Fault::from_fatal(f))
}
}

impl From<sender::Error> for Error {
fn from(e: sender::Error) -> Self {
match e.0 {
Fault::Fatal(f) => Self(Fault::Fatal(Fatal::Sender(f))),
Fault::Err(nf) => Self(Fault::Err(NonFatal::Sender(nf))),
}
}
}

/// Fatal errors of this subsystem.
#[derive(Debug, Error)]
pub enum Fatal {

/// Receiving subsystem message from overseer failed.
#[error("Receiving message from overseer failed")]
SubsystemReceive(#[source] SubsystemError),

/// Spawning a running task failed.
#[error("Spawning subsystem task failed")]
SpawnTask(#[source] SubsystemError),

/// DisputeSender mpsc receiver exhausted.
#[error("Erasure chunk requester stream exhausted")]
SenderExhausted,

#[error("Receive channel closed")]
IncomingMessageChannel(#[source] SubsystemError),

/// Errors coming from runtime::Runtime.
#[error("Error while accessing runtime information")]
Runtime(#[from] #[source] runtime::Fatal),

/// Errors coming from DisputeSender
#[error("Error while accessing runtime information")]
Sender(#[from] #[source] sender::Fatal),
}

/// Non-fatal errors of this subsystem.
#[derive(Debug, Error)]
pub enum NonFatal {
/// Errors coming from DisputeSender
#[error("Error while accessing runtime information")]
Sender(#[from] #[source] sender::NonFatal),
}

pub type Result<T> = std::result::Result<T, Error>;

pub type FatalResult<T> = std::result::Result<T, Fatal>;

/// Utility for eating top level errors and log them.
///
/// We basically always want to try and continue on error. This utility function is meant to
/// consume top-level errors by simply logging them
pub fn log_error(result: Result<()>, ctx: &'static str)
-> std::result::Result<(), Fatal>
{
if let Some(error) = unwrap_non_fatal(result.map_err(|e| e.0))? {
tracing::warn!(target: LOG_TARGET, error = ?error, ctx);
}
Ok(())
}
Loading