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

feat: record stats for majority vs. committee size ratio #347

Merged
merged 5 commits into from
Sep 10, 2024

Conversation

bajtos
Copy link
Member

@bajtos bajtos commented Sep 5, 2024

I'd like to get visibility into the size of the majorities - is it a tight majority or a super majority?

Links:

Signed-off-by: Miroslav Bajtoš <oss@bajtos.net>
@bajtos bajtos requested a review from juliangruber September 5, 2024 15:24
Comment on lines 242 to 243
// Ignore committees that are too small or with no majority
if (majoritySize > 0 && measurements > 0) {
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
// Ignore committees that are too small or with no majority
if (majoritySize > 0 && measurements > 0) {
// Ignore committees that are too small or with no majority
if (measurements > 0 && majoritySize > 0) {

I think in this order the condition matches the comment

Copy link
Member

Choose a reason for hiding this comment

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

Also, size zero != "too small", right? You could argue that a committee with one measurement is also too small. Is it instead that we want to ignore just empty committees?

Copy link
Member Author

Choose a reason for hiding this comment

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

I see how this is confusing, I had to re-read the code to understand what's going on.

majoritySize > 0 means that 1) the committee is large enough to give us confidence in the majority being honest 2) a majority was found in the measurements.

measurements > 0 is a safety check to prevent division by zero.

Now that I think about it, when majoritySize > 0 then measurements > 0 must be true as well, because "majority" size is always smaller or equal thant "committee size" (number of measurements).

I propose reworking the code as follows:

if (majoritySize > 0) {
  assert(measurements > 0, "majority cannot be larger than the committee size")
  // calculation
}

How can I improve the comment and/or the condition to make the intention more clear?

I can change majoritySize to number | undefined so that committees evaluated to COMMITTEE_TOO_SMALL and MAJORITY_NOT_FOUND will get majoritySize === undefined.

WDYT?

Copy link
Member

Choose a reason for hiding this comment

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

Sounds good! What about

if (majoritySize > 0) {
  assert(measurements > 0, "majority cannot be empty")
}

To me it takes two extra steps to realize why the assertion message is correct, even though we don't compare the values directly.

Copy link
Member Author

Choose a reason for hiding this comment

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

Sounds good! What about

if (majoritySize > 0) {
  assert(measurements > 0, "majority cannot be empty")
}

That's not what we are asserting.

measurements = majoritySize + sumOf(minoritySizes)

Copy link
Member Author

Choose a reason for hiding this comment

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

It is the same. I find the assertion message you proposed misleading.

We are not asserting that the majority cannot be empty - we already know that inside the if (majoritySize > 0) branch.

We are asserting that the invariants hold, i.e. majoritySize <= measurements.

Maybe this will be easier to reason about if we rename measurement to committeeSize. Then your proposal says this:

assert(committeeSize > 0, "majority cannot be empty")

Do you see now why I find that misleading?

Copy link
Member

Choose a reason for hiding this comment

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

I see! To me we don't need to rename the variables, only change the assertion message.

With this one I got confused:

if (majoritySize > 0) {
  assert(measurements > 0, "majority cannot be larger than the committee size")
  // calculation
}

We're not actually testing whether one is bigger than the other, so it relies on another invariant.

What about we make this as simple as possible:

if (majoritySize > 0) {
  assert(measurements > 0, "if there is a majority, there have to be measurements")
  // calculation
}

Copy link
Member Author

Choose a reason for hiding this comment

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

@juliangruber would you like me to apply the following change as well?

I can change majoritySize to number | undefined so that committees evaluated to COMMITTEE_TOO_SMALL and MAJORITY_NOT_FOUND will get majoritySize === undefined.

Copy link
Member

Choose a reason for hiding this comment

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

Sgtm, but I don't have a strong opinion on it

Copy link
Member Author

Choose a reason for hiding this comment

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

See d5c8883

@bajtos bajtos changed the title feat: record stats for majority vs. committee size feat: record stats for majority vs. committee size ratio Sep 9, 2024
Signed-off-by: Miroslav Bajtoš <oss@bajtos.net>
@bajtos
Copy link
Member Author

bajtos commented Sep 9, 2024

I added three new changes:

(1)

if (majoritySize > 0) {
  assert(measurements > 0, "if there is a majority, there have to be measurements")
  // calculation
}

(2)
Renamed majoritySizes to majorityToCommitteeRatios

(3)
Renamed the InfluxDB field prefix from majority_sizes_percents_ to majority_ratios_percents_

@juliangruber LGTY now?

@bajtos bajtos requested a review from juliangruber September 9, 2024 12:22
@juliangruber
Copy link
Member

Cool! Just #347 (comment) from my side

Signed-off-by: Miroslav Bajtoš <oss@bajtos.net>
@bajtos
Copy link
Member Author

bajtos commented Sep 10, 2024

@juliangruber PTAL again

@bajtos bajtos enabled auto-merge (squash) September 10, 2024 11:57
@bajtos bajtos merged commit f5ff8eb into main Sep 10, 2024
6 checks passed
@bajtos bajtos deleted the record-majority-sizes branch September 10, 2024 11:58
@bajtos
Copy link
Member Author

bajtos commented Sep 10, 2024

Screenshot 2024-09-10 at 14 55 52

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

2 participants