Skip to content

Commit

Permalink
Merge pull request #659 from input-output-hk/kll/merge-main-into-next…
Browse files Browse the repository at this point in the history
…-node-2022-08-11

Merge commits from main into next-node (2022-08-12)
  • Loading branch information
koslambrou authored Aug 12, 2022
2 parents af566dd + 593ffaf commit 19e1e6c
Show file tree
Hide file tree
Showing 24 changed files with 629 additions and 178 deletions.
8 changes: 4 additions & 4 deletions bitte/static-site.nix
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ let
".jpg" => "image/jpeg",
".jpeg" => "image/jpeg",
".html" => "text/html",
".js" => "text/javascript",
".svg" => "image/svg+xml",
".js" => "text/javascript",
".svg" => "image/svg+xml",
)
deflate.cache-dir = "/tmp"
deflate.mimetypes = ("text/plain", "text/html", "text/css")
deflate.cache-dir = "/tmp"
deflate.mimetypes = ("text/plain", "text/html", "text/css")
server.upload-dirs = ("/tmp")
'';
in
Expand Down
7 changes: 0 additions & 7 deletions cabal.project
Original file line number Diff line number Diff line change
Expand Up @@ -117,13 +117,6 @@ source-repository-package
location: https://github.com/input-output-hk/purescript-bridge
tag: 47a1f11825a0f9445e0f98792f79172efef66c00

-- Direct dependency.
-- Temporary indexing
source-repository-package
type: git
location: https://github.com/raduom/hysterical-screams
tag: 4c523469e9efd3f0d10d17da3304923b7b0e0674

-- Direct dependency.
source-repository-package
type: git
Expand Down
83 changes: 83 additions & 0 deletions doc/adr/0006-common-contract-api.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
.. _common_pab_api:

ADR 6: Common Contract API
==========================

Date: 2022-07-12

Authors
-------

Gergely Szabo <gergely@mlabs.city>

koslambrou <konstantinos.lambrou@iohk.io>

Status
------

Proposed

Context
-------

There are multiple implementations of a Plutus Application Backend (PAB) external of IO Global, and also other tools related to Plutus smart contracts.
Some of them are using the same contract interface as the official implementation, but some of them use a different interface.
However, as the ecosystem evolves, it would be beneficial to create a well defined standard, that other off-chain tools can use as a reference, or as an interface to implement.

Currently, as we are getting close to the Vasil hardfork, testing tools and Plutus Application backend tools are at a hurry to update their dependencies and get to a Vasil compliant/compatible state.
However, tools that are depending on `plutus-apps` are blocked by the PAB development.
This initiative was born out of this context, but could solve other problems as well.

The Contract API (defined in `plutus-apps/plutus-contract`) is using the `freer-simple` effect system to define all the contract effects.
This already allows us to separate the interface from the implementation, and to have multiple implementations/interpreters for one interface.
Currently, there are two implementations for the Contract API:

* one for the plutus-apps emulator (inside `plutus-apps/plutus-contract`)
* one for plutus-apps' Plutus Application Backend (inside `plutus-apps/plutus-pab`)

Therefore, we can leverage this separatation of interface and implementation in order to move the interface out of `plutus-apps`.

Decision
--------

* We will split the `plutus-apps/plutus-contract` package into two parts: the Contract API (`plutus-contract`) and the emulator (`plutus-contract-emulator`).

* We will create effects for the constraints-based transaction builder library (`plutus-apps/plutus-ledger-constraints`) in the Contract API.
Currently, the interface and the implementation in the transaction builder library are tightly coupled.
Therefore, we need to decouple them.

* We will create a separate repository with the contract effects and types (the splitted `plutus-contract`).
By moving the Contract API out of the plutus-apps monorepository, any tool could update to newer version to their discretion.
Without many dependencies, many tools could utilize the Contract API without having to depend on the whole plutus-apps monorepo.

* We (the Plutus Tools at IO Global) will continue to be the main maintainers of this new repository.
However, a new ADR will need to be created if we ever decide to make this a community driven project.

* TODO: What about governance? How do we decide which interface changes are accepted? ADRs? Who ultimately accepts and rejects them?

Argument
--------

We speed up the development of off-chain tools, by loosening up some of tightly coupled dependencies, so these external projects can move more freely.
This would also mean that the cost of the interface update would be reduced, so we could see more features added to the standard, and the PAB API following the capabilities of Cardano more closely.
As an added benefit, community involvement with the API could also greatly improve.

A standard API for all Plutus contacts would help keeping the ecosystem on the same track with their implementation.
As more and more off-chain tools implement the same contract interface in the future, it will be relatively easy to switch between different Plutus Application Backend implementations, or to use multiple of these tools at the same time without a need for serious code rewrites.

The implementation of the Contract API interface would track a specific version of the Contract API interface.
We would then need to regularly update the implementation given any interface changes.

Implications
------------

* We will need to decide if we should make this a community driven project.
If so, we will also need to make a decision about governance.
How do we decide which interface changes are accepted?
Do we use ADRs?
Who ultimately accepts and rejects them?

Notes
-----

