Skip to content

Commit d71a09d

Browse files
committed
Deparameterise ChainInformation.
1 parent c3ae0e0 commit d71a09d

File tree

1 file changed

+19
-26
lines changed

1 file changed

+19
-26
lines changed

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

+19-26
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ import Cardano.BM.Trace (traceNamedObject)
6565
import Cardano.BM.Tracing
6666

6767
import Ouroboros.Consensus.Block (BlockConfig, BlockProtocol, CannotForge,
68-
ConvertRawHash (..), ForgeStateInfo, ForgeStateUpdateError, Header, HeaderHash,
68+
ConvertRawHash (..), ForgeStateInfo, ForgeStateUpdateError, Header,
6969
realPointHash, realPointSlot)
7070
import Ouroboros.Consensus.BlockchainTime (SystemStart (..),
7171
TraceBlockchainTimeEvent (..))
@@ -88,8 +88,8 @@ import qualified Ouroboros.Consensus.Protocol.Ledger.HotKey as HotKey
8888
import Ouroboros.Consensus.Util.Enclose
8989

9090
import qualified Ouroboros.Network.AnchoredFragment as AF
91-
import Ouroboros.Network.Block (BlockNo (..), ChainHash (..), ChainUpdate (..),
92-
HasHeader (..), Point, StandardHash, blockNo, pointSlot, unBlockNo)
91+
import Ouroboros.Network.Block (BlockNo (..), ChainUpdate (..), HasHeader (..), Point,
92+
StandardHash, blockNo, pointSlot, unBlockNo)
9393
import Ouroboros.Network.BlockFetch.ClientState (TraceFetchClientState (..),
9494
TraceLabelPeer (..))
9595
import Ouroboros.Network.BlockFetch.Decision (FetchDecision, FetchDecline (..))
@@ -558,7 +558,7 @@ traceChainMetrics (Just _ekgDirect) tForks _blockConfig _fStats tr = do
558558
Tracer $ \ev ->
559559
maybe (pure ()) doTrace (chainTipInformation ev)
560560
where
561-
chainTipInformation :: ChainDB.TraceEvent blk -> Maybe (ChainInformation blk)
561+
chainTipInformation :: ChainDB.TraceEvent blk -> Maybe ChainInformation
562562
chainTipInformation = \case
563563
ChainDB.TraceAddBlockEvent ev -> case ev of
564564
ChainDB.SwitchedToAFork _warnings newTipInfo oldChain newChain ->
@@ -570,10 +570,10 @@ traceChainMetrics (Just _ekgDirect) tForks _blockConfig _fStats tr = do
570570
_ -> Nothing
571571
_ -> Nothing
572572

573-
doTrace :: ChainInformation blk -> IO ()
573+
doTrace :: ChainInformation -> IO ()
574574
doTrace
575575
ChainInformation { slots, blocks, density, epoch, slotInEpoch, fork, tipBlockHash, tipBlockParentHash, tipBlockIssuerVerificationKeyHash } = do
576-
-- TODO this is executed each time the newFhain changes. How cheap is it?
576+
-- TODO this is executed each time the newChain changes. How cheap is it?
577577
meta <- mkLOMeta Critical Public
578578

579579
traceD tr meta "density" (fromRational density)
@@ -584,29 +584,19 @@ traceChainMetrics (Just _ekgDirect) tForks _blockConfig _fStats tr = do
584584
when fork $
585585
traceI tr meta "forks" =<< STM.modifyReadTVarIO tForks succ
586586

