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 59 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
44 changes: 41 additions & 3 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 @@ -64,6 +64,7 @@ members = [
"node/network/availability-recovery",
"node/network/collator-protocol",
"node/network/gossip-support",
"node/network/dispute-distribution",
"node/overseer",
"node/malus",
"node/primitives",
Expand Down
16 changes: 11 additions & 5 deletions node/core/dispute-coordinator/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,11 @@
use std::collections::HashSet;
use std::sync::Arc;

use polkadot_node_primitives::{CandidateVotes, SignedDisputeStatement};
use polkadot_node_primitives::{CandidateVotes, DISPUTE_WINDOW, SignedDisputeStatement};
use polkadot_node_subsystem::{
messages::{
DisputeCoordinatorMessage, ChainApiMessage, DisputeParticipationMessage,
ImportStatementsResult,
},
Subsystem, SubsystemContext, FromOverseer, OverseerSignal, SpawnedSubsystem,
SubsystemError,
Expand Down Expand Up @@ -60,10 +61,6 @@ mod tests;

const LOG_TARGET: &str = "parachain::dispute-coordinator";

// It would be nice to draw this from the chain state, but we have no tools for it right now.
// On Polkadot this is 1 day, and on Kusama it's 6 hours.
const DISPUTE_WINDOW: SessionIndex = 6;

struct State {
keystore: Arc<LocalKeystore>,
highest_session: Option<SessionIndex>,
Expand Down Expand Up @@ -131,6 +128,9 @@ pub enum Error {
#[error(transparent)]
Oneshot(#[from] oneshot::Canceled),

#[error("Oneshot send failed")]
OneshotSend,

#[error(transparent)]
Subsystem(#[from] SubsystemError),

Expand Down Expand Up @@ -301,6 +301,7 @@ async fn handle_incoming(
candidate_receipt,
session,
statements,
pending_confirmation,
} => {
handle_import_statements(
ctx,
Expand All @@ -312,6 +313,11 @@ async fn handle_incoming(
session,
statements,
).await?;
// TODO: Recover availability and report back unavailable data:
eskimor marked this conversation as resolved.
Show resolved Hide resolved
// /~https://github.com/paritytech/polkadot/issues/3399
eskimor marked this conversation as resolved.
Show resolved Hide resolved
pending_confirmation
.send(ImportStatementsResult::ValidImport)
.map_err(|_| Error::OneshotSend)?;
}
DisputeCoordinatorMessage::ActiveDisputes(rx) => {
let active_disputes = db::v1::load_active_disputes(store, &config.column_config())?
Expand Down
16 changes: 16 additions & 0 deletions node/core/dispute-coordinator/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,7 @@ fn conflicting_votes_lead_to_dispute_participation() {
false,
).await;

let (pending_confirmation, _confirmation_rx) = oneshot::channel();
virtual_overseer.send(FromOverseer::Communication {
msg: DisputeCoordinatorMessage::ImportStatements {
candidate_hash,
Expand All @@ -270,6 +271,7 @@ fn conflicting_votes_lead_to_dispute_participation() {
(valid_vote, ValidatorIndex(0)),
(invalid_vote, ValidatorIndex(1)),
],
pending_confirmation,
},
}).await;

Expand Down Expand Up @@ -310,6 +312,7 @@ fn conflicting_votes_lead_to_dispute_participation() {
assert_eq!(votes.invalid.len(), 1);
}

let (pending_confirmation, _confirmation_rx) = oneshot::channel();
virtual_overseer.send(FromOverseer::Communication {
msg: DisputeCoordinatorMessage::ImportStatements {
candidate_hash,
Expand All @@ -318,6 +321,7 @@ fn conflicting_votes_lead_to_dispute_participation() {
statements: vec![
(invalid_vote_2, ValidatorIndex(2)),
],
pending_confirmation,
},
}).await;

Expand Down Expand Up @@ -371,6 +375,7 @@ fn positive_votes_dont_trigger_participation() {
true,
).await;

let (pending_confirmation, _confirmation_rx) = oneshot::channel();
virtual_overseer.send(FromOverseer::Communication {
msg: DisputeCoordinatorMessage::ImportStatements {
candidate_hash,
Expand All @@ -379,6 +384,7 @@ fn positive_votes_dont_trigger_participation() {
statements: vec![
(valid_vote, ValidatorIndex(0)),
],
pending_confirmation,
},
}).await;

Expand All @@ -404,6 +410,7 @@ fn positive_votes_dont_trigger_participation() {
assert!(votes.invalid.is_empty());
}

let (pending_confirmation, _confirmation_rx) = oneshot::channel();
virtual_overseer.send(FromOverseer::Communication {
msg: DisputeCoordinatorMessage::ImportStatements {
candidate_hash,
Expand All @@ -412,6 +419,7 @@ fn positive_votes_dont_trigger_participation() {
statements: vec![
(valid_vote_2, ValidatorIndex(1)),
],
pending_confirmation,
},
}).await;

Expand Down Expand Up @@ -472,6 +480,7 @@ fn wrong_validator_index_is_ignored() {
false,
).await;

let (pending_confirmation, _confirmation_rx) = oneshot::channel();
virtual_overseer.send(FromOverseer::Communication {
msg: DisputeCoordinatorMessage::ImportStatements {
candidate_hash,
Expand All @@ -481,6 +490,7 @@ fn wrong_validator_index_is_ignored() {
(valid_vote, ValidatorIndex(1)),
(invalid_vote, ValidatorIndex(0)),
],
pending_confirmation,
},
}).await;

Expand Down Expand Up @@ -541,6 +551,7 @@ fn finality_votes_ignore_disputed_candidates() {
false,
).await;

let (pending_confirmation, _confirmation_rx) = oneshot::channel();
virtual_overseer.send(FromOverseer::Communication {
msg: DisputeCoordinatorMessage::ImportStatements {
candidate_hash,
Expand All @@ -550,6 +561,7 @@ fn finality_votes_ignore_disputed_candidates() {
(valid_vote, ValidatorIndex(0)),
(invalid_vote, ValidatorIndex(1)),
],
pending_confirmation,
},
}).await;
let _ = virtual_overseer.recv().await;
Expand Down Expand Up @@ -624,6 +636,7 @@ fn supermajority_valid_dispute_may_be_finalized() {
false,
).await;

let (pending_confirmation, _confirmation_rx) = oneshot::channel();
virtual_overseer.send(FromOverseer::Communication {
msg: DisputeCoordinatorMessage::ImportStatements {
candidate_hash,
Expand All @@ -633,6 +646,7 @@ fn supermajority_valid_dispute_may_be_finalized() {
(valid_vote, ValidatorIndex(0)),
(invalid_vote, ValidatorIndex(1)),
],
pending_confirmation,
},
}).await;

Expand All @@ -650,12 +664,14 @@ fn supermajority_valid_dispute_may_be_finalized() {
statements.push((vote, ValidatorIndex(i as _)));
};

let (pending_confirmation, _confirmation_rx) = oneshot::channel();
virtual_overseer.send(FromOverseer::Communication {
msg: DisputeCoordinatorMessage::ImportStatements {
candidate_hash,
candidate_receipt: candidate_receipt.clone(),
session,
statements,
pending_confirmation,
},
}).await;

Expand Down
1 change: 0 additions & 1 deletion node/network/availability-distribution/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ polkadot-subsystem-testhelpers = { package = "polkadot-node-subsystem-test-helpe
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"
Expand Down
11 changes: 5 additions & 6 deletions node/network/availability-distribution/src/pov_requester/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,8 @@
use futures::{FutureExt, channel::oneshot, future::BoxFuture};

use polkadot_subsystem::jaeger;
use polkadot_node_network_protocol::{
request_response::{OutgoingRequest, Recipient, request::{RequestError, Requests},
v1::{PoVFetchingRequest, PoVFetchingResponse}}
};
use polkadot_node_network_protocol::request_response::{OutgoingRequest, Recipient, request::{RequestError, Requests},
v1::{PoVFetchingRequest, PoVFetchingResponse}};
use polkadot_primitives::v1::{
CandidateHash, Hash, ValidatorIndex,
};
Expand All @@ -49,7 +47,7 @@ pub async fn fetch_pov<Context>(
where
Context: SubsystemContext,
{
let info = &runtime.get_session_info(ctx, parent).await?.session_info;
let info = &runtime.get_session_info(ctx.sender(), parent).await?.session_info;
let authority_id = info.discovery_keys.get(from_validator.0 as usize)
.ok_or(NonFatal::InvalidValidatorIndex)?
.clone();
Expand Down Expand Up @@ -131,10 +129,11 @@ mod tests {
use polkadot_node_primitives::BlockData;
use polkadot_subsystem_testhelpers as test_helpers;
use polkadot_subsystem::messages::{AvailabilityDistributionMessage, RuntimeApiMessage, RuntimeApiRequest};
use test_helpers::mock::make_ferdie_keystore;

use super::*;
use crate::LOG_TARGET;
use crate::tests::mock::{make_session_info, make_ferdie_keystore};
use crate::tests::mock::{make_session_info};

#[test]
fn rejects_invalid_pov() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ impl SessionCache {
Context: SubsystemContext,
F: FnOnce(&SessionInfo) -> R,
{
let session_index = runtime.get_session_index(ctx, parent).await?;
let session_index = runtime.get_session_index(ctx.sender(), parent).await?;

if let Some(o_info) = self.session_info_cache.get(&session_index) {
tracing::trace!(target: LOG_TARGET, session_index, "Got session from lru");
Expand Down Expand Up @@ -183,7 +183,7 @@ impl SessionCache {
where
Context: SubsystemContext,
{
let info = runtime.get_session_info_by_index(ctx, parent, session_index).await?;
let info = runtime.get_session_info_by_index(ctx.sender(), parent, session_index).await?;

let discovery_keys = info.session_info.discovery_keys.clone();
let mut validator_groups = info.session_info.validator_groups.clone();
Expand Down
18 changes: 2 additions & 16 deletions node/network/availability-distribution/src/tests/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,30 +19,16 @@

use std::sync::Arc;

use sc_keystore::LocalKeystore;
use sp_keyring::Sr25519Keyring;
use sp_application_crypto::AppKey;

use polkadot_erasure_coding::{branches, obtain_chunks_v1 as obtain_chunks};
use polkadot_primitives::v1::{
CandidateCommitments, CandidateDescriptor, CandidateHash,
CommittedCandidateReceipt, GroupIndex, Hash, HeadData, Id as ParaId,
OccupiedCore, PersistedValidationData, SessionInfo, ValidatorId, ValidatorIndex
OccupiedCore, PersistedValidationData, SessionInfo, ValidatorIndex
};
use polkadot_node_primitives::{PoV, ErasureChunk, AvailableData, BlockData};
use sp_keystore::{SyncCryptoStore, SyncCryptoStorePtr};

/// Get mock keystore with `Ferdie` key.
pub fn make_ferdie_keystore() -> SyncCryptoStorePtr {
let keystore: SyncCryptoStorePtr = Arc::new(LocalKeystore::in_memory());
SyncCryptoStore::sr25519_generate_new(
&*keystore,
ValidatorId::ID,
Some(&Sr25519Keyring::Ferdie.to_seed()),
)
.expect("Insert key into keystore");
keystore
}


/// Create dummy session info with two validator groups.
pub fn make_session_info() -> SessionInfo {
Expand Down
Loading