Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cardano-cli/cardano-cli.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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, (</>))
Expand All @@ -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
19 changes: 0 additions & 19 deletions cardano-cli/src/Cardano/CLI/Type/Error/DebugCmdError.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand Down
Loading