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] - Remove saturating arith from state_processing #1644

Closed
wants to merge 1 commit into from

Conversation

michaelsproul
Copy link
Member

Issue Addressed

Resolves #1100

Proposed Changes

  • Implement the SafeArith trait for Slot and Epoch, so that methods like safe_add become available.
  • Tweak the SafeArith trait to allow a different Rhs type (analagous to std::ops::Add, etc).
  • Add a legacy-arith feature to types and state_processing that conditionally enables implementations of
    the std ops with saturating semantics.
  • Check compilation of types and state_processing without legacy-arith on CI,
    thus guaranteeing that they only use the SafeArith primitives 🎉

Additional Info

The legacy-arith feature gets turned on by all higher-level crates that depend on state_processing or types, thus allowing the beacon chain, networking, and other components to continue to rely on the availability of ops like +, -, *, etc.

This is a consensus-breaking change, but brings us in line with the spec, and our incompatibilities shouldn't have been reachable with any valid configuration of Eth2 parameters.

@michaelsproul michaelsproul added ready-for-review The code is ready for review t Consensus & Verification consensus An issue/PR that touches consensus code, such as state_processing or block verification. and removed t Consensus & Verification labels Sep 22, 2020
Copy link
Member

@paulhauner paulhauner left a comment

Choose a reason for hiding this comment

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

Beautiful, couldn't fault it.

During this review, but not caused by this PR, I did notice some assumptions about the genesis slot being zero. I documented them in #1666 (issue of the beast 🤘).

I'll let your bors it :)

@paulhauner paulhauner added ready-for-merge This PR is ready to merge. and removed ready-for-review The code is ready for review labels Sep 25, 2020
@michaelsproul
Copy link
Member Author

Thank you!

bors r+

bors bot pushed a commit that referenced this pull request Sep 25, 2020
## Issue Addressed

Resolves #1100

## Proposed Changes

* Implement the `SafeArith` trait for `Slot` and `Epoch`, so that methods like `safe_add` become available.
* Tweak the `SafeArith` trait to allow a different `Rhs` type (analagous to `std::ops::Add`, etc).
* Add a `legacy-arith` feature to `types` and `state_processing` that conditionally enables implementations of
  the `std` ops with saturating semantics.
* Check compilation of `types` and `state_processing` _without_ `legacy-arith` on CI,
  thus guaranteeing that they only use the `SafeArith` primitives :tada:

## Additional Info

The `legacy-arith` feature gets turned on by all higher-level crates that depend on `state_processing` or `types`, thus allowing the beacon chain, networking, and other components to continue to rely on the availability of ops like `+`, `-`, `*`, etc.

**This is a consensus-breaking change**, but brings us in line with the spec, and our incompatibilities shouldn't have been reachable with any valid configuration of Eth2 parameters.
@bors bors bot changed the title Remove saturating arith from state_processing [Merged by Bors] - Remove saturating arith from state_processing Sep 25, 2020
@bors bors bot closed this Sep 25, 2020
@michaelsproul michaelsproul deleted the unsaturated-arith branch September 25, 2020 06:31
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.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Saturating arith on Slot/Epoch should fail state transition
2 participants