@@ -27,6 +27,7 @@ import Cardano.Ledger.Val
27
27
import Cardano.Slotting.EpochInfo (fixedEpochInfo )
28
28
import Cardano.Slotting.Time (mkSlotLength )
29
29
import Control.DeepSeq
30
+ import Control.Monad (when )
30
31
import Criterion.Main
31
32
import Data.Aeson
32
33
import Data.Bifunctor (first )
@@ -41,6 +42,7 @@ import qualified Data.Set as Set
41
42
import GHC.Stack (HasCallStack )
42
43
import Lens.Micro ((^.) )
43
44
import System.Environment (getEnv )
45
+ import System.Exit (die )
44
46
import System.Random.Stateful
45
47
import Test.Cardano.Ledger.Api.State.Query (getFilteredDelegationsAndRewardAccounts )
46
48
import Test.Cardano.Ledger.Core.Arbitrary (uniformSubSet )
@@ -67,9 +69,13 @@ main = do
67
69
putStrLn $ " Importing NewEpochState from: " ++ show ledgerStateFilePath
68
70
es <- readNewEpochState ledgerStateFilePath
69
71
putStrLn " Done importing NewEpochState"
70
- let largeKeysNum = 100000
72
+ let utxoMap = unUTxO $ getUTxO es
73
+ utxoSize = Map. size utxoMap
74
+ largeKeysNum = 100000
71
75
stdGen = mkStdGen 2022
72
- largeKeys <- selectRandomMapKeys 100000 stdGen (unUTxO (getUTxO es))
76
+ when (utxoSize < largeKeysNum) $
77
+ die $ " UTxO size is too small (" <> show utxoSize <> " < " <> show largeKeysNum <> " )"
78
+ largeKeys <- selectRandomMapKeys 100000 stdGen utxoMap
73
79
defaultMain
74
80
[ env (pure (mkMempoolEnv es slotNo, toMempoolState es)) $ \ ~ (mempoolEnv, mempoolState) ->
75
81
bgroup
@@ -109,9 +115,8 @@ main = do
109
115
bench " areAllAdaOnly" . nf areAllAdaOnly
110
116
]
111
117
, env (pure es) $ \ newEpochState ->
112
- let utxo = getUTxO es
113
- (_, minTxOut) = Map. findMin $ unUTxO utxo
114
- (_, maxTxOut) = Map. findMax $ unUTxO utxo
118
+ let (_, minTxOut) = Map. findMin utxoMap
119
+ (_, maxTxOut) = Map. findMax utxoMap
115
120
setAddr =
116
121
Set. fromList [minTxOut ^. addrTxOutL, maxTxOut ^. addrTxOutL]
117
122
in bgroup
@@ -141,10 +146,10 @@ main = do
141
146
]
142
147
, bgroup
143
148
" DeleteTxOuts"
144
- [ extractKeysBench (unUTxO (getUTxO es)) largeKeysNum largeKeys
145
- , extractKeysBench (unUTxO (getUTxO es)) 9 (Set. take 9 largeKeys)
146
- , extractKeysBench (unUTxO (getUTxO es)) 5 (Set. take 5 largeKeys)
147
- , extractKeysBench (unUTxO (getUTxO es)) 2 (Set. take 2 largeKeys)
149
+ [ extractKeysBench utxoMap largeKeysNum largeKeys
150
+ , extractKeysBench utxoMap 9 (Set. take 9 largeKeys)
151
+ , extractKeysBench utxoMap 5 (Set. take 5 largeKeys)
152
+ , extractKeysBench utxoMap 2 (Set. take 2 largeKeys)
148
153
]
149
154
]
150
155
0 commit comments