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 take node config file as input #6103

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

smelc
Copy link
Contributor

@smelc smelc commented Feb 5, 2025

Description

Fixes #6069

With @CarlosLopezDeLara's input, I have chosen an all or nothing behavior: either you pass the configuration file and all genesis files or you pass none of them. If we choose an à la carte behavior, it's cumbersome to implement, and anyway since the node configuration file contains the hashes of genesis files, there is at least some degree of binding between all of these files.

After feedback from Jordan, we finally only ask the user to provide the node configuration file. Then we read the eras' genesis files by looking at the paths specified in the node configuration file. This way, no additional flag needed, nor checking consistency between the flags and the node configuration file.

How to trust this PR

TBD

Checklist

  • Commit sequence broadly makes sense and commits have useful messages
  • CI passes.
  • Self-reviewed the diff

@smelc smelc changed the title cardano-testnet: allow to take config files as input cardano-testnet: allow to take node config and genesis files as input Feb 5, 2025
@smelc smelc linked an issue Feb 5, 2025 that may be closed by this pull request
17 tasks
Base automatically changed from smelc/cardano-testnet-support-custom-node-config-file to master February 5, 2025 16:14
@smelc smelc force-pushed the smelc/testnet-pass-config-files branch from 3894926 to 8e37423 Compare February 7, 2025 13:53
@smelc smelc marked this pull request as ready for review February 7, 2025 13:53
@smelc smelc requested a review from a team as a code owner February 7, 2025 13:53
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.

How do you plan to deal with conflicts in the node configuration yaml file? I think this is the wrong approach. We don't want to be forced to reconcile configuration file differences. All we should need the is the node configuration yaml file.

decodeFileThrow $ icfAlonzoGenesisConfigFile inputConfigFiles
conwayGenesisFile :: ConwayGenesis StandardCrypto <-
decodeFileThrow $ icfConwayGenesisConfigFile inputConfigFiles
runTestnet testnetOptions $ cardanoTestnet
Copy link
Contributor

Choose a reason for hiding this comment

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

why does runTestnet result in a Property??

Copy link
Contributor Author

Choose a reason for hiding this comment

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

runTestnet doesn't return a property but it does take a Conf -> H.Integration a callback, as visible here:

runTestnet :: CardanoTestnetOptions -> (Conf -> H.Integration a) -> IO ()

This is a bit meh and we can probably improve that: in the case where the user provides a configuration file, we would like not be tied to the hedgehog-extras/hedgehog APIs like Integration and Property. But this is something we would better do in the future, not in this PR, because it's not required for reaching a first release of cardano-testnet IMHO. And also, it will be some work, because our existing "backend", e.g. cardanoTestnet here is in the Integration monad. So it's not an easy change.

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 return to this. Could you create an issue to track it? The issue just needs to point out its an issue 😆

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> created follow-up issue: #6122

@smelc smelc force-pushed the smelc/testnet-pass-config-files branch 2 times, most recently from 63c60a5 to 6ca79c5 Compare February 11, 2025 16:16
@smelc
Copy link
Contributor Author

smelc commented Feb 12, 2025

For future reference, if we leave the call to cardano-cli debug check-node-configuration, we have the following failures with the following genesis files:

> cabal run cardano-testnet -- cardano --output-dir cl-output-dir --node-config cl-example/configuration.json --testnet-magic 44
  ✗ <interactive> failed at src/Testnet/Start/Cardano.hs:283:3
    after 1 test.
    shrink path: 1:
  
    forAll0 =
      Process exited with non-zero exit-code: 1
      ━━━━ stdout ━━━━
      Checking byron genesis file: cl-example/byron.genesis.spec.json
      
      ━━━━ stderr ━━━━
      Error reading node configuration at: cl-example/byron.genesis.spec.json: Incorrect schema for GenesisData.
       Error: expected field protocolConsts

It seems the code is requiring too much data here when deserializing the Byron genesis. This data is actually not required to start the node (i.e. if we remove the check, the testnet starts fine). So it seems overkill to require this data when starting a testnet.

[edit] Oh well, it seems the node doesn't like it either actually:

