From b4445d5c672c620cd3e0cbc16dabdc211346708d Mon Sep 17 00:00:00 2001 From: Mateusz Galazyn Date: Mon, 16 Nov 2026 14:57:27 +0100 Subject: [PATCH] Accept the cardano-config layout of the node configuration Kupo read ByronGenesisFile and ShelleyGenesisFile only at the top level of --node-config. The configuration that cardano-node 11.2 and cardano-testnet write nests them under Configuration and then Protocol, so Kupo exited at start-up with "Failed to configure network parameters". Read the keys under Configuration and Protocol when the file has a Configuration object, and at the top level otherwise. Both layouts name the genesis files relative to the configuration file. Fixes #22 --- CHANGELOG.md | 2 ++ src/Kupo/App/Configuration.hs | 8 ++++-- test/Test/Kupo/App/ConfigurationSpec.hs | 37 +++++++++++++++++++++++++ 3 files changed, 45 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 28d7664b..b0662c32 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,8 @@ - The new `kupo db migrate --workdir DIRECTORY` command applies the pending migrations and data repairs. Stop Kupo first. Some repairs need `--confirm-complete-index`, which confirms that the index matches `*` and was synchronised from origin. - Kupo, read-only replicas, `kupo copy` and `kupo db migrate` refuse a database that a newer version of Kupo has migrated. +- Kupo now accepts both layouts of the node configuration given to `--node-config`: the flat layout of the public networks, and the layout with a `Configuration` section that cardano-node 11.2 and `cardano-testnet` write. It no longer exits at start-up with `Failed to configure network parameters` for the second layout (see [#22](https://github.com/IntersectMBO/kupo/issues/22)). + #### Changed - Kupo now requires cardano-node 11.1 or later. It talks to the node over node-to-client version 23 only, so older nodes are no longer supported. diff --git a/src/Kupo/App/Configuration.hs b/src/Kupo/App/Configuration.hs index b2ba698b..148b8265 100644 --- a/src/Kupo/App/Configuration.hs +++ b/src/Kupo/App/Configuration.hs @@ -150,9 +150,13 @@ fetchNetworkParameters ws = do parseNetworkParameters :: FilePath -> IO NetworkParameters parseNetworkParameters configFile = runOrDie $ do config <- decodeYaml @Yaml.Value configFile + -- The cardano-config envelope nests the keys; the legacy layout is flat. + let genesisFile name = case config ^? key "Configuration" of + Just envelope -> envelope ^? key "Protocol" . key name . _String + Nothing -> config ^? key name . _String let genesisFiles = (,) - <$> config ^? key "ByronGenesisFile" . _String - <*> config ^? key "ShelleyGenesisFile" . _String + <$> genesisFile "ByronGenesisFile" + <*> genesisFile "ShelleyGenesisFile" case genesisFiles of Nothing -> throwE "missing or invalid 'ByronGenesisFile' and/or 'ShelleyGenesisFile' from Cardano's configuration" diff --git a/test/Test/Kupo/App/ConfigurationSpec.hs b/test/Test/Kupo/App/ConfigurationSpec.hs index e3cc2616..fc9d045f 100644 --- a/test/Test/Kupo/App/ConfigurationSpec.hs +++ b/test/Test/Kupo/App/ConfigurationSpec.hs @@ -12,6 +12,11 @@ module Test.Kupo.App.ConfigurationSpec import Kupo.Prelude +import Data.Aeson + ( encodeFile + , object + , (.=) + ) import Kupo.App.Configuration ( parseNetworkParameters ) @@ -21,6 +26,16 @@ import Kupo.Data.Configuration , NetworkParameters (..) , mkSystemStart ) +import System.Directory + ( copyFile + , createDirectoryIfMissing + ) +import System.FilePath + ( () + ) +import System.IO.Temp + ( withSystemTempDirectory + ) import Test.Hspec ( Spec , context @@ -37,3 +52,25 @@ spec = parallel $ do networkMagic params `shouldBe` NetworkMagic 764824073 systemStart params `shouldBe` mkSystemStart 1506203091 slotsPerEpoch params `shouldBe` EpochSlots 21600 + + specify "mainnet, nested under Configuration and Protocol" $ do + let genesis = "./config/network/mainnet/genesis" + withSystemTempDirectory "kupo-configuration" $ \dir -> do + createDirectoryIfMissing True (dir "genesis") + createDirectoryIfMissing True (dir "node") + copyFile (genesis "byron.json") (dir "genesis" "byron.json") + copyFile (genesis "shelley.json") (dir "genesis" "shelley.json") + let configFile = dir "node" "configuration.yaml" + encodeFile configFile $ object + [ "Version" .= (2 :: Int) + , "Configuration" .= object + [ "Protocol" .= object + [ "ByronGenesisFile" .= ("../genesis/byron.json" :: Text) + , "ShelleyGenesisFile" .= ("../genesis/shelley.json" :: Text) + ] + ] + ] + params <- parseNetworkParameters configFile + networkMagic params `shouldBe` NetworkMagic 764824073 + systemStart params `shouldBe` mkSystemStart 1506203091 + slotsPerEpoch params `shouldBe` EpochSlots 21600