Skip to content

Commit 2bebf44

Browse files
Merge #4239
4239: tx-generator: fix a bug r=MarcFontaine a=MarcFontaine The bug was introduced in : #3815. The number of total output transactions of the tx-generator was used for the number of outputs of a single transaction. It was not found because the tests were only run for Plutus workloads and the bug was in a non-Plutus code-branch. Co-authored-by: MarcFontaine <[email protected]>
2 parents a9bc2f9 + be275eb commit 2bebf44

File tree

5 files changed

+47
-42
lines changed

5 files changed

+47
-42
lines changed

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

+8-11
Original file line numberDiff line numberDiff line change
@@ -112,16 +112,13 @@ txSubmissionClient tr bmtr initialTxSource endOfProtocolCallback =
112112
fail (T.unpack err)
113113
let (stillUnacked, acked) = L.splitAtEnd ack unAcked
114114
let newStats = stats { stsAcked = stsAcked stats + Ack ack }
115-
traceWith bmtr $ TraceBenchTxSubServAck (getTxId . getTxBody <$> acked)
115+
traceWith bmtr $ SubmissionClientDiscardAcknowledged (getTxId . getTxBody <$> acked)
116116
return (txSource, UnAcked stillUnacked, newStats)
117117

118118
queueNewTxs :: [tx] -> LocalState era -> LocalState era
119119
queueNewTxs newTxs (txSource, UnAcked unAcked, stats)
120120
= (txSource, UnAcked (newTxs <> unAcked), stats)
121121

122-
-- Sadly, we can't just return what we want, we instead have to
123-
-- communicate via IORefs, because..
124-
-- The () return type is forced by Ouroboros.Network.NodeToNode.connectTo
125122
client ::LocalState era -> ClientStIdle (GenTxId CardanoBlock) (GenTx CardanoBlock) m ()
126123

127124
client localState = ClientStIdle
@@ -140,13 +137,14 @@ txSubmissionClient tr bmtr initialTxSource endOfProtocolCallback =
140137
req = Req $ fromIntegral reqNum
141138
traceWith tr $ reqIdsTrace ack req blocking
142139
stateA <- discardAcknowledged blocking ack state
143-
140+
traceWith bmtr $ TraceBenchTxSubDebug "return from discard"
144141
(stateB, newTxs) <- produceNextTxs blocking req stateA
142+
traceWith bmtr $ TraceBenchTxSubDebug "return from produceNext"
145143
let stateC@(_, UnAcked outs , stats) = queueNewTxs newTxs stateB
146144

147145
traceWith tr $ idListTrace (ToAnnce newTxs) blocking
148-
traceWith bmtr $ TraceBenchTxSubServAnn (getTxId . getTxBody <$> newTxs)
149-
traceWith bmtr $ TraceBenchTxSubServOuts (getTxId . getTxBody <$> outs)
146+
traceWith bmtr $ SubmissionClientReplyTxIds (getTxId . getTxBody <$> newTxs)
147+
traceWith bmtr $ SubmissionClientUnAcked (getTxId . getTxBody <$> outs)
150148

151149
case blocking of
152150
TokBlocking -> case NE.nonEmpty newTxs of
@@ -175,8 +173,8 @@ txSubmissionClient tr bmtr initialTxSource endOfProtocolCallback =
175173
missIds = reqTxIds L.\\ uaIds
176174

177175
traceWith tr $ TxList (length toSend)
176+
traceWith bmtr $ SubmissionClientUnAcked (getTxId . getTxBody <$> ua)
178177
traceWith bmtr $ TraceBenchTxSubServReq reqTxIds
179-
traceWith bmtr $ TraceBenchTxSubServOuts (getTxId . getTxBody <$> ua)
180178
unless (L.null missIds) $
181179
traceWith bmtr $ TraceBenchTxSubServUnav missIds
182180
pure $ SendMsgReplyTxs (toGenTx <$> toSend)
@@ -213,10 +211,9 @@ txSubmissionClient tr bmtr initialTxSource endOfProtocolCallback =
213211
reqIdsTrace :: Ack -> Req -> TokBlockingStyle a -> NodeToNodeSubmissionTrace
214212
reqIdsTrace ack req = \case
215213
TokBlocking -> ReqIdsBlocking ack req
216-
TokNonBlocking -> ReqIdsPrompt ack req
214+
TokNonBlocking -> ReqIdsNonBlocking ack req
217215

218216
idListTrace :: ToAnnce tx -> TokBlockingStyle a -> NodeToNodeSubmissionTrace
219217
idListTrace (ToAnnce toAnn) = \case
220218
TokBlocking -> IdsListBlocking $ length toAnn
221-
TokNonBlocking -> IdsListPrompt $ length toAnn
222-
219+
TokNonBlocking -> IdsListNonBlocking $ length toAnn

bench/tx-generator/src/Cardano/Benchmarking/LogTypes.hs

