Skip to content

Commit c3e1210

Browse files
committed
Move cardano-testnet configuration paths to module in cardano-node
1 parent b2b5692 commit c3e1210

7 files changed

Lines changed: 82 additions & 15 deletions

File tree

cardano-node/cardano-node.cabal

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ library
8484
Cardano.Node.Run
8585
Cardano.Node.Startup
8686
Cardano.Node.STM
87+
Cardano.Node.Testnet.Paths
8788
Cardano.Node.TraceConstraints
8889
Cardano.Node.Tracing
8990
Cardano.Node.Tracing.API
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
-- | Shared path conventions for cardano-testnet output directories.
2+
--
3+
-- Both @cardano-testnet@ (producer) and consumers of generated
4+
-- testnet configurations depend on this module so that directory
5+
-- layout changes are kept in sync at compile time.
6+
module Cardano.Node.Testnet.Paths
7+
( defaultNodeName
8+
, defaultNodeDataDir
9+
, defaultUtxoKeyDir
10+
, defaultUtxoSKeyPath
11+
, defaultUtxoVKeyPath
12+
, defaultUtxoAddrPath
13+
, defaultSocketDir
14+
, defaultSocketName
15+
, defaultSocketPath
16+
, defaultConfigFile
17+
, defaultPortFile
18+
) where
19+
20+
import System.FilePath ((</>))
21+
22+
-- | The name of a node: @"node" <> show n@
23+
defaultNodeName :: Int -> String
24+
defaultNodeName n = "node" <> show n
25+
26+
-- | Relative path to a node's data directory: @"node-data" </> defaultNodeName n@
27+
defaultNodeDataDir :: Int -> FilePath
28+
defaultNodeDataDir n = "node-data" </> defaultNodeName n
29+
30+
-- | Relative path to a UTxO key directory: @"utxo-keys" </> "utxo" <> show n@
31+
defaultUtxoKeyDir :: Int -> FilePath
32+
defaultUtxoKeyDir n = "utxo-keys" </> "utxo" <> show n
33+
34+
-- | Relative path to a UTxO signing key: @defaultUtxoKeyDir n </> "utxo.skey"@
35+
defaultUtxoSKeyPath :: Int -> FilePath
36+
defaultUtxoSKeyPath n = defaultUtxoKeyDir n </> "utxo.skey"
37+
38+
-- | Relative path to a UTxO verification key: @defaultUtxoKeyDir n </> "utxo.vkey"@
39+
defaultUtxoVKeyPath :: Int -> FilePath
40+
defaultUtxoVKeyPath n = defaultUtxoKeyDir n </> "utxo.vkey"
41+
42+
-- | Relative path to a UTxO address file: @defaultUtxoKeyDir n </> "utxo.addr"@
43+
defaultUtxoAddrPath :: Int -> FilePath
44+
defaultUtxoAddrPath n = defaultUtxoKeyDir n </> "utxo.addr"
45+
46+
-- | Socket directory name: @"socket"@
47+
defaultSocketDir :: FilePath
48+
defaultSocketDir = "socket"
49+
50+
-- | Socket file name: @"sock"@
51+
defaultSocketName :: FilePath
52+
defaultSocketName = "sock"
53+
54+
-- | Relative path to a node's socket: @defaultSocketDir </> defaultNodeName n </> defaultSocketName@
55+
defaultSocketPath :: Int -> FilePath
56+
defaultSocketPath n = defaultSocketDir </> defaultNodeName n </> defaultSocketName
57+
58+
-- | Main node configuration file name: @"configuration.yaml"@
59+
defaultConfigFile :: FilePath
60+
defaultConfigFile = "configuration.yaml"
61+
62+
-- | Relative path to a node's port file: @defaultNodeDataDir n </> "port"@
63+
defaultPortFile :: Int -> FilePath
64+
defaultPortFile n = defaultNodeDataDir n </> "port"
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
2+
### Maintenance
3+
4+
- Moved shared testnet path conventions into `Cardano.Node.Testnet.Paths` module in `cardano-node`, and replaced some inline string literals.

cardano-testnet/src/Testnet/Defaults.hs

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,8 @@ import Numeric.Natural
9999
import System.FilePath ((</>))
100100

101101
import Test.Cardano.Ledger.Core.Rational
102+
import Cardano.Node.Testnet.Paths (defaultNodeName, defaultNodeDataDir, defaultUtxoSKeyPath,
103+
defaultUtxoVKeyPath)
102104
import Testnet.Start.Types
103105
import Testnet.Types
104106

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

