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

Only report concluded if there is an actual dispute. #6270

Merged
merged 4 commits into from
Nov 14, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Merge branch 'master' into rk-fix-onesided-disputes
  • Loading branch information
eskimor committed Nov 14, 2022
commit b5030244f62b95c86752f6592e10d16e208cc9cb
1 change: 0 additions & 1 deletion Cargo.lock

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

1 change: 0 additions & 1 deletion node/core/dispute-coordinator/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ assert_matches = "1.4.0"
test-helpers = { package = "polkadot-primitives-test-helpers", path = "../../../primitives/test-helpers" }
futures-timer = "3.0.2"
sp-application-crypto = { git = "https://github.com/paritytech/substrate", branch = "master" }
sp-tracing = { git = "https://github.com/paritytech/substrate", branch = "master" }

[features]
# If not enabled, the dispute coordinator will do nothing.
Expand Down
198 changes: 195 additions & 3 deletions node/core/dispute-coordinator/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2920,7 +2920,6 @@ fn redundant_votes_ignored() {
#[test]
/// Make sure no disputes are recorded when there are no opposing votes, even if we reached supermajority.
fn no_onesided_disputes() {
sp_tracing::try_init_simple();
test_harness(|mut test_state, mut virtual_overseer| {
Box::pin(async move {
let session = 1;
Expand All @@ -2929,8 +2928,9 @@ fn no_onesided_disputes() {

let candidate_receipt = make_valid_candidate_receipt();
let candidate_hash = candidate_receipt.hash();

test_state.activate_leaf_at_session(&mut virtual_overseer, session, 1).await;
test_state
.activate_leaf_at_session(&mut virtual_overseer, session, 1, Vec::new())
.await;

let mut statements = Vec::new();
for index in 1..10 {
Expand Down Expand Up @@ -2978,3 +2978,195 @@ fn no_onesided_disputes() {
})
});
}

#[test]
fn refrain_from_participation() {
test_harness(|mut test_state, mut virtual_overseer| {
Box::pin(async move {
let session = 1;

test_state.handle_resume_sync(&mut virtual_overseer, session).await;

let candidate_receipt = make_valid_candidate_receipt();
let candidate_hash = candidate_receipt.hash();

// activate leaf - no backing/included event
test_state
.activate_leaf_at_session(&mut virtual_overseer, session, 1, Vec::new())
.await;

// generate two votes
let valid_vote = test_state
.issue_explicit_statement_with_index(
ValidatorIndex(1),
candidate_hash,
session,
true,
)
.await;

let invalid_vote = test_state
.issue_explicit_statement_with_index(
ValidatorIndex(2),
candidate_hash,
session,
false,
)
.await;

virtual_overseer
.send(FromOrchestra::Communication {
msg: DisputeCoordinatorMessage::ImportStatements {
candidate_receipt: candidate_receipt.clone(),
session,
statements: vec![
(valid_vote, ValidatorIndex(1)),
(invalid_vote, ValidatorIndex(2)),
],
pending_confirmation: None,
},
})
.await;

handle_approval_vote_request(&mut virtual_overseer, &candidate_hash, HashMap::new())
.await;

{
let (tx, rx) = oneshot::channel();
virtual_overseer
.send(FromOrchestra::Communication {
msg: DisputeCoordinatorMessage::ActiveDisputes(tx),
})
.await;

assert_eq!(rx.await.unwrap().len(), 1);

let (tx, rx) = oneshot::channel();
virtual_overseer
.send(FromOrchestra::Communication {
msg: DisputeCoordinatorMessage::QueryCandidateVotes(
vec![(session, candidate_hash)],
tx,
),
})
.await;

let (_, _, votes) = rx.await.unwrap().get(0).unwrap().clone();
assert_eq!(votes.valid.len(), 1);
assert_eq!(votes.invalid.len(), 1);
}

// activate leaf - no backing event
test_state
.activate_leaf_at_session(&mut virtual_overseer, session, 1, Vec::new())
.await;

virtual_overseer.send(FromOrchestra::Signal(OverseerSignal::Conclude)).await;

// confirm that no participation request is made.
assert!(virtual_overseer.try_recv().await.is_none());

test_state
})
});
}

/// We have got no `participation_for_backed_candidates` test because most of the other tests (e.g.
/// `dispute_gets_confirmed_via_participation`, `backing_statements_import_works_and_no_spam`) use
/// candidate backing event to trigger participation. If they pass - that case works.
#[test]
fn participation_for_included_candidates() {
test_harness(|mut test_state, mut virtual_overseer| {
Box::pin(async move {
let session = 1;

test_state.handle_resume_sync(&mut virtual_overseer, session).await;

let candidate_receipt = make_valid_candidate_receipt();
let candidate_hash = candidate_receipt.hash();

// activate leaf - with candidate included event
test_state
.activate_leaf_at_session(
&mut virtual_overseer,
session,
1,
vec![make_candidate_included_event(candidate_receipt.clone())],
)
.await;

// generate two votes
let valid_vote = test_state
.issue_explicit_statement_with_index(
ValidatorIndex(1),
candidate_hash,
session,
true,
)
.await;

let invalid_vote = test_state
.issue_explicit_statement_with_index(
ValidatorIndex(2),
candidate_hash,
session,
false,
)
.await;

virtual_overseer
.send(FromOrchestra::Communication {
msg: DisputeCoordinatorMessage::ImportStatements {
candidate_receipt: candidate_receipt.clone(),
session,
statements: vec![
(valid_vote, ValidatorIndex(1)),
(invalid_vote, ValidatorIndex(2)),
],
pending_confirmation: None,
},
})
.await;

handle_approval_vote_request(&mut virtual_overseer, &candidate_hash, HashMap::new())
.await;

participation_with_distribution(
&mut virtual_overseer,
&candidate_hash,
candidate_receipt.commitments_hash,
)
.await;

{
let (tx, rx) = oneshot::channel();
virtual_overseer
.send(FromOrchestra::Communication {
msg: DisputeCoordinatorMessage::ActiveDisputes(tx),
})
.await;

assert_eq!(rx.await.unwrap().len(), 1);

// check if we have participated (casted a vote)
let (tx, rx) = oneshot::channel();
virtual_overseer
.send(FromOrchestra::Communication {
msg: DisputeCoordinatorMessage::QueryCandidateVotes(
vec![(session, candidate_hash)],
tx,
),
})
.await;

let (_, _, votes) = rx.await.unwrap().get(0).unwrap().clone();
assert_eq!(votes.valid.len(), 2); // 2 => we have participated
assert_eq!(votes.invalid.len(), 1);
}

virtual_overseer.send(FromOrchestra::Signal(OverseerSignal::Conclude)).await;

test_state
})
});
}
You are viewing a condensed version of this merge commit. You can view the full changes here.