587-
588-
let tipBlockHashText :: Text
589-
tipBlockHashText = renderHeaderHash (Proxy @blk) tipBlockHash
590-
591-
tipBlockParentHashText :: Text
592-
tipBlockParentHashText =
593-
renderChainHash
594-
(Text.decodeLatin1 . B16.encode . toRawHash (Proxy @blk))
595-
tipBlockParentHash
596-
597-
tipBlockIssuerVkHashText :: Text
587+
let tipBlockIssuerVkHashText :: Text
598588
tipBlockIssuerVkHashText =
599589
case tipBlockIssuerVerificationKeyHash of
600590
NoBlockIssuer -> "NoBlockIssuer"
601591
BlockIssuerVerificationKeyHash bs ->
602592
Text.decodeLatin1 (B16.encode bs)
603593
traceNamedObject
604594
(appendName "tipBlockHash" tr)
605-
(meta, LogMessage tipBlockHashText)
595+
(meta, LogMessage tipBlockHash)
606596

607597
traceNamedObject
608598
(appendName "tipBlockParentHash" tr)
609-
(meta, LogMessage tipBlockParentHashText)
599+
(meta, LogMessage tipBlockParentHash)
610600

611601
traceNamedObject
612602
(appendName "tipBlockIssuerVerificationKeyHash" tr)
@@ -1502,7 +1492,7 @@ traceInboundGovernorCountersMetrics (OnOff True) (Just ekgDirect) = ipgcTracer
15021492

15031493
-- | get information about a chain fragment
15041494

1505-
data ChainInformation blk = ChainInformation
1495+
data ChainInformation = ChainInformation
15061496
{ slots :: Word64
15071497
, blocks :: Word64
15081498
, density :: Rational
@@ -1518,22 +1508,25 @@ data ChainInformation blk = ChainInformation
15181508
-- current chain.
15191509
, fork :: Bool
15201510
-- ^ Was this a fork.
1521-
, tipBlockHash :: HeaderHash blk
1511+
, tipBlockHash :: Text
15221512
-- ^ Hash of the last adopted block.
1523-
, tipBlockParentHash :: ChainHash (Header blk)
1513+
, tipBlockParentHash :: Text
15241514
-- ^ Hash of the parent block of the last adopted block.
15251515
, tipBlockIssuerVerificationKeyHash :: BlockIssuerVerificationKeyHash
15261516
-- ^ Hash of the last adopted block issuer's verification key.
15271517
}
15281518

15291519
chainInformation
1530-
:: forall blk. (HasHeader (Header blk), HasIssuer blk)
1520+
:: forall blk. ()
1521+
=> HasHeader (Header blk)
1522+
=> HasIssuer blk
1523+
=> ConvertRawHash blk
15311524
=> ChainDB.NewTipInfo blk
15321525
-> Bool
15331526
-> AF.AnchoredFragment (Header blk) -- ^ Old fragment.
15341527
-> AF.AnchoredFragment (Header blk) -- ^ New fragment.
15351528
-> Int64
1536-
-> ChainInformation blk
1529+
-> ChainInformation
15371530
chainInformation newTipInfo fork oldFrag frag blocksUncoupledDelta = ChainInformation
15381531
{ slots = unSlotNo $ fromWithOrigin 0 (AF.headSlot frag)
15391532
, blocks = unBlockNo $ fromWithOrigin (BlockNo 1) (AF.headBlockNo frag)
@@ -1542,8 +1535,8 @@ chainInformation newTipInfo fork oldFrag frag blocksUncoupledDelta = ChainInform
15421535
, slotInEpoch = ChainDB.newTipSlotInEpoch newTipInfo
15431536
, blocksUncoupledDelta = blocksUncoupledDelta
15441537
, fork = fork
1545-
, tipBlockHash = realPointHash (ChainDB.newTipPoint newTipInfo)
1546-
, tipBlockParentHash = AF.headHash oldFrag
1538+
, tipBlockHash = renderHeaderHash (Proxy @blk) $ realPointHash (ChainDB.newTipPoint newTipInfo)
1539+
, tipBlockParentHash = renderChainHash (Text.decodeLatin1 . B16.encode . toRawHash (Proxy @blk)) $ AF.headHash oldFrag
15471540
, tipBlockIssuerVerificationKeyHash = tipIssuerVkHash
15481541
}
15491542
where

0 commit comments

Comments
 (0)