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

Add check-node-configuration command #923

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open

Conversation

smelc
Copy link
Contributor

@smelc smelc commented Oct 4, 2024

Changelog

- description: |
    Add the `debug check--node-configuration --node-configuration-file node-config.json` command
    that reads `node-config.json` and checks that the hashes of genesis files are correct.

    It accepts the `--fix` flag to correct (or fill in) the hashes in place if they are wrong (or missing).
# 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
  # - refactoring    # QoL changes
  # - 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

How to trust this PR

Try it yourself:

TBD

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/check-node-config branch 5 times, most recently from c740c1f to 9a6f631 Compare October 7, 2024 09:26
@smelc smelc force-pushed the smelc/check-node-config branch 2 times, most recently from 66c8ef2 to 9d4dba7 Compare October 8, 2024 08:52
@smelc smelc marked this pull request as ready for review October 8, 2024 09:08
@smelc smelc mentioned this pull request Oct 8, 2024
3 tasks
@smelc smelc force-pushed the smelc/check-node-config branch 2 times, most recently from 4be047d to 212c3d2 Compare October 10, 2024 08:44
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. I think I'll leave the approval to @Jimbo4350

@smelc smelc force-pushed the smelc/check-node-config branch 4 times, most recently from d8c18e5 to 5b42105 Compare October 10, 2024 12:32
@smelc smelc marked this pull request as draft October 10, 2024 14:31
@smelc
Copy link
Contributor Author

smelc commented Oct 10, 2024

Putting back to draft while I change the code to use NodeConfig.

@smelc smelc force-pushed the smelc/check-node-config branch 2 times, most recently from f64d941 to 682dc9a Compare October 11, 2024 15:25
@smelc
Copy link
Contributor Author

smelc commented Oct 11, 2024

@Jimbo4350, @carbolymer> done that: #923 (comment)

However, the code still needs to use the vanilla Aeson.Value version of the node configuration, to write it back (when --fix is passed). We need that, because, as NodeConfig only covers a subset of the node's configuration file, we would only write back this subset when fixing the file.

Nevertheless, this version using NodeConfig for deserialization is way better than the initial one, because indeed we don't have to check the shape of what we read from disk.

@smelc smelc marked this pull request as ready for review October 11, 2024 15:33
@smelc smelc force-pushed the smelc/check-node-config branch 3 times, most recently from 3db92ac to 1e89e5d Compare October 14, 2024 09:40
cardano-cli/src/Cardano/CLI/Types/Errors/DebugCmdError.hs Outdated Show resolved Hide resolved
-> NodeConfig
-- ^ The parsed node configuration file
-> ExceptT DebugCmdError IO (Maybe Analysis)
mkAnalysis cEra@(AnyCardanoEra era) configFile nodeConfig = do
Copy link
Contributor

Choose a reason for hiding this comment

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

We're doing a validation of the node configuration file. Why not use https://hackage.haskell.org/package/validation?

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 don't depend on validation yet and I believe this simple use case does not justify adding an external dependency.

-- | Build an 'Analysis' value from the given node configuration file, for the given era.
-- Reads the genesis file path and hash from the node configuration file, if they exist.
mkAnalysis
:: AnyCardanoEra
Copy link
Contributor

Choose a reason for hiding this comment

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

Use the experimental api interface here. We don't care about previous eras.

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 parameter isn't about the era we support, it's about the era whose hash we want to validate. I updated the haddock to make this explicit, as this indeed is an usual use case for us.

Copy link
Contributor

@Jimbo4350 Jimbo4350 Oct 15, 2024

Choose a reason for hiding this comment

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

We only care about mainnet and the upcoming era and therefore the configuration files associated with those eras which include Byron, Shelley, Alonzo and Conway genesis files/hashes. I.e we check all for the presence of all of theses things in the Conway era. If another genesis file is added in an upcoming era then we would add that additional check for the upcoming era. Currently there are a bunch of irrelevant cases that return Nothing which we can totally exclude by not parameterizing on AnyCardanoEra.


-- | Get the data associated with the given role for the given era.
getData :: CardanoEra a -> Role r -> NodeConfig -> Maybe (DataKind r)
getData era role config =
Copy link
Contributor

Choose a reason for hiding this comment

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

Create standalone functions that retrieve the genesis files and hashes from the node configuration. Pattern matching on the eras exposed by the experimental and calling the relevant functions will simplify this code.

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 I wrote in #923 (comment), this code doesn't depend on the era, so using the experimental API here doesn't help.

@smelc smelc force-pushed the smelc/check-node-config branch 4 times, most recently from 7ed8319 to 78c0fe5 Compare October 15, 2024 10:12
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.

#923 (comment)

Also we need to come up with a better name than Analysis.

@smelc
Copy link
Contributor Author

smelc commented Oct 16, 2024

Also we need to come up with a better name than Analysis.

Renamed to CheckGenesisAnalysis, but please note that this name is not exported, so using a short name was fine IMO 🙂

@smelc smelc force-pushed the smelc/check-node-config branch 2 times, most recently from 27126cd to 637e846 Compare October 16, 2024 11:51
@smelc smelc requested a review from Jimbo4350 October 16, 2024 11:53
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.

Add check-node-configuration command
3 participants