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

cardano-testnet: allow to pass genesis files #5645

Merged
merged 1 commit into from
Feb 1, 2024

Conversation

smelc
Copy link
Contributor

@smelc smelc commented Jan 19, 2024

Description

We want to be able to tweak genesis files in cardano-testnet. This PR makes it possible to pass custom alonzo, conway, and shelley genesis files to createTestnet. A new function createTestnetDefault is introduced, that uses default genesis files for all 3.

Context

This PR replaces #5643, whose design was deemed unsatisfying.

Checklist

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

@smelc smelc force-pushed the smelc/testnet-allow-passing-config-files branch 2 times, most recently from 2a2abde to f75e77d Compare January 23, 2024 11:04
@smelc smelc force-pushed the smelc/testnet-allow-passing-config-files branch from f75e77d to d3f8830 Compare January 23, 2024 11:07
@smelc smelc marked this pull request as ready for review January 24, 2024 10:58
cardano-testnet/src/Testnet/Components/Configuration.hs Outdated Show resolved Hide resolved
let testnetMagic = cardanoTestnetMagic testnetOptions
slotLength = cardanoSlotLength testnetOptions
epochLength = cardanoEpochLength testnetOptions
maxLovelaceLovelaceSupply = cardanoMaxSupply testnetOptions
in Api.shelleyGenesisDefaults
in (fromMaybe Api.shelleyGenesisDefaults mBase)
Copy link
Contributor

Choose a reason for hiding this comment

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

So the problem here is if a user did provide a shelley genesis we would be overriding several fields.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, but this is mitigated by the additional documentation I have added in all the call chain about this.

Also, discussing a similar API with @andreabedini, this overriding is the default expectation of callers (not doing it would be the surprise!).

So I'd keep it like this.

cardano-testnet/src/Testnet/Start/Cardano.hs Outdated Show resolved Hide resolved
@Jimbo4350
Copy link
Contributor

Jimbo4350 commented Jan 24, 2024

A viable option is exposing a cardanoTestnetDefault function that uses all of our defaults.

@smelc smelc force-pushed the smelc/testnet-allow-passing-config-files branch 7 times, most recently from 731e6d9 to 84f047e Compare January 25, 2024 13:34
Comment on lines 86 to 94
=> NumPools
-> AnyCardanoEra -- ^ The era to use
-> ShelleyGenesis StandardCrypto -- ^ The shelley genesis to use.
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 did this change to avoid mixing CardanoTestnetOptions and genesis files in the same signature. We should avoid having them together in a signature, because they contain duplicate data, e,g, the network magic is both in CardanoTestnetOptions and the genesis files.

So if we have them together, we are imposing on the caller to be careful to pass coherent data. This change avoids that, by using smaller types instead.

Copy link
Contributor

Choose a reason for hiding this comment

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

What about the ConwayGenesis and AlonzoGenesis parameters?

Copy link
Contributor

Choose a reason for hiding this comment

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

We should not expose the data constructor for NumPools and expose smart constructors instead: e.g numPools :: CardanoTestnetOptions -> NumPoolNodes

Copy link
Contributor Author

Choose a reason for hiding this comment

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

What about the ConwayGenesis and AlonzoGenesis parameters?

@Jimbo4350> since create-testnet-data doesn't yet take alonzo and conway genesis as CLI parameters, they do not make sense here yet. Adding them is tracked by IntersectMBO/cardano-cli#548

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We should not expose the data constructor for NumPools and expose smart constructors instead: e.g numPools :: CardanoTestnetOptions -> NumPoolNodes

Done 👍

Comment on lines +95 to +97
cardanoTestnetDefault :: ()
=> CardanoTestnetOptions
-> Conf
-> H.Integration TestnetRuntime
Copy link
Contributor Author

@smelc smelc Jan 25, 2024

Choose a reason for hiding this comment

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

Here, we're not mixing CardanoTestnetOptions and genesis files, which is good (as I explained elsewhere). This is nice for the vast majority of callers, that don't need to be exposed to a complex API.

Comment on lines +150 to +155
=> CardanoTestnetOptions -- ^ The options to use. Must be consistent with the genesis files.
-> Conf
-> UTCTime -- ^ The starting time. Must be the same as the one in the shelley genesis.
-> ShelleyGenesis StandardCrypto -- ^ The shelley genesis to use, for example 'Defaults.defaultShelleyGenesis'.
-- Some fields are overridden by the accompanying 'CardanoTestnetOptions'.
-> AlonzoGenesis -- ^ The alonzo genesis to use, for example 'Defaults.defaultAlonzoGenesis'.
-> ConwayGenesis StandardCrypto -- ^ The conway genesis to use, for example 'Defaults.defaultConwayGenesis'.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Here we mix CardanoTestnetOptions and genesis files. So callers must be careful to provide coherent data. If they don't, they will get caught by the new checks below. Ideally, in the future, we'll want to remove fields from CardanoTestnetOptions, so that the intersection with the data of genesis files becomes empty. This a bigger change though, so I chose this version, which is an improvement already, and minimizes disturbing users.

@smelc smelc force-pushed the smelc/testnet-allow-passing-config-files branch 2 times, most recently from 18a2054 to 38c52b8 Compare February 1, 2024 13:36
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! However you need to make the change regarding my comments about the smart constructors.

Comment on lines 86 to 94
=> NumPools
-> AnyCardanoEra -- ^ The era to use
-> ShelleyGenesis StandardCrypto -- ^ The shelley genesis to use.
Copy link
Contributor

Choose a reason for hiding this comment

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

What about the ConwayGenesis and AlonzoGenesis parameters?

-> TmpAbsolutePath
-> m FilePath -- ^ Shelley genesis directory
createSPOGenesisAndFiles testnetOptions startTime (TmpAbsolutePath tempAbsPath') = do
createSPOGenesisAndFiles NumPools {unNumPools = numPoolNodes} era shelleyGenesis (TmpAbsolutePath tempAbsPath') = do
Copy link
Contributor

Choose a reason for hiding this comment

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

(NumPools numPoolNodes) should be sufficient

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done 👍

Comment on lines 86 to 94
=> NumPools
-> AnyCardanoEra -- ^ The era to use
-> ShelleyGenesis StandardCrypto -- ^ The shelley genesis to use.
Copy link
Contributor

Choose a reason for hiding this comment

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

We should not expose the data constructor for NumPools and expose smart constructors instead: e.g numPools :: CardanoTestnetOptions -> NumPoolNodes

@smelc smelc force-pushed the smelc/testnet-allow-passing-config-files branch from 38c52b8 to e49b5c6 Compare February 1, 2024 19:55
@smelc smelc force-pushed the smelc/testnet-allow-passing-config-files branch from e49b5c6 to 73c883d Compare February 1, 2024 20:00
@smelc smelc enabled auto-merge February 1, 2024 20:01
@smelc smelc added this pull request to the merge queue Feb 1, 2024
Merged via the queue into master with commit f6edc1e Feb 1, 2024
17 of 19 checks passed
@smelc smelc deleted the smelc/testnet-allow-passing-config-files branch February 1, 2024 23:25
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.

3 participants