Skip to content

Commit d4dcec0

Browse files
committed
Fix block replay tracer in new tracing system
1 parent eb615a3 commit d4dcec0

File tree

1 file changed

+20
-10
lines changed

1 file changed

+20
-10
lines changed

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

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ module Cardano.Node.Tracing.Tracers.BlockReplayProgress
88
import Cardano.Api (textShow)
99

1010
import Cardano.Logging
11-
import Ouroboros.Consensus.Block (realPointSlot)
11+
import Ouroboros.Consensus.Block (SlotNo, realPointSlot)
1212
import qualified Ouroboros.Consensus.Storage.ChainDB as ChainDB
1313
import qualified Ouroboros.Consensus.Storage.LedgerDB as LedgerDB
1414
import Ouroboros.Network.Block (pointSlot, unSlotNo)
@@ -20,12 +20,14 @@ import Data.Text (pack)
2020

2121
data ReplayBlockStats = ReplayBlockStats
2222
{ rpsDisplay :: Bool
23+
, rpsCurSlot :: SlotNo
24+
, rpsGoalSlot :: SlotNo
2325
, rpsProgress :: Double
2426
, rpsLastProgress :: Double
2527
}
2628

2729
emptyReplayBlockStats :: ReplayBlockStats
28-
emptyReplayBlockStats = ReplayBlockStats False 0.0 0.0
30+
emptyReplayBlockStats = ReplayBlockStats False 0 0 0.0 0.0
2931

3032
--------------------------------------------------------------------------------
3133
-- ReplayBlockStats Tracer
@@ -37,7 +39,15 @@ instance LogFormatting ReplayBlockStats where
3739
[ "kind" .= String "ReplayBlockStats"
3840
, "progress" .= String (pack $ show rpsProgress)
3941
]
40-
forHuman ReplayBlockStats {..} = "Block replay progress " <> textShow rpsProgress <> "%"
42+
forHuman ReplayBlockStats {..} = "Replayed block: slot " <> textShow (unSlotNo rpsCurSlot) <> " out of " <> textShow (unSlotNo rpsGoalSlot) <> ". Progress: " <> textShow (round2 rpsProgress) <> "%"
43+
where
44+
round2 :: Double -> Double
45+
round2 num =
46+
let
47+
f :: Int
48+
f = round $ num * 100
49+
in fromIntegral f / 100
50+
4151
asMetrics ReplayBlockStats {..} =
4252
[DoubleM "blockReplayProgress" rpsProgress]
4353

@@ -77,12 +87,12 @@ replayBlockStats ReplayBlockStats {..} _context
7787
(ChainDB.TraceLedgerDBEvent
7888
(LedgerDB.LedgerReplayEvent
7989
(LedgerDB.TraceReplayProgressEvent
80-
(LedgerDB.ReplayedBlock pt [] (LedgerDB.ReplayStart replayTo) _)))) = do
81-
let slotno = toInteger $ unSlotNo (realPointSlot pt)
82-
endslot = toInteger $ withOrigin 0 unSlotNo (pointSlot replayTo)
83-
progress' = (fromInteger slotno * 100.0) / fromInteger (max slotno endslot)
90+
(LedgerDB.ReplayedBlock pt [] _ (LedgerDB.ReplayGoal replayTo))))) = do
91+
let slotno = realPointSlot pt
92+
endslot = withOrigin 0 id $ pointSlot replayTo
93+
progress' = (fromIntegral (unSlotNo slotno) * 100.0) / fromIntegral (unSlotNo $ max slotno endslot)
8494
pure $ if (progress' == 0.0 && not rpsDisplay)
85-
|| ((progress' - rpsLastProgress) > 1.0)
86-
then ReplayBlockStats True progress' progress'
87-
else ReplayBlockStats False progress' rpsLastProgress
95+
|| ((progress' - rpsLastProgress) > 0.1)
96+
then ReplayBlockStats True slotno endslot progress' progress'
97+
else ReplayBlockStats False slotno endslot progress' rpsLastProgress
8898
replayBlockStats st@ReplayBlockStats {} _context _ = pure st

0 commit comments

Comments
 (0)