Skip to content

Commit

Permalink
Merge pull request #6013 from IntersectMBO/mgalazyn/chore/remove-node…
Browse files Browse the repository at this point in the history
…runtime-type

cardano-testnet | Remove `NodeRuntime` type
  • Loading branch information
carbolymer authored Oct 15, 2024
2 parents d23ac18 + b0d8411 commit 959eb8e
Show file tree
Hide file tree
Showing 32 changed files with 108 additions and 114 deletions.
6 changes: 3 additions & 3 deletions cardano-node-chairman/test/Spec/Chairman/Cardano.hs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

module Spec.Chairman.Cardano where

import Cardano.Testnet (allNodes, cardanoTestnetDefault, mkConf)
import Cardano.Testnet (cardanoTestnetDefault, mkConf, testnetNodes)

import Data.Default.Class

Expand All @@ -19,6 +19,6 @@ hprop_chairman :: H.Property
hprop_chairman = integrationRetryWorkspace 2 "cardano-chairman" $ \tempAbsPath' -> H.runWithDefaultWatchdog_ $ do
conf <- mkConf tempAbsPath'

allNodes' <- allNodes <$> cardanoTestnetDefault def def conf
allNodes <- testnetNodes <$> cardanoTestnetDefault def def conf

chairmanOver 120 50 conf allNodes'
chairmanOver 120 50 conf allNodes
4 changes: 2 additions & 2 deletions cardano-node-chairman/test/Spec/Chairman/Chairman.hs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import System.FilePath.Posix ((</>))
import qualified System.IO as IO
import qualified System.Process as IO

import Testnet.Types (NodeRuntime, nodeSocketPath)
import Testnet.Types (TestnetNode, nodeSocketPath)

import qualified Hedgehog as H
import Hedgehog.Extras.Test.Base (Integration)
Expand All @@ -30,7 +30,7 @@ import qualified Hedgehog.Extras.Test.Process as H

{- HLINT ignore "Redundant <&>" -}

chairmanOver :: HasCallStack => Int -> Int -> H.Conf -> [NodeRuntime] -> Integration ()
chairmanOver :: HasCallStack => Int -> Int -> H.Conf -> [TestnetNode] -> Integration ()
chairmanOver timeoutSeconds requiredProgress H.Conf {H.tempAbsPath} allNodes = do
maybeChairman <- H.evalIO $ IO.lookupEnv "DISABLE_CHAIRMAN"
let tempAbsPath' = H.unTmpAbsPath tempAbsPath
Expand Down
11 changes: 8 additions & 3 deletions cardano-testnet/src/Cardano/Testnet.hs
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,14 @@ module Cardano.Testnet (
waitForEpochs,

-- * Runtime
NodeRuntime(..),
allNodes,

TestnetRuntime(..),
testnetSprockets,
spoNodes,
relayNodes,

TestnetNode(..),
isTestnetNodeSpo,
nodeSocketPath,
) where

