Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions cardano-node/cardano-node.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ library
Cardano.Node.Run
Cardano.Node.Startup
Cardano.Node.STM
Cardano.Node.Testnet.Paths
Cardano.Node.TraceConstraints
Cardano.Node.Tracing
Cardano.Node.Tracing.API
Expand Down
64 changes: 64 additions & 0 deletions cardano-node/src/Cardano/Node/Testnet/Paths.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
-- | Shared path conventions for cardano-testnet output directories.
--
-- Both @cardano-testnet@ (producer) and consumers of generated
-- testnet configurations depend on this module so that directory
-- layout changes are kept in sync at compile time.
module Cardano.Node.Testnet.Paths
( defaultNodeName
, defaultNodeDataDir
, defaultUtxoKeyDir
, defaultUtxoSKeyPath
, defaultUtxoVKeyPath
, defaultUtxoAddrPath
, defaultSocketDir
, defaultSocketName
, defaultSocketPath
, defaultConfigFile
, defaultPortFile
) where

import System.FilePath ((</>))

-- | The name of a node: @"node" <> show n@
defaultNodeName :: Int -> String
defaultNodeName n = "node" <> show n

-- | Relative path to a node's data directory: @"node-data" </> defaultNodeName n@
defaultNodeDataDir :: Int -> FilePath
defaultNodeDataDir n = "node-data" </> defaultNodeName n

-- | Relative path to a UTxO key directory: @"utxo-keys" </> "utxo" <> show n@
defaultUtxoKeyDir :: Int -> FilePath
defaultUtxoKeyDir n = "utxo-keys" </> "utxo" <> show n

-- | Relative path to a UTxO signing key: @defaultUtxoKeyDir n </> "utxo.skey"@
defaultUtxoSKeyPath :: Int -> FilePath
defaultUtxoSKeyPath n = defaultUtxoKeyDir n </> "utxo.skey"

-- | Relative path to a UTxO verification key: @defaultUtxoKeyDir n </> "utxo.vkey"@
defaultUtxoVKeyPath :: Int -> FilePath
defaultUtxoVKeyPath n = defaultUtxoKeyDir n </> "utxo.vkey"

-- | Relative path to a UTxO address file: @defaultUtxoKeyDir n </> "utxo.addr"@
defaultUtxoAddrPath :: Int -> FilePath
defaultUtxoAddrPath n = defaultUtxoKeyDir n </> "utxo.addr"

-- | Socket directory name: @"socket"@
defaultSocketDir :: FilePath
defaultSocketDir = "socket"

-- | Socket file name: @"sock"@
defaultSocketName :: FilePath
defaultSocketName = "sock"

-- | Relative path to a node's socket: @defaultSocketDir </> defaultNodeName n </> defaultSocketName@
defaultSocketPath :: Int -> FilePath
defaultSocketPath n = defaultSocketDir </> defaultNodeName n </> defaultSocketName

-- | Main node configuration file name: @"configuration.yaml"@
defaultConfigFile :: FilePath
defaultConfigFile = "configuration.yaml"

-- | Relative path to a node's port file: @defaultNodeDataDir n </> "port"@
defaultPortFile :: Int -> FilePath
defaultPortFile n = defaultNodeDataDir n </> "port"
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@

### Maintenance

- Moved shared testnet path conventions into `Cardano.Node.Testnet.Paths` module in `cardano-node`, and replaced some inline string literals.
14 changes: 4 additions & 10 deletions cardano-testnet/src/Testnet/Defaults.hs
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,8 @@ import Numeric.Natural
import System.FilePath ((</>))

import Test.Cardano.Ledger.Core.Rational
import Cardano.Node.Testnet.Paths (defaultNodeName, defaultNodeDataDir, defaultUtxoSKeyPath,
defaultUtxoVKeyPath)
import Testnet.Start.Types
import Testnet.Types

Expand Down Expand Up @@ -568,14 +570,6 @@ defaultSpoColdSKeyFp n = defaultSpoKeysDir n </> "cold.skey"
defaultSpoName :: Int -> String
defaultSpoName n = "pool" <> show n

