Skip to content

Commit d90370f

Browse files
committed
Allow predicate failures from applyTx
This is a temporary measure until the embedded transactions are fixed for Conway. With this change it's possible to run the benchmarks but they're measuring failing transactions which isn't representative of real traffic.
1 parent 5c059ef commit d90370f

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

libs/ledger-state/bench/Performance.hs

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{-# LANGUAGE BangPatterns #-}
22
{-# LANGUAGE FlexibleContexts #-}
3+
{-# LANGUAGE LambdaCase #-}
34
{-# LANGUAGE NamedFieldPuns #-}
45
{-# LANGUAGE OverloadedStrings #-}
56
{-# LANGUAGE TypeApplications #-}
@@ -11,6 +12,10 @@ import Cardano.Ledger.Api.Era
1112
import Cardano.Ledger.Api.State.Query (queryStakePoolDelegsAndRewards)
1213
import Cardano.Ledger.BaseTypes
1314
import Cardano.Ledger.Binary
15+
import Cardano.Ledger.Conway.Rules (
16+
ConwayLedgerPredFailure (ConwayUtxowFailure),
17+
ConwayUtxowPredFailure (InvalidWitnessesUTXOW),
18+
)
1419
import Cardano.Ledger.Core
1520
import Cardano.Ledger.Shelley.API.Mempool
1621
import Cardano.Ledger.Shelley.API.Wallet (getFilteredUTxO, getUTxO)
@@ -30,10 +35,11 @@ import Control.DeepSeq
3035
import Control.Monad (when)
3136
import Criterion.Main
3237
import Data.Aeson
33-
import Data.Bifunctor (first)
38+
import Data.Bifunctor (bimap, first)
3439
import Data.ByteString.Base16.Lazy as BSL16
3540
import Data.ByteString.Lazy (ByteString)
3641
import Data.Foldable as F
42+
import Data.List.NonEmpty (NonEmpty ((:|)))
3743
import Data.Map.Strict (Map)
3844
import qualified Data.Map.Strict as Map
3945
import Data.MapExtras (extractKeys, extractKeysSmallSet)
@@ -75,8 +81,12 @@ main = do
7581
toMempoolState NewEpochState {nesEs = EpochState {esLState}} = esLState
7682
!globals = mkGlobals genesis
7783
!slotNo = SlotNo 55733343
84+
restrictError = \case
85+
ApplyTxError (ConwayUtxowFailure (InvalidWitnessesUTXOW [_]) :| []) -> ()
86+
otherErr -> error . show $ otherErr
7887
applyTx' mempoolEnv mempoolState =
79-
either (error . show) seqTuple
88+
-- TODO: revert this to `either (error . show) seqTuple` after tx's are fixed
89+
bimap restrictError seqTuple
8090
. applyTx globals mempoolEnv mempoolState
8191
reapplyTx' mempoolEnv mempoolState =
8292
either (error . show) id
@@ -112,7 +122,9 @@ main = do
112122
bench "Tx3" . whnf (applyTx' mempoolEnv mempoolState)
113123
, env
114124
(pure [validatedTx1, validatedTx2, validatedTx3])
115-
$ bench "Tx1+Tx2+Tx3" . whnf (F.foldl' (\ms -> fst . applyTx' mempoolEnv ms . extractTx) mempoolState)
125+
$ bench "Tx1+Tx2+Tx3"
126+
-- TODO: revert this to `foldl'` without `fmap` after tx's are fixed
127+
. whnf (F.foldlM (\ms -> fmap fst . applyTx' mempoolEnv ms . extractTx) mempoolState)
116128
]
117129
, env (pure utxo) $ \utxo' ->
118130
bgroup

libs/ledger-state/ledger-state.cabal

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ benchmark performance
125125
cardano-data,
126126
cardano-ledger-api:{cardano-ledger-api, testlib},
127127
cardano-ledger-binary,
128+
cardano-ledger-conway,
128129
cardano-ledger-core:{cardano-ledger-core, testlib},
129130
cardano-ledger-shelley,
130131
cardano-slotting,

0 commit comments

Comments
 (0)