Skip to content

Commit 088a505

Browse files
committed
Updated cardano-client-demo & benchmarking code
1 parent d0d77db commit 088a505

File tree

2 files changed

+26
-24
lines changed

2 files changed

+26
-24
lines changed

bench/tx-generator/src/Cardano/Benchmarking/GeneratorTx/Submission.hs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ import Cardano.Tracing.OrphanInstances.Consensus ()
4545
import Cardano.Tracing.OrphanInstances.Network ()
4646
import Cardano.Tracing.OrphanInstances.Shelley ()
4747

48-
import Ouroboros.Network.Protocol.TxSubmission2.Type (TokBlockingStyle (..))
48+
import Ouroboros.Network.Protocol.TxSubmission2.Type (SingBlockingStyle (..))
4949

5050
import Cardano.Api hiding (Active)
5151
import Cardano.TxGenerator.Types (TPSRate, TxGenError)
@@ -124,11 +124,11 @@ mkSubmissionSummary startTime reportsRefs
124124
txStreamSource :: forall era. MVar (StreamState (TxStream IO era)) -> TpsThrottle -> TxSource era
125125
txStreamSource streamRef tpsThrottle = Active worker
126126
where
127-
worker :: forall m blocking . MonadIO m => TokBlockingStyle blocking -> Req -> m (TxSource era, [Tx era])
127+
worker :: forall m blocking . MonadIO m => SingBlockingStyle blocking -> Req -> m (TxSource era, [Tx era])
128128
worker blocking req = do
129129
(done, txCount) <- case blocking of
130-
TokBlocking -> liftIO $ consumeTxsBlocking tpsThrottle req
131-
TokNonBlocking -> liftIO $ consumeTxsNonBlocking tpsThrottle req
130+
SingBlocking -> liftIO $ consumeTxsBlocking tpsThrottle req
131+
SingNonBlocking -> liftIO $ consumeTxsNonBlocking tpsThrottle req
132132
txList <- liftIO $ unFold txCount
133133
case done of
134134
Stop -> return (Exhausted, txList)

