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

Cl/testnetdata #595

Merged
merged 8 commits into from
Feb 8, 2024
Merged

Cl/testnetdata #595

merged 8 commits into from
Feb 8, 2024

Conversation

CarlosLopezDeLara
Copy link
Contributor

@CarlosLopezDeLara CarlosLopezDeLara commented Feb 5, 2024

Changelog

- description: | 
    This PR improves `create-testnet-data` cmd so that it takes testnet magic either from template file or from the  CLI flag `--testnet-magic`, when used.   
# uncomment types applicable to the change:
  type:
  # - feature        # introduces a new feature
  # - breaking       # the API has changed in a breaking way
  # - compatible     # the API has changed but is non-breaking
  # - optimisation   # measurable performance improvements
  - improvement    # QoL changes e.g. refactoring
  # - bugfix         # fixes a defect
  # - test           # fixes/modifies tests
  # - maintenance    # not directly related to the code
  # - release        # related to a new release preparation
  # - documentation  # change in code docs, haddocks...

Context

Resolves #591

How to trust this PR

Passing a network magic via the flag overrides the value on the template file

carlos@focus:~/GitHub/cardano-cli$ cabal run cardano-cli -- conway genesis create-testnet-data --spec-shelley configuration/cardano/mainnet-shelley-genesis.json --out-dir out128 --testnet-magic 128
Resolving dependencies...
carlos@focus:~/GitHub/cardano-cli$ cat out128/genesis.json | jq .networkMagic
128

Using template file without using the --testnet-magic flag takes the value from the template

carlos@focus:~/GitHub/cardano-cli$ cabal run cardano-cli -- conway genesis create-testnet-data --spec-shelley configuration/cardano/mainnet-shelley-genesis.json --out-dir outnoflag
Resolving dependencies...
carlos@focus:~/GitHub/cardano-cli$ cat outnoflag/genesis.json | jq .networkMagic
764824073

If no template is used the default template is used instead.

cabal run cardano-cli -- conway genesis create-testnet-data --out-dir outdefault
Resolving dependencies...
carlos@focus:~/GitHub/cardano-cli$ cat outdefault/genesis.json | jq .networkMagic42

Checklist

  • Commit sequence broadly makes sense and commits have useful messages
  • New tests are added if needed and existing tests are updated. See Running tests for more details
  • Self-reviewed the diff

Copy link
Contributor

@carbolymer carbolymer left a comment

Choose a reason for hiding this comment

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

LGTM. Nice!

@CarlosLopezDeLara CarlosLopezDeLara added this pull request to the merge queue Feb 5, 2024
@@ -211,7 +211,7 @@ pGenesisCreateTestNetData envCli =
<*> pNumUtxoKeys
<*> pSupply
<*> pSupplyDelegated
<*> pNetworkId envCli
<*> (optional $ pNetworkId envCli)
Copy link
Contributor

@Jimbo4350 Jimbo4350 Feb 5, 2024

Choose a reason for hiding this comment

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

You should update the parser's help text so the user knows this value will override the genesis file's value.

Copy link
Contributor

Choose a reason for hiding this comment

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

@CarlosLopezDeLara> when you do so, you will need to regenerate the golden files as follows:

RECREATE_GOLDEN_FILES=1 cabal test all

cardano-cli/src/Cardano/CLI/EraBased/Commands/Genesis.hs Outdated Show resolved Hide resolved
@Jimbo4350 Jimbo4350 removed this pull request from the merge queue due to a manual request Feb 5, 2024
@@ -211,7 +211,7 @@ pGenesisCreateTestNetData envCli =
<*> pNumUtxoKeys
<*> pSupply
<*> pSupplyDelegated
<*> pNetworkId envCli
<*> (optional $ pNetworkId envCli)
Copy link
Contributor

Choose a reason for hiding this comment

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

@CarlosLopezDeLara> when you do so, you will need to regenerate the golden files as follows:

RECREATE_GOLDEN_FILES=1 cabal test all

@CarlosLopezDeLara
Copy link
Contributor Author

Addressing @Jimbo4350 comments about updating the parser.

We were using pNetworkId :: EnvCli -> Parser NetworkId which is used by al commands that talk to the node. So instead now we introduce

pGenesisCreateTestNetData :: Parser (GenesisCmds era)
pGenesisCreateTestNetData =
  fmap GenesisCreateTestNetData $ GenesisCreateTestNetDataCmdArgs
    <$> (optional $ pSpecFile "shelley")
...
    <*> optional pNetworkIdForTestnetData
...
  where
    pNetworkIdForTestnetData :: Parser NetworkId 
    pNetworkIdForTestnetData = Testnet . NetworkMagic <$> testnetMagicParser
      where
        testnetMagicParser = Opt.option (bounded "TESTNET_MAGIC")
          (  Opt.long "testnet-magic"
          <> Opt.metavar "NATURAL"
          <> Opt.help "Specify a testnet magic id for the cluster. Overrides the network id supplied in the spec file."
          )

This allows for better options, i.e.:

  • Not giving --mainnet as an option for create-testnet-data (we want to create testnets, not mainnets),
  • Avoid the hanging pure <$> maybeToList (envCliNetworkId envCli) from pNetworkId which does not make sense here,
  • Showing a better help. In the genesis commands the networkId has an entirely different use (setting the magic for the cluster, not for node-to-client)

@CarlosLopezDeLara CarlosLopezDeLara marked this pull request as draft February 7, 2024 17:30
Move pNetworkForTestnetData to Common.hs
@CarlosLopezDeLara
Copy link
Contributor Author

With that last changes now we have:

$ cabal run cardano-cli -- conway genesis create-testnet-data --spec-shelley configuration/cardano/mainnet-shelley-genesis.json --out-dir outFromSpecFile
Resolving dependencies...
$ cat outFromSpecFile/genesis.json | jq  .networkMagic
764824073
$ cabal run cardano-cli -- conway genesis create-testnet-data --spec-shelley configuration/cardano/mainnet-shelley-genesis.json --out-dir outFromFlag --testnet-magic 13579
Resolving dependencies...
$ cat outFromFlag/genesis.json | jq  .networkMagic
13579
$ export CARDANO_NODE_NETWORK_ID=24680
$ cabal run cardano-cli -- conway genesis create-testnet-data --spec-shelley configuration/cardano/mainnet-shelley-genesis.json --out-dir outFromEnv 
Resolving dependencies...
$ cat outFromEnv/genesis.json | jq  .networkMagic
24680
$ cabal run cardano-cli -- conway genesis create-testnet-data --spec-shelley configuration/cardano/mainnet-shelley-genesis.json --out-dir outFromFlagOverridesEnv --testnet-magic 9999999 
Resolving dependencies...
$ cat outFromFlagOverridesEnv/genesis.json | jq  .networkMagic
9999999

And help menu looks like this:

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

  Create data to use for starting a testnet.

Available options:
  ...
  --testnet-magic NATURAL  Specify a testnet magic id for the cluster. This
                           overrides both the network magic from the spec file
                           and CARDANO_NODE_NETWORK_ID environment variable.
...

@CarlosLopezDeLara CarlosLopezDeLara marked this pull request as ready for review February 7, 2024 18:32
Copy link
Contributor

@Jimbo4350 Jimbo4350 left a comment

Choose a reason for hiding this comment

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

LGTM!

@CarlosLopezDeLara CarlosLopezDeLara merged commit 79b264d into main Feb 8, 2024
19 checks passed
@CarlosLopezDeLara CarlosLopezDeLara deleted the cl/testnetdata branch February 8, 2024 20:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

create-testnet-data: --testnet-magic should override the template's value
4 participants