Skip to content

Commit

Permalink
Also subtract balances on notify
Browse files Browse the repository at this point in the history
  • Loading branch information
ch1bo committed Jul 20, 2021
1 parent d998abb commit 9362197
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions src/Hydra/Tail/Simulation.hs
Expand Up @@ -177,7 +177,14 @@ analyzeSimulation notify trace = do
(_threadLabel, Time _t, TraceClient (TraceClientAck clientId tx)) ->
( \(!m, !sl) ->
pure
( Map.alter (updateBalance tx) clientId m
( Map.alter (updateBalance (+ txAmount tx)) clientId m
, sl
)
)
(_threadLabel, Time _t, TraceClient (TraceClientNotify clientId tx)) ->
( \(!m, !sl) ->
pure
( Map.alter (updateBalance (subtract $ txAmount tx)) clientId m
, sl
)
)
Expand All @@ -195,9 +202,9 @@ analyzeSimulation notify trace = do
in foldTraceEvents fn (mempty, -1) trace
pure mempty
where
updateBalance tx = \case
Nothing -> Just $ txAmount tx
Just a -> Just $ a + txAmount tx
updateBalance fn = \case
Nothing -> Just $ fn 0
Just a -> Just $ fn a

mkAnalyze :: AnalyzeOptions -> Transactions -> Analyze
mkAnalyze AnalyzeOptions{discardEdges} txs =
Expand Down Expand Up @@ -600,8 +607,8 @@ runClient tracer events serverId opts Client{multiplexer, identifier} = do
-- to snapshot. For simplicity reasons, this is also shifted to the
-- server (for now) as we do track payment windows there.
traceWith tracer (TraceClientAck identifier tx)
(_, NotifyTx{}) ->
pure ()
(_, NotifyTx tx) ->
traceWith tracer (TraceClientNotify identifier tx)
(_, NeedSnapshot{}) -> do
-- NOTE: Holding on the MVar here prevents the client's event loop from
-- processing any new event. The other will block until the snapshot is done.
Expand Down Expand Up @@ -701,6 +708,7 @@ data TraceClient
= TraceClientMultiplexer (TraceMultiplexer Msg)
| TraceClientWakeUp SlotNo
| TraceClientAck ClientId MockTx
| TraceClientNotify ClientId MockTx
deriving (Show)

--
Expand Down

0 comments on commit 9362197

Please sign in to comment.