@@ -8,7 +8,7 @@ module Cardano.Node.Tracing.Tracers.BlockReplayProgress
88import Cardano.Api (textShow )
99
1010import Cardano.Logging
11- import Ouroboros.Consensus.Block (realPointSlot )
11+ import Ouroboros.Consensus.Block (SlotNo , realPointSlot )
1212import qualified Ouroboros.Consensus.Storage.ChainDB as ChainDB
1313import qualified Ouroboros.Consensus.Storage.LedgerDB as LedgerDB
1414import Ouroboros.Network.Block (pointSlot , unSlotNo )
@@ -20,12 +20,14 @@ import Data.Text (pack)
2020
2121data ReplayBlockStats = ReplayBlockStats
2222 { rpsDisplay :: Bool
23+ , rpsCurSlot :: SlotNo
24+ , rpsGoalSlot :: SlotNo
2325 , rpsProgress :: Double
2426 , rpsLastProgress :: Double
2527 }
2628
2729emptyReplayBlockStats :: 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
@@ -75,12 +85,12 @@ replayBlockStats :: MonadIO m
7585 -> m ReplayBlockStats
7686replayBlockStats ReplayBlockStats {.. } _context
7787 (ChainDB. TraceLedgerReplayEvent (LedgerDB. ReplayedBlock pt []
78- (LedgerDB. ReplayStart replayTo) _ )) = do
79- let slotno = toInteger $ unSlotNo ( realPointSlot pt)
80- endslot = toInteger $ withOrigin 0 unSlotNo ( pointSlot replayTo)
81- progress' = (fromInteger slotno * 100.0 ) / fromInteger ( max slotno endslot)
88+ _ (LedgerDB. ReplayGoal replayTo))) = do
89+ let slotno = realPointSlot pt
90+ endslot = withOrigin 0 id $ pointSlot replayTo
91+ progress' = (fromIntegral (unSlotNo slotno) * 100.0 ) / fromIntegral (unSlotNo $ max slotno endslot)
8292 pure $ if (progress' == 0.0 && not rpsDisplay)
83- || ((progress' - rpsLastProgress) > 1.0 )
84- then ReplayBlockStats True progress' progress'
85- else ReplayBlockStats False progress' rpsLastProgress
93+ || ((progress' - rpsLastProgress) > 0.1 )
94+ then ReplayBlockStats True slotno endslot progress' progress'
95+ else ReplayBlockStats False slotno endslot progress' rpsLastProgress
8696replayBlockStats st@ ReplayBlockStats {} _context _ = pure st
0 commit comments