1111{-# LANGUAGE OverloadedStrings #-}
1212{-# LANGUAGE RankNTypes #-}
1313{-# LANGUAGE ScopedTypeVariables #-}
14- {-# LANGUAGE TypeApplications #-}
15- {-# LANGUAGE TypeOperators #-}
1614{-# LANGUAGE UndecidableInstances #-}
1715
1816{-# OPTIONS_GHC -Wno-unticked-promoted-constructors #-}
@@ -26,10 +24,11 @@ module Cardano.Benchmarking.GeneratorTx.SubmissionClient
2624 ) where
2725
2826import Cardano.Api hiding (Active )
29- import Cardano.Api.Shelley (fromShelleyTxId , toConsensusGenTx )
27+ import Cardano.Api.Shelley (fromShelleyTxId , toConsensusGenTx , Tx ( .. ) )
3028
3129import Cardano.Benchmarking.LogTypes
3230import Cardano.Benchmarking.Types
31+ import qualified Cardano.Ledger.Core as Ledger
3332import Cardano.Logging
3433import Cardano.Prelude hiding (ByteString , atomically , retry , state , threadDelay )
3534import Cardano.Tracing.OrphanInstances.Byron ()
@@ -40,7 +39,7 @@ import Cardano.Tracing.OrphanInstances.Shelley ()
4039import qualified Ouroboros.Consensus.Cardano as Consensus (CardanoBlock )
4140import qualified Ouroboros.Consensus.Cardano.Block as Block
4241 (TxId (GenTxIdAllegra , GenTxIdAlonzo , GenTxIdBabbage , GenTxIdConway , GenTxIdMary , GenTxIdShelley ))
43- import Ouroboros.Consensus.Ledger.SupportsMempool (GenTx , GenTxId , txInBlockSize )
42+ import Ouroboros.Consensus.Ledger.SupportsMempool (GenTx , GenTxId )
4443import qualified Ouroboros.Consensus.Ledger.SupportsMempool as Mempool
4544import Ouroboros.Consensus.Shelley.Eras (StandardCrypto )
4645import qualified Ouroboros.Consensus.Shelley.Ledger.Mempool as Mempool (TxId (ShelleyTxId ))
@@ -57,6 +56,8 @@ import qualified Data.List as L
5756import qualified Data.List.Extra as L
5857import qualified Data.List.NonEmpty as NE
5958import qualified Data.Text as T
59+ import Lens.Micro ((^.) )
60+
6061type CardanoBlock = Consensus. CardanoBlock StandardCrypto
6162
6263data SubmissionThreadStats
@@ -85,10 +86,9 @@ type LocalState era = (TxSource era, UnAcked (Tx era), SubmissionThreadStats)
8586type EndOfProtocolCallback m = SubmissionThreadStats -> m ()
8687
8788txSubmissionClient
88- :: forall m era tx .
89+ :: forall m era .
8990 ( MonadIO m , MonadFail m
9091 , IsShelleyBasedEra era
91- , tx ~ Tx era
9292 )
9393 => Trace m NodeToNodeSubmissionTrace
9494 -> Trace m (TraceBenchTxSubmit TxId )
@@ -110,11 +110,11 @@ txSubmissionClient tr bmtr initialTxSource endOfProtocolCallback =
110110 traceWith bmtr $ SubmissionClientDiscardAcknowledged (getTxId . getTxBody <$> acked)
111111 return (txSource, UnAcked stillUnacked, newStats)
112112
113- queueNewTxs :: [tx ] -> LocalState era -> LocalState era
113+ queueNewTxs :: [Tx era ] -> LocalState era -> LocalState era
114114 queueNewTxs newTxs (txSource, UnAcked unAcked, stats)
115115 = (txSource, UnAcked (newTxs <> unAcked), stats)
116116
117- client :: LocalState era -> ClientStIdle (GenTxId CardanoBlock ) (GenTx CardanoBlock ) m ()
117+ client :: LocalState era -> ClientStIdle (GenTxId CardanoBlock ) (GenTx CardanoBlock ) m ()
118118
119119 client localState = ClientStIdle
120120 { recvMsgRequestTxIds = requestTxIds localState
@@ -177,12 +177,15 @@ txSubmissionClient tr bmtr initialTxSource endOfProtocolCallback =
177177 , stsUnavailable =
178178 stsUnavailable stats + Unav (length missIds)}))
179179
180- txToIdSize :: tx -> (GenTxId CardanoBlock , SizeInBytes )
181- txToIdSize = (Mempool. txId &&& (SizeInBytes . txInBlockSize)) . toGenTx
182-
183- toGenTx :: tx -> GenTx CardanoBlock
184- toGenTx tx = toConsensusGenTx $ TxInMode (shelleyBasedEra @ era ) tx
180+ txToIdSize :: Tx era -> (GenTxId CardanoBlock , SizeInBytes )
181+ txToIdSize = (Mempool. txId . toGenTx) &&& (SizeInBytes . fromInteger . getTxSize)
182+ where
183+ getTxSize :: Tx era -> Integer
184+ getTxSize (ShelleyTx sbe tx) =
185+ shelleyBasedEraConstraints sbe $ tx ^. Ledger. sizeTxF
185186
187+ toGenTx :: Tx era -> GenTx CardanoBlock
188+ toGenTx tx = toConsensusGenTx $ TxInMode shelleyBasedEra tx
186189
187190 fromGenTxId :: GenTxId CardanoBlock -> TxId
188191 fromGenTxId (Block. GenTxIdShelley (Mempool. ShelleyTxId i)) = fromShelleyTxId i
0 commit comments