Skip to content

TSLCP: Chain density #6186

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

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
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 @@ -1470,7 +1470,7 @@
, "slot" .= toJSON (unSlotNo tsSlotNo)
, "utxoSize" .= Number (fromIntegral tsUtxoSize)
, "delegMapSize" .= Number (fromIntegral tsDelegMapSize)
, "chainDensity" .= Number (fromRational (toRational tsChainDensity))
, "chainDensity" .= (toJSON tsChainDensity)

Check warning on line 1473 in cardano-node/src/Cardano/Node/Tracing/Tracers/Consensus.hs

View workflow job for this annotation

GitHub Actions / build

Suggestion in module Cardano.Node.Tracing.Tracers.Consensus: Redundant bracket ▫︎ Found: "\"chainDensity\" .= (toJSON tsChainDensity)" ▫︎ Perhaps: "\"chainDensity\" .= toJSON tsChainDensity"
]
forHuman TraceStartLeadershipCheckPlus {..} =
"Checking for leadership in slot " <> showT (unSlotNo tsSlotNo)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ forgeTracerTransform nodeKern (Trace tr) =
slotNo
utxoSize
delegMapSize
(fromRational chainDensity)
chainDensity
in pure (lc, Right (Right msg))
(lc, Right a) ->
pure (lc, Right a)
Expand All @@ -97,12 +97,12 @@ fragmentChainDensity ::
#else
AF.HasHeader (Header blk)
#endif
=> AF.AnchoredFragment (Header blk) -> Rational
=> AF.AnchoredFragment (Header blk) -> Double
fragmentChainDensity frag = calcDensity blockD slotD
where
calcDensity :: Word64 -> Word64 -> Rational
calcDensity :: Word64 -> Word64 -> Double
calcDensity bl sl
| sl > 0 = toRational bl / toRational sl
| sl > 0 = fromIntegral bl / fromIntegral sl
| otherwise = 0
slotN = unSlotNo $ fromWithOrigin 0 (AF.headSlot frag)
-- Slot of the tip - slot @k@ blocks back. Use 0 as the slot for genesis
Expand Down
12 changes: 6 additions & 6 deletions cardano-node/src/Cardano/Tracing/Tracers.hs
Original file line number Diff line number Diff line change
Expand Up @@ -645,7 +645,7 @@ traceChainMetrics (Just _ekgDirect) tForks _blockConfig _fStats tr = do
-- TODO this is executed each time the newChain changes. How cheap is it?
meta <- mkLOMeta Critical Public

traceD tr meta "density" (fromRational density)
traceD tr meta "density" density
traceI tr meta "slotNum" slots
traceI tr meta "blockNum" blocks
traceI tr meta "slotInEpoch" slotInEpoch
Expand Down Expand Up @@ -1082,7 +1082,7 @@ traceLeadershipChecks _ft nodeKern _tverb tr = Tracer $
\(utxoSize, delegMapSize, chainDensity) ->
[ ("utxoSize", toJSON utxoSize)
, ("delegMapSize", toJSON delegMapSize)
, ("chainDensity", toJSON (fromRational chainDensity :: Float))
, ("chainDensity", toJSON chainDensity)
])
)
_ -> pure ()
Expand Down Expand Up @@ -1693,7 +1693,7 @@ traceInboundGovernorCountersMetrics (OnOff True) (Just ekgDirect) = ipgcTracer
data ChainInformation = ChainInformation
{ slots :: Word64
, blocks :: Word64
, density :: Rational
, density :: Double
-- ^ the actual number of blocks created over the maximum expected number
-- of blocks that could be created over the span of the last @k@ blocks.
, epoch :: EpochNo
Expand Down Expand Up @@ -1749,12 +1749,12 @@ chainInformation selChangedInfo fork oldFrag frag blocksUncoupledDelta = ChainIn

fragmentChainDensity ::
HasHeader (Header blk)
=> AF.AnchoredFragment (Header blk) -> Rational
=> AF.AnchoredFragment (Header blk) -> Double
fragmentChainDensity frag = calcDensity blockD slotD
where
calcDensity :: Word64 -> Word64 -> Rational
calcDensity :: Word64 -> Word64 -> Double
calcDensity bl sl
| sl > 0 = toRational bl / toRational sl
| sl > 0 = fromIntegral bl / fromIntegral sl
| otherwise = 0
slotN = unSlotNo $ fromWithOrigin 0 (AF.headSlot frag)
-- Slot of the tip - slot @k@ blocks back. Use 0 as the slot for genesis
Expand Down
Loading