Skip to content

Commit

Permalink
Merge #648
Browse files Browse the repository at this point in the history
648: Add default path for `GenesisFile` and make path relative to configuration yaml file r=Jimbo4350 a=Jimbo4350

Issue
-----------

- #611

- This PR **does not result** in breaking changes to upstream dependencies.

Checklist
---------
- [x] This PR contains all the work required to resolve the linked issue.

- [ ] The work contained has sufficient documentation to describe what it does and how to do it.

- [ ] The work has sufficient tests and/or testing.

- [x] I have committed clear and descriptive commits. Be considerate as somebody else will have to read these.

- [x] I have added the appropriate labels to this PR.


Co-authored-by: Jordan Millar <[email protected]>
  • Loading branch information
iohk-bors[bot] and Jimbo4350 authored Mar 19, 2020
2 parents 06aa37b + fccd44a commit 4498e81
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 16 deletions.
2 changes: 2 additions & 0 deletions cardano-config/cardano-config.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@ library
, cardano-shell
, cborg
, contra-tracer
, directory
, file-embed
, filepath
, generic-monoid
, iohk-monitoring
, lobemo-backend-aggregation
Expand Down
20 changes: 16 additions & 4 deletions cardano-config/src/Cardano/Config/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ 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
import Cardano.BM.Data.Tracer (TracingVerbosity (..))
Expand Down Expand Up @@ -161,7 +163,7 @@ instance FromJSON NodeConfiguration where
parseJSON = withObject "NodeConfiguration" $ \v -> do
nId <- v .:? "NodeId"
ptcl <- v .: "Protocol" .!= RealPBFT
genFile <- v .: "GenesisFile"
genFile <- v .: "GenesisFile" .!= "configuration/genesis/genesis.json"
numCoreNode <- v .:? "NumCoreNodes"
rNetworkMagic <- v .:? "RequiresNetworkMagic" .!= RequiresNoMagic
pbftSignatureThresh <- v .:? "PBftSignatureThreshold"
Expand Down Expand Up @@ -241,9 +243,19 @@ instance FromJSON YamlSocketPath where
parseJSON invalid = panic $ "Parsing of SocketPath failed due to type mismatch. "
<> "Encountered: " <> (T.pack $ show invalid)

parseNodeConfigurationFP :: FilePath -> IO NodeConfiguration
parseNodeConfigurationFP fp = decodeFileThrow fp

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.
parseNodeConfiguration :: NodeProtocolMode -> IO NodeConfiguration
parseNodeConfiguration npm =
case npm of
Expand Down
2 changes: 1 addition & 1 deletion cardano-node/app/chairman.hs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ main = withIOManager $ \iocp -> do
, caDelegationCertFp
} <- execParser opts

nc <- liftIO . parseNodeConfigurationFP $ unConfigPath caConfigYaml
nc <- liftIO $ parseNodeConfigurationFP caConfigYaml
frmPtclRes <- runExceptT $ fromProtocol
(ncNodeId nc)
(ncNumCoreNodes nc)
Expand Down
2 changes: 1 addition & 1 deletion cardano-node/src/Cardano/CLI/Ops.hs
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ getLocalTip
-> AssociateWithIOCP
-> IO ()
getLocalTip configFp mSockPath iocp = do
nc <- parseNodeConfigurationFP $ unConfigPath configFp
nc <- parseNodeConfigurationFP configFp
sockPath <- return $ chooseSocketPath (ncSocketPath nc) mSockPath

frmPtclRes <- runExceptT . firstExceptT ProtocolError
Expand Down
16 changes: 8 additions & 8 deletions cardano-node/src/Cardano/CLI/Run.hs
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ runCommand (ToVerification ptcl skFp (NewVerificationKeyFile vkFp)) = do
ensureNewFile TL.writeFile vkFp vKey

runCommand (IssueDelegationCertificate configFp epoch issuerSK delegateVK cert) = do
nc <- liftIO . parseNodeConfigurationFP $ unConfigPath configFp
nc <- liftIO $ parseNodeConfigurationFP configFp
vk <- readVerificationKey delegateVK
sk <- readSigningKey (ncProtocol nc) issuerSK
pmId <- readProtocolMagicId $ ncGenesisFile nc
Expand All @@ -271,14 +271,14 @@ runCommand (IssueDelegationCertificate configFp epoch issuerSK delegateVK cert)
ensureNewFileLBS (nFp cert) sCert

