tweag / cooked-validators

MIT License
39 stars 11 forks source link

Contract instance #243

Closed carlhammann closed 2 months ago

carlhammann commented 1 year ago

This PR implements the MonadBlockChain instance for the plutus-apps Contract monad. As this necessitated an update to the plutus-apps version we depend on, it might be worthwhile to look at this PR in two diffs:

  1. A mechanical adjustment of dependencies and import statements.
  2. The interesting part.

Merging this PR will close #129 and close #78. Here are the main changes:

The same balancing for both monads

In order to close #129, I decided to factor out the common steps of balancing the TxSkel and generating a balanced Tx BabbageEra into a new module Cooked.MockChain.Balancing, which is used by both for the MonadBlockChain instance of our own direct implementation and for the Contract monad. You will see that the size of Cooked.MockChain.Direct decreased drastically as a consequence and that the implementation of validateTxSkel is now very concise (as it also is for the Contract monad).

Changed primitives in MonadBlockChain

In order to implement balancing for both monads, I decided to introduce another class below MonadBlockChainWithoutValidation, called MonadBlockChainBalancing that has a minimal set of primitives needed for balancing.

I also decided to change the type of the primitives that return a TxOut so that they return a Ledger.TxOut, and not a TxInfo-TxOut. The latter can always be obtained from the former, but not vice versa. This means that allUtxos and friends are now not primitives any more, but defined in terms of primitives. See Issue #239 for some further improvements I think are necessary in this area.

Open questions / What's left to do

carlhammann commented 1 year ago

As this turns out to be hairier than expected, I decided to separate individually valuable contributions out to separate PRs #250 and #251.

Niols commented 1 year ago

Now that https://github.com/tweag/cooked-validators/pull/311 has been merged, you will have a hairy conflict with main to resolve... Apart from that, what is the status of this PR? It hasn't moved in a month.

carlhammann commented 1 year ago

what is the status of this PR?

The status is that we decided to not have the (surprisingly hairy) Contract instance as a part of the v2.0.0 release, and focus our energies on something else. I think this specific PR will never be merged, but I want to keep it around as reference for when we finally decide to bite the bullet an implement the instance.

carlhammann commented 1 year ago

In particular, the three (merged) PRs #252, #250, and #251 were all derived from work done here first. So, I think this has already served as a good exploration vessel.

mmontin commented 2 months ago

I am closing this one because it is outdated, and it is very unlikely that we will need a Contract instance for MonadBlockChain in the future. If we do for future reasons, we will take inspiration from this one.