Skip to content

Commit

Permalink
Merge pull request ProvableHQ#2201 from AleoHQ/feat/min-committee
Browse files Browse the repository at this point in the history
Fix the minimum committee size
  • Loading branch information
howardwu authored Nov 28, 2023
2 parents 31d0bb5 + 4690056 commit afb38c5
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 8 deletions.
8 changes: 3 additions & 5 deletions ledger/committee/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,16 +52,14 @@ impl<N: Network> Committee<N> {

/// Initializes a new `Committee` instance.
pub fn new_genesis(members: IndexMap<Address<N>, (u64, bool)>) -> Result<Self> {
// Ensure there are exactly 4 members.
ensure!(members.len() == 4, "Genesis committee must have 4 members");
// Return the new committee.
Self::new(0u64, members)
}

/// Initializes a new `Committee` instance.
pub fn new(starting_round: u64, members: IndexMap<Address<N>, (u64, bool)>) -> Result<Self> {
// Ensure there are at least 4 members.
ensure!(members.len() >= 4, "Committee must have at least 4 members");
// Ensure there are at least 3 members.
ensure!(members.len() >= 3, "Committee must have at least 3 members");
// Ensure there are no more than the maximum number of members.
ensure!(
members.len() <= Self::MAX_COMMITTEE_SIZE as usize,
Expand Down Expand Up @@ -382,7 +380,7 @@ mod tests {
// Set the number of rounds.
const NUM_ROUNDS: u64 = 256 * 2_000;
// Sample the number of members.
let num_members = rng.gen_range(4..50);
let num_members = rng.gen_range(3..50);
// Sample a committee.
let committee = crate::test_helpers::sample_committee_custom(num_members, rng);
// Check the leader distribution.
Expand Down
6 changes: 3 additions & 3 deletions ledger/committee/src/prop_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ impl Arbitrary for ValidatorSet {

fn arbitrary_with(_: Self::Parameters) -> Self::Strategy {
// use minimal validator set to speed up tests that require signing from the committee members
validator_set(any_valid_validator(), size_range(4..=4usize)).boxed()
validator_set(any_valid_validator(), size_range(3..=4usize)).boxed()
}
}

Expand All @@ -149,7 +149,7 @@ pub fn any_valid_private_key() -> BoxedStrategy<PrivateKey<CurrentNetwork>> {

#[allow(dead_code)]
fn too_small_committee() -> BoxedStrategy<Result<Committee<CurrentNetwork>>> {
(1u64.., validator_set(any_valid_validator(), 0..4)).prop_map(to_committee).boxed()
(1u64.., validator_set(any_valid_validator(), 0..3)).prop_map(to_committee).boxed()
}

#[allow(dead_code)]
Expand Down Expand Up @@ -199,5 +199,5 @@ fn invalid_stakes(#[strategy(too_low_stake_committee())] committee: Result<Commi

#[proptest]
fn invalid_member_count(#[strategy(too_small_committee())] committee: Result<Committee<CurrentNetwork>>) {
assert!(matches!(committee, Err(e) if e.to_string().as_str() == "Committee must have at least 4 members"))
assert!(matches!(committee, Err(e) if e.to_string().as_str() == "Committee must have at least 3 members"))
}

0 comments on commit afb38c5

Please sign in to comment.