-- | The name of a node (which doesn't have to be a SPO)
defaultNodeName :: Int -> String
defaultNodeName n = "node" <> show n

-- | The relative path of the node data dir, where the database is stored
defaultNodeDataDir :: Int -> String
defaultNodeDataDir n = "node-data" </> defaultNodeName n

-- | The relative path where the SPO keys for the node are stored
defaultSpoKeysDir :: Int -> String
defaultSpoKeysDir n = "pools-keys" </> defaultSpoName n
Expand Down Expand Up @@ -619,8 +613,8 @@ defaultDelegatorStakeKeyPair n =
defaultUtxoKeys :: Int -> KeyPair PaymentKey
defaultUtxoKeys n =
KeyPair
{ verificationKey = File $ "utxo-keys" </> "utxo" <> show n </> "utxo.vkey"
, signingKey = File $ "utxo-keys" </> "utxo" <> show n </> "utxo.skey"
{ verificationKey = File $ defaultUtxoVKeyPath n
, signingKey = File $ defaultUtxoSKeyPath n
}


Expand Down
4 changes: 3 additions & 1 deletion cardano-testnet/src/Testnet/Filepath.hs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ import Hedgehog.Extras.Stock.IO.Network.Sprocket (Sprocket (..))

import RIO (Display (..))

import Cardano.Node.Testnet.Paths (defaultSocketDir)


makeSprocket
:: TmpAbsolutePath
Expand All @@ -42,7 +44,7 @@ makeTmpRelPath :: TmpAbsolutePath -> FilePath
makeTmpRelPath (TmpAbsolutePath fp) = makeRelative (makeTmpBaseAbsPath (TmpAbsolutePath fp)) fp

makeSocketDir :: TmpAbsolutePath -> FilePath
makeSocketDir fp = makeTmpRelPath fp </> "socket"
makeSocketDir fp = makeTmpRelPath fp </> defaultSocketDir

makeTmpBaseAbsPath :: TmpAbsolutePath -> FilePath
makeTmpBaseAbsPath (TmpAbsolutePath fp) = addTrailingPathSeparator $ takeDirectory fp
Expand Down
3 changes: 2 additions & 1 deletion cardano-testnet/src/Testnet/Runtime.hs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ import qualified System.Process as IO
import System.Process (waitForProcess)

import Testnet.Filepath
import Cardano.Node.Testnet.Paths (defaultSocketName)
import qualified Testnet.Ping as Ping
import Testnet.Process.Run (ProcessError (..), initiateProcess)
import Testnet.Process.RunIO (execCli_, execKesAgentControl_, liftIOAnnotated,
Expand Down Expand Up @@ -135,7 +136,7 @@ startNode tp node ipv4 port _testnetMagic nodeCmd = GHC.withFrozenCallStack $ do
let nodeStdoutFile = logDir </> node </> "stdout.log"
nodeStderrFile = logDir </> node </> "stderr.log"
nodePidFile = logDir </> node </> "node.pid"
socketRelPath = socketDir </> node </> "sock"
socketRelPath = socketDir </> node </> defaultSocketName
sprocket = Sprocket tempBaseAbsPath socketRelPath

hNodeStdout <- retryOpenFile nodeStdoutFile IO.WriteMode
Expand Down
12 changes: 7 additions & 5 deletions cardano-testnet/src/Testnet/Start/Cardano.hs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ import System.FilePath ((</>))

import Testnet.Components.Configuration
import qualified Testnet.Defaults as Defaults
import Cardano.Node.Testnet.Paths (defaultConfigFile, defaultPortFile,
defaultUtxoAddrPath)
import Testnet.Filepath
import Testnet.Handlers (interruptNodesOnSigINT)
import Testnet.Orphans ()
Expand Down Expand Up @@ -131,7 +133,7 @@ createTestnetEnv
testnetOptions genesisOptions onChainParams
(TmpAbsolutePath tmpAbsPath)

let configurationFile = tmpAbsPath </> "configuration.yaml"
let configurationFile = tmpAbsPath </> defaultConfigFile
-- Add Byron, Shelley and Alonzo genesis hashes to node configuration
config <- case genesisHashesPolicy of
WithHashes -> createConfigJson (TmpAbsolutePath tmpAbsPath) sbe
Expand All @@ -152,7 +154,7 @@ createTestnetEnv

-- Write port file
case Map.lookup i portNumbersMap of
Just port -> liftIOAnnotated $ writeFile (nodeDataDir </> "port") (show port)
Just port -> liftIOAnnotated $ writeFile (tmpAbsPath </> defaultPortFile i) (show port)
Nothing -> throwString $ "Port not found for node " <> show i

producers <- mapM (idToRemoteAddressP2P portNumbersMap) $ NodeId <$> NEL.filter (/= i) nodeIds
Expand Down Expand Up @@ -247,7 +249,7 @@ cardanoTestnet
, cardanoKESSource
} = testnetOptions
nPools = cardanoNumPools testnetOptions
nodeConfigFile = tmpAbsPath </> "configuration.yaml"
nodeConfigFile = tmpAbsPath </> defaultConfigFile
byronGenesisFile = tmpAbsPath </> "byron-genesis.json"
shelleyGenesisFile = tmpAbsPath </> "shelley-genesis.json"

Expand All @@ -260,7 +262,7 @@ cardanoTestnet

wallets <- forM [1..3] $ \idx -> do
let utxoKeys@KeyPair{verificationKey} = makePathsAbsolute $ Defaults.defaultUtxoKeys idx
let paymentAddrFile = tmpAbsPath </> "utxo-keys" </> "utxo" <> show idx </> "utxo.addr"
let paymentAddrFile = tmpAbsPath </> defaultUtxoAddrPath idx

execCli_
[ "latest", "address", "build"
Expand All @@ -279,7 +281,7 @@ cardanoTestnet
-- Read port numbers from disk (written by createTestnetEnv)
portNumbers <- forM (NEL.zip (1 :| [2..]) cardanoNodes) $ \(i, _nodeOption) -> do
let nodeDataDir = tmpAbsPath </> Defaults.defaultNodeDataDir i
portPath = nodeDataDir </> "port"
portPath = tmpAbsPath </> defaultPortFile i
portStr <- liftIOAnnotated $ readFile portPath
let port = read portStr :: PortNumber
let topologyPath = nodeDataDir </> "topology.json"
Expand Down
Loading