Skip to content
Permalink

Comparing changes

This is a direct comparison between two commits made in this repository or its related repositories. View the default comparison for this range or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: cardano-scaling/hydra
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 1cce7d3a370b200320a385cca563f28b45282b0f
Choose a base ref
..
head repository: cardano-scaling/hydra
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 8bef572559db501aee82bc4bed2ea8c356fbd900
Choose a head ref
Showing with 141 additions and 238 deletions.
  1. +2 −0 .github/workflows/ci-nix.yaml
  2. +2 −6 docs/docs/tutorial/index.md
  3. +0 −1 hydra-cardano-api/hydra-cardano-api.cabal
  4. +0 −1 hydra-cardano-api/src/Hydra/Cardano/Api.hs
  5. +0 −14 hydra-cardano-api/src/Hydra/Cardano/Api/PlutusScript.hs
  6. +2 −3 hydra-cardano-api/src/Hydra/Cardano/Api/ReferenceScript.hs
  7. +0 −2 hydra-cardano-api/src/Hydra/Cardano/Api/ScriptHash.hs
  8. +71 −131 hydra-cluster/src/Hydra/Cluster/Scenarios.hs
  9. +13 −14 hydra-node/src/Hydra/Chain/Direct/State.hs
  10. +12 −12 hydra-node/src/Hydra/Chain/Direct/Tx.hs
  11. +2 −3 hydra-node/test/Hydra/Chain/Direct/StateSpec.hs
  12. +1 −1 hydra-plutus/exe/inspect-script/Main.hs
  13. +5 −5 hydra-plutus/src/Hydra/Contract.hs
  14. +1 −13 hydra-plutus/src/Hydra/Contract/Dummy.hs
  15. +2 −3 hydra-plutus/src/Hydra/Contract/HeadTokens.hs
  16. +2 −2 hydra-plutus/test/Hydra/Plutus/GoldenSpec.hs
  17. +3 −3 hydra-tx/src/Hydra/Tx/Abort.hs
  18. +1 −1 hydra-tx/src/Hydra/Tx/Close.hs
  19. +2 −2 hydra-tx/src/Hydra/Tx/CollectCom.hs
  20. +1 −1 hydra-tx/src/Hydra/Tx/Commit.hs
  21. +1 −1 hydra-tx/src/Hydra/Tx/Contest.hs
  22. +1 −1 hydra-tx/src/Hydra/Tx/Decrement.hs
  23. +2 −2 hydra-tx/src/Hydra/Tx/Deposit.hs
  24. +1 −1 hydra-tx/src/Hydra/Tx/Fanout.hs
  25. +2 −2 hydra-tx/src/Hydra/Tx/Increment.hs
  26. +2 −2 hydra-tx/src/Hydra/Tx/Init.hs
  27. +2 −2 hydra-tx/src/Hydra/Tx/Recover.hs
  28. +1 −2 hydra-tx/src/Hydra/Tx/Utils.hs
  29. +4 −4 hydra-tx/test/Hydra/Tx/Contract/Abort.hs
  30. +2 −2 hydra-tx/test/Hydra/Tx/Contract/CollectCom.hs
  31. +1 −1 hydra-tx/testlib/Test/Hydra/Tx/Mutation.hs
2 changes: 2 additions & 0 deletions .github/workflows/ci-nix.yaml
Original file line number Diff line number Diff line change
@@ -15,6 +15,8 @@ on:
schedule:
# Everyday at 4:00 AM
- cron: "0 4 * * *"
# Allows to trigger runs on any branch
workflow_dispatch:

