From 660b176bda34d334152d3b1655797abe21a503ae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Hurlin?= Date: Fri, 31 Jan 2025 16:38:04 +0100 Subject: [PATCH] cardano-testnet: modify API to accept user-provided configuration file But we do not use this feature yet --- cardano-testnet/src/Testnet/Start/Cardano.hs | 25 ++++++++++++-------- cardano-testnet/src/Testnet/Start/Types.hs | 7 ++++++ 2 files changed, 22 insertions(+), 10 deletions(-) diff --git a/cardano-testnet/src/Testnet/Start/Cardano.hs b/cardano-testnet/src/Testnet/Start/Cardano.hs index 13d375cd1c8..c840bbd6254 100644 --- a/cardano-testnet/src/Testnet/Start/Cardano.hs +++ b/cardano-testnet/src/Testnet/Start/Cardano.hs @@ -100,7 +100,7 @@ cardanoTestnetDefault testnetOptions shelleyOptions conf = do AnyShelleyBasedEra sbe <- pure cardanoNodeEra alonzoGenesis <- getDefaultAlonzoGenesis sbe shelleyGenesis <- getDefaultShelleyGenesis cardanoNodeEra cardanoMaxSupply shelleyOptions - cardanoTestnet testnetOptions conf shelleyGenesis alonzoGenesis Defaults.defaultConwayGenesis + cardanoTestnet testnetOptions conf UserNodeConfigNotSubmitted shelleyGenesis alonzoGenesis Defaults.defaultConwayGenesis where CardanoTestnetOptions{cardanoNodeEra, cardanoMaxSupply} = testnetOptions @@ -194,13 +194,14 @@ cardanoTestnet :: () => HasCallStack => CardanoTestnetOptions -- ^ The options to use -> Conf + -> UserNodeConfig -- ^ The node configuration file to use. If omitted it's generated. -> ShelleyGenesis StandardCrypto -- ^ The shelley genesis to use, for example 'getDefaultShelleyGenesis' from this module. -- Some fields are overridden by the accompanying 'CardanoTestnetOptions'. -> AlonzoGenesis -- ^ The alonzo genesis to use, for example 'getDefaultAlonzoGenesis' from this module. -> ConwayGenesis StandardCrypto -- ^ The conway genesis to use, for example 'Defaults.defaultConwayGenesis'. -> H.Integration TestnetRuntime cardanoTestnet - testnetOptions Conf{tempAbsPath=TmpAbsolutePath tmpAbsPath} + testnetOptions Conf{tempAbsPath=TmpAbsolutePath tmpAbsPath} mNodeConfigFile shelleyGenesis alonzoGenesis conwayGenesis = do let CardanoTestnetOptions { cardanoNodeEra=asbe @@ -232,8 +233,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! @@ -272,12 +271,18 @@ cardanoTestnet } } - -- Add Byron, Shelley and Alonzo genesis hashes to node configuration - config <- createConfigJson (TmpAbsolutePath tmpAbsPath) sbe - H.evalIO $ LBS.writeFile (unFile configurationFile) config + nodeConfigFile <- case mNodeConfigFile of + UserNodeConfigNotSubmitted -> do + configurationFile <- H.noteShow $ tmpAbsPath "configuration.yaml" + -- Add Byron, Shelley and Alonzo genesis hashes to node configuration + config <- createConfigJson (TmpAbsolutePath tmpAbsPath) sbe + H.evalIO $ LBS.writeFile configurationFile config + return configurationFile + UserNodeConfig userSubmittedNodeConfigFile -> pure userSubmittedNodeConfigFile + execCli_ [ "debug", "check-node-configuration" - , "--node-configuration-file", unFile configurationFile + , "--node-configuration-file", nodeConfigFile ] portNumbersWithNodeOptions <- forM cardanoNodes $ \nodeOption -> (nodeOption,) <$> H.randomPort testnetDefaultIpv4Address @@ -324,7 +329,7 @@ cardanoTestnet eRuntime <- runExceptT . retryOnAddressInUseError $ startNode (TmpAbsolutePath tmpAbsPath) nodeName testnetDefaultIpv4Address port testnetMagic $ [ "run" - , "--config", unFile configurationFile + , "--config", nodeConfigFile , "--topology", nodeDataDir "topology.json" , "--database-path", nodeDataDir "db" ] @@ -352,7 +357,7 @@ cardanoTestnet H.cat . verificationKeyFp $ paymentKeyInfoPair wallet let runtime = TestnetRuntime - { configurationFile + { configurationFile = File nodeConfigFile , shelleyGenesisFile = tmpAbsPath Defaults.defaultGenesisFilepath ShelleyEra , testnetMagic , testnetNodes=testnetNodes' diff --git a/cardano-testnet/src/Testnet/Start/Types.hs b/cardano-testnet/src/Testnet/Start/Types.hs index acb48095377..147ce1af720 100644 --- a/cardano-testnet/src/Testnet/Start/Types.hs +++ b/cardano-testnet/src/Testnet/Start/Types.hs @@ -10,6 +10,7 @@ module Testnet.Start.Types , NumDReps(..) , NumPools(..) , NumRelays(..) + , UserNodeConfig(..) , cardanoNumPools , cardanoNumRelays @@ -133,6 +134,12 @@ data TestnetNodeOptions -- starting the node. deriving (Eq, Show) +-- | Type used to track whether the user is using its own node configuration file, +-- or whether it is programmatically generated. +data UserNodeConfig = + UserNodeConfigNotSubmitted + | UserNodeConfig FilePath + -- | Get extra CLI arguments passed to the node executable testnetNodeExtraCliArgs :: TestnetNodeOptions -> [String] testnetNodeExtraCliArgs (SpoNodeOptions _ args) = args