Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

create-testnet-data: use experimental API and make arguments era specific #968

Merged
merged 2 commits into from
Dec 10, 2024
Merged
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
14 changes: 10 additions & 4 deletions cardano-cli/src/Cardano/CLI/EraBased/Commands/Genesis.hs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE DuplicateRecordFields #-}
{-# LANGUAGE ExistentialQuantification #-}
{-# LANGUAGE LambdaCase #-}

module Cardano.CLI.EraBased.Commands.Genesis
Expand All @@ -19,6 +20,7 @@ module Cardano.CLI.EraBased.Commands.Genesis
where

import qualified Cardano.Api.Byron as Byron
import qualified Cardano.Api.Experimental as Exp
import Cardano.Api.Ledger (Coin)
import Cardano.Api.Shelley

Expand All @@ -30,7 +32,7 @@ data GenesisCmds era
= GenesisCreate !(GenesisCreateCmdArgs era)
| GenesisCreateCardano !(GenesisCreateCardanoCmdArgs era)
| GenesisCreateStaked !(GenesisCreateStakedCmdArgs era)
| GenesisCreateTestNetData !(GenesisCreateTestNetDataCmdArgs era)
| GenesisCreateTestNetData !GenesisCreateTestNetDataCmdArgs
| GenesisKeyGenGenesis !GenesisKeyGenGenesisCmdArgs
| GenesisKeyGenDelegate !GenesisKeyGenDelegateCmdArgs
| GenesisKeyGenUTxO !GenesisKeyGenUTxOCmdArgs
Expand Down Expand Up @@ -92,8 +94,10 @@ data GenesisCreateStakedCmdArgs era = GenesisCreateStakedCmdArgs
}
deriving Show

data GenesisCreateTestNetDataCmdArgs era = GenesisCreateTestNetDataCmdArgs
{ eon :: !(ShelleyBasedEra era)
-- TODO This existential type parameter should become a regular type parameter
-- when we parameterize the parent type by the experimental era API.
data GenesisCreateTestNetDataCmdArgs = forall era. GenesisCreateTestNetDataCmdArgs
{ eon :: !(Exp.Era era)
, specShelley :: !(Maybe FilePath)
-- ^ Path to the @genesis-shelley@ file to use. If unspecified, a default one will be used.
, specAlonzo :: !(Maybe FilePath)
Expand Down Expand Up @@ -127,7 +131,9 @@ data GenesisCreateTestNetDataCmdArgs era = GenesisCreateTestNetDataCmdArgs
, outputDir :: !FilePath
-- ^ Directory where to write credentials and files.
}
deriving Show

instance Show GenesisCreateTestNetDataCmdArgs where
show _ = "GenesisCreateTestNetDataCmdArgs"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It doesn't derive anymore? It is odd because Era does have a Show instance (here), maybe after moving the parameter it will?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@palas> it doesn't derive anymore because there's an existential type in GenesisCreateTestnetDataCmdArgs now:

image


data GenesisKeyGenGenesisCmdArgs = GenesisKeyGenGenesisCmdArgs
{ verificationKeyPath :: !(VerificationKeyFile Out)
Expand Down
11 changes: 6 additions & 5 deletions cardano-cli/src/Cardano/CLI/EraBased/Options/Genesis.hs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ where

import Cardano.Api hiding (QueryInShelleyBasedEra (..))
import qualified Cardano.Api.Byron as Byron
import qualified Cardano.Api.Experimental as Exp
import Cardano.Api.Ledger (Coin (..))

import Cardano.CLI.Environment (EnvCli (..))
Expand Down Expand Up @@ -217,18 +218,18 @@ pGenesisCreateStaked sbe envCli =
pRelayJsonFp =
parseFilePath "relay-specification-file" "JSON file that specifies the relays of each stake pool."

pGenesisCreateTestNetData :: ShelleyBasedEra era -> EnvCli -> Parser (GenesisCmds era)
pGenesisCreateTestNetData sbe envCli =
pGenesisCreateTestNetData :: Exp.Era era -> EnvCli -> Parser (GenesisCmds era)
pGenesisCreateTestNetData era envCli =
fmap GenesisCreateTestNetData $
GenesisCreateTestNetDataCmdArgs sbe
GenesisCreateTestNetDataCmdArgs era
<$> optional (pSpecFile "shelley")
<*> optional (pSpecFile "alonzo")
<*> optional (pSpecFile "conway")
<*> pNumGenesisKeys
<*> pNumPools
<*> pNumStakeDelegs
<*> pNumCommittee
<*> pNumDReps
<*> (case era of Exp.BabbageEra -> pure 0; Exp.ConwayEra -> pNumCommittee) -- Committee doesn't exist in babbage
<*> (case era of Exp.BabbageEra -> pure $ DRepCredentials OnDisk 0; Exp.ConwayEra -> pNumDReps) -- DReps don't exist in babbage
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Making it unrepresentable on the type would be safer. But this is probably much simpler, so it seems a reasonable trade-off

<*> pNumStuffedUtxoCount
<*> pNumUtxoKeys
<*> pSupply
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ data WriteFileGenesis where
WritePretty :: ToJSON genesis => genesis -> WriteFileGenesis

runGenesisCreateTestNetDataCmd
:: GenesisCreateTestNetDataCmdArgs era
:: GenesisCreateTestNetDataCmdArgs
-> ExceptT GenesisCmdError IO ()
runGenesisCreateTestNetDataCmd
Cmd.GenesisCreateTestNetDataCmdArgs
Expand Down Expand Up @@ -239,7 +239,7 @@ runGenesisCreateTestNetDataCmd
, outputDir
} = do
liftIO $ createDirectoryIfMissing False outputDir
let era = toCardanoEra eon
let era = convert eon
shelleyGenesisInit <-
fromMaybe shelleyGenesisDefaults <$> traverse decodeShelleyGenesisFile specShelley
alonzoGenesis <-
Expand Down Expand Up @@ -298,7 +298,8 @@ runGenesisCreateTestNetDataCmd

when (0 < numPools) $ writeREADME poolsDir poolsREADME

-- CC members
-- CC members. We don't need to look at the eon, because the command's parser guarantees
-- that before Conway, the number of CC members at this point is 0.
ccColdKeys <- forM [1 .. numCommitteeKeys] $ \index -> do
let committeeDir = committeesDir </> "cc" <> show index
vkeyHotFile = File @(VerificationKey ()) $ committeeDir </> "cc.hot.vkey"
Expand All @@ -318,7 +319,8 @@ runGenesisCreateTestNetDataCmd

when (0 < numCommitteeKeys) $ writeREADME committeesDir committeeREADME

-- DReps
-- DReps. We don't need to look at the eon, because the command's parser guarantees
-- that before Conway, the number of DReps at this point is 0.
g <- Random.getStdGen

dRepKeys <- firstExceptT GenesisCmdFileError $
Expand Down
100 changes: 0 additions & 100 deletions cardano-cli/test/cardano-cli-golden/files/golden/help.cli
Original file line number Diff line number Diff line change
Expand Up @@ -1094,7 +1094,6 @@ Usage: cardano-cli shelley genesis
| create-cardano
| create
| create-staked
| create-testnet-data
| hash
)

Expand Down Expand Up @@ -1194,29 +1193,6 @@ Usage: cardano-cli shelley genesis create-staked [--key-output-format STRING]
Create a staked Shelley genesis file from a genesis template and
genesis/delegation/spending keys.

Usage: cardano-cli shelley genesis create-testnet-data [--spec-shelley FILEPATH]
[--spec-alonzo FILEPATH]
[--spec-conway FILEPATH]
[--genesis-keys INT]
[--pools INT]
[ --stake-delegators INT
| --transient-stake-delegators INT
]
[--committee-keys INT]
[ --drep-keys INT
| --transient-drep-keys INT
]
[--stuffed-utxo INT]
[--utxo-keys INT]
[--total-supply LOVELACE]
[--delegated-supply LOVELACE]
[--testnet-magic NATURAL]
[--relays FILEPATH]
[--start-time UTC-TIME]
--out-dir DIR

Create data to use for starting a testnet.

Usage: cardano-cli shelley genesis hash --genesis FILEPATH

Compute the hash of a genesis file
Expand Down Expand Up @@ -2167,7 +2143,6 @@ Usage: cardano-cli allegra genesis
| create-cardano
| create
| create-staked
| create-testnet-data
| hash
)