571-
-- | The name of a node (which doesn't have to be a SPO)
572-
defaultNodeName :: Int -> String
573-
defaultNodeName n = "node" <> show n
574-
575-
-- | The relative path of the node data dir, where the database is stored
576-
defaultNodeDataDir :: Int -> String
577-
defaultNodeDataDir n = "node-data" </> defaultNodeName n
578-
579573
-- | The relative path where the SPO keys for the node are stored
580574
defaultSpoKeysDir :: Int -> String
581575
defaultSpoKeysDir n = "pools-keys" </> defaultSpoName n
@@ -619,8 +613,8 @@ defaultDelegatorStakeKeyPair n =
619613
defaultUtxoKeys :: Int -> KeyPair PaymentKey
620614
defaultUtxoKeys n =
621615
KeyPair
622-
{ verificationKey = File $ "utxo-keys" </> "utxo" <> show n </> "utxo.vkey"
623-
, signingKey = File $ "utxo-keys" </> "utxo" <> show n </> "utxo.skey"
616+
{ verificationKey = File $ defaultUtxoVKeyPath n
617+
, signingKey = File $ defaultUtxoSKeyPath n
624618
}
625619

626620

cardano-testnet/src/Testnet/Filepath.hs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ import Hedgehog.Extras.Stock.IO.Network.Sprocket (Sprocket (..))
2020

2121
import RIO (Display (..))
2222

23+
import Cardano.Node.Testnet.Paths (defaultSocketDir)
24+
2325

2426
makeSprocket
2527
:: TmpAbsolutePath
@@ -42,7 +44,7 @@ makeTmpRelPath :: TmpAbsolutePath -> FilePath
4244
makeTmpRelPath (TmpAbsolutePath fp) = makeRelative (makeTmpBaseAbsPath (TmpAbsolutePath fp)) fp
4345

4446
makeSocketDir :: TmpAbsolutePath -> FilePath
45-
makeSocketDir fp = makeTmpRelPath fp </> "socket"
47+
makeSocketDir fp = makeTmpRelPath fp </> defaultSocketDir
4648

4749
makeTmpBaseAbsPath :: TmpAbsolutePath -> FilePath
4850
makeTmpBaseAbsPath (TmpAbsolutePath fp) = addTrailingPathSeparator $ takeDirectory fp

cardano-testnet/src/Testnet/Runtime.hs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ import qualified System.Process as IO
5353
import System.Process (waitForProcess)
5454

5555
import Testnet.Filepath
56+
import Cardano.Node.Testnet.Paths (defaultSocketName)
5657
import qualified Testnet.Ping as Ping
5758
import Testnet.Process.Run (ProcessError (..), initiateProcess)
5859
import Testnet.Process.RunIO (execCli_, execKesAgentControl_, liftIOAnnotated,
@@ -135,7 +136,7 @@ startNode tp node ipv4 port _testnetMagic nodeCmd = GHC.withFrozenCallStack $ do
135136
let nodeStdoutFile = logDir </> node </> "stdout.log"
136137
nodeStderrFile = logDir </> node </> "stderr.log"
137138
nodePidFile = logDir </> node </> "node.pid"
138-
socketRelPath = socketDir </> node </> "sock"
139+
socketRelPath = socketDir </> node </> defaultSocketName
139140
sprocket = Sprocket tempBaseAbsPath socketRelPath
140141

141142
hNodeStdout <- retryOpenFile nodeStdoutFile IO.WriteMode

cardano-testnet/src/Testnet/Start/Cardano.hs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ import System.FilePath ((</>))
6464

6565
import Testnet.Components.Configuration
6666
import qualified Testnet.Defaults as Defaults
67+
import Cardano.Node.Testnet.Paths (defaultConfigFile, defaultUtxoAddrPath)
6768
import Testnet.Filepath
6869
import Testnet.Handlers (interruptNodesOnSigINT)
6970
import Testnet.Orphans ()
@@ -131,7 +132,7 @@ createTestnetEnv
131132
testnetOptions genesisOptions onChainParams
132133
(TmpAbsolutePath tmpAbsPath)
133134

134-
let configurationFile = tmpAbsPath </> "configuration.yaml"
135+
let configurationFile = tmpAbsPath </> defaultConfigFile
135136
-- Add Byron, Shelley and Alonzo genesis hashes to node configuration
136137
config <- case genesisHashesPolicy of
137138
WithHashes -> createConfigJson (TmpAbsolutePath tmpAbsPath) sbe
@@ -247,7 +248,7 @@ cardanoTestnet
247248
, cardanoKESSource
248249
} = testnetOptions
249250
nPools = cardanoNumPools testnetOptions
250-
nodeConfigFile = tmpAbsPath </> "configuration.yaml"
251+
nodeConfigFile = tmpAbsPath </> defaultConfigFile
251252
byronGenesisFile = tmpAbsPath </> "byron-genesis.json"
252253
shelleyGenesisFile = tmpAbsPath </> "shelley-genesis.json"
253254

@@ -260,7 +261,7 @@ cardanoTestnet
260261

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

265266
execCli_
266267
[ "latest", "address", "build"

0 commit comments

Comments
 (0)