Skip to content
This repository was archived by the owner on Dec 2, 2024. It is now read-only.

PLT-658: inline datum witnesses#765

Merged
sjoerdvisscher merged 10 commits intomainfrom
PLT-658-Inline-Datum-Witnesses
Oct 24, 2022
Merged

PLT-658: inline datum witnesses#765
sjoerdvisscher merged 10 commits intomainfrom
PLT-658-Inline-Datum-Witnesses

Conversation

@sjoerdvisscher
Copy link
Contributor

@sjoerdvisscher sjoerdvisscher commented Oct 19, 2022

Pre-submit checklist:

  • Branch
    • Tests are provided (if possible)
    • Commit sequence broadly makes sense
    • Key commits have useful messages
    • Formatting, PNG optimization, etc. are updated
  • PR
    • Self-reviewed the diff
    • Useful pull request description
    • Reference the ADR in the PR and reference the PR in the ADR (if revelant)
    • Reviewer requested

Copy link
Contributor

@berewt berewt left a comment

Choose a reason for hiding this comment

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

No blocker. The major concern I have is about the organisation of PSU and Ledger.Typed.Script but it could be discussed outside of thisPR.

, MonadError MkTxError m
)
=> ChainIndexTxOut -> m (Maybe (Versioned Validator, Datum, Value))
=> ChainIndexTxOut -> m (Maybe (Versioned Validator, (Datum, Bool), Value))
Copy link
Contributor

Choose a reason for hiding this comment

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

We can maybe change it to Maybe (Versioned Validator, Datum, Bool, Value)? It would improve readability when we need to consume the result of the function.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm not sure, the Bool really belongs to the Datum. I think I should just make yet another specific datatype. (It's really annoying that als these datum-related types have to be slightly different!)

Comment on lines +34 to +35
unsafeMkTypedValidator :: Versioned Validator -> TypedValidator Any
unsafeMkTypedValidator vl =
Copy link
Contributor

Choose a reason for hiding this comment

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

Not really related to the PR but still: did we officially decide of a strategy regarding the content of Ledger.Typed.Scripts vs PSU.Vx.Typed.Scripts modules? The deployment of V2 scripts may require clarification. We have an epic about cleaning the code after the Babbage era release, maybe we need to add a review/clean up/harmonisation of these modules to it? (cc @koslambrou)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'd say at least keep the version specific things as much as possible in PSU.Vx.Typed.Scripts, and let the rest work with Versioned scripts. It's tempting to export "the latest version" code from Ledger.Typed.Scripts too, but I'm not sure we should do that, and at least it would silently break a lot of our tests at the moment. (But that's a bug really, tests that depend on something being version 1 should explicitly import from V1 modules.)

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 say at least keep the version specific things as much as possible in PSU.Vx.Typed.Scripts, and let the rest work with Versioned scripts. It's tempting to export "the latest version" code from Ledger.Typed.Scripts too, but I'm not sure we should do that, and at least it would silently break a lot of our tests at the moment. (But that's a bug really, tests that depend on something being version 1 should explicitly import from V1 modules.)

Yes I was thinking of something alike, it would be quite aligned with Konstantinos' ADR about cardano API as well. We should probably stick to this behaviour in Ledger.Test as well (and maybe in other places, but I don't see where). At least it would give us a set of clearer rules to deal with plutus versions. This would probably imply moving Versioned to plutus-ledger as well?

Copy link
Contributor

@koslambrou koslambrou left a comment

Choose a reason for hiding this comment

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

LGTM. Just documentation comments.


mustSpendScriptOutputsInlineDatumHasNoDataInTx :: TestTree
mustSpendScriptOutputsInlineDatumHasNoDataInTx =
testGroup "mustSpendScriptOutput should not include datum in tx when spending a ref with inline datum"
Copy link
Contributor

Choose a reason for hiding this comment

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

The test group description is not accurate.

ScriptAddress !(Either (Versioned Validator) (Versioned TxOutRef)) !Redeemer !(Maybe Datum)
-- ^ A transaction input that consumes (with a validator) or references (with a txOutRef)
-- a script address with the given the redeemer and datum.
-- Datum is optional in case the input references an inline datum.
Copy link
Contributor

Choose a reason for hiding this comment

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

Mmm... What do you mean here exactly?

Do you actually mean "Datum is optional if the input refers to a script output which contains an inline datum"?

addScriptTxInput :: TxOutRef -> Versioned Validator -> Redeemer -> Datum -> Tx -> Tx
addScriptTxInput outRef vl rd dt tx@Tx{txInputs, txScripts, txData} = tx
{txInputs = TxInput outRef (TxScriptAddress rd (Left vlHash) dtHash) : txInputs,
-- Datum is optional when the reference points to an inline datum.
Copy link
Contributor

Choose a reason for hiding this comment

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

Same comment as above

addReferenceTxInput outRef vref rd dt tx@Tx{txInputs, txData} = tx
{txInputs = TxInput outRef (TxScriptAddress rd (Right vref) dtHash) : txInputs,
txData = Map.insert dtHash dt txData}
-- Datum is optional when the reference points to an inline datum.
Copy link
Contributor

Choose a reason for hiding this comment

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

Same comment as above.

@sjoerdvisscher sjoerdvisscher force-pushed the PLT-658-Inline-Datum-Witnesses branch from 7d01822 to 578be1e Compare October 22, 2022 13:39
@sjoerdvisscher sjoerdvisscher force-pushed the PLT-658-Inline-Datum-Witnesses branch from 7c52831 to 79eb64a Compare October 22, 2022 14:09
@sjoerdvisscher sjoerdvisscher merged commit 172873e into main Oct 24, 2022
@sjoerdvisscher sjoerdvisscher deleted the PLT-658-Inline-Datum-Witnesses branch October 24, 2022 15:17
kayvank pushed a commit that referenced this pull request Oct 27, 2022
* Support empty witness for inline datum reference

* Add test

* Fix merge issues

* Fix PureScript

* Clean up and documentation

* Replace (Datum, Bool) with DatumWithOrigin
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants