Skip to content
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

Use machine readable output for ToJSON ScriptWitnessIndex #5168

Conversation

newhoggy
Copy link
Contributor

@newhoggy newhoggy commented Apr 28, 2023

Description

  • New ToJSON ScriptWitnessIndex instance
  • Any JSON output uses this instance.
  • In JSON logging, "ExtraRedeemers" object contents are machine readable rather than difficult-to-parse user-friendly-string.

Checklist

  • Commit sequence broadly makes sense and commits have useful messages
  • New tests are added if needed and existing tests are updated. These may include:
    • golden tests
    • property tests
    • roundtrip tests
    • integration tests
      See Runnings tests for more details
  • Any changes are noted in the CHANGELOG.md for affected package
  • The version bounds in .cabal files are updated
  • CI passes. See note on CI. The following CI checks are required:
    • Code is linted with hlint. See .github/workflows/check-hlint.yml to get the hlint version
    • Code is formatted with stylish-haskell. See .github/workflows/stylish-haskell.yml to get the stylish-haskell version
    • Code builds on Linux, MacOS and Windows for ghc-8.10.7 and ghc-9.2.7
  • Self-reviewed the diff

Note on CI

If your PR is from a fork, the necessary CI jobs won't trigger automatically for security reasons.
You will need to get someone with write privileges. Please contact IOG node developers to do this
for you.

@newhoggy newhoggy force-pushed the newhoggy/use-machine-readable-output-for-ToJSON-ScriptWitnessIndex branch from 29414ae to 87a0591 Compare April 28, 2023 09:06
@newhoggy newhoggy marked this pull request as ready for review April 28, 2023 09:07
@newhoggy newhoggy force-pushed the newhoggy/use-machine-readable-output-for-ToJSON-ScriptWitnessIndex branch from 87a0591 to 3f4815c Compare April 28, 2023 09:08
@@ -4129,6 +4130,29 @@ data ScriptWitnessIndex =
| ScriptWitnessIndexWithdrawal !Word
deriving (Eq, Ord, Show)

instance ToJSON ScriptWitnessIndex where
toJSON = \case
ScriptWitnessIndexTxIn n ->
Copy link
Contributor

@carbolymer carbolymer Apr 28, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Manual instances are cumbersome in maintenance and error-prone. Maybe genericToJSON would be better here instead? For example:

data Foo = Foo !Text | Bar !Text | Baz !Text deriving (Generic)
genericToJSON (defaultOptions{sumEncoding=TaggedObject{tagFieldName="kind", contentsFieldName="value"}}) (Bar "barbar")

produces

{"kind":"Bar","value":"barbar"}

Copy link
Contributor Author

@newhoggy newhoggy Apr 29, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not certain that buys enough to justify the cost for a number of reasons.

We need to do this for LogFormatting and have no generic facility for that type class. If we have to manually type it out in one instance we may as well do it for both.

I use my editor's multi-cursor support and it takes very little time for something this regular.

My previous experience with aeson generic generation was that the compile time was quadratic and with a large enough type that actually became a problem.

I'm not sure if this particular case is quadratic, but that the problem exists gives me sufficient hesitation.

Copy link
Contributor

@carbolymer carbolymer May 2, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My main concern here is just an extra mental burden coming from the requirement to make proper changes in multiple places - what if you accidentally omit one place with your multi-cursor support? 😄

My previous experience with aeson generic generation was that the compile time was quadratic and with a large enough type that actually became a problem.

Fair point, and I agree that it matters here. I'm not insisting on using Generic here, but it would be better to have more safety either by using automatic generation of instances, or testing them in property tests.

PS. I had to roll-back prod deployment in the past once, because of faulty, manually written FromJSON instance, which was undetected for over a year, so I guess I'm a bit oversensitive on this topic. 😄

@newhoggy newhoggy requested a review from carbolymer April 29, 2023 00:13
@newhoggy newhoggy force-pushed the newhoggy/use-machine-readable-output-for-ToJSON-ScriptWitnessIndex branch from 3f4815c to 41da7b6 Compare April 29, 2023 00:17
@newhoggy
Copy link
Contributor Author

This might be worth doing a golden test for, so waiting on this input-output-hk/hedgehog-extras#31

@newhoggy newhoggy force-pushed the newhoggy/use-machine-readable-output-for-ToJSON-ScriptWitnessIndex branch from 41da7b6 to 988b868 Compare May 8, 2023 01:55
@newhoggy newhoggy force-pushed the newhoggy/use-machine-readable-output-for-ToJSON-ScriptWitnessIndex branch from 988b868 to a0e3505 Compare May 9, 2023 18:14
@newhoggy newhoggy enabled auto-merge May 9, 2023 18:15
@newhoggy newhoggy added this pull request to the merge queue May 10, 2023
Merged via the queue into master with commit 5103651 May 10, 2023
@iohk-bors iohk-bors bot deleted the newhoggy/use-machine-readable-output-for-ToJSON-ScriptWitnessIndex branch May 10, 2023 00:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants