Skip to content

Commit 80314fe

Browse files
authored
Merge pull request #6099 from IntersectMBO/smelc/cardano-testnet-support-custom-node-config-file
cardano-testnet: modify API to accept user-provided configuration file
2 parents 46484ea + 1e2a0fb commit 80314fe

File tree

3 files changed

+23
-11
lines changed

3 files changed

+23
-11
lines changed

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

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ cardanoTestnetDefault testnetOptions shelleyOptions conf = do
100100
AnyShelleyBasedEra sbe <- pure cardanoNodeEra
101101
alonzoGenesis <- getDefaultAlonzoGenesis sbe
102102
shelleyGenesis <- getDefaultShelleyGenesis cardanoNodeEra cardanoMaxSupply shelleyOptions
103-
cardanoTestnet testnetOptions conf shelleyGenesis alonzoGenesis Defaults.defaultConwayGenesis
103+
cardanoTestnet testnetOptions conf UserNodeConfigNotSubmitted shelleyGenesis alonzoGenesis Defaults.defaultConwayGenesis
104104
where
105105
CardanoTestnetOptions{cardanoNodeEra, cardanoMaxSupply} = testnetOptions
106106

@@ -194,13 +194,14 @@ cardanoTestnet :: ()
194194
=> HasCallStack
195195
=> CardanoTestnetOptions -- ^ The options to use
196196
-> Conf
197+
-> UserNodeConfig -- ^ The node configuration file to use. If omitted it's generated.
197198
-> ShelleyGenesis StandardCrypto -- ^ The shelley genesis to use, for example 'getDefaultShelleyGenesis' from this module.
198199
-- Some fields are overridden by the accompanying 'CardanoTestnetOptions'.
199200
-> AlonzoGenesis -- ^ The alonzo genesis to use, for example 'getDefaultAlonzoGenesis' from this module.
200201
-> ConwayGenesis StandardCrypto -- ^ The conway genesis to use, for example 'Defaults.defaultConwayGenesis'.
201202
-> H.Integration TestnetRuntime
202203
cardanoTestnet
203-
testnetOptions Conf{tempAbsPath=TmpAbsolutePath tmpAbsPath}
204+
testnetOptions Conf{tempAbsPath=TmpAbsolutePath tmpAbsPath} mNodeConfigFile
204205
shelleyGenesis alonzoGenesis conwayGenesis = do
205206
let CardanoTestnetOptions
206207
{ cardanoNodeEra=asbe
@@ -232,8 +233,6 @@ cardanoTestnet
232233
writeGenesisSpecFile "alonzo" alonzoGenesis
233234
writeGenesisSpecFile "conway" conwayGenesis
234235

235-
configurationFile <- H.noteShow . File $ tmpAbsPath </> "configuration.yaml"
236-
237236
_ <- createSPOGenesisAndFiles nPools nDReps maxSupply asbe shelleyGenesis alonzoGenesis conwayGenesis (TmpAbsolutePath tmpAbsPath)
238237

239238
-- TODO: This should come from the configuration!
@@ -272,12 +271,18 @@ cardanoTestnet
272271
}
273272
}
274273

275-
-- Add Byron, Shelley and Alonzo genesis hashes to node configuration
276-
config <- createConfigJson (TmpAbsolutePath tmpAbsPath) sbe
277-
H.evalIO $ LBS.writeFile (unFile configurationFile) config
274+
nodeConfigFile <- case mNodeConfigFile of
275+
UserNodeConfigNotSubmitted -> do
276+
configurationFile <- H.noteShow $ tmpAbsPath </> "configuration.yaml"
277+
-- Add Byron, Shelley and Alonzo genesis hashes to node configuration
278+
config <- createConfigJson (TmpAbsolutePath tmpAbsPath) sbe
279+
H.evalIO $ LBS.writeFile configurationFile config
280+
return configurationFile
281+
UserNodeConfig userSubmittedNodeConfigFile -> pure userSubmittedNodeConfigFile
282+
278283
execCli_
279284
[ "debug", "check-node-configuration"
280-
, "--node-configuration-file", unFile configurationFile
285+
, "--node-configuration-file", nodeConfigFile
281286
]
282287

283288
portNumbersWithNodeOptions <- forM cardanoNodes $ \nodeOption -> (nodeOption,) <$> H.randomPort testnetDefaultIpv4Address
@@ -324,7 +329,7 @@ cardanoTestnet
324329
eRuntime <- runExceptT . retryOnAddressInUseError $
325330
startNode (TmpAbsolutePath tmpAbsPath) nodeName testnetDefaultIpv4Address port testnetMagic $
326331
[ "run"
327-
, "--config", unFile configurationFile
332+
, "--config", nodeConfigFile
328333
, "--topology", nodeDataDir </> "topology.json"
329334
, "--database-path", nodeDataDir </> "db"
330335
]
@@ -352,7 +357,7 @@ cardanoTestnet
352357
H.cat . verificationKeyFp $ paymentKeyInfoPair wallet
353358

354359
let runtime = TestnetRuntime
355-
{ configurationFile
360+
{ configurationFile = File nodeConfigFile
356361
, shelleyGenesisFile = tmpAbsPath </> Defaults.defaultGenesisFilepath ShelleyEra
357362
, testnetMagic
358363
, testnetNodes=testnetNodes'

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ module Testnet.Start.Types
1010
, NumDReps(..)
1111
, NumPools(..)
1212
, NumRelays(..)
13+
, UserNodeConfig(..)
1314
, cardanoNumPools
1415
, cardanoNumRelays
1516

@@ -133,6 +134,12 @@ data TestnetNodeOptions
133134
-- starting the node.
134135
deriving (Eq, Show)
135136

137+
-- | Type used to track whether the user is using its own node configuration file,
138+
-- or whether it is programmatically generated.
139+
data UserNodeConfig =
140+
UserNodeConfigNotSubmitted
141+
| UserNodeConfig FilePath
142+
136143
-- | Get extra CLI arguments passed to the node executable
137144
testnetNodeExtraCliArgs :: TestnetNodeOptions -> [String]
138145
testnetNodeExtraCliArgs (SpoNodeOptions _ args) = args

cardano-testnet/test/cardano-testnet-test/Cardano/Testnet/Test/Gov/NoConfidence.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ hprop_gov_no_confidence = integrationWorkspace "no-confidence" $ \tempAbsBasePat
120120
, configurationFile
121121
} <- cardanoTestnet
122122
fastTestnetOptions
123-
conf shelleyGenesis'
123+
conf UserNodeConfigNotSubmitted shelleyGenesis'
124124
alonzoGenesis conwayGenesisWithCommittee
125125

126126
poolNode1 <- H.headM testnetNodes

0 commit comments

Comments
 (0)