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

Dispute Coordinator: Move to batch Request - Response model #3447

Closed
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
1 change: 1 addition & 0 deletions Cargo.lock

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

23 changes: 13 additions & 10 deletions node/core/dispute-coordinator/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -437,18 +437,21 @@ async fn handle_incoming(
let _ = rx.send(collect_active(recent_disputes, now));
}
DisputeCoordinatorMessage::QueryCandidateVotes(
session,
candidate_hash,
query,
rx
) => {
let candidate_votes = db::v1::load_candidate_votes(
store,
&config.column_config(),
session,
&candidate_hash,
)?;

let _ = rx.send(candidate_votes.map(Into::into));
let mut query_output = Vec::new();
for (session_index, candidate_hash) in query.into_iter() {
if let Some(v) = db::v1::load_candidate_votes(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be better to fail the request if any of the votes aren't present. As such, the zip done in the provisioner is inaccurate.

store,
&config.column_config(),
session_index,
&candidate_hash,
)? {
query_output.push(v.into());
}
}
let _ = rx.send(query_output);
}
DisputeCoordinatorMessage::IssueLocalStatement(
session,
Expand Down
25 changes: 10 additions & 15 deletions node/core/dispute-coordinator/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -326,13 +326,12 @@ fn conflicting_votes_lead_to_dispute_participation() {
let (tx, rx) = oneshot::channel();
virtual_overseer.send(FromOverseer::Communication {
msg: DisputeCoordinatorMessage::QueryCandidateVotes(
session,
candidate_hash,
vec![(session, candidate_hash)],
tx,
),
}).await;

let votes = rx.await.unwrap().unwrap();
let votes = rx.await.unwrap().get(0).unwrap().clone();
assert_eq!(votes.valid.len(), 1);
assert_eq!(votes.invalid.len(), 1);
}
Expand All @@ -352,13 +351,12 @@ fn conflicting_votes_lead_to_dispute_participation() {
let (tx, rx) = oneshot::channel();
virtual_overseer.send(FromOverseer::Communication {
msg: DisputeCoordinatorMessage::QueryCandidateVotes(
session,
candidate_hash,
vec![(session, candidate_hash)],
tx,
),
}).await;

let votes = rx.await.unwrap().unwrap();
let votes = rx.await.unwrap().get(0).unwrap().clone();
assert_eq!(votes.valid.len(), 1);
assert_eq!(votes.invalid.len(), 2);
}
Expand Down Expand Up @@ -420,13 +418,12 @@ fn positive_votes_dont_trigger_participation() {
let (tx, rx) = oneshot::channel();
virtual_overseer.send(FromOverseer::Communication {
msg: DisputeCoordinatorMessage::QueryCandidateVotes(
session,
candidate_hash,
vec![(session, candidate_hash)],
tx,
),
}).await;

let votes = rx.await.unwrap().unwrap();
let votes = rx.await.unwrap().get(0).unwrap().clone();
assert_eq!(votes.valid.len(), 1);
assert!(votes.invalid.is_empty());
}
Expand All @@ -453,13 +450,12 @@ fn positive_votes_dont_trigger_participation() {
let (tx, rx) = oneshot::channel();
virtual_overseer.send(FromOverseer::Communication {
msg: DisputeCoordinatorMessage::QueryCandidateVotes(
session,
candidate_hash,
vec![(session, candidate_hash)],
tx,
),
}).await;

let votes = rx.await.unwrap().unwrap();
let votes = rx.await.unwrap().get(0).unwrap().clone();
assert_eq!(votes.valid.len(), 2);
assert!(votes.invalid.is_empty());
}
Expand Down Expand Up @@ -522,13 +518,12 @@ fn wrong_validator_index_is_ignored() {
let (tx, rx) = oneshot::channel();
virtual_overseer.send(FromOverseer::Communication {
msg: DisputeCoordinatorMessage::QueryCandidateVotes(
session,
candidate_hash,
vec![(session, candidate_hash)],
tx,
),
}).await;

let votes = rx.await.unwrap().unwrap();
let votes = rx.await.unwrap().get(0).unwrap().clone();
assert!(votes.valid.is_empty());
assert!(votes.invalid.is_empty());
}
Expand Down
1 change: 1 addition & 0 deletions node/core/provisioner/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ futures = "0.3.15"
tracing = "0.1.26"
thiserror = "1.0.23"
polkadot-primitives = { path = "../../../primitives" }
polkadot-node-primitives = { path = "../../primitives" }
polkadot-node-subsystem = { path = "../../subsystem" }
polkadot-node-subsystem-util = { path = "../../subsystem-util" }
futures-timer = "3.0.2"
Expand Down
43 changes: 11 additions & 32 deletions node/core/provisioner/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,9 @@ use polkadot_node_subsystem_util::{
use polkadot_primitives::v1::{
BackedCandidate, BlockNumber, CandidateReceipt, CoreState, Hash, OccupiedCoreAssumption,
SignedAvailabilityBitfield, ValidatorIndex, MultiDisputeStatementSet, DisputeStatementSet,
DisputeStatement,
DisputeStatement, SessionIndex, CandidateHash,
};
use polkadot_node_primitives::CandidateVotes;
use std::{pin::Pin, collections::BTreeMap, sync::Arc};
use thiserror::Error;
use futures_timer::Delay;
Expand Down Expand Up @@ -567,38 +568,16 @@ async fn select_disputes(
};

// Load all votes for all disputes from the coordinator.
let dispute_candidate_votes = {
let mut awaited_votes = FuturesOrdered::new();

let n_disputes = recent_disputes.len();
for (session_index, candidate_hash) in recent_disputes {
let (tx, rx) = oneshot::channel();
sender.send_message(DisputeCoordinatorMessage::QueryCandidateVotes(
session_index,
candidate_hash,
tx,
).into()).await;

awaited_votes.push(async move {
rx.await
.map_err(Error::CanceledCandidateVotes)
.map(|maybe_votes| maybe_votes.map(|v| (session_index, candidate_hash, v)))
});
}

// Sadly `StreamExt::collect` requires `Default`, so we have to do this more
// manually.
let mut vote_sets = Vec::with_capacity(n_disputes);
while let Some(res) = awaited_votes.next().await {
// sanity check - anything present in recent disputes should have
// candidate votes. but we might race with block import on
// session boundaries.
if let Some(vote_set) = res? {
vote_sets.push(vote_set);
}
}
let dispute_candidate_votes: Vec<_> = {
let (tx, rx) = oneshot::channel();
sender.send_message(DisputeCoordinatorMessage::QueryCandidateVotes(
recent_disputes.clone(),
tx,
).into()).await;

vote_sets
rx.await.unwrap_or_default().into_iter().zip(recent_disputes.into_iter())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd like a debug! log as done above

.map(|(vote, (session_index, candidate_hash))| (session_index, candidate_hash, vote))
.collect::<Vec<(SessionIndex, CandidateHash, CandidateVotes)>>()
};

// Transform all `CandidateVotes` into `MultiDisputeStatementSet`.
Expand Down
2 changes: 1 addition & 1 deletion node/subsystem/src/messages.rs
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ pub enum DisputeCoordinatorMessage {
/// These disputes are either unconcluded or recently concluded.
ActiveDisputes(oneshot::Sender<Vec<(SessionIndex, CandidateHash)>>),
/// Get candidate votes for a candidate.
QueryCandidateVotes(SessionIndex, CandidateHash, oneshot::Sender<Option<CandidateVotes>>),
QueryCandidateVotes(Vec<(SessionIndex, CandidateHash)>, oneshot::Sender<Vec<CandidateVotes>>),
/// Sign and issue local dispute votes. A value of `true` indicates validity, and `false` invalidity.
IssueLocalStatement(SessionIndex, CandidateHash, CandidateReceipt, bool),
/// Determine the highest undisputed block within the given chain, based on where candidates
Expand Down