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

Commit

Permalink
votes_above_limit test
Browse files Browse the repository at this point in the history
  • Loading branch information
tdimitrov committed May 23, 2022
1 parent 46a6599 commit ea319f6
Showing 1 changed file with 63 additions and 18 deletions.
81 changes: 63 additions & 18 deletions node/core/provisioner/src/disputes/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -447,58 +447,58 @@ fn normal_flow() {
|r| mock_overseer(r, &mut disputes, &mut vote_queries),
|mut tx: TestSubsystemSender| async move {
let lf = leaf();
let disputes = select_disputes(&mut tx, &metrics, &lf).await.unwrap();
let selected_disputes = select_disputes(&mut tx, &metrics, &lf).await.unwrap();

assert!(!disputes.is_empty());
assert!(!selected_disputes.is_empty());

if cfg!(feature = "staging-client") {
assert_eq!(disputes.len(), 4 * DISPUTES_PER_BATCH);
assert_eq!(selected_disputes.len(), 4 * DISPUTES_PER_BATCH);
for i in 0..DISPUTES_PER_BATCH {
assert_eq!(disputes.get(i).unwrap().session, first_idx);
assert_eq!(selected_disputes.get(i).unwrap().session, first_idx);
}
for i in DISPUTES_PER_BATCH..2 * DISPUTES_PER_BATCH {
assert_eq!(disputes.get(i).unwrap().session, second_idx);
assert_eq!(selected_disputes.get(i).unwrap().session, second_idx);
}
for i in 2 * DISPUTES_PER_BATCH..3 * DISPUTES_PER_BATCH {
assert_eq!(disputes.get(i).unwrap().session, third_idx);
assert_eq!(selected_disputes.get(i).unwrap().session, third_idx);
}
for i in 3 * DISPUTES_PER_BATCH..4 * DISPUTES_PER_BATCH {
assert_eq!(disputes.get(i).unwrap().session, fifth_idx);
assert_eq!(selected_disputes.get(i).unwrap().session, fifth_idx);
}

assert_eq!(
disputes[0..DISPUTES_PER_BATCH]
selected_disputes[0..DISPUTES_PER_BATCH]
.iter()
.map(|d| d.statements.len())
.fold(0, |acc, v| acc + v),
first_votes
);
assert_eq!(
disputes[DISPUTES_PER_BATCH..2 * DISPUTES_PER_BATCH]
selected_disputes[DISPUTES_PER_BATCH..2 * DISPUTES_PER_BATCH]
.iter()
.map(|d| d.statements.len())
.fold(0, |acc, v| acc + v),
second_votes
);
assert_eq!(
disputes[2 * DISPUTES_PER_BATCH..3 * DISPUTES_PER_BATCH]
selected_disputes[2 * DISPUTES_PER_BATCH..3 * DISPUTES_PER_BATCH]
.iter()
.map(|d| d.statements.len())
.fold(0, |acc, v| acc + v),
third_votes
);
assert_eq!(
disputes[3 * DISPUTES_PER_BATCH..4 * DISPUTES_PER_BATCH]
selected_disputes[3 * DISPUTES_PER_BATCH..4 * DISPUTES_PER_BATCH]
.iter()
.map(|d| d.statements.len())
.fold(0, |acc, v| acc + v),
fifth_votes
);
} else {
assert_eq!(disputes.len(), 5 * DISPUTES_PER_BATCH);
assert_eq!(selected_disputes.len(), 5 * DISPUTES_PER_BATCH);
for i in 0..3 * DISPUTES_PER_BATCH {
assert_ne!(disputes.get(i).unwrap().session, fourth_idx);
assert_ne!(disputes.get(i).unwrap().session, fifth_idx);
assert_ne!(selected_disputes.get(i).unwrap().session, fourth_idx);
assert_ne!(selected_disputes.get(i).unwrap().session, fifth_idx);
}
}
},
Expand Down Expand Up @@ -536,11 +536,11 @@ fn many_batches() {
|r| mock_overseer(r, &mut disputes, &mut vote_queries),
|mut tx: TestSubsystemSender| async move {
let lf = leaf();
let disputes = select_disputes(&mut tx, &metrics, &lf).await.unwrap();
let selected_disputes = select_disputes(&mut tx, &metrics, &lf).await.unwrap();

assert!(!disputes.is_empty());
assert!(!selected_disputes.is_empty());

let vote_count = disputes.iter().map(|d| d.statements.len()).fold(0, |acc, v| acc + v);
let vote_count = selected_disputes.iter().map(|d| d.statements.len()).fold(0, |acc, v| acc + v);

assert!(
MAX_DISPUTE_VOTES_FORWARDED_TO_RUNTIME - VALIDATOR_COUNT <= vote_count &&
Expand All @@ -560,4 +560,49 @@ fn many_batches() {
}

#[test]
fn votes_above_limit() {}
fn votes_above_limit() {
const VALIDATOR_COUNT: usize = 100;
const DISPUTES_PER_PARTITION: usize = 5_000;
const ACCEPTABLE_RUNTIME_VOTES_QUERIES_COUNT: usize = 4;

let mut disputes = TestDisputes::new(VALIDATOR_COUNT);

// active which can conclude onchain
let (_, second_votes) = disputes.add_active_disputes_which_can_conclude_onchain(DISPUTES_PER_PARTITION);

// active which can't conclude onchain
let (_, first_votes) = disputes.add_active_disputes_which_cant_conclude_onchain(DISPUTES_PER_PARTITION);

//concluded disputes unknown onchain
let (_, third_votes) = disputes.add_concluded_disputes_unknown_onchain(DISPUTES_PER_PARTITION);

assert!(first_votes + second_votes + third_votes > 3 * MAX_DISPUTE_VOTES_FORWARDED_TO_RUNTIME, "Total relevant votes generated: {}", first_votes + second_votes + third_votes);

let metrics = metrics::Metrics::new_dummy();
let mut vote_queries: usize = 0;
test_harness(
|r| mock_overseer(r, &mut disputes, &mut vote_queries),
|mut tx: TestSubsystemSender| async move {
let lf = leaf();
let selected_disputes = select_disputes(&mut tx, &metrics, &lf).await.unwrap();

assert!(!selected_disputes.is_empty());

let vote_count = selected_disputes.iter().map(|d| d.statements.len()).fold(0, |acc, v| acc + v);

assert!(
MAX_DISPUTE_VOTES_FORWARDED_TO_RUNTIME - VALIDATOR_COUNT <= vote_count &&
vote_count <= MAX_DISPUTE_VOTES_FORWARDED_TO_RUNTIME,
"vote_count: {}",
vote_count
);
},
);

assert!(
vote_queries <= ACCEPTABLE_RUNTIME_VOTES_QUERIES_COUNT,
"vote_queries: {} ACCEPTABLE_RUNTIME_VOTES_QUERIES_COUNT: {}",
vote_queries,
ACCEPTABLE_RUNTIME_VOTES_QUERIES_COUNT
);
}

0 comments on commit ea319f6

Please sign in to comment.