permissions:
checks: write
8 changes: 2 additions & 6 deletions docs/docs/tutorial/index.md
Original file line number Diff line number Diff line change
@@ -46,15 +46,13 @@ that you have a good version of jq with this command:
```shell
mkdir -p bin
hydra_version=0.19.0
mithril_version=2437.1
cardano_node_version=10.1.2
curl -L -O https://github.com/cardano-scaling/hydra/releases/download/${hydra_version}/hydra-x86_64-linux-${hydra_version}.zip
unzip -d bin hydra-x86_64-linux-${hydra_version}.zip
curl -L -O https://github.com/IntersectMBO/cardano-node/releases/download/${cardano_node_version}/cardano-node-${cardano_node_version}-linux.tar.gz
tar xf cardano-node-${cardano_node_version}-linux.tar.gz ./bin/cardano-node ./bin/cardano-cli
tar xf cardano-node-${cardano_node_version}-linux.tar.gz ./share/preprod --strip-components=3
curl -L -o - https://github.com/input-output-hk/mithril/releases/download/${mithril_version}/mithril-${mithril_version}-linux-x64.tar.gz \
| tar xz -C bin mithril-client
curl --proto '=https' --tlsv1.2 -sSf https://raw.githubusercontent.com/input-output-hk/mithril/refs/heads/main/mithril-install.sh | sh -s -- -c mithril-client -d latest -p bin
chmod +x bin/*
```

