@@ -19,6 +19,7 @@ import Cardano.Node.Tracing.Era.Shelley ()
19
19
import Cardano.Node.Tracing.Formatting ()
20
20
import Cardano.Node.Tracing.Render
21
21
import Cardano.Prelude (maximumDef )
22
+ import Cardano.Tracing.HasIssuer
22
23
import Ouroboros.Consensus.Block
23
24
import Ouroboros.Consensus.HeaderValidation (HeaderEnvelopeError (.. ), HeaderError (.. ),
24
25
OtherHeaderEnvelopeError )
@@ -41,6 +42,7 @@ import Ouroboros.Consensus.Util.Enclose
41
42
import qualified Ouroboros.Network.AnchoredFragment as AF
42
43
43
44
import Data.Aeson (Value (String ), object , toJSON , (.=) )
45
+ import qualified Data.ByteString.Base16 as B16
44
46
import Data.Int (Int64 )
45
47
import Data.Text (Text )
46
48
import qualified Data.Text as Text
@@ -50,7 +52,7 @@ import Numeric (showFFloat)
50
52
51
53
-- {-# ANN module ("HLint: ignore Redundant bracket" :: Text) #-}
52
54
53
- -- TODO implement differently so that it uses configuration
55
+ -- A limiter that is not coming from configuration, because it carries a special filter
54
56
withAddedToCurrentChainEmptyLimited
55
57
:: Trace IO (ChainDB. TraceEvent blk )
56
58
-> IO (Trace IO (ChainDB. TraceEvent blk ))
@@ -79,6 +81,7 @@ instance ( LogFormatting (Header blk)
79
81
, ConvertRawHash (Header blk )
80
82
, LedgerSupportsProtocol blk
81
83
, InspectLedger blk
84
+ , HasIssuer blk
82
85
) => LogFormatting (ChainDB. TraceEvent blk ) where
83
86
forHuman ChainDB. TraceLastShutdownUnclean =
84
87
" ChainDB is not clean. Validating all immutable chunks"
@@ -394,6 +397,7 @@ instance ( LogFormatting (Header blk)
394
397
, ConvertRawHash (Header blk )
395
398
, LedgerSupportsProtocol blk
396
399
, InspectLedger blk
400
+ , HasIssuer blk
397
401
) => LogFormatting (ChainDB. TraceAddBlockEvent blk ) where
398
402
forHuman (ChainDB. IgnoreBlockOlderThanK pt) =
399
403
" Ignoring block older than K: " <> renderRealPointAsPhrase pt
@@ -480,7 +484,31 @@ instance ( LogFormatting (Header blk)
480
484
forMachine dtal (ChainDB. ChangingSelection pt) =
481
485
mconcat [ " kind" .= String " TraceAddBlockEvent.ChangingSelection"
482
486
, " 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) =
484
512
mconcat $
485
513
[ " kind" .= String " AddedToCurrentChain"
486
514
, " newtip" .= renderPointForDetails dtal (AF. headPoint extended)
@@ -489,11 +517,33 @@ instance ( LogFormatting (Header blk)
489
517
++ [ " oldTipSelectView" .= forMachine dtal oldTipSelectView
490
518
| Just oldTipSelectView <- [ChainDB. oldTipSelectView selChangedInfo]
491
519
]
492
- ++ [ " headers" .= toJSON (forMachine dtal `map` addedHdrsNewChain base extended)
493
- | dtal == DDetailed ]
494
520
++ [ " events" .= toJSON (map (forMachine dtal) events)
495
521
| 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) =
497
547
mconcat $
498
548
[ " kind" .= String " TraceAddBlockEvent.SwitchedToAFork"
499
549
, " newtip" .= renderPointForDetails dtal (AF. headPoint new)
@@ -502,10 +552,9 @@ instance ( LogFormatting (Header blk)
502
552
++ [ " oldTipSelectView" .= forMachine dtal oldTipSelectView
503
553
| Just oldTipSelectView <- [ChainDB. oldTipSelectView selChangedInfo]
504
554
]
505
- ++ [ " headers" .= toJSON (forMachine dtal `map` addedHdrsNewChain old new)
506
- | dtal == DDetailed ]
507
555
++ [ " events" .= toJSON (map (forMachine dtal) events)
508
556
| not (null events) ]
557
+
509
558
forMachine dtal (ChainDB. AddBlockValidation ev') =
510
559
forMachine dtal ev'
511
560
forMachine dtal (ChainDB. AddedBlockToVolatileDB pt (BlockNo bn) _ enclosing) =
@@ -544,22 +593,38 @@ instance ( LogFormatting (Header blk)
544
593
asMetrics (ChainDB. SwitchedToAFork _warnings selChangedInfo oldChain newChain) =
545
594
let forkIt = not $ AF. withinFragmentBounds (AF. headPoint oldChain)
546
595
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)
548
602
in [ DoubleM " density" (fromRational density)
549
603
, IntM " slotNum" (fromIntegral slots)
550
604
, IntM " blockNum" (fromIntegral blocks)
551
605
, IntM " slotInEpoch" (fromIntegral slotInEpoch)
552
606
, IntM " epoch" (fromIntegral (unEpochNo epoch))
553
607
, CounterM " forks" (Just (if forkIt then 1 else 0 ))
608
+ , PrometheusM " tipBlock" [(" hash" ,tipBlockHash)
609
+ ,(" parent_hash" ,tipBlockParentHash)
610
+ ,(" issuer_VKey_hash" , tipBlockIssuerVkHashText)]
554
611
]
555
- asMetrics (ChainDB. AddedToCurrentChain _warnings selChangedInfo _oldChain newChain) =
612
+ asMetrics (ChainDB. AddedToCurrentChain _warnings selChangedInfo oldChain newChain) =
556
613
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)
558
620
in [ DoubleM " density" (fromRational density)
559
621
, IntM " slotNum" (fromIntegral slots)
560
622
, IntM " blockNum" (fromIntegral blocks)
561
623
, IntM " slotInEpoch" (fromIntegral slotInEpoch)
562
624
, IntM " epoch" (fromIntegral (unEpochNo epoch))
625
+ , PrometheusM " tipBlock" [(" hash" ,tipBlockHash)
626
+ ,(" parent hash" ,tipBlockParentHash)
627
+ ,(" issuer verification key hash" , tipBlockIssuerVkHashText)]
563
628
]
564
629
asMetrics _ = []
565
630
@@ -680,7 +745,14 @@ instance MetaTrace (ChainDB.TraceAddBlockEvent blk) where
680
745
, ( " epoch"
681
746
, " In which epoch is the tip of the current chain."
682
747
)
748
+ , ( " forks"
749
+ , " counter for forks"
750
+ )
751
+ , ( " tipBlock"
752
+ , " Values for hash, parent hash and issuer verification key hash"
753
+ )
683
754
]
755
+
684
756
metricsDocFor (Namespace _ [" AddedToCurrentChain" ]) =
685
757
[ ( " density"
686
758
, mconcat
@@ -703,6 +775,9 @@ instance MetaTrace (ChainDB.TraceAddBlockEvent blk) where
703
775
, ( " epoch"
704
776
, " In which epoch is the tip of the current chain."
705
777
)
778
+ , ( " tipBlock"
779
+ , " Values for hash, parent hash and issuer verification key hash"
780
+ )
706
781
]
707
782
metricsDocFor _ = []
708
783
@@ -1488,7 +1563,6 @@ instance MetaTrace (ChainDB.UnknownRange blk) where
1488
1563
namespaceFor ChainDB. MissingBlock {} = Namespace [] [" MissingBlock" ]
1489
1564
namespaceFor ChainDB. ForkTooOld {} = Namespace [] [" ForkTooOld" ]
1490
1565
1491
- -- TODO Tracers Is this really as intended?
1492
1566
severityFor _ _ = Just Debug
1493
1567
1494
1568
documentFor (Namespace _ [" MissingBlock" ]) = Just
@@ -2097,22 +2171,38 @@ data ChainInformation = ChainInformation
2097
2171
-- ^ Relative slot number of the tip of the current chain within the
2098
2172
-- epoch.
2099
2173
, 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.
2100
2180
}
2101
2181
2182
+
2102
2183
chainInformation
2103
2184
:: forall blk . HasHeader (Header blk )
2185
+ => HasIssuer blk
2186
+ => ConvertRawHash blk
2104
2187
=> ChainDB. SelectionChangedInfo blk
2105
2188
-> AF. AnchoredFragment (Header blk )
2189
+ -> AF. AnchoredFragment (Header blk ) -- ^ New fragment.
2106
2190
-> Int64
2107
2191
-> ChainInformation
2108
- chainInformation selChangedInfo frag blocksUncoupledDelta = ChainInformation
2192
+ chainInformation selChangedInfo oldFrag frag blocksUncoupledDelta = ChainInformation
2109
2193
{ slots = unSlotNo $ fromWithOrigin 0 (AF. headSlot frag)
2110
2194
, blocks = unBlockNo $ fromWithOrigin (BlockNo 1 ) (AF. headBlockNo frag)
2111
2195
, density = fragmentChainDensity frag
2112
2196
, epoch = ChainDB. newTipEpoch selChangedInfo
2113
2197
, slotInEpoch = ChainDB. newTipSlotInEpoch selChangedInfo
2114
2198
, 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
2115
2202
}
2203
+ where
2204
+ tipIssuerVkHash :: BlockIssuerVerificationKeyHash
2205
+ tipIssuerVkHash = either (const NoBlockIssuer ) getIssuerVerificationKeyHash (AF. head frag)
2116
2206
2117
2207
fragmentChainDensity ::
2118
2208
HasHeader (Header blk )
0 commit comments