-
Notifications
You must be signed in to change notification settings - Fork 727
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
Conversation
7844ee4
to
4a36e28
Compare
This helps keep flake dependencies down & avoids having to go through a different team for changes to the scripts.
72fa031
to
74098c1
Compare
, bytestring | ||
, serialise | ||
, template-haskell | ||
, filepath |
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 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 ] |
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 will have quicker to perceive diffs, if we break this line to list-entry-per-line format:
[ 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)] |
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 might be easier to read:
= 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) ] |
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.
Also, further, last (split (=='.') . pack $ psName t) == pack (takeBaseName s)
might be worth binding to a local function name -- to hint at intended meaning.
bench/plutus-scripts-bench/src/Cardano/Benchmarking/PlutusScripts/CustomCall.hs
Show resolved
Hide resolved
data BenchScript | ||
= BenchScript | ||
{ psName :: String | ||
, psScript :: ScriptInAnyLang | ||
} |
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 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) |
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.
Again, to reach for easier diff reading time down the line:
(BenchScript, psName, psScript, mkBenchScript) | |
( BenchScript | |
, psName | |
, psScript | |
, mkBenchScript | |
) |
readPlutusScript fp | ||
readPlutusScript :: Either String FilePath -> IO (Either TxGenError ScriptInAnyLang) | ||
readPlutusScript (Left s) | ||
= return |
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.
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" } |
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'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:
- drop the
Left
wrappers from the profile definitions - unconditionally add the
Left
at the point where we pass the value totx-generator
So it'd be a Nix-only change.
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.
@NadiaYvette -- this is excellent work, thank you!
prepareScriptName :: String -> String | ||
prepareScriptName | ||
= head | ||
. dropWhile (=="hs") | ||
. map unpack | ||
. reverse | ||
. split (=='.') | ||
. last | ||
. split (=='/') | ||
. pack |
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.
https://hackage.haskell.org/package/filepath-1.4.100.3/docs/System-FilePath.html#v:dropExtension can simplify this a lot.
Commment what it's doing, make better use of filepath primitives, remove dependency on the text package, and use less golfy style.
1e8d37c
to
2fe2c43
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.
Thank you very much @NadiaYvette, great work.
Using TH-generated scripts helps keep flake dependencies down & avoids having to go through a different team for changes to the scripts.