-
Notifications
You must be signed in to change notification settings - Fork 157
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
Restructure the Core for consistency, clarity and new functionality #2901
Conversation
0b34c8e
to
3dc8b68
Compare
28b52ff
to
28e0cc6
Compare
eras/babbage/test-suite/test/Test/Cardano/Ledger/Babbage/Serialisation/Tripping.hs
Outdated
Show resolved
Hide resolved
a2f8af0
to
c67050d
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.
Colossal cleanup!! Thank you so much for putting in all this effort to make our codebase more friendly!
I'm happy with all the changes. I made a handful of comments, but nothing of real importance.
🚀
@lehins thank you also for the amazing PR notes. Not only is it very helpful for reviewers, it leaves a great trail for others later down the line. (and for myself too, later, when I might have forgotten some details). 💪 |
**Creation of class hierarchy** **New classes** ``` EraSegWits --> EraTx --> EraTxBody --> EraTxOut --> Era \ `--> EraPParams --> Era `--> EraWitnesses --> EraScript --> Era `--> EraAuxiliaryData --> Era ``` Note that all of the `Era*` classes have a few properties: * depend either directly or transitively on the `Era` type class. * define an associated type family (which was previously standalone). * add all constraints that the associated type must implement. This means that any function that uses an associated type family can safely use the corresponding type class. For example a function that accepts `TxBody` as argument can always set `EraTx` as a constraint, which will bring all of the superclasses as constraints as well. Loose corespondance of new classes to the old removed concepts: * `Era` class is the same as before with the addition of type level protocol version and deprecation of all of the functions. It also implements now a per era deprecation mechanism with protocol version bounds * `EraTxOut` has all superclasses as in `UsesTxOut` type synonym constraint as well as defines lenses that supercede all functions previously defined in `Era` type class * `EraTxBody` has all superclasses as in `UsesTxBody` type synonym constraint * `EraAuxiliaryData` has all superclasses as in `UsesAuxiliaryData` type synonym constraint and consolidates `ValidateAuxiliaryData` into it * `EraPParams` replaces `UsesPParams` type class now with an associated type family * `EraScript` has replaced `UsesScript` type synonym constraint and the `ValidateScripts` type class, with an exception of `validateScript` function, which was moved into `EraTx` type class, since it depends on the `Tx` **Lenses** This PR expands usage of [`microlens`](https://hackage.haskell.org/package/microlens) package. Each class defines lenses for associated types, all of which are getters and potentially setter. They also define a way to construct a minimal value of an asscoiated type. For example if we want to construct a function that will construct a `Tx` with a new `TxBody`, which uses `AuxiliaryData` from another `Tx`: ```haskell newTxWithOtherAuxData :: EraTx era => TxBody era -> Tx era -> Tx era newTxWithOtherAuxData txBody tx = mkBasicTx txBody & auxDataTxL .~ (tx ^. auxDataTxL) ``` Above function is guaranteed to work with transactions of all eras. Some are just getters, which simply relay some information from one or more fields of a concrete type, altohugh they might do some minimal computation. For example `allInputsTxBodyF` will return all of the inputs present in the `TxBody`. **Naming convention** All lenses are suffixed with the type name they operate on and either `L`ens or `G`etter. **Migration guide** **Accessor fields** Names suffered some very minor adjustments that don't match the spec (tagged with *) **TxOut** * `makeTxOut (Proxy era)` -> `mkBasicTxOut` * `getField @"value" txOut` -> `txOut ^. valueTxOutL` * `_` -> `txOut ^. compactValueTxOutL` * `getCoin` -> `txOut ^. coinTxOutL` * `getTxOutAddr txOut` -> `txOut ^. addrTxOutL` * `getTxOutEitherAddr txOut` -> `txOut ^. addrEitherTxOutL` * `getTxOutCompactAddr txOut` -> `txOut ^. compactAddrTxOutL` * `getTxOutBootstrapAddress txOut` -> `txOut ^. bootAddrTxOutF` * `getField @"datahash" txOut` -> `txOut ^. dataHashTxOutL` (*) * `getField @"referenceScript" txOut` -> `txOut ^. referenceScriptTxOutL` * `_` -> `txOut ^. dataTxOutL` * `_` -> `txOut ^. datumTxOutL` **TxBody** * `getField @"inputs" txBody` -> ` txBody ^. inputsTxBodyL` * `getField @"outputs" txBody` -> ` txBody ^. outputsTxBodyL` * `getField @"txfee" txBody` -> ` txBody ^. feeTxBodyL` (*) * `getField @"auxiliaryData" txBody` -> ` txBody ^. auxDataHashTxBodyL` (*) * `getAllInputs txBody` -> ` txBody ^. allInputsTxBodyF` * `getField @"minted" txBody` -> ` txBody ^. mintedTxBodyF` * `getField @"wdrls" txBody` -> `txBody ^. wdrlsTxBodyL` * `getField @"ttl" txBody` -> `txBody ^. ttlTxBodyL` * `getField @"update" txBody` -> `txBody ^. updateTxBodyL` * `getField @"certs" txBody` -> `txBody ^. certsTxBodyL` * `getField @"vldt" txBody` -> `txBody ^. vldtTxBodyL` * `getField @"mint" txBody` -> `txBody ^. mintTxBodyL` * `getField @"collateral" txBody` -> `txBody ^. collateralInputsTxBodyL` (*) * `getField @"reqSignerHashes" txBody` -> `txBody ^. reqSignerHashesTxBodyL` * `getField @"scriptIntegrityHash" txBody` -> `txBody ^. scriptIntegrityHashTxBodyL` * `getField @"txnetworkid" txBody` -> `txBody ^. networkIdTxBodyL` (*) * `getField @"sizedOutputs" txBody` -> `txBody ^. sizedOutputsTxBodyL` * `getField @"referenceInputs" txBody` -> `txBody ^. referenceInputsTxBodyL` * `getField @"totalCollateral" txBody` -> `txBody ^. totalCollateralTxBodyL` * `getField @"collateralReturn" txBody` -> `txBody ^. collateralReturnTxBodyL` * `getField @"sizedCollateralReturn" txBody` -> `txBody ^. sizedCollateralReturnTxBodyL` **Tx** * `getField @"body" tx` -> `tx ^. bodyTxL` * `getField @"wits" tx` -> `tx ^. witsTxL` * `getField @"auxData" tx` -> `tx ^. auxDataTxL` * `getField @"size" tx` -> `tx ^. sizeTxF` * `getField @"isValid" tx` -> `tx ^. isValidTxL` Nested instances are no longer needed, since composition of lenses works much better: * `getField @"addrWits" tx` -> `tx ^. witsTxL . addrWitsL` * `getField @"scriptWits" tx` -> `tx ^. witsTxL . scriptsWitsL` * `getField @"bootWits" tx` -> `tx ^. witsTxL . bootAddrWitsL` * `getField @"txdatahash" tx` -> `tx ^. witsTxL . datsWitsL . to unTxDats` **Witnesses** * `getField @"addr" txWits` -> `txWits ^. addrWitsL` * `getField @"bootAddr" txWits` -> `txWits ^. bootAddrWitsL` * `getField @"script" txWits` -> `txWits ^. scriptWitsL` * `getField @"dats" txWits` -> `txWits ^. datsWitsL` * `getField @"rdmrs" txWits` -> `txWits ^. rdmrsWitsL` **Removal of constraint type synonyms** All of the `Trans*`, `Uses*` constraints have been removed as they are fully replaced by the above hierarchy Names removed and their closest replacements: * `BlockAnn` -> `EraTx` * `ChainData` - no replacemnt, this was just an adhoc collection of classes SerialisableData, * `AnnotatedData` -> `FromCBOR (Annotator t)` + `ToCBOR t` * `SerialisableData` -> `FromCBOR t` + `ToCBOR t` * `WellFormed` -> `EraTx` * `ShelleyEraCrypto` **`Val` class** Addition of two class methods that allow efficient manipulation of compact coin representation: `injectCompact` and `modifyCompactCoin`, without uncompacting the actual type `t` for which the `Val` instance is being defined **Data type renaming** All concrete types for every era where either inconsistent or clashing with the core type families: * Before this commit: | Core | Shelley | ShelleyMA | Alonzo | Babbage | |:-------------:|:-------------:|:---------------:|:-------------:|:-------------:| | Tx | Tx | -- | ValidatedTx | -- | | TxBody | TxBody | MATxBody | TxBody | TxBody | | TxOut | TxOut | -- | TxOut | TxOut | | AuxiliaryData | AuxiliaryData | MAAuxiliaryData | AuxiliaryData | -- | | Witnesses | WitnessSetHKD | -- | TxWitness | -- | | Script | MultiSig | Timelock | Script | -- | | Value | Coin | Value | -- | -- | | PParams | PParams | -- | PParams | PParams | | PParamsDelta | PParamsUpdate | -- | PParamsUpdate | PParamsUpdate | * After this commit | Core | Shelley | ShelleyMA | Alonzo | Babbage | |:-------------:|:--------------------:|:---------------:|:-------------------:|:--------------------:| | Tx | ShelleyTx | -- | AlonzoTx | -- | | TxBody | ShelleyTxBody | MATxBody | AlonzoTxBody | BabbageTxBody | | TxOut | ShelleyTxOut | -- | AlonzoTxOut | BabbageTxOut | | AuxiliaryData | ShelleyAuxiliaryData | MAAuxiliaryData | AlonzoAuxiliaryData | -- | | Witnesses | WitnessSetHKD | -- | TxWitness | -- | | Script | MultiSig | Timelock | AlonzoScript | -- | | Value | Coin | MaryValue | -- | -- | | PParams | ShelleyPParams | -- | AlonzoPParams | BabbagePParams | | PParamsUpdate | ShelleyPParamsUpdate | -- | AlonzoPParamsUpdate | BabbagePParamsUpdate | **Module restructure** Concrete era data type (eg. `BabageEra`) is no longer defined at the top level module (eg. `Cardano.Ledger.Babbage`), but rather in a new private `.Era` module (eg. `Cardano.Ledger.Babbage.Era`). It is later re-exported from the top level module together with all of the orphan instances. This allows us to define all of the relevant instances in their respective modules (eg. `EraTxBody` is defined in the `TxBody` module) **Other minor changes** * Defined `NFData` for `Sized` * Rename `Cardano.Ledger.Shelley.Core` to `Cardano.Ledger.Shelley.Type` * Move module `Cardano.Ledger.Shelley.Address.Bootstrap` (`cardano-ledger-shelley`) -> `Cardano.Ledger.Keys.Bootstrap` (`cardano-ledger-core`) * Moved `langsUsed` into tests, since that was the only use site.
c67050d
to
acd88e8
Compare
537bba8
to
73b77de
Compare
Recent PR to ledger: IntersectMBO/cardano-ledger#2901 introduced a lot of breaking changes. This commit accounts for those changes
Recent PR to ledger: IntersectMBO/cardano-ledger#2901 introduced a lot of breaking changes. This commit accounts for those changes
Recent PR to ledger: IntersectMBO/cardano-ledger#2901 introduced a lot of breaking changes. This commit accounts for those changes
Recent PR to ledger: IntersectMBO/cardano-ledger#2901 introduced a lot of breaking changes. This commit accounts for those changes
Recent PR to ledger: IntersectMBO/cardano-ledger#2901 introduced a lot of breaking changes. This commit accounts for those changes
Recent PR to ledger: IntersectMBO/cardano-ledger#2901 introduced a lot of breaking changes. This commit accounts for those changes
Recent PR to ledger: IntersectMBO/cardano-ledger#2901 introduced a lot of breaking changes. This commit accounts for those changes
Recent PR to ledger: IntersectMBO/cardano-ledger#2901 introduced a lot of breaking changes. This commit accounts for those changes
Recent PR to ledger: IntersectMBO/cardano-ledger#2901 introduced a lot of breaking changes. This commit accounts for those changes
3933: Account for new ledger refactor. r=lehins a=lehins Recent PR to ledger: IntersectMBO/cardano-ledger#2901 introduced a lot of breaking changes. This PR accounts for those changes. # Description <!-- CI flakiness -- delete this before opening a PR Sadly, some CI checks are currently flaky. Right now, this includes: - GH Actions Windows job runs out of memory, e.g. in https://github.com/input-output-hk/ouroboros-network/runs/7231748864?check_suite_focus=true - The Hydra check for test-storage on Windows (mingwW64) fails with inscrutable malloc-related error messages: https://hydra.iohk.io/build/16260881/nixlog/1 - The tests in WallClock.delay* can fail under load (quite rarely): https://hydra.iohk.io/build/16723452/nixlog/76 If you encounter one of these, try restarting the job to see if the failure vanishes. If it does not or when in doubt, consider posting in the #network or #consensus channels on Slack. --> _description of the pull request, if it fixes a particular issue it should link the PR to a particular issue, see [ref](https://docs.github.com/en/issues/tracking-your-work-with-issues/linking-a-pull-request-to-an-issue#linking-a-pull-request-to-an-issue-using-a-keyword=)_ Co-authored-by: Alexey Kuleshevich <[email protected]>
3933: Account for new ledger refactor. r=lehins a=lehins Recent PR to ledger: IntersectMBO/cardano-ledger#2901 introduced a lot of breaking changes. This PR accounts for those changes. # Description <!-- CI flakiness -- delete this before opening a PR Sadly, some CI checks are currently flaky. Right now, this includes: - GH Actions Windows job runs out of memory, e.g. in https://github.com/input-output-hk/ouroboros-network/runs/7231748864?check_suite_focus=true - The Hydra check for test-storage on Windows (mingwW64) fails with inscrutable malloc-related error messages: https://hydra.iohk.io/build/16260881/nixlog/1 - The tests in WallClock.delay* can fail under load (quite rarely): https://hydra.iohk.io/build/16723452/nixlog/76 If you encounter one of these, try restarting the job to see if the failure vanishes. If it does not or when in doubt, consider posting in the #network or #consensus channels on Slack. --> _description of the pull request, if it fixes a particular issue it should link the PR to a particular issue, see [ref](https://docs.github.com/en/issues/tracking-your-work-with-issues/linking-a-pull-request-to-an-issue#linking-a-pull-request-to-an-issue-using-a-keyword=)_ Co-authored-by: Alexey Kuleshevich <[email protected]>
4608: Update ouroboros-network and cardano-ledger dependencies r=angerman a=Soupstraw This PR updates ouroboros-network and cardano-ledger dependencies. This bumps `cardano-ledger` to `0.1.1.1`, which is IntersectMBO/cardano-ledger#3080. This in turn is the `release/1.1.x` branch + heapword split compatibility introduced in `cardano-base`, which is in CHaP. It also bumps ouroboros-network to [a38f898a](https://github.com/input-output-hk/ouroboros-network/commits/a38f898a3740925ccaa0617fa870ca7054a485a6), which is 45 commits ahead of the old [c764553](https://github.com/input-output-hk/ouroboros-network/commits/c764553561bed8978d2c6753d1608dc65449617a) pin. This is one commit ahead of what IntersectMBO/ouroboros-network#3933 (on ouroboros-network/master), that made network compatible with IntersectMBO/cardano-ledger#2901 Co-authored-by: Joosep Jääger <[email protected]> Co-authored-by: Samuel Leathers <[email protected]>
Changes in this humongous PR:
Creation of class hierarchy:
New classes:
Note that all of the
Era*
classes have a few properties:Era
type class.This means that any function that uses an associated type family can safely use
the corresponding type class. For example a function that accepts
TxBody
asargument can always set
EraTx
as a constraint, which will bring all of thesuperclasses as constraints as well.
Loose corespondance of new classes to the old removed concepts:
Era
class is the same as before with the addition of type level protocolversion and deprecation of all of the functions
EraTxOut
has all superclasses as inUsesTxOut
type synonym constraint aswell as defines lenses that supercede all functions previously defined in
Era
type classEraTxBody
has all superclasses as inUsesTxBody
type synonym constraintEraAuxiliaryData
has all superclasses as inUsesAuxiliaryData
type synonymconstraint and consolidates
ValidateAuxiliaryData
into itEraPParams
replacesUsesPParams
type class now with an associated type familyEraScript
has replacedUsesScript
type synonym constraint and theValidateScripts
type class, with an exception ofvalidateScript
function,which was moved into
EraTx
type class, since it depends on theTx
Lenses
This PR expands usage of
microlens
package.Each class defines lenses for associated types, all of which are getters and
potentially setter. They also define a way to construct a minimal value of an
asscoiated type. For example if we want to construct a function that will
construct a
Tx
with a newTxBody
, which usesAuxiliaryData
from anotherTx
:Above function is guaranteed to work with transactions of all eras.
Some are just getters, which simply relay some information from one or more
fields of a concrete type, altohugh they might do some minimal computation. For
example
allInputsTxBodyF
will return all of the inputs present in theTxBody
.Naming convention
All lenses are suffixed with the type name they operate on and either
L
ens orG
etter.Migration guide
Accessor fields
Names suffered some very minor adjustments that don't match the spec (tagged with *)
TxOut
makeTxOut (Proxy era)
->mkBasicTxOut
getField @"value" txOut
->txOut ^. valueTxOutL
_
->txOut ^. compactValueTxOutL
getCoin
->txOut ^. coinTxOutL
getTxOutAddr txOut
->txOut ^. addrTxOutL
getTxOutEitherAddr txOut
->txOut ^. addrEitherTxOutL
getTxOutCompactAddr txOut
->txOut ^. compactAddrTxOutL
getTxOutBootstrapAddress txOut
->txOut ^. bootAddrTxOutF
getField @"datahash" txOut
->txOut ^. dataHashTxOutL
(*)getField @"referenceScript" txOut
->txOut ^. referenceScriptTxOutL
_
->txOut ^. dataTxOutL
_
->txOut ^. datumTxOutL
TxBody
getField @"inputs" txBody
->txBody ^. inputsTxBodyL
getField @"outputs" txBody
->txBody ^. outputsTxBodyL
getField @"txfee" txBody
->txBody ^. feeTxBodyL
(*)getField @"auxiliaryData" txBody
->txBody ^. auxDataHashTxBodyL
(*)getAllInputs txBody
->txBody ^. allInputsTxBodyF
getField @"minted" txBody
->txBody ^. mintedTxBodyF
getField @"wdrls" txBody
->txBody ^. wdrlsTxBodyL
getField @"ttl" txBody
->txBody ^. ttlTxBodyL
getField @"update" txBody
->txBody ^. updateTxBodyL
getField @"certs" txBody
->txBody ^. certsTxBodyL
getField @"vldt" txBody
->txBody ^. vldtTxBodyL
getField @"mint" txBody
->txBody ^. mintTxBodyL
getField @"collateral" txBody
->txBody ^. collateralInputsTxBodyL
(*)getField @"reqSignerHashes" txBody
->txBody ^. reqSignerHashesTxBodyL
getField @"scriptIntegrityHash" txBody
->txBody ^. scriptIntegrityHashTxBodyL
getField @"txnetworkid" txBody
->txBody ^. networkIdTxBodyL
(*)getField @"sizedOutputs" txBody
->txBody ^. sizedOutputsTxBodyL
getField @"referenceInputs" txBody
->txBody ^. referenceInputsTxBodyL
getField @"totalCollateral" txBody
->txBody ^. totalCollateralTxBodyL
getField @"collateralReturn" txBody
->txBody ^. collateralReturnTxBodyL
getField @"sizedCollateralReturn" txBody
->txBody ^. sizedCollateralReturnTxBodyL
Tx
getField @"body" tx
->tx ^. bodyTxL
getField @"wits" tx
->tx ^. witsTxL
getField @"auxData" tx
->tx ^. auxDataTxL
getField @"size" tx
->tx ^. sizeTxF
getField @"isValid" tx
->tx ^. isValidTxL
Nested instances are no longer needed, since composition of lenses works much better:
getField @"addrWits" tx
->tx ^. witsTxL . addrWitsL
getField @"scriptWits" tx
->tx ^. witsTxL . scriptsWitsL
getField @"bootWits" tx
->tx ^. witsTxL . bootAddrWitsL
getField @"txdatahash" tx
->tx ^. witsTxL . datsWitsL . to unTxDats
Witnesses
getField @"addr" txWits
->txWits ^. addrWitsL
getField @"bootAddr" txWits
->txWits ^. bootAddrWitsL
getField @"script" txWits
->txWits ^. scriptWitsL
getField @"dats" txWits
->txWits ^. datsWitsL
getField @"rdmrs" txWits
->txWits ^. rdmrsWitsL
Removal of constraint type synonyms
All of the
Trans*
,Uses*
constraints have been removed as they are fullyreplaced by the above hierarchy
Names removed and their closest replacements:
BlockAnn
->EraTx
ChainData
- no replacemnt, this was just an adhoc collection of classesSerialisableData,
AnnotatedData
->FromCBOR (Annotator t)
+ToCBOR t
SerialisableData
->FromCBOR t
+ToCBOR t
WellFormed
->EraTx
Val
classAddition of two class methods that allow efficient manipulation of compact coin
representation:
injectCompact
andmodifyCompactCoin
, without uncompactingthe actual type
t
for which theVal
instance is being definedData type renaming
All concrete types for every era where either inconsistent or clashing with the
core type families:
Module restructure:
Concrete era data type (eg.
BabageEra
) is no longer defined at the top levelmodule (eg.
Cardano.Ledger.Babbage
), but rather in a new private.Era
module(eg.
Cardano.Ledger.Babbage.Era
). It is later re-exported from the top levelmodule together with all of the orphan instances. This allows us to define all
of the relevant instances in their respective modules (eg.
EraTxBody
is definedin the
TxBody
module)Other minor changes
NFData
forSized
Cardano.Ledger.Shelley.Address.Bootstrap
(
cardano-ledger-shelley
) ->Cardano.Ledger.Keys.Bootstrap
(cardano-ledger-core
)langsUsed
into tests, since that was the only use site.