@@ -19,6 +19,7 @@ import Cardano.Node.Tracing.Era.Shelley ()
1919import Cardano.Node.Tracing.Formatting ()
2020import Cardano.Node.Tracing.Render
2121import Cardano.Prelude (maximumDef )
22+ import Cardano.Tracing.HasIssuer
2223import Ouroboros.Consensus.Block
2324import Ouroboros.Consensus.HeaderValidation (HeaderEnvelopeError (.. ), HeaderError (.. ),
2425 OtherHeaderEnvelopeError )
@@ -41,6 +42,7 @@ import Ouroboros.Consensus.Util.Enclose
4142import qualified Ouroboros.Network.AnchoredFragment as AF
4243
4344import Data.Aeson (Value (String ), object , toJSON , (.=) )
45+ import qualified Data.ByteString.Base16 as B16
4446import Data.Int (Int64 )
4547import Data.Text (Text )
4648import qualified Data.Text as Text
@@ -50,7 +52,7 @@ import Numeric (showFFloat)
5052
5153-- {-# ANN module ("HLint: ignore Redundant bracket" :: Text) #-}
5254
53- -- TODO implement differently so that it uses configuration
55+ -- A limiter that is not coming from configuration, because it carries a special filter
5456withAddedToCurrentChainEmptyLimited
5557 :: Trace IO (ChainDB. TraceEvent blk )
5658 -> IO (Trace IO (ChainDB. TraceEvent blk ))
@@ -79,6 +81,7 @@ instance ( LogFormatting (Header blk)
7981 , ConvertRawHash (Header blk )
8082 , LedgerSupportsProtocol blk
8183 , InspectLedger blk
84+ , HasIssuer blk
8285 ) => LogFormatting (ChainDB. TraceEvent blk ) where
8386 forHuman ChainDB. TraceLastShutdownUnclean =
8487 " ChainDB is not clean. Validating all immutable chunks"
@@ -394,6 +397,7 @@ instance ( LogFormatting (Header blk)
394397 , ConvertRawHash (Header blk )
395398 , LedgerSupportsProtocol blk
396399 , InspectLedger blk
400+ , HasIssuer blk
397401 ) => LogFormatting (ChainDB. TraceAddBlockEvent blk ) where
398402 forHuman (ChainDB. IgnoreBlockOlderThanK pt) =
399403 " Ignoring block older than K: " <> renderRealPointAsPhrase pt
@@ -480,7 +484,31 @@ instance ( LogFormatting (Header blk)
480484 forMachine dtal (ChainDB. ChangingSelection pt) =
481485 mconcat [ " kind" .= String " TraceAddBlockEvent.ChangingSelection"
482486 , " block" .= forMachine dtal pt ]
483- forMachine dtal (ChainDB. AddedToCurrentChain events selChangedInfo base extended) =
487+
488+ forMachine DDetailed (ChainDB. AddedToCurrentChain events selChangedInfo base extended) =
489+ let ChainInformation { .. } = chainInformation selChangedInfo base extended 0
490+ tipBlockIssuerVkHashText :: Text
491+ tipBlockIssuerVkHashText =
492+ case tipBlockIssuerVerificationKeyHash of
493+ NoBlockIssuer -> " NoBlockIssuer"
494+ BlockIssuerVerificationKeyHash bs ->
495+ Text. decodeLatin1 (B16. encode bs)
496+ in mconcat $
497+ [ " kind" .= String " AddedToCurrentChain"
498+ , " newtip" .= renderPointForDetails DDetailed (AF. headPoint extended)
499+ , " newTipSelectView" .= forMachine DDetailed (ChainDB. newTipSelectView selChangedInfo)
500+ ]
501+ ++ [ " oldTipSelectView" .= forMachine DDetailed oldTipSelectView
502+ | Just oldTipSelectView <- [ChainDB. oldTipSelectView selChangedInfo]
503+ ]
504+ ++ [ " headers" .= toJSON (forMachine DDetailed `map` addedHdrsNewChain base extended)
505+ ]
506+ ++ [ " events" .= toJSON (map (forMachine DDetailed ) events)
507+ | not (null events) ]
508+ ++ [ " tipBlockHash" .= tipBlockHash
509+ , " tipBlockParentHash" .= tipBlockParentHash
510+ , " tipBlockIssuerVKeyHash" .= tipBlockIssuerVkHashText]
511+ forMachine dtal (ChainDB. AddedToCurrentChain events selChangedInfo _base extended) =
484512 mconcat $
485513 [ " kind" .= String " AddedToCurrentChain"
486514 , " newtip" .= renderPointForDetails dtal (AF. headPoint extended)
@@ -489,11 +517,33 @@ instance ( LogFormatting (Header blk)
489517 ++ [ " oldTipSelectView" .= forMachine dtal oldTipSelectView
490518 | Just oldTipSelectView <- [ChainDB. oldTipSelectView selChangedInfo]
491519 ]
492- ++ [ " headers" .= toJSON (forMachine dtal `map` addedHdrsNewChain base extended)
493- | dtal == DDetailed ]
494520 ++ [ " events" .= toJSON (map (forMachine dtal) events)
495521 | not (null events) ]
496- forMachine dtal (ChainDB. SwitchedToAFork events selChangedInfo old new) =
522+
523+ forMachine DDetailed (ChainDB. SwitchedToAFork events selChangedInfo old new) =
524+ let ChainInformation { .. } = chainInformation selChangedInfo old new 0
525+ tipBlockIssuerVkHashText :: Text
526+ tipBlockIssuerVkHashText =
527+ case tipBlockIssuerVerificationKeyHash of
528+ NoBlockIssuer -> " NoBlockIssuer"
529+ BlockIssuerVerificationKeyHash bs ->
530+ Text. decodeLatin1 (B16. encode bs)
531+ in mconcat $
532+ [ " kind" .= String " TraceAddBlockEvent.SwitchedToAFork"
533+ , " newtip" .= renderPointForDetails DDetailed (AF. headPoint new)
534+ , " newTipSelectView" .= forMachine DDetailed (ChainDB. newTipSelectView selChangedInfo)
535+ ]
536+ ++ [ " oldTipSelectView" .= forMachine DDetailed oldTipSelectView
537+ | Just oldTipSelectView <- [ChainDB. oldTipSelectView selChangedInfo]
538+ ]
539+ ++ [ " headers" .= toJSON (forMachine DDetailed `map` addedHdrsNewChain old new)
540+ ]
541+ ++ [ " events" .= toJSON (map (forMachine DDetailed ) events)
542+ | not (null events) ]
543+ ++ [ " tipBlockHash" .= tipBlockHash
544+ , " tipBlockParentHash" .= tipBlockParentHash
545+ , " tipBlockIssuerVKeyHash" .= tipBlockIssuerVkHashText]
546+ forMachine dtal (ChainDB. SwitchedToAFork events selChangedInfo _old new) =
497547 mconcat $
498548 [ " kind" .= String " TraceAddBlockEvent.SwitchedToAFork"
499549 , " newtip" .= renderPointForDetails dtal (AF. headPoint new)
@@ -502,10 +552,9 @@ instance ( LogFormatting (Header blk)
502552 ++ [ " oldTipSelectView" .= forMachine dtal oldTipSelectView
503553 | Just oldTipSelectView <- [ChainDB. oldTipSelectView selChangedInfo]
504554 ]
505- ++ [ " headers" .= toJSON (forMachine dtal `map` addedHdrsNewChain old new)
506- | dtal == DDetailed ]
507555 ++ [ " events" .= toJSON (map (forMachine dtal) events)
508556 | not (null events) ]
557+
509558 forMachine dtal (ChainDB. AddBlockValidation ev') =
510559 forMachine dtal ev'
511560 forMachine dtal (ChainDB. AddedBlockToVolatileDB pt (BlockNo bn) _ enclosing) =
@@ -544,22 +593,38 @@ instance ( LogFormatting (Header blk)
544593 asMetrics (ChainDB. SwitchedToAFork _warnings selChangedInfo oldChain newChain) =
545594 let forkIt = not $ AF. withinFragmentBounds (AF. headPoint oldChain)
546595 newChain
547- ChainInformation { .. } = chainInformation selChangedInfo newChain 0
596+ ChainInformation { .. } = chainInformation selChangedInfo oldChain newChain 0
597+ tipBlockIssuerVkHashText =
598+ case tipBlockIssuerVerificationKeyHash of
599+ NoBlockIssuer -> " NoBlockIssuer"
600+ BlockIssuerVerificationKeyHash bs ->
601+ Text. decodeLatin1 (B16. encode bs)
548602 in [ DoubleM " density" (fromRational density)
549603 , IntM " slotNum" (fromIntegral slots)
550604 , IntM " blockNum" (fromIntegral blocks)
551605 , IntM " slotInEpoch" (fromIntegral slotInEpoch)
552606 , IntM " epoch" (fromIntegral (unEpochNo epoch))
553607 , CounterM " forks" (Just (if forkIt then 1 else 0 ))
608+ , PrometheusM " tipBlock" [(" hash" ,tipBlockHash)
609+ ,(" parent_hash" ,tipBlockParentHash)
610+ ,(" issuer_VKey_hash" , tipBlockIssuerVkHashText)]
554611 ]
555- asMetrics (ChainDB. AddedToCurrentChain _warnings selChangedInfo _oldChain newChain) =
612+ asMetrics (ChainDB. AddedToCurrentChain _warnings selChangedInfo oldChain newChain) =
556613 let ChainInformation { .. } =
557- chainInformation selChangedInfo newChain 0
614+ chainInformation selChangedInfo oldChain newChain 0
615+ tipBlockIssuerVkHashText =
616+ case tipBlockIssuerVerificationKeyHash of
617+ NoBlockIssuer -> " NoBlockIssuer"
618+ BlockIssuerVerificationKeyHash bs ->
619+ Text. decodeLatin1 (B16. encode bs)
558620 in [ DoubleM " density" (fromRational density)
559621 , IntM " slotNum" (fromIntegral slots)
560622 , IntM " blockNum" (fromIntegral blocks)
561623 , IntM " slotInEpoch" (fromIntegral slotInEpoch)
562624 , IntM " epoch" (fromIntegral (unEpochNo epoch))
625+ , PrometheusM " tipBlock" [(" hash" ,tipBlockHash)
626+ ,(" parent hash" ,tipBlockParentHash)
627+ ,(" issuer verification key hash" , tipBlockIssuerVkHashText)]
563628 ]
564629 asMetrics _ = []
565630
@@ -680,7 +745,14 @@ instance MetaTrace (ChainDB.TraceAddBlockEvent blk) where
680745 , ( " epoch"
681746 , " In which epoch is the tip of the current chain."
682747 )
748+ , ( " forks"
749+ , " counter for forks"
750+ )
751+ , ( " tipBlock"
752+ , " Values for hash, parent hash and issuer verification key hash"
753+ )
683754 ]
755+
684756 metricsDocFor (Namespace _ [" AddedToCurrentChain" ]) =
685757 [ ( " density"
686758 , mconcat
@@ -703,6 +775,9 @@ instance MetaTrace (ChainDB.TraceAddBlockEvent blk) where
703775 , ( " epoch"
704776 , " In which epoch is the tip of the current chain."
705777 )
778+ , ( " tipBlock"
779+ , " Values for hash, parent hash and issuer verification key hash"
780+ )
706781 ]
707782 metricsDocFor _ = []
708783
@@ -1488,7 +1563,6 @@ instance MetaTrace (ChainDB.UnknownRange blk) where
14881563 namespaceFor ChainDB. MissingBlock {} = Namespace [] [" MissingBlock" ]
14891564 namespaceFor ChainDB. ForkTooOld {} = Namespace [] [" ForkTooOld" ]
14901565
1491- -- TODO Tracers Is this really as intended?
14921566 severityFor _ _ = Just Debug
14931567
14941568 documentFor (Namespace _ [" MissingBlock" ]) = Just
@@ -2097,22 +2171,38 @@ data ChainInformation = ChainInformation
20972171 -- ^ Relative slot number of the tip of the current chain within the
20982172 -- epoch.
20992173 , blocksUncoupledDelta :: Int64
2174+ , tipBlockHash :: Text
2175+ -- ^ Hash of the last adopted block.
2176+ , tipBlockParentHash :: Text
2177+ -- ^ Hash of the parent block of the last adopted block.
2178+ , tipBlockIssuerVerificationKeyHash :: BlockIssuerVerificationKeyHash
2179+ -- ^ Hash of the last adopted block issuer's verification key.
21002180 }
21012181
2182+
21022183chainInformation
21032184 :: forall blk . HasHeader (Header blk )
2185+ => HasIssuer blk
2186+ => ConvertRawHash blk
21042187 => ChainDB. SelectionChangedInfo blk
21052188 -> AF. AnchoredFragment (Header blk )
2189+ -> AF. AnchoredFragment (Header blk ) -- ^ New fragment.
21062190 -> Int64
21072191 -> ChainInformation
2108- chainInformation selChangedInfo frag blocksUncoupledDelta = ChainInformation
2192+ chainInformation selChangedInfo oldFrag frag blocksUncoupledDelta = ChainInformation
21092193 { slots = unSlotNo $ fromWithOrigin 0 (AF. headSlot frag)
21102194 , blocks = unBlockNo $ fromWithOrigin (BlockNo 1 ) (AF. headBlockNo frag)
21112195 , density = fragmentChainDensity frag
21122196 , epoch = ChainDB. newTipEpoch selChangedInfo
21132197 , slotInEpoch = ChainDB. newTipSlotInEpoch selChangedInfo
21142198 , blocksUncoupledDelta = blocksUncoupledDelta
2199+ , tipBlockHash = renderHeaderHash (Proxy @ blk ) $ realPointHash (ChainDB. newTipPoint selChangedInfo)
2200+ , tipBlockParentHash = renderChainHash (Text. decodeLatin1 . B16. encode . toRawHash (Proxy @ blk )) $ AF. headHash oldFrag
2201+ , tipBlockIssuerVerificationKeyHash = tipIssuerVkHash
21152202 }
2203+ where
2204+ tipIssuerVkHash :: BlockIssuerVerificationKeyHash
2205+ tipIssuerVkHash = either (const NoBlockIssuer ) getIssuerVerificationKeyHash (AF. head frag)
21162206
21172207fragmentChainDensity ::
21182208 HasHeader (Header blk )
0 commit comments