Skip to content

Commit

Permalink
WIP: drop DNS dependency; base type for keepalive
Browse files Browse the repository at this point in the history
  • Loading branch information
mgmeier committed May 3, 2024
1 parent 4e128dd commit f57a06f
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 11 deletions.
5 changes: 3 additions & 2 deletions bench/tx-generator/src/Cardano/Benchmarking/GeneratorTx.hs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import Cardano.Api hiding (txFee)
import Cardano.Benchmarking.GeneratorTx.NodeToNode
import Cardano.Benchmarking.GeneratorTx.Submission
import Cardano.Benchmarking.GeneratorTx.SubmissionClient
import Cardano.TxGenerator.Setup.NixService
import Cardano.Benchmarking.LogTypes
import Cardano.Benchmarking.TpsThrottle
import Cardano.Benchmarking.Types
Expand Down Expand Up @@ -155,7 +156,7 @@ walletBenchmark :: forall era. IsShelleyBasedEra era
-> Trace IO NodeToNodeSubmissionTrace
-> ConnectClient
-> String
-> NonEmpty NodeIPv4Address
-> NonEmpty (WithAlias NodeIPv4Address)
-> TPSRate
-> SubmissionErrorPolicy
-> AsType era
Expand All @@ -182,7 +183,7 @@ walletBenchmark
= liftIO $ do
traceDebug "******* Tx generator, phase 2: pay to recipients *******"

remoteAddresses <- forM targets lookupNodeAddress
remoteAddresses <- forM targets (lookupNodeAddress . getAliasPayload)
let numTargets :: Natural = fromIntegral $ NE.length targets

traceDebug $ "******* Tx generator, launching Tx peers: " ++ show (NE.length remoteAddresses) ++ " of them"
Expand Down
3 changes: 2 additions & 1 deletion bench/tx-generator/src/Cardano/Benchmarking/Script/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ import Cardano.Api.Shelley
import Cardano.Benchmarking.OuroborosImports (SigningKeyFile)
import Cardano.Node.Configuration.NodeAddress (NodeIPv4Address)
import Cardano.TxGenerator.Types
import Cardano.TxGenerator.Setup.NixService (WithAlias)

import Prelude

Expand Down Expand Up @@ -177,7 +178,7 @@ data ProtocolParametersSource where
deriving (Show, Eq)
deriving instance Generic ProtocolParametersSource

type TargetNodes = NonEmpty NodeIPv4Address
type TargetNodes = NonEmpty (WithAlias NodeIPv4Address)

data SubmitMode where
LocalSocket :: SubmitMode
Expand Down
49 changes: 43 additions & 6 deletions bench/tx-generator/src/Cardano/TxGenerator/Setup/NixService.hs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,16 @@

