Skip to content

Commit

Permalink
fixup! Era = ConwayEra
Browse files Browse the repository at this point in the history
  • Loading branch information
locallycompact committed Mar 13, 2024
1 parent f1cfd0a commit b3c46c8
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 35 deletions.
1 change: 0 additions & 1 deletion hydra-cardano-api/hydra-cardano-api.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,6 @@ library
, cardano-ledger-alonzo >=1.6 && <1.7
, cardano-ledger-api >=1.8 && <1.9
, cardano-ledger-babbage >=1.6 && <1.7
, cardano-ledger-conway >=1.12 && <1.13
, cardano-ledger-binary >=1.3 && <1.4
, cardano-ledger-byron >=1.0.0 && <1.1
, cardano-ledger-conway >=1.12 && <1.13
Expand Down
2 changes: 1 addition & 1 deletion hydra-cardano-api/src/Hydra/Cardano/Api/TxBody.hs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module Hydra.Cardano.Api.TxBody where
import Hydra.Cardano.Api.Prelude

import Cardano.Ledger.Alonzo.TxWits qualified as Ledger
import Cardano.Ledger.Api (AsIndex, AsItem (..), PlutusPurpose, ConwayPlutusPurpose (..))
import Cardano.Ledger.Api (AsIndex, AsItem (..), ConwayPlutusPurpose (..), PlutusPurpose)
import Cardano.Ledger.Babbage.Core (redeemerPointer)
import Cardano.Ledger.BaseTypes (strictMaybeToMaybe)
import Cardano.Ledger.Core qualified as Ledger
Expand Down
4 changes: 1 addition & 3 deletions hydra-chain-observer/src/Hydra/ChainObserver.hs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import Hydra.Cardano.Api (
UTxO,
chainTipToChainPoint,
connectToLocalNode,
convertTx,
getChainPoint,
getTxBody,
getTxId,
Expand Down Expand Up @@ -172,8 +171,7 @@ chainSyncClient tracer networkId startingPoint observerHandler =
ClientStNext
{ recvMsgRollForward = \blockInMode tip -> ChainSyncClient $ do
let txs = case blockInMode of
BlockInMode ConwayEra (Block _header conwayTxs) -> mapMaybe convertTx conwayTxs
BlockInMode BabbageEra (Block _header babbageTxs) -> babbageTxs
BlockInMode ConwayEra (Block _header conwayTxs) -> conwayTxs
_ -> []

(BlockInMode _ (Block bh@(BlockHeader _ _ blockNo) _)) = blockInMode
Expand Down
19 changes: 10 additions & 9 deletions hydra-node/hydra-node.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ library
, cardano-crypto-class
, cardano-ledger-alonzo
, cardano-ledger-api
, cardano-ledger-babbage:{cardano-ledger-babbage, testlib}
, cardano-ledger-babbage
, cardano-ledger-binary
, cardano-ledger-conway:{cardano-ledger-conway, testlib}
, cardano-ledger-core
Expand All @@ -137,7 +137,7 @@ library
, hydra-plutus
, hydra-plutus-extras
, hydra-prelude
, io-classes >=0.3.0.0
, io-classes >=0.3.0.0
, iohk-monitoring
, iproute
, lens
Expand All @@ -148,11 +148,11 @@ library
, optparse-applicative
, ouroboros-consensus
, ouroboros-consensus-cardano
, ouroboros-network-api >=0.1.0.0
, ouroboros-network-framework >=0.3.0.0
, ouroboros-network-protocols >=0.3.0.0
, plutus-core >=1.21 && <1.22
, plutus-ledger-api >=1.21 && <1.22
, ouroboros-network-api >=0.1.0.0
, ouroboros-network-framework >=0.3.0.0
, ouroboros-network-protocols >=0.3.0.0
, plutus-core >=1.21 && <1.22
, plutus-ledger-api >=1.21 && <1.22
, prometheus
, QuickCheck
, quickcheck-instances
Expand All @@ -162,8 +162,8 @@ library
, text
, time
, transformers
, typed-protocols >=0.1.0.0
, typed-protocols-cborg >=0.1.0.0
, typed-protocols >=0.1.0.0
, typed-protocols-cborg >=0.1.0.0
, unliftio
, vector
, wai
Expand Down Expand Up @@ -333,6 +333,7 @@ test-suite tests
, cardano-ledger-alonzo
, cardano-ledger-api
, cardano-ledger-babbage:{cardano-ledger-babbage, testlib}
, cardano-ledger-conway
, cardano-ledger-core
, cardano-ledger-mary
, cardano-ledger-shelley
Expand Down
7 changes: 1 addition & 6 deletions hydra-node/src/Hydra/Chain/Direct.hs
Original file line number Diff line number Diff line change
Expand Up @@ -317,12 +317,7 @@ chainSyncClient handler wallet startingPoint =
-- Observe Hydra transactions
onRollForward handler header txs
pure clientStIdle
BlockInMode BabbageEra (Block header txs) -> do
-- Update the tiny wallet
update wallet header txs
-- Observe Hydra transactions
onRollForward handler header txs
pure clientStIdle
BlockInMode era@BabbageEra _ -> throwIO $ EraNotSupportedAnymore{otherEraName = show era}
BlockInMode era@AlonzoEra _ -> throwIO $ EraNotSupportedAnymore{otherEraName = show era}
BlockInMode era@AllegraEra _ -> throwIO $ EraNotSupportedAnymore{otherEraName = show era}
BlockInMode era@MaryEra _ -> throwIO $ EraNotSupportedAnymore{otherEraName = show era}
Expand Down
8 changes: 5 additions & 3 deletions hydra-node/src/Hydra/Chain/Direct/Wallet.hs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import Cardano.Ledger.Address qualified as Ledger
import Cardano.Ledger.Alonzo.Plutus.Context (ContextError)
import Cardano.Ledger.Alonzo.Scripts (
AlonzoEraScript (..),
AlonzoPlutusPurpose (AlonzoSpending),
AsIndex (..),
ExUnits (ExUnits),
plutusScriptLanguage,
Expand Down Expand Up @@ -47,6 +46,9 @@ import Cardano.Ledger.Babbage.TxBody qualified as Babbage
import Cardano.Ledger.Babbage.UTxO (getReferenceScripts)
import Cardano.Ledger.BaseTypes qualified as Ledger
import Cardano.Ledger.Coin (Coin (..))
import Cardano.Ledger.Conway.Scripts (
ConwayPlutusPurpose (ConwaySpending),
)
import Cardano.Ledger.Core (isNativeScript)
import Cardano.Ledger.Core qualified as Core
import Cardano.Ledger.Core qualified as Ledger
Expand Down Expand Up @@ -376,9 +378,9 @@ coverFee_ pparams systemStart epochInfo lookupUTxO walletUTxO partialTx@Babbage.

adjustOne (ptr, (d, _exUnits)) =
case ptr of
AlonzoSpending idx
ConwaySpending idx
| fromIntegral (unAsIndex idx) `elem` differences ->
(AlonzoSpending (AsIndex (unAsIndex idx + 1)), (d, executionUnitsFor ptr))
(ConwaySpending (AsIndex (unAsIndex idx + 1)), (d, executionUnitsFor ptr))
_ ->
(ptr, (d, executionUnitsFor ptr))

Expand Down
23 changes: 13 additions & 10 deletions hydra-node/test/Hydra/Chain/Direct/Contract/Mutation.hs
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,8 @@ 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 (AllegraEraTxBody (vldtTxBodyL), AlonzoPlutusPurpose (..), AsIndex (..), inputsTxBodyL, mintTxBodyL, outputsTxBodyL, reqSignerHashesTxBodyL)
import Cardano.Ledger.Api (AllegraEraTxBody (vldtTxBodyL), AsIndex (..), inputsTxBodyL, mintTxBodyL, outputsTxBodyL, reqSignerHashesTxBodyL)
import Cardano.Ledger.Conway.Scripts (ConwayPlutusPurpose (..))
import Cardano.Ledger.Core qualified as Ledger
import Cardano.Ledger.Credential (Credential (..))
import Cardano.Ledger.Mary.Value qualified as Ledger
Expand Down Expand Up @@ -328,13 +329,15 @@ applyMutation mutation (tx@(Tx body wits), utxo) = case mutation of
| isHeadOutput (resolveInput ix) = (Ledger.Data (toData newRedeemer), units)
| otherwise = (dat, units)

resolveInput :: Ledger.AlonzoPlutusPurpose AsIndex w -> TxOut CtxUTxO
resolveInput :: ConwayPlutusPurpose AsIndex w -> TxOut CtxUTxO
resolveInput ix =
let k = case ix of
AlonzoSpending i -> unAsIndex i
AlonzoCertifying i -> unAsIndex i
AlonzoRewarding i -> unAsIndex i
AlonzoMinting i -> unAsIndex i
ConwaySpending i -> unAsIndex i
ConwayCertifying i -> unAsIndex i
ConwayRewarding i -> unAsIndex i
ConwayMinting i -> unAsIndex i
ConwayVoting i -> unAsIndex i
ConwayProposing 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
Expand Down Expand Up @@ -441,7 +444,7 @@ applyMutation mutation (tx@(Tx body wits), utxo) = case mutation of
let newRedeemers =
Map.filterWithKey
( \x _ -> case x of
Ledger.AlonzoMinting _ -> False
ConwayMinting _ -> False
_ -> True
)
redeemers
Expand Down Expand Up @@ -630,15 +633,15 @@ alterTxIns fn tx =
nonSpendingRedeemers =
Map.filterWithKey
( \x _ -> case x of
Ledger.AlonzoSpending _ -> False
ConwaySpending _ -> False
_ -> True
)
redeemersMap

rebuiltSpendingRedeemers = Map.fromList $
flip mapMaybe (zip [0 ..] newSortedInputs) $ \(i, (_, mRedeemer)) ->
mRedeemer <&> \d ->
(Ledger.AlonzoSpending (AsIndex i), (toLedgerData d, Ledger.ExUnits 0 0))
(ConwaySpending (AsIndex i), (toLedgerData d, Ledger.ExUnits 0 0))

-- NOTE: This needs to be ordered, such that we can calculate the redeemer
-- pointers correctly.
Expand All @@ -654,7 +657,7 @@ alterTxIns fn tx =
resolveRedeemers :: [TxIn] -> [(TxIn, Maybe HashableScriptData)]
resolveRedeemers txInputs =
zip txInputs [0 ..] <&> \(txIn, i) ->
case Map.lookup (Ledger.AlonzoSpending (AsIndex i)) redeemersMap of
case Map.lookup (ConwaySpending (AsIndex i)) redeemersMap of
Nothing -> (txIn, Nothing)
Just (redeemerData, _exUnits) -> (txIn, Just $ fromLedgerData redeemerData)

Expand Down
5 changes: 3 additions & 2 deletions hydra-node/test/Hydra/Chain/Direct/WalletSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@ import Test.Hydra.Prelude

import Cardano.Ledger.Api (EraTx (getMinFeeTx), EraTxBody (feeTxBodyL, inputsTxBodyL), PParams, bodyTxL, coinTxOutL, outputsTxBodyL)
import Cardano.Ledger.Babbage.Tx (AlonzoTx (..))
import Cardano.Ledger.Babbage.TxBody (BabbageTxBody (..), BabbageTxOut (..))
import Cardano.Ledger.Babbage.TxBody (BabbageTxOut (..))
import Cardano.Ledger.BaseTypes qualified as Ledger
import Cardano.Ledger.Coin (Coin (..))
import Cardano.Ledger.Conway.TxBody (ConwayTxBody (..))
import Cardano.Ledger.Core (Tx, Value)
import Cardano.Ledger.SafeHash qualified as SafeHash
import Cardano.Ledger.Shelley.API qualified as Ledger
Expand Down Expand Up @@ -336,7 +337,7 @@ genTxsSpending utxo = scale (round @Double . sqrt . fromIntegral) $ do
-- Generate a TxBody by consuming a UTXO from the state, and generating a new
-- one. The number of UTXO in the state after calling this function remains
-- identical.
genBodyFromUTxO :: StateT (Map TxIn TxOut) Gen (BabbageTxBody LedgerEra)
genBodyFromUTxO :: StateT (Map TxIn TxOut) Gen (ConwayTxBody LedgerEra)
genBodyFromUTxO = do
base <- lift arbitrary
(input, output) <- gets Map.findMax
Expand Down

0 comments on commit b3c46c8

Please sign in to comment.