+5-5
Original file line numberDiff line numberDiff line change
@@ -68,16 +68,16 @@ data TraceBenchTxSubmit txid
6868
| TraceBenchTxSubStart [txid]
6969
-- ^ The @txid@ has been submitted to `TxSubmission`
7070
-- protocol peer.
71-
| TraceBenchTxSubServAnn [txid]
71+
| SubmissionClientReplyTxIds [txid]
7272
-- ^ Announcing txids in response for server's request.
7373
| TraceBenchTxSubServReq [txid]
7474
-- ^ Request for @tx@ received from `TxSubmission` protocol
7575
-- peer.
76-
| TraceBenchTxSubServAck [txid]
76+
| SubmissionClientDiscardAcknowledged [txid]
7777
-- ^ An ack (window moved over) received for these transactions.
7878
| TraceBenchTxSubServDrop [txid]
7979
-- ^ Transactions the server implicitly dropped.
80-
| TraceBenchTxSubServOuts [txid]
80+
| SubmissionClientUnAcked [txid]
8181
-- ^ Transactions outstanding.
8282
| TraceBenchTxSubServUnav [txid]
8383
-- ^ Transactions requested, but unavailable in the outstanding set.
@@ -113,8 +113,8 @@ instance ToJSON SubmissionSummary
113113
data NodeToNodeSubmissionTrace
114114
= ReqIdsBlocking Ack Req
115115
| IdsListBlocking Int
116-
| ReqIdsPrompt Ack Req
117-
| IdsListPrompt Int
116+
| ReqIdsNonBlocking Ack Req
117+
| IdsListNonBlocking Int
118118
| ReqTxs Int
119119
| TxList Int
120120
| EndOfProtocol

bench/tx-generator/src/Cardano/Benchmarking/Script/Core.hs

+1-2
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ runBenchmarkInEra sourceWallet submitMode (ThreadName threadName) shape tps era
276276

277277
let
278278
inToOut :: [Lovelace] -> [Lovelace]
279-
inToOut = FundSet.inputsToOutputsWithFee (auxFee shape) (auxOutputs shape)
279+
inToOut = FundSet.inputsToOutputsWithFee (auxFee shape) (auxOutputsPerTx shape)
280280

281281
txGenerator = genTx protocolParameters (TxInsCollateralNone, []) (mkFee (auxFee shape)) metadata (KeyWitness KeyWitnessForSpending)
282282

@@ -642,4 +642,3 @@ and for which the JSON encoding is "reserved".
642642
reserved :: [String] -> ActionM ()
643643
reserved _ = do
644644
throwE $ UserError "no dirty hack is implemented"
645-

bench/tx-generator/src/Cardano/Benchmarking/TpsThrottle.hs

+23-14
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,13 @@ data TpsThrottle = TpsThrottle {
1919
startSending :: IO ()
2020
, sendStop :: STM ()
2121
, receiveBlocking :: STM Step
22-
, receiveNoneBlocking :: STM (Maybe Step)
22+
, receiveNonBlocking :: STM (Maybe Step)
2323
}
2424

2525
-- TVar state ::
2626
-- empty -> Block submission
27-
-- Just n -> allow n transmissions
27+
-- Just 0 -> illegal state
28+
-- Just n -> allow n transmissions ( n must be >0 )
2829
-- Nothing -> teminate transmission
2930

3031
newTpsThrottle :: Int -> Int -> TPSRate -> IO TpsThrottle
@@ -34,19 +35,16 @@ newTpsThrottle buffersize count tpsRate = do
3435
startSending = sendNTicks tpsRate buffersize count var
3536
, sendStop = putTMVar var Nothing
3637
, receiveBlocking = takeTMVar var >>= receiveAction var
37-
, receiveNoneBlocking = do
38-
s <- tryTakeTMVar var
39-
case s of
40-
Nothing -> return Nothing
41-
Just state -> Just <$> receiveAction var state
38+
, receiveNonBlocking =
39+
(Just <$> (takeTMVar var >>= receiveAction var )) `orElse` return Nothing
4240
}
4341

4442
receiveAction :: TMVar (Maybe Int) -> Maybe Int -> STM Step
4543
receiveAction var state = case state of
4644
Nothing -> do
4745
putTMVar var Nothing
4846
return Stop
49-
Just 1 -> return Next -- leave var empty
47+
Just 1 -> return Next -- leave var empty, i.e. block submission until sendNTicks unblocks
5048
Just n -> do
5149
-- decrease counter and let other threads transmit
5250
putTMVar var $ Just $ pred n
@@ -59,15 +57,15 @@ sendNTicks (TPSRate rate) buffersize count var = do
5957
where
6058
worker 0 _ _ = return ()
6159
worker n lastPreDelay lastDelay = do
62-
atomically increaseWatermark
60+
increaseWatermark
6361
now <- Clock.getCurrentTime
6462
let targetDelay = realToFrac $ 1.0 / rate
6563
loopCost = (now `Clock.diffUTCTime` lastPreDelay) - lastDelay
6664
delay = targetDelay - loopCost
6765
threadDelay . ceiling $ (realToFrac delay * 1000000.0 :: Double)
6866
worker (pred n) now delay
6967
-- increaseWatermark can retry/block if there are already buffersize ticks in the "queue"
70-
increaseWatermark = do
68+
increaseWatermark = atomically $ do
7169
s <- tryTakeTMVar var
7270
case s of
7371
Nothing -> putTMVar var $ Just 1
@@ -90,19 +88,18 @@ consumeTxsNonBlocking tpsThrottle req
9088
= if req==0
9189
then pure (Next, 0)
9290
else do
93-
STM.atomically (receiveNoneBlocking tpsThrottle) >>= \case
91+
STM.atomically (receiveNonBlocking tpsThrottle) >>= \case
9492
Nothing -> pure (Next, 0)
9593
Just Stop -> pure (Stop, 0)
9694
Just Next -> pure (Next, 1)
9795

