@@ -22,6 +22,7 @@ import Control.Lens (to, (^..), (^?))
22
22
import Control.Monad.Class.MonadAsync (mapConcurrently )
23
23
import Data.Aeson (Result (Error , Success ), Value , encode , fromJSON , (.=) )
24
24
import Data.Aeson.Lens (key , values , _JSON , _Number , _String )
25
+ import Data.ByteString.Lazy qualified as LBS
25
26
import Data.List qualified as List
26
27
import Data.Map qualified as Map
27
28
import Data.Scientific (Scientific )
@@ -130,6 +131,12 @@ benchDemo networkId nodeSocket timeoutSeconds hydraClients workDir dataset@Datas
130
131
(leader : followers) ->
131
132
(,[] ) <$> scenario hydraTracer backend workDir dataset (leader :| followers)
132
133
where
134
+ withHydraClientConnections ::
135
+ Tracer IO HydraNodeLog ->
136
+ [(Host , Int )] ->
137
+ [HydraClient ] ->
138
+ ([HydraClient ] -> IO a ) ->
139
+ IO a
133
140
withHydraClientConnections tracer apiHosts connections action = do
134
141
case apiHosts of
135
142
[] -> action connections
@@ -309,10 +316,14 @@ movingAverage confirmations =
309
316
timeSlice t@ UTCTime {utctDayTime} =
310
317
t{utctDayTime = fromIntegral (floor (utctDayTime / window) * window :: Integer )}
311
318
319
+ fiveSecSlice :: (UTCTime , NominalDiffTime , NominalDiffTime ) -> (UTCTime , NominalDiffTime , NominalDiffTime ) -> Bool
312
320
fiveSecSlice (timeSlice -> t1, _, _) (timeSlice -> t2, _, _) = t1 == t2
313
321
322
+ fst3 :: (a , b , c ) -> a
314
323
fst3 (a, _, _) = a
324
+ snd3 :: (a , b , c ) -> b
315
325
snd3 (_, a, _) = a
326
+ thd3 :: (a , b , c ) -> c
316
327
thd3 (_, _, a) = a
317
328
318
329
average = \ case
@@ -481,21 +492,29 @@ waitForAllConfirmations n1 Registry{processedTxs} allIds = do
481
492
waitForSnapshotConfirmation = waitMatch 20 n1 $ \ v ->
482
493
maybeTxValid v <|> maybeTxInvalid v <|> maybeSnapshotConfirmed v
483
494
495
+ maybeTxValid :: Value -> Maybe WaitResult
484
496
maybeTxValid v = do
485
497
guard (v ^? key " tag" == Just " TxValid" )
486
498
v
487
- ^? key " transactionId" . to fromJSON >>= \ case
488
- Error _ -> Nothing
489
- Success txid -> pure $ TxValid txid
499
+ ^? key " transactionId"
500
+ . to fromJSON
501
+ >>= \ case
502
+ Error _ -> Nothing
503
+ Success txid -> pure $ TxValid txid
490
504
505
+ maybeTxInvalid :: Value -> Maybe WaitResult
491
506
maybeTxInvalid v = do
492
507
guard (v ^? key " tag" == Just " TxInvalid" )
493
508
v
494
- ^? key " transaction" . key " txId" . to fromJSON >>= \ case
495
- Error _ -> Nothing
496
- Success tx ->
497
- TxInvalid tx <$> v ^? key " validationError" . key " reason" . _String
498
-
509
+ ^? key " transaction"
510
+ . key " txId"
511
+ . to fromJSON
512
+ >>= \ case
513
+ Error _ -> Nothing
514
+ Success tx ->
515
+ TxInvalid tx <$> v ^? key " validationError" . key " reason" . _String
516
+
517
+ maybeSnapshotConfirmed :: Value -> Maybe WaitResult
499
518
maybeSnapshotConfirmed v = do
500
519
guard (v ^? key " tag" == Just " SnapshotConfirmed" )
501
520
snapshot <- v ^? key " snapshot"
@@ -553,4 +572,5 @@ writeResultsCsv fp res = do
553
572
where
554
573
headers = " txId,confirmationTime"
555
574
575
+ toCsv :: (UTCTime , NominalDiffTime , NominalDiffTime , Int ) -> LBS. ByteString
556
576
toCsv (a, b, c, d) = show a <> " ," <> encode b <> " ," <> encode c <> " ," <> encode d <> " \n "
0 commit comments