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 TH-generated plutus scripts #5048

Merged
merged 5 commits into from
Apr 11, 2023
Merged

use TH-generated plutus scripts #5048

merged 5 commits into from
Apr 11, 2023

Conversation

NadiaYvette
Copy link
Contributor

@NadiaYvette NadiaYvette commented Apr 3, 2023

Using TH-generated scripts helps keep flake dependencies down & avoids having to go through a different team for changes to the scripts.

@NadiaYvette NadiaYvette added the WIP Work In Progress (cannot be merged yet) label Apr 3, 2023
@NadiaYvette NadiaYvette self-assigned this Apr 3, 2023
@NadiaYvette NadiaYvette force-pushed the nyc-plutus-bench-01 branch from 7844ee4 to 4a36e28 Compare April 3, 2023 15:08
This helps keep flake dependencies down & avoids having to go through a
different team for changes to the scripts.
@NadiaYvette NadiaYvette force-pushed the nyc-plutus-bench-01 branch from 72fa031 to 74098c1 Compare April 7, 2023 00:12
, bytestring
, serialise
, template-haskell
, filepath
Copy link
Contributor

Choose a reason for hiding this comment

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

We try to keep the package and module lists sorted.

, (normalizeModuleName Loop.scriptName , asAnyLang Loop.scriptSerialized)
, (normalizeModuleName Schnorr.scriptName , asAnyLang Schnorr.scriptSerialized)
]
[ CustomCall.script, ECDSA.script, Loop.script, Schnorr.script ]
Copy link
Contributor

Choose a reason for hiding this comment

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

This will have quicker to perceive diffs, if we break this line to list-entry-per-line format:

Suggested change
[ CustomCall.script, ECDSA.script, Loop.script, Schnorr.script ]
[ CustomCall.script
, ECDSA.script
, Loop.script
, Schnorr.script
]

findPlutusScript
= (`lookup` getAllScripts)
findPlutusScript s
= listToMaybe [psScript t | t <- getAllScripts, last (split (=='.') . pack $ psName t) == pack (takeBaseName s)]
Copy link
Contributor

@deepfire deepfire Apr 7, 2023

Choose a reason for hiding this comment

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

I think this might be easier to read:

Suggested change
= listToMaybe [psScript t | t <- getAllScripts, last (split (=='.') . pack $ psName t) == pack (takeBaseName s)]
= listToMaybe [ psScript t
| t <- getAllScripts
, last (split (=='.') . pack $ psName t) == pack (takeBaseName s) ]

Copy link
Contributor

Choose a reason for hiding this comment

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

Also, further, last (split (=='.') . pack $ psName t) == pack (takeBaseName s) might be worth binding to a local function name -- to hint at intended meaning.

Comment on lines 10 to 14
data BenchScript
= BenchScript
{ psName :: String
, psScript :: ScriptInAnyLang
}
Copy link
Contributor

@deepfire deepfire Apr 7, 2023

Choose a reason for hiding this comment

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

I apologise for not raising this matter sooner, since it'd save work, but I can't fail to mention this either.

The choice of name here is a bit confusing -- if taken with a bit of a wider context "bench script" can mean different things in the benchmarking automation ecosystem.

A bit more specificity, like, perhaps, but not necessarily, PlutusBenchScript or PlutusWorkloadScript would be really useful.

{-# OPTIONS_GHC -fno-warn-orphans #-}

module Cardano.Benchmarking.ScriptAPI
(BenchScript, psName, psScript, mkBenchScript)
Copy link
Contributor

@deepfire deepfire Apr 7, 2023

Choose a reason for hiding this comment

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

Again, to reach for easier diff reading time down the line:

Suggested change
(BenchScript, psName, psScript, mkBenchScript)
( BenchScript
, psName
, psScript
, mkBenchScript
)

readPlutusScript fp
readPlutusScript :: Either String FilePath -> IO (Either TxGenError ScriptInAnyLang)
readPlutusScript (Left s)
= return
Copy link
Contributor

Choose a reason for hiding this comment

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

Very minor, but pure in stead of return is more suggestive.

@@ -276,7 +276,7 @@ def all_profile_variants:
({ generator:
{ plutus:
{ type: "LimitSaturationLoop"
, script: "v1/loop.plutus"
, script: { "Left": "Loop.hs" }
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd question whether the .hs suffix really belong in the script names.

We want the script name to be present in the reports -- and the report generator (and the rest of the workbench, by the way) mostly treats profile definitions as abstract, where all names are clean and usable directly.

If the report generator had to do the .hs suffix stripping, that'd be a pretty severe violation of the abstraction.

The same goes for the Left/Right wrappers -- they'd be unnatural to deal with.

So what I suggest -- since we're unlikely to use the Plutus scripts directly -- they all depend on the script-specific tx-generator knowledge to run them -- to just:

  1. drop the Left wrappers from the profile definitions
  2. unconditionally add the Left at the point where we pass the value to tx-generator

So it'd be a Nix-only change.

Copy link
Contributor

@deepfire deepfire left a comment

Choose a reason for hiding this comment

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

@NadiaYvette -- this is excellent work, thank you!

Comment on lines 24 to 33
prepareScriptName :: String -> String
prepareScriptName
= head
. dropWhile (=="hs")
. map unpack
. reverse
. split (=='.')
. last
. split (=='/')
. pack
Copy link
Contributor

Choose a reason for hiding this comment

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

Commment what it's doing, make better use of filepath primitives,
remove dependency on the text package, and use less golfy style.
@mgmeier mgmeier force-pushed the nyc-plutus-bench-01 branch from 1e8d37c to 2fe2c43 Compare April 11, 2023 15:23
Copy link
Contributor

@mgmeier mgmeier left a comment

Choose a reason for hiding this comment

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

Thank you very much @NadiaYvette, great work.

@NadiaYvette NadiaYvette removed the WIP Work In Progress (cannot be merged yet) label Apr 11, 2023
@mgmeier mgmeier enabled auto-merge April 11, 2023 15:28
@mgmeier mgmeier added this pull request to the merge queue Apr 11, 2023
Merged via the queue into master with commit 26af241 Apr 11, 2023
@iohk-bors iohk-bors bot deleted the nyc-plutus-bench-01 branch April 11, 2023 16:24
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