This ADR has been discussed here: `#586 <https://github.com/input-output-hk/plutus-apps/pull/586>`_.
47 changes: 47 additions & 0 deletions doc/adr/0007-support-reference-inputs-in-constraint-library.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
.. _support_reference_inputs_in_constraint_library:

ADR 7: Support reference inputs in constraint library
=====================================================

Date: 2022-08-09

Authors
-------

koslambrou <konstantinos.lambrou@iohk.io>

Status
------

Proposed

Context
-------

After the Vasil HF, the Cardano blockchain will support `reference` inputs by adding a new field in the transaction data type.
With reference inputs, transactions can take a look at UTXOs without actually spending them.

Thus, we need to adapt our transaction constraint data type (`TxConstraints`) to support referencing UTXOs.

Decision
--------

* We will add the data constuctor `MustReferenceOutput TxOutRef` to the `TxConstraints` data type.

* The PlutusV1 on-chain implementation of this new constraint will simply return `False`.
However, `cardano-ledger` throws a phase-1 validation error if transactions that use the some of the new features (reference inputs, inline datums and reference scripts) try to execute PlutusV1 scripts.
See the `Babbage era ledger specification <https://hydra.iohk.io/job/Cardano/cardano-ledger/specs.babbage-ledger/latest/download-by-type/doc-pdf/babbage-changes>`_.
Therefore, the only way to get a phase-2 validation error would be to use this constraint on-chain in a PlutusV1 script, without using any of the new Babbage era features off-chain.

* The PlutusV2 on-chain implementation of this new constraint will check that the provided `TxOutRef` is part of the `ScriptContext`'s reference inputs.

Argument
--------

At first glance, we might think that we need two data constructors for reference inputs such as `MustReferencePubKeyOutput` and `MustReferenceScriptOutput` in contrast to the existing `MustSpendPubKeyOutput` and `MustSpendScriptOutput` constraints.
However, we do not need to make the distinction between public key outputs and script outputs because we're not spending the output, therefore, we don't need to provide a redeemer nor the actual script as a witness to the transaction input.

Notes
-----

