Skip to content

Commit

Permalink
Update dependencies to remove PAB
Browse files Browse the repository at this point in the history
* Update to recent versions of cardano-node, cardano-ledger-specs and
plutus
* Remove dependency on plutus-application-framework (PAB) and any
related code
* Fix code following various API changes
* Vendorize on-chain code for Plutus.Contract.StateMachine as we need
it for Head validator and it's in the plutus-apps repository
* Make LocalClusterSpec test pass using newer cardano-api providing
the ability to pass full script in Datum
  • Loading branch information
abailly-iohk committed Oct 26, 2021
1 parent 414686b commit fc1e237
Show file tree
Hide file tree
Showing 35 changed files with 379 additions and 2,247 deletions.
69 changes: 29 additions & 40 deletions cabal.project
Expand Up @@ -54,16 +54,11 @@ source-repository-package
location: https://github.com/input-output-hk/plutus.git
subdir:
freer-extras
playground-common
plutus-chain-index
plutus-core
plutus-contract
plutus-ledger
plutus-ledger-api
plutus-tx
plutus-tx-plugin
plutus-pab
plutus-use-cases
prettyprinter-configurable
quickcheck-dynamic
word-array
Expand Down Expand Up @@ -125,8 +120,7 @@ source-repository-package
source-repository-package
type: git
location: https://github.com/input-output-hk/cardano-base
tag: 592aa61d657ad5935a33bace1243abce3728b643
--sha256: 1bgq3a2wfdz24jqfwylcc6jjg5aji8dpy5gjkhpnmkkvgcr2rkyb
tag: 654f5b7c76f7cc57900b4ddc664a82fc3b925fb0
subdir:
base-deriving-via
binary
Expand All @@ -142,20 +136,19 @@ source-repository-package
source-repository-package
type: git
location: https://github.com/input-output-hk/cardano-prelude
tag: fd773f7a58412131512b9f694ab95653ac430852
--sha256: 02jddik1yw0222wd6q0vv10f7y8rdgrlqaiy83ph002f9kjx7mh6
tag: bb4ed71ba8e587f672d06edf9d2e376f4b055555
subdir:
cardano-prelude
cardano-prelude-test

source-repository-package
type: git
location: https://github.com/input-output-hk/ouroboros-network
tag: 5d37a927046bc7da2887830d8e35cf604622ce09
--sha256: 1620zcnivgm1wp1kq3vqc44g77lv7dalzgywc96qsblf1sv9fw3p
tag: 94782e5ca52f234ff8eeddc6322a46cca0b69c0e
subdir:
monoidal-synchronisation
typed-protocols
typed-protocols-cborg
typed-protocols-examples
ouroboros-network
ouroboros-network-testing
Expand Down Expand Up @@ -184,43 +177,39 @@ source-repository-package

source-repository-package
type: git
location: file:///home/curry/raduom
tag: fb902575867eba7ec58f8cea483b41555f305818
location: https://github.com/input-output-hk/cardano-ledger-specs
tag: bf008ce028751cae9fb0b53c3bef20f07c06e333
subdir:
alonzo/impl

source-repository-package
type: git
location: https://github.com/raduom/cardano-ledger-specs
tag: ef6bb99782d61316da55470620c7da994cc352b2
--sha256: 0z2818kwiwv7smz0ff8wr4zb405pymgd12zm32asas0mp5bqxkin
subdir:
byron/chain/executable-spec
byron/crypto
byron/crypto/test
byron/ledger/executable-spec
byron/ledger/impl
byron/ledger/impl/test
semantics/executable-spec
semantics/small-steps-test
shelley/chain-and-ledger/dependencies/non-integer
shelley/chain-and-ledger/executable-spec
shelley/chain-and-ledger/shelley-spec-ledger-test
shelley-ma/impl
shelley-ma/shelley-ma-test
cardano-ledger-core
cardano-protocol-tpraos
alonzo/test
cardano-ledger-test
eras/alonzo/impl
eras/alonzo/test-suite
eras/byron/chain/executable-spec
eras/byron/crypto
eras/byron/crypto/test
eras/byron/ledger/executable-spec
eras/byron/ledger/impl
eras/byron/ledger/impl/test
eras/shelley/impl
eras/shelley/test-suite
eras/shelley-ma/impl
eras/shelley-ma/test-suite
libs/cardano-ledger-core
libs/cardano-ledger-pretty
libs/cardano-ledger-test
libs/cardano-protocol-tpraos
libs/small-steps
libs/small-steps-test
libs/non-integral
eras/shelley/chain-and-ledger/executable-spec
eras/shelley/chain-and-ledger/shelley-spec-ledger-test
eras/shelley/chain-and-ledger/dependencies/non-integer

