Skip to content
This repository has been archived by the owner on Oct 17, 2022. It is now read-only.

fix: Make leader election select from the whole Committee #762

Merged
merged 4 commits into from
Aug 16, 2022

Conversation

huitseeker
Copy link
Contributor

Fixes #755

Copy link
Contributor

@akichidis akichidis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great fix @huitseeker , changes make sense to me (from a non-consensus expert point of view compared to the other peer reviewers).

let mut leader_counts_stepping_by_2 = HashMap::new();
for i in 0..100 {
let leader = committee.leader(i);
let leader_stepping_by_2 = committee.leader(i * 2);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not immediately clear to me what we are trying to test by having the leader_stepping_by_2 here. @huitseeker could you please provide some info?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've added a comment: we iterate through even rounds in practice, and so I wanted to make sure we hit the whole roster (each available validator) reliably.

.entry(leader_stepping_by_2)
.or_insert(0) += 1;
}
assert!(leader_counts.values().all(|v| *v > 1));
Copy link
Contributor

@akichidis akichidis Aug 15, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we are weighting based on stake (where here is always 1 across the authorities) would it make sense to also check the diff between the number of times the leaders have been elected and ensure they don't diverge much? (since we use normal distribution).

Copy link
Contributor Author

@huitseeker huitseeker Aug 15, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be an improvement, but I'm not sure how much to invest there.

We use a uniform distribution for the test_utils::committee function, which means we are doing Bernouilli sampling.

  1. If we want to be as general as we can, this test should generate a binomial distribution, something we can test with a goodness-of-fit test adapted for the discrete case.
  2. We can also test exact numbers (the test is deterministic), but this may break the second we move out of our current discipline of iterating through seeds in a very particular way.
  3. A good trade-off would be to use a simple inequality (e.g. Chebysheff).

I've made the tests more strict for now (solution 2. : I check each validator is hit 20 times). Please use this comment to open an issue if you think we need something better.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the detailed reply on this! Great to see that you did with solution (2). Definitely (3) is something we could apply here - and now that I can think off we could use in other places in the end to end tests .

config/src/lib.rs Show resolved Hide resolved
@huitseeker huitseeker force-pushed the fix_leader_election branch 2 times, most recently from bc72c3f to 68abdfa Compare August 15, 2022 21:43
@huitseeker huitseeker enabled auto-merge (squash) August 15, 2022 21:47
@huitseeker huitseeker merged commit 050049c into MystenLabs:main Aug 16, 2022
huitseeker added a commit to huitseeker/narwhal that referenced this pull request Aug 16, 2022
…#762)

* fix: Make leader election select from the whole Committee

Fixes MystenLabs#755

* fix: Make tests of binomial result more strict

* fix: make the leader see a strict u64 (from usize)

* fix: consensus behavior under tests
huitseeker added a commit that referenced this pull request Aug 16, 2022
* fix: Make leader election select from the whole Committee

Fixes #755

* fix: Make tests of binomial result more strict

* fix: make the leader see a strict u64 (from usize)

* fix: consensus behavior under tests
huitseeker added a commit that referenced this pull request Aug 16, 2022
* fix: Make leader election select from the whole Committee

Fixes #755

* fix: Make tests of binomial result more strict

* fix: make the leader see a strict u64 (from usize)

* fix: consensus behavior under tests
mwtian pushed a commit to mwtian/sui that referenced this pull request Sep 30, 2022
…/narwhal#762)

* fix: Make leader election select from the whole Committee

Fixes MystenLabs/narwhal#755

* fix: Make tests of binomial result more strict

* fix: make the leader see a strict u64 (from usize)

* fix: consensus behavior under tests
@huitseeker huitseeker deleted the fix_leader_election branch January 21, 2023 13:35
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[consensus] Rotate through all the leader roster
3 participants