Skip to content

Commit

Permalink
consensus: remove round from sortition hash
Browse files Browse the repository at this point in the history
Resolves #1204
  • Loading branch information
herr-seppia committed Jan 8, 2024
1 parent e8c13ab commit ce7cd7a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 12 deletions.
4 changes: 2 additions & 2 deletions consensus/src/aggregator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -261,8 +261,8 @@ mod tests {
dbg!("{:?}", p);

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

// The index of the provisioner (inside expected_members) that let the
// quorum being reached
Expand Down
21 changes: 11 additions & 10 deletions consensus/src/user/sortition.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ pub fn create_sortition_hash(cfg: &Config, counter: u32) -> [u8; 32] {

// write input message
hasher.update(&cfg.seed.inner()[..]);
hasher.update(cfg.round.to_le_bytes());
hasher.update(cfg.step.to_le_bytes());
hasher.update(counter.to_le_bytes());

Expand Down Expand Up @@ -132,9 +131,9 @@ mod tests {
#[test]
pub fn test_sortition_hash() {
let hash = [
247, 14, 92, 48, 116, 139, 3, 5, 171, 135, 3, 182, 119, 212, 157,
225, 128, 0, 254, 222, 137, 136, 24, 77, 124, 168, 221, 84, 82,
110, 159, 206,
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,
];

assert_eq!(
Expand All @@ -148,8 +147,10 @@ mod tests {

#[test]
pub fn test_generate_sortition_score() {
let dataset =
vec![([3; 48], 123342342, 6458782), ([4; 48], 44443333, 13070642)];
let dataset = vec![
([3; 48], 123342342, 40818748),
([4; 48], 44443333, 26458886),
];

for (seed, total_weight, expected_score) in dataset {
let hash = create_sortition_hash(
Expand Down Expand Up @@ -182,7 +183,7 @@ mod tests {
);

// Verify expected distribution
assert_eq!(vec![8, 18, 17, 21], committee.get_occurrences());
assert_eq!(vec![8, 20, 14, 22], committee.get_occurrences());
}

#[test]
Expand All @@ -198,7 +199,7 @@ mod tests {
committee_size,
committee.get_occurrences().iter().sum::<usize>()
);
assert_eq!(vec![2, 18, 9, 16], committee.get_occurrences());
assert_eq!(vec![3, 17, 9, 16], committee.get_occurrences());
}

#[test]
Expand All @@ -224,7 +225,7 @@ mod tests {
committee_size,
committee.get_occurrences().iter().sum::<usize>()
);
assert_eq!(vec![2, 18, 9, 16], committee.get_occurrences());
assert_eq!(vec![3, 17, 9, 16], committee.get_occurrences());

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

#[test]
Expand Down

0 comments on commit ce7cd7a

Please sign in to comment.