Skip to content

Commit

Permalink
consensus: change step from u16 to u8 in sortition
Browse files Browse the repository at this point in the history
  • Loading branch information
herr-seppia committed Jul 22, 2024
1 parent f4a2c8d commit 53a7874
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 13 deletions.
6 changes: 4 additions & 2 deletions consensus/src/aggregator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -305,8 +305,8 @@ mod tests {
dbg!("{:?}", p);

// Collect votes from expected committee members
let expected_members = vec![0, 1, 3, 4, 5];
let expected_votes = vec![1, 1, 1, 2, 3];
let expected_members = vec![1, 2, 3, 4];
let expected_votes = vec![1, 1, 2, 1];

// The index of the provisioner (inside expected_members) that let the
// quorum being reached
Expand All @@ -320,6 +320,7 @@ mod tests {
}
},
);
println!("winning index {winning_index}");
let mut collected_votes = 0;
for i in 0..expected_members.len() - 1 {
// Select provisioner
Expand All @@ -345,6 +346,7 @@ mod tests {
break;
}

println!("Collecting vote for index {i}");
// Check collected votes
let (_, quorum_reached) = a.collect_vote(&c, msg).unwrap();

Expand Down
20 changes: 9 additions & 11 deletions consensus/src/user/sortition.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,6 @@ pub fn create_sortition_hash(cfg: &Config, counter: u32) -> [u8; 32] {
// write input message
hasher.update(&cfg.seed.inner()[..]);
hasher.update(cfg.step.to_le_bytes());
// FIXME: Remove the extra bytes after update the tests
hasher.update(0u8.to_le_bytes());
hasher.update(counter.to_le_bytes());

// read hash digest
Expand Down Expand Up @@ -127,9 +125,9 @@ mod tests {
#[test]
pub fn test_sortition_hash() {
let hash = [
102, 194, 89, 58, 228, 163, 25, 223, 222, 214, 246, 137, 213, 168,
65, 13, 83, 130, 73, 187, 213, 145, 71, 20, 64, 167, 93, 251, 151,
200, 167, 168,
74, 64, 238, 174, 226, 52, 11, 105, 93, 251, 204, 6, 137, 176, 14,
96, 77, 139, 92, 76, 7, 178, 38, 16, 132, 233, 13, 180, 78, 206,
204, 31,
];

assert_eq!(
Expand All @@ -144,8 +142,8 @@ mod tests {
#[test]
pub fn test_generate_sortition_score() {
let dataset = vec![
([3; 48], 123342342, 40818748),
([4; 48], 44443333, 26458886),
([3; 48], 123342342, 80689917),
([4; 48], 44443333, 20330495),
];

for (seed, total_weight, expected_score) in dataset {
Expand Down Expand Up @@ -179,7 +177,7 @@ mod tests {
);

// Verify expected distribution
assert_eq!(vec![8, 20, 14, 22], committee.get_occurrences());
assert_eq!(vec![4, 29, 9, 22], committee.get_occurrences());
}

#[test]
Expand All @@ -200,7 +198,7 @@ mod tests {
committee_credits,
committee.get_occurrences().iter().sum::<usize>()
);
assert_eq!(vec![3, 17, 9, 16], committee.get_occurrences());
assert_eq!(vec![6, 13, 11, 15], committee.get_occurrences());
}

#[test]
Expand All @@ -226,7 +224,7 @@ mod tests {
committee_credits,
committee.get_occurrences().iter().sum::<usize>()
);
assert_eq!(vec![3, 17, 9, 16], committee.get_occurrences());
assert_eq!(vec![6, 13, 11, 15], committee.get_occurrences());

// Run the same extraction, with the generator excluded
let cfg =
Expand All @@ -244,7 +242,7 @@ mod tests {
committee_credits,
committee.get_occurrences().iter().sum::<usize>()
);
assert_eq!(vec![5, 23, 17], committee.get_occurrences());
assert_eq!(vec![8, 13, 24], committee.get_occurrences());
}

#[test]
Expand Down

0 comments on commit 53a7874

Please sign in to comment.