{-# OPTIONS_GHC -fno-warn-orphans #-}

-- TODO: remove me
{-# OPTIONS_GHC -fno-warn-unused-imports #-}


module Cardano.TxGenerator.Setup.NixService
( NixServiceOptions (..)
, NodeConfigDiffTime (..)
--, NodeConfigDiffTime (..)
, WithAlias(..)
, getKeepaliveTimeout
, getAliasPayload
, getNodeConfigFile
, setNodeConfigFile
, txGenTxParams
Expand All @@ -28,9 +35,8 @@ import Cardano.TxGenerator.Internal.Orphans ()
import Cardano.TxGenerator.Types

import qualified Control.Applicative as App (empty)
import Data.Aeson (FromJSON (..), Options (fieldLabelModifier), ToJSON (..),
Value (Number), (.:), (.:?))
import qualified Data.Aeson as Aeson (Options, defaultOptions, genericParseJSON, withObject)
import Data.Aeson as Aeson
-- import qualified Data.Aeson as Aeson (Options, defaultOptions, genericParseJSON, withObject)
import Data.List.NonEmpty (NonEmpty)
import Data.Maybe (fromMaybe)
import Data.Scientific (Scientific)
Expand All @@ -50,16 +56,17 @@ data NixServiceOptions = NixServiceOptions {
, _nix_init_cooldown :: Double
, _nix_era :: AnyCardanoEra
, _nix_plutus :: Maybe TxGenPlutusParams
, _nix_keepalive :: Maybe NodeConfigDiffTime
, _nix_keepalive :: Maybe Integer
, _nix_nodeConfigFile :: Maybe FilePath
, _nix_cardanoTracerSocket :: Maybe FilePath
, _nix_sigKey :: SigningKeyFile In
, _nix_localNodeSocketPath :: String
, _nix_targetNodes :: NonEmpty NodeIPv4Address
, _nix_targetNodes :: NonEmpty (WithAlias NodeIPv4Address)
} deriving (Show, Eq)

deriving instance Generic NixServiceOptions

{-
newtype NodeConfigDiffTime =
NodeConfigDiffTime { nodeConfigDiffTime :: Clock.DiffTime }
deriving (Eq, Ord, Read, Show)
Expand All @@ -80,6 +87,36 @@ instance ToJSON NodeConfigDiffTime where
toJSON NodeConfigDiffTime {..} =
let picoSeconds = Clock.diffTimeToPicoseconds nodeConfigDiffTime
in toJSON $ picoSeconds `div` 10^(12 :: Int)
-}

-- only works on JSON Object types
data WithAlias a =
WithAlias String a

deriving instance Show a => Show (WithAlias a)
deriving instance Eq a => Eq (WithAlias a)
-- deriving instance Generic a => Generic (WithAlias a)

-- { "alias": "foo", "addr": ..., "port": ... }
instance (Show a, FromJSON a) => FromJSON (WithAlias a) where
parseJSON val = case fromJSON val of
Error e -> fail e
Success payload -> withObject "WithAlias" (\o' -> do
alias <- o' .:? "name" .!= show payload
pure $ WithAlias alias payload
) val

instance ToJSON a => ToJSON (WithAlias a) where
toJSON (WithAlias _ val) = toJSON val


-- TODO: add comment about hard-coded default value
-- and when to change (account for long GC pauses at target nodes)
getKeepaliveTimeout :: NixServiceOptions -> Clock.DiffTime
getKeepaliveTimeout = maybe 10 Clock.secondsToDiffTime . _nix_keepalive

getAliasPayload :: WithAlias a -> a
getAliasPayload (WithAlias _ val) = val

getNodeConfigFile :: NixServiceOptions -> Maybe FilePath
getNodeConfigFile = _nix_nodeConfigFile
Expand Down
4 changes: 3 additions & 1 deletion nix/nixos/tx-generator-service.nix
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ let
capitalise = x: (pkgs.lib.toUpper (__substring 0 1 x)) + __substring 1 99999 x;

targetNodesList = targets: __attrValues (__mapAttrs
(name: { ip, port }: { addr = ip; port = port; })
(name: { ip, port, name }: { addr = ip; port = port; name = name; })
targets);
in pkgs.commonLib.defServiceModule
(lib: with lib;
Expand Down Expand Up @@ -114,6 +114,8 @@ in pkgs.commonLib.defServiceModule
"Strength of generated load, in TPS.";
init_cooldown = opt int 50 "Delay between init and main submissions.";
min_utxo_value = opt int 10000000 "Minimum value allowed per UTxO entry";
keepalive = opt int 10 "Default timeout for keep-alive mini-protocol";

runScriptFn = opt (functionTo attrs) defaultGeneratorScriptFn
"Function accepting this service config and producing the generator run script (a list of command attrsets). Takes effect unless runScript or runScriptFile are specified.";
runScript = mayOpt (listOf attrs)
Expand Down
2 changes: 1 addition & 1 deletion nix/workbench/service/generator.nix
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ let

targetNodes = __mapAttrs
(name: { name, port, ...}@nodeSpec:
{ inherit port;
{ inherit name port;
ip = let ip = nodePublicIP nodeSpec; # getPublicIp resources nodes name
in __trace "generator target: ${name}/${ip}:${toString port}" ip;
})
Expand Down

0 comments on commit f57a06f

Please sign in to comment.