Skip to content
Merged
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: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
8 changes: 6 additions & 2 deletions src/Kupo/App/Configuration.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
37 changes: 37 additions & 0 deletions test/Test/Kupo/App/ConfigurationSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ module Test.Kupo.App.ConfigurationSpec

import Kupo.Prelude

import Data.Aeson
( encodeFile
, object
, (.=)
)
import Kupo.App.Configuration
( parseNetworkParameters
)
Expand All @@ -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
Expand All @@ -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
Loading