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

[Merged by Bors] - simplify calculate_committee_fraction #4213

Closed

Conversation

eserilev
Copy link
Collaborator

Issue Addressed

#4211

Proposed Changes

This PR conforms the helper function calculate_committee_fraction to the v1.3.0 spec

Additional Info

the old definition of calculate_committee_fraction is almost identical, but the new definition is simpler.

@eserilev
Copy link
Collaborator Author

fork_choice_test_definition::execution_status::test_03 is failing

line 1003 mentions a "magic number" generated from calculate_committee_fraction. I might need to generate a new magic number here for the test to pass

@michaelsproul
Copy link
Member

line 1003 mentions a "magic number" generated from calculate_committee_fraction

Huh, that is strange. I wouldn't have thought the values calculated by calculate_committee_fraction would actually be any different due to the simplification. We may want to dig into this a bit to understand exactly what's going on

@eserilev
Copy link
Collaborator Author

eserilev commented Apr 20, 2023

line 1003 mentions a "magic number" generated from calculate_committee_fraction

Huh, that is strange. I wouldn't have thought the values calculated by calculate_committee_fraction would actually be any different due to the simplification. We may want to dig into this a bit to understand exactly what's going on

Digging into whats going on

the update to calculate_committee_fraction is causing issues with test_03. I attempted to debug the issue by running test_03 locally. When executing the operations in test_03, I added a call to calculate_committee_fraction each time a new op is iterated through, and logged the results.

In the previous version of calculate_committee_fraction, calling the function in test_03 returns 31,000 at each op iteration

In the new version of calculate_committee_fraction, calling the function in test_03 returns 31,250 at each op iteration.

so the previous vs new iterations return a slightly different value.

Furthermore, in test_03, the magic numbers chosen on lines 990, 994, and 1003 only work for the older version of calculate_committee_fraction. In my most recent push I updated the magic numbers to reflect what they should be for the new version of calculate_committee_fraction. This update allows test_03 to pass. To be honest, I have no idea what the implications of this are. I'll try to continue digging into fork choice rules and some of the discussions around this specific spec update to gain additional context.

@eserilev
Copy link
Collaborator Author

ok I thought about this some more and I think I understand whats going on here

in Rust the following calculations could return different results, even though they are mathematically equivalent

a * (b /c) vs (a * b) / c

that's because w/ integer division, the remainder gets thrown away, so the order in which we divide and multiply plays a factor.

so even though the old vs new committee_weight calculations are mathematically equivalent:

(total_effective_balance / num_active_validators) * (num_active_validators / slots_per epoch) = total_effective_balance / slots_per_epoch

they dont return the exact same results due to the fact that the remainder gets thrown away during integer division

@michaelsproul michaelsproul added ready-for-review The code is ready for review consensus An issue/PR that touches consensus code, such as state_processing or block verification. v4.2.0 Q2 2023 labels Apr 27, 2023
@michaelsproul
Copy link
Member

@eserilev Do you mind rebasing on/merging the latest unstable? That will fix the outstanding CI failures.

We'll try to review this ASAP and get it merged for 4.2.0

@eserilev
Copy link
Collaborator Author

@michaelsproul i merged the latest unstable. thank you!

Copy link
Member

@michaelsproul michaelsproul left a comment

Choose a reason for hiding this comment

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

Looks good. Happy to merge.

@michaelsproul michaelsproul added ready-for-merge This PR is ready to merge. and removed ready-for-review The code is ready for review labels May 3, 2023
@michaelsproul
Copy link
Member

bors r+

bors bot pushed a commit that referenced this pull request May 3, 2023
## Issue Addressed

[#4211](#4211)

## Proposed Changes

This PR conforms the helper function `calculate_committee_fraction` to the [v1.3.0 spec](https://github.com/ethereum/consensus-specs/blob/v1.3.0/specs/phase0/fork-choice.md#get_weight)

## Additional Info

the old definition of `calculate_committee_fraction` is almost identical, but the new definition is simpler.
@bors
Copy link

bors bot commented May 3, 2023

@bors bors bot changed the title simplify calculate_committee_fraction [Merged by Bors] - simplify calculate_committee_fraction May 3, 2023
@bors bors bot closed this May 3, 2023
ghost pushed a commit to oone-world/lighthouse that referenced this pull request Jul 13, 2023
## Issue Addressed

[sigp#4211](sigp#4211)

## Proposed Changes

This PR conforms the helper function `calculate_committee_fraction` to the [v1.3.0 spec](https://github.com/ethereum/consensus-specs/blob/v1.3.0/specs/phase0/fork-choice.md#get_weight)

## Additional Info

the old definition of `calculate_committee_fraction` is almost identical, but the new definition is simpler.
Woodpile37 pushed a commit to Woodpile37/lighthouse that referenced this pull request Jan 6, 2024
## Issue Addressed

[sigp#4211](sigp#4211)

## Proposed Changes

This PR conforms the helper function `calculate_committee_fraction` to the [v1.3.0 spec](https://github.com/ethereum/consensus-specs/blob/v1.3.0/specs/phase0/fork-choice.md#get_weight)

## Additional Info

the old definition of `calculate_committee_fraction` is almost identical, but the new definition is simpler.
Woodpile37 pushed a commit to Woodpile37/lighthouse that referenced this pull request Jan 6, 2024
## Issue Addressed

[sigp#4211](sigp#4211)

## Proposed Changes

This PR conforms the helper function `calculate_committee_fraction` to the [v1.3.0 spec](https://github.com/ethereum/consensus-specs/blob/v1.3.0/specs/phase0/fork-choice.md#get_weight)

## Additional Info

the old definition of `calculate_committee_fraction` is almost identical, but the new definition is simpler.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
consensus An issue/PR that touches consensus code, such as state_processing or block verification. ready-for-merge This PR is ready to merge. v4.2.0 Q2 2023
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants