7

In the docs about validators a function named unstableMakeIsData is used, but has the following comment:

-- 'unstableMakeIsData' is a TemplateHaskell function that takes a type name and
-- generates an 'IsData' instance definition for it. It should work for most
-- types, including newtypes and sum types. For production usage use 'makeIsDataIndexed'
-- which ensures that the output is stable across time.
unstableMakeIsData ''Date

It seems inconvenient to have code that needs to be changed for production so I'm curious why this is required. For example, why not just use makeIsDataIndexed in development too? What benefit does unstableMakeIsData have?

I tried searching for both function names across the docs, but the only instances are in two different comments along these same lines.

2
  • The URL is now broken. 404 Jul 2 at 23:15
  • @Elrond_EGLDer I've updated it to what seems to be the same page hosted on another domain. Thanks! Jul 4 at 8:58
5
+50

If you take a look at the code you can see that makeIsDataIndexed takes 2 arguments (datatype and mapping) but unstableMakeIsData takes only 1 argument, so it's faster to use (that's why it's used in examples)

enter image description here

Usage example:

PlutusTx.makeIsDataIndexed ''Action [('Deposit,0),('Choice,1),('Notify,2)]

With unstableMakeIsData it would look like this:

PlutusTx.unstableMakeIsData ''Action

You can find more context in this commit as well. Note, that unsafeMakeIsData was later renamed to unstableMakeIsData.

The old `makeIsData` would encode/decode based on the ordering of the
constructors, which isn't stable. We *need* this to be stable across
time, since tools other than our Haskell programs might be producing
datums/redeemers (e.g. CBOR tools in other languages), so we really
don't want this to change unexpectedly.

So we avoid it everywhere. The exception is the usecases: they're just
examples so it's fine for them to be unstable.

Marlowe is probably the most annoying, but I think we *do* care about
the Marlowe types being stable!
2
  • 1
    Aha, perfect! I didn't see any examples using makeIsData so didn't realise it took this extra data. Makes sense now, thank you! Jun 16 at 11:30
  • Great answer, I will award the bounty on Monday just in case somebody can come up with a better answer. But a better answer seems unlikely. :-)
    – gRebel
    Jun 17 at 4:16
0

makeIsDataIndexed take 2 values and we use it when we are working with stable data and we don't them to be changing in the future so we index them explicitly to ensure. Example: makeIsDataIndexed ''Bool [('False,0),('True,1)] so if we refer 1 we will get True and 0 False.

unstableMakeIsData only takes one value and this value won't be changing in the future which mean that there is no need to index it it is only one value. unstableMakeIsData ''() Hope it helps

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.