From b4d983531ba9a07c24743ba021a64e5a4490bbdd Mon Sep 17 00:00:00 2001 From: Yura Lazarev Date: Thu, 26 Oct 2023 12:51:15 +0200 Subject: [PATCH 1/6] Refactor latency benchmark script --- .buildkite/bench-latency.sh | 17 +++-------------- 1 file changed, 3 insertions(+), 14 deletions(-) diff --git a/.buildkite/bench-latency.sh b/.buildkite/bench-latency.sh index 600c55063f5..a997d152143 100755 --- a/.buildkite/bench-latency.sh +++ b/.buildkite/bench-latency.sh @@ -1,18 +1,7 @@ -#! /usr/bin/env nix-shell -#! nix-shell -i bash -p coreutils buildkite-agent +#! /usr/bin/env bash set -euo pipefail -cd $(dirname $0)/.. +echo "+++ Build & run benchmark - shelley" -echo "--- Build" - -nix build .#ci.benchmarks.latency -o bench-latency-shelley - -# Note: the tracing will not work if program output is piped -# to another process (e.g. "tee"). -# It says "Error: Switchboard's queue full, dropping log items!" - -echo "+++ Run benchmark - shelley" - -./bench-latency-shelley/bin/latency +nix run .#ci.benchmarks.latency From 498c06a017b403df696e85a3c2cc20c5eb11a0dc Mon Sep 17 00:00:00 2001 From: Yura Lazarev Date: Fri, 27 Oct 2023 15:58:16 +0200 Subject: [PATCH 2/6] refactor: pass a parameter via a CLI arg. --- .buildkite/bench-latency.sh | 2 +- .../lib/Cardano/Wallet/LocalCluster.hs | 50 ++++++------------- lib/wallet/bench/latency-bench.hs | 30 +++++++++-- lib/wallet/cardano-wallet.cabal | 26 ++++++---- nix/haskell.nix | 14 ++---- 5 files changed, 61 insertions(+), 61 deletions(-) diff --git a/.buildkite/bench-latency.sh b/.buildkite/bench-latency.sh index a997d152143..500f93569eb 100755 --- a/.buildkite/bench-latency.sh +++ b/.buildkite/bench-latency.sh @@ -2,6 +2,6 @@ set -euo pipefail -echo "+++ Build & run benchmark - shelley" +echo "+++ Build & run latency benchmark" nix run .#ci.benchmarks.latency diff --git a/lib/local-cluster/lib/Cardano/Wallet/LocalCluster.hs b/lib/local-cluster/lib/Cardano/Wallet/LocalCluster.hs index cd06c3b57ff..f24ac8a5532 100644 --- a/lib/local-cluster/lib/Cardano/Wallet/LocalCluster.hs +++ b/lib/local-cluster/lib/Cardano/Wallet/LocalCluster.hs @@ -43,16 +43,12 @@ import Cardano.Wallet.Primitive.Types.Coin ( Coin (..) ) import Control.Applicative - ( optional - , (<**>) + ( (<**>) ) import Control.Monad.Trans.Resource ( allocate , runResourceT ) -import Data.Functor - ( (<&>) - ) import Data.Tagged ( Tagged (..) ) @@ -61,18 +57,11 @@ import Main.Utf8 ) import System.Environment.Extended ( isEnvSet - , lookupEnvNonEmpty - ) -import System.FilePath - ( () ) import System.IO.Temp.Extra ( SkipCleanup (..) , withSystemTempDir ) -import Test.Utils.Paths - ( getTestData - ) import UnliftIO.Concurrent ( threadDelay ) @@ -218,15 +207,13 @@ main = withUtf8 $ do cfgNodeLogging <- Cluster.logFileConfigFromEnv (Just (Cluster.clusterEraToString clusterEra)) - cfgClusterConfigs <- parseCommandLineOptions >>= \case - CommandLineOptions Nothing -> getClusterConfigsPathFromEnv - CommandLineOptions (Just path) -> pure path + CommandLineOptions { clusterConfigsDir } <- parseCommandLineOptions let clusterCfg = Cluster.Config { cfgStakePools = Cluster.defaultPoolConfigs , cfgLastHardFork = clusterEra , cfgNodeLogging , cfgClusterDir = Tagged clusterPath - , cfgClusterConfigs + , cfgClusterConfigs = clusterConfigsDir , cfgTestnetMagic = Cluster.TestnetMagic 42 } Cluster.withCluster stdoutTextTracer clusterCfg faucetFunds $ \node -> do @@ -274,27 +261,20 @@ main = withUtf8 $ do ] } --- | Returns a path to the local cluster configuration, which is usually relative to the --- package sources, but can be overridden by the @LOCAL_CLUSTER_CONFIGS@ environment --- variable. -getClusterConfigsPathFromEnv :: IO (Tagged "cluster-configs" FilePath) -getClusterConfigsPathFromEnv = - lookupEnvNonEmpty "LOCAL_CLUSTER_CONFIGS" <&> Tagged . \case - Nothing -> $(getTestData) "cluster-configs" - Just fp -> fp - newtype CommandLineOptions = CommandLineOptions - { clusterConfigsDir :: Maybe (Tagged "cluster-configs" FilePath) - } + { clusterConfigsDir :: Tagged "cluster-configs" FilePath } + deriving stock (Show) parseCommandLineOptions :: IO CommandLineOptions parseCommandLineOptions = O.execParser $ - O.info (parser <**> O.helper) (O.progDesc "Local Cluster for testing") - where - parser = CommandLineOptions <$> optional ( - Tagged <$> O.strOption - ( O.long "cluster-configs" - <> O.metavar "LOCAL_CLUSTER_CONFIGS" - <> O.help "Path to the local cluster configuration directory" - ) + O.info + (fmap CommandLineOptions clusterConfigsDirParser <**> O.helper) + (O.progDesc "Local Cluster for testing") + +clusterConfigsDirParser :: O.Parser (Tagged "cluster-configs" FilePath) +clusterConfigsDirParser = + Tagged <$> O.strOption + ( O.long "cluster-configs" + <> O.metavar "LOCAL_CLUSTER_CONFIGS" + <> O.help "Path to the local cluster configuration directory" ) diff --git a/lib/wallet/bench/latency-bench.hs b/lib/wallet/bench/latency-bench.hs index 276a86859e7..86579d3be70 100644 --- a/lib/wallet/bench/latency-bench.hs +++ b/lib/wallet/bench/latency-bench.hs @@ -1,6 +1,8 @@ {-# LANGUAGE DataKinds #-} +{-# LANGUAGE DerivingStrategies #-} {-# LANGUAGE FlexibleContexts #-} {-# LANGUAGE LambdaCase #-} +{-# LANGUAGE NamedFieldPuns #-} {-# LANGUAGE NumericUnderscores #-} {-# LANGUAGE OverloadedLabels #-} {-# LANGUAGE QuasiQuotes #-} @@ -81,6 +83,9 @@ import Cardano.Wallet.Launch.Cluster , defaultPoolConfigs , withCluster ) +import Cardano.Wallet.LocalCluster + ( clusterConfigsDirParser + ) import Cardano.Wallet.Network.Ports ( portFromURL ) @@ -113,6 +118,9 @@ import Cardano.Wallet.Unsafe ( unsafeFromText , unsafeMkMnemonic ) +import Control.Applicative + ( (<**>) + ) import Control.Monad ( replicateM , replicateM_ @@ -212,13 +220,13 @@ import UnliftIO.STM import qualified Cardano.Address as CA import qualified Cardano.Wallet.Api.Link as Link import qualified Cardano.Wallet.Launch.Cluster as Cluster -import qualified Cardano.Wallet.LocalCluster as LocalCluster import qualified Data.List.NonEmpty as NE import qualified Data.Text as T import qualified Network.HTTP.Types.Status as HTTP +import qualified Options.Applicative as O main :: forall n. (n ~ 'Mainnet) => IO () -main = withUtf8 $ +main = withUtf8 $ do withLatencyLogging setupTracers $ \tracers capture -> withShelleyServer tracers $ \ctx -> do walletApiBench @n capture ctx @@ -555,13 +563,13 @@ withShelleyServer tracers action = do withSystemTempDir nullTracer "latency" skipCleanup $ \dir -> do let db = dir "wallets" createDirectory db - cfgClusterConfigs <- LocalCluster.getClusterConfigsPathFromEnv + CommandLineOptions { clusterConfigsDir } <- parseCommandLineOptions let clusterConfig = Cluster.Config { Cluster.cfgStakePools = NE.head defaultPoolConfigs :| [] , Cluster.cfgLastHardFork = maxBound , Cluster.cfgNodeLogging = LogFileConfig Error Nothing Error , Cluster.cfgClusterDir = Tagged @"cluster" dir - , Cluster.cfgClusterConfigs = cfgClusterConfigs + , Cluster.cfgClusterConfigs = clusterConfigsDir , Cluster.cfgTestnetMagic = testnetMagic } withCluster @@ -624,3 +632,17 @@ massiveWalletAmt = ada 1_000 era :: ApiEra era = maxBound + + +-------------------------------------------------------------------------------- +-- Command line options -------------------------------------------------------- + +newtype CommandLineOptions = CommandLineOptions + { clusterConfigsDir :: Tagged "cluster-configs" FilePath } + deriving stock (Show) + +parseCommandLineOptions :: IO CommandLineOptions +parseCommandLineOptions = O.execParser $ + O.info + (fmap CommandLineOptions clusterConfigsDirParser <**> O.helper) + (O.progDesc "Cardano Wallet's Latency Benchmark") diff --git a/lib/wallet/cardano-wallet.cabal b/lib/wallet/cardano-wallet.cabal index 13ec2f5084c..ebec2663d18 100644 --- a/lib/wallet/cardano-wallet.cabal +++ b/lib/wallet/cardano-wallet.cabal @@ -68,7 +68,7 @@ library , cardano-addresses , cardano-addresses-cli , cardano-api - , cardano-balance-tx:{cardano-balance-tx,internal} + , cardano-balance-tx:{cardano-balance-tx, internal} , cardano-binary , cardano-cli , cardano-coin-selection @@ -136,7 +136,7 @@ library , int-cast , io-classes , iohk-monitoring - , iohk-monitoring-extra ^>=0.1 + , iohk-monitoring-extra ^>=0.1 , iproute , lattices , lens @@ -165,14 +165,14 @@ library , ouroboros-network-framework , ouroboros-network-protocols , path-pieces - , persistent ^>=2.13 - , persistent-sqlite ^>=2.13 - , persistent-template ^>=2.12 + , persistent ^>=2.13 + , persistent-sqlite ^>=2.13 + , persistent-template ^>=2.12 , plutus-core , plutus-ledger-api , pretty-simple , profunctors - , QuickCheck ^>=2.14.3 + , QuickCheck ^>=2.14.3 , quickcheck-instances , quiet , random @@ -386,7 +386,7 @@ library cardano-wallet-api-http , cardano-addresses , cardano-addresses-cli , cardano-api - , cardano-balance-tx:{cardano-balance-tx,internal} + , cardano-balance-tx:{cardano-balance-tx, internal} , cardano-binary , cardano-cli , cardano-crypto @@ -424,7 +424,7 @@ library cardano-wallet-api-http , http-types , int-cast , iohk-monitoring - , iohk-monitoring-extra ^>=0.1 + , iohk-monitoring-extra ^>=0.1 , lens , memory , mtl @@ -708,7 +708,7 @@ test-suite unit , cardano-addresses , cardano-api , cardano-api-extra - , cardano-balance-tx:{cardano-balance-tx,internal} + , cardano-balance-tx:{cardano-balance-tx, internal} , cardano-binary , cardano-coin-selection , cardano-crypto @@ -868,9 +868,9 @@ test-suite unit Cardano.Wallet.Api.ServerSpec Cardano.Wallet.Api.TypesSpec Cardano.Wallet.ApiSpec - Cardano.Wallet.Balance.MigrationSpec Cardano.Wallet.Balance.Migration.PlanningSpec Cardano.Wallet.Balance.Migration.SelectionSpec + Cardano.Wallet.Balance.MigrationSpec Cardano.Wallet.Checkpoints.PolicySpec Cardano.Wallet.CheckpointsSpec Cardano.Wallet.DB.Arbitrary @@ -925,13 +925,13 @@ test-suite unit Cardano.Wallet.Submissions.PrimitivesSpec Cardano.Wallet.TokenMetadataSpec Cardano.WalletSpec - Internal.Cardano.Write.Tx.BalanceSpec Control.Concurrent.ConciergeSpec Control.Monad.UtilSpec Data.Function.UtilsSpec Data.Time.TextSpec Data.Time.UtilsSpec Data.Vector.ShuffleSpec + Internal.Cardano.Write.Tx.BalanceSpec Spec SpecHook @@ -972,6 +972,7 @@ test-suite integration , text-class , unliftio , with-utf8 + build-tool-depends: cardano-wallet:cardano-wallet benchmark restore @@ -1035,6 +1036,7 @@ benchmark latency , iohk-monitoring , iohk-monitoring-extra , local-cluster + , optparse-applicative , tagged ^>=0.8.7 , temporary-extra , text @@ -1042,6 +1044,7 @@ benchmark latency , unliftio , wai-middleware-logging , with-utf8 + other-modules: Cardano.Wallet.LatencyBenchShared benchmark db @@ -1081,6 +1084,7 @@ benchmark db , transformers , unliftio , with-utf8 + other-modules: Cardano.Wallet.DummyTarget.Primitive.Types benchmark api diff --git a/nix/haskell.nix b/nix/haskell.nix index 8ab941b24df..ba2e4d94eee 100644 --- a/nix/haskell.nix +++ b/nix/haskell.nix @@ -258,6 +258,7 @@ CHaP: haskell-nix: nixpkgs-recent: nodePkgs: haskell-nix.cabalProject' [ postInstall = '' wrapProgram $out/bin/* \ --run "cd ${srcAll}/lib/wallet" \ + --add-flags --cluster-configs="${localClusterConfigs}" \ --prefix PATH : ${lib.makeBinPath cardanoNodeExes} ''; }; @@ -275,18 +276,11 @@ CHaP: haskell-nix: nixpkgs-recent: nodePkgs: haskell-nix.cabalProject' [ ''; }; - - packages.cardano-wallet.components.exes.local-cluster = - if (stdenv.hostPlatform.isWindows) then { - postInstall = '' - mkdir -p $out/bin/test/data - cp -Rv ${localClusterConfigs} $out/bin/test/data - ''; - } else { + packages.cardano-wallet.components.exes.local-cluster = { build-tools = [ pkgs.buildPackages.makeWrapper ]; postInstall = '' - wrapProgram $out/bin/local-cluster \ - --set LOCAL_CLUSTER_CONFIGS ${localClusterConfigs} \ + wrapProgram $out/bin/* \ + --add-flags --cluster-configs="${localClusterConfigs}" \ --prefix PATH : ${lib.makeBinPath cardanoNodeExes} ''; }; From 2d065893b35e69093f969d7845b28b0cb786ada1 Mon Sep 17 00:00:00 2001 From: Yura Lazarev Date: Fri, 27 Oct 2023 15:58:37 +0200 Subject: [PATCH 3/6] add more useful tasks to justfile --- justfile | 30 ++++++++++++++++++++++++++---- 1 file changed, 26 insertions(+), 4 deletions(-) diff --git a/justfile b/justfile index 407579f1906..cd351351324 100644 --- a/justfile +++ b/justfile @@ -1,15 +1,37 @@ default: @just --list +# check that the code is formatted with stylish-haskell +check target="stylish": + ./.buildkite/check-{{target}}.sh + # build wallet-e2e suite with cabal build: cabal build all -local-cluster $LOCAL_CLUSTER_CONFIGS="lib/local-cluster/test/data/cluster-configs": - nix shell '.#local-cluster' '.#cardano-node' '.#cardano-wallet' -c "local-cluster" +# run a nix shell with `cardano-wallet` in scope +shell: + nix shell '.#cardano-wallet' + +# run a benchmark: api | latency | memory | db | restore +bench target: + ./.buildkite/bench-{{target}}.sh + +# run a local test cluster +local-cluster: + nix shell '.#local-cluster' '.#cardano-node' '.#cardano-wallet' \ + -c "local-cluster" \ + --cluster-configs lib/local-cluster/test/data/cluster-configs + +# run unit tests +unit: + cabal run cardano-wallet:test:unit \ + --test-options '--cluster-configs lib/local-cluster/test/data/cluster-configs' -unit $LOCAL_CLUSTER_CONFIGS="lib/local-cluster/test/data/cluster-configs": - cabal test cardano-wallet:unit +# run integration tests +integration: + LOCAL_CLUSTER_CONFIGS=lib/local-cluster/test/data/cluster-configs \ + nix shell '.#cardano-wallet' -c cabal test integration # run wallet-e2e suite against the preprod network e2e-preprod: From d4b8422d83b2240ef95f9b6bf55d6c2706cd1720 Mon Sep 17 00:00:00 2001 From: Yura Lazarev Date: Fri, 27 Oct 2023 15:58:49 +0200 Subject: [PATCH 4/6] remove obsolete bors script --- .buildkite/check-bors.sh | 34 ---------------------------------- 1 file changed, 34 deletions(-) delete mode 100755 .buildkite/check-bors.sh diff --git a/.buildkite/check-bors.sh b/.buildkite/check-bors.sh deleted file mode 100755 index b1c675c406d..00000000000 --- a/.buildkite/check-bors.sh +++ /dev/null @@ -1,34 +0,0 @@ -#!/usr/bin/env bash - -######################################################################## -# This script is only meant to be run under Buildkite for the Bors -# staging branch. -# -# Example variables: -# -# BUILDKITE_BRANCH=staging -# BUILDKITE_PIPELINE_DEFAULT_BRANCH=master -# BUILDKITE_REPO=https://github.com/cardano-foundation/cardano-wallet.git -# -######################################################################## - -set -euo pipefail - -# Find the parents of the staging branch merge commit. -# This is a space-separated list of commit hashes. -staging_branch_parents=$(git show -s --pretty=%P HEAD) - -# Find the commit hash of origin/master. -master_rev=$(git ls-remote $BUILDKITE_REPO $BUILDKITE_PIPELINE_DEFAULT_BRANCH | cut -f1) - -if [[ "$staging_branch_parents" =~ "$master_rev" ]]; then - exit 0 -else - echo "$BUILDKITE_PIPELINE_DEFAULT_BRANCH commit is $master_rev" - echo "$BUILDKITE_BRANCH parent commits are $staging_branch_parents" - echo - echo "Refusing to merge because the pull request does not target $BUILDKITE_PIPELINE_DEFAULT_BRANCH." - echo "You should only use Bors to merge into the $BUILDKITE_PIPELINE_DEFAULT_BRANCH branch." - echo "Either change the PR base branch to $BUILDKITE_PIPELINE_DEFAULT_BRANCH, or merge manually." - exit 1 -fi From 64b90f6526f3255ab20cd4ab58951a9a2f79ae4a Mon Sep 17 00:00:00 2001 From: Yura Lazarev Date: Fri, 27 Oct 2023 15:59:04 +0200 Subject: [PATCH 5/6] refactor: avoid reading env var twice. --- .../integration/shelley-integration-test.hs | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/lib/wallet/test/integration/shelley-integration-test.hs b/lib/wallet/test/integration/shelley-integration-test.hs index 3e52982f0fa..54fd3204495 100644 --- a/lib/wallet/test/integration/shelley-integration-test.hs +++ b/lib/wallet/test/integration/shelley-integration-test.hs @@ -237,7 +237,6 @@ import qualified Cardano.Pool.DB as Pool import qualified Cardano.Pool.DB.Sqlite as Pool import qualified Cardano.Wallet.Faucet.Mnemonics as Mnemonics import qualified Cardano.Wallet.Launch.Cluster as Cluster -import qualified Cardano.Wallet.LocalCluster as LocalCluster import qualified Data.Text as T import qualified Test.Integration.Scenario.API.Blocks as Blocks import qualified Test.Integration.Scenario.API.Byron.Addresses as ByronAddresses @@ -362,6 +361,11 @@ specWithServer testnetMagic testDir (tr, tracers) = aroundAll withContext withContext :: (Context -> IO ()) -> IO () withContext action = bracketTracer' tr "withContext" $ do ctx <- newEmptyMVar + + clusterConfigs <- lookupEnvNonEmpty "LOCAL_CLUSTER_CONFIGS" + <&> Tagged @"cluster-configs" + . fromMaybe "../local-cluster/test/data/cluster-configs" + poolGarbageCollectionEvents <- newIORef [] let dbEventRecorder = recordPoolGarbageCollectionEvents poolGarbageCollectionEvents @@ -379,10 +383,6 @@ specWithServer testnetMagic testDir (tr, tracers) = aroundAll withContext mintSeaHorseAssetsLock <- newMVar () - clusterConfigs <- lookupEnvNonEmpty "LOCAL_CLUSTER_CONFIGS" - <&> Tagged @"cluster-configs" - . fromMaybe "../local-cluster/test/data/cluster-configs" - let config = Cluster.Config { cfgStakePools = error "cfgStakePools: unused" , cfgLastHardFork = era @@ -413,7 +413,7 @@ specWithServer testnetMagic testDir (tr, tracers) = aroundAll withContext } let action' = bracketTracer' tr "spec" . action res <- race - (withServer dbEventRecorder setupContext) + (withServer clusterConfigs dbEventRecorder setupContext) (takeMVar ctx >>= action') whenLeft res (throwIO . ProcessHasExited "integration") @@ -439,15 +439,15 @@ specWithServer testnetMagic testDir (tr, tracers) = aroundAll withContext atomicModifyIORef' eventsRef ((,()) . (event :)) pure certificates - withServer dbDecorator onReady = bracketTracer' tr "withServer" $ + withServer clusterConfigs dbDecorator onReady = + bracketTracer' tr "withServer" $ withSMASH tr' testDir $ \smashUrl -> do - cfgClusterConfigs <- LocalCluster.getClusterConfigsPathFromEnv let clusterConfig = Cluster.Config { Cluster.cfgStakePools = Cluster.defaultPoolConfigs , Cluster.cfgLastHardFork = BabbageHardFork , Cluster.cfgNodeLogging = LogFileConfig Info Nothing Info , Cluster.cfgClusterDir = Tagged @"cluster" testDir - , Cluster.cfgClusterConfigs = cfgClusterConfigs + , Cluster.cfgClusterConfigs = clusterConfigs , Cluster.cfgTestnetMagic = testnetMagic } withCluster tr' clusterConfig faucetFunds From 329e24fa86accbca03a37eec5ee6e24f41420c40 Mon Sep 17 00:00:00 2001 From: Yura Lazarev Date: Thu, 2 Nov 2023 15:45:13 +0100 Subject: [PATCH 6/6] fix: latency-bench --- .buildkite/bench-latency.sh | 7 +- .../lib/Cardano/Wallet/Launch/Cluster.hs | 135 ++++--- .../lib/Cardano/Wallet/LocalCluster.hs | 5 + .../data/cluster-configs/alonzo-genesis.yaml | 363 ------------------ .../data/cluster-configs/byron-genesis.yaml | 35 -- ...lonzo-genesis.json => genesis-alonzo.json} | 0 ...{byron-genesis.json => genesis-byron.json} | 0 ...onway-genesis.json => genesis-conway.json} | 0 .../data/cluster-configs/node-config.json | 17 +- .../data/cluster-configs/shelley-genesis.json | 48 --- lib/std-gen-seed/std-gen-seed.cabal | 2 - lib/wallet/bench/latency-bench.hs | 165 ++++---- .../src/Cardano/Wallet/LatencyBenchShared.hs | 48 ++- lib/wallet/cardano-wallet.cabal | 1 + .../src/Test/Integration/Framework/DSL.hs | 16 +- lib/wallet/src/Cardano/Wallet.hs | 6 +- .../src/Cardano/Wallet/Primitive/Slotting.hs | 3 +- .../integration/shelley-integration-test.hs | 14 +- .../Cardano/Wallet/Shelley/NetworkSpec.hs | 15 +- 19 files changed, 259 insertions(+), 621 deletions(-) delete mode 100644 lib/local-cluster/test/data/cluster-configs/alonzo-genesis.yaml delete mode 100644 lib/local-cluster/test/data/cluster-configs/byron-genesis.yaml rename lib/local-cluster/test/data/cluster-configs/{alonzo-genesis.json => genesis-alonzo.json} (100%) rename lib/local-cluster/test/data/cluster-configs/{byron-genesis.json => genesis-byron.json} (100%) rename lib/local-cluster/test/data/cluster-configs/{conway-genesis.json => genesis-conway.json} (100%) delete mode 100644 lib/local-cluster/test/data/cluster-configs/shelley-genesis.json diff --git a/.buildkite/bench-latency.sh b/.buildkite/bench-latency.sh index 500f93569eb..6d012c21e0a 100755 --- a/.buildkite/bench-latency.sh +++ b/.buildkite/bench-latency.sh @@ -4,4 +4,9 @@ set -euo pipefail echo "+++ Build & run latency benchmark" -nix run .#ci.benchmarks.latency +nix shell \ + '.#local-cluster' \ + '.#cardano-node' \ + '.#cardano-wallet' \ + '.#ci.benchmarks.latency' \ + -c latency diff --git a/lib/local-cluster/lib/Cardano/Wallet/Launch/Cluster.hs b/lib/local-cluster/lib/Cardano/Wallet/Launch/Cluster.hs index 7a2d0d640bf..c7deeb3b254 100644 --- a/lib/local-cluster/lib/Cardano/Wallet/Launch/Cluster.hs +++ b/lib/local-cluster/lib/Cardano/Wallet/Launch/Cluster.hs @@ -26,6 +26,7 @@ module Cardano.Wallet.Launch.Cluster ( -- * Local test cluster launcher withCluster , Config (..) + , ShelleyGenesisModifier , TestnetMagic (..) , ClusterEra (..) , FaucetFunds (..) @@ -188,6 +189,7 @@ import Control.Monad , liftM2 , replicateM , replicateM_ + , unless , void , when , (>=>) @@ -1040,6 +1042,9 @@ clusterEraToString = \case newtype TestnetMagic = TestnetMagic { testnetMagicToNatural :: Natural } deriving stock (Show) +type ShelleyGenesisModifier = + ShelleyGenesis StandardCrypto -> ShelleyGenesis StandardCrypto + data Config = Config { cfgStakePools :: NonEmpty PoolRecipe -- ^ Stake pools to register. @@ -1052,7 +1057,10 @@ data Config = Config , cfgClusterConfigs :: Tagged "cluster-configs" FilePath -- ^ Directory containing data for cluster setup. , cfgTestnetMagic :: TestnetMagic - } deriving stock (Show) + -- ^ Testnet magic to use. + , cfgShelleyGenesisMods :: [ShelleyGenesisModifier] + -- ^ Shelley genesis modifications to apply. + } -- | Information about a launched node. data RunningNode = RunningNode @@ -1083,10 +1091,9 @@ generateGenesis :: HasCallStack => Config -> [(Address, Coin)] - -> (ShelleyGenesis StandardCrypto -> ShelleyGenesis StandardCrypto) - -- ^ For adding genesis pools and staking in Babbage and later. + -> [ShelleyGenesisModifier] -> IO GenesisFiles -generateGenesis Config{..} initialFunds addPoolsToGenesis = do +generateGenesis Config{..} initialFunds genesisMods = do {- The timestamp of the 0-th slot. Ideally it should be few seconds later than the cluster actually starts. @@ -1094,7 +1101,7 @@ generateGenesis Config{..} initialFunds addPoolsToGenesis = do If it's slightly before the actual starts, some slots will be missed, but it shouldn't be critical as long as less than k slots are missed. - Empirically, 10 seconds seems to be a good value: enough for a cluster to + Empirically, 5 seconds seems to be a good value: enough for a cluster to initialize itself before producing any blocks, but not too much to wait for. Lower values (e.g. 1 second) might cause custer to start but not produce @@ -1102,14 +1109,41 @@ generateGenesis Config{..} initialFunds addPoolsToGenesis = do happens then node logs contain TraceNoLedgerView message and wallet log says "Current tip is [point genesis]. (not applying blocks)" -} - systemStart <- addUTCTime 10 <$> getCurrentTime - - let shelleyGenesisData = addPoolsToGenesis ShelleyGenesis + systemStart <- addUTCTime 5 <$> getCurrentTime + + let sgProtocolParams = Ledger.emptyPParams + & ppMinFeeAL .~ Ledger.Coin 100 + & ppMinFeeBL .~ Ledger.Coin 100_000 + & ppMinUTxOValueL .~ Ledger.Coin 1_000_000 + & ppKeyDepositL .~ Ledger.Coin 1_000_000 + & ppPoolDepositL .~ Ledger.Coin 0 + & ppMaxBBSizeL .~ 239_857 + & ppMaxBHSizeL .~ 217_569 + & ppMaxTxSizeL .~ 16_384 + & ppMinPoolCostL .~ Ledger.Coin 0 + & ppExtraEntropyL .~ Ledger.NeutralNonce + -- There are a few smaller features/fixes which are enabled + -- based on the protocol version rather than just the era, + -- so we need to set it to a realisitic value. + & ppProtocolVersionL .~ Ledger.ProtVer (natVersion @8) 0 + -- Sensible pool & reward parameters: + & ppNOptL .~ 3 + & ppRhoL .~ unsafeUnitInterval 0.178_650_067 + & ppTauL .~ unsafeUnitInterval 0.1 + & ppA0L .~ unsafeNonNegativeInterval 0.1 + & ppDL .~ unsafeUnitInterval 0 + -- The epoch bound on pool retirements specifies how many epochs + -- in advance retirements may be announced. For testing purposes, + -- we allow retirements to be announced far into the future. + & ppEMaxL .~ 1_000_000 + + let shelleyGenesisData = + foldr ($) ShelleyGenesis { sgSystemStart = systemStart , sgActiveSlotsCoeff = unsafePositiveUnitInterval 0.5 - , sgSlotLength = 0.1 , sgSecurityParam = 10 , sgEpochLength = 100 + , sgSlotLength = 0.1 , sgUpdateQuorum = 1 , sgNetworkMagic = fromIntegral (testnetMagicToNatural cfgTestnetMagic) @@ -1117,73 +1151,53 @@ generateGenesis Config{..} initialFunds addPoolsToGenesis = do , sgMaxKESEvolutions = 5 , sgNetworkId = Testnet , sgMaxLovelaceSupply = 1_000_000_000_000_000_000 - , sgProtocolParams = Ledger.emptyPParams - & ppMinFeeAL .~ Ledger.Coin 100 - & ppMinFeeBL .~ Ledger.Coin 100_000 - & ppMinUTxOValueL .~ Ledger.Coin 1_000_000 - & ppKeyDepositL .~ Ledger.Coin 1_000_000 - & ppPoolDepositL .~ Ledger.Coin 0 - & ppMaxBBSizeL .~ 239_857 - & ppMaxBHSizeL .~ 217_569 - & ppMaxTxSizeL .~ 16_384 - & ppMinPoolCostL .~ Ledger.Coin 0 - & ppExtraEntropyL .~ Ledger.NeutralNonce - -- There are a few smaller features/fixes which are enabled - -- based on the protocol version rather than just the era, - -- so we need to set it to a realisitic value. - & ppProtocolVersionL .~ Ledger.ProtVer (natVersion @8) 0 - -- Sensible pool & reward parameters: - & ppNOptL .~ 3 - & ppRhoL .~ unsafeUnitInterval 0.178_650_067 - & ppTauL .~ unsafeUnitInterval 0.1 - & ppA0L .~ unsafeNonNegativeInterval 0.1 - & ppDL .~ unsafeUnitInterval 0 - -- The epoch bound on pool retirements specifies how many epochs - -- in advance retirements may be announced. For testing purposes, - -- we allow retirements to be announced far into the future. - & ppEMaxL .~ 1_000_000 + , sgProtocolParams , sgInitialFunds = ListMap.fromList [ ( fromMaybe (error "sgInitialFunds: invalid addr") $ Ledger.deserialiseAddr $ unAddress address - , Ledger.Coin $ intCast c - ) + , Ledger.Coin $ intCast c + ) | (address, Coin c) <- initialFunds ] , sgStaking = Ledger.emptyGenesisStaking -- We need this to submit MIR certs -- (and probably for the BFT node pre-babbage): , sgGenDelegs = - fromRight (error "invalid sgGenDelegs") - $ Aeson.eitherDecode - $ Aeson.encode - [aesonQQ|{ - "91612ee7b158dc64871a959060973d0f2b8fb6e85ae960f03b8640ac": { - "delegate": "180b3fae61789f61cbdbc69e5f8e1beae9093aa2215e482dc8d89ec9", - "vrf": "e9ef3b5d81d400eb046de696354ff8e84122f505e706e3c86a361cce919a686e" - } - }|] - } + fromRight (error "invalid sgGenDelegs") . Aeson.eitherDecode + $ Aeson.encode [aesonQQ| + {"91612ee7b158dc64871a959060973d0f2b8fb6e85ae960f03b8640ac": { + "delegate": "180b3fae61789f61cbdbc69e5f8e1beae9093aa2215e482dc8d89ec9", + "vrf": "e9ef3b5d81d400eb046de696354ff8e84122f505e706e3c86a361cce919a686e" + }}|] + } + genesisMods - let shelleyGenesis = untag cfgClusterDir "genesis.shelley.json" + let shelleyGenesis = untag cfgClusterDir "genesis-shelley.json" Aeson.encodeFile shelleyGenesis shelleyGenesisData - let yamlToAeson = Yaml.decodeFileThrow @_ @Aeson.Value + let fileToAeson :: FilePath -> IO Aeson.Value + fileToAeson f = Aeson.eitherDecodeFileStrict f >>= either fail pure - let byronGenesis = untag cfgClusterDir "genesis.byron.json" - yamlToAeson (untag cfgClusterConfigs "byron-genesis.yaml") + let byronGenesis = untag cfgClusterDir "genesis-byron.json" + fileToAeson (untag cfgClusterConfigs "genesis-byron.json") >>= withAddedKey "startTime" - (round @_ @Int $ utcTimeToPOSIXSeconds systemStart) + (round @_ @Int $ utcTimeToPOSIXSeconds systemStart) >>= Aeson.encodeFile byronGenesis - let alonzoGenesis = untag cfgClusterDir "genesis.alonzo.json" - yamlToAeson (untag cfgClusterConfigs "alonzo-genesis.yaml") + let alonzoGenesis = untag cfgClusterDir "genesis-alonzo.json" + fileToAeson (untag cfgClusterConfigs "genesis-alonzo.json") >>= Aeson.encodeFile alonzoGenesis - let conwayGenesis = untag cfgClusterDir "conway-genesis.json" - copyFile (untag cfgClusterConfigs "conway-genesis.json") conwayGenesis + let conwayGenesis = untag cfgClusterDir "genesis-conway.json" + copyFile (untag cfgClusterConfigs "genesis-conway.json") conwayGenesis - pure GenesisFiles{..} + pure GenesisFiles + { byronGenesis + , shelleyGenesis + , alonzoGenesis + , conwayGenesis + } data FaucetFunds = FaucetFunds { pureAdaFunds :: [(Address, Coin)] @@ -1248,7 +1262,8 @@ withCluster tr config@Config{..} faucetFunds onClusterStart = generateGenesis config (adaFunds <> map (,Coin 1_000_000_000_000_000) faucetAddresses) - (if postAlonzo then addGenesisPools else federalizeNetwork) + ((if postAlonzo then addGenesisPools else federalizeNetwork) + : cfgShelleyGenesisMods) extraPort : poolsTcpPorts <- randomUnusedTCPPorts (length cfgStakePools + 1) @@ -1723,7 +1738,7 @@ genNodeConfig poolDir setupDir name genesisFiles clusterEra logCfg = do ] let poolNodeConfig = - untag poolDir ("node" <> untag name <> "-config.json") + untag poolDir ("node" <> untag name <> "-config.yaml") Yaml.decodeFileThrow (untag setupDir "node-config.json") >>= withAddedKey "ShelleyGenesisFile" shelleyGenesis @@ -1764,7 +1779,7 @@ genNodeConfig poolDir setupDir name genesisFiles clusterEra logCfg = do ] withAddedKey - :: (MonadFail m, Yaml.ToJSON a) + :: (MonadFail m, Aeson.ToJSON a) => Aeson.Key -> a -> Aeson.Value @@ -2327,7 +2342,7 @@ moveInstantaneousRewardsTo -> CardanoNodeConn -> [(Credential, Coin)] -> IO () -moveInstantaneousRewardsTo tr config conn targets = do +moveInstantaneousRewardsTo tr config conn targets = unless (null targets) $ do let clusterDir = cfgClusterDir config let clusterConfigs = cfgClusterConfigs config let outputDir = retag @"cluster" @_ @"output" clusterDir diff --git a/lib/local-cluster/lib/Cardano/Wallet/LocalCluster.hs b/lib/local-cluster/lib/Cardano/Wallet/LocalCluster.hs index f24ac8a5532..49881ad7b6f 100644 --- a/lib/local-cluster/lib/Cardano/Wallet/LocalCluster.hs +++ b/lib/local-cluster/lib/Cardano/Wallet/LocalCluster.hs @@ -5,6 +5,7 @@ {-# LANGUAGE LambdaCase #-} {-# LANGUAGE NamedFieldPuns #-} {-# LANGUAGE NumericUnderscores #-} +{-# LANGUAGE OverloadedLabels #-} {-# LANGUAGE QuasiQuotes #-} {-# LANGUAGE RecordWildCards #-} {-# LANGUAGE ScopedTypeVariables #-} @@ -45,6 +46,9 @@ import Cardano.Wallet.Primitive.Types.Coin import Control.Applicative ( (<**>) ) +import Control.Lens + ( over + ) import Control.Monad.Trans.Resource ( allocate , runResourceT @@ -215,6 +219,7 @@ main = withUtf8 $ do , cfgClusterDir = Tagged clusterPath , cfgClusterConfigs = clusterConfigsDir , cfgTestnetMagic = Cluster.TestnetMagic 42 + , cfgShelleyGenesisMods = [ over #sgSlotLength \_ -> 0.2 ] } Cluster.withCluster stdoutTextTracer clusterCfg faucetFunds $ \node -> do clusterDir <- Path.parseAbsDir clusterPath diff --git a/lib/local-cluster/test/data/cluster-configs/alonzo-genesis.yaml b/lib/local-cluster/test/data/cluster-configs/alonzo-genesis.yaml deleted file mode 100644 index 8072cc4deab..00000000000 --- a/lib/local-cluster/test/data/cluster-configs/alonzo-genesis.yaml +++ /dev/null @@ -1,363 +0,0 @@ -# Originally taken from https://hydra.iohk.io/build/7578887/download/1/index.html - -lovelacePerUTxOWord: 34482 -executionPrices: - prSteps: - numerator: 721 - denominator: 10000000 - prMem: - numerator: 577 - denominator: 10000 -maxTxExUnits: - exUnitsMem: 10000000 - exUnitsSteps: 10000000000 -maxBlockExUnits: - exUnitsMem: 50000000 - exUnitsSteps: 40000000000 -maxValueSize: 5000 -collateralPercentage: 150 -maxCollateralInputs: 3 -costModels: - PlutusV1: - sha2_256-memory-arguments: 4 - equalsString-cpu-arguments-constant: 1000 - cekDelayCost-exBudgetMemory: 100 - lessThanEqualsByteString-cpu-arguments-intercept: 103599 - divideInteger-memory-arguments-minimum: 1 - appendByteString-cpu-arguments-slope: 621 - blake2b-cpu-arguments-slope: 29175 - iData-cpu-arguments: 150000 - encodeUtf8-cpu-arguments-slope: 1000 - unBData-cpu-arguments: 150000 - multiplyInteger-cpu-arguments-intercept: 61516 - cekConstCost-exBudgetMemory: 100 - nullList-cpu-arguments: 150000 - equalsString-cpu-arguments-intercept: 150000 - trace-cpu-arguments: 150000 - mkNilData-memory-arguments: 32 - lengthOfByteString-cpu-arguments: 150000 - cekBuiltinCost-exBudgetCPU: 29773 - bData-cpu-arguments: 150000 - subtractInteger-cpu-arguments-slope: 0 - unIData-cpu-arguments: 150000 - consByteString-memory-arguments-intercept: 0 - divideInteger-memory-arguments-slope: 1 - divideInteger-cpu-arguments-model-arguments-slope: 118 - listData-cpu-arguments: 150000 - headList-cpu-arguments: 150000 - chooseData-memory-arguments: 32 - equalsInteger-cpu-arguments-intercept: 136542 - sha3_256-cpu-arguments-slope: 82363 - sliceByteString-cpu-arguments-slope: 5000 - unMapData-cpu-arguments: 150000 - lessThanInteger-cpu-arguments-intercept: 179690 - mkCons-cpu-arguments: 150000 - appendString-memory-arguments-intercept: 0 - modInteger-cpu-arguments-model-arguments-slope: 118 - ifThenElse-cpu-arguments: 1 - mkNilPairData-cpu-arguments: 150000 - lessThanEqualsInteger-cpu-arguments-intercept: 145276 - addInteger-memory-arguments-slope: 1 - chooseList-memory-arguments: 32 - constrData-memory-arguments: 32 - decodeUtf8-cpu-arguments-intercept: 150000 - equalsData-memory-arguments: 1 - subtractInteger-memory-arguments-slope: 1 - appendByteString-memory-arguments-intercept: 0 - lengthOfByteString-memory-arguments: 4 - headList-memory-arguments: 32 - listData-memory-arguments: 32 - consByteString-cpu-arguments-intercept: 150000 - unIData-memory-arguments: 32 - remainderInteger-memory-arguments-minimum: 1 - bData-memory-arguments: 32 - lessThanByteString-cpu-arguments-slope: 248 - encodeUtf8-memory-arguments-intercept: 0 - cekStartupCost-exBudgetCPU: 100 - multiplyInteger-memory-arguments-intercept: 0 - unListData-memory-arguments: 32 - remainderInteger-cpu-arguments-model-arguments-slope: 118 - cekVarCost-exBudgetCPU: 29773 - remainderInteger-memory-arguments-slope: 1 - cekForceCost-exBudgetCPU: 29773 - sha2_256-cpu-arguments-slope: 29175 - equalsInteger-memory-arguments: 1 - indexByteString-memory-arguments: 1 - addInteger-memory-arguments-intercept: 1 - chooseUnit-cpu-arguments: 150000 - sndPair-cpu-arguments: 150000 - cekLamCost-exBudgetCPU: 29773 - fstPair-cpu-arguments: 150000 - quotientInteger-memory-arguments-minimum: 1 - decodeUtf8-cpu-arguments-slope: 1000 - lessThanInteger-memory-arguments: 1 - lessThanEqualsInteger-cpu-arguments-slope: 1366 - fstPair-memory-arguments: 32 - modInteger-memory-arguments-intercept: 0 - unConstrData-cpu-arguments: 150000 - lessThanEqualsInteger-memory-arguments: 1 - chooseUnit-memory-arguments: 32 - sndPair-memory-arguments: 32 - addInteger-cpu-arguments-intercept: 197209 - decodeUtf8-memory-arguments-slope: 8 - equalsData-cpu-arguments-intercept: 150000 - mapData-cpu-arguments: 150000 - mkPairData-cpu-arguments: 150000 - quotientInteger-cpu-arguments-constant: 148000 - consByteString-memory-arguments-slope: 1 - cekVarCost-exBudgetMemory: 100 - indexByteString-cpu-arguments: 150000 - unListData-cpu-arguments: 150000 - equalsInteger-cpu-arguments-slope: 1326 - cekStartupCost-exBudgetMemory: 100 - subtractInteger-cpu-arguments-intercept: 197209 - divideInteger-cpu-arguments-model-arguments-intercept: 425507 - divideInteger-memory-arguments-intercept: 0 - cekForceCost-exBudgetMemory: 100 - blake2b-cpu-arguments-intercept: 2477736 - remainderInteger-cpu-arguments-constant: 148000 - tailList-cpu-arguments: 150000 - encodeUtf8-cpu-arguments-intercept: 150000 - equalsString-cpu-arguments-slope: 1000 - lessThanByteString-memory-arguments: 1 - multiplyInteger-cpu-arguments-slope: 11218 - appendByteString-cpu-arguments-intercept: 396231 - lessThanEqualsByteString-cpu-arguments-slope: 248 - modInteger-memory-arguments-slope: 1 - addInteger-cpu-arguments-slope: 0 - equalsData-cpu-arguments-slope: 10000 - decodeUtf8-memory-arguments-intercept: 0 - chooseList-cpu-arguments: 150000 - constrData-cpu-arguments: 150000 - equalsByteString-memory-arguments: 1 - cekApplyCost-exBudgetCPU: 29773 - quotientInteger-memory-arguments-slope: 1 - verifySignature-cpu-arguments-intercept: 3345831 - unMapData-memory-arguments: 32 - mkCons-memory-arguments: 32 - sliceByteString-memory-arguments-slope: 1 - sha3_256-memory-arguments: 4 - ifThenElse-memory-arguments: 1 - mkNilPairData-memory-arguments: 32 - equalsByteString-cpu-arguments-slope: 247 - appendString-cpu-arguments-intercept: 150000 - quotientInteger-cpu-arguments-model-arguments-slope: 118 - cekApplyCost-exBudgetMemory: 100 - equalsString-memory-arguments: 1 - multiplyInteger-memory-arguments-slope: 1 - cekBuiltinCost-exBudgetMemory: 100 - remainderInteger-memory-arguments-intercept: 0 - sha2_256-cpu-arguments-intercept: 2477736 - remainderInteger-cpu-arguments-model-arguments-intercept: 425507 - lessThanEqualsByteString-memory-arguments: 1 - tailList-memory-arguments: 32 - mkNilData-cpu-arguments: 150000 - chooseData-cpu-arguments: 150000 - unBData-memory-arguments: 32 - blake2b-memory-arguments: 4 - iData-memory-arguments: 32 - nullList-memory-arguments: 32 - cekDelayCost-exBudgetCPU: 29773 - subtractInteger-memory-arguments-intercept: 1 - lessThanByteString-cpu-arguments-intercept: 103599 - consByteString-cpu-arguments-slope: 1000 - appendByteString-memory-arguments-slope: 1 - trace-memory-arguments: 32 - divideInteger-cpu-arguments-constant: 148000 - cekConstCost-exBudgetCPU: 29773 - encodeUtf8-memory-arguments-slope: 8 - quotientInteger-cpu-arguments-model-arguments-intercept: 425507 - mapData-memory-arguments: 32 - appendString-cpu-arguments-slope: 1000 - modInteger-cpu-arguments-constant: 148000 - verifySignature-cpu-arguments-slope: 1 - unConstrData-memory-arguments: 32 - quotientInteger-memory-arguments-intercept: 0 - equalsByteString-cpu-arguments-constant: 150000 - sliceByteString-memory-arguments-intercept: 0 - mkPairData-memory-arguments: 32 - equalsByteString-cpu-arguments-intercept: 112536 - appendString-memory-arguments-slope: 1 - lessThanInteger-cpu-arguments-slope: 497 - modInteger-cpu-arguments-model-arguments-intercept: 425507 - modInteger-memory-arguments-minimum: 1 - sha3_256-cpu-arguments-intercept: 0 - verifySignature-memory-arguments: 1 - cekLamCost-exBudgetMemory: 100 - sliceByteString-cpu-arguments-intercept: 150000 - PlutusV2: - addInteger-cpu-arguments-intercept: 205665 - addInteger-cpu-arguments-slope: 812 - addInteger-memory-arguments-intercept: 1 - addInteger-memory-arguments-slope: 1 - appendByteString-cpu-arguments-intercept: 1000 - appendByteString-cpu-arguments-slope: 571 - appendByteString-memory-arguments-intercept: 0 - appendByteString-memory-arguments-slope: 1 - appendString-cpu-arguments-intercept: 1000 - appendString-cpu-arguments-slope: 24177 - appendString-memory-arguments-intercept: 4 - appendString-memory-arguments-slope: 1 - bData-cpu-arguments: 1000 - bData-memory-arguments: 32 - blake2b_256-cpu-arguments-intercept: 117366 - blake2b_256-cpu-arguments-slope: 10475 - blake2b_256-memory-arguments: 4 - cekApplyCost-exBudgetCPU: 23000 - cekApplyCost-exBudgetMemory: 100 - cekBuiltinCost-exBudgetCPU: 23000 - cekBuiltinCost-exBudgetMemory: 100 - cekConstCost-exBudgetCPU: 23000 - cekConstCost-exBudgetMemory: 100 - cekDelayCost-exBudgetCPU: 23000 - cekDelayCost-exBudgetMemory: 100 - cekForceCost-exBudgetCPU: 23000 - cekForceCost-exBudgetMemory: 100 - cekLamCost-exBudgetCPU: 23000 - cekLamCost-exBudgetMemory: 100 - cekStartupCost-exBudgetCPU: 100 - cekStartupCost-exBudgetMemory: 100 - cekVarCost-exBudgetCPU: 23000 - cekVarCost-exBudgetMemory: 100 - chooseData-cpu-arguments: 19537 - chooseData-memory-arguments: 32 - chooseList-cpu-arguments: 175354 - chooseList-memory-arguments: 32 - chooseUnit-cpu-arguments: 46417 - chooseUnit-memory-arguments: 4 - consByteString-cpu-arguments-intercept: 221973 - consByteString-cpu-arguments-slope: 511 - consByteString-memory-arguments-intercept: 0 - consByteString-memory-arguments-slope: 1 - constrData-cpu-arguments: 89141 - constrData-memory-arguments: 32 - decodeUtf8-cpu-arguments-intercept: 497525 - decodeUtf8-cpu-arguments-slope: 14068 - decodeUtf8-memory-arguments-intercept: 4 - decodeUtf8-memory-arguments-slope: 2 - divideInteger-cpu-arguments-constant: 196500 - divideInteger-cpu-arguments-model-arguments-intercept: 453240 - divideInteger-cpu-arguments-model-arguments-slope: 220 - divideInteger-memory-arguments-intercept: 0 - divideInteger-memory-arguments-minimum: 1 - divideInteger-memory-arguments-slope: 1 - encodeUtf8-cpu-arguments-intercept: 1000 - encodeUtf8-cpu-arguments-slope: 28662 - encodeUtf8-memory-arguments-intercept: 4 - encodeUtf8-memory-arguments-slope: 2 - equalsByteString-cpu-arguments-constant: 245000 - equalsByteString-cpu-arguments-intercept: 216773 - equalsByteString-cpu-arguments-slope: 62 - equalsByteString-memory-arguments: 1 - equalsData-cpu-arguments-intercept: 1060367 - equalsData-cpu-arguments-slope: 12586 - equalsData-memory-arguments: 1 - equalsInteger-cpu-arguments-intercept: 208512 - equalsInteger-cpu-arguments-slope: 421 - equalsInteger-memory-arguments: 1 - equalsString-cpu-arguments-constant: 187000 - equalsString-cpu-arguments-intercept: 1000 - equalsString-cpu-arguments-slope: 52998 - equalsString-memory-arguments: 1 - fstPair-cpu-arguments: 80436 - fstPair-memory-arguments: 32 - headList-cpu-arguments: 43249 - headList-memory-arguments: 32 - iData-cpu-arguments: 1000 - iData-memory-arguments: 32 - ifThenElse-cpu-arguments: 80556 - ifThenElse-memory-arguments: 1 - indexByteString-cpu-arguments: 57667 - indexByteString-memory-arguments: 4 - lengthOfByteString-cpu-arguments: 1000 - lengthOfByteString-memory-arguments: 10 - lessThanByteString-cpu-arguments-intercept: 197145 - lessThanByteString-cpu-arguments-slope: 156 - lessThanByteString-memory-arguments: 1 - lessThanEqualsByteString-cpu-arguments-intercept: 197145 - lessThanEqualsByteString-cpu-arguments-slope: 156 - lessThanEqualsByteString-memory-arguments: 1 - lessThanEqualsInteger-cpu-arguments-intercept: 204924 - lessThanEqualsInteger-cpu-arguments-slope: 473 - lessThanEqualsInteger-memory-arguments: 1 - lessThanInteger-cpu-arguments-intercept: 208896 - lessThanInteger-cpu-arguments-slope: 511 - lessThanInteger-memory-arguments: 1 - listData-cpu-arguments: 52467 - listData-memory-arguments: 32 - mapData-cpu-arguments: 64832 - mapData-memory-arguments: 32 - mkCons-cpu-arguments: 65493 - mkCons-memory-arguments: 32 - mkNilData-cpu-arguments: 22558 - mkNilData-memory-arguments: 32 - mkNilPairData-cpu-arguments: 16563 - mkNilPairData-memory-arguments: 32 - mkPairData-cpu-arguments: 76511 - mkPairData-memory-arguments: 32 - modInteger-cpu-arguments-constant: 196500 - modInteger-cpu-arguments-model-arguments-intercept: 453240 - modInteger-cpu-arguments-model-arguments-slope: 220 - modInteger-memory-arguments-intercept: 0 - modInteger-memory-arguments-minimum: 1 - modInteger-memory-arguments-slope: 1 - multiplyInteger-cpu-arguments-intercept: 69522 - multiplyInteger-cpu-arguments-slope: 11687 - multiplyInteger-memory-arguments-intercept: 0 - multiplyInteger-memory-arguments-slope: 1 - nullList-cpu-arguments: 60091 - nullList-memory-arguments: 32 - quotientInteger-cpu-arguments-constant: 196500 - quotientInteger-cpu-arguments-model-arguments-intercept: 453240 - quotientInteger-cpu-arguments-model-arguments-slope: 220 - quotientInteger-memory-arguments-intercept: 0 - quotientInteger-memory-arguments-minimum: 1 - quotientInteger-memory-arguments-slope: 1 - remainderInteger-cpu-arguments-constant: 196500 - remainderInteger-cpu-arguments-model-arguments-intercept: 453240 - remainderInteger-cpu-arguments-model-arguments-slope: 220 - remainderInteger-memory-arguments-intercept: 0 - remainderInteger-memory-arguments-minimum: 1 - remainderInteger-memory-arguments-slope: 1 - serialiseData-cpu-arguments-intercept: 1159724 - serialiseData-cpu-arguments-slope: 392670 - serialiseData-memory-arguments-intercept: 0 - serialiseData-memory-arguments-slope: 2 - sha2_256-cpu-arguments-intercept: 806990 - sha2_256-cpu-arguments-slope: 30482 - sha2_256-memory-arguments: 4 - sha3_256-cpu-arguments-intercept: 1927926 - sha3_256-cpu-arguments-slope: 82523 - sha3_256-memory-arguments: 4 - sliceByteString-cpu-arguments-intercept: 265318 - sliceByteString-cpu-arguments-slope: 0 - sliceByteString-memory-arguments-intercept: 4 - sliceByteString-memory-arguments-slope: 0 - sndPair-cpu-arguments: 85931 - sndPair-memory-arguments: 32 - subtractInteger-cpu-arguments-intercept: 205665 - subtractInteger-cpu-arguments-slope: 812 - subtractInteger-memory-arguments-intercept: 1 - subtractInteger-memory-arguments-slope: 1 - tailList-cpu-arguments: 41182 - tailList-memory-arguments: 32 - trace-cpu-arguments: 212342 - trace-memory-arguments: 32 - unBData-cpu-arguments: 31220 - unBData-memory-arguments: 32 - unConstrData-cpu-arguments: 32696 - unConstrData-memory-arguments: 32 - unIData-cpu-arguments: 43357 - unIData-memory-arguments: 32 - unListData-cpu-arguments: 32247 - unListData-memory-arguments: 32 - unMapData-cpu-arguments: 38314 - unMapData-memory-arguments: 32 - verifyEcdsaSecp256k1Signature-cpu-arguments: 20000000000 - verifyEcdsaSecp256k1Signature-memory-arguments: 20000000000 - verifyEd25519Signature-cpu-arguments-intercept: 9462713 - verifyEd25519Signature-cpu-arguments-slope: 1021 - verifyEd25519Signature-memory-arguments: 10 - verifySchnorrSecp256k1Signature-cpu-arguments-intercept: 20000000000 - verifySchnorrSecp256k1Signature-cpu-arguments-slope: 0 - verifySchnorrSecp256k1Signature-memory-arguments: 20000000000 \ No newline at end of file diff --git a/lib/local-cluster/test/data/cluster-configs/byron-genesis.yaml b/lib/local-cluster/test/data/cluster-configs/byron-genesis.yaml deleted file mode 100644 index ade5033329b..00000000000 --- a/lib/local-cluster/test/data/cluster-configs/byron-genesis.yaml +++ /dev/null @@ -1,35 +0,0 @@ -avvmDistr: {} -blockVersionData: - heavyDelThd: '300000000000' - maxBlockSize: '2000000' - maxHeaderSize: '2000000' - maxProposalSize: '700' - maxTxSize: '4096' - mpcThd: '20000000000000' - scriptVersion: 0 - slotDuration: '20000' - softforkRule: - initThd: '900000000000000' - minThd: '600000000000000' - thdDecrement: '50000000000000' - txFeePolicy: - multiplier: '43946000000' - summand: '155381000000000' - unlockStakeEpoch: '18446744073709551615' - updateImplicit: '10000' - updateProposalThd: '100000000000000' - updateVoteThd: '1000000000000' -bootStakeholders: - dd4194236324c8d89b5f2877eb6b1d5abc23217ecc60076b583902bb: 1 -heavyDelegation: - dd4194236324c8d89b5f2877eb6b1d5abc23217ecc60076b583902bb: - cert: 86fe8c7fd9d6475dceacdd7f50e0b428e176a643ede9d08a186e4817ffed4f12fd38e1c29b68f2af9bf9b89ab1545db88a769ccaa274f15d162ed1682268ac02 - delegatePk: zmgaMKBfDDeex3Q99KG/24K7PwskBuKKw6/g/ssIVTmUaNK5R4l25YSkDHNTVOxwo7jawvwAGxe5RcbwwEULdw== - issuerPk: siJZ1ewbKx9n3AxeFSegymNvyhhRuZd5B0CkbI8mlt6g6kFBqDtseUNOdp3CZorqPhiZdapS5eEOmHNneqWZOg== - omega: 0 -nonAvvmBalances: - 2657WMsDfac5Gwc9G8G47uNRRWXRRBGHssq5SVy8BAGg3jUfFM8tEgvxdiKhDFwEV: '0' - 2657WMsDfac5djvSd1zzLx9Y3fBe81u6jFA85Ct65Qn5tLs8Z8AyWwGjwCLiEcS82: '45000000000000000' -protocolConsts: - k: 108 - protocolMagic: 42 diff --git a/lib/local-cluster/test/data/cluster-configs/alonzo-genesis.json b/lib/local-cluster/test/data/cluster-configs/genesis-alonzo.json similarity index 100% rename from lib/local-cluster/test/data/cluster-configs/alonzo-genesis.json rename to lib/local-cluster/test/data/cluster-configs/genesis-alonzo.json diff --git a/lib/local-cluster/test/data/cluster-configs/byron-genesis.json b/lib/local-cluster/test/data/cluster-configs/genesis-byron.json similarity index 100% rename from lib/local-cluster/test/data/cluster-configs/byron-genesis.json rename to lib/local-cluster/test/data/cluster-configs/genesis-byron.json diff --git a/lib/local-cluster/test/data/cluster-configs/conway-genesis.json b/lib/local-cluster/test/data/cluster-configs/genesis-conway.json similarity index 100% rename from lib/local-cluster/test/data/cluster-configs/conway-genesis.json rename to lib/local-cluster/test/data/cluster-configs/genesis-conway.json diff --git a/lib/local-cluster/test/data/cluster-configs/node-config.json b/lib/local-cluster/test/data/cluster-configs/node-config.json index e7ef446606f..457b1bb45ed 100644 --- a/lib/local-cluster/test/data/cluster-configs/node-config.json +++ b/lib/local-cluster/test/data/cluster-configs/node-config.json @@ -1,9 +1,9 @@ { - "AlonzoGenesisFile": "alonzo-genesis.json", + "AlonzoGenesisFile": "genesis-alonzo.json", "ApplicationName": "cardano-sl", "ApplicationVersion": 0, - "ByronGenesisFile": "byron-genesis.json", - "ConwayGenesisFile": "conway-genesis.json", + "ByronGenesisFile": "genesis-byron.json", + "ConwayGenesisFile": "genesis-conway.json", "EnableP2P": false, "ExperimentalHardForksEnabled": true, "ExperimentalProtocolsEnabled": true, @@ -15,7 +15,7 @@ "PBftSignatureThreshold": 1.1, "Protocol": "Cardano", "RequiresNetworkMagic": "RequiresMagic", - "ShelleyGenesisFile": "shelley-genesis.json", + "ShelleyGenesisFile": "genesis-shelley.json", "TargetNumberOfActivePeers": 20, "TargetNumberOfEstablishedPeers": 50, "TargetNumberOfKnownPeers": 100, @@ -61,7 +61,7 @@ "TraceTxOutbound": false, "TraceTxSubmissionProtocol": false, "TracingVerbosity": "NormalVerbosity", - "TurnOnLogMetrics": true, + "TurnOnLogMetrics": false, "TurnOnLogging": true, "defaultBackends": [ "KatipBK" @@ -72,11 +72,6 @@ "cardano" ] ], - "hasEKG": 12788, - "hasPrometheus": [ - "0.0.0.0", - 12798 - ], "minSeverity": "Debug", "options": { "mapBackends": { @@ -95,7 +90,7 @@ }, "rotation": { "rpKeepFilesNum": 10, - "rpLogLimitBytes": 5000000, + "rpLogLimitBytes": 50000000, "rpMaxAgeHours": 24 }, "setupBackends": [ diff --git a/lib/local-cluster/test/data/cluster-configs/shelley-genesis.json b/lib/local-cluster/test/data/cluster-configs/shelley-genesis.json deleted file mode 100644 index 963de7ae1ac..00000000000 --- a/lib/local-cluster/test/data/cluster-configs/shelley-genesis.json +++ /dev/null @@ -1,48 +0,0 @@ -{ - "activeSlotsCoeff": 5.0e-2, - "epochLength": 21600, - "genDelegs": { - "91612ee7b158dc64871a959060973d0f2b8fb6e85ae960f03b8640ac": { - "delegate": "180b3fae61789f61cbdbc69e5f8e1beae9093aa2215e482dc8d89ec9", - "vrf": "e9ef3b5d81d400eb046de696354ff8e84122f505e706e3c86a361cce919a686e" - } - }, - "initialFunds": {}, - "maxKESEvolutions": 62, - "maxLovelaceSupply": 45000000000000000, - "networkId": "Testnet", - "networkMagic": 42, - "protocolParams": { - "a0": 0.3, - "decentralisationParam": 1.0, - "eMax": 18, - "extraEntropy": { - "tag": "NeutralNonce" - }, - "keyDeposit": 2000000, - "maxBlockBodySize": 65536, - "maxBlockHeaderSize": 1100, - "maxTxSize": 16384, - "minFeeA": 44, - "minFeeB": 155381, - "minPoolCost": 340000000, - "minUTxOValue": 1000000, - "nOpt": 150, - "poolDeposit": 500000000, - "protocolVersion": { - "major": 6, - "minor": 0 - }, - "rho": 3.0e-3, - "tau": 0.2 - }, - "securityParam": 108, - "slotLength": 1, - "slotsPerKESPeriod": 129600, - "staking": { - "pools": {}, - "stake": {} - }, - "systemStart": "2023-10-02T13:59:37.951348047Z", - "updateQuorum": 1 -} \ No newline at end of file diff --git a/lib/std-gen-seed/std-gen-seed.cabal b/lib/std-gen-seed/std-gen-seed.cabal index 5af55e3bc7e..cb6d47104a6 100644 --- a/lib/std-gen-seed/std-gen-seed.cabal +++ b/lib/std-gen-seed/std-gen-seed.cabal @@ -6,7 +6,6 @@ license: Apache-2.0 author: HAL, Cardano Foundation maintainer: hal@cardanofoundation.org build-type: Simple -extra-doc-files: CHANGELOG.md common language default-language: Haskell2010 @@ -63,4 +62,3 @@ test-suite unit std-gen-seed-unit-test.hs other-modules: System.Random.StdGenSeedSpec - diff --git a/lib/wallet/bench/latency-bench.hs b/lib/wallet/bench/latency-bench.hs index 86579d3be70..4e7d4089db7 100644 --- a/lib/wallet/bench/latency-bench.hs +++ b/lib/wallet/bench/latency-bench.hs @@ -1,3 +1,4 @@ +{-# LANGUAGE AllowAmbiguousTypes #-} {-# LANGUAGE DataKinds #-} {-# LANGUAGE DerivingStrategies #-} {-# LANGUAGE FlexibleContexts #-} @@ -19,18 +20,23 @@ import Prelude import Cardano.Address ( Address ) +import Cardano.Address.Style.Shelley + ( shelleyTestnet + ) import Cardano.BM.Data.LogItem ( LogObject ) import Cardano.BM.Data.Severity - ( Severity (..) + ( Severity (Error) ) import Cardano.BM.Data.Tracer - ( contramap - , nullTracer + ( HasSeverityAnnotation + , Tracer (..) + , filterSeverity ) import Cardano.BM.Extra - ( trMessage + ( stdoutTextTracer + , trMessage ) import Cardano.BM.Trace ( traceInTVarIO @@ -44,7 +50,7 @@ import Cardano.Mnemonic , mnemonicToText ) import Cardano.Wallet.Api.Http.Shelley.Server - ( Listen (ListenOnRandomPort) + ( Listen (ListenOnPort) ) import Cardano.Wallet.Api.Types ( ApiAddressWithPath @@ -77,10 +83,11 @@ import Cardano.Wallet.LatencyBenchShared , withLatencyLogging ) import Cardano.Wallet.Launch.Cluster - ( FaucetFunds (..) - , LogFileConfig (..) + ( Config (..) + , FaucetFunds (..) , RunningNode (..) , defaultPoolConfigs + , testnetMagicToNatural , withCluster ) import Cardano.Wallet.LocalCluster @@ -93,7 +100,8 @@ import Cardano.Wallet.Pools ( StakePool ) import Cardano.Wallet.Primitive.NetworkId - ( NetworkDiscriminant (..) + ( HasSNetworkId + , NetworkDiscriminant (..) , NetworkId (..) ) import Cardano.Wallet.Primitive.SyncProgress @@ -105,7 +113,6 @@ import Cardano.Wallet.Primitive.Types.Coin import Cardano.Wallet.Shelley ( Tracers , Tracers' (..) - , nullTracers , serveWallet ) import Cardano.Wallet.Shelley.BlockchainSource @@ -134,15 +141,19 @@ import Data.Aeson import Data.Bifunctor ( bimap ) -import Data.Generics.Internal.VL.Lens - ( (^.) +import Data.Functor.Contravariant + ( (>$<) ) -import Data.List.NonEmpty - ( NonEmpty ((:|)) +import Data.Generics.Internal.VL.Lens + ( over + , (^.) ) import Data.Tagged ( Tagged (..) ) +import Data.Text.Class.Extended + ( ToText + ) import Fmt ( build ) @@ -178,12 +189,14 @@ import System.IO.Temp.Extra , withSystemTempDir ) import Test.Hspec - ( shouldBe + ( HasCallStack + , shouldBe ) import Test.Integration.Framework.DSL ( Context (..) , Headers (..) , Payload (..) + , ResourceT , eventually , expectField , expectResponseCode @@ -217,7 +230,6 @@ import UnliftIO.STM ( TVar ) -import qualified Cardano.Address as CA import qualified Cardano.Wallet.Api.Link as Link import qualified Cardano.Wallet.Launch.Cluster as Cluster import qualified Data.List.NonEmpty as NE @@ -225,19 +237,32 @@ import qualified Data.Text as T import qualified Network.HTTP.Types.Status as HTTP import qualified Options.Applicative as O -main :: forall n. (n ~ 'Mainnet) => IO () -main = withUtf8 $ do +main :: forall n. (n ~ 'Testnet 42) => IO () +main = withUtf8 $ withLatencyLogging setupTracers $ \tracers capture -> - withShelleyServer tracers $ \ctx -> do + withShelleyServer tracers $ \ctx -> walletApiBench @n capture ctx where + onlyErrors :: (HasSeverityAnnotation a, ToText a) => Tracer IO a + onlyErrors = filterSeverity (const $ pure Error) stdoutTextTracer + setupTracers :: TVar [LogObject ApiLog] -> Tracers IO - setupTracers tvar = nullTracers - { apiServerTracer = trMessage $ contramap snd (traceInTVarIO tvar) } + setupTracers tvar = + Tracers + { apiServerTracer = trMessage $ snd >$< traceInTVarIO tvar + , applicationTracer = onlyErrors + , tokenMetadataTracer = onlyErrors + , walletEngineTracer = onlyErrors + , walletDbTracer = onlyErrors + , poolsEngineTracer = onlyErrors + , poolsDbTracer = onlyErrors + , ntpClientTracer = onlyErrors + , networkTracer = onlyErrors + } walletApiBench :: forall n - . (n ~ 'Mainnet) + . HasSNetworkId n => LogCaptureFunc ApiLog () -> Context -> IO () @@ -283,6 +308,7 @@ walletApiBench capture ctx = do fmtTitle "Latencies for 2 fixture wallets with 1000 utxos scenario" runScenario (nFixtureWalletWithUTxOs 2 1_000) + fmtTitle $ "Latencies for 2 fixture wallets with " <> build massiveWalletUTxOSize <> " utxos scenario" @@ -290,6 +316,10 @@ walletApiBench capture ctx = do where -- Creates n fixture wallets and return 3 of them + nFixtureWallet + :: HasCallStack + => Int + -> ResourceT IO (ApiWallet, ApiWallet, ApiWallet, ApiWallet) nFixtureWallet n = do wal1 : wal2 : _ <- replicateM n (fixtureWallet ctx) walMA <- fixtureMultiAssetWallet ctx @@ -311,7 +341,7 @@ walletApiBench capture ctx = do let amtExp val = ((amt * fromIntegral val) + faucetAmt) :: Natural let expInflows = if whole10Rounds > 0 then - [x*batchSize | x<-[1..whole10Rounds]] ++ [lastBit] + [x * batchSize | x <- [1..whole10Rounds]] ++ [lastBit] else [lastBit] let expInflows' = filter (/=0) expInflows @@ -375,7 +405,6 @@ walletApiBench capture ctx = do ] rDel <- request @ApiWallet ctx (Link.deleteWallet @'Shelley wSrc) Default Empty expectResponseCode HTTP.status204 rDel - pure () postTx (wSrc, postTxEndp, pass) wDest amt = do (_, addrs) <- unsafeRequest @[ApiAddressWithPath n] ctx @@ -516,7 +545,6 @@ walletApiBench capture ctx = do }|] fmtResult "postMigration " t12b - pure () where arbitraryStake :: Maybe Coin arbitraryStake = Just $ ada 10_000 @@ -528,11 +556,11 @@ walletApiBench capture ctx = do t <- measureApiLogs capture $ request @ApiNetworkInformation ctx Link.getNetworkInfo Default Empty fmtResult "getNetworkInfo " t - pure () withShelleyServer :: Tracers IO -> (Context -> IO ()) -> IO () withShelleyServer tracers action = do ctx <- newEmptyMVar + let testnetMagic = Cluster.TestnetMagic 42 let setupContext np baseUrl = do let sixtySeconds = 60 * 1_000_000 -- 60s in microseconds manager <- (baseUrl,) <$> newManager (defaultManagerSettings @@ -555,59 +583,65 @@ withShelleyServer tracers action = do , _moveRewardsToScript = error "moveRewardsToScript not available" } - race_ (takeMVar ctx >>= action) (withServer setupContext) + race_ (takeMVar ctx >>= action) (withServer testnetMagic setupContext) where - withServer act = do + withServer cfgTestnetMagic setupAction = do skipCleanup <- SkipCleanup <$> isEnvSet "NO_CLEANUP" - withSystemTempDir nullTracer "latency" skipCleanup $ \dir -> do + withSystemTempDir stdoutTextTracer "latency" skipCleanup $ \dir -> do let db = dir "wallets" createDirectory db - CommandLineOptions { clusterConfigsDir } <- parseCommandLineOptions - let clusterConfig = Cluster.Config - { Cluster.cfgStakePools = NE.head defaultPoolConfigs :| [] - , Cluster.cfgLastHardFork = maxBound - , Cluster.cfgNodeLogging = LogFileConfig Error Nothing Error - , Cluster.cfgClusterDir = Tagged @"cluster" dir - , Cluster.cfgClusterConfigs = clusterConfigsDir - , Cluster.cfgTestnetMagic = testnetMagic - } + CommandLineOptions{clusterConfigsDir} <- parseCommandLineOptions + clusterEra <- Cluster.clusterEraFromEnv + cfgNodeLogging <- + Cluster.logFileConfigFromEnv + (Just (Cluster.clusterEraToString clusterEra)) withCluster - nullTracer clusterConfig faucetFunds (onClusterStart act db) - - testnetMagic = Cluster.TestnetMagic 42 - - faucetFunds = FaucetFunds - { pureAdaFunds = - let networkTag = CA.NetworkTag - (fromIntegral (Cluster.testnetMagicToNatural testnetMagic)) - in shelleyIntegrationTestFunds networkTag - <> byronIntegrationTestFunds networkTag - <> massiveWalletFunds - , maFunds = - maryIntegrationTestFunds (Coin 10_000_000) - , mirFunds = [] -- not needed - } - - onClusterStart act db (RunningNode conn genesisData vData) = do - let (np, block0, _gp) = fromGenesisData genesisData - listen = ListenOnRandomPort + stdoutTextTracer + Cluster.Config + { cfgStakePools = pure (NE.head defaultPoolConfigs) + , cfgLastHardFork = clusterEra + , cfgNodeLogging + , cfgClusterDir = Tagged @"cluster" dir + , cfgClusterConfigs = clusterConfigsDir + , cfgTestnetMagic + , cfgShelleyGenesisMods = + [ over #sgSlotLength (const 0.2) + -- to avoid "PastHorizonException" errors, as wallet + -- doesn't keep up with retrieving fresh time interpreter. + , over #sgSecurityParam (const 100) + -- when it low then cluster is not making blocks; + ] + } + FaucetFunds + { pureAdaFunds = + shelleyIntegrationTestFunds shelleyTestnet + <> byronIntegrationTestFunds shelleyTestnet + <> massiveWalletFunds + , maFunds = maryIntegrationTestFunds (Coin 10_000_000) + , mirFunds = [] + } + (onClusterStart cfgTestnetMagic setupAction db) + + onClusterStart testnetMagic setupAction db node = do + let (RunningNode conn genesisData vData) = node + let (networkParameters, block0, _gp) = fromGenesisData genesisData serveWallet (NodeSource conn vData (SyncTolerance 10)) - np + networkParameters tunedForMainnetPipeliningStrategy - NMainnet - [] + (NTestnet . fromIntegral $ testnetMagicToNatural testnetMagic) + [] -- pool certificates tracers (Just db) - Nothing + Nothing -- db decorator "127.0.0.1" - listen - Nothing - Nothing - Nothing + (ListenOnPort 8090) + Nothing -- tls configuration + Nothing -- settings + Nothing -- token metadata server block0 - (act np) + (setupAction networkParameters) -- | A special Shelley Wallet with a massive UTxO set massiveWallet :: Mnemonic 15 @@ -633,7 +667,6 @@ massiveWalletAmt = ada 1_000 era :: ApiEra era = maxBound - -------------------------------------------------------------------------------- -- Command line options -------------------------------------------------------- diff --git a/lib/wallet/bench/src/Cardano/Wallet/LatencyBenchShared.hs b/lib/wallet/bench/src/Cardano/Wallet/LatencyBenchShared.hs index 177003cd909..e5e7d27ecd5 100644 --- a/lib/wallet/bench/src/Cardano/Wallet/LatencyBenchShared.hs +++ b/lib/wallet/bench/src/Cardano/Wallet/LatencyBenchShared.hs @@ -43,6 +43,7 @@ import Data.Maybe ) import Data.Time ( NominalDiffTime + , UTCTime ) import Data.Time.Clock ( diffUTCTime @@ -112,7 +113,8 @@ sampleNTimes = 10 -- | Measure how long an action takes based on trace points and taking an -- average of results over a short time period. measureLatency - :: (msg -> Bool) -- ^ Predicate for start message + :: Show msg + => (msg -> Bool) -- ^ Predicate for start message -> (msg -> Bool) -- ^ Predicate for end message -> LogCaptureFunc msg () -- ^ Log capture function. -> IO a -- ^ Action to run @@ -124,25 +126,49 @@ measureLatency start finish capture action = do -- | Scan through iohk-monitoring logs and extract time differences between -- start and end messages. extractTimings - :: (a -> Bool) -- ^ Predicate for start message + :: forall a + . Show a + => (a -> Bool) -- ^ Predicate for start message -> (a -> Bool) -- ^ Predicate for end message -> [LogObject a] -- ^ Log messages -> [NominalDiffTime] -extractTimings isStart isFinish msgs = map2 mkDiff filtered +extractTimings isStart isFinish msgs = map2 mkDiff $ + if even (length filtered) + then filtered + else error "start trace without matching finish trace" where + map2 :: ((Bool, UTCTime, LOContent a) + -> (Bool, UTCTime, LOContent a) + -> NominalDiffTime) + -> [(Bool, UTCTime, LOContent a)] + -> [NominalDiffTime] map2 _ [] = [] - map2 f (a:b:xs) = (f a b:map2 f xs) + map2 f (a : b : xs) = (f a b : map2 f xs) map2 _ _ = error "start trace without matching finish trace" - mkDiff (False, start) (True, finish) = diffUTCTime finish start - mkDiff (False, _) _ = error "missing finish trace" - mkDiff (True, _) _ = error "missing start trace" + mkDiff :: (Bool, UTCTime, LOContent a) + -> (Bool, UTCTime, LOContent a) + -> NominalDiffTime + mkDiff (False, start, _) (True, finish, _) = diffUTCTime finish start + mkDiff (False, _time, logContent) _ = + error $ "Missing finish trace for " <> show logContent + mkDiff (True, _time, logContent) _ = + error $ "Missing start trace for " <> show logContent + filtered :: [(Bool, UTCTime, LOContent a)] filtered = mapMaybe filterMsg msgs - filterMsg logObj = case loContent logObj of - LogMessage msg | isStart msg -> Just (False, getTimestamp logObj) - LogMessage msg | isFinish msg -> Just (True, getTimestamp logObj) - _ -> Nothing + + filterMsg :: LogObject a -> Maybe (Bool, UTCTime, LOContent a) + filterMsg logObj = do + let content = loContent logObj + case content of + LogMessage msg | isStart msg -> + Just (False, getTimestamp logObj, content) + LogMessage msg | isFinish msg -> + Just (True, getTimestamp logObj, content) + _logMessage -> Nothing + + getTimestamp :: LogObject a -> UTCTime getTimestamp = tstamp . loMeta type LogCaptureFunc msg b = IO b -> IO ([LogObject msg], b) diff --git a/lib/wallet/cardano-wallet.cabal b/lib/wallet/cardano-wallet.cabal index ebec2663d18..9aa08a3e545 100644 --- a/lib/wallet/cardano-wallet.cabal +++ b/lib/wallet/cardano-wallet.cabal @@ -1025,6 +1025,7 @@ benchmark latency , cardano-wallet-api-http , cardano-wallet-application-extras , cardano-wallet-integration + , cardano-wallet-launcher , cardano-wallet-primitive , directory , filepath diff --git a/lib/wallet/integration/src/Test/Integration/Framework/DSL.hs b/lib/wallet/integration/src/Test/Integration/Framework/DSL.hs index 697a9cf9382..606f2f9e291 100644 --- a/lib/wallet/integration/src/Test/Integration/Framework/DSL.hs +++ b/lib/wallet/integration/src/Test/Integration/Framework/DSL.hs @@ -1816,6 +1816,7 @@ rewardWallet ctx = do fixtureMultiAssetWallet :: MonadIO m + => HasCallStack => Context -> ResourceT m ApiWallet fixtureMultiAssetWallet = fmap fst . fixtureWalletWithMnemonics (Proxy @"ma") @@ -2243,13 +2244,14 @@ fixturePassphraseEncrypted = -- wallets through small blocks of @runResourceT@ (e.g. once per test). It -- doesn't return @ReleaseKey@ since manual releasing is not needed. fixtureWallet - :: MonadIO m + :: (HasCallStack, MonadIO m) => Context -> ResourceT m ApiWallet fixtureWallet = fmap fst . fixtureWalletWithMnemonics (Proxy @"shelley") fixtureWalletWithMnemonics - :: forall m scheme. (MonadIO m, NextWallet scheme) + :: forall m scheme + . (HasCallStack, MonadIO m, NextWallet scheme) => Proxy scheme -> Context -> ResourceT m (ApiWallet, [Text]) @@ -2262,21 +2264,19 @@ fixtureWalletWithMnemonics _ ctx = snd <$> allocate create (free . fst) "mnemonic_sentence": #{mnemonics}, "passphrase": #{fixturePassphrase} } |] - r <- request @ApiWallet ctx - (Link.postWallet @'Shelley) Default payload + r <- request @ApiWallet ctx (Link.postWallet @'Shelley) Default payload expectResponseCode HTTP.status201 r let w = getResponse r - race (threadDelay sixtySeconds) (checkBalance w) >>= \case + race (threadDelay (60 * oneSecond)) (checkBalance w) >>= \case Left _ -> expectationFailure' "fixtureWallet: waited too long for initial transaction" Right a -> return (a, mnemonics) free w = void $ request @Aeson.Value ctx (Link.deleteWallet @'Shelley w) Default Empty - sixtySeconds = 60*oneSecond + checkBalance w = do - r <- request @ApiWallet ctx - (Link.getWallet @'Shelley w) Default Empty + r <- request @ApiWallet ctx (Link.getWallet @'Shelley w) Default Empty if getFromResponse (#balance . #available) r > Quantity 0 then return (getResponse r) else threadDelay oneSecond *> checkBalance w diff --git a/lib/wallet/src/Cardano/Wallet.hs b/lib/wallet/src/Cardano/Wallet.hs index 0bb29afefdd..18e92af619c 100644 --- a/lib/wallet/src/Cardano/Wallet.hs +++ b/lib/wallet/src/Cardano/Wallet.hs @@ -751,6 +751,9 @@ import GHC.Generics import GHC.Num ( Natural ) +import GHC.Stack + ( HasCallStack + ) import GHC.TypeNats ( Nat ) @@ -1065,8 +1068,7 @@ readDelegation walletState = do -- In the event that wall clock time is too far ahead of the node, -- we return the epoch of the node tip. getCurrentEpochSlotting - :: NetworkLayer IO block - -> IO CurrentEpochSlotting + :: HasCallStack => NetworkLayer IO block -> IO CurrentEpochSlotting getCurrentEpochSlotting nl = do epoch <- getCurrentEpoch mkCurrentEpochSlotting ti epoch diff --git a/lib/wallet/src/Cardano/Wallet/Primitive/Slotting.hs b/lib/wallet/src/Cardano/Wallet/Primitive/Slotting.hs index 98141729974..2058b67ed36 100644 --- a/lib/wallet/src/Cardano/Wallet/Primitive/Slotting.hs +++ b/lib/wallet/src/Cardano/Wallet/Primitive/Slotting.hs @@ -528,8 +528,7 @@ interpretQuery (TimeInterpreter getI start tr handleRes) qry = do i <- getI let res = runQuery start i qry case res of - Left e -> do - traceWith tr $ MsgInterpreterPastHorizon Nothing start e + Left e -> traceWith tr $ MsgInterpreterPastHorizon Nothing start e Right _ -> pure () handleRes res diff --git a/lib/wallet/test/integration/shelley-integration-test.hs b/lib/wallet/test/integration/shelley-integration-test.hs index 54fd3204495..8a4f5f2c6bb 100644 --- a/lib/wallet/test/integration/shelley-integration-test.hs +++ b/lib/wallet/test/integration/shelley-integration-test.hs @@ -390,6 +390,7 @@ specWithServer testnetMagic testDir (tr, tracers) = aroundAll withContext , cfgClusterDir = Tagged @"cluster" testDir , cfgClusterConfigs = clusterConfigs , cfgTestnetMagic = testnetMagic + , cfgShelleyGenesisMods = [] } putMVar ctx Context @@ -443,12 +444,13 @@ specWithServer testnetMagic testDir (tr, tracers) = aroundAll withContext bracketTracer' tr "withServer" $ withSMASH tr' testDir $ \smashUrl -> do let clusterConfig = Cluster.Config - { Cluster.cfgStakePools = Cluster.defaultPoolConfigs - , Cluster.cfgLastHardFork = BabbageHardFork - , Cluster.cfgNodeLogging = LogFileConfig Info Nothing Info - , Cluster.cfgClusterDir = Tagged @"cluster" testDir - , Cluster.cfgClusterConfigs = clusterConfigs - , Cluster.cfgTestnetMagic = testnetMagic + { cfgStakePools = Cluster.defaultPoolConfigs + , cfgLastHardFork = BabbageHardFork + , cfgNodeLogging = LogFileConfig Info Nothing Info + , cfgClusterDir = Tagged @"cluster" testDir + , cfgClusterConfigs = clusterConfigs + , cfgTestnetMagic = testnetMagic + , cfgShelleyGenesisMods = [] } withCluster tr' clusterConfig faucetFunds $ onClusterStart (onReady $ T.pack smashUrl) dbDecorator diff --git a/lib/wallet/test/unit/Cardano/Wallet/Shelley/NetworkSpec.hs b/lib/wallet/test/unit/Cardano/Wallet/Shelley/NetworkSpec.hs index 23c508748ca..f1cb0350809 100644 --- a/lib/wallet/test/unit/Cardano/Wallet/Shelley/NetworkSpec.hs +++ b/lib/wallet/test/unit/Cardano/Wallet/Shelley/NetworkSpec.hs @@ -1,4 +1,5 @@ {-# LANGUAGE DataKinds #-} +{-# LANGUAGE NamedFieldPuns #-} {-# LANGUAGE ScopedTypeVariables #-} {-# LANGUAGE TypeApplications #-} @@ -19,6 +20,7 @@ import Cardano.Launcher.Node import Cardano.Wallet.Launch.Cluster ( ClusterEra (..) , ClusterLog (..) + , Config (..) , LogFileConfig (..) , RunningNode (..) , defaultPoolConfigs @@ -319,12 +321,13 @@ withTestNode tr action = do cfgClusterConfigs <- Tagged @"cluster-configs" <$> getEnv "LOCAL_CLUSTER_CONFIGS" let clusterConfig = Cluster.Config - { Cluster.cfgStakePools = defaultPoolConfigs - , Cluster.cfgLastHardFork = BabbageHardFork - , Cluster.cfgNodeLogging = LogFileConfig Info Nothing Info - , Cluster.cfgClusterDir = Tagged @"cluster" dir - , Cluster.cfgClusterConfigs = cfgClusterConfigs - , Cluster.cfgTestnetMagic = Cluster.TestnetMagic 42 + { cfgStakePools = defaultPoolConfigs + , cfgLastHardFork = BabbageHardFork + , cfgNodeLogging = LogFileConfig Info Nothing Info + , cfgClusterDir = Tagged @"cluster" dir + , cfgClusterConfigs + , cfgTestnetMagic = Cluster.TestnetMagic 42 + , cfgShelleyGenesisMods = [] } withCluster tr clusterConfig mempty $ \(RunningNode sock genesisData vData) -> do