Skip to content

Commit 3d53a9e

Browse files
authored
Fix monitoring of confirmed snapshots (#1897)
The code was too strict on tracing 'LogicOutcome's. Closes #1896 --- <!-- Consider each and tick it off one way or the other --> * [x] CHANGELOG update not needed (fixes a bug introduced in #1860) * [x] Documentation update not needed * [x] Haddocks update not needed * [x] No new TODOs introduced
2 parents a16c858 + 408dbca commit 3d53a9e

File tree

1 file changed

+15
-12
lines changed

1 file changed

+15
-12
lines changed

hydra-node/src/Hydra/Logging/Monitoring.hs

+15-12
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@ import Data.Map.Strict as Map
1919
import Hydra.HeadLogic (
2020
Input (NetworkInput),
2121
)
22-
import Hydra.HeadLogic.Outcome (Outcome (Continue), StateChanged (..))
22+
import Hydra.HeadLogic.Outcome (Outcome (..), StateChanged (..))
2323
import Hydra.Logging.Messages (HydraLog (..))
2424
import Hydra.Network (PortNumber)
2525
import Hydra.Network.Message (Message (ReqTx), NetworkEvent (..))
2626
import Hydra.Node (HydraNodeLog (..))
27-
import Hydra.Tx (IsTx (TxIdType), Snapshot (confirmed), txId)
27+
import Hydra.Tx (IsTx (TxIdType), Snapshot (..), txId)
2828
import System.Metrics.Prometheus.Http.Scrape (serveMetrics)
2929
import System.Metrics.Prometheus.Metric (Metric (CounterMetric, HistogramMetric))
3030
import System.Metrics.Prometheus.Metric.Counter (add, inc)
@@ -94,16 +94,19 @@ monitor transactionsMap metricsMap = \case
9494
-- transactions after some timeout expires
9595
atomically $ modifyTVar' transactionsMap (Map.insert (txId tx) t)
9696
tick "hydra_head_requested_tx"
97-
(Node (LogicOutcome _ (Continue [SnapshotConfirmed _ snapshot _] _))) -> do
98-
t <- getMonotonicTime
99-
forM_ (confirmed snapshot) $ \tx -> do
100-
txsStartTime <- readTVarIO transactionsMap
101-
case Map.lookup (txId tx) txsStartTime of
102-
Just start -> do
103-
atomically $ modifyTVar' transactionsMap $ Map.delete (txId tx)
104-
histo "hydra_head_tx_confirmation_time_ms" (diffTime t start)
105-
Nothing -> pure ()
106-
tickN "hydra_head_confirmed_tx" (length $ confirmed snapshot)
97+
(Node LogicOutcome{outcome = Continue{stateChanges}}) -> do
98+
forM_ stateChanges $ \case
99+
SnapshotConfirmed{snapshot = Snapshot{confirmed}} -> do
100+
tickN "hydra_head_confirmed_tx" (length confirmed)
101+
forM_ confirmed $ \tx -> do
102+
t <- getMonotonicTime
103+
txsStartTime <- readTVarIO transactionsMap
104+
case Map.lookup (txId tx) txsStartTime of
105+
Just start -> do
106+
atomically $ modifyTVar' transactionsMap $ Map.delete (txId tx)
107+
histo "hydra_head_tx_confirmation_time_ms" (diffTime t start)
108+
Nothing -> pure ()
109+
_ -> pure ()
107110
(Node (EndInput _ _)) ->
108111
tick "hydra_head_inputs"
109112
_ -> pure ()

0 commit comments

Comments
 (0)