-- A lot of plutus dependencies have to be synchronized with the dependencies of
-- cardano-node. If you update cardano-node, please make sure that all dependencies
-- of cardano-node are also updated.
source-repository-package
type: git
location: https://github.com/input-output-hk/cardano-node.git
tag: ed7fdbf65f40f8e194850b87dd8c631fe26154e6
--sha256: 0ivvqnw6fflfbzywychfsyyjd6jn3pg1r0vv63m1rdwp04v59kh5
tag: b6ca519f97a0e795611a63174687e6bb70c9f752
subdir:
cardano-api
cardano-node
Expand Down
12 changes: 5 additions & 7 deletions hydra-node/hydra-node.cabal
Expand Up @@ -80,7 +80,6 @@ library
Hydra.Chain.Direct.Tx
Hydra.Chain.Direct.Util
Hydra.Chain.Direct.Wallet
Hydra.Chain.ExternalPAB
Hydra.Chain.ZeroMQ
Hydra.ClientInput
Hydra.HeadLogic
Expand Down Expand Up @@ -120,8 +119,10 @@ library
, cardano-ledger-alonzo-test
, cardano-ledger-byron
, cardano-ledger-core
, cardano-ledger-shelley
, cardano-ledger-shelley-ma
, cardano-ledger-shelley-ma-test
, cardano-ledger-shelley-test
, cardano-node
, cardano-prelude
, cardano-slotting
Expand All @@ -147,10 +148,8 @@ library
, ouroboros-consensus-shelley
, ouroboros-network
, ouroboros-network-framework
, plutus-contract
, plutus-ledger
, plutus-ledger-api
, plutus-pab
, prometheus
, QuickCheck
, req
Expand All @@ -161,6 +160,7 @@ library
, text
, time
, typed-protocols
, typed-protocols-cborg
, typed-protocols-examples
, websockets
, zeromq4-haskell
Expand Down Expand Up @@ -204,7 +204,6 @@ test-suite tests
Hydra.Chain.Direct.TxSpec
Hydra.Chain.Direct.WalletSpec
Hydra.Chain.DirectSpec
Hydra.Chain.ExternalPABSpec
Hydra.Chain.ZeroMQSpec
Hydra.ClientInputSpec
Hydra.FireForgetSpec
Expand Down Expand Up @@ -237,6 +236,7 @@ test-suite tests
, cardano-ledger-alonzo
, cardano-ledger-alonzo-test
, cardano-ledger-core
, cardano-ledger-shelley
, cardano-ledger-shelley-ma
, cardano-ledger-shelley-ma-test
, cardano-ledger-test
Expand Down Expand Up @@ -284,7 +284,5 @@ test-suite tests
, websockets
, yaml

build-tool-depends:
hspec-discover:hspec-discover -any, hydra-plutus:hydra-pab -any

build-tool-depends: hspec-discover:hspec-discover -any
ghc-options: -threaded -rtsopts
4 changes: 2 additions & 2 deletions hydra-node/src/Hydra/Chain/Direct.hs
Expand Up @@ -14,6 +14,7 @@ import Hydra.Prelude