import Testnet.Components.Query
Expand Down
16 changes: 13 additions & 3 deletions cardano-testnet/src/Testnet/Runtime.hs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ import qualified System.Process as IO
import Testnet.Filepath
import qualified Testnet.Ping as Ping
import Testnet.Process.Run
import Testnet.Types (NodeRuntime (NodeRuntime), TestnetRuntime (configurationFile),
import Testnet.Types (TestnetNode (..), TestnetRuntime (configurationFile),
showIpv4Address, testnetSprockets)

import Hedgehog (MonadTest)
Expand Down Expand Up @@ -115,7 +115,7 @@ startNode
-- ^ Testnet magic
-> [String]
-- ^ The command --socket-path will be added automatically.
-> ExceptT NodeStartFailure m NodeRuntime
-> ExceptT NodeStartFailure m TestnetNode
startNode tp node ipv4 port testnetMagic nodeCmd = GHC.withFrozenCallStack $ do
let tempBaseAbsPath = makeTmpBaseAbsPath tp
socketDir = makeSocketDir tp
Expand Down Expand Up @@ -195,7 +195,17 @@ startNode tp node ipv4 port testnetMagic nodeCmd = GHC.withFrozenCallStack $ do
Ping.pingNode (fromIntegral testnetMagic) sprocket
>>= (firstExceptT (NodeExecutableError . ("Ping error:" <+>) . prettyError) . hoistEither)

pure $ NodeRuntime node ipv4 port sprocket stdIn nodeStdoutFile nodeStderrFile hProcess
pure $ TestnetNode
{ nodeName = node
, poolKeys = Nothing -- they're set in the function caller, if present
, nodeIpv4 = ipv4
, nodePort = port
, nodeSprocket = sprocket
, nodeStdinHandle = stdIn
, nodeStdout = nodeStdoutFile
, nodeStderr = nodeStderrFile
, nodeProcessHandle = hProcess
}
where
-- close provided list of handles when 'ExceptT' throws an error
closeHandlesOnError :: MonadIO m => [IO.Handle] -> ExceptT e m a -> ExceptT e m a
Expand Down
7 changes: 4 additions & 3 deletions cardano-testnet/src/Testnet/Start/Cardano.hs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import qualified Data.Aeson as Aeson
import Data.Bifunctor (first)
import qualified Data.ByteString.Lazy as LBS
import Data.Either
import Data.Functor
import Data.Maybe
import Data.MonoTraversable (Element, MonoFunctor, omap)
import qualified Data.Text as Text
Expand Down Expand Up @@ -350,19 +351,19 @@ cardanoTestnet
]
<> spoNodeCliArgs
<> testnetNodeExtraCliArgs nodeOptions
pure $ flip TestnetNode mKeys <$> eRuntime
pure $ eRuntime <&> \rt -> rt{poolKeys=mKeys}

