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

Convert CertState to a type family #4861

Draft
wants to merge 10 commits into
base: master
Choose a base branch
from

Conversation

Lucsanszky
Copy link
Contributor

Description

Checklist

  • Commits in meaningful sequence and with useful messages
  • Tests added or updated when needed
  • CHANGELOG.md files updated for packages with externally visible changes

    New section is never added with the code changes. (See RELEASING.md)
  • Versions updated in .cabal and CHANGELOG.md files when necessary, according to the
    versioning process.
  • Version bounds in .cabal files updated when necessary

    If you change the bounds in a cabal file, that package itself must have a version increase. (See RELEASING.md)
  • Code formatted (use scripts/fourmolize.sh)
  • Cabal files formatted (use scripts/cabal-format.sh)
  • hie.yaml updated (use scripts/gen-hie.sh)
  • Self-reviewed the diff

Copy link
Collaborator

@lehins lehins left a comment

Choose a reason for hiding this comment

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

I did a quick skim over the PR and it looks awesome.
There is one important point that I made that will need to be address that has to do with a common issue of changes getting lost during rebasing, but that shouldn't be too hard.
I'll do a proper review once the PR is out of the Draft state.

where
type CertState era = (r :: Type) | r -> era

mkCertState :: VState era -> PState era -> DState era -> CertState era
Copy link
Collaborator

Choose a reason for hiding this comment

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

For this PR this is totally fine, but just heads up for the future adjustments that we'll need to make we won't be able to construct it like that because VState will not be available.

This isn't really a problem since we can always construct it from an empty CertState, eg:

mkShelleyCertState pState dState = 
  def & certPStateL .~ pState
      & certDStateL .~ dState
mkConwayCertState pState dState vState = 
  mkConwayCertState pState dState & certVStateL .~ vState

Moreover in ledger rules we can always get away with modifying CertState, instead of constructing a new one.

Again, for this PR it will be fine to keep it as is, I am just giving you a heads up for the follow up work that we'll have to do.

Comment on lines 767 to 774
-- instance Era era => Arbitrary (CertState era) where
-- arbitrary = CertState <$> arbitrary <*> arbitrary <*> arbitrary
-- shrink = genericShrink
Copy link
Collaborator

Choose a reason for hiding this comment

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

Yeah, it will have to be concrete types that will be defining the Arbitrary instances, so feel free to get rid of this commented out code:

Suggested change
-- instance Era era => Arbitrary (CertState era) where
-- arbitrary = CertState <$> arbitrary <*> arbitrary <*> arbitrary
-- shrink = genericShrink


mkCertState = mkShelleyCertState

upgradeCertState = error "It is not possible to translate Byron CertState with 'upgradeCertState'"
Copy link
Collaborator

Choose a reason for hiding this comment

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

It is good to add Impossible, cause this would result in a compile time error, since ByronEra does not have a EraCertState instance implemented

Suggested change
upgradeCertState = error "It is not possible to translate Byron CertState with 'upgradeCertState'"
upgradeCertState = error "Impossible: ByronEra does not have `EraCertState` instance"

<> encCBOR shelleyCertPState
<> encCBOR shelleyCertDState

instance Era era => DecShareCBOR (ShelleyCertState era) where
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please take a look at the recent changes to all of the DecShareCBOR instances in this PR, since they have changed significantly since you started work on this work
See current instance for CertState:

instance Era era => DecShareCBOR (CertState era) where
type
Share (CertState era) =
( Interns (Credential 'Staking)
, Interns (KeyHash 'StakePool)
, Interns (Credential 'DRepRole)
, Interns (Credential 'HotCommitteeRole)
)
decSharePlusCBOR = decodeRecordNamedT "CertState" (const 3) $ do
certVState <-
decSharePlusLensCBOR $
lens (\(cs, _, cd, ch) -> (cs, cd, ch)) (\(_, ks, _, _) (cs, cd, ch) -> (cs, ks, cd, ch))
certPState <- decSharePlusLensCBOR _2
certDState <-
decSharePlusLensCBOR $
lens (\(cs, ks, cd, _) -> (cs, ks, cd)) (\(_, _, _, ch) (cs, ks, cd) -> (cs, ks, cd, ch))
pure CertState {certPState, certDState, certVState}

Please, make sure you don't loose any of the functionality from this PR: #4826

eras/alonzo/impl/cardano-ledger-alonzo.cabal Show resolved Hide resolved
eras/alonzo/impl/src/Cardano/Ledger/Alonzo/Translation.hs Outdated Show resolved Hide resolved
eras/mary/impl/src/Cardano/Ledger/Mary/Translation.hs Outdated Show resolved Hide resolved
@Lucsanszky Lucsanszky force-pushed the ldan/certstate-type-family branch 12 times, most recently from eb26cae to fe9f0b7 Compare February 11, 2025 04:05
@Lucsanszky Lucsanszky force-pushed the ldan/certstate-type-family branch from fe9f0b7 to 4f48af4 Compare February 11, 2025 06:24
@Lucsanszky Lucsanszky force-pushed the ldan/certstate-type-family branch from 4f48af4 to 425828e Compare February 11, 2025 06:42
@Lucsanszky Lucsanszky force-pushed the ldan/certstate-type-family branch from 425828e to 71a08ce Compare February 11, 2025 07:14
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.

2 participants