Skip to content

Commit

Permalink
Make genesis file relative to configuration yaml file fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Jimbo4350 committed Apr 2, 2020
1 parent 6317e84 commit fd59eb0
Show file tree
Hide file tree
Showing 8 changed files with 14 additions and 20 deletions.
20 changes: 7 additions & 13 deletions cardano-config/src/Cardano/Config/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ import qualified Data.IP as IP
import qualified Data.Text as T
import Data.Yaml (decodeFileThrow)
import Network.Socket (PortNumber)
import System.Directory (doesFileExist)
import System.FilePath ((</>), takeDirectory)

import qualified Cardano.Chain.Update as Update
Expand Down Expand Up @@ -163,7 +162,7 @@ instance FromJSON NodeConfiguration where
parseJSON = withObject "NodeConfiguration" $ \v -> do
nId <- v .:? "NodeId"
ptcl <- v .: "Protocol" .!= RealPBFT
genFile <- v .: "GenesisFile" .!= "configuration/genesis/genesis.json"
genFile <- v .: "GenesisFile" .!= "genesis/genesis.json"
numCoreNode <- v .:? "NumCoreNodes"
rNetworkMagic <- v .:? "RequiresNetworkMagic" .!= RequiresNoMagic
pbftSignatureThresh <- v .:? "PBftSignatureThreshold"
Expand Down Expand Up @@ -248,20 +247,15 @@ parseNodeConfigurationFP :: ConfigYamlFilePath -> IO NodeConfiguration
parseNodeConfigurationFP (ConfigYamlFilePath fp) = do
nc <- decodeFileThrow fp
let genFile = unGenesisFile $ ncGenesisFile nc
exists <- doesFileExist genFile
case exists of
-- Genesis file is an absolute path
True -> pure nc
-- Genesis file is a relative path (relative to configuration yaml filepath)
False -> do let d = takeDirectory fp
pure $ nc { ncGenesisFile = GenesisFile $ d </> genFile }

-- TODO: Make genesisfile relative to configuration file as above.
-- Make genesis file relative to configuration yaml filepath.
let d = takeDirectory fp
pure $ nc { ncGenesisFile = GenesisFile $ d </> genFile }

parseNodeConfiguration :: NodeProtocolMode -> IO NodeConfiguration
parseNodeConfiguration npm =
case npm of
MockProtocolMode (NodeMockCLI _ _ cy _) -> decodeFileThrow $ unConfigPath cy
RealProtocolMode (NodeCLI _ _ cy _) -> decodeFileThrow $ unConfigPath cy
MockProtocolMode (NodeMockCLI _ _ cy _) -> parseNodeConfigurationFP cy
RealProtocolMode (NodeCLI _ _ cy _) -> parseNodeConfigurationFP cy

-- TODO: we don't want ByronLegacy in Protocol. Let's wrap Protocol with another
-- sum type for cases where it's required.
Expand Down
2 changes: 1 addition & 1 deletion configuration/configuration-mainnet.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

##### Locations #####

GenesisFile: configuration/mainnet-genesis.json
GenesisFile: mainnet-genesis.json
SocketPath: db/node.socket

#TODO: These parameters cannot yet be used in the config file, only on the CLI:
Expand Down
2 changes: 1 addition & 1 deletion configuration/log-config-0.liveview.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ options:

NodeId:
Protocol: RealPBFT
GenesisFile: configuration/genesis/genesis.json
GenesisFile: genesis/genesis.json
NumCoreNodes: 1
RequiresNetworkMagic: RequiresMagic
PBftSignatureThreshold:
Expand Down
2 changes: 1 addition & 1 deletion configuration/log-config-0.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ options:

NodeId:
Protocol: RealPBFT
GenesisFile: configuration/genesis/genesis.json
GenesisFile: genesis/genesis.json
NumCoreNodes: 1
RequiresNetworkMagic: RequiresMagic
PBftSignatureThreshold:
Expand Down
2 changes: 1 addition & 1 deletion configuration/log-config-1.liveview.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ options:

NodeId:
Protocol: RealPBFT
GenesisFile: configuration/genesis/genesis.json
GenesisFile: genesis/genesis.json
NumCoreNodes: 1
RequiresNetworkMagic: RequiresMagic
PBftSignatureThreshold:
Expand Down
2 changes: 1 addition & 1 deletion configuration/log-config-1.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ options:

NodeId:
Protocol: RealPBFT
GenesisFile: configuration/genesis/genesis.json
GenesisFile: genesis/genesis.json
NumCoreNodes: 1
RequiresNetworkMagic: RequiresMagic
PBftSignatureThreshold:
Expand Down
2 changes: 1 addition & 1 deletion configuration/log-config-2.liveview.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ options:

NodeId:
Protocol: RealPBFT
GenesisFile: configuration/genesis/genesis.json
GenesisFile: genesis/genesis.json
NumCoreNodes: 1
RequiresNetworkMagic: RequiresMagic
PBftSignatureThreshold:
Expand Down
2 changes: 1 addition & 1 deletion configuration/log-config-2.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ options:

NodeId:
Protocol: RealPBFT
GenesisFile: configuration/genesis/genesis.json
GenesisFile: genesis/genesis.json
NumCoreNodes: 1
RequiresNetworkMagic: RequiresMagic
PBftSignatureThreshold:
Expand Down

0 comments on commit fd59eb0

Please sign in to comment.