let (failedNodes, testnetNodes') = partitionEithers eTestnetNodes
unless (null failedNodes) $ do
H.noteShow_ . vsep $ prettyError <$> failedNodes
H.failure

H.annotateShow $ nodeSprocket . testnetNodeRuntime <$> testnetNodes'
H.annotateShow $ nodeSprocket <$> testnetNodes'

-- FIXME: use foldEpochState waiting for chain extensions
now <- H.noteShowIO DTC.getCurrentTime
deadline <- H.noteShow $ DTC.addUTCTime 45 now
forM_ (map (nodeStdout . testnetNodeRuntime) testnetNodes') $ \nodeStdoutFile -> do
forM_ (map nodeStdout testnetNodes') $ \nodeStdoutFile -> do
assertChainExtended deadline nodeLoggingFormat nodeStdoutFile

H.noteShowIO_ DTC.getCurrentTime
Expand Down
36 changes: 11 additions & 25 deletions cardano-testnet/src/Testnet/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,12 @@ module Testnet.Types
, NodeLoggingFormat(..)
, PaymentKeyInfo(..)
, TestnetRuntime(..)
, allNodes
, spoNodes
, relayNodes
, testnetSprockets
, NodeRuntime(..)
, nodeSocketPath
, TestnetNode(..)
, nodeSocketPath
, isTestnetNodeSpo
, testnetNodeStdout
, SpoNodeKeys(..)
, Delegator(..)
, KeyPair(..)
Expand Down Expand Up @@ -120,31 +117,17 @@ data TestnetRuntime = TestnetRuntime
}

testnetSprockets :: TestnetRuntime -> [Sprocket]
testnetSprockets = fmap (nodeSprocket . testnetNodeRuntime) . testnetNodes
testnetSprockets = fmap nodeSprocket . testnetNodes

allNodes :: TestnetRuntime -> [NodeRuntime]
allNodes = fmap testnetNodeRuntime . testnetNodes
spoNodes :: TestnetRuntime -> [TestnetNode]
spoNodes = filter isTestnetNodeSpo . testnetNodes

spoNodes :: TestnetRuntime -> [NodeRuntime]
spoNodes = fmap testnetNodeRuntime . filter isTestnetNodeSpo . testnetNodes

relayNodes :: TestnetRuntime -> [NodeRuntime]
relayNodes = fmap testnetNodeRuntime . filter (not . isTestnetNodeSpo) . testnetNodes
relayNodes :: TestnetRuntime -> [TestnetNode]
relayNodes = filter (not . isTestnetNodeSpo) . testnetNodes

data TestnetNode = TestnetNode
{ testnetNodeRuntime :: !NodeRuntime
, poolKeys :: Maybe SpoNodeKeys -- ^ Keys are only present for SPO nodes
}

testnetNodeStdout :: TestnetNode -> FilePath
testnetNodeStdout = nodeStdout . testnetNodeRuntime

isTestnetNodeSpo :: TestnetNode -> Bool
isTestnetNodeSpo = isJust . poolKeys

-- | Node process runtime parameters
data NodeRuntime = NodeRuntime
{ nodeName :: !String
, poolKeys :: Maybe SpoNodeKeys -- ^ Keys are only present for SPO nodes
, nodeIpv4 :: !HostAddress
, nodePort :: !PortNumber
, nodeSprocket :: !Sprocket
Expand All @@ -154,7 +137,10 @@ data NodeRuntime = NodeRuntime
, nodeProcessHandle :: !IO.ProcessHandle
}

nodeSocketPath :: NodeRuntime -> SocketPath
isTestnetNodeSpo :: TestnetNode -> Bool
isTestnetNodeSpo = isJust . poolKeys

nodeSocketPath :: TestnetNode -> SocketPath
nodeSocketPath = File . H.sprocketSystemName . nodeSprocket

data ColdPoolKey
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,14 +65,14 @@ hprop_plutus_v3 = integrationWorkspace "all-plutus-script-purposes" $ \tempAbsBa
, wallets=wallet0:wallet1:_
} <- cardanoTestnetDefault options def conf

TestnetNode{testnetNodeRuntime} <- H.headM testnetNodes
poolSprocket1 <- H.noteShow $ nodeSprocket testnetNodeRuntime
node <- H.headM testnetNodes
poolSprocket1 <- H.noteShow $ nodeSprocket node
execConfig <- mkExecConfig tempBaseAbsPath poolSprocket1 testnetMagic
H.noteShow_ wallet0
let utxoAddr = Text.unpack $ paymentKeyInfoAddr wallet0
utxoSKeyFile = signingKeyFp $ paymentKeyInfoPair wallet0
utxoSKeyFile2 = signingKeyFp $ paymentKeyInfoPair wallet1
socketPath = nodeSocketPath testnetNodeRuntime
socketPath = nodeSocketPath node

epochStateView <- getEpochStateView configurationFile socketPath
txin1 <- findLargestUtxoForPaymentKey epochStateView sbe wallet0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import qualified System.Info as SYS

import Testnet.Process.Run (execCliStdoutToJson, mkExecConfig)
import Testnet.Property.Util (integrationRetryWorkspace)
import Testnet.Types

import Hedgehog (Property, (===))
import qualified Hedgehog as H
Expand All @@ -43,7 +42,7 @@ hprop_stakeSnapshot = integrationRetryWorkspace 2 "conway-stake-snapshot" $ \tem
} <- cardanoTestnetDefault def def conf

poolNode1 <- H.headM testnetNodes
poolSprocket1 <- H.noteShow $ nodeSprocket $ testnetNodeRuntime poolNode1
poolSprocket1 <- H.noteShow $ nodeSprocket poolNode1
execConfig <- mkExecConfig tempBaseAbsPath poolSprocket1 testnetMagic

void $ waitUntilEpoch configurationFile
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ hprop_kes_period_info = integrationRetryWorkspace 2 "kes-period-info" $ \tempAbs
H.createDirectoryIfMissing_ testSpoDir
let valency = 1
topology = RealNodeTopology $
flip map testnetNodes $ \TestnetNode{testnetNodeRuntime=NodeRuntime{nodeIpv4,nodePort}} ->
flip map testnetNodes $ \TestnetNode{nodeIpv4,nodePort} ->
RemoteAddress (showIpv4Address nodeIpv4) nodePort valency
H.lbsWriteFile topologyFile $ Aeson.encode topology

Expand Down Expand Up @@ -260,7 +260,7 @@ hprop_kes_period_info = integrationRetryWorkspace 2 "kes-period-info" $ \tempAbs
, "--shelley-vrf-key", testSpoVrfSKey
, "--shelley-operational-certificate", testSpoOperationalCertFp
]
NodeRuntime{ nodeStdout } <- H.evalEither eRuntime
TestnetNode{nodeStdout} <- H.evalEither eRuntime

