Skip to content

Commit

Permalink
Factor away some complexity of withBFTNode
Browse files Browse the repository at this point in the history
Also left a FIXME about the wrong promises made by the function name and
its arguments.
  • Loading branch information
ch1bo committed Jul 8, 2022
1 parent b1cf9a6 commit fa5d3de
Showing 1 changed file with 26 additions and 23 deletions.
49 changes: 26 additions & 23 deletions hydra-cluster/src/CardanoNode.hs
Original file line number Diff line number Diff line change
Expand Up @@ -112,25 +112,28 @@ getCardanoNodeVersion =
readProcess "cardano-node" ["--version"] ""

-- | Start a cardano-node in BFT mode using the config from config/ and
-- credentials from config/credentials/ using given 'nodeId'. NOTE: This means
-- that nodeId should only be 1,2 or 3 and that only the faucet receives
-- 'initialFunds'. Use 'seedFromFaucet' to distribute funds other wallets.
-- credentials from config/credentials/ using given 'nodeId'. Only the 'Faucet'
-- actor will receive "initialFunds". Use 'seedFromFaucet' to distribute funds
-- other wallets.
--
-- FIXME: This is actually not a BFT node and it also only supports nodeId == 1.
-- We should rename this function and also think about removing the `nodeId`
-- from `CardanoNodeConfig` as it is a lie.
withBFTNode ::
Tracer IO NodeLog ->
CardanoNodeConfig ->
(RunningNode -> IO ()) ->
IO ()
withBFTNode tracer cfg action = do
createDirectoryIfMissing False (stateDirectory cfg)
createDirectoryIfMissing False (stateDirectory cfg </> dirname (nodeId cfg))
createDirectoryIfMissing True (stateDirectory cfg </> dirname)

[dlgCert, signKey, vrfKey, kesKey, opCert] <-
forM
[ dlgCertFilename (nodeId cfg)
, signKeyFilename (nodeId cfg)
, vrfKeyFilename (nodeId cfg)
, kesKeyFilename (nodeId cfg)
, opCertFilename (nodeId cfg)
[ dlgCertFilename
, signKeyFilename
, vrfKeyFilename
, kesKeyFilename
, opCertFilename
]
(copyCredential (stateDirectory cfg))

Expand Down Expand Up @@ -166,19 +169,19 @@ withBFTNode tracer cfg action = do
traceWith tracer $ MsgSocketIsReady socket
action rn
where
dirname i =
"stake-pool-" <> show i

dlgCertFilename i =
dirname i </> "byron-delegation.cert"
signKeyFilename i =
dirname i </> "byron-delegate.key"
vrfKeyFilename i =
dirname i </> "vrf.skey"
kesKeyFilename i =
dirname i </> "kes.skey"
opCertFilename i =
dirname i </> "opcert.cert"
dirname =
"stake-pool-" <> show (nodeId cfg)

dlgCertFilename =
dirname </> "byron-delegation.cert"
signKeyFilename =
dirname </> "byron-delegate.key"
vrfKeyFilename =
dirname </> "vrf.skey"
kesKeyFilename =
dirname </> "kes.skey"
opCertFilename =
dirname </> "opcert.cert"

copyCredential parentDir file = do
bs <- readConfigFile ("credentials" </> file)
Expand Down

0 comments on commit fa5d3de

Please sign in to comment.