@@ -14,6 +14,7 @@ import Cardano.CLI.Type.Error.DebugCmdError
1414import Cardano.Crypto.Hash qualified as Crypto
1515
1616import Control.Monad
17+ import Data.Foldable (for_ )
1718import Data.Text qualified as Text
1819import Data.Yaml qualified as Yaml
1920import System.FilePath (takeDirectory , (</>) )
@@ -33,61 +34,39 @@ checkNodeGenesisConfiguration
3334 -- ^ The parsed node configuration file
3435 -> CIO e ()
3536checkNodeGenesisConfiguration configFile nodeConfig = do
36- let byronGenFile = adjustFilepath $ unFile $ ncByronGenesisFile nodeConfig
37- alonzoGenFile = adjustFilepath $ unFile $ ncAlonzoGenesisFile nodeConfig
38- shelleyGenFile = adjustFilepath $ unFile $ ncShelleyGenesisFile nodeConfig
39- conwayGenFile <- case ncConwayGenesisFile nodeConfig of
40- Nothing -> throwCliError $ DebugNodeConfigNoConwayFileCmdError configFilePath
41- Just conwayGenesisFile -> pure $ adjustFilepath $ unFile conwayGenesisFile
37+ let byronGenFile = adjustFilepath $ ncByronGenesisFile nodeConfig
38+ alonzoGenFile = adjustFilepath $ ncAlonzoGenesisFile nodeConfig
39+ shelleyGenFile = adjustFilepath $ ncShelleyGenesisFile nodeConfig
40+ conwayGenFile = adjustFilepath $ ncConwayGenesisFile nodeConfig
4241
4342 liftIO $ putStrLn $ " Checking byron genesis file: " <> byronGenFile
4443
45- let expectedByronHash = unGenesisHashByron $ ncByronGenesisHash nodeConfig
46- expectedAlonzoHash = Crypto. hashToTextAsHex $ unGenesisHashAlonzo $ ncAlonzoGenesisHash nodeConfig
47- expectedShelleyHash = Crypto. hashToTextAsHex $ unGenesisHashShelley $ ncShelleyGenesisHash nodeConfig
48- expectedConwayHash <- case ncConwayGenesisHash nodeConfig of
49- Nothing -> throwCliError $ DebugNodeConfigNoConwayHashCmdError configFilePath
50- Just conwayGenesisHash -> pure $ Crypto. hashToTextAsHex $ unGenesisHashConway conwayGenesisHash
44+ let mExpectedByronHash = unGenesisHashByron <$> ncByronGenesisHash nodeConfig
45+ mExpectedAlonzoHash = Crypto. hashToTextAsHex . unGenesisHashAlonzo <$> ncAlonzoGenesisHash nodeConfig
46+ mExpectedShelleyHash = Crypto. hashToTextAsHex . unGenesisHashShelley <$> ncShelleyGenesisHash nodeConfig
47+ mExpectedConwayHash = Crypto. hashToTextAsHex . unGenesisHashConway <$> ncConwayGenesisHash nodeConfig
5148
52- (_, Byron. GenesisHash byronHash) <-
53- fromExceptTCli $
54- Byron. readGenesisData byronGenFile
55- let actualByronHash = Text. pack $ show byronHash
49+ (_, Byron. GenesisHash byronHash) <- fromExceptTCli $ Byron. readGenesisData byronGenFile
50+ let actualByronHash = Text. show byronHash
5651 actualAlonzoHash <- Crypto. hashToTextAsHex <$> Read. readShelleyOnwardsGenesisAndHash alonzoGenFile
5752 actualShelleyHash <- Crypto. hashToTextAsHex <$> Read. readShelleyOnwardsGenesisAndHash shelleyGenFile
5853 actualConwayHash <- Crypto. hashToTextAsHex <$> Read. readShelleyOnwardsGenesisAndHash conwayGenFile
5954
60- when (actualByronHash /= expectedByronHash) $
61- throwCliError $
62- DebugNodeConfigWrongGenesisHashCmdError
63- configFilePath
64- byronGenFile
65- actualByronHash
66- expectedByronHash
67- when (actualAlonzoHash /= expectedAlonzoHash) $
68- throwCliError $
69- DebugNodeConfigWrongGenesisHashCmdError
70- configFilePath
71- alonzoGenFile
72- actualAlonzoHash
73- expectedAlonzoHash
74- when (actualShelleyHash /= expectedShelleyHash) $
75- throwCliError $
76- DebugNodeConfigWrongGenesisHashCmdError
77- configFilePath
78- shelleyGenFile
79- actualShelleyHash
80- expectedShelleyHash
81- when (actualConwayHash /= expectedConwayHash) $
82- throwCliError $
83- DebugNodeConfigWrongGenesisHashCmdError
84- configFilePath
85- conwayGenFile
86- actualConwayHash
87- expectedConwayHash
55+ -- check only hashes which were specified for the genesis
56+ for_
57+ [ (mExpectedByronHash, actualByronHash, byronGenFile)
58+ , (mExpectedShelleyHash, actualShelleyHash, shelleyGenFile)
59+ , (mExpectedAlonzoHash, actualAlonzoHash, alonzoGenFile)
60+ , (mExpectedConwayHash, actualConwayHash, conwayGenFile)
61+ ]
62+ $ \ (mExpected, actual, genFile) ->
63+ for_ mExpected $ \ expected ->
64+ when (actual /= expected) $
65+ throwCliError $
66+ DebugNodeConfigWrongGenesisHashCmdError configFilePath genFile actual expected
8867 where
8968 configFilePath = unFile configFile
9069 -- We make the genesis filepath relative to the node configuration file, like the node does:
9170 -- https://github.com/IntersectMBO/cardano-node/blob/9671e7b6a1b91f5a530722937949b86deafaad43/cardano-node/src/Cardano/Node/Configuration/POM.hs#L668
9271 -- Note that, if the genesis filepath is absolute, the node configuration file's directory is ignored (by property of </>)
93- adjustFilepath f = takeDirectory configFilePath </> f
72+ adjustFilepath ( File f) = takeDirectory configFilePath </> f
0 commit comments