threadDelay 5_000_000

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ hprop_leadershipSchedule = integrationRetryWorkspace 2 "leadership-schedule" $ \
H.createDirectoryIfMissing_ testSpoDir
let valency = 1
topology = RealNodeTopology $
flip map testnetNodes $ \TestnetNode{testnetNodeRuntime=NodeRuntime{nodeIpv4,nodePort}} ->
flip map testnetNodes $ \TestnetNode{nodeIpv4,nodePort} ->
RemoteAddress (showIpv4Address nodeIpv4) nodePort valency
H.lbsWriteFile topologyFile $ Aeson.encode topology
let testSpoKesVKey = work </> "kes.vkey"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,10 +114,10 @@ hprop_cli_queries = integrationWorkspace "cli-queries" $ \tempAbsBasePath' -> H.

let shelleyGeneisFile = work </> Defaults.defaultGenesisFilepath ShelleyEra

TestnetNode{testnetNodeRuntime} <- H.headM testnetNodes
poolSprocket1 <- H.noteShow $ nodeSprocket testnetNodeRuntime
node <- H.headM testnetNodes
poolSprocket1 <- H.noteShow $ nodeSprocket node
execConfig <- mkExecConfig tempBaseAbsPath poolSprocket1 testnetMagic
let socketPath = nodeSocketPath testnetNodeRuntime
let socketPath = nodeSocketPath node

epochStateView <- getEpochStateView configurationFile socketPath

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ hprop_querySlotNumber = integrationRetryWorkspace 2 "query-slot-number" $ \tempA
epochSize = fromIntegral (unEpochSize sgEpochLength) :: Int

poolNode1 <- H.headM testnetNodes
poolSprocket1 <- H.noteShow $ nodeSprocket $ testnetNodeRuntime poolNode1
poolSprocket1 <- H.noteShow $ nodeSprocket poolNode1
execConfig <- mkExecConfig tempBaseAbsPath' poolSprocket1 testnetMagic

id do
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import qualified System.Info as SYS

import Testnet.Process.Run (execCliStdoutToJson, mkExecConfig)
import Testnet.Property.Util (integrationRetryWorkspace)
import Testnet.Types

import Hedgehog (Property, (===))
import qualified Hedgehog as H
Expand All @@ -45,7 +44,7 @@ hprop_stakeSnapshot = integrationRetryWorkspace 2 "stake-snapshot" $ \tempAbsBas

let nSpoNodes = length $ spoNodes runtime
poolNode1 <- H.headM testnetNodes
poolSprocket1 <- H.noteShow $ nodeSprocket $ testnetNodeRuntime poolNode1
poolSprocket1 <- H.noteShow $ nodeSprocket poolNode1
execConfig <- mkExecConfig tempBaseAbsPath poolSprocket1 testnetMagic

void $ waitUntilEpoch configurationFile
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ hprop_transaction = integrationRetryWorkspace 2 "simple transaction build" $ \te
} <- cardanoTestnetDefault options def conf

poolNode1 <- H.headM testnetNodes
poolSprocket1 <- H.noteShow $ nodeSprocket $ testnetNodeRuntime poolNode1
poolSprocket1 <- H.noteShow $ nodeSprocket poolNode1
execConfig <- mkExecConfig tempBaseAbsPath poolSprocket1 testnetMagic


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import qualified System.Directory as IO
import System.FilePath ((</>))

import Testnet.Property.Util (integrationWorkspace)
import Testnet.Types

import Hedgehog ((===))
import qualified Hedgehog as H
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,10 @@ hprop_constitutional_committee_add_new = integrationWorkspace "constitutional-co
}
<- cardanoTestnetDefault fastTestnetOptions shelleyOptions conf

TestnetNode{testnetNodeRuntime, poolKeys=Just poolKeys} <- H.headM . filter isTestnetNodeSpo $ testnetNodes runtime
poolSprocket1 <- H.noteShow $ nodeSprocket testnetNodeRuntime
node@TestnetNode{poolKeys=Just poolKeys} <- H.headM . filter isTestnetNodeSpo $ testnetNodes runtime
poolSprocket1 <- H.noteShow $ nodeSprocket node
execConfig <- mkExecConfig tempBaseAbsPath poolSprocket1 testnetMagic
let socketPath = nodeSocketPath testnetNodeRuntime
let socketPath = nodeSocketPath node

