@@ -137,6 +137,8 @@ import Data.IntPSQ (IntPSQ)
137
137
import qualified Data.IntPSQ as Pq
138
138
import qualified Data.Map.Strict as Map
139
139
import Data.Proxy (Proxy (.. ))
140
+ import Data.Ratio ((%) )
141
+ import qualified Data.Scientific as Scientific
140
142
import Data.Text (Text )
141
143
import qualified Data.Text as Text
142
144
import qualified Data.Text.Encoding as Text
@@ -666,7 +668,7 @@ traceChainMetrics (Just _ekgDirect) tForks _blockConfig _fStats tr = do
666
668
-- TODO this is executed each time the newChain changes. How cheap is it?
667
669
meta <- mkLOMeta Critical Public
668
670
669
- traceD tr meta " density" density
671
+ traceD tr meta " density" ( fromRational density)
670
672
traceI tr meta " slotNum" slots
671
673
traceI tr meta " blockNum" blocks
672
674
traceI tr meta " slotInEpoch" slotInEpoch
@@ -1103,7 +1105,11 @@ traceLeadershipChecks _ft nodeKern _tverb tr = Tracer $
1103
1105
\ (utxoSize, delegMapSize, chainDensity) ->
1104
1106
[ (" utxoSize" , toJSON utxoSize)
1105
1107
, (" 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
+ )
1107
1113
])
1108
1114
)
1109
1115
_ -> pure ()
@@ -1716,7 +1722,7 @@ traceInboundGovernorCountersMetrics (OnOff True) (Just ekgDirect) = ipgcTracer
1716
1722
data ChainInformation = ChainInformation
1717
1723
{ slots :: Word64
1718
1724
, blocks :: Word64
1719
- , density :: Double
1725
+ , density :: Rational
1720
1726
-- ^ the actual number of blocks created over the maximum expected number
1721
1727
-- of blocks that could be created over the span of the last @k@ blocks.
1722
1728
, epoch :: EpochNo
@@ -1772,12 +1778,12 @@ chainInformation selChangedInfo fork oldFrag frag blocksUncoupledDelta = ChainIn
1772
1778
1773
1779
fragmentChainDensity ::
1774
1780
HasHeader (Header blk )
1775
- => AF. AnchoredFragment (Header blk ) -> Double
1781
+ => AF. AnchoredFragment (Header blk ) -> Rational
1776
1782
fragmentChainDensity frag = calcDensity blockD slotD
1777
1783
where
1778
- calcDensity :: Word64 -> Word64 -> Double
1784
+ calcDensity :: Word64 -> Word64 -> Rational
1779
1785
calcDensity bl sl
1780
- | sl > 0 = fromIntegral bl / fromIntegral sl
1786
+ | sl > 0 = toInteger bl % toInteger sl
1781
1787
| otherwise = 0
1782
1788
slotN = unSlotNo $ fromWithOrigin 0 (AF. headSlot frag)
1783
1789
-- Slot of the tip - slot @k@ blocks back. Use 0 as the slot for genesis
0 commit comments