Skip to content

Commit bfed8e2

Browse files
committed
legacy tracing: fix overeager elision in ledger replay tracer
1 parent 98382f1 commit bfed8e2

File tree

1 file changed

+19
-5
lines changed

1 file changed

+19
-5
lines changed

cardano-node/src/Cardano/Tracing/Tracers.hs

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ import Ouroboros.Network.PeerSelection.Churn (ChurnCounters (..))
103103
import Ouroboros.Network.PeerSelection.Governor (
104104
PeerSelectionView (..))
105105
import qualified Ouroboros.Network.PeerSelection.Governor as Governor
106-
import Ouroboros.Network.Point (fromWithOrigin)
106+
import Ouroboros.Network.Point (fromWithOrigin, withOrigin)
107107
import Ouroboros.Network.Protocol.LocalStateQuery.Type (LocalStateQuery, ShowQuery)
108108
import qualified Ouroboros.Network.Protocol.LocalStateQuery.Type as LocalStateQuery
109109
import Ouroboros.Network.TxSubmission.Inbound
@@ -137,7 +137,6 @@ import qualified System.Metrics.Label as Label
137137
import qualified System.Remote.Monitoring.Wai as EKG
138138

139139

140-
141140
{-# OPTIONS_GHC -Wno-redundant-constraints #-}
142141
-- needs different instances on ghc8 and on ghc9
143142

@@ -167,6 +166,16 @@ indexGCType :: ChainDB.TraceGCEvent a -> Int
167166
indexGCType ChainDB.ScheduledGC{} = 1
168167
indexGCType ChainDB.PerformedGC{} = 2
169168

169+
-- helper to classify meaningful progress changes (i.e. in the ten thousandths)
170+
replayProgress :: LedgerDB.TraceReplayProgressEvent a -> Integer
171+
replayProgress (LedgerDB.ReplayedBlock pt _ledgerEvents (LedgerDB.ReplayStart replayFrom) (LedgerDB.ReplayGoal replayTo)) =
172+
let fromSlot = withOrigin 0 Prelude.id $ unSlotNo <$> pointSlot replayFrom
173+
atSlot = unSlotNo $ realPointSlot pt
174+
atDiff = atSlot - fromSlot
175+
toSlot = withOrigin 0 Prelude.id $ unSlotNo <$> pointSlot replayTo
176+
toDiff = toSlot - fromSlot
177+
in if toDiff == 0 then 0 else round (10000 * fromIntegral atDiff / fromIntegral toDiff :: Float)
178+
170179
instance ElidingTracer (WithSeverity (ChainDB.TraceEvent blk)) where
171180
-- equivalent by type and severity
172181
isEquivalent (WithSeverity s1 (ChainDB.TraceGCEvent ev1))
@@ -194,6 +203,7 @@ instance ElidingTracer (WithSeverity (ChainDB.TraceEvent blk)) where
194203
(WithSeverity _s2 (ChainDB.TraceLedgerDBEvent
195204
(LedgerDB.LedgerReplayEvent
196205
(LedgerDB.TraceReplayProgressEvent _)))) = True
206+
197207
-- HACK: we never want any of the forker or flavor events to break the elision.
198208
--
199209
-- when a forker event arrives, it will be compared as @(ev `isEquivalent`)@, but once it is
@@ -203,6 +213,7 @@ instance ElidingTracer (WithSeverity (ChainDB.TraceEvent blk)) where
203213
isEquivalent (WithSeverity _s1 (ChainDB.TraceLedgerDBEvent LedgerDB.LedgerDBFlavorImplEvent{})) _ = True
204214
isEquivalent _ (WithSeverity _s1 (ChainDB.TraceLedgerDBEvent LedgerDB.LedgerDBForkerEvent{})) = True
205215
isEquivalent _ (WithSeverity _s1 (ChainDB.TraceLedgerDBEvent LedgerDB.LedgerDBFlavorImplEvent{})) = True
216+
206217
isEquivalent (WithSeverity _s1 (ChainDB.TraceInitChainSelEvent ev1))
207218
(WithSeverity _s2 (ChainDB.TraceInitChainSelEvent ev2)) =
208219
case (ev1, ev2) of
@@ -253,10 +264,13 @@ instance ElidingTracer (WithSeverity (ChainDB.TraceEvent blk)) where
253264
return (Just ev, count)
254265
conteliding _tverb _tr ev@(WithSeverity _ (ChainDB.TraceGCEvent _)) (_old, count) =
255266
return (Just ev, count)
256-
conteliding _tverb _tr ev@(WithSeverity _ (ChainDB.TraceLedgerDBEvent
267+
conteliding tverb tr ev@(WithSeverity _ (ChainDB.TraceLedgerDBEvent
257268
(LedgerDB.LedgerReplayEvent
258-
(LedgerDB.TraceReplayProgressEvent _)))) (_old, count) = do
259-
return (Just ev, count)
269+
(LedgerDB.TraceReplayProgressEvent inner)))) (_old, previous) =
270+
let current = replayProgress inner
271+
in if current > previous
272+
then traceWith (toLogObject' tverb tr) ev >> return (Just ev, current)
273+
else return (Just ev, previous)
260274
conteliding _tverb _tr ev@(WithSeverity _ (ChainDB.TraceLedgerDBEvent LedgerDB.LedgerDBForkerEvent{})) (_old, count) = do
261275
return (Just ev, count)
262276
conteliding _tverb _tr ev@(WithSeverity _ (ChainDB.TraceLedgerDBEvent LedgerDB.LedgerDBFlavorImplEvent{})) (_old, count) = do

0 commit comments

Comments
 (0)