epochStateView <- getEpochStateView configurationFile socketPath

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,10 @@ hprop_check_drep_activity = integrationWorkspace "test-activity" $ \tempAbsBaseP
}
<- cardanoTestnetDefault fastTestnetOptions shelleyOptions conf

TestnetNode{testnetNodeRuntime} <- H.headM testnetNodes
poolSprocket1 <- H.noteShow $ nodeSprocket testnetNodeRuntime
node <- H.headM testnetNodes
poolSprocket1 <- H.noteShow $ nodeSprocket node
execConfig <- mkExecConfig tempBaseAbsPath poolSprocket1 testnetMagic
let socketPath = nodeSocketPath testnetNodeRuntime
let socketPath = nodeSocketPath node

epochStateView <- getEpochStateView configurationFile socketPath

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,10 @@ hprop_ledger_events_drep_deposits = integrationWorkspace "drep-deposits" $ \temp
}
<- cardanoTestnetDefault fastTestnetOptions shelleyOptions conf

TestnetNode{testnetNodeRuntime} <- H.headM testnetNodes
poolSprocket1 <- H.noteShow $ nodeSprocket testnetNodeRuntime
node <- H.headM testnetNodes
poolSprocket1 <- H.noteShow $ nodeSprocket node
execConfig <- mkExecConfig tempBaseAbsPath poolSprocket1 testnetMagic
let socketPath = nodeSocketPath testnetNodeRuntime
let socketPath = nodeSocketPath node

epochStateView <- getEpochStateView configurationFile socketPath

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,10 @@ hprop_drep_retirement = integrationRetryWorkspace 2 "drep-retirement" $ \tempAbs
}
<- cardanoTestnetDefault fastTestnetOptions shelleyOptions conf

TestnetNode{testnetNodeRuntime} <- H.headM testnetNodes
poolSprocket1 <- H.noteShow $ nodeSprocket testnetNodeRuntime
node <- H.headM testnetNodes
poolSprocket1 <- H.noteShow $ nodeSprocket node
execConfig <- mkExecConfig tempBaseAbsPath poolSprocket1 testnetMagic
let socketPath = nodeSocketPath testnetNodeRuntime
let socketPath = nodeSocketPath node

epochStateView <- getEpochStateView configurationFile socketPath

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import Testnet.Process.Cli.DRep (makeActivityChangeProposal)
import Testnet.Process.Run (mkExecConfig)
import Testnet.Property.Util (integrationWorkspace)
import Testnet.Start.Types
import Testnet.Types

import Hedgehog (Property)
import qualified Hedgehog as H
Expand Down Expand Up @@ -59,10 +58,10 @@ hprop_check_gov_action_timeout = integrationWorkspace "gov-action-timeout" $ \te
}
<- cardanoTestnetDefault fastTestnetOptions shelleyOptions conf

TestnetNode{testnetNodeRuntime} <- H.headM testnetNodes
poolSprocket1 <- H.noteShow $ nodeSprocket testnetNodeRuntime
node <- H.headM testnetNodes
poolSprocket1 <- H.noteShow $ nodeSprocket node
execConfig <- mkExecConfig tempBaseAbsPath poolSprocket1 testnetMagic
let socketPath = nodeSocketPath testnetNodeRuntime
let socketPath = nodeSocketPath node

epochStateView <- getEpochStateView configurationFile socketPath

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,10 @@ hprop_ledger_events_info_action = integrationRetryWorkspace 2 "info-hash" $ \tem
}
<- cardanoTestnetDefault fastTestnetOptions shelleyOptions conf

TestnetNode{testnetNodeRuntime} <- H.headM testnetNodes
poolSprocket1 <- H.noteShow $ nodeSprocket testnetNodeRuntime
node <- H.headM testnetNodes
poolSprocket1 <- H.noteShow $ nodeSprocket node
execConfig <- mkExecConfig tempBaseAbsPath poolSprocket1 testnetMagic
let socketPath = nodeSocketPath testnetNodeRuntime
let socketPath = nodeSocketPath node

epochStateView <- getEpochStateView configurationFile socketPath

Expand Down
Loading

0 comments on commit 959eb8e

Please sign in to comment.