Skip to content
Closed
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
2 changes: 1 addition & 1 deletion cardano-testnet/src/Parsers/Cardano.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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) <$>
Expand Down
9 changes: 2 additions & 7 deletions cardano-testnet/src/Testnet/Components/Configuration.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
12 changes: 1 addition & 11 deletions cardano-testnet/src/Testnet/Start/Cardano.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
102 changes: 30 additions & 72 deletions cardano-testnet/src/Testnet/Start/Types.hs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE DerivingVia #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE NumericUnderscores #-}

Check warning on line 4 in cardano-testnet/src/Testnet/Start/Types.hs

View workflow job for this annotation

GitHub Actions / build

Warning in module Testnet.Start.Types: Unused LANGUAGE pragma ▫︎ Found: "{-# LANGUAGE NumericUnderscores #-}"
{-# LANGUAGE ScopedTypeVariables #-}

module Testnet.Start.Types
Expand Down Expand Up @@ -50,32 +50,37 @@
-- | 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
Expand Down Expand Up @@ -108,54 +113,7 @@
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
Expand Down
31 changes: 17 additions & 14 deletions cardano-testnet/test/cardano-testnet-golden/files/golden/help.cli
Original file line number Diff line number Diff line change
@@ -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

Expand Down
Loading