Expand Down Expand Up @@ -2267,29 +2242,6 @@ Usage: cardano-cli allegra genesis create-staked [--key-output-format STRING]
Create a staked Shelley genesis file from a genesis template and
genesis/delegation/spending keys.

Usage: cardano-cli allegra genesis create-testnet-data [--spec-shelley FILEPATH]
[--spec-alonzo FILEPATH]
[--spec-conway FILEPATH]
[--genesis-keys INT]
[--pools INT]
[ --stake-delegators INT
| --transient-stake-delegators INT
]
[--committee-keys INT]
[ --drep-keys INT
| --transient-drep-keys INT
]
[--stuffed-utxo INT]
[--utxo-keys INT]
[--total-supply LOVELACE]
[--delegated-supply LOVELACE]
[--testnet-magic NATURAL]
[--relays FILEPATH]
[--start-time UTC-TIME]
--out-dir DIR

Create data to use for starting a testnet.

Usage: cardano-cli allegra genesis hash --genesis FILEPATH

Compute the hash of a genesis file
Expand Down Expand Up @@ -3240,7 +3192,6 @@ Usage: cardano-cli mary genesis
| create-cardano
| create
| create-staked
| create-testnet-data
| hash
)

Expand Down Expand Up @@ -3338,29 +3289,6 @@ Usage: cardano-cli mary genesis create-staked [--key-output-format STRING]
Create a staked Shelley genesis file from a genesis template and
genesis/delegation/spending keys.

