Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make ChainSelStarvation carry an Enclosed #1349

Merged
merged 1 commit into from
Dec 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ import qualified Ouroboros.Consensus.Storage.ChainDB.Impl as ChainDB
import Ouroboros.Consensus.Storage.ChainDB.Impl.Types
(TraceAddBlockEvent (..))
import Ouroboros.Consensus.Util.Condense (condense)
import Ouroboros.Consensus.Util.Enclose
import Ouroboros.Consensus.Util.IOLike (IOLike, MonadMonotonicTime,
Time (Time), atomically, getMonotonicTime, readTVarIO,
uncheckedNewTVarM, writeTVar)
Expand Down Expand Up @@ -376,10 +377,10 @@ traceChainDBEventTestBlockWith tracer = \case
AddedReprocessLoEBlocksToQueue ->
trace $ "Requested ChainSel run"
_ -> pure ()
ChainDB.TraceChainSelStarvationEvent (ChainDB.ChainSelStarvationStarted time) ->
trace $ "ChainSel starvation started at " ++ prettyTime time
ChainDB.TraceChainSelStarvationEvent (ChainDB.ChainSelStarvationEnded time pt) ->
trace $ "ChainSel starvation ended at " ++ prettyTime time ++ " thanks to " ++ terseRealPoint pt
ChainDB.TraceChainSelStarvationEvent (ChainDB.ChainSelStarvation RisingEdge) ->
trace "ChainSel starvation started"
ChainDB.TraceChainSelStarvationEvent (ChainDB.ChainSelStarvation (FallingEdgeWith pt)) ->
trace $ "ChainSel starvation ended thanks to " ++ terseRealPoint pt
_ -> pure ()
where
trace = traceUnitWith tracer "ChainDB"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -541,15 +541,14 @@ getChainSelMessage starvationTracer starvationVar chainSelQueue =
startStarvationMeasure = do
prevStarvation <- atomically $ swapTVar starvationVar ChainSelStarvationOngoing
when (prevStarvation /= ChainSelStarvationOngoing) $
traceWith starvationTracer . ChainSelStarvationStarted =<< getMonotonicTime
traceWith starvationTracer $ ChainSelStarvation RisingEdge

terminateStarvationMeasure :: ChainSelMessage m blk -> m ()
terminateStarvationMeasure = \case
ChainSelAddBlock BlockToAdd{blockToAdd=block} -> do
tf <- getMonotonicTime
let pt = blockRealPoint block
traceWith starvationTracer $ ChainSelStarvationEnded tf pt
atomically $ writeTVar starvationVar (ChainSelStarvationEndedAt tf)
traceWith starvationTracer $ ChainSelStarvation (FallingEdgeWith pt)
atomically . writeTVar starvationVar . ChainSelStarvationEndedAt =<< getMonotonicTime
ChainSelReprocessLoEBlocks{} -> pure ()

-- TODO Can't use tryReadTBQueue from io-classes because it is broken for IOSim
Expand Down Expand Up @@ -938,11 +937,11 @@ data TraceIteratorEvent blk
-- This is the usual case and innocent while caught-up; but while syncing, it
-- means that we are downloading blocks at a smaller rate than we can validate
-- them, even though we generally expect to be CPU-bound.
data TraceChainSelStarvationEvent blk
-- | A ChainSel starvation started at the given time.
= ChainSelStarvationStarted Time

-- | The last ChainSel starvation ended at the given time as a block wth the
-- given point has been received.
| ChainSelStarvationEnded Time (RealPoint blk)
--
-- TODO: Investigate why it happens regularly during syncing for very short
-- times.
--
-- The point in the trace is the block that finished the starvation.
newtype TraceChainSelStarvationEvent blk =
ChainSelStarvation (Enclosing' (RealPoint blk))
deriving (Generic, Eq, Show)
Original file line number Diff line number Diff line change
Expand Up @@ -1241,8 +1241,8 @@ deriving instance SOP.Generic (ImmutableDB.TraceEvent blk)
deriving instance SOP.HasDatatypeInfo (ImmutableDB.TraceEvent blk)
deriving instance SOP.Generic (VolatileDB.TraceEvent blk)
deriving instance SOP.HasDatatypeInfo (VolatileDB.TraceEvent blk)
deriving instance SOP.Generic (TraceChainSelStarvationEvent blk)
deriving instance SOP.HasDatatypeInfo (TraceChainSelStarvationEvent blk)
deriving anyclass instance SOP.Generic (TraceChainSelStarvationEvent blk)
deriving anyclass instance SOP.HasDatatypeInfo (TraceChainSelStarvationEvent blk)

data Tag =
TagGetIsValidJust
Expand Down
Loading