Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

parse quorum sets #14

Draft
wants to merge 29 commits into
base: qs-equality
Choose a base branch
from
Draft
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
69 changes: 69 additions & 0 deletions Cargo.lock

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

2 changes: 2 additions & 0 deletions consensus/scp/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ mc-util-metrics = { path = "../../util/metrics" }
mc-util-serial = { path = "../../util/serial", features = ["std"] }

bigint = "4.4"
pest = "2.0"
pest_derive = "2.0"
rand = "0.7"
rand_hc = "0.2"
serde = { version = "1.0", default-features = false, features = ["alloc", "derive"] }
Expand Down
5 changes: 4 additions & 1 deletion consensus/scp/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
#![feature(external_doc)]
#![doc(include = "../README.md")]
#![allow(non_snake_case)]
#![deny(missing_docs)]

// missing_docs is broken for macros
// https://github.com/rust-lang/rust/issues/59306
// #![deny(missing_docs)]

pub mod core_types;
pub mod msg;
Expand Down
4 changes: 2 additions & 2 deletions consensus/scp/src/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -319,14 +319,14 @@ mod tests {
// A two-node network, where the only quorum is both nodes.
let mut node1 = Node::<u32, TransactionValidationError>::new(
test_node_id(1),
QuorumSet::new_with_node_ids(1, vec![test_node_id(2)]),
quorum_set_from_str("([1],2)"),
Arc::new(trivial_validity_fn),
Arc::new(trivial_combine_fn),
logger.clone(),
);
let mut node2 = Node::<u32, TransactionValidationError>::new(
test_node_id(2),
QuorumSet::new_with_node_ids(1, vec![test_node_id(1)]),
quorum_set_from_str("([1],1)"),
Arc::new(trivial_validity_fn),
Arc::new(trivial_combine_fn),
logger.clone(),
Expand Down
209 changes: 30 additions & 179 deletions consensus/scp/src/predicates.rs
Original file line number Diff line number Diff line change
Expand Up @@ -231,60 +231,23 @@ impl<'a, V: Value, ID: GenericNodeId> Predicate<V, ID> for FuncPredicate<'a, V,
#[cfg(test)]
mod predicates_tests {
use super::*;
use crate::{core_types::*, msg::*, quorum_set::*, test_utils::test_node_id};
use crate::{
core_types::*,
msg::*,
test_utils::{quorum_set_from_str, test_node_id},
};
use mc_common::HashMap;
use std::iter::FromIterator;

#[test]
// BallotSetPredicate can be used to pick a quorum that intersects with a given set of ballots.
pub fn test_ballot_set_predicate_quorum() {
let local_node_id = test_node_id(1);
let local_node_quorum_set = QuorumSet::new_with_node_ids(
2,
vec![
test_node_id(2),
test_node_id(3),
test_node_id(4),
test_node_id(5),
],
);

let node_2_quorum_set = QuorumSet::new_with_node_ids(
1,
vec![
test_node_id(1),
test_node_id(3),
test_node_id(4),
test_node_id(5),
],
);
let node_3_quorum_set = QuorumSet::new_with_node_ids(
1,
vec![
test_node_id(1),
test_node_id(2),
test_node_id(4),
test_node_id(5),
],
);
let node_4_quorum_set = QuorumSet::new_with_node_ids(
1,
vec![
test_node_id(1),
test_node_id(2),
test_node_id(3),
test_node_id(5),
],
);
let node_5_quorum_set = QuorumSet::new_with_node_ids(
1,
vec![
test_node_id(1),
test_node_id(2),
test_node_id(3),
test_node_id(4),
],
);
let local_node_quorum_set = quorum_set_from_str("([2],2,3,4,5)");
let node_2_quorum_set = quorum_set_from_str("([1],1,3,4,5)");
let node_3_quorum_set = quorum_set_from_str("([1],1,2,4,5)");
let node_4_quorum_set = quorum_set_from_str("([1],1,2,3,5)");
let node_5_quorum_set = quorum_set_from_str("([1],1,2,3,4)");

let ballot_1 = Ballot::new(1, &[1111]);
let ballot_2 = Ballot::new(1, &[2222]);
Expand Down Expand Up @@ -351,26 +314,11 @@ mod predicates_tests {
// BallotSetPredicate can be used to pick a blocking set that intersects with a given set of ballots.
pub fn test_ballot_set_predicate_blocking_set() {
// Node 2 and 3 form a blocking set. Node 5 and 6 also form a blocking set.
let local_node_quorum_set: QuorumSet = {
let inner_quorum_set_one = QuorumSet::new_with_node_ids(
2,
vec![test_node_id(2), test_node_id(3), test_node_id(4)],
);
let inner_quorum_set_two = QuorumSet::new_with_node_ids(
2,
vec![test_node_id(5), test_node_id(6), test_node_id(7)],
);
QuorumSet::new_with_inner_sets(2, vec![inner_quorum_set_one, inner_quorum_set_two])
};

let node_2_quorum_set =
QuorumSet::new_with_node_ids(1, vec![test_node_id(3), test_node_id(4)]);
let node_3_quorum_set =
QuorumSet::new_with_node_ids(1, vec![test_node_id(2), test_node_id(4)]);
let node_5_quorum_set =
QuorumSet::new_with_node_ids(1, vec![test_node_id(6), test_node_id(7)]);
let node_6_quorum_set =
QuorumSet::new_with_node_ids(1, vec![test_node_id(5), test_node_id(7)]);
let local_node_quorum_set = quorum_set_from_str("([2],([2],2,3,4),([2],5,6,7))");
let node_2_quorum_set = quorum_set_from_str("([1],3,4)");
let node_3_quorum_set = quorum_set_from_str("([1],2,4)");
let node_5_quorum_set = quorum_set_from_str("([1],6,7)");
let node_6_quorum_set = quorum_set_from_str("([1],5,7)");

let ballot_1 = Ballot::new(1, &[1111]);
let ballot_2 = Ballot::new(1, &[2222]);
Expand Down Expand Up @@ -436,52 +384,11 @@ mod predicates_tests {
// ValueSetPredicate can be used to pick a set of values that has reached quorum.
pub fn test_value_set_predicate_quorum() {
let local_node_id = test_node_id(1);
let local_node_quorum_set = QuorumSet::new_with_node_ids(
2,
vec![
test_node_id(2),
test_node_id(3),
test_node_id(4),
test_node_id(5),
],
);

let node_2_quorum_set = QuorumSet::new_with_node_ids(
1,
vec![
test_node_id(1),
test_node_id(3),
test_node_id(4),
test_node_id(5),
],
);
let node_3_quorum_set = QuorumSet::new_with_node_ids(
1,
vec![
test_node_id(1),
test_node_id(2),
test_node_id(4),
test_node_id(5),
],
);
let node_4_quorum_set = QuorumSet::new_with_node_ids(
1,
vec![
test_node_id(1),
test_node_id(2),
test_node_id(3),
test_node_id(5),
],
);
let node_5_quorum_set = QuorumSet::new_with_node_ids(
1,
vec![
test_node_id(1),
test_node_id(2),
test_node_id(3),
test_node_id(4),
],
);
let local_node_quorum_set = quorum_set_from_str("([2],2,3,4,5)");
let node_2_quorum_set = quorum_set_from_str("([1],1,3,4,5)");
let node_3_quorum_set = quorum_set_from_str("([1],1,2,4,5)");
let node_4_quorum_set = quorum_set_from_str("([1],1,2,3,5)");
let node_5_quorum_set = quorum_set_from_str("([1],1,2,3,4)");

let values_1 = BTreeSet::from_iter(vec!["a".to_string(), "A".to_string()]);
let values_2 = BTreeSet::from_iter(vec!["b".to_string(), "B".to_string()]);
Expand Down Expand Up @@ -544,26 +451,11 @@ mod predicates_tests {
// ValueSetPredicate can be used to pick a set values that has reached blocking threshold.
pub fn test_value_set_predicate_blocking_set() {
// Node 2 and 3 form a blocking set. Node 5 and 6 also form a blocking set.
let local_node_quorum_set: QuorumSet = {
let inner_quorum_set_one = QuorumSet::new_with_node_ids(
2,
vec![test_node_id(2), test_node_id(3), test_node_id(4)],
);
let inner_quorum_set_two = QuorumSet::new_with_node_ids(
2,
vec![test_node_id(5), test_node_id(6), test_node_id(7)],
);
QuorumSet::new_with_inner_sets(2, vec![inner_quorum_set_one, inner_quorum_set_two])
};

let node_2_quorum_set =
QuorumSet::new_with_node_ids(1, vec![test_node_id(3), test_node_id(4)]);
let node_3_quorum_set =
QuorumSet::new_with_node_ids(1, vec![test_node_id(2), test_node_id(4)]);
let node_5_quorum_set =
QuorumSet::new_with_node_ids(1, vec![test_node_id(6), test_node_id(7)]);
let node_6_quorum_set =
QuorumSet::new_with_node_ids(1, vec![test_node_id(5), test_node_id(7)]);
let local_node_quorum_set = quorum_set_from_str("([2],([2],2,3,4),([2],5,6,7))");
let node_2_quorum_set = quorum_set_from_str("([1],3,4)");
let node_3_quorum_set = quorum_set_from_str("([1],2,4)");
let node_5_quorum_set = quorum_set_from_str("([1],6,7)");
let node_6_quorum_set = quorum_set_from_str("([1],5,7)");

let values_1 = BTreeSet::from_iter(vec!["a".to_string(), "A".to_string()]);
let values_2 = BTreeSet::from_iter(vec!["b".to_string(), "B".to_string()]);
Expand Down Expand Up @@ -625,52 +517,11 @@ mod predicates_tests {
// MinMaxPredicate can be used to narrow down min and max CN/HN values in a quorum.
pub fn test_quorum_min_max_predicate() {
let local_node_id = test_node_id(1);
let local_node_quorum_set = QuorumSet::new_with_node_ids(
2,
vec![
test_node_id(2),
test_node_id(3),
test_node_id(4),
test_node_id(5),
],
);

let node_2_quorum_set = QuorumSet::new_with_node_ids(
1,
vec![
test_node_id(1),
test_node_id(3),
test_node_id(4),
test_node_id(5),
],
);
let node_3_quorum_set = QuorumSet::new_with_node_ids(
1,
vec![
test_node_id(1),
test_node_id(2),
test_node_id(4),
test_node_id(5),
],
);
let node_4_quorum_set = QuorumSet::new_with_node_ids(
1,
vec![
test_node_id(1),
test_node_id(2),
test_node_id(3),
test_node_id(5),
],
);
let node_5_quorum_set = QuorumSet::new_with_node_ids(
1,
vec![
test_node_id(1),
test_node_id(2),
test_node_id(3),
test_node_id(4),
],
);
let local_node_quorum_set = quorum_set_from_str("([2],2,3,4,5)");
let node_2_quorum_set = quorum_set_from_str("([1],1,3,4,5)");
let node_3_quorum_set = quorum_set_from_str("([1],1,2,4,5)");
let node_4_quorum_set = quorum_set_from_str("([1],1,2,3,5)");
let node_5_quorum_set = quorum_set_from_str("([1],1,2,3,4)");

let ballot_1 = Ballot::new(1, &["a".to_string(), "A".to_string()]);
let ballot_2 = Ballot::new(1, &["b".to_string(), "B".to_string()]);
Expand Down
Loading