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

Flesh out Plutarch.Api, port utilities #652

Merged
merged 13 commits into from
Apr 10, 2024
Merged

Flesh out Plutarch.Api, port utilities #652

merged 13 commits into from
Apr 10, 2024

Conversation

kozross
Copy link
Contributor

@kozross kozross commented Jan 24, 2024

Closes #636. This is a fairly major set of changes: a lot of identifiers have moved, some have vanished altogether, and a few bits still remain outstanding. Every change has been logged, but a few are a bit more 'invisible'.

Guide to migration

Essentially, a lot of stuff that used to be in plutarch-extra is now part of plutarch-api. Specifically, Plutarch.Extra.Map, Plutarch.Extra.Interval, Plutarch.Extra.Api have been wholesale ported into plutarch-api (either a submodule, or Plutarch.Api itself), and any part of Plutarch.Extra.Maybe to do with PMaybeData is now in Plutarch.Api as well. Furthermore, Plutarch.Api.* from the main Plutarch repo is now gone: everything that was there was moved to plutarch-api.

Most notable change is that now, the API is V2 only. V1 stuff is gone, and all data types and functionality that differed between V1 and V2 now defaults to V2. This is a temporary measure, as we're moving to V3 in short order. This may mean some data types have changed a bit: if your old data types or functions were V1, you need to migrate to their V2 versions.

A few things have been removed altogether, as they either have no V1 equivalents, weren't useful (or covered by tests), or are otherwise no longer required:

  • pnever (no V2 equivalent)
  • PTuple (type synonym, PTuple a b is identical to PBuiltinPair (PAsData a) (PAsData b))
  • All the functionality around different MergeHandlers (hidden for now unless someone wants it, pending a full rethink)
  • ptuple, ptupleFromBuiltin, pbuiltinPairFromTuple (no-ops anyway, now useless with PTuple being gone)
  • PValidator, PMintingPolicy, PStakingValidator (all types, just use their equivalents, which are PData :--> PData :--> PScriptContext :--> POpaque, PData :--> PScriptContext :--> POpaque and PData :--> PScriptContext :--> POpaque respectively)
  • IsList instances for PMap (were broken and a bad idea to begin with, use punsortedMapFromFoldable or psortedMapFromFoldable instead of fromList)

It is possible some functionality for PMap or PValue slipped by us: if you need it, please let us know and we'll do our best to restore it!

Outstanding tasks

In light of this PR landing, there are some remaining things to do:

  1. Some of our tests are currently stubbed out, as they don't fit within V1 requirements, or are somehow broken more fundamentally. These need restoring, either with or without more broad test revisions.
  2. Some functionality (particularly PMap functionality that used to be in plutarch-extra) has no test coverage. This should be dealt with, either with or without more broad test revisions.
  3. V3 API support needs to be added. This is a key requirement for CIP-1694.
  4. The rest of plutarch-extra needs to be subsumed into Plutarch itself, and the entire sublibrary needs to be eliminated.
  5. Documentation for many of the identifiers in the new plutarch-api is quite lacklustre, and needs improvement. This is particularly important for stuff coming from the Plutus side (such as data types), as this is a known confusion point. Examples of its use would also help drastically.
  6. All uses of type must be killed with fire. While efforts have been made to make plutarch-api free of that terrible idea, the rest of Plutarch still has rather a lot of it.

@SeungheonOh
Copy link
Collaborator

SeungheonOh commented Jan 25, 2024

  1. Note about deprecation of PTuple:

PTuple a b is identical to PAsData (PBuiltinPair (PAsData a) (PAsData b)) and therefore PBuiltinPair will entirely replace PTuple. Utility functions of PBuiltinPair will take over the removed utility functions of PTuple.

  1. Note about deprecation of IsList instances:

IsList instances of various type have been removed due to their incompleteness in definition. The reason being, in order to lift Plutarch Term into Haskell value, one needs to evaluate the underlying value a term holds. As evaluation is not pure, Plutarch types were unable to implement the toList instance of IsList type class, and they were left to throw error all the time.

  1. Note about deprecation of V1 API:

V1 plutus-ledger-api is no longer supported as of this PR. It is because there's no reason for users to develop and maintain script on older ledger API. V2 is strict superset of V1(and V3 is likely to be strict superset of V2) and therefore, nothing incentivizes using V1 ledger API over V2.

For existing codebase that is using V1(and V2, after V3 lands), they would need to bump their codebase, adapting to new api library. Since smart contract scripts are rather static objects, meaning they are hard to change easily nor frequently, discontinuation of old ledger API on Plutarch will not break existing and deployed onchain scripts. When replacing a old script, ledger version of the new script does not need to match that of old script; therefore, new ledger api can be used to build replacement script.

@bladyjoker
Copy link
Collaborator

Woohooo staging!

bladyjoker
bladyjoker previously approved these changes Jan 26, 2024
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.

Thanks folks!

`Plutrach.LedgerApi` for better consistency
Copy link
Collaborator

@SeungheonOh SeungheonOh left a comment

Choose a reason for hiding this comment

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

There are very few instances of commented out ledger api test cases, but we will eventually get better and separated test cases for ledger repo itself.

LGTM

@SeungheonOh SeungheonOh merged commit b482197 into staging Apr 10, 2024
2 checks passed
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.

Tests for V2 API spec
3 participants