98-
99-
10096
test :: IO ()
10197
test = do
10298
t <- newTpsThrottle 10 50 2
10399
_threadId <- startThrottle t
104100
threadDelay 5000000
105101
forM_ [1 .. 5] $ \i -> forkIO $ consumer t i
102+
forM_ [6 .. 7] $ \i -> forkIO $ consumer2 t i
106103
putStrLn "done"
107104
where
108105
startThrottle t = forkIO $ do
@@ -114,4 +111,16 @@ test = do
114111
consumer t n = do
115112
s <- atomically $ receiveBlocking t
116113
print (n, s)
117-
if s==Next then consumer t n else putStrLn $ "Done " ++ show n
114+
if s == Next then consumer t n else putStrLn $ "Done " ++ show n
115+
116+
consumer2 :: TpsThrottle -> Int -> IO ()
117+
consumer2 t n = do
118+
r <- atomically $ receiveNonBlocking t
119+
case r of
120+
Just s -> do
121+
print (n, s)
122+
if s == Next then consumer2 t n else putStrLn $ "Done " ++ show n
123+
Nothing -> do
124+
putStrLn $ "wait " ++ show n
125+
threadDelay 100000
126+
consumer2 t n

bench/tx-generator/src/Cardano/Benchmarking/Tracer.hs

+10-10
Original file line numberDiff line numberDiff line change
@@ -129,24 +129,24 @@ instance LogFormatting (TraceBenchTxSubmit TxId) where
129129
mconcat [ "kind" .= A.String "TraceBenchTxSubStart"
130130
, "txIds" .= toJSON txIds
131131
]
132-
TraceBenchTxSubServAnn txIds ->
133-
mconcat [ "kind" .= A.String "TraceBenchTxSubServAnn"
132+
SubmissionClientReplyTxIds txIds ->
133+
mconcat [ "kind" .= A.String "SubmissionClientReplyTxIds"
134134
, "txIds" .= toJSON txIds
135135
]
136136
TraceBenchTxSubServReq txIds ->
137137
mconcat [ "kind" .= A.String "TraceBenchTxSubServReq"
138138
, "txIds" .= toJSON txIds
139139
]
140-
TraceBenchTxSubServAck txIds ->
141-
mconcat [ "kind" .= A.String "TraceBenchTxSubServAck"
140+
SubmissionClientDiscardAcknowledged txIds ->
141+
mconcat [ "kind" .= A.String "SubmissionClientDiscardAcknowledged"
142142
, "txIds" .= toJSON txIds
143143
]
144144
TraceBenchTxSubServDrop txIds ->
145145
mconcat [ "kind" .= A.String "TraceBenchTxSubServDrop"
146146
, "txIds" .= toJSON txIds
147147
]
148-
TraceBenchTxSubServOuts txIds ->
149-
mconcat [ "kind" .= A.String "TraceBenchTxSubServOuts"
148+
SubmissionClientUnAcked txIds ->
149+
mconcat [ "kind" .= A.String "SubmissionClientUnAcked"
150150
, "txIds" .= toJSON txIds
151151
]
152152
TraceBenchTxSubServUnav txIds ->
@@ -196,12 +196,12 @@ instance LogFormatting NodeToNodeSubmissionTrace where
196196
IdsListBlocking sent -> KeyMap.fromList
197197
[ "kind" .= A.String "IdsListBlocking"
198198
, "sent" .= A.toJSON sent ]
199-
ReqIdsPrompt (Ack ack) (Req req) -> KeyMap.fromList
200-
[ "kind" .= A.String "ReqIdsPrompt"
199+
ReqIdsNonBlocking (Ack ack) (Req req) -> KeyMap.fromList
200+
[ "kind" .= A.String "ReqIdsNonBlocking"
201201
, "ack" .= A.toJSON ack
202202
, "req" .= A.toJSON req ]
203-
IdsListPrompt sent -> KeyMap.fromList
204-
[ "kind" .= A.String "IdsListPrompt"
203+
IdsListNonBlocking sent -> KeyMap.fromList
204+
[ "kind" .= A.String "IdsListNonBlocking"
205205
, "sent" .= A.toJSON sent ]
206206
EndOfProtocol -> KeyMap.fromList [ "kind" .= A.String "EndOfProtocol" ]
207207
ReqTxs req -> KeyMap.fromList

0 commit comments

Comments
 (0)