<interactive> failed at src/Testnet/Start/Cardano.hs:342:5
    after 1 test.
    shrink path: 1:
  
    forAll0 =
      Cardano node process did not start: CardanoProtocolInstantiationError (CardanoProtocolInstantiationErrorByron (GenesisReadError "/home/churlin/dev/cardano-node/cl-example/byron.genesis.spec.json" (GenesisDataSchemaError (SchemaError {seExpected = "field protocolConsts", seActual = Nothing}))))
      
      cardano-node: There was an error parsing the genesis file: "/home/churlin/dev/cardano-node/cl-example/byron.genesis.spec.json" Error: GenesisDataSchemaError (SchemaError {seExpected = "field protocolConsts", seActual = Nothing})

smelc added a commit that referenced this pull request Feb 12, 2025
The node itself, when it starts, doesn't require hashes of genesis
files. So it seems overkill to require it to start a testnet.
See also
#6103 (comment)
@smelc smelc force-pushed the smelc/testnet-pass-config-files branch from 6ca79c5 to d67ff61 Compare February 12, 2025 10:38
smelc added a commit that referenced this pull request Feb 12, 2025
The node itself, when it starts, doesn't require hashes of genesis
files. So it seems overkill to require it to start a testnet.
See also
#6103 (comment)
@smelc smelc force-pushed the smelc/testnet-pass-config-files branch from d67ff61 to c78c34f Compare February 12, 2025 10:39
smelc added a commit that referenced this pull request Feb 12, 2025
The node itself, when it starts, doesn't require hashes of genesis
files. So it seems overkill to require it to start a testnet.
See also
#6103 (comment)
@smelc smelc force-pushed the smelc/testnet-pass-config-files branch from c78c34f to 1f7c3d8 Compare February 12, 2025 14:25
smelc added a commit that referenced this pull request Feb 12, 2025
The node itself, when it starts, doesn't require hashes of genesis
files. So it seems overkill to require it to start a testnet.
See also
#6103 (comment)
@smelc smelc force-pushed the smelc/testnet-pass-config-files branch from 18c0d3e to 50849e1 Compare February 12, 2025 15:30
@smelc
Copy link
Contributor Author

smelc commented Feb 12, 2025

Starting with the configuration.yaml file created by running the queries (e.g. the sandbox created by DISABLE_RETRIES=1 cabal test cardano-testnet-test --test-options '-p "/CliQueries/"') test fails as follows:

> cabal run cardano-testnet -- cardano --output-dir cl-output-dir --node-config nix-shell.Ai0S6G/cli-queries-test-6184168d6b9797eb/configuration.yaml --testnet-magic 44

✗ <interactive> failed at src/Testnet/Start/Cardano.hs:342:5
    after 1 test.
    shrink path: 1:
  
    forAll0 =
      Cardano node process did not start: CardanoProtocolInstantiationError (CardanoProtocolInstantiationErrorByron (CredentialsError DelegationCertificateNotFromGenesisKey))
      
      cardano-node: Byron leader credentials error: DelegationCertificateNotFromGenesisKey

I'm a bit puzzled.

[edit] Solved later on, it was related to not honoring the custom configuration file everywhere

smelc added a commit that referenced this pull request Feb 12, 2025
The node itself, when it starts, doesn't require hashes of genesis
files. So it seems overkill to require it to start a testnet.
See also
#6103 (comment)
@smelc smelc force-pushed the smelc/testnet-pass-config-files branch 3 times, most recently from 8117ffc to 3671f83 Compare February 18, 2025 12:14
@smelc smelc changed the title cardano-testnet: allow to take node config and genesis files as input cardano-testnet: allow to take node config file as input Feb 18, 2025
@smelc
Copy link
Contributor Author

smelc commented Feb 18, 2025

All we should need the is the node configuration yaml file.

@Jimbo4350> Updated version of this PR now does that 👍

smelc added a commit that referenced this pull request Feb 18, 2025
… node configuration file (it was unused)

This will be done differently in
#6103
smelc added a commit that referenced this pull request Feb 18, 2025
… node configuration file (it was unused)

