-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #923 from IntersectMBO/smelc/check-node-config
Add check-node-configuration command
- Loading branch information
Showing
19 changed files
with
1,072 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
cardano-cli/src/Cardano/CLI/Commands/Debug/CheckNodeConfiguration.hs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{-# LANGUAGE DataKinds #-} | ||
|
||
module Cardano.CLI.Commands.Debug.CheckNodeConfiguration where | ||
|
||
import Cardano.Api | ||
|
||
-- | Argument for the 'debug check-node-configuration' command. | ||
newtype CheckNodeConfigCmdArgs = CheckNodeConfigCmdArgs (NodeConfigFile 'In) | ||
deriving Show |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
91 changes: 91 additions & 0 deletions
91
cardano-cli/src/Cardano/CLI/Run/Debug/CheckNodeConfiguration.hs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
{-# LANGUAGE DataKinds #-} | ||
{-# LANGUAGE ScopedTypeVariables #-} | ||
|
||
module Cardano.CLI.Run.Debug.CheckNodeConfiguration (runCheckNodeConfig) where | ||
|
||
import Cardano.Api | ||
import qualified Cardano.Api.Byron as Byron | ||
|
||
import Cardano.CLI.Commands.Debug.CheckNodeConfiguration | ||
import qualified Cardano.CLI.Read as Read | ||
import Cardano.CLI.Types.Errors.DebugCmdError | ||
import qualified Cardano.Crypto.Hash as Crypto | ||
|
||
import Control.Monad | ||
import qualified Data.Text as Text | ||
import qualified Data.Yaml as Yaml | ||
import System.FilePath (takeDirectory, (</>)) | ||
|
||
runCheckNodeConfig :: CheckNodeConfigCmdArgs -> ExceptT DebugCmdError IO () | ||
runCheckNodeConfig (CheckNodeConfigCmdArgs configFile) = do | ||
nodeConfig :: NodeConfig <- liftIO $ Yaml.decodeFileThrow configFilePath | ||
checkNodeGenesisConfiguration configFile nodeConfig | ||
liftIO $ putStrLn $ "Successfully checked node configuration file: " <> configFilePath | ||
where | ||
configFilePath = unFile configFile | ||
|
||
checkNodeGenesisConfiguration | ||
:: NodeConfigFile 'In | ||
-- ^ The node configuration file path. It's not read by this function, but used for producing error messages. | ||
-> NodeConfig | ||
-- ^ The parsed node configuration file | ||
-> ExceptT DebugCmdError IO () | ||
checkNodeGenesisConfiguration configFile nodeConfig = do | ||
let byronGenFile = adjustFilepath $ unFile $ ncByronGenesisFile nodeConfig | ||
alonzoGenFile = adjustFilepath $ unFile $ ncAlonzoGenesisFile nodeConfig | ||
shelleyGenFile = adjustFilepath $ unFile $ ncShelleyGenesisFile nodeConfig | ||
conwayGenFile <- case ncConwayGenesisFile nodeConfig of | ||
Nothing -> throwError $ DebugNodeConfigNoConwayFileCmdError configFilePath | ||
Just conwayGenesisFile -> pure $ adjustFilepath $ unFile conwayGenesisFile | ||
|
||
liftIO $ putStrLn $ "Checking byron genesis file: " <> byronGenFile | ||
|
||
let expectedByronHash = unGenesisHashByron $ ncByronGenesisHash nodeConfig | ||
expectedAlonzoHash = Crypto.hashToTextAsHex $ unGenesisHashAlonzo $ ncAlonzoGenesisHash nodeConfig | ||
expectedShelleyHash = Crypto.hashToTextAsHex $ unGenesisHashShelley $ ncShelleyGenesisHash nodeConfig | ||
expectedConwayHash <- case ncConwayGenesisHash nodeConfig of | ||
Nothing -> throwError $ DebugNodeConfigNoConwayHashCmdError configFilePath | ||
Just conwayGenesisHash -> pure $ Crypto.hashToTextAsHex $ unGenesisHashConway conwayGenesisHash | ||
|
||
(_, Byron.GenesisHash byronHash) <- | ||
firstExceptT (DebugNodeConfigGenesisDataCmdError byronGenFile) $ | ||
Byron.readGenesisData byronGenFile | ||
let actualByronHash = Text.pack $ show byronHash | ||
actualAlonzoHash <- Crypto.hashToTextAsHex <$> Read.readShelleyOnwardsGenesisAndHash alonzoGenFile | ||
actualShelleyHash <- Crypto.hashToTextAsHex <$> Read.readShelleyOnwardsGenesisAndHash shelleyGenFile | ||
actualConwayHash <- Crypto.hashToTextAsHex <$> Read.readShelleyOnwardsGenesisAndHash conwayGenFile | ||
|
||
when (actualByronHash /= expectedByronHash) $ | ||
throwError $ | ||
DebugNodeConfigWrongGenesisHashCmdError | ||
configFilePath | ||
byronGenFile | ||
actualByronHash | ||
expectedByronHash | ||
when (actualAlonzoHash /= expectedAlonzoHash) $ | ||
throwError $ | ||
DebugNodeConfigWrongGenesisHashCmdError | ||
configFilePath | ||
alonzoGenFile | ||
actualAlonzoHash | ||
expectedAlonzoHash | ||
when (actualShelleyHash /= expectedShelleyHash) $ | ||
throwError $ | ||
DebugNodeConfigWrongGenesisHashCmdError | ||
configFilePath | ||
shelleyGenFile | ||
actualShelleyHash | ||
expectedShelleyHash | ||
when (actualConwayHash /= expectedConwayHash) $ | ||
throwError $ | ||
DebugNodeConfigWrongGenesisHashCmdError | ||
configFilePath | ||
conwayGenFile | ||
actualConwayHash | ||
expectedConwayHash | ||
where | ||
configFilePath = unFile configFile | ||
-- We make the genesis filepath relative to the node configuration file, like the node does: | ||
-- https://github.com/IntersectMBO/cardano-node/blob/9671e7b6a1b91f5a530722937949b86deafaad43/cardano-node/src/Cardano/Node/Configuration/POM.hs#L668 | ||
-- Note that, if the genesis filepath is absolute, the node configuration file's directory is ignored (by property of </>) | ||
adjustFilepath f = takeDirectory configFilePath </> f |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
cardano-cli/test/cardano-cli-golden/files/golden/help/debug_check-node-configuration.cli
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
Usage: cardano-cli debug check-node-configuration --node-configuration-file FILEPATH | ||
|
||
Check hashes and paths of genesis files in the given node configuration file. | ||
|
||
Available options: | ||
--node-configuration-file FILEPATH | ||
Input filepath of the node configuration file. | ||
-h,--help Show this help text |
Oops, something went wrong.