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: allow to specify relays for SPOs (like create-staked) #632

Merged
merged 5 commits into from
Mar 6, 2024

Conversation

smelc
Copy link
Contributor

@smelc smelc commented Mar 5, 2024

Changelog

- description: |
    create-testnet-data: allow to specify relays for SPOs (like create-staked)
# 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

Fixes #630

How to trust this PR

Run the following:

cabal run cardano-cli -- conway genesis create-testnet-data --out-dir create_testnet_out --stake-delegators 3 --pools 4 --utxo-keys 5 --genesis-keys 6 --testnet-magic 42 --relays pool-relays.json

pool-relays.json is the following file:

{
  "0": [
    {
      "single host name": {
        "dnsName": "node-0",
        "port": 30000
      }
    }
  ],
  "1": [
    {
      "single host name": {
        "dnsName": "node-1",
        "port": 30001
      }
    }
  ]
}

Then open create_testnet_out/genesis.json and observe that the pools have a non-empty entry in their relays field.

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

@smelc smelc force-pushed the smelc/create-testnet-data-relays branch 3 times, most recently from 128617d to 33d3ad8 Compare March 5, 2024 16:26
@smelc smelc marked this pull request as ready for review March 5, 2024 16:26
pRelays :: Parser FilePath
pRelays =
Opt.strOption $ mconcat
[ Opt.long "relays"
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I chose a shorter flag name than create-staked's relay-specification-file. I feel the longer name didn't bring much value. We already chose to use different names in create-testnet-data before, so this should not be a surprise to users.

Copy link
Contributor

Choose a reason for hiding this comment

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

Why two different names for the same file?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not sure what you mean @carbolymer: there is a single name in create-testnet-data and one single name in create-staked. I simply chose a shorter, I think better, name for create-testnet-data.

Copy link
Contributor

Choose a reason for hiding this comment

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

My question is why two different parmeter names relay-specification-file and relays? I agree with your choice, but why not just use relays everywhere, also in create-staked.

mSPOsRelays <- forM relays readRelays
case (relays, mSPOsRelays) of
(Just fp, Just stakePoolRelays) | Map.size stakePoolRelays > fromIntegral numPools ->
throwError $ GenesisCmdTooManyRelaysError fp (fromIntegral numPools) (Map.size stakePoolRelays)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This check wasn't in create-staked, but checked with @mgmeier that it was nice to have in create-testnet-data.

Copy link
Contributor

Choose a reason for hiding this comment

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

Just curious, what's wrong with having more relays than SPOs?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@Jimbo4350> it means the user is passing data that is being ignored. It's probably nice to tell the user that.

@smelc smelc force-pushed the smelc/create-testnet-data-relays branch from 33d3ad8 to 6ee4235 Compare March 5, 2024 16:29
handleIOExceptT (GenesisCmdStakePoolRelayFileError fp) (LBS.readFile fp)
firstExceptT (GenesisCmdStakePoolRelayJsonDecodeError fp)
. hoistEither $ Aeson.eitherDecode relaySpecJsonBs
mayStakePoolRelays <- forM mStakePoolRelaySpecFile TN.readRelays
Copy link
Contributor Author

Choose a reason for hiding this comment

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

As in other parts of create-staked, it's create-staked's implementation that calls create-testnet-data's implementation when they are shared. So nothing new here.

@smelc smelc force-pushed the smelc/create-testnet-data-relays branch 2 times, most recently from 2820153 to 38a1669 Compare March 6, 2024 09:13
@smelc smelc force-pushed the smelc/create-testnet-data-relays branch from b717fd6 to 829f70e Compare March 6, 2024 13:08
@smelc smelc added this pull request to the merge queue Mar 6, 2024
Merged via the queue into main with commit 156820e Mar 6, 2024
17 checks passed
@smelc smelc deleted the smelc/create-testnet-data-relays branch March 6, 2024 13:32
@@ -649,6 +657,18 @@ readAndDecodeShelleyGenesis fpath = runExceptT $ do
firstExceptT (GenesisCmdGenesisFileDecodeError fpath . Text.pack)
. hoistEither $ Aeson.eitherDecode' lbs

-- @readRelays fp@ reads the relays specification from a file
readRelays :: ()
Copy link
Contributor

Choose a reason for hiding this comment

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

We could have made the types here concrete.

Opt.strOption $ mconcat
[ Opt.long "relay-specification-file"
, Opt.metavar "FILE"
, Opt.help "JSON file specified the relays of each stake pool."
Copy link
Contributor

Choose a reason for hiding this comment

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

"that specifies"

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Since this is in create-staked, I chose not to change anything 🙂

case (relays, mSPOsRelays) of
(Just fp, Just stakePoolRelays) | Map.size stakePoolRelays > fromIntegral numPools ->
throwError $ GenesisCmdTooManyRelaysError fp (fromIntegral numPools) (Map.size stakePoolRelays)
_ -> pure ()
Copy link
Contributor

Choose a reason for hiding this comment

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

We can avoid the wildcard pattern (IMO this is less readable) match if you case on relays i.e

case relays of 
  Nothing -> pure ()
  Just relaySpecFile -> ...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@Jimbo4350> not much shorter with your version, because I need mSPOsRelays to be a Just to look at the size of the underlying Map. If I don't pattern match on it, I need to default Nothing to being of size 0, which is a bit cumbersome.

So I'll skip this one.

poolColdVKF = File $ dir </> "cold" ++ strIndex ++ ".vkey"
poolVrfVKF = File $ dir </> "vrf" ++ strIndex ++ ".vkey"
poolRewardVKF = File $ dir </> "staking-reward" ++ strIndex ++ ".vkey"
lookupPoolRelay :: Map Word [L.StakePoolRelay] -> Seq.StrictSeq L.StakePoolRelay
Copy link
Contributor

Choose a reason for hiding this comment

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

👍

mSPOsRelays <- forM relays readRelays
case (relays, mSPOsRelays) of
(Just fp, Just stakePoolRelays) | Map.size stakePoolRelays > fromIntegral numPools ->
throwError $ GenesisCmdTooManyRelaysError fp (fromIntegral numPools) (Map.size stakePoolRelays)
Copy link
Contributor

Choose a reason for hiding this comment

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

Just curious, what's wrong with having more relays than SPOs?

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 to support relay specification (like create-staked)
3 participants