This will be done differently in
#6103
@smelc smelc force-pushed the smelc/testnet-pass-config-files branch from c25acc3 to 6dc7fb4 Compare February 18, 2025 14:52
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.

This is an improvement 👍 . Have a look at my comments.

<> OA.showDefault
<> OA.value 1)
, UserNodeOptions
<$> strOption ( long "node-config"
Copy link
Contributor

Choose a reason for hiding this comment

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

So this is an improvement however the resultant type should be [TestnetNodeOptions]. Users (or QA) may want to for example create forking conditions whereby nodes have different configurations. This will have to be done in another PR at some point.

Nothing -> error $ "Genesis files not specified in node configuration file: " <> nodeInputConfigFile
Just x -> x
adjustedProtocolConfig =
-- Make all the files be relative to the location of the config file.
Copy link
Contributor

Choose a reason for hiding this comment

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

👍

alonzoGenesisFile
conwayGenesisFile
where
getShelleyGenesises (NodeProtocolConfigurationCardano _byron shelley alonzo conway _hardForkConfig) =
Copy link
Contributor

Choose a reason for hiding this comment

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

We also want to confirm the validity of the byron genesis but that can be a separate PR in the future.

where
nSpoNodes =
case cardanoNodes of
UserNodeOptions _ -> 1
Copy link
Contributor

Choose a reason for hiding this comment

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

Hardcoding this isn't great. This is related to my comment above regarding [TestnetNodeOptions]

-- to run a testnet. "create-staked" is not a good way to do this especially because it
-- makes assumptions about where things should go and where genesis template files should be.
-- See all of the ad hoc file creation/renaming/dir creation etc below.
H.failMessage GHC.callStack "Specifying node configuration files per node not supported yet."
Copy link
Contributor

Choose a reason for hiding this comment

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

We need to note that we want to support configuration files per node. However it's not urgent to do this now.

@@ -67,7 +66,7 @@ instance Default CardanoTestnetCliOptions where
data CardanoTestnetOptions = CardanoTestnetOptions
{ -- | List of node options. Each option will result in a single node being
-- created.
cardanoNodes :: [TestnetNodeOptions]
cardanoNodes :: TestnetNodeOptions
Copy link
Contributor

Choose a reason for hiding this comment

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

The haddock should be updated

cardanoNumRelays CardanoTestnetOptions{cardanoNodes} =
NumRelays . length $ filter isRelayNodeOptions cardanoNodes
cardanoNumRelays CardanoTestnetOptions{cardanoNodes=_} =
undefined
Copy link
Contributor

Choose a reason for hiding this comment

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

?

@@ -193,16 +197,15 @@ getDefaultShelleyGenesis asbe maxSupply opts = do
cardanoTestnet :: ()
=> HasCallStack
=> CardanoTestnetOptions -- ^ The options to use
-> Conf
-> UserNodeConfig -- ^ The node configuration file to use. If omitted it's generated.
Copy link
Contributor

@Jimbo4350 Jimbo4350 Feb 18, 2025

Choose a reason for hiding this comment

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

This is an indication that TestnetNodeOptions ought to be renamed to TestnetNodeConfiguration.
A type like the following would be more indicative:

data TestnetNodeConfiguration
  = UserSpecifiedConfiguration FilePath
  | DefaultConfiguration [AutomaticNodeOption]

However what we really want is:

data TestnetNodeConfiguration
  = UserSpecifiedConfiguration FilePath
  | DefaultSpoConfiguration [String]
  | DefaultRelayConfiguration [String]

This gives users the most flexibility in that they can spin up a testnet with a mixture of nodes. Haddocks are desperately needed to indicate that [String] types are command line executable modifiers.

smelc added a commit that referenced this pull request Feb 19, 2025
… node configuration file (it was unused)

This will be done differently in
#6103
@smelc smelc force-pushed the smelc/testnet-pass-config-files branch 5 times, most recently from a9301e7 to 12c67b4 Compare February 21, 2025 15:44
@smelc smelc force-pushed the smelc/testnet-pass-config-files branch from 12c67b4 to b26b198 Compare February 26, 2025 16:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[FEATURE] - cardano-testnet: Use flags to pass genesis and configuration files
2 participants