diff --git a/cabal.project b/cabal.project index 95116efc1e6..e655a146b8e 100644 --- a/cabal.project +++ b/cabal.project @@ -12,8 +12,8 @@ repository cardano-haskell-packages -- See CONTRIBUTING.md for information about when and how to update these. index-state: - , hackage.haskell.org 2024-01-29T15:07:04Z - , cardano-haskell-packages 2024-01-29T19:04:02Z + , hackage.haskell.org 2024-02-07T15:07:04Z + , cardano-haskell-packages 2024-02-07T19:04:02Z packages: hydra-prelude diff --git a/flake.lock b/flake.lock index db27a0dc816..b59a9e9327b 100644 --- a/flake.lock +++ b/flake.lock @@ -3,11 +3,11 @@ "CHaP": { "flake": false, "locked": { - "lastModified": 1706612908, - "narHash": "sha256-rZytUcsrRO6EIOdDSuQw9vhNUFRk1GuG6w2vUxLv5H8=", + "lastModified": 1707261293, + "narHash": "sha256-icbnYI4cK6juBHsLKnvhmolVuAg+XcrBFR4xnawjZyE=", "owner": "input-output-hk", "repo": "cardano-haskell-packages", - "rev": "44e3f3330cc807066818f739946ab08e868a4b30", + "rev": "2211393aee44275d2eed09f20e28ad252e248108", "type": "github" }, "original": { diff --git a/hydra-cardano-api/hydra-cardano-api.cabal b/hydra-cardano-api/hydra-cardano-api.cabal index e18de5fbd93..2065fa643fb 100644 --- a/hydra-cardano-api/hydra-cardano-api.cabal +++ b/hydra-cardano-api/hydra-cardano-api.cabal @@ -87,21 +87,21 @@ library , base >=4.16 , base16-bytestring , bytestring - , cardano-api >=8.37.0 && <8.38 - , cardano-binary >=1.7.0 && <1.8 - , cardano-crypto-class >=2.1.1 && <2.2 - , cardano-ledger-allegra >=1.2.1 && <1.3 - , cardano-ledger-alonzo >=1.5 && <1.6 - , cardano-ledger-api >=1.7 && <1.8 - , cardano-ledger-babbage >=1.5 && <1.6 - , cardano-ledger-binary >=1.2 && <1.3 - , cardano-ledger-byron >=1.0.0 && <1.1 - , cardano-ledger-core >=1.9 && <1.10 - , cardano-ledger-mary >=1.4 && <1.5 - , cardano-ledger-shelley >=1.8 && <1.9 + , cardano-api >=8.38.0 && <8.39 + , cardano-binary >=1.7.0 && <1.8 + , cardano-crypto-class >=2.1.1 && <2.2 + , cardano-ledger-allegra >=1.3 && <1.4 + , cardano-ledger-alonzo >=1.6 && <1.7 + , cardano-ledger-api >=1.8 && <1.9 + , cardano-ledger-babbage >=1.6 && <1.7 + , cardano-ledger-binary >=1.3 && <1.4 + , cardano-ledger-byron >=1.0.0 && <1.1 + , cardano-ledger-core >=1.10 && <1.11 + , cardano-ledger-mary >=1.5 && <1.6 + , cardano-ledger-shelley >=1.9 && <1.10 , containers , lens - , plutus-ledger-api >=1.15.0.1 && <1.16 + , plutus-ledger-api >=1.21 && <1.22 , QuickCheck , serialise , text >=2 diff --git a/hydra-cardano-api/src/Hydra/Cardano/Api.hs b/hydra-cardano-api/src/Hydra/Cardano/Api.hs index d7b863bf576..6a0d7b894f1 100644 --- a/hydra-cardano-api/src/Hydra/Cardano/Api.hs +++ b/hydra-cardano-api/src/Hydra/Cardano/Api.hs @@ -110,9 +110,7 @@ import Hydra.Cardano.Api.Prelude ( LedgerEra, LedgerProtocolParameters, Map, - Proposal, StandardCrypto, - VotingProcedures, ledgerEraVersion, ) @@ -156,8 +154,6 @@ import Cardano.Ledger.Alonzo.TxAuxData qualified as Ledger import Cardano.Ledger.Alonzo.TxWits qualified as Ledger import Cardano.Ledger.Core qualified as Ledger import Cardano.Ledger.Keys qualified as Ledger -import Cardano.Ledger.Keys.Bootstrap qualified as Ledger -import Cardano.Ledger.Keys.WitVKey qualified as Ledger import Data.ByteString.Short (ShortByteString) import Prelude @@ -379,13 +375,13 @@ defaultTxBodyContent = Cardano.Api.defaultTxBodyContent shelleyBasedEra -- ** TxBodyContent -type TxBodyContent build = Cardano.Api.TxBodyContent build Era +type TxBodyContent buidl = Cardano.Api.TxBodyContent buidl Era {-# COMPLETE TxBodyContent #-} pattern TxBodyContent :: - TxIns build -> + TxIns buidl -> TxInsCollateral -> - TxInsReference build -> + TxInsReference buidl -> [TxOut CtxTx] -> TxTotalCollateral Era -> TxReturnCollateral CtxTx Era -> @@ -395,15 +391,15 @@ pattern TxBodyContent :: TxMetadataInEra -> TxAuxScripts -> TxExtraKeyWitnesses -> - BuildTxWith build (Maybe (LedgerProtocolParameters Era)) -> - TxWithdrawals build Era -> - TxCertificates build Era -> + BuildTxWith buidl (Maybe (LedgerProtocolParameters Era)) -> + TxWithdrawals buidl Era -> + TxCertificates buidl Era -> TxUpdateProposal Era -> - TxMintValue build -> + TxMintValue buidl -> TxScriptValidity -> - Maybe (Featured ConwayEraOnwards Era [Proposal Era]) -> - Maybe (Featured ConwayEraOnwards Era (VotingProcedures Era)) -> - TxBodyContent build + Maybe (Featured ConwayEraOnwards Era (TxProposalProcedures buidl Era)) -> + Maybe (Featured ConwayEraOnwards Era (TxVotingProcedures buidl Era)) -> + TxBodyContent buidl pattern TxBodyContent { txIns , txInsCollateral @@ -565,10 +561,10 @@ pattern TxMetadataInEra{txMetadataInEra} <- -- ** TxMintValue -type TxMintValue build = Cardano.Api.TxMintValue build Era +type TxMintValue buidl = Cardano.Api.TxMintValue buidl Era {-# COMPLETE TxMintValueNone, TxMintValue #-} -pattern TxMintValueNone :: TxMintValue build +pattern TxMintValueNone :: TxMintValue buidl pattern TxMintValueNone <- Cardano.Api.TxMintNone where @@ -577,8 +573,8 @@ pattern TxMintValueNone <- pattern TxMintValue :: Value -> - BuildTxWith build (Map PolicyId (ScriptWitness WitCtxMint)) -> - TxMintValue build + BuildTxWith buidl (Map PolicyId (ScriptWitness WitCtxMint)) -> + TxMintValue buidl pattern TxMintValue{txMintValueInEra, txMintValueScriptWitnesses} <- Cardano.Api.TxMintValue _ txMintValueInEra txMintValueScriptWitnesses where diff --git a/hydra-cardano-api/src/Hydra/Cardano/Api/Hash.hs b/hydra-cardano-api/src/Hydra/Cardano/Api/Hash.hs index 2f7b4ad0eed..c65af934b9b 100644 --- a/hydra-cardano-api/src/Hydra/Cardano/Api/Hash.hs +++ b/hydra-cardano-api/src/Hydra/Cardano/Api/Hash.hs @@ -2,8 +2,8 @@ module Hydra.Cardano.Api.Hash where import Hydra.Cardano.Api.Prelude -import Cardano.Ledger.Alonzo.Plutus.TxInfo qualified as Ledger import Cardano.Ledger.Keys qualified as Ledger +import Cardano.Ledger.Plutus.TxInfo (transKeyHash) import Cardano.Ledger.SafeHash (unsafeMakeSafeHash) import Cardano.Ledger.Shelley.Scripts qualified as Ledger import Data.ByteString qualified as BS @@ -13,8 +13,7 @@ import PlutusLedgerApi.V2 qualified as Plutus -- | Convert a cardano-api 'Hash' into a plutus 'PubKeyHash' toPlutusKeyHash :: Hash PaymentKey -> Plutus.PubKeyHash -toPlutusKeyHash (PaymentKeyHash vkh) = - Ledger.transKeyHash vkh +toPlutusKeyHash (PaymentKeyHash vkh) = transKeyHash vkh -- | Convert a cardano-api 'Hash' into a cardano-ledger 'KeyHash' toLedgerKeyHash :: Hash PaymentKey -> Ledger.KeyHash 'Ledger.Witness StandardCrypto diff --git a/hydra-cardano-api/src/Hydra/Cardano/Api/KeyWitness.hs b/hydra-cardano-api/src/Hydra/Cardano/Api/KeyWitness.hs index 4354e312fdb..f97b96a7b10 100644 --- a/hydra-cardano-api/src/Hydra/Cardano/Api/KeyWitness.hs +++ b/hydra-cardano-api/src/Hydra/Cardano/Api/KeyWitness.hs @@ -5,7 +5,6 @@ import Hydra.Cardano.Api.Prelude import Cardano.Ledger.Alonzo.TxWits qualified as Ledger import Cardano.Ledger.Era qualified as Ledger import Cardano.Ledger.Keys qualified as Ledger -import Cardano.Ledger.Shelley.API qualified as Ledger import Data.Set qualified as Set -- * Extras diff --git a/hydra-cardano-api/src/Hydra/Cardano/Api/PlutusScript.hs b/hydra-cardano-api/src/Hydra/Cardano/Api/PlutusScript.hs index 587fd107151..14a6038a204 100644 --- a/hydra-cardano-api/src/Hydra/Cardano/Api/PlutusScript.hs +++ b/hydra-cardano-api/src/Hydra/Cardano/Api/PlutusScript.hs @@ -5,6 +5,7 @@ module Hydra.Cardano.Api.PlutusScript where import Hydra.Cardano.Api.Prelude import Cardano.Ledger.Alonzo.Scripts qualified as Ledger +import Cardano.Ledger.Babbage.Scripts qualified as Ledger import Cardano.Ledger.Plutus.Language qualified as Ledger import Data.ByteString.Short qualified as SBS import PlutusLedgerApi.Common qualified as Plutus @@ -18,10 +19,15 @@ import Test.QuickCheck (listOf) -- -- (a) If the given script is a timelock script, it throws an impure exception; -- (b) If the given script is in a wrong language, it silently coerces it. -fromLedgerScript :: HasCallStack => Ledger.AlonzoScript era -> PlutusScript lang +fromLedgerScript :: + ( HasCallStack + , Ledger.AlonzoEraScript era + ) => + Ledger.AlonzoScript era -> + PlutusScript lang fromLedgerScript = \case Ledger.TimelockScript{} -> error "fromLedgerScript: TimelockScript" - Ledger.PlutusScript (Ledger.Plutus _ (Ledger.BinaryPlutus bytes)) -> PlutusScriptSerialised bytes + Ledger.PlutusScript x -> Ledger.withPlutusScript x (\(Ledger.Plutus (Ledger.PlutusBinary bytes)) -> PlutusScriptSerialised bytes) -- | Convert a cardano-api 'PlutusScript' into a cardano-ledger 'Script'. toLedgerScript :: @@ -30,11 +36,10 @@ toLedgerScript :: PlutusScript lang -> Ledger.AlonzoScript (ShelleyLedgerEra Era) toLedgerScript (PlutusScriptSerialised bytes) = - let lang = case plutusScriptVersion @lang of - PlutusScriptV1 -> Ledger.PlutusV1 - PlutusScriptV2 -> Ledger.PlutusV2 - PlutusScriptV3 -> Ledger.PlutusV3 - in Ledger.PlutusScript $ Ledger.Plutus lang (Ledger.BinaryPlutus bytes) + Ledger.PlutusScript $ case plutusScriptVersion @lang of + PlutusScriptV1 -> Ledger.BabbagePlutusV1 $ Ledger.Plutus (Ledger.PlutusBinary bytes) + PlutusScriptV2 -> Ledger.BabbagePlutusV2 $ Ledger.Plutus (Ledger.PlutusBinary bytes) + PlutusScriptV3 -> error "toLedgerScript: PlutusV3 not supported in Babbage" -- | Convert a serialized plutus script into a cardano-api 'PlutusScript'. fromPlutusScript :: Plutus.SerialisedScript -> PlutusScript lang diff --git a/hydra-cardano-api/src/Hydra/Cardano/Api/Pretty.hs b/hydra-cardano-api/src/Hydra/Cardano/Api/Pretty.hs index 43d9b152f5d..aa3e081f5a7 100644 --- a/hydra-cardano-api/src/Hydra/Cardano/Api/Pretty.hs +++ b/hydra-cardano-api/src/Hydra/Cardano/Api/Pretty.hs @@ -142,11 +142,8 @@ renderTxWithUTxO utxo (Tx body _wits) = totalScriptSize = sum $ BL.length . serialize <$> scripts - prettyScript (Api.fromLedgerScript -> script) = - "Script (" <> scriptHash <> ")" - where - scriptHash = - show (Ledger.hashScript @(ShelleyLedgerEra Era) (Api.toLedgerScript @PlutusScriptV2 script)) + prettyScript script = + "Script (" <> show (Ledger.hashScript script) <> ")" datumLines = case scriptsData of Api.TxBodyNoScriptData -> [] @@ -171,9 +168,9 @@ renderTxWithUTxO utxo (Tx body _wits) = in "== REDEEMERS (" <> show (length rdmrs) <> ")" : (("- " <>) . prettyRedeemer <$> rdmrs) - prettyRedeemer (Ledger.RdmrPtr tag ix, (redeemerData, redeemerBudget)) = + prettyRedeemer (purpose, (redeemerData, redeemerBudget)) = unwords - [ show tag <> "#" <> show ix + [ show purpose , mconcat [ "( cpu = " <> show (Ledger.exUnitsSteps redeemerBudget) , ", mem = " <> show (Ledger.exUnitsMem redeemerBudget) <> " )" diff --git a/hydra-cardano-api/src/Hydra/Cardano/Api/ScriptData.hs b/hydra-cardano-api/src/Hydra/Cardano/Api/ScriptData.hs index 085b481e8f5..5013dc4d6b0 100644 --- a/hydra-cardano-api/src/Hydra/Cardano/Api/ScriptData.hs +++ b/hydra-cardano-api/src/Hydra/Cardano/Api/ScriptData.hs @@ -63,9 +63,10 @@ lookupScriptData (Tx (ShelleyTxBody _ _ _ scriptsData _ _) _) (TxOut _ _ datum _ (TxOutDatumInline _ dat) -> Just dat where - datums = case scriptsData of - TxBodyNoScriptData -> mempty - TxBodyScriptData _ (Ledger.TxDats m) _ -> m + datums :: Map (Ledger.DataHash StandardCrypto) (Ledger.Data (ShelleyLedgerEra era)) = + case (scriptsData :: TxBodyScriptData era) of + TxBodyNoScriptData -> mempty + TxBodyScriptData _ (Ledger.TxDats m) _ -> m -- * Type Conversions diff --git a/hydra-cardano-api/src/Hydra/Cardano/Api/TxBody.hs b/hydra-cardano-api/src/Hydra/Cardano/Api/TxBody.hs index 8a145dad773..54c13e21d3c 100644 --- a/hydra-cardano-api/src/Hydra/Cardano/Api/TxBody.hs +++ b/hydra-cardano-api/src/Hydra/Cardano/Api/TxBody.hs @@ -3,7 +3,8 @@ module Hydra.Cardano.Api.TxBody where import Hydra.Cardano.Api.Prelude import Cardano.Ledger.Alonzo.TxWits qualified as Ledger -import Cardano.Ledger.Babbage.Tx qualified as Ledger +import Cardano.Ledger.Api (AlonzoPlutusPurpose (..), AsIndex, AsItem (..), PlutusPurpose) +import Cardano.Ledger.Babbage.Core (redeemerPointer) import Cardano.Ledger.BaseTypes (strictMaybeToMaybe) import Cardano.Ledger.Core qualified as Ledger import Cardano.Ledger.Plutus.Data qualified as Ledger @@ -11,29 +12,27 @@ import Data.List (find) import Data.Map qualified as Map import Hydra.Cardano.Api.PlutusScript (fromLedgerScript) import Hydra.Cardano.Api.PolicyId (toLedgerPolicyID, toLedgerScriptHash) -import Hydra.Cardano.Api.ScriptData (FromScriptData) import Hydra.Cardano.Api.TxIn (toLedgerTxIn) import PlutusLedgerApi.V2 qualified as Plutus -- | Find and deserialise from 'ScriptData', a redeemer from the transaction -- associated to the given input. findRedeemerSpending :: - FromScriptData a => + Plutus.FromData a => Tx Era -> TxIn -> Maybe a findRedeemerSpending (getTxBody -> ShelleyTxBody _ body _ scriptData _ _) txIn = do - ptr <- strictMaybeToMaybe $ Ledger.rdptr body (Ledger.Spending $ toLedgerTxIn txIn) + ptr <- strictMaybeToMaybe $ redeemerPointer body (AlonzoSpending . AsItem $ toLedgerTxIn txIn) lookupRedeemer ptr scriptData findRedeemerMinting :: - forall a. - FromScriptData a => + Plutus.FromData a => Tx Era -> PolicyId -> Maybe a findRedeemerMinting (getTxBody -> ShelleyTxBody _ body _ scriptData _ _) pid = do - ptr <- strictMaybeToMaybe $ Ledger.rdptr body (Ledger.Minting $ toLedgerPolicyID pid) + ptr <- strictMaybeToMaybe $ redeemerPointer body (AlonzoMinting . AsItem $ toLedgerPolicyID pid) lookupRedeemer ptr scriptData findScriptMinting :: @@ -53,12 +52,9 @@ findScriptMinting (getTxBody -> ShelleyTxBody _ _ scripts _ _ _) pid = do -- lookupRedeemer :: - forall a era. - ( FromScriptData a - , Ledger.Era (ShelleyLedgerEra era) - ) => - Ledger.RdmrPtr -> - TxBodyScriptData era -> + Plutus.FromData a => + PlutusPurpose AsIndex LedgerEra -> + TxBodyScriptData Era -> Maybe a lookupRedeemer ptr scriptData = do (d, _exUnits) <- Map.lookup ptr redeemers diff --git a/hydra-cardano-api/src/Hydra/Cardano/Api/TxIn.hs b/hydra-cardano-api/src/Hydra/Cardano/Api/TxIn.hs index b7e77a3911e..d2eda5c3026 100644 --- a/hydra-cardano-api/src/Hydra/Cardano/Api/TxIn.hs +++ b/hydra-cardano-api/src/Hydra/Cardano/Api/TxIn.hs @@ -6,7 +6,7 @@ import Hydra.Cardano.Api.Prelude import Cardano.Ledger.BaseTypes qualified as Ledger import Cardano.Ledger.Binary qualified as Ledger -import Cardano.Ledger.Plutus.TxInfo qualified as Ledger +import Cardano.Ledger.Plutus (transTxIn) import Cardano.Ledger.TxIn qualified as Ledger import Data.ByteString qualified as BS import Data.Set qualified as Set @@ -54,7 +54,7 @@ fromPlutusTxOutRef (Plutus.TxOutRef (Plutus.TxId bytes) ix) = -- | Convert a cardano-api 'TxIn' into a plutus 'TxOutRef'. toPlutusTxOutRef :: TxIn -> Plutus.TxOutRef -toPlutusTxOutRef = Ledger.txInfoIn' . toLedgerTxIn +toPlutusTxOutRef = transTxIn . toLedgerTxIn -- * Arbitrary values diff --git a/hydra-cardano-api/src/Hydra/Cardano/Api/TxOut.hs b/hydra-cardano-api/src/Hydra/Cardano/Api/TxOut.hs index 2b43f3c0d15..b114b8d34ad 100644 --- a/hydra-cardano-api/src/Hydra/Cardano/Api/TxOut.hs +++ b/hydra-cardano-api/src/Hydra/Cardano/Api/TxOut.hs @@ -183,13 +183,13 @@ fromPlutusTxOut network out = do -- | Convert a cardano-api 'TxOut' into a plutus 'TxOut'. Returns 'Nothing' -- if a byron address is used in the given 'TxOut'. -toPlutusTxOut :: TxOut CtxUTxO Era -> Maybe Plutus.TxOut +toPlutusTxOut :: HasCallStack => TxOut CtxUTxO Era -> Maybe Plutus.TxOut toPlutusTxOut = - -- NOTE: The txInfoOutV2 conversion does take this 'TxOutSource' to report + -- NOTE: The transTxOutV2 conversion does take this 'TxOutSource' to report -- origins of 'TranslationError'. However, this value is NOT used for -- constructing the Plutus.TxOut and hence we error out should it be used via -- a 'Left', which we expect to throw away anyway on 'eitherToMaybe'. - eitherToMaybe . Ledger.txInfoOutV2 (error "TxOutSource used unexpectedly") . toLedgerTxOut + eitherToMaybe . Ledger.transTxOutV2 (error "TxOutSource used unexpectedly") . toLedgerTxOut where eitherToMaybe = \case Left _ -> Nothing diff --git a/hydra-cluster/src/Hydra/Cluster/Faucet.hs b/hydra-cluster/src/Hydra/Cluster/Faucet.hs index ba6fee77eba..0e711263b54 100644 --- a/hydra-cluster/src/Hydra/Cluster/Faucet.hs +++ b/hydra-cluster/src/Hydra/Cluster/Faucet.hs @@ -33,7 +33,7 @@ import Hydra.Ledger.Cardano () data FaucetException = FaucetHasNotEnoughFunds {faucetUTxO :: UTxO} - | FaucetFailedToBuildTx {reason :: TxBodyErrorAutoBalance} + | FaucetFailedToBuildTx {reason :: TxBodyErrorAutoBalance Era} deriving stock (Show) instance Exception FaucetException diff --git a/hydra-node/hydra-node.cabal b/hydra-node/hydra-node.cabal index 3f0055b1024..0605400cc79 100644 --- a/hydra-node/hydra-node.cabal +++ b/hydra-node/hydra-node.cabal @@ -79,7 +79,6 @@ library Hydra.Ledger.Cardano.Builder Hydra.Ledger.Cardano.Configuration Hydra.Ledger.Cardano.Evaluate - Hydra.Ledger.Cardano.Json Hydra.Ledger.Cardano.Time Hydra.Ledger.Simple Hydra.Logging @@ -151,8 +150,8 @@ library , ouroboros-network-api >=0.1.0.0 , ouroboros-network-framework >=0.3.0.0 , ouroboros-network-protocols >=0.3.0.0 - , plutus-core >=1.15.0.1 && <1.16 - , plutus-ledger-api >=1.15.0.1 && <1.16 + , plutus-core >=1.21 && <1.22 + , plutus-ledger-api >=1.21 && <1.22 , prometheus , QuickCheck , quickcheck-instances diff --git a/hydra-node/src/Hydra/Chain/CardanoClient.hs b/hydra-node/src/Hydra/Chain/CardanoClient.hs index d76d75a2402..1bee5e9c57d 100644 --- a/hydra-node/src/Hydra/Chain/CardanoClient.hs +++ b/hydra-node/src/Hydra/Chain/CardanoClient.hs @@ -13,11 +13,14 @@ import Cardano.Ledger.Core (PParams (..)) import Data.Aeson (eitherDecode', encode) import Data.Set qualified as Set import Data.Text qualified as Text -import Hydra.Ledger.Cardano.Json () import Ouroboros.Consensus.Cardano.Block (EraMismatch (..)) import Test.QuickCheck (oneof) import Text.Printf (printf) +-- XXX: This should be re-exported by cardano-api +-- https://github.com/IntersectMBO/cardano-api/issues/447 +import Ouroboros.Network.Protocol.LocalStateQuery.Type (Target (..)) + data QueryException = QueryAcquireException AcquiringFailure | QueryEraMismatchException EraMismatch @@ -92,7 +95,7 @@ buildTransaction :: [TxIn] -> -- | Outputs to create. [TxOut CtxTx] -> - IO (Either TxBodyErrorAutoBalance TxBody) + IO (Either (TxBodyErrorAutoBalance Era) TxBody) buildTransaction networkId socket changeAddress utxoToSpend collateral outs = do pparams <- queryProtocolParameters networkId socket QueryTip systemStart <- querySystemStart networkId socket QueryTip @@ -359,8 +362,7 @@ queryUTxOWhole :: SocketPath -> QueryPoint -> IO UTxO -queryUTxOWhole networkId socket queryPoint = do - UTxO.fromApi <$> (runQuery networkId socket queryPoint query >>= throwOnEraMismatch) +queryUTxOWhole networkId socket queryPoint = UTxO.fromApi <$> (runQuery networkId socket queryPoint query >>= throwOnEraMismatch) where query = QueryInEra @@ -414,20 +416,22 @@ queryInShelleyBasedEraExpr :: LocalStateQueryExpr b p QueryInMode r IO a queryInShelleyBasedEraExpr sbe query = queryExpr (QueryInEra $ QueryInShelleyBasedEra sbe query) - >>= (liftIO . throwOnUnsupportedNtcVersion) - >>= (liftIO . throwOnEraMismatch) + >>= liftIO + . throwOnUnsupportedNtcVersion + >>= liftIO + . throwOnEraMismatch -- | Throws at least 'QueryException' if query fails. runQuery :: NetworkId -> SocketPath -> QueryPoint -> QueryInMode a -> IO a runQuery networkId socket point query = - queryNodeLocalState (localNodeConnectInfo networkId socket) maybePoint query >>= \case + queryNodeLocalState (localNodeConnectInfo networkId socket) queryTarget query >>= \case Left err -> throwIO $ QueryAcquireException err Right result -> pure result where - maybePoint = + queryTarget = case point of - QueryTip -> Nothing - QueryAt cp -> Just cp + QueryTip -> VolatileTip + QueryAt cp -> SpecificPoint cp -- | Throws at least 'QueryException' if query fails. runQueryExpr :: @@ -437,14 +441,14 @@ runQueryExpr :: LocalStateQueryExpr BlockInMode ChainPoint QueryInMode () IO a -> IO a runQueryExpr networkId socket point query = - executeLocalStateQueryExpr (localNodeConnectInfo networkId socket) maybePoint query >>= \case + executeLocalStateQueryExpr (localNodeConnectInfo networkId socket) queryTarget query >>= \case Left err -> throwIO $ QueryAcquireException err Right result -> pure result where - maybePoint = + queryTarget = case point of - QueryTip -> Nothing - QueryAt cp -> Just cp + QueryTip -> VolatileTip + QueryAt cp -> SpecificPoint cp throwOnEraMismatch :: MonadThrow m => Either EraMismatch a -> m a throwOnEraMismatch res = diff --git a/hydra-node/src/Hydra/Chain/Direct/State.hs b/hydra-node/src/Hydra/Chain/Direct/State.hs index aa3ace929f9..3401ae0b3a1 100644 --- a/hydra-node/src/Hydra/Chain/Direct/State.hs +++ b/hydra-node/src/Hydra/Chain/Direct/State.hs @@ -119,7 +119,6 @@ import Hydra.HeadId (HeadId (..)) import Hydra.Ledger (ChainSlot (ChainSlot), IsTx (hashUTxO)) import Hydra.Ledger.Cardano (genOneUTxOFor, genUTxOAdaOnlyOfSize, genVerificationKey) import Hydra.Ledger.Cardano.Evaluate (genPointInTimeBefore, genValidityBoundsFromContestationPeriod, slotLength, systemStart) -import Hydra.Ledger.Cardano.Json () import Hydra.Ledger.Cardano.Time (slotNoFromUTCTime) import Hydra.OnChainId (OnChainId) import Hydra.Party (Party, deriveParty, partyToChain) diff --git a/hydra-node/src/Hydra/Chain/Direct/Wallet.hs b/hydra-node/src/Hydra/Chain/Direct/Wallet.hs index e2345ff46b6..f4a0e5bf4c4 100644 --- a/hydra-node/src/Hydra/Chain/Direct/Wallet.hs +++ b/hydra-node/src/Hydra/Chain/Direct/Wallet.hs @@ -10,10 +10,11 @@ import Cardano.Api.UTxO (UTxO) import Cardano.Api.UTxO qualified as UTxO import Cardano.Crypto.Hash.Class import Cardano.Ledger.Address qualified as Ledger -import Cardano.Ledger.Alonzo.Plutus.TxInfo (TranslationError) -import Cardano.Ledger.Alonzo.PlutusScriptApi (language) -import Cardano.Ledger.Alonzo.Scripts (ExUnits (ExUnits), Tag (Spend), txscriptfee) -import Cardano.Ledger.Alonzo.TxWits (AlonzoTxWits (..), RdmrPtr (RdmrPtr), Redeemers (..), txdats, txscripts) +import Cardano.Ledger.Alonzo (AlonzoScript) +import Cardano.Ledger.Alonzo.PParams (LangDepView) +import Cardano.Ledger.Alonzo.Plutus.Context (ContextError) +import Cardano.Ledger.Alonzo.Scripts (AlonzoEraScript (..), AlonzoPlutusPurpose (AlonzoSpending), AsIndex (..), ExUnits (ExUnits), plutusScriptLanguage, txscriptfee, unAsIndex) +import Cardano.Ledger.Alonzo.TxWits (AlonzoTxWits (..), Redeemers (..), txdats, txscripts) import Cardano.Ledger.Api (TransactionScriptFailure, ensureMinCoinTxOut, evalTxExUnits, outputsTxBodyL, ppMaxTxExUnitsL, ppPricesL) import Cardano.Ledger.Babbage.Tx (body, getLanguageView, hashScriptIntegrity, wits) import Cardano.Ledger.Babbage.Tx qualified as Babbage @@ -215,8 +216,8 @@ data ErrCoverFee = ErrNotEnoughFunds ChangeError | ErrNoFuelUTxOFound | ErrUnknownInput {input :: TxIn} - | ErrScriptExecutionFailed {scriptFailure :: (RdmrPtr, TransactionScriptFailure LedgerEra)} - | ErrTranslationError (TranslationError StandardCrypto) + | ErrScriptExecutionFailed {scriptFailure :: (PlutusPurpose AsIndex LedgerEra, TransactionScriptFailure LedgerEra)} + | ErrTranslationError (ContextError LedgerEra) deriving stock (Show) data ChangeError = ChangeError {inputBalance :: Coin, outputBalance :: Coin} @@ -267,12 +268,14 @@ coverFee_ pparams systemStart epochInfo lookupUTxO walletUTxO partialTx@Babbage. needlesslyHighFee let newOutputs = txOuts <> StrictSeq.singleton change + referenceScripts :: Map (Ledger.ScriptHash StandardCrypto) (AlonzoScript LedgerEra) referenceScripts = getReferenceScripts @LedgerEra (Ledger.UTxO utxo) (Babbage.referenceInputs' body) + langs :: [LangDepView] langs = [ getLanguageView pparams l | (_hash, script) <- Map.toList $ Map.union (txscripts wits) referenceScripts , (not . isNativeScript @LedgerEra) script - , l <- maybeToList (language script) + , l <- maybeToList $ plutusScriptLanguage <$> toPlutusScript script ] finalBody = body @@ -328,14 +331,14 @@ coverFee_ pparams systemStart epochInfo lookupUTxO walletUTxO partialTx@Babbage. , outputBalance = totalOut } | otherwise = - Right $ Babbage.BabbageTxOut addr (inject changeOut) datum refScript + Right $ Babbage.BabbageTxOut addr (Ledger.inject changeOut) datum refScript where totalOut = foldMap getAdaValue otherOutputs <> fee totalIn = foldMap getAdaValue resolvedInputs changeOut = totalIn <> invert totalOut refScript = SNothing - adjustRedeemers :: Set TxIn -> Set TxIn -> Map RdmrPtr ExUnits -> Redeemers LedgerEra -> Redeemers LedgerEra + adjustRedeemers :: Set TxIn -> Set TxIn -> Map (PlutusPurpose AsIndex LedgerEra) ExUnits -> Redeemers LedgerEra -> Redeemers LedgerEra adjustRedeemers initialInputs finalInputs estimatedCosts (Redeemers initialRedeemers) = Redeemers $ Map.fromList $ map adjustOne $ Map.toList initialRedeemers where @@ -345,13 +348,13 @@ coverFee_ pparams systemStart epochInfo lookupUTxO walletUTxO partialTx@Babbage. adjustOne (ptr, (d, _exUnits)) = case ptr of - RdmrPtr Spend idx - | fromIntegral idx `elem` differences -> - (RdmrPtr Spend (idx + 1), (d, executionUnitsFor ptr)) + AlonzoSpending idx + | fromIntegral (unAsIndex idx) `elem` differences -> + (AlonzoSpending (AsIndex (unAsIndex idx + 1)), (d, executionUnitsFor ptr)) _ -> (ptr, (d, executionUnitsFor ptr)) - executionUnitsFor :: RdmrPtr -> ExUnits + executionUnitsFor :: PlutusPurpose AsIndex LedgerEra -> ExUnits executionUnitsFor ptr = let ExUnits maxMem maxCpu = pparams ^. ppMaxTxExUnitsL ExUnits totalMem totalCpu = foldMap identity estimatedCosts @@ -387,7 +390,7 @@ estimateScriptsCost :: Map TxIn TxOut -> -- | The pre-constructed transaction Babbage.AlonzoTx LedgerEra -> - Either ErrCoverFee (Map RdmrPtr ExUnits) + Either ErrCoverFee (Map (PlutusPurpose AsIndex LedgerEra) ExUnits) estimateScriptsCost pparams systemStart epochInfo utxo tx = do case result of Left translationError -> diff --git a/hydra-node/src/Hydra/Ledger/Cardano.hs b/hydra-node/src/Hydra/Ledger/Cardano.hs index d266c0ec50d..3fe892f6184 100644 --- a/hydra-node/src/Hydra/Ledger/Cardano.hs +++ b/hydra-node/src/Hydra/Ledger/Cardano.hs @@ -40,7 +40,6 @@ import Data.Text.Lazy.Builder (toLazyText) import Formatting.Buildable (build) import Hydra.Contract.Head qualified as Head import Hydra.Ledger (ChainSlot (..), IsTx (..), Ledger (..), ValidationError (..)) -import Hydra.Ledger.Cardano.Json () import PlutusLedgerApi.V2 (fromBuiltin) import Test.Cardano.Ledger.Babbage.Arbitrary () import Test.QuickCheck ( @@ -434,8 +433,7 @@ genValue = fmap ((lovelaceToValue $ Lovelace 10_000_000) <>) (scale (`div` 10) $ -- | Generate UTXO entries that do not contain any assets. Useful to test / -- measure cases where genAdaOnlyUTxO :: Gen UTxO -genAdaOnlyUTxO = do - fmap adaOnly <$> arbitrary +genAdaOnlyUTxO = fmap adaOnly <$> arbitrary adaOnly :: TxOut CtxUTxO -> TxOut CtxUTxO adaOnly = \case @@ -482,8 +480,7 @@ instance Arbitrary (VerificationKey PaymentKey) where arbitrary = fst <$> genKeyPair instance Arbitrary (Hash PaymentKey) where - arbitrary = do - unsafePaymentKeyHashFromBytes . BS.pack <$> vectorOf 28 arbitrary + arbitrary = unsafePaymentKeyHashFromBytes . BS.pack <$> vectorOf 28 arbitrary instance ToCBOR UTxO where toCBOR = toCBOR . toLedgerUTxO diff --git a/hydra-node/src/Hydra/Ledger/Cardano/Configuration.hs b/hydra-node/src/Hydra/Ledger/Cardano/Configuration.hs index d651d01b7b5..7cfa90f7fe5 100644 --- a/hydra-node/src/Hydra/Ledger/Cardano/Configuration.hs +++ b/hydra-node/src/Hydra/Ledger/Cardano/Configuration.hs @@ -16,7 +16,6 @@ import Cardano.Slotting.EpochInfo (fixedEpochInfo) import Cardano.Slotting.Time (mkSlotLength) import Data.Aeson qualified as Json import Data.Aeson.Types qualified as Json -import Hydra.Ledger.Cardano.Json () -- * Helpers diff --git a/hydra-node/src/Hydra/Ledger/Cardano/Evaluate.hs b/hydra-node/src/Hydra/Ledger/Cardano/Evaluate.hs index 1689c1e0081..5a807ab6b85 100644 --- a/hydra-node/src/Hydra/Ledger/Cardano/Evaluate.hs +++ b/hydra-node/src/Hydra/Ledger/Cardano/Evaluate.hs @@ -13,16 +13,15 @@ module Hydra.Ledger.Cardano.Evaluate where import Hydra.Prelude hiding (label) import Cardano.Api.UTxO qualified as UTxO -import Cardano.Ledger.Alonzo.Plutus.TxInfo (PlutusWithContext (PlutusWithContext)) -import Cardano.Ledger.Alonzo.PlutusScriptApi qualified as Ledger -import Cardano.Ledger.Alonzo.Scripts (CostModel, Prices (..), costModelsValid, emptyCostModels, mkCostModel, txscriptfee) +import Cardano.Ledger.Alonzo.Plutus.Evaluate (collectPlutusScriptsWithContext) +import Cardano.Ledger.Alonzo.Scripts (CostModel, Prices (..), mkCostModel, mkCostModels, txscriptfee) import Cardano.Ledger.Api (CoinPerByte (..), ppCoinsPerUTxOByteL, ppCostModelsL, ppMaxBlockExUnitsL, ppMaxTxExUnitsL, ppMaxValSizeL, ppMinFeeAL, ppMinFeeBL, ppPricesL, ppProtocolVersionL) import Cardano.Ledger.BaseTypes (BoundedRational (boundRational), ProtVer (..), natVersion) import Cardano.Ledger.Binary (getVersion) import Cardano.Ledger.Coin (Coin (Coin)) import Cardano.Ledger.Core (PParams, ppMaxTxSizeL) -import Cardano.Ledger.Plutus.Data qualified as Ledger -import Cardano.Ledger.Plutus.Language (BinaryPlutus (..), Language (PlutusV2), Plutus (..)) +import Cardano.Ledger.Plutus (PlutusDatums (unPlutusDatums), PlutusLanguage (decodePlutusRunnable), PlutusRunnable (..), PlutusWithContext (..)) +import Cardano.Ledger.Plutus.Language (Language (PlutusV2)) import Cardano.Ledger.Val (Val ((<+>)), (<×>)) import Cardano.Slotting.EpochInfo (EpochInfo, fixedEpochInfo) import Cardano.Slotting.Slot (EpochNo (EpochNo), EpochSize (EpochSize), SlotNo (SlotNo)) @@ -39,6 +38,7 @@ import Data.SOP.NonEmpty (NonEmpty (NonEmptyOne)) import Data.Time.Clock.POSIX (posixSecondsToUTCTime) import Flat (flat) import Hydra.Cardano.Api ( + Era, EraHistory (EraHistory), ExecutionUnits (..), IsCardanoEra (cardanoEra), @@ -143,7 +143,7 @@ checkBudget maxUnits report -- 'TransactionValidityError' with additional cases. data EvaluationError = TransactionBudgetOverspent {used :: ExecutionUnits, available :: ExecutionUnits} - | TransactionInvalid TransactionValidityError + | TransactionInvalid (TransactionValidityError Era) | PParamsConversion ProtocolParametersConversionError deriving stock (Show) @@ -215,15 +215,18 @@ prepareTxScripts :: prepareTxScripts tx utxo = do -- Tuples with scripts and their arguments collected from the tx results <- - case Ledger.collectPlutusScriptsWithContext epochInfo systemStart pparams ltx lutxo of + case collectPlutusScriptsWithContext epochInfo systemStart pparams ltx lutxo of Left e -> Left $ show e Right x -> pure x -- Fully applied UPLC programs which we could run using the cekMachine - programs <- forM results $ \(PlutusWithContext (Plutus _ (BinaryPlutus script)) arguments _exUnits _costModel) -> do - let pArgs = Ledger.getPlutusData <$> arguments - x <- left show $ Plutus.deserialiseScript Plutus.PlutusV2 protocolVersion script - appliedTerm <- left show $ mkTermToEvaluate Plutus.PlutusV2 protocolVersion x pArgs + programs <- forM results $ \(PlutusWithContext protocolVersion script arguments _exUnits _costModel) -> do + (PlutusRunnable x) <- + case script of + Right runnable -> pure runnable + Left serialised -> left show $ decodePlutusRunnable protocolVersion serialised + let majorProtocolVersion = Plutus.MajorProtocolVersion $ getVersion protocolVersion + appliedTerm <- left show $ mkTermToEvaluate Plutus.PlutusV2 majorProtocolVersion x (unPlutusDatums arguments) pure $ UPLC.Program () PLC.latestVersion appliedTerm pure $ flat . UnrestrictedProgram <$> programs @@ -232,10 +235,6 @@ prepareTxScripts tx utxo = do lutxo = toLedgerUTxO utxo - protocolVersion = - let ProtVer{pvMajor} = pparams ^. ppProtocolVersionL - in Plutus.MajorProtocolVersion $ getVersion pvMajor - -- * Fixtures -- | Current (2023-04-12) mainchain protocol parameters. @@ -246,7 +245,7 @@ prepareTxScripts tx utxo = do pparams :: PParams LedgerEra pparams = def - & ppMaxTxSizeL .~ maxTxSize + & ppMaxTxSizeL .~ fromIntegral maxTxSize & ppMaxValSizeL .~ 1000000000 & ppMinFeeAL .~ Coin 44 & ppMinFeeBL .~ Coin 155381 @@ -264,7 +263,7 @@ pparams = , prMem = fromJust $ boundRational $ 577 % 10000 } & ppProtocolVersionL .~ ProtVer{pvMajor = natVersion @8, pvMinor = 0} - & ppCostModelsL .~ emptyCostModels{costModelsValid = Map.fromList [(PlutusV2, plutusV2CostModel)]} + & ppCostModelsL .~ mkCostModels (Map.fromList [(PlutusV2, plutusV2CostModel)]) maxTxSize :: Natural maxTxSize = 16384 diff --git a/hydra-node/src/Hydra/Ledger/Cardano/Json.hs b/hydra-node/src/Hydra/Ledger/Cardano/Json.hs deleted file mode 100644 index 1b5f0c26518..00000000000 --- a/hydra-node/src/Hydra/Ledger/Cardano/Json.hs +++ /dev/null @@ -1,76 +0,0 @@ -{-# LANGUAGE AllowAmbiguousTypes #-} -{-# LANGUAGE UndecidableInstances #-} -{-# OPTIONS_GHC -Wno-orphans #-} - --- | Orphans ToJSON/FromJSON instances on ledger types used by --- Hydra.Ledger.Cardano to have JSON representations for various types. --- --- XXX: The ledger team notified that we should be using lenses going forward. -module Hydra.Ledger.Cardano.Json where - -import Hydra.Cardano.Api -import Hydra.Prelude - -import Cardano.Ledger.Api (Babbage) -import Cardano.Ledger.Api.Era (eraProtVerLow) -import Cardano.Ledger.Babbage.PParams (BabbagePParams (..)) -import Cardano.Ledger.Babbage.PParams qualified as Ledger -import Cardano.Ledger.Shelley.API qualified as Ledger -import Data.Aeson ( - (.!=), - (.:), - (.:?), - ) -import Data.Aeson qualified as Aeson - --- XXX: Maybe use babbagePParamsHKDPairs? -instance FromJSON (Ledger.BabbagePParams Identity era) where - parseJSON = - Aeson.withObject "PParams" $ \obj -> - BabbagePParams - <$> obj - .: "minFeeA" - <*> obj - .: "minFeeB" - <*> obj - .: "maxBlockBodySize" - <*> obj - .: "maxTxSize" - <*> obj - .: "maxBlockHeaderSize" - <*> obj - .: "keyDeposit" - <*> obj - .: "poolDeposit" - <*> obj - .: "eMax" - <*> obj - .: "nOpt" - <*> obj - .: "a0" - <*> obj - .: "rho" - <*> obj - .: "tau" - -- NOTE: 'protocolVersion' here is set to optional until the upstream - -- bug fix is released. Relevant PR https://github.com/IntersectMBO/cardano-ledger/pull/3953 - <*> (obj .:? "protocolVersion" .!= Ledger.ProtVer (eraProtVerLow @Babbage) 0) - <*> obj - .: "minPoolCost" - .!= mempty - <*> obj - .: "coinsPerUTxOByte" - <*> obj - .: "costmdls" - <*> obj - .: "prices" - <*> obj - .: "maxTxExUnits" - <*> obj - .: "maxBlockExUnits" - <*> obj - .: "maxValSize" - <*> obj - .: "collateralPercentage" - <*> obj - .: "maxCollateralInputs" diff --git a/hydra-node/test/Hydra/Chain/Direct/Contract/Mutation.hs b/hydra-node/test/Hydra/Chain/Direct/Contract/Mutation.hs index c18fc6cf67b..256ed343681 100644 --- a/hydra-node/test/Hydra/Chain/Direct/Contract/Mutation.hs +++ b/hydra-node/test/Hydra/Chain/Direct/Contract/Mutation.hs @@ -133,7 +133,7 @@ import Hydra.Cardano.Api import Cardano.Api.UTxO qualified as UTxO import Cardano.Ledger.Alonzo.Scripts qualified as Ledger import Cardano.Ledger.Alonzo.TxWits qualified as Ledger -import Cardano.Ledger.Api (outputsTxBodyL) +import Cardano.Ledger.Api (AlonzoPlutusPurpose (..), AsIndex (..), outputsTxBodyL) import Cardano.Ledger.Babbage.TxBody qualified as Ledger import Cardano.Ledger.Binary (mkSized) import Cardano.Ledger.Core qualified as Ledger @@ -326,12 +326,18 @@ applyMutation mutation (tx@(Tx body wits), utxo) = case mutation of redeemers' = alterRedeemers newHeadRedeemer scriptData - newHeadRedeemer (Ledger.RdmrPtr _ ix) (dat, units) + newHeadRedeemer ix (dat, units) | isHeadOutput (resolveInput ix) = (Ledger.Data (toData newRedeemer), units) | otherwise = (dat, units) + resolveInput :: Ledger.AlonzoPlutusPurpose AsIndex w -> TxOut CtxUTxO resolveInput ix = - let txIn = Set.elemAt (fromIntegral ix) ledgerInputs -- NOTE: calls 'error' if out of bounds + let k = case ix of + AlonzoSpending i -> unAsIndex i + AlonzoCertifying i -> unAsIndex i + AlonzoRewarding i -> unAsIndex i + AlonzoMinting i -> unAsIndex i + txIn = Set.elemAt (fromIntegral k) ledgerInputs -- NOTE: calls 'error' if out of bounds in case UTxO.resolve (fromLedgerTxIn txIn) utxo of Nothing -> error $ "txIn not resolvable: " <> show txIn Just o -> o @@ -432,7 +438,13 @@ applyMutation mutation (tx@(Tx body wits), utxo) = case mutation of else case scriptData of TxBodyNoScriptData -> TxBodyNoScriptData TxBodyScriptData dats (Ledger.Redeemers redeemers) -> - let newRedeemers = Map.filterWithKey (\(Ledger.RdmrPtr tag _) _ -> tag /= Ledger.Mint) redeemers + let newRedeemers = + Map.filterWithKey + ( \x _ -> case x of + Ledger.AlonzoMinting _ -> False + _ -> True + ) + redeemers in TxBodyScriptData dats (Ledger.Redeemers newRedeemers) ChangeRequiredSigners newSigners -> (Tx body' wits, utxo) @@ -584,7 +596,7 @@ ensureDatums outs scriptData = -- | Alter a transaction's redeemers map given some mapping function. alterRedeemers :: - ( Ledger.RdmrPtr -> + ( Ledger.PlutusPurpose Ledger.AsIndex LedgerEra -> (Ledger.Data LedgerEra, Ledger.ExUnits) -> (Ledger.Data LedgerEra, Ledger.ExUnits) ) -> @@ -617,15 +629,21 @@ alterTxIns fn tx = redeemers' = Ledger.Redeemers $ rebuiltSpendingRedeemers <> nonSpendingRedeemers nonSpendingRedeemers = - Map.filterWithKey (\(Ledger.RdmrPtr tag _) _ -> tag /= Ledger.Spend) redeemersMap + Map.filterWithKey + ( \x _ -> case x of + Ledger.AlonzoSpending _ -> False + _ -> True + ) + redeemersMap rebuiltSpendingRedeemers = Map.fromList $ flip mapMaybe (zip [0 ..] newSortedInputs) $ \(i, (_, mRedeemer)) -> mRedeemer <&> \d -> - (Ledger.RdmrPtr Ledger.Spend i, (toLedgerData d, Ledger.ExUnits 0 0)) + (Ledger.AlonzoSpending (AsIndex i), (toLedgerData d, Ledger.ExUnits 0 0)) -- NOTE: This needs to be ordered, such that we can calculate the redeemer -- pointers correctly. + newSortedInputs :: [(TxIn, Maybe HashableScriptData)] newSortedInputs = sortOn fst $ fn @@ -637,7 +655,7 @@ alterTxIns fn tx = resolveRedeemers :: [TxIn] -> [(TxIn, Maybe HashableScriptData)] resolveRedeemers txInputs = zip txInputs [0 ..] <&> \(txIn, i) -> - case Map.lookup (Ledger.RdmrPtr Ledger.Spend i) redeemersMap of + case Map.lookup (Ledger.AlonzoSpending (AsIndex i)) redeemersMap of Nothing -> (txIn, Nothing) Just (redeemerData, _exUnits) -> (txIn, Just $ fromLedgerData redeemerData) diff --git a/hydra-node/test/Hydra/Chain/Direct/ContractSpec.hs b/hydra-node/test/Hydra/Chain/Direct/ContractSpec.hs index b9a3b2c9dc6..e6a169a3af7 100644 --- a/hydra-node/test/Hydra/Chain/Direct/ContractSpec.hs +++ b/hydra-node/test/Hydra/Chain/Direct/ContractSpec.hs @@ -8,8 +8,8 @@ import Test.Hydra.Prelude import Cardano.Api.UTxO qualified as UTxO import Cardano.Crypto.Util (SignableRepresentation (getSignableRepresentation)) -import Cardano.Ledger.Alonzo.TxInfo (TxOutSource (TxOutFromOutput)) -import Cardano.Ledger.Babbage.TxInfo (txInfoOutV2) +import Cardano.Ledger.Alonzo.Plutus.TxInfo (TxOutSource (TxOutFromOutput)) +import Cardano.Ledger.Babbage.TxInfo (transTxOutV2) import Cardano.Ledger.BaseTypes qualified as Ledger import Data.ByteString.Base16 qualified as Base16 import Data.List qualified as List @@ -158,7 +158,7 @@ prop_consistentOnAndOffChainHashOfTxOuts = let plutusTxOuts = rights $ zipWith - (\ix o -> txInfoOutV2 (TxOutFromOutput $ Ledger.TxIx ix) $ toLedgerTxOut o) + (\ix o -> transTxOutV2 (TxOutFromOutput $ Ledger.TxIx ix) $ toLedgerTxOut o) [0 ..] txOuts txOuts = map snd . sortOn fst $ UTxO.pairs utxo @@ -188,7 +188,7 @@ prop_hashingCaresAboutOrderingOfTxOuts = let plutusTxOuts = rights $ zipWith - (\ix o -> txInfoOutV2 (TxOutFromOutput $ Ledger.TxIx ix) $ toLedgerTxOut o) + (\ix o -> transTxOutV2 (TxOutFromOutput $ Ledger.TxIx ix) $ toLedgerTxOut o) [0 ..] txOuts txOuts = snd <$> UTxO.pairs utxo diff --git a/hydra-node/test/Hydra/Chain/Direct/WalletSpec.hs b/hydra-node/test/Hydra/Chain/Direct/WalletSpec.hs index 76af8487350..aa4dc153f0e 100644 --- a/hydra-node/test/Hydra/Chain/Direct/WalletSpec.hs +++ b/hydra-node/test/Hydra/Chain/Direct/WalletSpec.hs @@ -329,7 +329,7 @@ genUTxO = do where scaleAda :: TxOut -> TxOut scaleAda (BabbageTxOut addr value datum refScript) = - let value' = value <> inject (Coin 20_000_000) + let value' = value <> Ledger.inject (Coin 20_000_000) in BabbageTxOut addr value' datum refScript genOutputsForInputs :: Tx LedgerEra -> Gen (Map TxIn TxOut) diff --git a/hydra-plutus/hydra-plutus.cabal b/hydra-plutus/hydra-plutus.cabal index fe5d464d225..3b1291b0aec 100644 --- a/hydra-plutus/hydra-plutus.cabal +++ b/hydra-plutus/hydra-plutus.cabal @@ -69,10 +69,10 @@ library , hydra-cardano-api , hydra-plutus-extras , hydra-prelude - , plutus-core >=1.15.0.1 && <1.16 - , plutus-ledger-api >=1.15.0.1 && <1.16 - , plutus-tx >=1.15.0.1 && <1.16 - , plutus-tx-plugin >=1.15.0.1 && <1.16 + , plutus-core >=1.21 && <1.22 + , plutus-ledger-api >=1.21 && <1.22 + , plutus-tx >=1.21 && <1.22 + , plutus-tx-plugin >=1.21 && <1.22 , QuickCheck , serialise , template-haskell diff --git a/hydra-test-utils/src/Test/Plutus/Validator.hs b/hydra-test-utils/src/Test/Plutus/Validator.hs index 91c254fb353..7e4ee1f19be 100644 --- a/hydra-test-utils/src/Test/Plutus/Validator.hs +++ b/hydra-test-utils/src/Test/Plutus/Validator.hs @@ -14,7 +14,7 @@ import Hydra.Prelude import Cardano.Api.UTxO qualified as UTxO import Cardano.Ledger.Alonzo.Core qualified as Ledger -import Cardano.Ledger.Alonzo.Scripts (CostModel, costModelsValid, emptyCostModels, mkCostModel) +import Cardano.Ledger.Alonzo.Scripts (CostModel, mkCostModel, mkCostModels) import Cardano.Ledger.BaseTypes (ProtVer (..), natVersion) import Cardano.Ledger.Plutus.Language (Language (PlutusV2)) import Cardano.Slotting.EpochInfo (fixedEpochInfo) @@ -95,7 +95,7 @@ evaluateScriptExecutionUnits validatorScript redeemer = pparams :: Ledger.PParams LedgerEra pparams = def - & Ledger.ppCostModelsL .~ emptyCostModels{costModelsValid = Map.fromList [(PlutusV2, plutusV2CostModel)]} + & Ledger.ppCostModelsL .~ mkCostModels (Map.fromList [(PlutusV2, plutusV2CostModel)]) & Ledger.ppMaxTxExUnitsL .~ toLedgerExUnits defaultMaxExecutionUnits & Ledger.ppProtocolVersionL .~ ProtVer{pvMajor = natVersion @8, pvMinor = 0} diff --git a/hydra-tui/hydra-tui.cabal b/hydra-tui/hydra-tui.cabal index b1131f7c8ad..ac7b58bfef2 100644 --- a/hydra-tui/hydra-tui.cabal +++ b/hydra-tui/hydra-tui.cabal @@ -58,7 +58,7 @@ library , aeson , async , base - , brick ==1.10 + , brick >=1.10 , containers , hydra-cardano-api , hydra-node @@ -72,6 +72,7 @@ library , text , time , vty + , vty-unix , websockets executable hydra-tui @@ -111,6 +112,7 @@ test-suite tests , regex-tdfa , unix , vty + , vty-unix build-tool-depends: , hspec-discover:hspec-discover diff --git a/hydra-tui/src/Hydra/TUI.hs b/hydra-tui/src/Hydra/TUI.hs index fd6df612d80..4d32b33e348 100644 --- a/hydra-tui/src/Hydra/TUI.hs +++ b/hydra-tui/src/Hydra/TUI.hs @@ -12,8 +12,8 @@ import Brick.BChan (newBChan, writeBChan) import Graphics.Vty ( Vty, defaultConfig, - mkVty, ) +import Graphics.Vty.Platform.Unix (mkVty) import Hydra.Chain.CardanoClient (mkCardanoClient) import Hydra.Chain.Direct.State () import Hydra.Client (HydraEvent (..), withClient) diff --git a/hydra-tui/test/Hydra/TUISpec.hs b/hydra-tui/test/Hydra/TUISpec.hs index 2b3f8ad66d7..19464956319 100644 --- a/hydra-tui/test/Hydra/TUISpec.hs +++ b/hydra-tui/test/Hydra/TUISpec.hs @@ -20,14 +20,13 @@ import Graphics.Vty ( defaultConfig, displayContext, initialAssumedState, - inputForConfig, - outputFd, - outputForConfig, outputPicture, shutdownInput, - termName, ) import Graphics.Vty.Image (DisplayRegion) +import Graphics.Vty.Platform.Unix.Input (buildInput) +import Graphics.Vty.Platform.Unix.Output (buildOutput) +import Graphics.Vty.Platform.Unix.Settings (defaultSettings) import Hydra.Cardano.Api (Key (getVerificationKey), Lovelace) import Hydra.Cluster.Faucet ( FaucetLog, @@ -239,7 +238,7 @@ withTUITest region action = do findBytes bytes = BS.concat $ BS.drop 1 . BS.dropWhile (/= 109) <$> BS.split 27 bytes buildVty q frameBuffer = do - input <- inputForConfig defaultConfig + input <- buildInput defaultConfig =<< defaultSettings -- NOTE(SN): This is used by outputPicture and we hack it such that it -- always has the initial state to get a full rendering of the picture. That -- way we can capture output bytes line-by-line and drop the cursor moving. @@ -247,7 +246,7 @@ withTUITest region action = do -- NOTE(SN): The null device should allow using this in CI, while we do -- capture the output via `outputByteBuffer` anyway. nullFd <- openFd "/dev/null" WriteOnly defaultFileFlags - realOut <- outputForConfig $ defaultConfig{outputFd = Just nullFd, termName = Just "xterm"} + realOut <- buildOutput =<< defaultSettings closeFd nullFd let output = testOut realOut as frameBuffer pure $