import Cardano.Ledger.Alonzo.Tx (ValidatedTx)
import Cardano.Ledger.Alonzo.TxSeq (txSeqTxns)
import qualified Cardano.Ledger.Shelley.API as Ledger
import Control.Exception (IOException)
import Control.Monad.Class.MonadSTM (
newTQueueIO,
Expand Down Expand Up @@ -76,7 +77,6 @@ import Ouroboros.Network.Protocol.LocalTxSubmission.Client (
LocalTxSubmissionClient (..),
localTxSubmissionClientPeer,
)
import qualified Shelley.Spec.Ledger.API as Ledger
import Test.Cardano.Ledger.Alonzo.Serialisation.Generators ()

withDirectChain ::
Expand All @@ -99,7 +99,7 @@ withDirectChain tracer networkMagic iocp socketPath keyPair callback action = do
race_
(action $ Chain{postTx = atomically . writeTQueue queue})
( connectTo
(localSnocket iocp socketPath)
(localSnocket iocp)
nullConnectTracers
(versions networkMagic (client tracer queue headState wallet callback))
socketPath
Expand Down
27 changes: 14 additions & 13 deletions hydra-node/src/Hydra/Chain/Direct/Tx.hs
Expand Up @@ -15,13 +15,25 @@ import Cardano.Binary (serialize)
import Cardano.Ledger.Address (Addr (Addr))
import Cardano.Ledger.Alonzo (AlonzoEra, Script)
import Cardano.Ledger.Alonzo.Data (Data (Data), DataHash, getPlutusData, hashData)
import Cardano.Ledger.Alonzo.Language (Language (PlutusV1))
import Cardano.Ledger.Alonzo.Scripts (ExUnits (..), Script (PlutusScript))
import Cardano.Ledger.Alonzo.Tx (IsValid (IsValid), ScriptPurpose (Spending), ValidatedTx (..), rdptr)
import Cardano.Ledger.Alonzo.TxBody (TxBody (..), TxOut (TxOut))
import Cardano.Ledger.Alonzo.TxWitness (RdmrPtr, Redeemers (..), TxDats (..), TxWitness (..), unRedeemers, unTxDats)
import Cardano.Ledger.Crypto (StandardCrypto)
import Cardano.Ledger.Era (hashScript)
import qualified Cardano.Ledger.SafeHash as SafeHash
import Cardano.Ledger.Shelley.API (
Coin (..),
Credential (ScriptHashObj),
Network (Testnet),
ScriptHash,
StakeReference (StakeRefNull),
StrictMaybe (..),
TxId (TxId),
TxIn (TxIn),
Wdrl (Wdrl),
)
import Cardano.Ledger.ShelleyMA.Timelocks (ValidityInterval (..))
import Cardano.Ledger.Val (inject)
import Control.Monad (foldM)
Expand All @@ -40,17 +52,6 @@ import Ledger.Value (AssetClass (..), currencyMPSHash)
import Plutus.V1.Ledger.Api (MintingPolicyHash, PubKeyHash (..), fromData, toData)
import qualified Plutus.V1.Ledger.Api as Plutus
import Plutus.V1.Ledger.Value (assetClass, currencySymbol, tokenName)
import Shelley.Spec.Ledger.API (
Coin (..),
Credential (ScriptHashObj),
Network (Testnet),
ScriptHash,
StakeReference (StakeRefNull),
StrictMaybe (..),
TxId (TxId),
TxIn (TxIn),
Wdrl (Wdrl),
)

-- TODO(SN): parameterize
network :: Network
Expand Down Expand Up @@ -165,7 +166,7 @@ abortTx (smInput, _token, HeadParameters{contestationPeriod, parties}) initInput
scripts =
fromList $
map withScriptHash $
[headScript] ++ [initialScript | not (null initInputs)]
headScript : [initialScript | not (null initInputs)]

initialScript = plutusScript Initial.validatorScript

Expand Down Expand Up @@ -320,7 +321,7 @@ scriptAddr script =
StakeRefNull

plutusScript :: Plutus.Script -> Script Era
plutusScript = PlutusScript . toShort . fromLazy . serialize
plutusScript = PlutusScript PlutusV1 . toShort . fromLazy . serialize

withDataHash :: Data Era -> (DataHash StandardCrypto, Data Era)
withDataHash d = (hashData d, d)
Expand Down
15 changes: 7 additions & 8 deletions hydra-node/src/Hydra/Chain/Direct/Wallet.hs
Expand Up @@ -39,6 +39,8 @@ import Cardano.Ledger.Crypto (DSIGN, StandardCrypto)
import Cardano.Ledger.Era (ValidateScript (..))
import qualified Cardano.Ledger.Keys as Ledger
import qualified Cardano.Ledger.SafeHash as SafeHash
import qualified Cardano.Ledger.Shelley.API as Ledger hiding (TxBody, TxOut)
import Cardano.Ledger.Shelley.BlockChain (HashHeader)
import Cardano.Ledger.Val (Val (..), invert)
import Control.Monad.Class.MonadSTM (
check,
Expand Down Expand Up @@ -110,9 +112,6 @@ import Ouroboros.Network.Protocol.LocalStateQuery.Client (
localStateQueryClientPeer,
)
import qualified Ouroboros.Network.Protocol.LocalStateQuery.Client as LSQ
import qualified Shelley.Spec.Ledger.API as Ledger hiding (TxBody, TxOut)
import Shelley.Spec.Ledger.BlockChain (HashHeader)
import Shelley.Spec.Ledger.TxBody (TxId (..), pattern TxIn)
import Test.QuickCheck (generate)

type Address = Ledger.Addr StandardCrypto
Expand Down Expand Up @@ -157,7 +156,7 @@ withTinyWallet tracer magic (vk, sk) iocp addr action = do
race_
(action $ newTinyWallet utxoVar)
( connectTo
(localSnocket iocp addr)
(localSnocket iocp)
nullConnectTracers
(versions magic $ client tracer tipVar utxoVar address)
addr
Expand Down Expand Up @@ -202,13 +201,13 @@ applyBlock blk isOurs utxo = case blk of
BlockAlonzo (ShelleyBlock (Ledger.Block _ bbody) _) ->
flip execState utxo $ do
forM_ (txSeqTxns bbody) $ \tx -> do
let txId = TxId $ SafeHash.hashAnnotated (body tx)
let txId = Ledger.TxId $ SafeHash.hashAnnotated (body tx)
modify (`Map.withoutKeys` inputs (body tx))
let indexedOutputs =
let outs = outputs (body tx)
in StrictSeq.zip (StrictSeq.fromList [0 .. length outs]) outs
forM_ indexedOutputs $ \(fromIntegral -> ix, out@(TxOut addr _ _)) ->
when (isOurs addr) $ modify (Map.insert (TxIn txId ix) out)
when (isOurs addr) $ modify (Map.insert (Ledger.TxIn txId ix) out)
_ ->
utxo

Expand Down Expand Up @@ -274,7 +273,7 @@ coverFee_ pparams lookupUtxo walletUtxo partialTx@ValidatedTx{body, wits} = do
where
-- TODO: Do a better fee estimation based on the transaction's content.
needlesslyHighFee :: Coin
needlesslyHighFee = Coin 10_000_000
needlesslyHighFee = Coin 1_000_000_000

getAdaValue :: TxOut -> Coin
getAdaValue (TxOut _ value _) =
Expand Down Expand Up @@ -441,7 +440,7 @@ chainSyncClient tracer tipVar utxoVar address =
msg <- atomically $ do
(utxo, pparams) <- readTMVar utxoVar
let utxo' = applyBlock block (== address) utxo
if (utxo' /= utxo)
if utxo' /= utxo
then do
void $ swapTMVar utxoVar (utxo', pparams)
pure $ Just $ ApplyBlock utxo utxo'
Expand Down

0 comments on commit fc1e237

Please sign in to comment.