Usage: cardano-cli mary genesis create-testnet-data [--spec-shelley FILEPATH]
[--spec-alonzo FILEPATH]
[--spec-conway FILEPATH]
[--genesis-keys INT]
[--pools INT]
[ --stake-delegators INT
| --transient-stake-delegators INT
]
[--committee-keys INT]
[ --drep-keys INT
| --transient-drep-keys INT
]
[--stuffed-utxo INT]
[--utxo-keys INT]
[--total-supply LOVELACE]
[--delegated-supply LOVELACE]
[--testnet-magic NATURAL]
[--relays FILEPATH]
[--start-time UTC-TIME]
--out-dir DIR

Create data to use for starting a testnet.

Usage: cardano-cli mary genesis hash --genesis FILEPATH

Compute the hash of a genesis file
Expand Down Expand Up @@ -4303,7 +4231,6 @@ Usage: cardano-cli alonzo genesis
| create-cardano
| create
| create-staked
| create-testnet-data
| hash
)

Expand Down Expand Up @@ -4401,29 +4328,6 @@ Usage: cardano-cli alonzo genesis create-staked [--key-output-format STRING]
Create a staked Shelley genesis file from a genesis template and
genesis/delegation/spending keys.

Usage: cardano-cli alonzo genesis create-testnet-data [--spec-shelley FILEPATH]
[--spec-alonzo FILEPATH]
[--spec-conway FILEPATH]
[--genesis-keys INT]
[--pools INT]
[ --stake-delegators INT
| --transient-stake-delegators INT
]
[--committee-keys INT]
[ --drep-keys INT
| --transient-drep-keys INT
]
[--stuffed-utxo INT]
[--utxo-keys INT]
[--total-supply LOVELACE]
[--delegated-supply LOVELACE]
[--testnet-magic NATURAL]
[--relays FILEPATH]
[--start-time UTC-TIME]
--out-dir DIR

Create data to use for starting a testnet.

Usage: cardano-cli alonzo genesis hash --genesis FILEPATH

Compute the hash of a genesis file
Expand Down Expand Up @@ -5489,10 +5393,6 @@ Usage: cardano-cli babbage genesis create-testnet-data [--spec-shelley FILEPATH]
[ --stake-delegators INT
| --transient-stake-delegators INT
]
[--committee-keys INT]
[ --drep-keys INT
| --transient-drep-keys INT
]
[--stuffed-utxo INT]
[--utxo-keys INT]
[--total-supply LOVELACE]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ Usage: cardano-cli allegra genesis
| create-cardano
| create
| create-staked
| create-testnet-data
| hash
)

Expand All @@ -35,5 +34,4 @@ Available commands:
and genesis/delegation/spending keys.
create-staked Create a staked Shelley genesis file from a genesis
template and genesis/delegation/spending keys.
create-testnet-data Create data to use for starting a testnet.
hash Compute the hash of a genesis file

This file was deleted.

Loading
Loading