diff --git a/cardano-cli/cardano-cli.cabal b/cardano-cli/cardano-cli.cabal index d2036dae26..df92b0a310 100644 --- a/cardano-cli/cardano-cli.cabal +++ b/cardano-cli/cardano-cli.cabal @@ -241,7 +241,7 @@ library binary, bytestring, canonical-json, - cardano-api ^>=10.20, + cardano-api ^>=10.21, cardano-binary, cardano-crypto, cardano-crypto-class ^>=2.2.3.2, diff --git a/cardano-cli/src/Cardano/CLI/EraIndependent/Debug/CheckNodeConfiguration/Run.hs b/cardano-cli/src/Cardano/CLI/EraIndependent/Debug/CheckNodeConfiguration/Run.hs index de0a986b2f..90804c62a0 100644 --- a/cardano-cli/src/Cardano/CLI/EraIndependent/Debug/CheckNodeConfiguration/Run.hs +++ b/cardano-cli/src/Cardano/CLI/EraIndependent/Debug/CheckNodeConfiguration/Run.hs @@ -14,6 +14,7 @@ import Cardano.CLI.Type.Error.DebugCmdError import Cardano.Crypto.Hash qualified as Crypto import Control.Monad +import Data.Foldable (for_) import Data.Text qualified as Text import Data.Yaml qualified as Yaml import System.FilePath (takeDirectory, ()) @@ -33,61 +34,39 @@ checkNodeGenesisConfiguration -- ^ The parsed node configuration file -> CIO e () 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 -> throwCliError $ DebugNodeConfigNoConwayFileCmdError configFilePath - Just conwayGenesisFile -> pure $ adjustFilepath $ unFile conwayGenesisFile + let byronGenFile = adjustFilepath $ ncByronGenesisFile nodeConfig + alonzoGenFile = adjustFilepath $ ncAlonzoGenesisFile nodeConfig + shelleyGenFile = adjustFilepath $ ncShelleyGenesisFile nodeConfig + conwayGenFile = adjustFilepath $ ncConwayGenesisFile nodeConfig 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 -> throwCliError $ DebugNodeConfigNoConwayHashCmdError configFilePath - Just conwayGenesisHash -> pure $ Crypto.hashToTextAsHex $ unGenesisHashConway conwayGenesisHash + let mExpectedByronHash = unGenesisHashByron <$> ncByronGenesisHash nodeConfig + mExpectedAlonzoHash = Crypto.hashToTextAsHex . unGenesisHashAlonzo <$> ncAlonzoGenesisHash nodeConfig + mExpectedShelleyHash = Crypto.hashToTextAsHex . unGenesisHashShelley <$> ncShelleyGenesisHash nodeConfig + mExpectedConwayHash = Crypto.hashToTextAsHex . unGenesisHashConway <$> ncConwayGenesisHash nodeConfig - (_, Byron.GenesisHash byronHash) <- - fromExceptTCli $ - Byron.readGenesisData byronGenFile - let actualByronHash = Text.pack $ show byronHash + (_, Byron.GenesisHash byronHash) <- fromExceptTCli $ Byron.readGenesisData byronGenFile + let actualByronHash = Text.show byronHash actualAlonzoHash <- Crypto.hashToTextAsHex <$> Read.readShelleyOnwardsGenesisAndHash alonzoGenFile actualShelleyHash <- Crypto.hashToTextAsHex <$> Read.readShelleyOnwardsGenesisAndHash shelleyGenFile actualConwayHash <- Crypto.hashToTextAsHex <$> Read.readShelleyOnwardsGenesisAndHash conwayGenFile - when (actualByronHash /= expectedByronHash) $ - throwCliError $ - DebugNodeConfigWrongGenesisHashCmdError - configFilePath - byronGenFile - actualByronHash - expectedByronHash - when (actualAlonzoHash /= expectedAlonzoHash) $ - throwCliError $ - DebugNodeConfigWrongGenesisHashCmdError - configFilePath - alonzoGenFile - actualAlonzoHash - expectedAlonzoHash - when (actualShelleyHash /= expectedShelleyHash) $ - throwCliError $ - DebugNodeConfigWrongGenesisHashCmdError - configFilePath - shelleyGenFile - actualShelleyHash - expectedShelleyHash - when (actualConwayHash /= expectedConwayHash) $ - throwCliError $ - DebugNodeConfigWrongGenesisHashCmdError - configFilePath - conwayGenFile - actualConwayHash - expectedConwayHash + -- check only hashes which were specified for the genesis + for_ + [ (mExpectedByronHash, actualByronHash, byronGenFile) + , (mExpectedShelleyHash, actualShelleyHash, shelleyGenFile) + , (mExpectedAlonzoHash, actualAlonzoHash, alonzoGenFile) + , (mExpectedConwayHash, actualConwayHash, conwayGenFile) + ] + $ \(mExpected, actual, genFile) -> + for_ mExpected $ \expected -> + when (actual /= expected) $ + throwCliError $ + DebugNodeConfigWrongGenesisHashCmdError configFilePath genFile actual expected 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 + adjustFilepath (File f) = takeDirectory configFilePath f diff --git a/cardano-cli/src/Cardano/CLI/Type/Error/DebugCmdError.hs b/cardano-cli/src/Cardano/CLI/Type/Error/DebugCmdError.hs index 6f466d24b3..e289fec585 100644 --- a/cardano-cli/src/Cardano/CLI/Type/Error/DebugCmdError.hs +++ b/cardano-cli/src/Cardano/CLI/Type/Error/DebugCmdError.hs @@ -30,15 +30,6 @@ data DebugCmdError -- ^ The actual hash (the hash found by hashing the genesis file) !Text -- ^ The expected hash (the hash mentioned in the configuration file) - | -- | @DebugNodeConfigNoConwayFileCmdError filepath@ represents a user error - -- that the genesis file for Conway in @filepath@ is not specified - DebugNodeConfigNoConwayFileCmdError - !FilePath - | -- | @DebugNodeConfigNoConwayHashCmdError filepath@ represents a user error - -- that the hash for the Conway genesis file in @filepath@ is not specified - DebugNodeConfigNoConwayHashCmdError - !FilePath - -- ^ The file path of the node configuration file | DebugTxCmdError !TxCmdError deriving Show @@ -50,16 +41,6 @@ instance Error DebugCmdError where <> pretty fp <> ": " <> pretty (Text.toLazyText $ build err) - DebugNodeConfigNoConwayFileCmdError fp -> - "Conway genesis file not specified in " - <> pretty fp - <> ". Please add a \"ConwayGenesisFile\" key to the file at " - <> pretty fp - DebugNodeConfigNoConwayHashCmdError fp -> - "Conway genesis hash not specified in " - <> pretty fp - <> ". Please add a \"ConwayGenesisHash\" key to the file at " - <> pretty fp DebugNodeConfigWrongGenesisHashCmdError nodeFp genesisFp actualHash expectedHash -> "Wrong genesis hash for " <> pretty genesisFp