diff --git a/cardano-testnet/src/Parsers/Cardano.hs b/cardano-testnet/src/Parsers/Cardano.hs index 013c3349872..140aab6c62e 100644 --- a/cardano-testnet/src/Parsers/Cardano.hs +++ b/cardano-testnet/src/Parsers/Cardano.hs @@ -71,7 +71,7 @@ pCardanoTestnetCliOptions envCli = CardanoTestnetOptions pAnyShelleyBasedEra' = pAnyShelleyBasedEra envCli <&> (\(EraInEon x) -> AnyShelleyBasedEra x) -pTestnetNodeOptions :: Parser TestnetNodeOptions +pTestnetNodeOptions :: Parser [TestnetNodeOptions] pTestnetNodeOptions = asum' [ AutomaticNodeOptions . (`L.replicate` defaultSpoOptions) <$> diff --git a/cardano-testnet/src/Testnet/Components/Configuration.hs b/cardano-testnet/src/Testnet/Components/Configuration.hs index 77c78ca96ea..041e73a7f10 100644 --- a/cardano-testnet/src/Testnet/Components/Configuration.hs +++ b/cardano-testnet/src/Testnet/Components/Configuration.hs @@ -152,16 +152,11 @@ numSeededUTxOKeys = 3 createSPOGenesisAndFiles :: (MonadTest m, MonadCatch m, MonadIO m, HasCallStack) - => CardanoTestnetOptions -- ^ The options to use - -> GenesisOptions - -> UserProvidedData (ShelleyGenesis StandardCrypto) - -> UserProvidedData AlonzoGenesis - -> UserProvidedData (ConwayGenesis StandardCrypto) + => Either AutomaticNodeOptions [InputNodeConfigFile] -> TmpAbsolutePath -> m FilePath -- ^ Shelley genesis directory createSPOGenesisAndFiles - testnetOptions genesisOptions@GenesisOptions{genesisTestnetMagic} - mShelleyGenesis mAlonzoGenesis mConwayGenesis + testnetOptions (TmpAbsolutePath tempAbsPath) = GHC.withFrozenCallStack $ do AnyShelleyBasedEra sbe <- pure cardanoNodeEra diff --git a/cardano-testnet/src/Testnet/Start/Cardano.hs b/cardano-testnet/src/Testnet/Start/Cardano.hs index bd151728b7a..5ef0c814f37 100644 --- a/cardano-testnet/src/Testnet/Start/Cardano.hs +++ b/cardano-testnet/src/Testnet/Start/Cardano.hs @@ -162,17 +162,7 @@ cardanoTestnetDefault testnetOptions genesisOptions conf = do -- > └── module cardanoTestnet :: () => HasCallStack - => CardanoTestnetOptions -- ^ The options to use - -> GenesisOptions - -> UserProvidedData (ShelleyGenesis StandardCrypto) - -- ^ The shelley genesis to use, One possible way to provide this value is to use 'getDefaultShelleyGenesis' - -- and customize it. Generated if omitted. - -> UserProvidedData AlonzoGenesis - -- ^ The alonzo genesis to use. One possible way to provide this value is to use 'getDefaultAlonzoGenesis' - -- and customize it. Generated if omitted. - -> UserProvidedData (ConwayGenesis StandardCrypto) - -- ^ The conway genesis to use. One possible way to provide this value is to use 'defaultConwayGenesis' - -- and customize it. Generated if omitted. + => CardanoTestnetCliOptions -- ^ The options to use -> Conf -> H.Integration TestnetRuntime cardanoTestnet diff --git a/cardano-testnet/src/Testnet/Start/Types.hs b/cardano-testnet/src/Testnet/Start/Types.hs index 53703bed3c8..c792319faa7 100644 --- a/cardano-testnet/src/Testnet/Start/Types.hs +++ b/cardano-testnet/src/Testnet/Start/Types.hs @@ -50,32 +50,37 @@ import qualified Hedgehog.Extras as H -- | Command line options for the @cardano-testnet@ executable. They are used -- in the parser, and then get split into 'CardanoTestnetOptions' and -- 'GenesisOptions' -data CardanoTestnetCliOptions = CardanoTestnetCliOptions - { cliTestnetOptions :: CardanoTestnetOptions - , cliGenesisOptions :: GenesisOptions - } deriving (Eq, Show) +data CardanoTestnetCliOptions = CardanoTestnetCliOptions { + -- First options that are common to both the automatic and user-provided cases + cardanoNodeLoggingFormat :: NodeLoggingFormat + , cardanoEnableNewEpochStateLogging :: Bool -- ^ if epoch state logging is enabled + , cardanoOutputDir :: Maybe FilePath -- ^ The output directory where to store files, sockets, and so on. If unset, a temporary directory is used. commonOptions :: CardanoTestnetCommonOptions + -- Then onto options that depend on the scenario + , nodeOptions :: Either AutomaticNodeOptions [InputNodeConfigFile] + } + +-- | The kind of options used when the user doesn't provide the +-- nodes' configuration files (nor the genesis files) and instead +-- relies on @cardano-testnet@ to generate them +data AutomaticNodeOptions = AutomaticNodeOptions + { cardanoMaxSupply :: Word64 -- ^ The amount of Lovelace you are starting your testnet with (forward to shelley genesis) + , cardanoNumDReps :: NumDReps -- ^ The number of DReps to generate at creation + , cardanoNodeEra :: AnyShelleyBasedEra -- ^ The era to start at + , individualNodeOptions :: AutomaticNodeOption -- ^ The number of nodes to create, and whether to create a SPO or relay node + , genesisEpochLength :: Int -- ^ An epoch's duration, in number of slots + , genesisSlotLength :: Double -- ^ Slot length, in seconds + , genesisActiveSlotsCoeff :: Double + , genesisTestnetMagic :: Int -- TODO Use the NetworkMagic type from API + } + deriving (Eq, Show) -instance Default CardanoTestnetCliOptions where - def = CardanoTestnetCliOptions - { cliTestnetOptions = def - , cliGenesisOptions = def - } +data AutomaticNodeOption = AutomaticNodeOption + { isSpoOrRelayNode :: Bool + , enableP2P :: Bool + } --- | Options which, contrary to 'GenesisOptions' are not implemented --- by tuning the genesis files. -data CardanoTestnetOptions = CardanoTestnetOptions - { -- | Options controlling how many nodes to create and whether to use user-provided - -- configuration files, or to generate them automatically. - cardanoNodes :: TestnetNodeOptions - , cardanoNodeEra :: AnyShelleyBasedEra -- ^ The era to start at - , cardanoMaxSupply :: Word64 -- ^ The amount of Lovelace you are starting your testnet with (forwarded to shelley genesis) - -- TODO move me to GenesisOptions when https://github.com/IntersectMBO/cardano-cli/pull/874 makes it to cardano-node - , cardanoEnableP2P :: Bool - , cardanoNodeLoggingFormat :: NodeLoggingFormat - , cardanoNumDReps :: NumDReps -- ^ The number of DReps to generate at creation - , cardanoEnableNewEpochStateLogging :: Bool -- ^ if epoch state logging is enabled - , cardanoOutputDir :: Maybe FilePath -- ^ The output directory where to store files, sockets, and so on. If unset, a temporary directory is used. - } deriving (Eq, Show) +instance Default CardanoTestnetCliOptions where + def = undefined -- | Path to the configuration file of the node, specified by the user newtype InputNodeConfigFile = InputNodeConfigFile FilePath @@ -108,54 +113,7 @@ newtype NumDReps = NumDReps Int deriving (Show, Read, Eq, Enum, Ord, Num, Real, Integral) via Int instance Default CardanoTestnetOptions where - def = CardanoTestnetOptions - { cardanoNodes = cardanoDefaultTestnetNodeOptions - , cardanoNodeEra = AnyShelleyBasedEra ShelleyBasedEraBabbage - , cardanoMaxSupply = 100_000_020_000_000 -- 100 000 billions Lovelace, so 100 millions ADA. This amount should be bigger than the 'byronTotalBalance' in Testnet.Start.Byron - , cardanoEnableP2P = False - , cardanoNodeLoggingFormat = NodeLoggingFormatAsJson - , cardanoNumDReps = 3 - , cardanoEnableNewEpochStateLogging = True - , cardanoOutputDir = Nothing - } - --- | Options that are implemented by writing fields in the Shelley genesis file. -data GenesisOptions = GenesisOptions - { genesisTestnetMagic :: Int -- TODO Use the NetworkMagic type from API - , genesisEpochLength :: Int -- ^ An epoch's duration, in number of slots - , genesisSlotLength :: Double -- ^ Slot length, in seconds - , genesisActiveSlotsCoeff :: Double - } deriving (Eq, Show) - -instance Default GenesisOptions where - def = GenesisOptions - { genesisTestnetMagic = 42 - , genesisEpochLength = 500 - , genesisSlotLength = 0.1 - , genesisActiveSlotsCoeff = 0.05 - } - -data TestnetNodeOptions = - UserProvidedNodeOptions FilePath - -- ^ Value used when the user specifies the node configuration file. We start one single SPO node. - | AutomaticNodeOptions [AutomaticNodeOption] - -- ^ Value used when @cardano-testnet@ controls the node configuration files. - -- We start a custom number of nodes. - deriving (Eq, Show) - --- | Type used when the user doesn't specify the node configuration file. We start --- a custom number of nodes. The '@String' arguments will be appended to the default --- options when starting the node. -data AutomaticNodeOption = - SpoNodeOptions [String] - | RelayNodeOptions [String] - deriving (Eq, Show) - --- | Type used to track whether the user is providing its data (node configuration file path, genesis file, etc.) --- or whether it needs to be programmatically generated by @cardanoTestnet@ and friends. -data UserProvidedData a = - UserProvidedData a - | NoUserProvidedData + def = undefined isSpoNodeOptions :: AutomaticNodeOption -> Bool isSpoNodeOptions SpoNodeOptions{} = True diff --git a/cardano-testnet/test/cardano-testnet-golden/files/golden/help.cli b/cardano-testnet/test/cardano-testnet-golden/files/golden/help.cli index 445f59aa6d3..48e7010a815 100644 --- a/cardano-testnet/test/cardano-testnet-golden/files/golden/help.cli +++ b/cardano-testnet/test/cardano-testnet-golden/files/golden/help.cli @@ -1,23 +1,26 @@ Usage: cardano-testnet (cardano | version | help) -Usage: cardano-testnet cardano [--num-pool-nodes COUNT | --node-config FILEPATH] - [ --shelley-era - | --allegra-era - | --mary-era - | --alonzo-era - | --babbage-era - | --conway-era - ] - [--max-lovelace-supply WORD64] - [--enable-p2p BOOL] +Usage: cardano-testnet cardano + [[[--num-spo-nodes COUNT] + [--num-relay-nodes COUNT] + [--max-lovelace-supply WORD64] + [--num-dreps NUMBER] + [--epoch-length SLOTS] + [--slot-length SECONDS] + [--active-slots-coeff DOUBLE] + [ --shelley-era + | --allegra-era + | --mary-era + | --alonzo-era + | --babbage-era + | --conway-era + ] + ] + | --node-config FILEPATH] [--nodeLoggingFormat LOGGING_FORMAT] - [--num-dreps NUMBER] [--enable-new-epoch-state-logging] [--output-dir DIRECTORY] --testnet-magic INT - [--epoch-length SLOTS] - [--slot-length SECONDS] - [--active-slots-coeff DOUBLE] Start a testnet in any era