-
Notifications
You must be signed in to change notification settings - Fork 22
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
Avoid IsShelleyBasedEra
and IsCardanoEra
where possible
#313
Conversation
[ byronAddressInEra <$> genAddressByron | ||
, shelleyAddressInEra <$> genAddressShelley | ||
[ byronAddressInEra <$> genAddressByron | ||
, shelleyAddressInEra sbe <$> genAddressShelley |
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.
shelleyAddressInEra
is an example of a function that previously demanded a constraint, but now demands a witness instead. It is often the case that the witness is just available somewhere in the context.
parseJSON = withText "AddressInEra" $ \txt -> do | ||
addressAny <- runParsecParser parseAddressAny txt | ||
pure $ anyAddressInShelleyBasedEra addressAny | ||
parseJSON = |
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.
We still retain the use of IsShelleyBasedEra
and IsCardanoEra
constraints for type class instances for now because we don't yet have a way to express these.
|
||
ShelleyBasedEra | ||
:: ShelleyBasedEra era | ||
-> CardanoEraStyle 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.
There is no need to embed both the constraint and the witness in the same constructor. They are convertible to each other.
in | ||
case tx of | ||
ShelleyTx _ tx' -> | ||
let x = shelleyBasedEraConstraints sbe $ tx' ^. L.sizeTxF in Lovelace (a * x + b) |
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.
Often we need more constraints than just IsShelleyBasedEra
so demanding it doesn't really help. We can summon all the constraints we need with just the eon witness.
ShelleyTxBody _ txbody _ _ _ _ -> makeShelleyBasedBootstrapWitness sbe nwOrAddr txbody sk | ||
|
||
makeShelleyBasedBootstrapWitness :: forall era. () | ||
=> ShelleyBasedEra 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.
An example of where the witness is sufficient to summon all the constrains we need.
LegacyByronEra -> makeByronTransactionBody | ||
ShelleyBasedEra sbe -> makeShelleyTransactionBody sbe | ||
createAndValidateTransactionBody era = | ||
case cardanoEraStyle era of |
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.
Using witness is less messy because we avoid having to give type-hints.
97c880e
to
099db6e
Compare
@@ -1840,8 +1840,7 @@ fromConwayPParams :: BabbageEraPParams ledgerera | |||
-> ProtocolParameters | |||
fromConwayPParams = fromBabbagePParams | |||
|
|||
checkProtocolParameters | |||
:: forall era. IsCardanoEra era | |||
checkProtocolParameters :: () | |||
=> ShelleyBasedEra 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.
Sometimes we demanded both the witness and constraint and they don't match.
(\w -> TxOutValue w (lovelaceToValue (Lovelace (2^(64 :: Integer)) - 1) <> nonAdaChange)) | ||
(cardanoEra @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.
Code that uses constraints are harder to maintain. For example we use cardanoEra @era
here despite era'
already being defined further down.
099db6e
to
153ac0b
Compare
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.
Can you open a PR in cardano-cli before we merge this? I see we only use IsShelleyBasedEra
twice in cardano-cli so it should be fine.
3eb911a
to
6dd0cce
Compare
There is a POC here. Will clean up the POC some more. |
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.
LGTM!
6dd0cce
to
5eb9017
Compare
…ead of IsCardanoEra.
fdf5bad
to
43027e5
Compare
Changelog
Context
We often use a combination of witness and constraints, sometimes inconsistently.
This PR standardises on the the use of witnesses because those are eon-friendly, more flexible and have better type-inference.
Removal of the constraints means that callers no longer have to satisfy those constraints.
Checklist
See Running tests for more details
.cabal
files are updatedhlint
. See.github/workflows/check-hlint.yml
to get thehlint
versionstylish-haskell
. See.github/workflows/stylish-haskell.yml
to get thestylish-haskell
versionghc-8.10.7
andghc-9.2.7