bench/tx-generator/src/Cardano/Benchmarking/GeneratorTx/SubmissionClient.hs

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,12 @@ import qualified Ouroboros.Consensus.Shelley.Ledger.Mempool as Mempool (TxId (Sh
5050
import qualified Ouroboros.Consensus.Cardano.Block as Block
5151
(TxId (GenTxIdAllegra, GenTxIdAlonzo, GenTxIdBabbage, GenTxIdConway, GenTxIdMary, GenTxIdShelley))
5252

53+
import Ouroboros.Network.Protocol.TxSubmission2.Type
54+
(NumTxIdsToAck (..), NumTxIdsToReq (..))
5355
import Ouroboros.Network.Protocol.TxSubmission2.Client (ClientStIdle (..),
5456
ClientStTxIds (..), ClientStTxs (..), TxSubmissionClient (..))
5557
import Ouroboros.Network.Protocol.TxSubmission2.Type (BlockingReplyList (..),
56-
TokBlockingStyle (..), TxSizeInBytes)
58+
SingBlockingStyle (..), TxSizeInBytes)
5759

5860
import Cardano.Api hiding (Active)
5961
import Cardano.Api.Shelley (fromShelleyTxId, toConsensusGenTx)
@@ -75,14 +77,14 @@ data TxSource era
7577
= Exhausted
7678
| Active (ProduceNextTxs era)
7779

78-
type ProduceNextTxs era = (forall m blocking . MonadIO m => TokBlockingStyle blocking -> Req -> m (TxSource era, [Tx era]))
80+
type ProduceNextTxs era = (forall m blocking . MonadIO m => SingBlockingStyle blocking -> Req -> m (TxSource era, [Tx era]))
7981

80-
produceNextTxs :: forall m blocking era . MonadIO m => TokBlockingStyle blocking -> Req -> LocalState era -> m (LocalState era, [Tx era])
82+
produceNextTxs :: forall m blocking era . MonadIO m => SingBlockingStyle blocking -> Req -> LocalState era -> m (LocalState era, [Tx era])
8183
produceNextTxs blocking req (txProducer, unack, stats) = do
8284
(newTxProducer, txList) <- produceNextTxs' blocking req txProducer
8385
return ((newTxProducer, unack, stats), txList)
8486

85-
produceNextTxs' :: forall m blocking era . MonadIO m => TokBlockingStyle blocking -> Req -> TxSource era -> m (TxSource era, [Tx era])
87+
produceNextTxs' :: forall m blocking era . MonadIO m => SingBlockingStyle blocking -> Req -> TxSource era -> m (TxSource era, [Tx era])
8688
produceNextTxs' _ _ Exhausted = return (Exhausted, [])
8789
produceNextTxs' blocking req (Active callback) = callback blocking req
8890

@@ -104,10 +106,10 @@ txSubmissionClient tr bmtr initialTxSource endOfProtocolCallback =
104106
TxSubmissionClient $
105107
pure $ client (initialTxSource, UnAcked [], SubmissionThreadStats 0 0 0)
106108
where
107-
discardAcknowledged :: TokBlockingStyle a -> Ack -> LocalState era -> m (LocalState era)
109+
discardAcknowledged :: SingBlockingStyle a -> Ack -> LocalState era -> m (LocalState era)
108110
discardAcknowledged blocking (Ack ack) (txSource, UnAcked unAcked, stats) = do
109111
when (tokIsBlocking blocking && ack /= length unAcked) $ do
110-
let err = "decideAnnouncement: TokBlocking, but length unAcked != ack"
112+
let err = "decideAnnouncement: SingBlocking, but length unAcked != ack"
111113
traceWith bmtr (TraceBenchTxSubError err)
112114
fail (T.unpack err)
113115
let (stillUnacked, acked) = L.splitAtEnd ack unAcked
@@ -128,9 +130,9 @@ txSubmissionClient tr bmtr initialTxSource endOfProtocolCallback =
128130

129131
requestTxIds :: forall blocking.
130132
LocalState era
131-
-> TokBlockingStyle blocking
132-
-> Word16
133-
-> Word16
133+
-> SingBlockingStyle blocking
134+
-> NumTxIdsToAck
135+
-> NumTxIdsToReq
134136
-> m (ClientStTxIds blocking (GenTxId CardanoBlock) (GenTx CardanoBlock) m ())
135137
requestTxIds state blocking ackNum reqNum = do
136138
let ack = Ack $ fromIntegral ackNum
@@ -145,15 +147,15 @@ txSubmissionClient tr bmtr initialTxSource endOfProtocolCallback =
145147
traceWith bmtr $ SubmissionClientUnAcked (getTxId . getTxBody <$> outs)
146148

147149
case blocking of
148-
TokBlocking -> case NE.nonEmpty newTxs of
150+
SingBlocking -> case NE.nonEmpty newTxs of
149151
Nothing -> do
150152
traceWith tr EndOfProtocol
151153
endOfProtocolCallback stats
152154
pure $ SendMsgDone ()
153155
(Just txs) -> pure $ SendMsgReplyTxIds
154156
(BlockingReply $ txToIdSize <$> txs)
155157
(client stateC)
156-
TokNonBlocking -> pure $ SendMsgReplyTxIds
158+
SingNonBlocking -> pure $ SendMsgReplyTxIds
157159
(NonBlockingReply $ txToIdSize <$> newTxs)
158160
(client stateC)
159161

@@ -198,17 +200,17 @@ txSubmissionClient tr bmtr initialTxSource endOfProtocolCallback =
198200
fromGenTxId (Block.GenTxIdConway (Mempool.ShelleyTxId i)) = fromShelleyTxId i
199201
fromGenTxId _ = error "TODO: fix incomplete match"
200202

201-
tokIsBlocking :: TokBlockingStyle a -> Bool
203+
tokIsBlocking :: SingBlockingStyle a -> Bool
202204
tokIsBlocking = \case
203-
TokBlocking -> True
204-
TokNonBlocking -> False
205+
SingBlocking -> True
206+
SingNonBlocking -> False
205207

206-
reqIdsTrace :: Ack -> Req -> TokBlockingStyle a -> NodeToNodeSubmissionTrace
208+
reqIdsTrace :: Ack -> Req -> SingBlockingStyle a -> NodeToNodeSubmissionTrace
207209
reqIdsTrace ack req = \case
208-
TokBlocking -> ReqIdsBlocking ack req
209-
TokNonBlocking -> ReqIdsNonBlocking ack req
210+
SingBlocking -> ReqIdsBlocking ack req
211+
SingNonBlocking -> ReqIdsNonBlocking ack req
210212

211-
idListTrace :: ToAnnce tx -> TokBlockingStyle a -> NodeToNodeSubmissionTrace
213+
idListTrace :: ToAnnce tx -> SingBlockingStyle a -> NodeToNodeSubmissionTrace
212214
idListTrace (ToAnnce toAnn) = \case
213-
TokBlocking -> IdsListBlocking $ length toAnn
214-
TokNonBlocking -> IdsListNonBlocking $ length toAnn
215+
SingBlocking -> IdsListBlocking $ length toAnn
216+
SingNonBlocking -> IdsListNonBlocking $ length toAnn

0 commit comments

Comments
 (0)