Skip to content

Commit

Permalink
Fixes after rebase work
Browse files Browse the repository at this point in the history
  • Loading branch information
v0d1ch committed Dec 24, 2023
1 parent 00a1985 commit 32676cd
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 41 deletions.
4 changes: 2 additions & 2 deletions hydra-cluster/src/CardanoNode.hs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ module CardanoNode where

import Hydra.Prelude

import Control.Lens ((?~), (^?!))
import Cardano.Ledger.Core (PParams)
import Control.Lens ((?~), (^?!))
import Control.Tracer (Tracer, traceWith)
import Data.Aeson (Value (String), (.=))
import Data.Aeson qualified as Aeson
Expand Down Expand Up @@ -121,7 +121,7 @@ withCardanoNodeDevnet ::
IO a
withCardanoNodeDevnet tracer stateDirectory action = do
args <- setupCardanoDevnet stateDirectory
withCardanoNode tracer networkId stateDirectory args $ \rn -> do
withCardanoNode tracer stateDirectory args $ \nodeSocket -> do
traceWith tracer MsgNodeIsReady
pparams <- queryProtocolParameters networkId nodeSocket QueryTip
let rn =
Expand Down
5 changes: 5 additions & 0 deletions hydra-cluster/src/Hydra/Cluster/Fixture.hs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@ module Hydra.Cluster.Fixture where

import Hydra.Prelude

import Cardano.Ledger.Core (PParams)
import Hydra.Cardano.Api (NetworkId)
import Hydra.Cardano.Api qualified as Api
import Hydra.ContestationPeriod (ContestationPeriod (..))
import Hydra.Crypto (HydraKey, SigningKey, VerificationKey, generateSigningKey, getVerificationKey)
import Hydra.Ledger.Cardano.Configuration (pparamsFromJson, readJsonFileThrow)
import Hydra.Party (Party, deriveParty)

alice, bob, carol :: Party
Expand Down Expand Up @@ -37,6 +39,9 @@ cperiod = UnsafeContestationPeriod 10
defaultNetworkId :: NetworkId
defaultNetworkId = Api.Testnet (Api.NetworkMagic 42)

loadDefaultPParams :: IO (PParams Api.LedgerEra)
loadDefaultPParams = readJsonFileThrow pparamsFromJson "./config/pparams.json"