runCommand (CheckDelegation configFp cert issuerVF delegateVF) = do
nc <- liftIO . parseNodeConfigurationFP $ unConfigPath configFp
nc <- liftIO $ parseNodeConfigurationFP configFp
issuerVK <- readVerificationKey issuerVF
delegateVK <- readVerificationKey delegateVF
pmId <- readProtocolMagicId $ ncGenesisFile nc
checkByronGenesisDelegation cert pmId issuerVK delegateVK

runCommand (SubmitTx fp configFp mCliSockPath) = withIOManagerE $ \iocp -> do
nc <- liftIO . parseNodeConfigurationFP $ unConfigPath configFp
nc <- liftIO $ parseNodeConfigurationFP configFp
-- Default update value
let update = Update (ApplicationName "cardano-sl") 1 $ LastKnownBlockVersion 0 2 0
tx <- readByronTx fp
Expand All @@ -300,7 +300,7 @@ runCommand (SubmitTx fp configFp mCliSockPath) = withIOManagerE $ \iocp -> do
(ncProtocol nc)
tx
runCommand (SpendGenesisUTxO configFp (NewTxFile ctTx) ctKey genRichAddr outs) = do
nc <- liftIO . parseNodeConfigurationFP $ unConfigPath configFp
nc <- liftIO $ parseNodeConfigurationFP configFp
sk <- readSigningKey (ncProtocol nc) ctKey
-- Default update value
let update = Update (ApplicationName "cardano-sl") 1 $ LastKnownBlockVersion 0 2 0
Expand All @@ -323,7 +323,7 @@ runCommand (SpendGenesisUTxO configFp (NewTxFile ctTx) ctKey genRichAddr outs) =
ensureNewFileLBS ctTx $ toCborTxAux tx

runCommand (SpendUTxO configFp (NewTxFile ctTx) ctKey ins outs) = do
nc <- liftIO . parseNodeConfigurationFP $ unConfigPath configFp
nc <- liftIO $ parseNodeConfigurationFP configFp
sk <- readSigningKey (ncProtocol nc) ctKey
-- Default update value
let update = Update (ApplicationName "cardano-sl") 1 $ LastKnownBlockVersion 0 2 0
Expand All @@ -347,7 +347,7 @@ runCommand (SpendUTxO configFp (NewTxFile ctTx) ctKey ins outs) = do
ensureNewFileLBS ctTx $ toCborTxAux gTx

runCommand (GenerateTxs
logConfigFp
configFp
signingKey
delegCert
genFile
Expand All @@ -363,14 +363,14 @@ runCommand (GenerateTxs
sigKeysFiles) = withIOManagerE $ \iocp -> do
-- Default update value
let update = Update (ApplicationName "cardano-sl") 1 $ LastKnownBlockVersion 0 2 0
nc <- liftIO $ parseNodeConfigurationFP logConfigFp
nc <- liftIO . parseNodeConfigurationFP $ ConfigYamlFilePath configFp

-- Logging layer
(loggingLayer, _) <- firstExceptT (\(ConfigErrorFileNotFound fp) -> FileNotFoundError fp) $
createLoggingFeatureCLI
(pack $ showVersion version)
NoEnvironment
(Just logConfigFp)
(Just configFp)
(ncLogMetrics nc)

genHash <- getGenesisHashText genFile
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import Cardano.Config.Protocol
, fromProtocol
)
import Cardano.Config.Types
( ConfigError (..)
( ConfigError (..), ConfigYamlFilePath (..)
, CardanoEnvironment(..), LastKnownBlockVersion(..)
, Protocol, SigningKeyFile(..), Update(..)
, ncLogMetrics, ncReqNetworkMagic, ncProtocol
Expand Down Expand Up @@ -79,7 +79,7 @@ runCommand (GenerateTxs logConfigFp
withIOManagerE $ \iocp -> do
-- Default update value
let update = Update (ApplicationName "cardano-tx-generator") 1 $ LastKnownBlockVersion 0 2 0
nc <- liftIO $ parseNodeConfigurationFP logConfigFp
nc <- liftIO . parseNodeConfigurationFP $ ConfigYamlFilePath logConfigFp

-- Logging layer
(loggingLayer, _) <- firstExceptT (\(ConfigErrorFileNotFound fp) -> FileNotFoundError fp) $
Expand Down

0 comments on commit 4498e81

Please sign in to comment.