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

Addition of lenses for PParams #3242

Merged
merged 5 commits into from
Jan 13, 2023
Merged

Addition of lenses for PParams #3242

merged 5 commits into from
Jan 13, 2023

Conversation

lehins
Copy link
Collaborator

@lehins lehins commented Jan 10, 2023

Description

Addition of EraPParams, AlonzoEraPParams and BabageEraPParams type classes with lenses that can access and manipulate both PParams and ParamsUpdate. Each type class requires implementation lenses for the PParamsHKD type, which are later used for defining specific lenses for PParams and PParamsUpdate respectfully

HKD types ShelleyPParams, AlonzoPParams and BabbagePParams now become internal, for the most part and the PParams+PParamsUpdate are the newtype wrappers around the era specific internal HKD type. All operations on PParams should be done with lenses from now on.

Other notable things in this PR:

  • Fixes Ord instances for AlonzoPParams and BabbagePParams by introducing an internal `OrdExUniits type.
  • Moves around To/FromJSON instances to prevent the from being orphan
  • Moved CostModels into Cardano.Ledger.Alozno.Scripts from Cardano.Ledger.Alozno.PParams
  • Switch all functions that accepted PParams as an argument, but only used protocol version, to accept only protocol version. Most notable examples are functions that do conditional checking on the hardfork
  • Makes PoolEnv fields strict
  • Adds a data type ByronEra that has an Era instance. This is done mostly for completeness, but also to allow getting protocol version from the type level. Also this allowed PreviousEra type family to be moved into Era type class.
  • Moved all class definitions {EraName}Era{Type}, into the Cardano.Ledger.{EraName}.Core module. It was discussed before, but wasn't fully implemented.

Fixes #2927

Checklist

  • Commit sequence broadly makes sense
  • Commits have useful messages
  • New tests are added if needed and existing tests are updated
  • Any changes are noted in the changelog
  • Code is formatted with fourmolu (which can be run with scripts/fourmolize.sh
  • Self-reviewed the diff

CHANGELOG.md Outdated Show resolved Hide resolved
@lehins lehins force-pushed the lehins/pparams-lens branch 2 times, most recently from 1814588 to 67ea7d0 Compare January 11, 2023 22:10
@lehins lehins requested a review from a team as a code owner January 11, 2023 22:10
Copy link
Contributor

@JaredCorduan JaredCorduan left a comment

Choose a reason for hiding this comment

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

This all looks amazing, thank you!

You don't have to do this, just an idea: maybe we could add a section to the CONTRIBUTING.md doc about open imports, forbidden them except for Core modules, and maybe lenses?

Soupstraw and others added 3 commits January 13, 2023 16:33
* Added `EraPParams` `AlonzoEraPParams` and `BabageEraPParams` with lenses
  that can access and manipulate both `PParams` and `ParamsUpdate` for each era.
* Introduced `upgradePParams` and `downgradePParams`, which loosely
  correspond to `extendPP` and `retractPP`.
* Removed all occurrences of HasField from all the eras.
* Extracted `Era` related code and `TranslateEra` related code from
  `Cardano.Ledger.Core` into `Cardano.Ledger.Core.Era` and
  `Cardano.Ledger.Core.Translation` respectfully
* Moved `PreviousEra` type family into `Era` type class.
* Defined an `Era` instance for new `ByronEra` type
* Concrete PParams types for each era had their fields renamed to follow
  the convention used throughout the codebase
* Adjust transaction generation in the travce generator to work for
  eras beyond Mary
* Got rid of `ShelleyTest` and `UsesPP` type synonyms
It is acceptable to turn off the warning for the whole package
for ghc-8.10 since we are developing with ghc-9.2 and we have CI
for both of those GHC versions, so we will definitely catch any
name shadowing warnings that aren't related to the bug.
* According to Github documentation cache action will already
automatically look into `master` branch cache, however it will never
look into caches for other branches. So, previous logic was a bit faulty
* Enable trigger on pushes to master, this way we can have a build after
each PR is merged.
@lehins lehins merged commit e0947b0 into master Jan 13, 2023
@iohk-bors iohk-bors bot deleted the lehins/pparams-lens branch January 13, 2023 15:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Switch PParams to use lenses instead of HasField
3 participants