-- NOTE: This is hard-coded and needs to correspond to the initial funds set in
-- the genesis-shelley.json file.
availableInitialFunds :: Num a => a
Expand Down
7 changes: 2 additions & 5 deletions hydra-cluster/src/HydraNode.hs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import Data.List qualified as List
import Data.Text (pack)
import Data.Text qualified as T
import Hydra.API.HTTPServer (DraftCommitTxRequest (..), DraftCommitTxResponse (..), TxOutWithWitness (..))
import Hydra.Cluster.Util (readConfigFile)
import Hydra.ContestationPeriod (ContestationPeriod)
import Hydra.Crypto (HydraKey)
import Hydra.Ledger.Cardano ()
Expand Down Expand Up @@ -306,7 +305,7 @@ withHydraNode' ::
IO a
withHydraNode' chainConfig workDir hydraNodeId hydraSKey hydraVKeys allNodeIds pparams mGivenStdOut action = do
withSystemTempDirectory "hydra-node" $ \dir -> do
let cardanoLedgerProtocolParametersFile = dir </> "protocol-parameters.json"
let cardanoLedgerProtocolParametersFile = dir </> "pparams.json"
writeFileBS cardanoLedgerProtocolParametersFile (writeZeroedPParams pparams)
let hydraSigningKey = dir </> (show hydraNodeId <> ".sk")
void $ writeFileTextEnvelope (File hydraSigningKey) Nothing hydraSKey
Expand Down Expand Up @@ -350,7 +349,7 @@ withHydraNode' chainConfig workDir hydraNodeId hydraSKey hydraVKeys allNodeIds p
toStrict $
( Aeson.encode (toJSON pparams)
-- FIXME: this is a hack because cardano-ledger has a bug
-- (https://github.com/IntersectMBO/cardano-ledger/issues/3948) in the
-- (https://github.com/IntersectMBO/cardano-ledger/issues/3943) in the
-- BabbagePParams ToJSON instance where 'protocolVersion' is missing.
& atKey "protocolVersion" ?~ toJSON bppProtocolVersion
& atKey "minFeeA" ?~ toJSON (Number 0)
Expand All @@ -361,8 +360,6 @@ withHydraNode' chainConfig workDir hydraNodeId hydraSKey hydraVKeys allNodeIds p
& key "executionUnitPrices" . atKey "priceSteps" ?~ toJSON (Number 0)
)

-- \| jq ".txFeeFixed = 0 | .txFeePerByte = 0 | .executionUnitPrices.priceMemory = 0 | .executionUnitPrices.priceSteps = 0" > protocol-parameters.json

peers =
[ Host
{ Network.hostname = "127.0.0.1"
Expand Down
58 changes: 31 additions & 27 deletions hydra-cluster/test/Test/EndToEndSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ import Hydra.Cluster.Fixture (
carolVk,
cperiod,
defaultNetworkId,
loadDefaultPParams,
)
import Hydra.Cluster.Scenarios (
EndToEndLog (..),
Expand All @@ -92,6 +93,7 @@ import Hydra.Cluster.Util (chainConfigFor, keysFor, modifyConfig)
import Hydra.ContestationPeriod (ContestationPeriod (UnsafeContestationPeriod))
import Hydra.Ledger (txId)
import Hydra.Ledger.Cardano (genKeyPair, genUTxOFor, mkRangedTx, mkSimpleTx)
import Hydra.Ledger.Cardano.Configuration (pparamsFromJson, readJsonFileThrow)
import Hydra.Logging (Tracer, showLogsOnFailure)
import Hydra.Options
import HydraNode (
Expand Down Expand Up @@ -149,9 +151,9 @@ spec = around (showLogsOnFailure "EndToEndSpec") $ do
{ initialUTxOFile = tmpDir </> "utxo.json"
, ledgerGenesisFile = Nothing
}

pparams <- loadDefaultPParams
-- Start a hydra-node in offline mode and submit a transaction from alice to bob
aliceToBob <- withHydraNode (contramap FromHydraNode tracer) offlineConfig tmpDir 0 aliceSk [] [1] $ \node -> do
aliceToBob <- withHydraNode (contramap FromHydraNode tracer) offlineConfig tmpDir 0 aliceSk [] [1] pparams $ \node -> do
let Just (aliceSeedTxIn, aliceSeedTxOut) = UTxO.find (isVkTxOut aliceCardanoVk) initialUTxO
let Right aliceToBob =
mkSimpleTx
Expand All @@ -164,7 +166,7 @@ spec = around (showLogsOnFailure "EndToEndSpec") $ do
pure aliceToBob

-- Restart a hydra-node in offline mode expect we can reverse the transaction (it retains state)
withHydraNode (contramap FromHydraNode tracer) offlineConfig tmpDir 0 aliceSk [] [1] $ \node -> do
withHydraNode (contramap FromHydraNode tracer) offlineConfig tmpDir 0 aliceSk [] [1] pparams $ \node -> do
let
bobTxOut = toUTxOContext $ txOuts' aliceToBob !! 0
Right bobToAlice =
Expand Down Expand Up @@ -499,13 +501,13 @@ spec = around (showLogsOnFailure "EndToEndSpec") $ do
withCardanoNodeDevnet (contramap FromCardanoNode tracer) dir $ \node@RunningNode{nodeSocket, pparams} -> do
hydraScriptsTxId <- publishHydraScriptsAs node Faucet
chainConfig <- chainConfigFor Alice dir nodeSocket hydraScriptsTxId [] (UnsafeContestationPeriod 1)
withHydraNode' chainConfig dir 1 aliceSk [] [1] Nothing pparams $ \stdOut _ _processHandle -> do
withHydraNode' chainConfig dir 1 aliceSk [] [1] pparams Nothing $ \stdOut _ _processHandle -> do
waitForLog 10 stdOut "JSON object with key NodeOptions" $ \line ->
line ^? key "message" . key "tag" == Just (Aeson.String "NodeOptions")

it "logs to a logfile" $ \tracer -> do
withClusterTempDir "logs-to-logfile" $ \dir -> do
withCardanoNodeDevnet (contramap FromCardanoNode tracer) dir $ \node@RunningNode{nodeSocket, networkId, pparams} -> do
withCardanoNodeDevnet (contramap FromCardanoNode tracer) dir $ \node@RunningNode{nodeSocket, pparams} -> do
let hydraTracer = contramap FromHydraNode tracer
hydraScriptsTxId <- publishHydraScriptsAs node Faucet
refuelIfNeeded tracer node Alice 100_000_000
Expand All @@ -523,37 +525,39 @@ spec = around (showLogsOnFailure "EndToEndSpec") $ do
withClusterTempDir "unsupported-era" $ \tmpDir -> do
args <- setupCardanoDevnet tmpDir
forkIntoConwayInEpoch tmpDir args 1
withCardanoNode (contramap FromCardanoNode tracer) defaultNetworkId tmpDir args $
\node@RunningNode{nodeSocket} -> do
hydraScriptsTxId <- publishHydraScriptsAs node Faucet
chainConfig <- chainConfigFor Alice tmpDir nodeSocket hydraScriptsTxId [] cperiod
withHydraNode' chainConfig tmpDir 1 aliceSk [] [1] Nothing $ \out err ph -> do
-- Assert nominal startup
waitForLog 5 out "missing NodeOptions" (Text.isInfixOf "NodeOptions")
withCardanoNode (contramap FromCardanoNode tracer) tmpDir args $ \nodeSocket -> do
pparams <- loadDefaultPParams
let node = RunningNode{nodeSocket, networkId = defaultNetworkId, pparams}
hydraScriptsTxId <- publishHydraScriptsAs node Faucet
chainConfig <- chainConfigFor Alice tmpDir nodeSocket hydraScriptsTxId [] cperiod
withHydraNode' chainConfig tmpDir 1 aliceSk [] [1] pparams Nothing $ \out err ph -> do
-- Assert nominal startup
waitForLog 5 out "missing NodeOptions" (Text.isInfixOf "NodeOptions")

waitUntilEpoch tmpDir args node 1
waitUntilEpoch tmpDir args node 1

waitForProcess ph `shouldReturn` ExitFailure 1
errorOutputs <- hGetContents err
errorOutputs `shouldContain` "Received blocks in unsupported era"
errorOutputs `shouldContain` "upgrade your hydra-node"
waitForProcess ph `shouldReturn` ExitFailure 1
errorOutputs <- hGetContents err
errorOutputs `shouldContain` "Received blocks in unsupported era"
errorOutputs `shouldContain` "upgrade your hydra-node"

it "does report on unsupported era on startup" $ \tracer -> do
withClusterTempDir "unsupported-era-startup" $ \tmpDir -> do
args <- setupCardanoDevnet tmpDir
forkIntoConwayInEpoch tmpDir args 1
withCardanoNode (contramap FromCardanoNode tracer) defaultNetworkId tmpDir args $
\node@RunningNode{nodeSocket} -> do
hydraScriptsTxId <- publishHydraScriptsAs node Faucet
chainConfig <- chainConfigFor Alice tmpDir nodeSocket hydraScriptsTxId [] cperiod
withCardanoNode (contramap FromCardanoNode tracer) tmpDir args $ \nodeSocket -> do
pparams <- loadDefaultPParams
let node = RunningNode{nodeSocket, networkId = defaultNetworkId, pparams}
hydraScriptsTxId <- publishHydraScriptsAs node Faucet
chainConfig <- chainConfigFor Alice tmpDir nodeSocket hydraScriptsTxId [] cperiod

waitUntilEpoch tmpDir args node 2
waitUntilEpoch tmpDir args node 2

withHydraNode' chainConfig tmpDir 1 aliceSk [] [1] Nothing $ \_out err ph -> do
waitForProcess ph `shouldReturn` ExitFailure 1
errorOutputs <- hGetContents err
errorOutputs `shouldContain` "Connected to cardano-node in unsupported era"
errorOutputs `shouldContain` "upgrade your hydra-node"
withHydraNode' chainConfig tmpDir 1 aliceSk [] [1] pparams Nothing $ \_out err ph -> do
waitForProcess ph `shouldReturn` ExitFailure 1
errorOutputs <- hGetContents err
errorOutputs `shouldContain` "Connected to cardano-node in unsupported era"
errorOutputs `shouldContain` "upgrade your hydra-node"

-- | Wait until given number of epoch. This uses the epoch and slot lengths from
-- the 'ShelleyGenesisFile' of the node args passed in.
Expand Down
6 changes: 0 additions & 6 deletions hydra-node/src/Hydra/Node/Run.hs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,6 @@ import Hydra.API.Server (Server (..), withAPIServer)
import Hydra.API.ServerOutput (ServerOutput (..))
import Hydra.Cardano.Api (
ProtocolParametersConversionError,
ShelleyBasedEra (..),
toLedgerPParams,
StandardCrypto,
SystemStart (..),
)
import Hydra.Chain (maximumNumberOfParties)
import Hydra.Chain.CardanoClient (QueryPoint (..), queryGenesisParameters)
Expand Down Expand Up @@ -81,8 +77,6 @@ run opts = do
let RunOptions{chainConfig, ledgerConfig} = opts
pparams <- readJsonFileThrow pparamsFromJson (cardanoLedgerProtocolParametersFile ledgerConfig)

let DirectChainConfig{networkId, nodeSocket} = chainConfig

globals <- getGlobalsForChain chainConfig

withCardanoLedger pparams globals $ \ledger -> do
Expand Down
2 changes: 1 addition & 1 deletion hydra-node/test/Hydra/Ledger/CardanoSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ spec =
shouldParseJSONAs @UTxO bs

-- FIXME: this is expected to fail because of a bug in cardano-ledger
-- (https://github.com/IntersectMBO/cardano-ledger/issues/3948) . Once a fix
-- (https://github.com/IntersectMBO/cardano-ledger/issues/3943) . Once a fix
-- is upstream SB will remove the failure expectation.
describe "PParams" $
prop "Same PParams before/after JSON encoding" (expectFailure roundtripPParams)
Expand Down

0 comments on commit 32676cd

Please sign in to comment.