Skip to content

Commit 9e001f7

Browse files
committed
Make ChainSelStarvation carry an Enclosed
1 parent a36fd87 commit 9e001f7

File tree

3 files changed

+17
-17
lines changed
  • ouroboros-consensus-diffusion/test/consensus-test/Test/Consensus/PeerSimulator
  • ouroboros-consensus
    • src/ouroboros-consensus/Ouroboros/Consensus/Storage/ChainDB/Impl
    • test/storage-test/Test/Ouroboros/Storage/ChainDB

3 files changed

+17
-17
lines changed

ouroboros-consensus-diffusion/test/consensus-test/Test/Consensus/PeerSimulator/Trace.hs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ import qualified Ouroboros.Consensus.Storage.ChainDB.Impl as ChainDB
4343
import Ouroboros.Consensus.Storage.ChainDB.Impl.Types
4444
(TraceAddBlockEvent (..))
4545
import Ouroboros.Consensus.Util.Condense (condense)
46+
import Ouroboros.Consensus.Util.Enclose
4647
import Ouroboros.Consensus.Util.IOLike (IOLike, MonadMonotonicTime,
4748
Time (Time), atomically, getMonotonicTime, readTVarIO,
4849
uncheckedNewTVarM, writeTVar)
@@ -376,10 +377,10 @@ traceChainDBEventTestBlockWith tracer = \case
376377
AddedReprocessLoEBlocksToQueue ->
377378
trace $ "Requested ChainSel run"
378379
_ -> pure ()
379-
ChainDB.TraceChainSelStarvationEvent (ChainDB.ChainSelStarvationStarted time) ->
380-
trace $ "ChainSel starvation started at " ++ prettyTime time
381-
ChainDB.TraceChainSelStarvationEvent (ChainDB.ChainSelStarvationEnded time pt) ->
382-
trace $ "ChainSel starvation ended at " ++ prettyTime time ++ " thanks to " ++ terseRealPoint pt
380+
ChainDB.TraceChainSelStarvationEvent (ChainDB.ChainSelStarvation RisingEdge) ->
381+
trace "ChainSel starvation started"
382+
ChainDB.TraceChainSelStarvationEvent (ChainDB.ChainSelStarvation (FallingEdgeWith pt)) ->
383+
trace $ "ChainSel starvation ended thanks to " ++ terseRealPoint pt
383384
_ -> pure ()
384385
where
385386
trace = traceUnitWith tracer "ChainDB"

ouroboros-consensus/src/ouroboros-consensus/Ouroboros/Consensus/Storage/ChainDB/Impl/Types.hs

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -541,15 +541,14 @@ getChainSelMessage starvationTracer starvationVar chainSelQueue =
541541
startStarvationMeasure = do
542542
prevStarvation <- atomically $ swapTVar starvationVar ChainSelStarvationOngoing
543543
when (prevStarvation /= ChainSelStarvationOngoing) $
544-
traceWith starvationTracer . ChainSelStarvationStarted =<< getMonotonicTime
544+
traceWith starvationTracer $ ChainSelStarvation RisingEdge
545545

546546
terminateStarvationMeasure :: ChainSelMessage m blk -> m ()
547547
terminateStarvationMeasure = \case
548548
ChainSelAddBlock BlockToAdd{blockToAdd=block} -> do
549-
tf <- getMonotonicTime
550549
let pt = blockRealPoint block
551-
traceWith starvationTracer $ ChainSelStarvationEnded tf pt
552-
atomically $ writeTVar starvationVar (ChainSelStarvationEndedAt tf)
550+
traceWith starvationTracer $ ChainSelStarvation (FallingEdgeWith pt)
551+
atomically . writeTVar starvationVar . ChainSelStarvationEndedAt =<< getMonotonicTime
553552
ChainSelReprocessLoEBlocks{} -> pure ()
554553

555554
-- TODO Can't use tryReadTBQueue from io-classes because it is broken for IOSim
@@ -938,11 +937,11 @@ data TraceIteratorEvent blk
938937
-- This is the usual case and innocent while caught-up; but while syncing, it
939938
-- means that we are downloading blocks at a smaller rate than we can validate
940939
-- them, even though we generally expect to be CPU-bound.
941-
data TraceChainSelStarvationEvent blk
942-
-- | A ChainSel starvation started at the given time.
943-
= ChainSelStarvationStarted Time
944-
945-
-- | The last ChainSel starvation ended at the given time as a block wth the
946-
-- given point has been received.
947-
| ChainSelStarvationEnded Time (RealPoint blk)
940+
--
941+
-- TODO: Investigate why it happens regularly during syncing for very short
942+
-- times.
943+
--
944+
-- The point in the trace is the block that finished the starvation.
945+
newtype TraceChainSelStarvationEvent blk =
946+
ChainSelStarvation (Enclosing' (RealPoint blk))
948947
deriving (Generic, Eq, Show)

ouroboros-consensus/test/storage-test/Test/Ouroboros/Storage/ChainDB/StateMachine.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1241,8 +1241,8 @@ deriving instance SOP.Generic (ImmutableDB.TraceEvent blk)
12411241
deriving instance SOP.HasDatatypeInfo (ImmutableDB.TraceEvent blk)
12421242
deriving instance SOP.Generic (VolatileDB.TraceEvent blk)
12431243
deriving instance SOP.HasDatatypeInfo (VolatileDB.TraceEvent blk)
1244-
deriving instance SOP.Generic (TraceChainSelStarvationEvent blk)
1245-
deriving instance SOP.HasDatatypeInfo (TraceChainSelStarvationEvent blk)
1244+
deriving anyclass instance SOP.Generic (TraceChainSelStarvationEvent blk)
1245+
deriving anyclass instance SOP.HasDatatypeInfo (TraceChainSelStarvationEvent blk)
12461246

12471247
data Tag =
12481248
TagGetIsValidJust

0 commit comments

Comments
 (0)