@@ -64,15 +62,13 @@ chmod +x bin/*
```shell
mkdir -p bin
hydra_version=0.19.0
mithril_version=2437.1
cardano_node_version=10.1.2
curl -L -O https://github.com/cardano-scaling/hydra/releases/download/${hydra_version}/hydra-aarch64-darwin-${hydra_version}.zip
unzip -d bin hydra-aarch64-darwin-${hydra_version}.zip
curl -L -O https://github.com/IntersectMBO/cardano-node/releases/download/${cardano_node_version}/cardano-node-${cardano_node_version}-macos.tar.gz
tar xf cardano-node-${cardano_node_version}-macos.tar.gz --wildcards ./bin/cardano-node ./bin/cardano-cli './bin/*.dylib'
tar xf cardano-node-${cardano_node_version}-macos.tar.gz ./share/preprod --strip-components=3
curl -L -o - https://github.com/input-output-hk/mithril/releases/download/${mithril_version}/mithril-${mithril_version}-macos-x64.tar.gz \
| tar xz -C bin
curl --proto '=https' --tlsv1.2 -sSf https://raw.githubusercontent.com/input-output-hk/mithril/refs/heads/main/mithril-install.sh | sh -s -- -c mithril-client -d latest -p bin
chmod +x bin/*
```

1 change: 0 additions & 1 deletion hydra-cardano-api/hydra-cardano-api.cabal
Original file line number Diff line number Diff line change
@@ -51,7 +51,6 @@ library
Hydra.Cardano.Api.Hash
Hydra.Cardano.Api.Network
Hydra.Cardano.Api.NetworkId
Hydra.Cardano.Api.PlutusScript
Hydra.Cardano.Api.PolicyId
Hydra.Cardano.Api.Prelude
Hydra.Cardano.Api.Pretty
1 change: 0 additions & 1 deletion hydra-cardano-api/src/Hydra/Cardano/Api.hs
Original file line number Diff line number Diff line change
@@ -129,7 +129,6 @@ import Hydra.Cardano.Api.CtxTx as Extras
import Hydra.Cardano.Api.ExecutionUnits as Extras
import Hydra.Cardano.Api.Hash as Extras
import Hydra.Cardano.Api.NetworkId ()
import Hydra.Cardano.Api.PlutusScript as Extras
import Hydra.Cardano.Api.PolicyId as Extras
import Hydra.Cardano.Api.ReferenceScript as Extras
import Hydra.Cardano.Api.ScriptData as Extras
14 changes: 0 additions & 14 deletions hydra-cardano-api/src/Hydra/Cardano/Api/PlutusScript.hs

This file was deleted.

5 changes: 2 additions & 3 deletions hydra-cardano-api/src/Hydra/Cardano/Api/ReferenceScript.hs
Original file line number Diff line number Diff line change
@@ -2,7 +2,6 @@ module Hydra.Cardano.Api.ReferenceScript where

import Hydra.Cardano.Api.Prelude

import Hydra.Cardano.Api.PlutusScript (fromPlutusScript)
import PlutusLedgerApi.V3 qualified as Plutus

-- | Construct a 'ReferenceScript' from any given Plutus script.
@@ -13,12 +12,12 @@ mkScriptRef =
ReferenceScript babbageBasedEra
. toScriptInAnyLang
. PlutusScript PlutusScriptV3
. fromPlutusScript
. PlutusScriptSerialised

-- | Construct a PlutusV3 'ReferenceScript' from any given Plutus script.
mkScriptRefV3 :: Plutus.SerialisedScript -> ReferenceScript Era
mkScriptRefV3 =
ReferenceScript babbageBasedEra
. toScriptInAnyLang
. PlutusScript PlutusScriptV3
. fromPlutusScript
. PlutusScriptSerialised
2 changes: 0 additions & 2 deletions hydra-cardano-api/src/Hydra/Cardano/Api/ScriptHash.hs
Original file line number Diff line number Diff line change
@@ -4,8 +4,6 @@ module Hydra.Cardano.Api.ScriptHash where

import Hydra.Cardano.Api.Prelude

import Hydra.Cardano.Api.PlutusScript ()

-- * Extras

-- | Like 'hashScript', but for a 'ScriptInAnyLang'.
202 changes: 71 additions & 131 deletions hydra-cluster/src/Hydra/Cluster/Scenarios.hs
Original file line number Diff line number Diff line change
@@ -86,7 +86,7 @@ import Hydra.Logging (Tracer, traceWith)
import Hydra.Options (DirectChainConfig (..), networkId, startChainFrom)
import Hydra.Tx (HeadId, IsTx (balance), Party, txId)
import Hydra.Tx.ContestationPeriod (ContestationPeriod (UnsafeContestationPeriod), fromNominalDiffTime)
import Hydra.Tx.Utils (dummyValidatorScript, schnorrkelValidatorScript, verificationKeyToOnChainId)
import Hydra.Tx.Utils (dummyValidatorScript, verificationKeyToOnChainId)
import HydraNode (
HydraClient (..),
HydraNodeLog,
@@ -397,146 +397,86 @@ singlePartyUsesSchnorrkelScriptOnL2 ::
[TxId] ->
IO ()
singlePartyUsesSchnorrkelScriptOnL2 tracer workDir node hydraScriptsTxId =
( `finally`
do
returnFundsToFaucet tracer node Alice
returnFundsToFaucet tracer node AliceFunds
)
$ do
refuelIfNeeded tracer node Alice 25_000_000
aliceChainConfig <- chainConfigFor Alice workDir nodeSocket hydraScriptsTxId [] $ UnsafeContestationPeriod 100
let hydraNodeId = 1
let hydraTracer = contramap FromHydraNode tracer
withHydraNode hydraTracer aliceChainConfig workDir hydraNodeId aliceSk [] [1] $ \n1 -> do
send n1 $ input "Init" []
headId <- waitMatch (10 * blockTime) n1 $ headIsInitializingWith (Set.fromList [alice])

-- Commit nothing just to open
requestCommitTx n1 mempty >>= submitTx node
waitFor hydraTracer (10 * blockTime) [n1] $
output "HeadIsOpen" ["utxo" .= object mempty, "headId" .= headId]

-- Then commit a Tx with the schnorrkel validator
(walletVk, walletSk) <- keysFor AliceFunds

let amt = 5_000_000
fee = 173_465

-- L1 setup to (incrementally) commit funds
-- Script
(clientPayload, scriptUTxO) <- prepareScriptPayload amt
res <-
runReq defaultHttpConfig $
req
POST
(http "127.0.0.1" /: "commit")
(ReqBodyJson clientPayload)
(Proxy :: Proxy (JsonResponse Tx))
(port $ 4000 + hydraNodeId)

let commitTx = responseBody res
submitTx node commitTx

depositTxId <- waitMatch (10 * blockTime) n1 $ \v -> do
guard $ v ^? key "headId" == Just (toJSON headId)
guard $ v ^? key "tag" == Just "CommitFinalized"
pure $ v ^? key "theDeposit"
depositTxId `shouldBe` Just (toJSON $ getTxId $ getTxBody commitTx)

-- "Normal"
(clientPayload, utxoToCommit) <- prepareScriptPayload amt
res <-
runReq defaultHttpConfig $
req
POST
(http "127.0.0.1" /: "commit")
(ReqBodyJson clientPayload)
(Proxy :: Proxy (JsonResponse Tx))
(port $ 4000 + hydraNodeId)

let commitTx = responseBody res
submitTx node commitTx

depositTxId <- waitMatch (10 * blockTime) n1 $ \v -> do
guard $ v ^? key "headId" == Just (toJSON headId)
guard $ v ^? key "tag" == Just "CommitFinalized"
pure $ v ^? key "theDeposit"
depositTxId `shouldBe` Just (toJSON $ getTxId $ getTxBody commitTx)
(`finally` returnFundsToFaucet tracer node Alice) $ do
refuelIfNeeded tracer node Alice 20_000_000
aliceChainConfig <- chainConfigFor Alice workDir nodeSocket hydraScriptsTxId [] $ UnsafeContestationPeriod 100
let hydraNodeId = 1
let hydraTracer = contramap FromHydraNode tracer
(walletVk, walletSk) <- keysFor AliceFunds
utxoToCommit <- seedFromFaucet node walletVk 5_000_000 (contramap FromFaucet tracer)
withHydraNode hydraTracer aliceChainConfig workDir hydraNodeId aliceSk [] [1] $ \n1 -> do
send n1 $ input "Init" []
headId <- waitMatch (10 * blockTime) n1 $ headIsInitializingWith (Set.fromList [alice])

-- Collateral
(clientPayload, collateralUTxO) <- prepareScriptPayload amt
res <-
runReq defaultHttpConfig $
req
POST
(http "127.0.0.1" /: "commit")
(ReqBodyJson clientPayload)
(Proxy :: Proxy (JsonResponse Tx))
(port $ 4000 + hydraNodeId)
requestCommitTx n1 utxoToCommit <&> signTx walletSk >>= submitTx node
waitFor hydraTracer (10 * blockTime) [n1] $
output "HeadIsOpen" ["utxo" .= toJSON utxoToCommit, "headId" .= headId]
(clientPayload, scriptUTxO) <- prepareScriptPayload
res <-
runReq defaultHttpConfig $
req
POST
(http "127.0.0.1" /: "commit")
(ReqBodyJson clientPayload)
(Proxy :: Proxy (JsonResponse Tx))
(port $ 4000 + hydraNodeId)

let commitTx = responseBody res
submitTx node commitTx
let commitTx = responseBody res
submitTx node commitTx

depositTxId <- waitMatch (10 * blockTime) n1 $ \v -> do
guard $ v ^? key "headId" == Just (toJSON headId)
guard $ v ^? key "tag" == Just "CommitFinalized"
pure $ v ^? key "theDeposit"
depositTxId `shouldBe` Just (toJSON $ getTxId $ getTxBody commitTx)

--
-- Now, L2 with schnorrkel
let (scriptInput, _) = List.head $ UTxO.pairs scriptUTxO
let (normalInput', _) = List.head $ UTxO.pairs utxoToCommit
let (collateralInput, _) = List.head $ UTxO.pairs collateralUTxO
pparams <- queryProtocolParameters networkId nodeSocket QueryTip

-- Note: Here is the first time we use the schnorrkel validator
let serializedScript = PlutusScriptSerialised schnorrkelValidatorScript
let scriptAddress = mkScriptAddress networkId serializedScript
let scriptOutput =
mkTxOutAutoBalance
pparams
scriptAddress
(lovelaceToValue 0)
(mkTxOutDatumHash ())
ReferenceScriptNone

let returnOutput =
TxOut (mkVkAddress networkId walletVk) (lovelaceToValue (amt - fee)) TxOutDatumNone ReferenceScriptNone

let normalInput = (,BuildTxWith $ KeyWitness KeyWitnessForSpending) <$> [normalInput']
let scriptWitness =
BuildTxWith $
ScriptWitness scriptWitnessInCtx $
mkScriptWitness serializedScript (mkScriptDatum ()) (toScriptData ())

let tx =
unsafeBuildTransaction $
defaultTxBodyContent
& changePParams pparams
& addTxIns ([(scriptInput, scriptWitness)] <> normalInput)
& addTxInsCollateral [collateralInput]
& addTxOuts [scriptOutput, returnOutput]
& setTxFee (TxFeeExplicit fee)

let signedL2tx = signTx walletSk tx
send n1 $ input "NewTx" ["transaction" .= signedL2tx]

waitMatch 10 n1 $ \v -> do
guard $ v ^? key "tag" == Just "SnapshotConfirmed"
guard $
toJSON tx
`elem` (v ^.. key "snapshot" . key "confirmed" . values)
v ^? key "snapshot" . key "utxo" >>= parseMaybe parseJSON
depositTxId <- waitMatch (10 * blockTime) n1 $ \v -> do
guard $ v ^? key "headId" == Just (toJSON headId)
guard $ v ^? key "tag" == Just "CommitFinalized"
pure $ v ^? key "theDeposit"
depositTxId `shouldBe` Just (toJSON $ getTxId $ getTxBody commitTx)
let (collateralInput, _) = List.head $ UTxO.pairs utxoToCommit

let (scriptInput, _) = List.head $ UTxO.pairs scriptUTxO
let (normalInput', _) = List.head $ UTxO.pairs utxoToCommit
pparams <- queryProtocolParameters networkId nodeSocket QueryTip

let serializedScript = PlutusScriptSerialised dummyValidatorScript
let scriptAddress = mkScriptAddress networkId serializedScript
let scriptOutput =
mkTxOutAutoBalance
pparams
scriptAddress
(lovelaceToValue 0)
(mkTxOutDatumHash ())
ReferenceScriptNone
let returnOutput =
TxOut (mkVkAddress networkId walletVk) (lovelaceToValue 4_826_535) TxOutDatumNone ReferenceScriptNone
let normalInput = (,BuildTxWith $ KeyWitness KeyWitnessForSpending) <$> [normalInput']
let scriptWitness =
BuildTxWith $
ScriptWitness scriptWitnessInCtx $
mkScriptWitness serializedScript (mkScriptDatum ()) (toScriptData ())
let tx =
unsafeBuildTransaction $
defaultTxBodyContent
& changePParams pparams
& addTxIns ([(scriptInput, scriptWitness)] <> normalInput)
& addTxInsCollateral [collateralInput]
& addTxOuts [scriptOutput, returnOutput]
& setTxFee (TxFeeExplicit $ Coin 173_465)
let signedL2tx = signTx walletSk tx
send n1 $ input "NewTx" ["transaction" .= signedL2tx]

waitMatch 10 n1 $ \v -> do
guard $ v ^? key "tag" == Just "SnapshotConfirmed"
guard $
toJSON tx
`elem` (v ^.. key "snapshot" . key "confirmed" . values)
v ^? key "snapshot" . key "utxo" >>= parseMaybe parseJSON
where
RunningNode{networkId, nodeSocket, blockTime} = node
-- TODO: extract this to standalone function
prepareScriptPayload lovelaceAmt = do
prepareScriptPayload = do
let script = dummyValidatorScript
let serializedScript = PlutusScriptSerialised script
let scriptAddress = mkScriptAddress networkId serializedScript
let datumHash = mkTxOutDatumHash ()
(scriptIn, scriptOut) <- createOutputAtAddress node scriptAddress datumHash (lovelaceToValue lovelaceAmt)
(scriptIn, scriptOut) <- createOutputAtAddress node scriptAddress datumHash (lovelaceToValue 1_000_000)
let scriptUTxO = UTxO.singleton (scriptIn, scriptOut)

let scriptWitness =
Loading