-
Notifications
You must be signed in to change notification settings - Fork 156
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
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this 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 |
There was a problem hiding this comment.
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.
-- instance Era era => Arbitrary (CertState era) where | ||
-- arbitrary = CertState <$> arbitrary <*> arbitrary <*> arbitrary | ||
-- shrink = genericShrink |
There was a problem hiding this comment.
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:
-- 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'" |
There was a problem hiding this comment.
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
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 |
There was a problem hiding this comment.
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:
cardano-ledger/libs/cardano-ledger-core/src/Cardano/Ledger/CertState.hs
Lines 423 to 439 in bc10beb
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
eb26cae
to
fe9f0b7
Compare
fe9f0b7
to
4f48af4
Compare
4f48af4
to
425828e
Compare
425828e
to
71a08ce
Compare
Description
Checklist
CHANGELOG.md
files updated for packages with externally visible changesNew section is never added with the code changes. (See RELEASING.md)
.cabal
andCHANGELOG.md
files when necessary, according to theversioning process.
.cabal
files updated when necessaryIf you change the bounds in a cabal file, that package itself must have a version increase. (See RELEASING.md)
scripts/fourmolize.sh
)scripts/cabal-format.sh
)hie.yaml
updated (usescripts/gen-hie.sh
)