From 06dea0d1ea6111487b646bc05194a9cacbb715e0 Mon Sep 17 00:00:00 2001 From: Jordan Millar Date: Tue, 26 Jul 2022 13:29:42 -0500 Subject: [PATCH 1/9] Introduce the --relay-specification-file option to the create-staked command. This will allow the specification of the pool relays for all of the created stake pools --- cardano-api/src/Cardano/Api/Shelley.hs | 2 +- .../src/Cardano/CLI/Shelley/Commands.hs | 15 ++- .../src/Cardano/CLI/Shelley/Parsers.hs | 12 ++- .../src/Cardano/CLI/Shelley/Run/Genesis.hs | 100 ++++++++++++------ 4 files changed, 92 insertions(+), 37 deletions(-) diff --git a/cardano-api/src/Cardano/Api/Shelley.hs b/cardano-api/src/Cardano/Api/Shelley.hs index 2ab1c9c4562..f167e71b345 100644 --- a/cardano-api/src/Cardano/Api/Shelley.hs +++ b/cardano-api/src/Cardano/Api/Shelley.hs @@ -235,8 +235,8 @@ import Cardano.Api.Address import Cardano.Api.Block import Cardano.Api.Certificate import Cardano.Api.Eras -import Cardano.Api.IPC import Cardano.Api.InMode +import Cardano.Api.IPC import Cardano.Api.KeysByron import Cardano.Api.KeysPraos import Cardano.Api.KeysShelley diff --git a/cardano-cli/src/Cardano/CLI/Shelley/Commands.hs b/cardano-cli/src/Cardano/CLI/Shelley/Commands.hs index da0e428f0f7..50272e1b894 100644 --- a/cardano-cli/src/Cardano/CLI/Shelley/Commands.hs +++ b/cardano-cli/src/Cardano/CLI/Shelley/Commands.hs @@ -429,7 +429,20 @@ renderTextViewCmd (TextViewInfo _ _) = "text-view decode-cbor" data GenesisCmd = GenesisCreate GenesisDir Word Word (Maybe SystemStart) (Maybe Lovelace) NetworkId | GenesisCreateCardano GenesisDir Word Word (Maybe SystemStart) (Maybe Lovelace) BlockCount Word Rational NetworkId FilePath FilePath FilePath (Maybe FilePath) - | GenesisCreateStaked GenesisDir Word Word Word Word (Maybe SystemStart) (Maybe Lovelace) Lovelace NetworkId Word Word Word + | GenesisCreateStaked + GenesisDir + Word + Word + Word + Word + (Maybe SystemStart) + (Maybe Lovelace) + Lovelace + NetworkId + Word + Word + Word + FilePath -- ^ Relay specification filepath | GenesisKeyGenGenesis VerificationKeyFile SigningKeyFile | GenesisKeyGenDelegate VerificationKeyFile SigningKeyFile OpCertCounterFile | GenesisKeyGenUTxO VerificationKeyFile SigningKeyFile diff --git a/cardano-cli/src/Cardano/CLI/Shelley/Parsers.hs b/cardano-cli/src/Cardano/CLI/Shelley/Parsers.hs index d92058e9458..8193c24efef 100644 --- a/cardano-cli/src/Cardano/CLI/Shelley/Parsers.hs +++ b/cardano-cli/src/Cardano/CLI/Shelley/Parsers.hs @@ -1232,6 +1232,7 @@ pGenesisCmd = <*> pBulkPoolCredFiles <*> pBulkPoolsPerFile <*> pStuffedUtxoCount + <*> pRelayJsonFp pGenesisHash :: Parser GenesisCmd pGenesisHash = @@ -1304,6 +1305,15 @@ pGenesisCmd = <> Opt.value 0 ) + pRelayJsonFp :: Parser FilePath + pRelayJsonFp = + Opt.strOption + ( Opt.long "relay-specification-file" + <> Opt.metavar "FILE" + <> Opt.help "JSON file specified the relays of each stake pool." + <> Opt.completer (Opt.bashCompleter "file") + ) + convertTime :: String -> UTCTime convertTime = parseTimeOrError False defaultTimeLocale (iso8601DateFormat $ Just "%H:%M:%SZ") @@ -2779,7 +2789,7 @@ eDNSName :: String -> Either String ByteString eDNSName str = -- We're using 'Shelley.textToDns' to validate the string. case Shelley.textToDns (toS str) of - Nothing -> Left "DNS name is more than 64 bytes" + Nothing -> Left $ "DNS name is more than 64 bytes: " <> str Just dnsName -> Right . Text.encodeUtf8 . Shelley.dnsToText $ dnsName pSingleHostAddress :: Parser StakePoolRelay diff --git a/cardano-cli/src/Cardano/CLI/Shelley/Run/Genesis.hs b/cardano-cli/src/Cardano/CLI/Shelley/Run/Genesis.hs index b7d639d3483..ec8b385a24c 100644 --- a/cardano-cli/src/Cardano/CLI/Shelley/Run/Genesis.hs +++ b/cardano-cli/src/Cardano/CLI/Shelley/Run/Genesis.hs @@ -23,7 +23,7 @@ module Cardano.CLI.Shelley.Run.Genesis ) where import Cardano.Prelude hiding (unlines) -import Prelude (error, id, unlines, zip3) +import Prelude (String, error, id, unlines, zip3) import Data.Aeson hiding (Key) import qualified Data.Aeson as Aeson @@ -92,12 +92,12 @@ import Cardano.CLI.Shelley.Run.StakeAddress (ShelleyStakeAddressCmdErr renderShelleyStakeAddressCmdError, runStakeAddressKeyGenToFile) import Cardano.CLI.Types -import Cardano.CLI.Byron.Delegation -import Cardano.CLI.Byron.Genesis as Byron -import qualified Cardano.CLI.Byron.Key as Byron import qualified Cardano.Chain.Common as Byron (KeyHash, mkKnownLovelace, rationalToLovelacePortion) import Cardano.Chain.Genesis (FakeAvvmOptions (..), TestnetBalanceOptions (..), gdProtocolParameters, gsDlgIssuersSecrets, gsPoorSecrets, gsRichSecrets) +import Cardano.CLI.Byron.Delegation +import Cardano.CLI.Byron.Genesis as Byron +import qualified Cardano.CLI.Byron.Key as Byron import qualified Cardano.Crypto.Signing as Byron import Cardano.Api.SerialiseTextEnvelope (textEnvelopeToJSON) @@ -115,8 +115,8 @@ import Data.ListMap (ListMap (..)) import qualified Cardano.CLI.IO.Lazy as Lazy -import System.Random (StdGen) import qualified System.Random as Random +import System.Random (StdGen) data ShelleyGenesisCmdError = ShelleyGenesisCmdAesonDecodeError !FilePath !Text @@ -136,6 +136,8 @@ data ShelleyGenesisCmdError | ShelleyGenesisCmdStakeAddressCmdError !ShelleyStakeAddressCmdError | ShelleyGenesisCmdCostModelsError !FilePath | ShelleyGenesisCmdByronError !ByronGenesisError + | ShelleyGenesisStakePoolRelayFileError !FilePath !IOException + | ShelleyGenesisStakePoolRelayJsonDecodeError !FilePath !String deriving Show instance Error ShelleyGenesisCmdError where @@ -176,6 +178,12 @@ instance Error ShelleyGenesisCmdError where " Error: " <> Text.unpack e ShelleyGenesisCmdGenesisFileReadError e -> displayError e ShelleyGenesisCmdByronError e -> show e + ShelleyGenesisStakePoolRelayFileError fp e -> + "Error occurred while reading the stake pool relay specification file: " <> fp <> + " Error: " <> show e + ShelleyGenesisStakePoolRelayJsonDecodeError fp e -> + "Error occurred while decoding the stake pool relay specification file: " <> fp <> + " Error: " <> e runGenesisCmd :: GenesisCmd -> ExceptT ShelleyGenesisCmdError IO () runGenesisCmd (GenesisKeyGenGenesis vk sk) = runGenesisKeyGenGenesis vk sk @@ -187,7 +195,8 @@ runGenesisCmd (GenesisTxIn vk nw mOutFile) = runGenesisTxIn vk nw mOutFile runGenesisCmd (GenesisAddr vk nw mOutFile) = runGenesisAddr vk nw mOutFile runGenesisCmd (GenesisCreate gd gn un ms am nw) = runGenesisCreate gd gn un ms am nw runGenesisCmd (GenesisCreateCardano gd gn un ms am k slotLength sc nw bg sg ag mNodeCfg) = runGenesisCreateCardano gd gn un ms am k slotLength sc nw bg sg ag mNodeCfg -runGenesisCmd (GenesisCreateStaked gd gn gp gl un ms am ds nw bf bp su) = runGenesisCreateStaked gd gn gp gl un ms am ds nw bf bp su +runGenesisCmd (GenesisCreateStaked gd gn gp gl un ms am ds nw bf bp su relayJsonFp) = + runGenesisCreateStaked gd gn gp gl un ms am ds nw bf bp su relayJsonFp runGenesisCmd (GenesisHashFile gf) = runGenesisHashFile gf -- @@ -661,11 +670,13 @@ runGenesisCreateStaked -> Word -- ^ bulk credential files to write -> Word -- ^ pool credentials per bulk file -> Word -- ^ num stuffed UTxO entries + -> FilePath -- ^ Specified stake pool relays -> ExceptT ShelleyGenesisCmdError IO () runGenesisCreateStaked (GenesisDir rootdir) genNumGenesisKeys genNumUTxOKeys genNumPools genNumStDelegs mStart mNonDlgAmount stDlgAmount network - bulkPoolCredFiles bulkPoolsPerFile numStuffedUtxo = do + numBulkPoolCredFiles bulkPoolsPerFile numStuffedUtxo + sPoolRelayFp = do liftIO $ do createDirectoryIfMissing False rootdir createDirectoryIfMissing False gendir @@ -678,31 +689,39 @@ runGenesisCreateStaked (GenesisDir rootdir) alonzoGenesis <- readAlonzoGenesis (rootdir "genesis.alonzo.spec.json") forM_ [ 1 .. genNumGenesisKeys ] $ \index -> do - createGenesisKeys gendir index + createGenesisKeys gendir index createDelegateKeys deldir index forM_ [ 1 .. genNumUTxOKeys ] $ \index -> createUtxoKeys utxodir index - pools <- forM [ 1 .. genNumPools ] $ \index -> do + relaySpecificationJsonBs + <- handleIOExceptT (ShelleyGenesisStakePoolRelayFileError sPoolRelayFp) + $ LBS.readFile sPoolRelayFp + + specifiedStakePoolRelays + <- firstExceptT (ShelleyGenesisStakePoolRelayJsonDecodeError sPoolRelayFp) + . hoistEither $ Aeson.eitherDecode relaySpecificationJsonBs + + poolParams <- forM [ 1 .. genNumPools ] $ \index -> do createPoolCredentials pooldir index - buildPool network pooldir index + buildPoolParams network pooldir index specifiedStakePoolRelays - when (bulkPoolCredFiles * bulkPoolsPerFile > genNumPools) $ - left $ ShelleyGenesisCmdTooFewPoolsForBulkCreds genNumPools bulkPoolCredFiles bulkPoolsPerFile + when (numBulkPoolCredFiles * bulkPoolsPerFile > genNumPools) $ + left $ ShelleyGenesisCmdTooFewPoolsForBulkCreds genNumPools numBulkPoolCredFiles bulkPoolsPerFile -- We generate the bulk files for the last pool indices, -- so that all the non-bulk pools have stable indices at beginning: - let bulkOffset = fromIntegral $ genNumPools - bulkPoolCredFiles * bulkPoolsPerFile + let bulkOffset = fromIntegral $ genNumPools - numBulkPoolCredFiles * bulkPoolsPerFile bulkIndices :: [Word] = [ 1 + bulkOffset .. genNumPools ] bulkSlices :: [[Word]] = List.chunksOf (fromIntegral bulkPoolsPerFile) bulkIndices - forM_ (zip [ 1 .. bulkPoolCredFiles ] bulkSlices) $ + forM_ (zip [ 1 .. numBulkPoolCredFiles ] bulkSlices) $ uncurry (writeBulkPoolCredentials pooldir) let (delegsPerPool, delegsRemaining) = divMod genNumStDelegs genNumPools delegsForPool poolIx = if delegsRemaining /= 0 && poolIx == genNumPools then delegsPerPool else delegsPerPool + delegsRemaining - distribution = [pool | (pool, poolIx) <- zip pools [1 ..], _ <- [1 .. delegsForPool poolIx]] + distribution = [pool | (pool, poolIx) <- zip poolParams [1 ..], _ <- [1 .. delegsForPool poolIx]] g <- Random.getStdGen @@ -718,7 +737,7 @@ runGenesisCreateStaked (GenesisDir rootdir) stuffedUtxoAddrs <- liftIO $ Lazy.replicateM (fromIntegral numStuffedUtxo) genStuffedAddress let stake = second Ledger._poolId . mkDelegationMapEntry <$> delegations - stakePools = [ (Ledger._poolId poolParams, poolParams) | poolParams <- snd . mkDelegationMapEntry <$> delegations ] + stakePools = [ (Ledger._poolId poolParams', poolParams') | poolParams' <- snd . mkDelegationMapEntry <$> delegations ] delegAddrs = dInitialUtxoAddr <$> delegations !shelleyGenesis = updateCreateStakedOutputTemplate @@ -741,13 +760,13 @@ runGenesisCreateStaked (GenesisDir rootdir) ] ++ [ mconcat [ ", " - , textShow bulkPoolCredFiles, " bulk pool credential files, " + , textShow numBulkPoolCredFiles, " bulk pool credential files, " , textShow bulkPoolsPerFile, " pools per bulk credential file, indices starting from " , textShow bulkOffset, ", " , textShow $ length bulkIndices, " total pools in bulk nodes, each bulk node having this many entries: " , textShow $ length <$> bulkSlices ] - | bulkPoolCredFiles * bulkPoolsPerFile > 0 ] + | numBulkPoolCredFiles * bulkPoolsPerFile > 0 ] where adjustTemplate t = t { sgNetworkMagic = unNetworkMagic (toNetworkMagic network) } @@ -861,19 +880,24 @@ data Delegation = Delegation } deriving (Generic, NFData) -buildPool :: NetworkId -> FilePath -> Word -> ExceptT ShelleyGenesisCmdError IO (Ledger.PoolParams StandardCrypto) -buildPool nw dir index = do - StakePoolVerificationKey poolColdVK <- firstExceptT (ShelleyGenesisCmdPoolCmdError - . ShelleyPoolCmdReadFileError) - . newExceptT - $ readFileTextEnvelope (AsVerificationKey AsStakePoolKey) poolColdVKF - VrfVerificationKey poolVrfVK <- firstExceptT (ShelleyGenesisCmdNodeCmdError - . ShelleyNodeCmdReadFileError) - . newExceptT - $ readFileTextEnvelope (AsVerificationKey AsVrfKey) poolVrfVKF - rewardsSVK <- firstExceptT ShelleyGenesisCmdTextEnvReadFileError - . newExceptT - $ readFileTextEnvelope (AsVerificationKey AsStakeKey) poolRewardVKF +buildPoolParams + :: NetworkId + -> FilePath -- ^ File directory where the necessary pool credentials were created + -> Word + -> Map Word Ledger.StakePoolRelay -- ^ User submitted stake pool relay map + -> ExceptT ShelleyGenesisCmdError IO (Ledger.PoolParams StandardCrypto) +buildPoolParams nw dir index specifiedRelays = do + StakePoolVerificationKey poolColdVK + <- firstExceptT (ShelleyGenesisCmdPoolCmdError . ShelleyPoolCmdReadFileError) + . newExceptT $ readFileTextEnvelope (AsVerificationKey AsStakePoolKey) poolColdVKF + + VrfVerificationKey poolVrfVK + <- firstExceptT (ShelleyGenesisCmdNodeCmdError . ShelleyNodeCmdReadFileError) + . newExceptT $ readFileTextEnvelope (AsVerificationKey AsVrfKey) poolVrfVKF + rewardsSVK + <- firstExceptT ShelleyGenesisCmdTextEnvReadFileError + . newExceptT $ readFileTextEnvelope (AsVerificationKey AsStakeKey) poolRewardVKF + pure Ledger.PoolParams { Ledger._poolId = Ledger.hashKey poolColdVK , Ledger._poolVrf = Ledger.hashVerKeyVRF poolVrfVK @@ -883,10 +907,18 @@ buildPool nw dir index = do , Ledger._poolRAcnt = toShelleyStakeAddr $ makeStakeAddress nw $ StakeCredentialByKey (verificationKeyHash rewardsSVK) , Ledger._poolOwners = mempty - , Ledger._poolRelays = Seq.empty + , Ledger._poolRelays = lookupPoolRelay specifiedRelays , Ledger._poolMD = Ledger.SNothing } where + lookupPoolRelay + :: Map Word Ledger.StakePoolRelay -> Seq.StrictSeq Ledger.StakePoolRelay + lookupPoolRelay m = + case Map.lookup index m of + Just spRelay -> + Seq.singleton spRelay + Nothing -> mempty + strIndex = show index poolColdVKF = dir "cold" ++ strIndex ++ ".vkey" poolVrfVKF = dir "vrf" ++ strIndex ++ ".vkey" @@ -903,12 +935,12 @@ writeBulkPoolCredentials dir bulkIx poolIxs = do readPoolCreds :: Word -> ExceptT ShelleyGenesisCmdError IO (TextEnvelope, TextEnvelope, TextEnvelope) readPoolCreds ix = do - (,,) <$> readEnvelope poolCert + (,,) <$> readEnvelope poolOpCert <*> readEnvelope poolVrfSKF <*> readEnvelope poolKesSKF where strIndex = show ix - poolCert = dir "opcert" ++ strIndex ++ ".cert" + poolOpCert = dir "opcert" ++ strIndex ++ ".cert" poolVrfSKF = dir "vrf" ++ strIndex ++ ".skey" poolKesSKF = dir "kes" ++ strIndex ++ ".skey" readEnvelope :: FilePath -> ExceptT ShelleyGenesisCmdError IO TextEnvelope From 5cd9288fbf5a86bb15f53c882cfc589a4f2f411e Mon Sep 17 00:00:00 2001 From: Federico Mastellone Date: Mon, 8 Aug 2022 17:59:51 +0000 Subject: [PATCH 2/9] workbench: Extract node-services configuration Create a backend independent configuration for generator-service, node-services and tracer-service --- nix/workbench/default.nix | 2 +- nix/workbench/profiles/default.nix | 10 +- nix/workbench/profiles/generator-service.nix | 10 +- nix/workbench/profiles/node-services.nix | 12 +- nix/workbench/profiles/services-config.nix | 115 +++++++++++++++++++ nix/workbench/profiles/tracer-service.nix | 8 +- nix/workbench/supervisor.nix | 100 +--------------- 7 files changed, 137 insertions(+), 120 deletions(-) create mode 100644 nix/workbench/profiles/services-config.nix diff --git a/nix/workbench/default.nix b/nix/workbench/default.nix index b000aec00a5..46fc0e03e68 100644 --- a/nix/workbench/default.nix +++ b/nix/workbench/default.nix @@ -86,8 +86,8 @@ let { inherit pkgs runWorkbenchJqOnly runJq workbench - backend profileName; + inherit (backend) services-config; }; value = genAttrs profile-names mkProfile; diff --git a/nix/workbench/profiles/default.nix b/nix/workbench/profiles/default.nix index 315468879c0..a74aa8dd1af 100644 --- a/nix/workbench/profiles/default.nix +++ b/nix/workbench/profiles/default.nix @@ -1,8 +1,8 @@ { pkgs, cardanoLib , runCommand, runWorkbenchJqOnly, runJq, workbench, writeText -## The backend is an attrset of AWS/supervisord-specific methods and parameters. -, backend +## An attrset of specific methods and parameters. +, services-config , profileName }: @@ -33,19 +33,19 @@ let inherit (pkgs.callPackage ./node-services.nix - { inherit runJq backend profile; + { inherit runJq services-config profile; baseNodeConfig = cardanoLib.environments.testnet.nodeConfig; }) node-services; inherit (pkgs.callPackage ./generator-service.nix - { inherit runJq backend profile; }) + { inherit runJq services-config profile;}) generator-service; inherit (pkgs.callPackage ./tracer-service.nix - { inherit runJq backend profile; }) + { inherit runJq services-config profile;}) tracer-service; }; diff --git a/nix/workbench/profiles/generator-service.nix b/nix/workbench/profiles/generator-service.nix index 890c833fd9f..dc2afe48ebd 100644 --- a/nix/workbench/profiles/generator-service.nix +++ b/nix/workbench/profiles/generator-service.nix @@ -1,8 +1,8 @@ { pkgs , runJq -## The backend is an attrset of AWS/supervisord-specific methods and parameters. -, backend +## An attrset of specific methods and parameters. +, services-config , profile }: @@ -26,14 +26,14 @@ let ShelleyGenesisFile ByronGenesisFile; }; in - backend.finaliseGeneratorService + services-config.finaliseGeneratorService { inherit (profile.value) era; targetNodes = __mapAttrs (name: { name, port, ...}@nodeSpec: { inherit port; - ip = let ip = backend.nodePublicIP nodeSpec; # getPublicIp resources nodes name + ip = let ip = services-config.nodePublicIP nodeSpec; # getPublicIp resources nodes name in __trace "generator target: ${name}/${ip}:${toString port}" ip; }) nodeSpecs; @@ -45,7 +45,7 @@ let localNodeConf = removeAttrs exemplarNode.serviceConfig.value ["executable"]; ## The nodeConfig of the Tx generator itself. - nodeConfig = backend.finaliseGeneratorConfig generatorNodeConfigDefault; + nodeConfig = services-config.finaliseGeneratorConfig generatorNodeConfigDefault; dsmPassthrough = { # rtsOpts = ["-xc"]; diff --git a/nix/workbench/profiles/node-services.nix b/nix/workbench/profiles/node-services.nix index d218f0e6b83..6332c51ca97 100644 --- a/nix/workbench/profiles/node-services.nix +++ b/nix/workbench/profiles/node-services.nix @@ -1,8 +1,8 @@ { pkgs , runJq -## The backend is an attrset of AWS/supervisord-specific methods and parameters. -, backend +## An attrset of specific methods and parameters. +, services-config ## The cardano-node config used as baseline: , baseNodeConfig @@ -133,7 +133,7 @@ let }.${profile.value.era}; }; in - backend.finaliseNodeService profile.value nodeSpec + services-config.finaliseNodeService profile.value nodeSpec { inherit port; @@ -145,7 +145,7 @@ let nodeConfig = nodeConfigBits.tracing-transform.${profile.value.node.tracing_backend} (recursiveUpdate - (backend.finaliseNodeConfig nodeSpec + (services-config.finaliseNodeConfig nodeSpec (recursiveUpdate (recursiveUpdate nodeConfigBits.base @@ -169,7 +169,7 @@ let else []; shutBlockArgs = mayKindArgs shutdownBlock nodeSpec.kind "--shutdown-on-block-synced"; shutSlotArgs = mayKindArgs shutdownSlot nodeSpec.kind "--shutdown-on-slot-synced"; - in backend.finaliseNodeArgs profile nodeSpec + in services-config.finaliseNodeArgs profile nodeSpec (if shutBlockArgs != [] then shutBlockArgs else shutSlotArgs); @@ -242,7 +242,7 @@ let }; topology = rec { - JSON = backend.topologyForNodeSpec { inherit profile nodeSpec; }; + JSON = services-config.topologyForNodeSpec { inherit profile nodeSpec; }; value = __fromJSON (__readFile JSON); }; diff --git a/nix/workbench/profiles/services-config.nix b/nix/workbench/profiles/services-config.nix new file mode 100644 index 00000000000..13bf26c6df6 --- /dev/null +++ b/nix/workbench/profiles/services-config.nix @@ -0,0 +1,115 @@ +{ lib +, workbench +## +, basePort ? 30000 +, stateDir ? "run/current" +, useCabalRun ? false +, enableEKG ? true +}: +with lib; +{ + ## Generic Nix bits: + topologyForNodeSpec = + { profile, nodeSpec }: + let inherit (nodeSpec) name i; in + workbench.runWorkbench + "topology-${name}.json" + "topology projection-for local-${nodeSpec.kind} ${toString i} ${profile.name} ${profile.topology.files} ${toString basePort}"; + + nodePublicIP = + { i, name, ... }@nodeSpec: + "127.0.0.1"; + + finaliseNodeService = + let time_fmtstr = + "{ " + escape [''"''] (concatStringsSep ''\n, '' time_entries) + " }"; + time_entries = [ + ''"wall_clock_s": %e'' + ''"user_cpu_s": %U'' + ''"sys_cpu_s": %S'' + ''"avg_cpu_pct": "%P"'' + ''"rss_peak_kb": %M'' + ''"signals_received": %k'' + ''"ctxsw_involuntary": %c'' + ''"ctxsw_volunt_waits": %w'' + ''"pageflt_major": %F'' + ''"pageflt_minor": %R'' + ''"swaps": %W'' + ''"io_fs_reads": %I'' + ''"io_fs_writes": %O'' + ''"cmdline": "%C"'' + ''"exit_code": %x'' + ]; + in + profile: { name, i, isProducer, ... }: svc: recursiveUpdate svc + ({ + stateDir = stateDir + "/${name}"; + ## Everything is local in the supervisord setup: + socketPath = "node.socket"; + topology = "topology.json"; + nodeConfigFile = "config.json"; + } // optionalAttrs useCabalRun { + # Make the shell function take over. + executable = "cardano-node"; + # executable = ''time -f "${time_fmtstr}" -o kernel-resource-summary.json cabal run exe:cardano-node ''${WB_FLAGS_RTS} -- +RTS -sghc-rts-report.txt -RTS''; + } // optionalAttrs isProducer { + operationalCertificate = "../genesis/node-keys/node${toString i}.opcert"; + kesKey = "../genesis/node-keys/node-kes${toString i}.skey"; + vrfKey = "../genesis/node-keys/node-vrf${toString i}.skey"; + } // optionalAttrs profile.node.tracer { + tracerSocketPathConnect = "../tracer/tracer.socket"; + }); + + finaliseNodeConfig = + { port, ... }: cfg: recursiveUpdate cfg + ( + { + AlonzoGenesisFile = "../genesis/genesis.alonzo.json"; + ShelleyGenesisFile = "../genesis/genesis-shelley.json"; + ByronGenesisFile = "../genesis/byron/genesis.json"; + } + // optionalAttrs enableEKG + (let portShiftEkg = 100; + portShiftPrometheus = 200; + in { + hasEKG = port + portShiftEkg; + hasPrometheus = ["127.0.0.1" (port + portShiftPrometheus)]; + setupBackends = [ + "EKGViewBK" + ]; + }) + ); + + finaliseNodeArgs = + profile: nodeSpec: args: args; + + finaliseGeneratorService = + svc: recursiveUpdate svc + ({ + sigKey = "../genesis/utxo-keys/utxo1.skey"; + nodeConfigFile = "config.json"; + runScriptFile = "run-script.json"; + } // optionalAttrs useCabalRun { + executable = "cabal run exe:tx-generator --"; + }); + + finaliseGeneratorConfig = + cfg: recursiveUpdate cfg + ({ + AlonzoGenesisFile = "../genesis/genesis.alonzo.json"; + ShelleyGenesisFile = "../genesis/genesis-shelley.json"; + ByronGenesisFile = "../genesis/byron/genesis.json"; + } // optionalAttrs useCabalRun { + executable = "tx-generator"; + }); + + finaliseTracerService = + svc: recursiveUpdate svc + ({ + configFile = "config.json"; + logRoot = "."; + } // optionalAttrs useCabalRun { + executable = "cardano-tracer"; + }); + +} diff --git a/nix/workbench/profiles/tracer-service.nix b/nix/workbench/profiles/tracer-service.nix index 1a67b39ec35..36cfcf54b4c 100644 --- a/nix/workbench/profiles/tracer-service.nix +++ b/nix/workbench/profiles/tracer-service.nix @@ -1,8 +1,8 @@ { pkgs , runJq -## The backend is an attrset of AWS/supervisord-specific methods and parameters. -, backend +## An attrset of specific methods and parameters. +, services-config , profile }: @@ -20,14 +20,14 @@ let nodeSpecs: let in - backend.finaliseTracerService + services-config.finaliseTracerService { ## In both the local and remote scenarios, it's most frequently convenient to act as an acceptor. acceptingSocket = "tracer.socket"; networkMagic = profile.value.genesis.network_magic; - ## logRoot = ## ..really depends on context -- available in backend.finaliseTracerService + ## logRoot = ## ..really depends on context -- available in services-config.finaliseTracerService dsmPassthrough = { # rtsOpts = ["-xc"]; diff --git a/nix/workbench/supervisor.nix b/nix/workbench/supervisor.nix index 4ba94a97c46..8e6f20f4e90 100644 --- a/nix/workbench/supervisor.nix +++ b/nix/workbench/supervisor.nix @@ -19,103 +19,8 @@ let backend = rec { name = "supervisor"; - ## Generic Nix bits: - topologyForNodeSpec = - { profile, nodeSpec }: - let inherit (nodeSpec) name i; in - workbench.runWorkbench - "topology-${name}.json" - "topology projection-for local-${nodeSpec.kind} ${toString i} ${profile.name} ${profile.topology.files} ${toString basePort}"; - nodePublicIP = - { i, name, ... }@nodeSpec: - "127.0.0.1"; - - finaliseNodeService = - let time_fmtstr = - "{ " + escape [''"''] (concatStringsSep ''\n, '' time_entries) + " }"; - time_entries = [ - ''"wall_clock_s": %e'' - ''"user_cpu_s": %U'' - ''"sys_cpu_s": %S'' - ''"avg_cpu_pct": "%P"'' - ''"rss_peak_kb": %M'' - ''"signals_received": %k'' - ''"ctxsw_involuntary": %c'' - ''"ctxsw_volunt_waits": %w'' - ''"pageflt_major": %F'' - ''"pageflt_minor": %R'' - ''"swaps": %W'' - ''"io_fs_reads": %I'' - ''"io_fs_writes": %O'' - ''"cmdline": "%C"'' - ''"exit_code": %x'' - ]; - in - profile: { name, i, isProducer, ... }: svc: recursiveUpdate svc - ({ - stateDir = stateDir + "/${name}"; - ## Everything is local in the supervisord setup: - socketPath = "node.socket"; - topology = "topology.json"; - nodeConfigFile = "config.json"; - } // optionalAttrs useCabalRun { - # Make the shell function take over. - executable = "cardano-node"; - # executable = ''time -f "${time_fmtstr}" -o kernel-resource-summary.json cabal run exe:cardano-node ''${WB_FLAGS_RTS} -- +RTS -sghc-rts-report.txt -RTS''; - } // optionalAttrs isProducer { - operationalCertificate = "../genesis/node-keys/node${toString i}.opcert"; - kesKey = "../genesis/node-keys/node-kes${toString i}.skey"; - vrfKey = "../genesis/node-keys/node-vrf${toString i}.skey"; - } // optionalAttrs profile.node.tracer { - tracerSocketPathConnect = "../tracer/tracer.socket"; - }); - - finaliseNodeConfig = - { port, ... }: cfg: recursiveUpdate cfg - ({ - AlonzoGenesisFile = "../genesis.alonzo.json"; - ShelleyGenesisFile = "../genesis-shelley.json"; - ByronGenesisFile = "../genesis/byron/genesis.json"; - } // optionalAttrs enableEKG { - hasEKG = port + supervisord.portShiftEkg; - hasPrometheus = [ "127.0.0.1" (port + supervisord.portShiftPrometheus) ]; - setupBackends = [ - "EKGViewBK" - ]; - }); - - finaliseNodeArgs = - profile: nodeSpec: args: args; - - finaliseGeneratorService = - svc: recursiveUpdate svc - ({ - sigKey = "../genesis/utxo-keys/utxo1.skey"; - nodeConfigFile = "config.json"; - runScriptFile = "run-script.json"; - } // optionalAttrs useCabalRun { - executable = "cabal run exe:tx-generator --"; - }); - - finaliseGeneratorConfig = - cfg: recursiveUpdate cfg - ({ - AlonzoGenesisFile = "../genesis.alonzo.json"; - ShelleyGenesisFile = "../genesis-shelley.json"; - ByronGenesisFile = "../genesis/byron/genesis.json"; - } // optionalAttrs useCabalRun { - executable = "tx-generator"; - }); - - finaliseTracerService = - svc: recursiveUpdate svc - ({ - configFile = "config.json"; - logRoot = "."; - } // optionalAttrs useCabalRun { - executable = "cardano-tracer"; - }); + services-config = import ./profiles/services-config.nix {inherit lib workbench basePort stateDir useCabalRun enableEKG;}; materialise-profile = { profileNix }: @@ -139,9 +44,6 @@ let inherit extraSupervisorConfig; - portShiftEkg = 100; - portShiftPrometheus = 200; - ## mkSupervisorConf :: Profile -> SupervisorConf mkSupervisorConf = profile: From 9cc61fe4805571d6c08ae3cb37afaefee8d0f165 Mon Sep 17 00:00:00 2001 From: Federico Mastellone Date: Wed, 27 Jul 2022 14:41:41 +0000 Subject: [PATCH 3/9] workbench: Remove unused code --- nix/workbench/default.nix | 17 +++++------------ nix/workbench/profile.nix | 6 +----- nix/workbench/profiles/default.nix | 2 +- nix/workbench/supervisor-conf.nix | 1 - nix/workbench/supervisor-run.nix | 6 ++---- nix/workbench/supervisor.nix | 17 ++--------------- 6 files changed, 11 insertions(+), 38 deletions(-) diff --git a/nix/workbench/default.nix b/nix/workbench/default.nix index 46fc0e03e68..9cec39727de 100644 --- a/nix/workbench/default.nix +++ b/nix/workbench/default.nix @@ -72,13 +72,7 @@ let all-profiles = ## The backend is an attrset of AWS/supervisord-specific methods and parameters. - { backend - - ## Environment arguments: - ## - either affect semantics on all backends equally, - ## - or have no semantic effect - , envArgs - }: + { backend }: rec { mkProfile = profileName: @@ -103,17 +97,16 @@ let profile-topology-genesis = import ./genesis.nix { inherit pkgs; }; with-profile = - { backend, envArgs, profileName }: + { backend, profileName }: let - ps = all-profiles { inherit backend envArgs; }; + ps = all-profiles { inherit backend; }; profileNix = ps.value."${profileName}" or (throw "No such profile: ${profileName}; Known profiles: ${toString (__attrNames ps.value)}"); profile = materialise-profile - { inherit profileNix workbench; - backendProfile = - backend.materialise-profile { inherit profileNix; }; + { inherit profileNix; + backendProfile = backend.materialise-profile { inherit profileNix; }; }; topology = profile-topology { inherit profileNix profile; }; diff --git a/nix/workbench/profile.nix b/nix/workbench/profile.nix index fd923f312ea..454433686e6 100644 --- a/nix/workbench/profile.nix +++ b/nix/workbench/profile.nix @@ -3,10 +3,9 @@ with lib; { profileNix , backendProfile ## Backend-specific results for forwarding -, workbench }: pkgs.runCommand "workbench-profile-output-${profileNix.name}" - { buildInputs = with pkgs; [ jq workbench ]; + { buildInputs = []; nodeServices = __toJSON (flip mapAttrs profileNix.node-services @@ -47,6 +46,3 @@ pkgs.runCommand "workbench-profile-output-${profileNix.name}" wb profile node-specs $out/profile.json > $out/node-specs.json '' -// { inherit (profileNix) name; - inherit workbench; - } diff --git a/nix/workbench/profiles/default.nix b/nix/workbench/profiles/default.nix index a74aa8dd1af..783f987ecd7 100644 --- a/nix/workbench/profiles/default.nix +++ b/nix/workbench/profiles/default.nix @@ -1,5 +1,5 @@ { pkgs, cardanoLib -, runCommand, runWorkbenchJqOnly, runJq, workbench, writeText +, runCommand, runWorkbenchJqOnly, runJq, workbench ## An attrset of specific methods and parameters. , services-config diff --git a/nix/workbench/supervisor-conf.nix b/nix/workbench/supervisor-conf.nix index aeadaba43e1..ff0e0618574 100644 --- a/nix/workbench/supervisor-conf.nix +++ b/nix/workbench/supervisor-conf.nix @@ -3,7 +3,6 @@ , stateDir , basePort , node-services -, generator-service ## Last-moment overrides: , extraSupervisorConfig }: diff --git a/nix/workbench/supervisor-run.nix b/nix/workbench/supervisor-run.nix index 21782b8501c..e4438c2ad76 100644 --- a/nix/workbench/supervisor-run.nix +++ b/nix/workbench/supervisor-run.nix @@ -18,11 +18,9 @@ let inherit (supervisord-workbench) workbench backend cacheDir stateDir basePort; with-supervisord-profile = - { envArgsOverride ? {} }: + { envArgsOverride ? {} }: ## TODO: envArgsOverride is not used! workbench.with-profile - { inherit backend profileName; - envArgs = supervisord-workbench.env-args-base // envArgsOverride; - }; + { inherit backend profileName; }; inherit (with-supervisord-profile {}) diff --git a/nix/workbench/supervisor.nix b/nix/workbench/supervisor.nix index 8e6f20f4e90..83950d48304 100644 --- a/nix/workbench/supervisor.nix +++ b/nix/workbench/supervisor.nix @@ -30,25 +30,14 @@ let cp ${supervisord.mkSupervisorConf profileNix} $out/supervisor.conf ''; - ## IMPORTANT: keep in sync with envArgs in 'workbench/default.nix/generateProfiles/environment'. - env-args-base = - { - inherit (pkgs) cardanoLib; - inherit stateDir cacheDir basePort; - staggerPorts = true; - }; - ## Backend-specific Nix bits: supervisord = { - inherit - extraSupervisorConfig; - ## mkSupervisorConf :: Profile -> SupervisorConf mkSupervisorConf = profile: pkgs.callPackage ./supervisor-conf.nix - { inherit (profile) node-services generator-service; + { inherit (profile) node-services; inherit pkgs lib stateDir basePort @@ -59,9 +48,7 @@ let all-profiles = workbench.all-profiles - { inherit backend; - envArgs = backend.env-args-base; - }; + { inherit backend; }; in { inherit cacheDir stateDir basePort; From 0c02476a63f7113c9d42bf89e935553580af2847 Mon Sep 17 00:00:00 2001 From: Federico Mastellone Date: Wed, 27 Jul 2022 17:49:29 +0000 Subject: [PATCH 4/9] workbench: Make common code backend independent Cleanups and refactorings that are needed to add the Docker backend alongside the supervisord backend --- nix/custom-config.nix | 2 +- nix/pkgs.nix | 2 +- nix/workbench/default.nix | 5 +--- nix/workbench/profile.nix | 18 ++++++++------- nix/workbench/supervisor-conf.nix | 4 ++-- nix/workbench/supervisor.nix | 38 ++++++++++++------------------- 6 files changed, 30 insertions(+), 39 deletions(-) diff --git a/nix/custom-config.nix b/nix/custom-config.nix index 234547a54df..83d89dfa949 100644 --- a/nix/custom-config.nix +++ b/nix/custom-config.nix @@ -8,7 +8,7 @@ self: { basePort = 30000; enableEKG = true; workbenchDevMode = true; - extraSupervisorConfig = {}; + extraBackendConfig = {}; }; membench = { snapshotSlot = 37173650; diff --git a/nix/pkgs.nix b/nix/pkgs.nix index c0c4b598d76..5c850d09010 100644 --- a/nix/pkgs.nix +++ b/nix/pkgs.nix @@ -84,7 +84,7 @@ final: prev: with final; { supervisord-workbench-nix = { workbench ? pkgs.workbench, ... }@args: pkgs.callPackage ./workbench/supervisor.nix args; - all-profiles-json = (pkgs.callPackage ./workbench/supervisor.nix {}).all-profiles.JSON; + all-profiles-json = (workbench.all-profiles{ inherit (supervisord-workbench-nix) backend; }).JSON; # An instance of the workbench, specialised to the supervisord backend and a profile, # that can be used with nix-shell or lorri. diff --git a/nix/workbench/default.nix b/nix/workbench/default.nix index 9cec39727de..b4c9da803a5 100644 --- a/nix/workbench/default.nix +++ b/nix/workbench/default.nix @@ -104,10 +104,7 @@ let profileNix = ps.value."${profileName}" or (throw "No such profile: ${profileName}; Known profiles: ${toString (__attrNames ps.value)}"); - profile = materialise-profile - { inherit profileNix; - backendProfile = backend.materialise-profile { inherit profileNix; }; - }; + profile = materialise-profile { inherit profileNix backend; }; topology = profile-topology { inherit profileNix profile; }; diff --git a/nix/workbench/profile.nix b/nix/workbench/profile.nix index 454433686e6..f539836016c 100644 --- a/nix/workbench/profile.nix +++ b/nix/workbench/profile.nix @@ -2,10 +2,13 @@ with lib; { profileNix -, backendProfile ## Backend-specific results for forwarding +, backend ## Backend-specifics for forwarding }: pkgs.runCommand "workbench-profile-output-${profileNix.name}" { buildInputs = []; + profileConfigJsonPath = profileNix.JSON; + nodeSpecsJsonPath = profileNix.node-specs.JSON; + backendConfigPath = backend.materialise-profile { inherit profileNix; }; nodeServices = __toJSON (flip mapAttrs profileNix.node-services @@ -38,11 +41,10 @@ pkgs.runCommand "workbench-profile-output-${profileNix.name}" } '' mkdir $out - cp ${profileNix.JSON} $out/profile.json - cp ${backendProfile}/* $out - cp $nodeServicesPath $out/node-services.json - cp $generatorServicePath $out/generator-service.json - cp $tracerServicePath $out/tracer-service.json - - wb profile node-specs $out/profile.json > $out/node-specs.json + cp $profileConfigJsonPath $out/profile.json + cp $nodeSpecsJsonPath $out/node-specs.json + cp $backendConfigPath/* $out + cp $nodeServicesPath $out/node-services.json + cp $generatorServicePath $out/generator-service.json + cp $tracerServicePath $out/tracer-service.json '' diff --git a/nix/workbench/supervisor-conf.nix b/nix/workbench/supervisor-conf.nix index ff0e0618574..fa89d474b9d 100644 --- a/nix/workbench/supervisor-conf.nix +++ b/nix/workbench/supervisor-conf.nix @@ -4,7 +4,7 @@ , basePort , node-services ## Last-moment overrides: -, extraSupervisorConfig +, extraBackendConfig }: with lib; @@ -56,7 +56,7 @@ let }; } // - extraSupervisorConfig; + extraBackendConfig; ## ## nodeSvcSupervisorProgram :: NodeService -> SupervisorConfSection diff --git a/nix/workbench/supervisor.nix b/nix/workbench/supervisor.nix index 83950d48304..a151fefe9cb 100644 --- a/nix/workbench/supervisor.nix +++ b/nix/workbench/supervisor.nix @@ -8,7 +8,7 @@ in , workbench ## , cacheDir ? cacheDirDefault -, extraSupervisorConfig ? {} +, extraBackendConfig ? {} , useCabalRun ? false , enableEKG ? true ## @@ -24,35 +24,27 @@ let materialise-profile = { profileNix }: - pkgs.runCommand "workbench-profile-outputs-${profileNix.name}-supervisord" {} - '' - mkdir $out - cp ${supervisord.mkSupervisorConf profileNix} $out/supervisor.conf - ''; + pkgs.runCommand "workbench-profile-outputs-${profileNix.name}-${name}d" {} + '' + mkdir $out + cp ${mkBackendConf profileNix} $out/supervisor.conf + ''; ## Backend-specific Nix bits: - supervisord = - { - ## mkSupervisorConf :: Profile -> SupervisorConf - mkSupervisorConf = - profile: - pkgs.callPackage ./supervisor-conf.nix - { inherit (profile) node-services; - inherit - pkgs lib stateDir - basePort - extraSupervisorConfig; - }; + ## mkBackendConf :: Profile -> SupervisorConf/DockerConf + mkBackendConf = + profile: + pkgs.callPackage ./supervisor-conf.nix + { inherit (profile) node-services; + inherit + pkgs lib stateDir + basePort + extraBackendConfig; }; }; - - all-profiles = - workbench.all-profiles - { inherit backend; }; in { inherit cacheDir stateDir basePort; inherit workbench; inherit backend; - inherit all-profiles; } From ea70f0a23818cb43d17e7e3bf77a004817e192ce Mon Sep 17 00:00:00 2001 From: Federico Mastellone Date: Fri, 5 Aug 2022 15:03:13 +0000 Subject: [PATCH 5/9] workbench: Create backend awareness Create backend subfolder and make nix output names specify the backend used --- nix/pkgs.nix | 8 ++++---- nix/workbench/{profiles => backend}/services-config.nix | 0 nix/workbench/{ => backend}/supervisor-conf.nix | 0 nix/workbench/{ => backend}/supervisor-run.nix | 0 nix/workbench/{ => backend}/supervisor.nix | 4 ++-- nix/workbench/profile.nix | 2 +- 6 files changed, 7 insertions(+), 7 deletions(-) rename nix/workbench/{profiles => backend}/services-config.nix (100%) rename nix/workbench/{ => backend}/supervisor-conf.nix (100%) rename nix/workbench/{ => backend}/supervisor-run.nix (100%) rename nix/workbench/{ => backend}/supervisor.nix (82%) diff --git a/nix/pkgs.nix b/nix/pkgs.nix index 5c850d09010..76d5b443fff 100644 --- a/nix/pkgs.nix +++ b/nix/pkgs.nix @@ -80,9 +80,9 @@ final: prev: with final; { workbench = pkgs.callPackage ./workbench {}; supervisord-workbench-cabal = - { workbench ? pkgs.workbench, ... }@args: pkgs.callPackage ./workbench/supervisor.nix (args // { useCabalRun = true; }); + { workbench ? pkgs.workbench, ... }@args: pkgs.callPackage ./workbench/backend/supervisor.nix (args // { useCabalRun = true; }); supervisord-workbench-nix = - { workbench ? pkgs.workbench, ... }@args: pkgs.callPackage ./workbench/supervisor.nix args; + { workbench ? pkgs.workbench, ... }@args: pkgs.callPackage ./workbench/backend/supervisor.nix args; all-profiles-json = (workbench.all-profiles{ inherit (supervisord-workbench-nix) backend; }).JSON; @@ -95,10 +95,10 @@ final: prev: with final; { , useCabalRun ? false , workbenchDevMode ? false , profiled ? false - , supervisord-workbench ? pkgs.callPackage ./workbench/supervisor.nix { inherit useCabalRun; } + , supervisord-workbench ? pkgs.callPackage ./workbench/backend/supervisor.nix { inherit useCabalRun; } , cardano-node-rev ? null }: - pkgs.callPackage ./workbench/supervisor-run.nix + pkgs.callPackage ./workbench/backend/supervisor-run.nix { inherit batchName profileName supervisord-workbench cardano-node-rev; }; diff --git a/nix/workbench/profiles/services-config.nix b/nix/workbench/backend/services-config.nix similarity index 100% rename from nix/workbench/profiles/services-config.nix rename to nix/workbench/backend/services-config.nix diff --git a/nix/workbench/supervisor-conf.nix b/nix/workbench/backend/supervisor-conf.nix similarity index 100% rename from nix/workbench/supervisor-conf.nix rename to nix/workbench/backend/supervisor-conf.nix diff --git a/nix/workbench/supervisor-run.nix b/nix/workbench/backend/supervisor-run.nix similarity index 100% rename from nix/workbench/supervisor-run.nix rename to nix/workbench/backend/supervisor-run.nix diff --git a/nix/workbench/supervisor.nix b/nix/workbench/backend/supervisor.nix similarity index 82% rename from nix/workbench/supervisor.nix rename to nix/workbench/backend/supervisor.nix index a151fefe9cb..cbfd5797d07 100644 --- a/nix/workbench/supervisor.nix +++ b/nix/workbench/backend/supervisor.nix @@ -20,11 +20,11 @@ let rec { name = "supervisor"; - services-config = import ./profiles/services-config.nix {inherit lib workbench basePort stateDir useCabalRun enableEKG;}; + services-config = import ./services-config.nix {inherit lib workbench basePort stateDir useCabalRun enableEKG;}; materialise-profile = { profileNix }: - pkgs.runCommand "workbench-profile-outputs-${profileNix.name}-${name}d" {} + pkgs.runCommand "workbench-backend-output-${profileNix.name}-${name}d" {} '' mkdir $out cp ${mkBackendConf profileNix} $out/supervisor.conf diff --git a/nix/workbench/profile.nix b/nix/workbench/profile.nix index f539836016c..5e97129b509 100644 --- a/nix/workbench/profile.nix +++ b/nix/workbench/profile.nix @@ -4,7 +4,7 @@ with lib; { profileNix , backend ## Backend-specifics for forwarding }: -pkgs.runCommand "workbench-profile-output-${profileNix.name}" +pkgs.runCommand "workbench-profile-output-${profileNix.name}-${backend.name}d" { buildInputs = []; profileConfigJsonPath = profileNix.JSON; nodeSpecsJsonPath = profileNix.node-specs.JSON; From ac52974feb7b23146658ef33ec5c9e77795b50c5 Mon Sep 17 00:00:00 2001 From: Federico Mastellone Date: Fri, 5 Aug 2022 17:02:52 +0000 Subject: [PATCH 6/9] workbench: Indentation --- nix/workbench/backend/supervisor-run.nix | 179 +++++++++++------------ nix/workbench/profile.nix | 94 ++++++------ 2 files changed, 133 insertions(+), 140 deletions(-) diff --git a/nix/workbench/backend/supervisor-run.nix b/nix/workbench/backend/supervisor-run.nix index e4438c2ad76..110395832db 100644 --- a/nix/workbench/backend/supervisor-run.nix +++ b/nix/workbench/backend/supervisor-run.nix @@ -2,7 +2,6 @@ let batchNameDefault = "plain"; profileNameDefault = "default-bage"; in - { pkgs , cardanoNodePackages , supervisord-workbench @@ -13,7 +12,6 @@ in , workbenchDevMode ? false , cardano-node-rev ? "0000000000000000000000000000000000000000" }: - let inherit (supervisord-workbench) workbench backend cacheDir stateDir basePort; @@ -22,29 +20,26 @@ let workbench.with-profile { inherit backend profileName; }; - inherit - (with-supervisord-profile {}) - profileNix profile topology genesis; + inherit (with-supervisord-profile {}) profileNix profile topology genesis; in + let -let - - inherit (profile.value) era composition monetary; + inherit (profile.value) era composition monetary; - path = pkgs.lib.makeBinPath path'; - path' = - [ cardanoNodePackages.bech32 pkgs.jq pkgs.gnused pkgs.coreutils pkgs.bash pkgs.moreutils - ] - ## In dev mode, call the script directly: - ++ pkgs.lib.optionals (!workbenchDevMode) - [ workbench.workbench ]; + path = pkgs.lib.makeBinPath path'; + path' = + [ cardanoNodePackages.bech32 pkgs.jq pkgs.gnused pkgs.coreutils pkgs.bash pkgs.moreutils + ] + ## In dev mode, call the script directly: + ++ pkgs.lib.optionals (!workbenchDevMode) + [ workbench.workbench ]; - interactive-start = pkgs.writeScriptBin "start-cluster" '' - set -euo pipefail + interactive-start = pkgs.writeScriptBin "start-cluster" '' + set -euo pipefail - export PATH=$PATH:${path} + export PATH=$PATH:${path} - wb start \ + wb start \ --batch-name ${batchName} \ --profile-name ${profileName} \ --profile ${profile} \ @@ -52,58 +47,58 @@ let --base-port ${toString basePort} \ ''${WB_MODE_CABAL:+--cabal} \ "$@" - ''; + ''; - interactive-stop = pkgs.writeScriptBin "stop-cluster" '' - set -euo pipefail + interactive-stop = pkgs.writeScriptBin "stop-cluster" '' + set -euo pipefail - wb finish "$@" - ''; + wb finish "$@" + ''; - interactive-restart = pkgs.writeScriptBin "restart-cluster" '' - set -euo pipefail + interactive-restart = pkgs.writeScriptBin "restart-cluster" '' + set -euo pipefail - wb run restart "$@" && \ + wb run restart "$@" && \ echo "workbench: alternate command for this action: wb run restart" >&2 - ''; - - nodeBuildProduct = - name: - "report ${name}-log $out ${name}/stdout"; - - profile-run = - { trace ? false }: - let - inherit - (with-supervisord-profile - { envArgsOverride = { cacheDir = "./cache"; stateDir = "./"; }; }) - profileNix profile topology genesis; - - run = pkgs.runCommand "workbench-run-supervisord-${profileName}" - { requiredSystemFeatures = [ "benchmark" ]; - nativeBuildInputs = with cardanoNodePackages; with pkgs; [ - bash - bech32 - coreutils - gnused - jq - moreutils - nixWrapped - pstree - python3Packages.supervisor - workbench.workbench - zstd - ]; - } - '' - mkdir -p $out/{cache,nix-support} - cd $out - export HOME=$out - - export WB_BACKEND=supervisor - export CARDANO_NODE_SOCKET_PATH=$(wb backend get-node-socket-path ${stateDir} node-0) - - cmd=( + ''; + + nodeBuildProduct = + name: + "report ${name}-log $out ${name}/stdout"; + + profile-run = + { trace ? false }: + let + inherit + (with-supervisord-profile + { envArgsOverride = { cacheDir = "./cache"; stateDir = "./"; }; }) + profileNix profile topology genesis; + + run = pkgs.runCommand "workbench-run-supervisord-${profileName}" + { requiredSystemFeatures = [ "benchmark" ]; + nativeBuildInputs = with cardanoNodePackages; with pkgs; [ + bash + bech32 + coreutils + gnused + jq + moreutils + nixWrapped + pstree + python3Packages.supervisor + workbench.workbench + zstd + ]; + } + '' + mkdir -p $out/{cache,nix-support} + cd $out + export HOME=$out + + export WB_BACKEND=supervisor + export CARDANO_NODE_SOCKET_PATH=$(wb backend get-node-socket-path ${stateDir} node-0) + + cmd=( wb ${pkgs.lib.optionalString trace "--trace"} start @@ -116,35 +111,35 @@ let --node-source ${cardanoNodePackages.cardano-node.src.origSrc} --node-rev ${cardano-node-rev} --cache-dir ./cache - ) - echo "''${cmd[*]}" > $out/wb-start.sh + ) + echo "''${cmd[*]}" > $out/wb-start.sh - time "''${cmd[@]}" 2>&1 | + time "''${cmd[@]}" 2>&1 | tee $out/wb-start.log - ## Convert structure from $out/run/RUN-ID/* to $out/*: - rm -rf cache - rm -f run/{current,-current} - find $out -type s | xargs rm -f - tag=$(cd run; ls) - (cd run; tar c $tag --zstd) > archive.tar.zst - mv run/$tag/* . - rmdir run/$tag run - - cat > $out/nix-support/hydra-build-products < archive.tar.zst + mv run/$tag/* . + rmdir run/$tag run + + cat > $out/nix-support/hydra-build-products < Date: Sat, 6 Aug 2022 04:53:42 +0000 Subject: [PATCH 7/9] workbench: Inline nix module imports Remove one level of abstraction --- nix/workbench/default.nix | 13 +++-------- nix/workbench/genesis.nix | 48 ++++++++++++++++++-------------------- nix/workbench/profile.nix | 6 ++--- nix/workbench/topology.nix | 28 +++++++++++----------- 4 files changed, 41 insertions(+), 54 deletions(-) diff --git a/nix/workbench/default.nix b/nix/workbench/default.nix index b4c9da803a5..94ff043cb7e 100644 --- a/nix/workbench/default.nix +++ b/nix/workbench/default.nix @@ -89,13 +89,6 @@ let JSON = pkgs.writeText "all-profiles.json" (__toJSON (mapAttrs (_: x: x.value) value)); }; - ## materialise-profile :: ProfileNix -> BackendProfile -> Profile - materialise-profile = import ./profile.nix { inherit pkgs lib; }; - ## profile-topology :: ProfileNix -> Topology - profile-topology = import ./topology.nix { inherit pkgs; }; - ## profile-topology :: ProfileNix -> Topology -> Genesis - profile-topology-genesis = import ./genesis.nix { inherit pkgs; }; - with-profile = { backend, profileName }: let @@ -104,11 +97,11 @@ let profileNix = ps.value."${profileName}" or (throw "No such profile: ${profileName}; Known profiles: ${toString (__attrNames ps.value)}"); - profile = materialise-profile { inherit profileNix backend; }; + profile = import ./profile.nix { inherit pkgs lib profileNix backend; }; - topology = profile-topology { inherit profileNix profile; }; + topology = import ./topology.nix { inherit pkgs profileNix profile; }; - genesis = profile-topology-genesis { inherit profile; }; + genesis = import ./genesis.nix { inherit pkgs profile; }; in { inherit profileNix profile diff --git a/nix/workbench/genesis.nix b/nix/workbench/genesis.nix index 73e8a9e58a5..3c8e0b023cc 100644 --- a/nix/workbench/genesis.nix +++ b/nix/workbench/genesis.nix @@ -1,38 +1,36 @@ -{ pkgs }: +{ pkgs, profile }: + pkgs.runCommand "workbench-profile-genesis-cache-${profile.name}" + { requiredSystemFeatures = [ "benchmark" ]; + nativeBuildInputs = with pkgs.haskellPackages; with pkgs; + [ bash cardano-cli coreutils gnused jq moreutils workbench.workbench ]; + } + '' + mkdir $out -{ profile }: -pkgs.runCommand "workbench-profile-genesis-cache-${profile.name}" - { requiredSystemFeatures = [ "benchmark" ]; - nativeBuildInputs = with pkgs.haskellPackages; with pkgs; - [ bash cardano-cli coreutils gnused jq moreutils workbench.workbench ]; - } - '' - mkdir $out + cache_key_input=$(wb genesis profile-cache-key-input ${profile}/profile.json) + cache_key=$( wb genesis profile-cache-key ${profile}/profile.json) - cache_key_input=$(wb genesis profile-cache-key-input ${profile}/profile.json) - cache_key=$( wb genesis profile-cache-key ${profile}/profile.json) - - genesis_keepalive() { + genesis_keepalive() { while test ! -e $out/profile; do echo 'genesis_keepalive for Hydra'; sleep 10s; done - } - genesis_keepalive & - __genesis_keepalive_pid=$! - __genesis_keepalive_termination() { + } + genesis_keepalive & + __genesis_keepalive_pid=$! + __genesis_keepalive_termination() { kill $__genesis_keepalive_pid 2>/dev/null || true - } - trap __genesis_keepalive_termination EXIT + } + trap __genesis_keepalive_termination EXIT - args=( + args=( genesis actually-genesis ${profile}/profile.json ${profile}/node-specs.json $out "$cache_key_input" "$cache_key" - ) - time wb "''${args[@]}" + ) + time wb "''${args[@]}" - touch done + touch done - ln -s ${profile} $out/profile - '' + ln -s ${profile} $out/profile + '' diff --git a/nix/workbench/profile.nix b/nix/workbench/profile.nix index cea1edcb294..9359b1d0e1b 100644 --- a/nix/workbench/profile.nix +++ b/nix/workbench/profile.nix @@ -1,7 +1,5 @@ -{ pkgs, lib }: with lib; - { profileNix - , backend ## Backend-specifics for forwarding - }: +{ pkgs, lib, profileNix, backend }: + with lib; pkgs.runCommand "workbench-profile-output-${profileNix.name}-${backend.name}d" { buildInputs = []; profileConfigJsonPath = profileNix.JSON; diff --git a/nix/workbench/topology.nix b/nix/workbench/topology.nix index 0d9b5b629ff..ab2961c6055 100644 --- a/nix/workbench/topology.nix +++ b/nix/workbench/topology.nix @@ -1,19 +1,17 @@ -{ pkgs }: - -{ profileNix, profile }: -pkgs.runCommand "workbench-topology-${profileNix.name}" - { requiredSystemFeatures = [ "benchmark" ]; - nativeBuildInputs = with pkgs.haskellPackages; with pkgs; - [ bash cardano-cli coreutils gnused jq moreutils workbench.workbench ]; - } - '' - mkdir $out - args=( +{ pkgs, profileNix, profile }: + pkgs.runCommand "workbench-topology-${profileNix.name}" + { requiredSystemFeatures = [ "benchmark" ]; + nativeBuildInputs = with pkgs.haskellPackages; with pkgs; + [ bash cardano-cli coreutils gnused jq moreutils workbench.workbench ]; + } + '' + mkdir $out + args=( topology make ${profileNix.JSON} $out - ) - time wb ''${args[@]} + ) + time wb ''${args[@]} - ln -s ${profile} $out/profile - '' + ln -s ${profile} $out/profile + '' From 3364b3eaeca846c5345950ed3247ee8258a74bcc Mon Sep 17 00:00:00 2001 From: Kosyrev Serge Date: Wed, 10 Aug 2022 23:11:44 +0800 Subject: [PATCH 8/9] cli genesis create-staked: make the relay spec optional, and allow more than one relay per pool --- .../src/Cardano/CLI/Shelley/Commands.hs | 2 +- .../src/Cardano/CLI/Shelley/Parsers.hs | 2 +- .../src/Cardano/CLI/Shelley/Run/Genesis.hs | 25 +++++++++---------- 3 files changed, 14 insertions(+), 15 deletions(-) diff --git a/cardano-cli/src/Cardano/CLI/Shelley/Commands.hs b/cardano-cli/src/Cardano/CLI/Shelley/Commands.hs index 50272e1b894..cf6c5f2e350 100644 --- a/cardano-cli/src/Cardano/CLI/Shelley/Commands.hs +++ b/cardano-cli/src/Cardano/CLI/Shelley/Commands.hs @@ -442,7 +442,7 @@ data GenesisCmd Word Word Word - FilePath -- ^ Relay specification filepath + (Maybe FilePath) -- ^ Relay specification filepath | GenesisKeyGenGenesis VerificationKeyFile SigningKeyFile | GenesisKeyGenDelegate VerificationKeyFile SigningKeyFile OpCertCounterFile | GenesisKeyGenUTxO VerificationKeyFile SigningKeyFile diff --git a/cardano-cli/src/Cardano/CLI/Shelley/Parsers.hs b/cardano-cli/src/Cardano/CLI/Shelley/Parsers.hs index 8193c24efef..88af07fffa2 100644 --- a/cardano-cli/src/Cardano/CLI/Shelley/Parsers.hs +++ b/cardano-cli/src/Cardano/CLI/Shelley/Parsers.hs @@ -1232,7 +1232,7 @@ pGenesisCmd = <*> pBulkPoolCredFiles <*> pBulkPoolsPerFile <*> pStuffedUtxoCount - <*> pRelayJsonFp + <*> Opt.optional pRelayJsonFp pGenesisHash :: Parser GenesisCmd pGenesisHash = diff --git a/cardano-cli/src/Cardano/CLI/Shelley/Run/Genesis.hs b/cardano-cli/src/Cardano/CLI/Shelley/Run/Genesis.hs index ec8b385a24c..b4ab3623d17 100644 --- a/cardano-cli/src/Cardano/CLI/Shelley/Run/Genesis.hs +++ b/cardano-cli/src/Cardano/CLI/Shelley/Run/Genesis.hs @@ -670,7 +670,7 @@ runGenesisCreateStaked -> Word -- ^ bulk credential files to write -> Word -- ^ pool credentials per bulk file -> Word -- ^ num stuffed UTxO entries - -> FilePath -- ^ Specified stake pool relays + -> Maybe FilePath -- ^ Specified stake pool relays -> ExceptT ShelleyGenesisCmdError IO () runGenesisCreateStaked (GenesisDir rootdir) genNumGenesisKeys genNumUTxOKeys genNumPools genNumStDelegs @@ -695,17 +695,17 @@ runGenesisCreateStaked (GenesisDir rootdir) forM_ [ 1 .. genNumUTxOKeys ] $ \index -> createUtxoKeys utxodir index - relaySpecificationJsonBs - <- handleIOExceptT (ShelleyGenesisStakePoolRelayFileError sPoolRelayFp) - $ LBS.readFile sPoolRelayFp - - specifiedStakePoolRelays - <- firstExceptT (ShelleyGenesisStakePoolRelayJsonDecodeError sPoolRelayFp) - . hoistEither $ Aeson.eitherDecode relaySpecificationJsonBs + mayStakePoolRelays + <- forM sPoolRelayFp $ + \fp -> do + relaySpecJsonBs <- + handleIOExceptT (ShelleyGenesisStakePoolRelayFileError fp) (LBS.readFile fp) + firstExceptT (ShelleyGenesisStakePoolRelayJsonDecodeError fp) + . hoistEither $ Aeson.eitherDecode relaySpecJsonBs poolParams <- forM [ 1 .. genNumPools ] $ \index -> do createPoolCredentials pooldir index - buildPoolParams network pooldir index specifiedStakePoolRelays + buildPoolParams network pooldir index (fromMaybe mempty mayStakePoolRelays) when (numBulkPoolCredFiles * bulkPoolsPerFile > genNumPools) $ left $ ShelleyGenesisCmdTooFewPoolsForBulkCreds genNumPools numBulkPoolCredFiles bulkPoolsPerFile @@ -884,7 +884,7 @@ buildPoolParams :: NetworkId -> FilePath -- ^ File directory where the necessary pool credentials were created -> Word - -> Map Word Ledger.StakePoolRelay -- ^ User submitted stake pool relay map + -> Map Word [Ledger.StakePoolRelay] -- ^ User submitted stake pool relay map -> ExceptT ShelleyGenesisCmdError IO (Ledger.PoolParams StandardCrypto) buildPoolParams nw dir index specifiedRelays = do StakePoolVerificationKey poolColdVK @@ -912,11 +912,10 @@ buildPoolParams nw dir index specifiedRelays = do } where lookupPoolRelay - :: Map Word Ledger.StakePoolRelay -> Seq.StrictSeq Ledger.StakePoolRelay + :: Map Word [Ledger.StakePoolRelay] -> Seq.StrictSeq Ledger.StakePoolRelay lookupPoolRelay m = case Map.lookup index m of - Just spRelay -> - Seq.singleton spRelay + Just spRelays -> Seq.fromList spRelays Nothing -> mempty strIndex = show index From 6c5b9ae619dc7a61486b83d7d703b0a8f60ea2ed Mon Sep 17 00:00:00 2001 From: Kosyrev Serge Date: Wed, 10 Aug 2022 23:47:07 +0800 Subject: [PATCH 9/9] workbench: generate ledger peers --- nix/workbench/genesis.sh | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/nix/workbench/genesis.sh b/nix/workbench/genesis.sh index 8dca7cef190..78c750045de 100644 --- a/nix/workbench/genesis.sh +++ b/nix/workbench/genesis.sh @@ -190,7 +190,24 @@ case "$op" in # }' # -o "$dir"/cardano-cli-execution-stats.json # ) + + jq ' + to_entries + | map + ({ key: (.value.i | tostring) + , value: + [{ "single host name": + { dnsName: .key + , port: .port + } + } + ] + }) + | from_entries + ' "$node_specs" > "$dir"/pool-relays.json + params=(--genesis-dir "$dir" + --relay-specification-file "$dir/pool-relays.json" $(jq '.cli_args.createFinalBulk | join(" ")' "$profile_json" --raw-output) ) time cardano-cli genesis create-staked "${params[@]}"