IntersectMBO / IntersectMBO/plutus
Explicit ToJSON/FromJSON conversions for costing types
- Dominant language
- Haskell
- Stars
- 1.6k
- Forks
- 508
- Avg merge
- 3d 10h
- Merged PRs (30d)
- 22
Description
We need to be able to convert our costing types to and from JSON, for example so that we can read cost models from JSON configuration files. Currently all of this is done using Aeson's `FromJSON` and `ToJSON` classes, and the instances are all [automatically derived](https://github.com/IntersectMBO/plutus/blob/master/plutus-core/plutus-core/src/PlutusCore/Evaluation/Machine/CostingFun/JSON.hs), which involves automatically generating JSON tags from constructor names. This is convenient in some ways, but not in others. For example, if we generalise a costing function type then the names of the tags may change and we'll no longer be able to read in old configuration files: see [this Note](https://github.com/IntersectMBO/plutus/blob/d319fe5844cf9fc791510d7b63bf76322a97d2d5/plutus-core/plutus-core/src/PlutusCore/Evaluation/Machine/CostingFun/Core.hs#L336). To [maintain compatibility with the Alonzo genesis file](https://github.com/IntersectMBO/plutus/pull/5932) we've had to retain [at least one old type](https://github.com/IntersectMBO/plutus/blob/d319fe5844cf9fc791510d7b63bf76322a97d2d5/plutus-core/plutus-core/src/PlutusCore/Evaluation/Machine/CostingFun/Core.hs#L312) that's been subsumed by a newer more general type. If we had explicit JSON conversions then we'd be able to convert JSON data with the old tag into objects of the new type and remove the old type again. We'd need a lot of code for explicit conversions, but that would probably be justified by the extra flexibility.
[Radical alternative: do away with JSON altogether and use some other textual format.]
Contributor guide
Assessment
This issue has not been assessed yet.