@@ -21,7 +21,7 @@ import Cardano.Ledger.Shelley.Genesis (
21
21
)
22
22
import Cardano.Ledger.Shelley.LedgerState
23
23
import Cardano.Ledger.State
24
- import Cardano.Ledger.State.UTxO (CurrentEra , readNewEpochState )
24
+ import Cardano.Ledger.State.UTxO (CurrentEra , readHexUTxO , readNewEpochState )
25
25
import Cardano.Ledger.UMap
26
26
import Cardano.Ledger.Val
27
27
import Cardano.Slotting.EpochInfo (fixedEpochInfo )
@@ -40,7 +40,7 @@ import Data.MapExtras (extractKeys, extractKeysSmallSet)
40
40
import Data.Set (Set )
41
41
import qualified Data.Set as Set
42
42
import GHC.Stack (HasCallStack )
43
- import Lens.Micro ((^.) )
43
+ import Lens.Micro ((&) , (.~) , ( ^.) )
44
44
import System.Environment (getEnv )
45
45
import System.Exit (die )
46
46
import System.Random.Stateful
@@ -49,11 +49,27 @@ import Test.Cardano.Ledger.Core.Arbitrary (uniformSubSet)
49
49
50
50
main :: IO ()
51
51
main = do
52
- let ledgerVarName = " BENCH_LEDGER_STATE_PATH "
53
- genesisVarName = " BENCH_GENESIS_PATH "
54
- ledgerStateFilePath <- getEnv ledgerVarName
52
+ let genesisVarName = " BENCH_GENESIS_PATH "
53
+ utxoVarName = " BENCH_UTXO_PATH "
54
+ ledgerStateVarName = " BENCH_LEDGER_STATE_PATH "
55
55
genesisFilePath <- getEnv genesisVarName
56
+ utxoFilePath <- getEnv utxoVarName
57
+ ledgerStateFilePath <- getEnv ledgerStateVarName
58
+
56
59
genesis <- either error id <$> eitherDecodeFileStrict' genesisFilePath
60
+ putStrLn $ " Importing UTxO from: " ++ show utxoFilePath
61
+ utxo <- readHexUTxO utxoFilePath
62
+ putStrLn " Done importing UTxO"
63
+ putStrLn $ " Importing NewEpochState from: " ++ show ledgerStateFilePath
64
+ es' <- readNewEpochState ledgerStateFilePath
65
+ putStrLn " Done importing NewEpochState"
66
+
67
+ let nesUTxOL = nesEsL . esLStateL . lsUTxOStateL . utxoL
68
+ es = es' & nesUTxOL .~ utxo
69
+ utxoMap = unUTxO utxo
70
+ utxoSize = Map. size utxoMap
71
+ largeKeysNum = 100000
72
+ stdGen = mkStdGen 2022
57
73
58
74
let toMempoolState :: NewEpochState CurrentEra -> MempoolState CurrentEra
59
75
toMempoolState NewEpochState {nesEs = EpochState {esLState}} = esLState
@@ -62,20 +78,15 @@ main = do
62
78
applyTx' mempoolEnv mempoolState =
63
79
either (error . show ) seqTuple
64
80
. applyTx globals mempoolEnv mempoolState
65
- reapplyTx' mempoolEnv mempoolState tx =
66
- case reapplyTx globals mempoolEnv mempoolState tx of
67
- Left err -> error (show err)
68
- Right st -> st
69
- putStrLn $ " Importing NewEpochState from: " ++ show ledgerStateFilePath
70
- es <- readNewEpochState ledgerStateFilePath
71
- putStrLn " Done importing NewEpochState"
72
- let utxoMap = unUTxO $ getUTxO es
73
- utxoSize = Map. size utxoMap
74
- largeKeysNum = 100000
75
- stdGen = mkStdGen 2022
81
+ reapplyTx' mempoolEnv mempoolState =
82
+ either (error . show ) id
83
+ . reapplyTx globals mempoolEnv mempoolState
84
+
76
85
when (utxoSize < largeKeysNum) $
77
- die $ " UTxO size is too small (" <> show utxoSize <> " < " <> show largeKeysNum <> " )"
86
+ die $
87
+ " UTxO size is too small (" <> show utxoSize <> " < " <> show largeKeysNum <> " )"
78
88
largeKeys <- selectRandomMapKeys 100000 stdGen utxoMap
89
+
79
90
defaultMain
80
91
[ env (pure (mkMempoolEnv es slotNo, toMempoolState es)) $ \ ~ (mempoolEnv, mempoolState) ->
81
92
bgroup
@@ -103,15 +114,15 @@ main = do
103
114
(pure [validatedTx1, validatedTx2, validatedTx3])
104
115
$ bench " Tx1+Tx2+Tx3" . whnf (F. foldl' (\ ms -> fst . applyTx' mempoolEnv ms . extractTx) mempoolState)
105
116
]
106
- , env (pure (getUTxO es)) $ \ utxo ->
117
+ , env (pure utxo) $ \ utxo' ->
107
118
bgroup
108
119
" UTxO"
109
- [ bench " balance" $ nf balance utxo
110
- , bench " coinBalance" $ nf coinBalance utxo
120
+ [ bench " balance" $ nf balance utxo'
121
+ , bench " coinBalance" $ nf coinBalance utxo'
111
122
, -- We need to filter out all multi-assets to prevent `areAllAdaOnly`
112
123
-- from short circuiting and producing results that are way better
113
124
-- than the worst case
114
- env (pure $ Map. filter (\ txOut -> isAdaOnly (txOut ^. valueTxOutL)) $ unUTxO utxo) $
125
+ env (pure $ Map. filter (\ txOut -> isAdaOnly (txOut ^. valueTxOutL)) $ unUTxO utxo' ) $
115
126
bench " areAllAdaOnly" . nf areAllAdaOnly
116
127
]
117
128
, env (pure es) $ \ newEpochState ->
0 commit comments