-
Notifications
You must be signed in to change notification settings - Fork 23
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
Reduce constraint usage with eons #299
Conversation
(toLedgerUTxO sbe utxo) | ||
txbody | ||
|
||
evalAdaOnly :: ShelleyToAllegraEra era -> TxOutValue 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.
This has changed from ByronToAllegraEra
. Was that intentional?
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.
Yes. The original code had ShelleyLedgerEra era
in the constraints so you could not call it in the Byron
era anyway.
9fe07d7
to
fcae06e
Compare
case txProtocolParams of | ||
BuildTxWith Nothing -> SNothing | ||
BuildTxWith (Just (LedgerProtocolParameters pp)) -> | ||
Alonzo.hashScriptIntegrity (Set.map (L.getLanguageView pp) languages) redeemers datums |
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.
convPParamsToScriptIntegrityHash
simplified a lot for three reasons:
- The function was returning and
Either
whenLeft
is never returned. This imposed on callers to handle theLeft
case as well, which is unnecessary. - The function is called with
ShelleyBasedEra
but the constraint makes it not possible for eras before alonzo anyway. Changing this toAlonzoEraOnwards
means we don't have tocase
on those earlier eras that never happen. alonzoEraOnwardsConstraints
removes the need to handle the remaining cases.
IsShelleyBasedEra era | ||
=> L.AlonzoEraTxOut ledgerera | ||
=> Ledger.EraCrypto ledgerera ~ StandardCrypto | ||
=> Ledger.Value ledgerera ~ MaryValue StandardCrypto |
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.
Removing constraints like these means the caller no longer needs to supply them.
<> CBOR.encCBOR (txScriptValidityToScriptValidity scriptValidity) | ||
<> CBOR.encodeNullMaybe CBOR.encCBOR txmetadata | ||
ShelleyBasedEraConway -> | ||
CBOR.serialize' (L.eraProtVerLow @L.Babbage) |
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.
This looks like a bug. We say Babbage
when doing Conway
stuff.
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 think this was implemented when there was no Conway era available.
, CBOR.encodeNullMaybe CBOR.encCBOR txmetadata | ||
] | ||
) | ||
(const $ CBOR.serialize' (L.eraProtVerLow @(ShelleyLedgerEra era)) $ mconcat |
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 the era
parameter means we can't get this wrong:
https://github.com/input-output-hk/cardano-api/pull/299/files#r1349452875
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 think we can actually delete this function (or we should) because we no longer use the intermediate tx body format.
case sData of | ||
TxBodyNoScriptData -> SNothing | ||
TxBodyScriptData w datums redeemers -> | ||
convPParamsToScriptIntegrityHash w apiProtocolParameters redeemers datums languages |
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.
Now that convPParamsToScriptIntegrityHash
takes the more appropriate AlonzoEraOnwards
witness (as opposed to ShelleyBasedEra
we can make use of the witness supplied by TxBodyScriptData
.
=> IsShelleyBasedEra era | ||
=> ShelleyLedgerEra era ~ ledgerera | ||
=> Ledger.EraCrypto ledgerera ~ StandardCrypto | ||
=> Ledger.Value ledgerera ~ MaryValue StandardCrypto |
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.
Removing constraints relieves the caller of the burden of providing them.
=> Ledger.Value ledgerera ~ MaryValue StandardCrypto | ||
=> MaryEraOnwards era | ||
-> AlonzoEraOnwards era | ||
-> BabbageEraOnwards 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.
We were previously demanding callers provide three witnesses. We only need the BabbageEraOnwards
because that's the most strict and the others are redundant. Demanding fewer witness relieves the called of the burden of providing so many.
fcae06e
to
47847fb
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.
Nice 👍
<> CBOR.encCBOR (txScriptValidityToScriptValidity scriptValidity) | ||
<> CBOR.encodeNullMaybe CBOR.encCBOR txmetadata | ||
ShelleyBasedEraConway -> | ||
CBOR.serialize' (L.eraProtVerLow @L.Babbage) |
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 think this was implemented when there was no Conway era available.
, CBOR.encodeNullMaybe CBOR.encCBOR txmetadata | ||
] | ||
) | ||
(const $ CBOR.serialize' (L.eraProtVerLow @(ShelleyLedgerEra era)) $ mconcat |
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 think we can actually delete this function (or we should) because we no longer use the intermediate tx body format.
47847fb
to
11efd28
Compare
Changelog
Context
By using eons to summon constraints our functions can have fewer or no constraints in their type signatures which simplifies code here as well as later in
cardano-cli
.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