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

Add trace message codifier #709

Open
wants to merge 2 commits into
base: staging
Choose a base branch
from
Open

Conversation

SeungheonOh
Copy link
Collaborator

Small utility function to turn long messages into code table.

@SeungheonOh SeungheonOh changed the base branch from master to staging July 18, 2024 03:42
Copy link
Collaborator

@bladyjoker bladyjoker 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 @SeungheonOh , I would really like to see some tests covering this so the users don't discover any issues themselves.

@@ -65,19 +66,23 @@ common c
-Wincomplete-record-updates -Wmissing-deriving-strategies
-Wno-name-shadowing -Wunused-foralls -fprint-explicit-foralls
-fprint-explicit-kinds -Wno-unrecognised-warning-flags
-Wno-missing-export-lists
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why?

Copy link
Contributor

Choose a reason for hiding this comment

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

This is a weird leftover from earlier Plutarch days. Should be removed I think.

errorTagReplacer :: Int -> Text -> Maybe Text
errorTagReplacer n s =
if T.isPrefixOf "ERR:" s
then Just $ "CODE:" <> T.pack (show n)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Maybe also ERR:1 rather than CODE:1?

Comment on lines +21 to +22
codifyStrings :: (Int -> Text -> Maybe Text) -> Script -> (Script, [(Text, Text)])
codifyStrings codify (Script (UPLC.Program ann version terms)) =
Copy link
Collaborator

Choose a reason for hiding this comment

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

This should return a Map Text Text not a list?

collectErrorMessages uterm <> foldMap collectErrorMessages uterms

replaceMessages ::
[(Text, Text)] ->
Copy link
Collaborator

Choose a reason for hiding this comment

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

Also Map Text Text

Copy link
Contributor

@kozross kozross left a comment

Choose a reason for hiding this comment

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

Basically I think @bladyjoker beat me to most of the review.

Comment on lines +24 to +25
immap :: forall a b. (Int -> a -> Maybe b) -> [a] -> [(a, b)]
immap f xs = go 0 xs
Copy link
Contributor

Choose a reason for hiding this comment

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

Were you looking for this perhaps?

@L-as
Copy link
Member

L-as commented Jul 29, 2024

My thoughts:

  • I can't see why you want this TBF, when is this useful? You don't want strings on-chain anyway?
  • If you did want error codes on-chain, wouldn't it make more sense to use a more compact representation that uses the full extent of UTF-8?
  • Rather than doing this in a post-processing step, shouldn't ptrace etc. do this at generation time? You could add another alternative between the no tracing and full tracing options.

(Feel free to disregard of course, this isn't a "request change" review.)

@SeungheonOh
Copy link
Collaborator Author

This is per @bladyjoker 's request. I see this being very useful. IMO, not having any trace for mainnet script was a huge mistake, at least for Liqwid. Anytime script threw up, it was massive pain to recreate that with scripts with tracing to actually figure out what went wrong. Codifying error messages would save a lot of efforts without not much cost since it will be reference script anyways.

As for UTF-8 codes, I think that is a good idea. I change it to support UTF-8 tags.

Also, for having this on Plutarch's compile time, this was made to be external tool so that it can be used on already existing scripts as well. Also, deep integration to Plutarch was too much effort; this is small and portable. Maybe if we can get more funding on Plutarch, we can tackle this.

@L-as
Copy link
Member

L-as commented Jul 29, 2024

That makes more sense, but FWIW you should be able to just use the same inputs for the script to figure out why it failed.

@SeungheonOh
Copy link
Collaborator Author

Not really, in case of Liqwid, we'd need to deploy extra sets of scripts which will cost few hundred Ada and make changes to offchain in some annoying way. So, rather, we have this utility that extracts CBOR and input UTXOs in their resolved form into JSON. We import that to Haskell project and run the CEK manually. It is less painful for sure, but still immensely annoying. Not to mention, this is very offchain framework dependent.

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.

4 participants