Skip to content

Commit 48e1b55

Browse files
committed
SQUASH
1 parent ccde6bd commit 48e1b55

File tree

3 files changed

+21
-11
lines changed

3 files changed

+21
-11
lines changed

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

+5-1
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ import qualified Data.IntPSQ as Pq
8282
import qualified Data.List as List
8383
import qualified Data.Text as Text
8484
import Data.Time (NominalDiffTime)
85+
import qualified Data.Scientific as Scientific
8586
import Data.Word (Word32, Word64)
8687
import Network.TypedProtocol.Core
8788

@@ -1516,7 +1517,10 @@ instance LogFormatting TraceStartLeadershipCheckPlus where
15161517
, "slot" .= toJSON (unSlotNo tsSlotNo)
15171518
, "utxoSize" .= Number (fromIntegral tsUtxoSize)
15181519
, "delegMapSize" .= Number (fromIntegral tsDelegMapSize)
1519-
, "chainDensity" .= (toJSON tsChainDensity)
1520+
, "chainDensity" .= Number $
1521+
case Scientific.fromRationalRepetendLimited 10 tsChainDensity of
1522+
(Left (sc, _)) -> sc
1523+
(Right (sc, _)) -> sc
15201524
]
15211525
forHuman TraceStartLeadershipCheckPlus {..} =
15221526
"Checking for leadership in slot " <> showT (unSlotNo tsSlotNo)

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

+4-4
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ data TraceStartLeadershipCheckPlus =
4747
tsSlotNo :: SlotNo
4848
, tsUtxoSize :: Int
4949
, tsDelegMapSize :: Int
50-
, tsChainDensity :: Double
50+
, tsChainDensity :: Rational
5151
}
5252

5353
forgeTracerTransform ::
@@ -96,12 +96,12 @@ fragmentChainDensity ::
9696
#else
9797
AF.HasHeader (Header blk)
9898
#endif
99-
=> AF.AnchoredFragment (Header blk) -> Double
99+
=> AF.AnchoredFragment (Header blk) -> Rational
100100
fragmentChainDensity frag = calcDensity blockD slotD
101101
where
102-
calcDensity :: Word64 -> Word64 -> Double
102+
calcDensity :: Word64 -> Word64 -> Rational
103103
calcDensity bl sl
104-
| sl > 0 = fromIntegral bl / fromIntegral sl
104+
| sl > 0 = toInteger bl % toInteger sl
105105
| otherwise = 0
106106
slotN = unSlotNo $ fromWithOrigin 0 (AF.headSlot frag)
107107
-- Slot of the tip - slot @k@ blocks back. Use 0 as the slot for genesis

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

+12-6
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,8 @@ import Data.IntPSQ (IntPSQ)
137137
import qualified Data.IntPSQ as Pq
138138
import qualified Data.Map.Strict as Map
139139
import Data.Proxy (Proxy (..))
140+
import Data.Ratio ((%))
141+
import qualified Data.Scientific as Scientific
140142
import Data.Text (Text)
141143
import qualified Data.Text as Text
142144
import qualified Data.Text.Encoding as Text
@@ -666,7 +668,7 @@ traceChainMetrics (Just _ekgDirect) tForks _blockConfig _fStats tr = do
666668
-- TODO this is executed each time the newChain changes. How cheap is it?
667669
meta <- mkLOMeta Critical Public
668670

669-
traceD tr meta "density" density
671+
traceD tr meta "density" (fromRational density)
670672
traceI tr meta "slotNum" slots
671673
traceI tr meta "blockNum" blocks
672674
traceI tr meta "slotInEpoch" slotInEpoch
@@ -1103,7 +1105,11 @@ traceLeadershipChecks _ft nodeKern _tverb tr = Tracer $
11031105
\(utxoSize, delegMapSize, chainDensity) ->
11041106
[ ("utxoSize", toJSON utxoSize)
11051107
, ("delegMapSize", toJSON delegMapSize)
1106-
, ("chainDensity", toJSON chainDensity)
1108+
, ("chainDensity", Number $
1109+
case Scientific.fromRationalRepetendLimited 10 chainDensity of
1110+
(Left (sc, _)) -> sc
1111+
(Right (sc, _)) -> sc
1112+
)
11071113
])
11081114
)
11091115
_ -> pure ()
@@ -1716,7 +1722,7 @@ traceInboundGovernorCountersMetrics (OnOff True) (Just ekgDirect) = ipgcTracer
17161722
data ChainInformation = ChainInformation
17171723
{ slots :: Word64
17181724
, blocks :: Word64
1719-
, density :: Double
1725+
, density :: Rational
17201726
-- ^ the actual number of blocks created over the maximum expected number
17211727
-- of blocks that could be created over the span of the last @k@ blocks.
17221728
, epoch :: EpochNo
@@ -1772,12 +1778,12 @@ chainInformation selChangedInfo fork oldFrag frag blocksUncoupledDelta = ChainIn
17721778

17731779
fragmentChainDensity ::
17741780
HasHeader (Header blk)
1775-
=> AF.AnchoredFragment (Header blk) -> Double
1781+
=> AF.AnchoredFragment (Header blk) -> Rational
17761782
fragmentChainDensity frag = calcDensity blockD slotD
17771783
where
1778-
calcDensity :: Word64 -> Word64 -> Double
1784+
calcDensity :: Word64 -> Word64 -> Rational
17791785
calcDensity bl sl
1780-
| sl > 0 = fromIntegral bl / fromIntegral sl
1786+
| sl > 0 = toInteger bl % toInteger sl
17811787
| otherwise = 0
17821788
slotN = unSlotNo $ fromWithOrigin 0 (AF.headSlot frag)
17831789
-- Slot of the tip - slot @k@ blocks back. Use 0 as the slot for genesis

0 commit comments

Comments
 (0)