This ADR has been partially addressed on PR `#640 <https://github.com/input-output-hk/plutus-apps/pull/640>`_.
2 changes: 2 additions & 0 deletions doc/adr/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,5 @@ The general process for creating an ADR is:
0003-marconi-monorepo
0004-marconi-initiative
0005-pab-indexing-solution-integration
0006-common-contract-api
0007-support-reference-inputs-in-constraint-library
1 change: 0 additions & 1 deletion nix/pkgs/haskell/sha256map.nix
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
"https://github.com/input-output-hk/servant-purescript"."44e7cacf109f84984cd99cd3faf185d161826963" = "10pb0yfp80jhb9ryn65a4rha2lxzsn2vlhcc6xphrrkf4x5lhzqc";
"https://github.com/input-output-hk/typed-protocols"."181601bc3d9e9d21a671ce01e0b481348b3ca104" = "sha256-5Wof5yTKb12EPY6B8LfapX18xNZZpF+rvhnQ88U6KdM=";
"https://github.com/input-output-hk/Win32-network"."3825d3abf75f83f406c1f7161883c438dac7277d" = "19wahfv726fa3mqajpqdqhnl9ica3xmf68i254q45iyjcpj1psqx";
"https://github.com/raduom/hysterical-screams"."4c523469e9efd3f0d10d17da3304923b7b0e0674" = "0w118v4vffrsjxfmwfv8qcn2qxmxpd1gxwcjnda91qz09jnpg0vp";
"https://github.com/sevanspowell/hw-aeson"."b5ef03a7d7443fcd6217ed88c335f0c411a05408" = "1dwx90wqavdl4d0npbzbxyh2pzi9zs1qz7nvsrb3n1cm2xbv4i5z";
"https://github.com/vshabanov/ekg-json"."00ebe7211c981686e65730b7144fbf5350462608" = "sha256-VT8Ur585TCn03P2TVi6t92v2Z6tl8vKijICjse6ocv8=";
}
2 changes: 1 addition & 1 deletion plutus-chain-index/app/Marconi.hs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ import Data.Proxy (Proxy (Proxy))
import Data.Set (Set)
import Data.Set qualified as Set
import Data.String (IsString)
import Index.VSplit qualified as Ix
import Ledger (TxIn (..), TxOut (..), TxOutRef (..))
import Ledger.Tx.CardanoAPI (fromCardanoTxId, fromCardanoTxIn, fromCardanoTxOut, fromTxScriptValidity,
scriptDataFromCardanoTxBody)
Expand All @@ -39,6 +38,7 @@ import Marconi.Index.Utxo qualified as Utxo
import Marconi.Logging (logging)
import Options.Applicative (Mod, OptionFields, Parser, auto, execParser, flag', help, helper, info, long, maybeReader,
metavar, option, readerError, strOption, (<**>), (<|>))
import Plutus.HystericalScreams.Index.VSplit qualified as Ix
import Plutus.Streaming (ChainSyncEvent (RollBackward, RollForward), ChainSyncEventException (NoIntersectionFound),
withChainSyncEventStream)
import Plutus.V1.Ledger.Api (Datum, DatumHash)
Expand Down
4 changes: 2 additions & 2 deletions plutus-chain-index/app/Marconi/Index/Datum.hs
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ import Database.SQLite.Simple.FromField (FromField (fromField), ResultError (Con
import Database.SQLite.Simple.ToField (ToField (toField))

import Cardano.Api (SlotNo (SlotNo))
import Index.VSqlite (SqliteIndex)
import Index.VSqlite qualified as Ix
import Ledger.Scripts (Datum, DatumHash)
import Plutus.HystericalScreams.Index.VSqlite (SqliteIndex)
import Plutus.HystericalScreams.Index.VSqlite qualified as Ix

type Event = [(SlotNo, (DatumHash, Datum))]
type Query = DatumHash
Expand Down
4 changes: 2 additions & 2 deletions plutus-chain-index/app/Marconi/Index/Utxo.hs
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ import Ledger (Address, TxId, TxOut, TxOutRef (TxOutRef, txOutRefId, txOutRefIdx
import Ledger qualified as Ledger
import System.Random.MWC (createSystemRandom, uniformR)

import Index.VSqlite (SqliteIndex)
import Index.VSqlite qualified as Ix
import Plutus.HystericalScreams.Index.VSqlite (SqliteIndex)
import Plutus.HystericalScreams.Index.VSqlite qualified as Ix

data UtxoUpdate = UtxoUpdate
{ _inputs :: !(Set TxOutRef)
Expand Down
6 changes: 3 additions & 3 deletions plutus-chain-index/plutus-chain-index.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -126,9 +126,9 @@ executable marconi
-- Local components
--------------------
build-depends:
, hysterical-screams
, plutus-ledger >=1.0.0
, plutus-streaming >=1.0.0
, plutus-hysterical-screams
, plutus-ledger >=1.0.0
, plutus-streaming >=1.0.0

--------------------------
-- Other IOG dependencies
Expand Down
4 changes: 3 additions & 1 deletion plutus-contract/plutus-contract.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,9 @@ test-suite plutus-contract-test
Spec.Secrets
Spec.State
Spec.ThreadToken
Spec.TimeValidity
Spec.TxConstraints.MustSpendAtLeast
Spec.TxConstraints.RequiredSigner
Spec.TxConstraints.TimeValidity

--------------------
-- Local components
Expand Down
2 changes: 1 addition & 1 deletion plutus-contract/src/Wallet/Emulator/Chain.hs
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ validateEm h cUtxoIndex txn = do
let (e, events) = txn & mergeCardanoTxWith
(\tx -> Index.runValidation (Index.validateTransaction h tx) ctx)
(\tx -> validateL params h cUtxoIndex tx)
(\(e1, sve1) (e2, sve2) -> (e1 <|> e2, sve1 ++ sve2))
(\(e1, sve1) (e2, sve2) -> (e2 <|> e1, sve2 ++ sve1))
idx' = case e of
Just (Index.Phase1, _) -> idx
Just (Index.Phase2, _) -> Index.insertCollateral txn idx
Expand Down
10 changes: 6 additions & 4 deletions plutus-contract/src/Wallet/Emulator/MultiAgent.hs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import Ledger hiding (to, value)
import Ledger.Ada qualified as Ada
import Ledger.AddressMap qualified as AM
import Ledger.Index qualified as Index
import Ledger.Value qualified as Value
import Plutus.ChainIndex.Emulator qualified as ChainIndex
import Plutus.Contract.Error (AssertionError (GenericAssertion))
import Plutus.Trace.Emulator.Types (ContractInstanceLog, EmulatedWalletEffects, EmulatedWalletEffects', UserThreadMsg)
Expand Down Expand Up @@ -303,12 +304,13 @@ emulatorStateInitialDist mp = emulatorStatePool [EmulatorTx tx] where
, txData = mempty
}
-- See [Creating wallets with multiple outputs]
mkOutputs (key, vl) = mkOutput key <$> splitHeadinto10 (Wallet.splitOffAdaOnlyValue vl)
splitHeadinto10 [] = []
splitHeadinto10 (vl:vls) = replicate (fromIntegral count) (Ada.toValue . (`div` count) . Ada.fromValue $ vl) ++ vls
mkOutputs (key, vl) = mkOutput key <$> splitInto10 vl
splitInto10 vl = replicate (fromIntegral count) (Ada.toValue (ada `div` count)) ++ remainder
where
ada = if Value.isAdaOnlyValue vl then Ada.fromValue vl else Ada.fromValue vl - minAdaTxOut
-- Make sure we don't make the outputs too small
count = min 10 $ Ada.fromValue vl `div` minAdaTxOut
count = min 10 $ ada `div` minAdaTxOut
remainder = [ vl <> Ada.toValue (-ada) | not (Value.isAdaOnlyValue vl) ]
mkOutput key vl = pubKeyHashTxOut vl (unPaymentPubKeyHash key)

type MultiAgentEffs =
Expand Down
Loading

0 comments on commit 19e1e6c

Please sign in to comment.