Skip to content

Commit

Permalink
cardano-testnet: honor command line arguments of nodes
Browse files Browse the repository at this point in the history
  • Loading branch information
smelc committed Oct 10, 2024
1 parent 1b252ff commit b87724e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
5 changes: 3 additions & 2 deletions cardano-testnet/src/Testnet/Runtime.hs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,8 @@ startNode
-> Int
-- ^ Testnet magic
-> [String]
-- ^ The command --socket-path will be added automatically.
-- ^ The command to execute to start the node.
-- @--socket-path@, @--port@, and @--host-addr@ gets added automatically.
-> ExceptT NodeStartFailure m NodeRuntime
startNode tp node ipv4 port testnetMagic nodeCmd = GHC.withFrozenCallStack $ do
let tempBaseAbsPath = makeTmpBaseAbsPath tp
Expand Down Expand Up @@ -190,7 +191,7 @@ startNode tp node ipv4 port testnetMagic nodeCmd = GHC.withFrozenCallStack $ do
NodeExecutableError . hsep $
["Socket", pretty socketAbsPath, "was not created after 120 seconds. There was no output on stderr. Exception:", prettyException ioex])
$ hoistEither eSprocketError

-- Ping node and fail on error
Ping.pingNode (fromIntegral testnetMagic) sprocket
>>= (firstExceptT (NodeExecutableError . ("Ping error:" <+>) . prettyError) . hoistEither)
Expand Down
15 changes: 9 additions & 6 deletions cardano-testnet/src/Testnet/Start/Cardano.hs
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,10 @@ cardanoTestnet
startTime = sgSystemStart shelleyGenesis
testnetMagic = fromIntegral $ sgNetworkMagic shelleyGenesis
numPoolNodes = length $ cardanoNodes testnetOptions
-- TODO @smelc Honor the @Maybe NodeConfigurationYaml@ part of 'nodesTuning'
-- This can be done once we use @check-node-configuration --fix@ (see https://github.com/IntersectMBO/cardano-cli/pull/923)
-- to augment the configuration file automatically
nodesTuning = cardanoNodes testnetOptions
nPools = numPools testnetOptions
nDReps = numDReps testnetOptions
AnyShelleyBasedEra sbe <- pure asbe
Expand Down Expand Up @@ -221,8 +225,6 @@ cardanoTestnet
writeGenesisSpecFile "alonzo" alonzoGenesis
writeGenesisSpecFile "conway" conwayGenesis

configurationFile <- H.noteShow . File $ tmpAbsPath </> "configuration.yaml"

_ <- createSPOGenesisAndFiles nPools nDReps maxSupply asbe shelleyGenesis alonzoGenesis conwayGenesis (TmpAbsolutePath tmpAbsPath)

-- TODO: This should come from the configuration!
Expand Down Expand Up @@ -294,6 +296,7 @@ cardanoTestnet
-- Add Byron, Shelley and Alonzo genesis hashes to node configuration
config <- createConfigJson (TmpAbsolutePath tmpAbsPath) sbe

configurationFile <- H.noteShow . File $ tmpAbsPath </> "configuration.yaml"
H.evalIO $ LBS.writeFile (unFile configurationFile) config

portNumbers <- replicateM numPoolNodes $ H.randomPort testnetDefaultIpv4Address
Expand All @@ -316,13 +319,13 @@ cardanoTestnet
H.lbsWriteFile (tmpAbsPath </> poolKeyDir i </> "topology.json") . encode $
RealNodeTopology producers

let keysWithPorts = L.zip3 [1..] poolKeys portNumbers
ePoolNodes <- H.forConcurrently keysWithPorts $ \(i, key, port) -> do
let nodesData = L.zip4 [1..] poolKeys portNumbers (map (\(TestnetNodeOptions _ cfg) -> cfg) nodesTuning)
ePoolNodes <- H.forConcurrently nodesData $ \(i, key, port, cmdArgs) -> do
let nodeName = mkNodeName i
keyDir = tmpAbsPath </> poolKeyDir i
H.note_ $ "Node name: " <> nodeName
eRuntime <- runExceptT . retryOnAddressInUseError $
startNode (TmpAbsolutePath tmpAbsPath) nodeName testnetDefaultIpv4Address port testnetMagic
startNode (TmpAbsolutePath tmpAbsPath) nodeName testnetDefaultIpv4Address port testnetMagic $
[ "run"
, "--config", unFile configurationFile
, "--topology", keyDir </> "topology.json"
Expand All @@ -332,7 +335,7 @@ cardanoTestnet
, "--byron-delegation-certificate", keyDir </> "byron-delegation.cert"
, "--byron-signing-key", keyDir </> "byron-delegate.key"
, "--shelley-operational-certificate", keyDir </> "opcert.cert"
]
] ++ cmdArgs
pure $ flip PoolNode key <$> eRuntime

let (failedNodes, poolNodes) = partitionEithers ePoolNodes
Expand Down

0 comments on commit b87724e

Please sign in to comment.