Skip to content

Commit

Permalink
Merge pull request #3998 from cardano-foundation/paolino/ADP-3076/fix…
Browse files Browse the repository at this point in the history
…-benchmarks-after-delegation-migration

[ADP-3076] fix benchmarks, after new migration library
  • Loading branch information
paolino authored Jun 23, 2023
2 parents ba1f811 + ff7ba2b commit 3e97810
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 10 deletions.
25 changes: 18 additions & 7 deletions lib/wallet/bench/db-bench.hs
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@
{-# LANGUAGE InstanceSigs #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE NumericUnderscores #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TupleSections #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE TypeFamilies #-}

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

-- |
Expand Down Expand Up @@ -86,10 +88,16 @@ import Cardano.Wallet.Address.Keys.SequentialAny
( mkSeqStateFromRootXPrv )
import Cardano.Wallet.Address.Keys.WalletKey
( publicKey )
import Cardano.Wallet.BenchShared
( withTempSqliteFile )
import Cardano.Wallet.DB
( DBFresh (..), DBLayer (..), DBLayerParams (..) )
import Cardano.Wallet.DB.Layer
( PersistAddressBook, WalletDBLog (..), withDBFresh )
( DefaultFieldValues (..)
, PersistAddressBook
, WalletDBLog (..)
, withDBFresh
)
import Cardano.Wallet.DummyTarget.Primitive.Types
( block0, dummyGenesisParameters, mkTxId )
import Cardano.Wallet.Flavor
Expand Down Expand Up @@ -197,8 +205,6 @@ import Test.Utils.Resource
( unBracket )
import UnliftIO.Exception
( bracket )
import UnliftIO.Temporary
( withSystemTempFile )

import qualified Cardano.BM.Configuration.Model as CM
import qualified Cardano.BM.Data.BackendKind as CM
Expand Down Expand Up @@ -722,9 +728,6 @@ instance NFData (BenchEnv s) where
rnf :: BenchEnv s -> ()
rnf _ = ()

withTempSqliteFile :: (FilePath -> IO a) -> IO a
withTempSqliteFile action = withSystemTempFile "bench.db" $ \fp _ -> action fp

setupDB
:: forall s
. ( PersistAddressBook s
Expand All @@ -738,7 +741,7 @@ setupDB tr = do
where
withSetup action = withTempSqliteFile $ \fp -> do
withDBFresh (walletFlavor @s)
tr Nothing fp singleEraInterpreter testWid
tr (Just defaultFieldValues) fp singleEraInterpreter testWid
$ \db -> action (fp, db)

singleEraInterpreter :: TimeInterpreter IO
Expand Down Expand Up @@ -774,6 +777,14 @@ withCleanDB tr f g = perRunEnvWithCleanup setup (dbDown . fst) $
x <- f dbFresh
pure (be , x)

defaultFieldValues :: DefaultFieldValues
defaultFieldValues = DefaultFieldValues
{ defaultActiveSlotCoefficient = ActiveSlotCoefficient 1.0
, defaultDesiredNumberOfPool = 0
, defaultMinimumUTxOValue = Coin 1_000_000
, defaultHardforkEpoch = Nothing
, defaultKeyDeposit = Coin 2_000_000
}
----------------------------------------------------------------------------
-- Mock data to use for benchmarks

Expand Down
5 changes: 2 additions & 3 deletions lib/wallet/bench/restore-bench.hs
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ import Cardano.Wallet.BenchShared
, execBenchWithNode
, initBenchmarkLogging
, runBenchmarks
, withTempSqliteFile
)
import Cardano.Wallet.DB
( DBFresh )
Expand Down Expand Up @@ -235,8 +236,6 @@ import UnliftIO.Concurrent
( forkIO, threadDelay )
import UnliftIO.Exception
( evaluate, throwString )
import UnliftIO.Temporary
( withSystemTempFile )

import qualified Cardano.Wallet as W
import qualified Cardano.Wallet.Address.Derivation.Byron as Byron
Expand Down Expand Up @@ -832,7 +831,7 @@ withBenchDBLayer
-> (DBFresh IO s -> IO a)
-> IO a
withBenchDBLayer ti tr wid action =
withSystemTempFile "bench.db" $ \dbFile _ ->
withTempSqliteFile $ \dbFile ->
withDBFresh (walletFlavor @s) tr'
(Just migrationDefaultValues) dbFile ti wid action
where
Expand Down
7 changes: 7 additions & 0 deletions lib/wallet/bench/src/Cardano/Wallet/BenchShared.hs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ module Cardano.Wallet.BenchShared
, runBenchmarks
, bench
, Time
, withTempSqliteFile
) where

import Prelude
Expand Down Expand Up @@ -285,3 +286,9 @@ initBenchmarkLogging name minSeverity = do
CM.setSetupBackends c [CM.KatipBK, CM.AggregationBK]
(tr, _sb) <- setupTrace_ c name
pure (c, tr)

withTempSqliteFile :: (FilePath -> IO a) -> IO a
withTempSqliteFile action =
withSystemTempDirectory "bench-restoration" $ \dir -> do
let path = dir </> "restoration.db"
action path
1 change: 1 addition & 0 deletions lib/wallet/cardano-wallet.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -1094,6 +1094,7 @@ benchmark db
, cardano-api
, cardano-crypto
, cardano-wallet
, cardano-wallet-bench
, cardano-wallet-launcher
, cardano-wallet-primitive
, cardano-wallet-test-utils
Expand Down

0 comments on commit 3e97810

Please sign in to comment.