Skip to content

Commit e85b48e

Browse files
committed
cardano-node: Fixes
1 parent 51ec011 commit e85b48e

File tree

3 files changed

+56
-8
lines changed

3 files changed

+56
-8
lines changed

cardano-node/src/Cardano/Node/TraceConstraints.hs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ type TraceConstraints blk =
4444
, HasKESInfo blk
4545
, GetKESInfo blk
4646
, RunNode blk
47+
, HasIssuer blk
4748

4849
, ToObject (ApplyTxErr blk)
4950
, ToObject (GenTx blk)

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

Lines changed: 54 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import Cardano.Node.Tracing.Era.Shelley ()
1919
import Cardano.Node.Tracing.Formatting ()
2020
import Cardano.Node.Tracing.Render
2121
import Cardano.Prelude (maximumDef)
22+
import Cardano.Tracing.HasIssuer
2223
import Ouroboros.Consensus.Block
2324
import Ouroboros.Consensus.HeaderValidation (HeaderEnvelopeError (..), HeaderError (..),
2425
OtherHeaderEnvelopeError)
@@ -41,6 +42,7 @@ import Ouroboros.Consensus.Util.Enclose
4142
import qualified Ouroboros.Network.AnchoredFragment as AF
4243

4344
import Data.Aeson (Value (String), object, toJSON, (.=))
45+
import qualified Data.ByteString.Base16 as B16
4446
import Data.Int (Int64)
4547
import Data.Text (Text)
4648
import 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
5456
withAddedToCurrentChainEmptyLimited
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
@@ -481,7 +485,14 @@ instance ( LogFormatting (Header blk)
481485
mconcat [ "kind" .= String "TraceAddBlockEvent.ChangingSelection"
482486
, "block" .= forMachine dtal pt ]
483487
forMachine dtal (ChainDB.AddedToCurrentChain events selChangedInfo base extended) =
484-
mconcat $
488+
let ChainInformation { .. } = chainInformation selChangedInfo base extended 0
489+
tipBlockIssuerVkHashText :: Text
490+
tipBlockIssuerVkHashText =
491+
case tipBlockIssuerVerificationKeyHash of
492+
NoBlockIssuer -> "NoBlockIssuer"
493+
BlockIssuerVerificationKeyHash bs ->
494+
Text.decodeLatin1 (B16.encode bs)
495+
in mconcat $
485496
[ "kind" .= String "AddedToCurrentChain"
486497
, "newtip" .= renderPointForDetails dtal (AF.headPoint extended)
487498
, "newTipSelectView" .= forMachine dtal (ChainDB.newTipSelectView selChangedInfo)
@@ -493,8 +504,18 @@ instance ( LogFormatting (Header blk)
493504
| dtal == DDetailed ]
494505
++ [ "events" .= toJSON (map (forMachine dtal) events)
495506
| not (null events) ]
507+
++ [ "tipBlockHash" .= tipBlockHash]
508+
++ [ "tipBlockParentHash" .= tipBlockParentHash]
509+
++ [ "tipBlockIssuerVerificationKeyHash" .= tipBlockIssuerVkHashText]
496510
forMachine dtal (ChainDB.SwitchedToAFork events selChangedInfo old new) =
497-
mconcat $
511+
let ChainInformation { .. } = chainInformation selChangedInfo old new 0
512+
tipBlockIssuerVkHashText :: Text
513+
tipBlockIssuerVkHashText =
514+
case tipBlockIssuerVerificationKeyHash of
515+
NoBlockIssuer -> "NoBlockIssuer"
516+
BlockIssuerVerificationKeyHash bs ->
517+
Text.decodeLatin1 (B16.encode bs)
518+
in mconcat $
498519
[ "kind" .= String "TraceAddBlockEvent.SwitchedToAFork"
499520
, "newtip" .= renderPointForDetails dtal (AF.headPoint new)
500521
, "newTipSelectView" .= forMachine dtal (ChainDB.newTipSelectView selChangedInfo)
@@ -506,6 +527,10 @@ instance ( LogFormatting (Header blk)
506527
| dtal == DDetailed ]
507528
++ [ "events" .= toJSON (map (forMachine dtal) events)
508529
| not (null events) ]
530+
++ [ "tipBlockHash" .= tipBlockHash]
531+
++ [ "tipBlockParentHash" .= tipBlockParentHash]
532+
++ [ "tipBlockIssuerVerificationKeyHash" .= tipBlockIssuerVkHashText]
533+
509534
forMachine dtal (ChainDB.AddBlockValidation ev') =
510535
forMachine dtal ev'
511536
forMachine dtal (ChainDB.AddedBlockToVolatileDB pt (BlockNo bn) _ enclosing) =
@@ -544,17 +569,17 @@ instance ( LogFormatting (Header blk)
544569
asMetrics (ChainDB.SwitchedToAFork _warnings selChangedInfo oldChain newChain) =
545570
let forkIt = not $ AF.withinFragmentBounds (AF.headPoint oldChain)
546571
newChain
547-
ChainInformation { .. } = chainInformation selChangedInfo newChain 0
572+
ChainInformation { .. } = chainInformation selChangedInfo oldChain newChain 0
548573
in [ DoubleM "density" (fromRational density)
549574
, IntM "slotNum" (fromIntegral slots)
550575
, IntM "blockNum" (fromIntegral blocks)
551576
, IntM "slotInEpoch" (fromIntegral slotInEpoch)
552577
, IntM "epoch" (fromIntegral (unEpochNo epoch))
553578
, CounterM "forks" (Just (if forkIt then 1 else 0))
554579
]
555-
asMetrics (ChainDB.AddedToCurrentChain _warnings selChangedInfo _oldChain newChain) =
580+
asMetrics (ChainDB.AddedToCurrentChain _warnings selChangedInfo oldChain newChain) =
556581
let ChainInformation { .. } =
557-
chainInformation selChangedInfo newChain 0
582+
chainInformation selChangedInfo oldChain newChain 0
558583
in [ DoubleM "density" (fromRational density)
559584
, IntM "slotNum" (fromIntegral slots)
560585
, IntM "blockNum" (fromIntegral blocks)
@@ -1488,7 +1513,6 @@ instance MetaTrace (ChainDB.UnknownRange blk) where
14881513
namespaceFor ChainDB.MissingBlock {} = Namespace [] ["MissingBlock"]
14891514
namespaceFor ChainDB.ForkTooOld {} = Namespace [] ["ForkTooOld"]
14901515

1491-
-- TODO Tracers Is this really as intended?
14921516
severityFor _ _ = Just Debug
14931517

14941518
documentFor (Namespace _ ["MissingBlock"]) = Just
@@ -2097,22 +2121,44 @@ data ChainInformation = ChainInformation
20972121
-- ^ Relative slot number of the tip of the current chain within the
20982122
-- epoch.
20992123
, blocksUncoupledDelta :: Int64
2124+
, tipBlockHash :: Text
2125+
-- ^ Hash of the last adopted block.
2126+
, tipBlockParentHash :: Text
2127+
-- ^ Hash of the parent block of the last adopted block.
2128+
, tipBlockIssuerVerificationKeyHash :: BlockIssuerVerificationKeyHash
2129+
-- ^ Hash of the last adopted block issuer's verification key.
21002130
}
21012131

2132+
21022133
chainInformation
21032134
:: forall blk. HasHeader (Header blk)
2135+
=> HasIssuer blk
2136+
=> ConvertRawHash blk
21042137
=> ChainDB.SelectionChangedInfo blk
21052138
-> AF.AnchoredFragment (Header blk)
2139+
-> AF.AnchoredFragment (Header blk) -- ^ New fragment.
21062140
-> Int64
21072141
-> ChainInformation
2108-
chainInformation selChangedInfo frag blocksUncoupledDelta = ChainInformation
2142+
chainInformation selChangedInfo oldFrag frag blocksUncoupledDelta = ChainInformation
21092143
{ slots = unSlotNo $ fromWithOrigin 0 (AF.headSlot frag)
21102144
, blocks = unBlockNo $ fromWithOrigin (BlockNo 1) (AF.headBlockNo frag)
21112145
, density = fragmentChainDensity frag
21122146
, epoch = ChainDB.newTipEpoch selChangedInfo
21132147
, slotInEpoch = ChainDB.newTipSlotInEpoch selChangedInfo
21142148
, blocksUncoupledDelta = blocksUncoupledDelta
2149+
, tipBlockHash = renderHeaderHash (Proxy @blk) $ realPointHash (ChainDB.newTipPoint selChangedInfo)
2150+
, tipBlockParentHash = renderChainHash (Text.decodeLatin1 . B16.encode . toRawHash (Proxy @blk)) $ AF.headHash oldFrag
2151+
, tipBlockIssuerVerificationKeyHash = tipIssuerVkHash
21152152
}
2153+
where
2154+
tipIssuerVkHash :: BlockIssuerVerificationKeyHash
2155+
tipIssuerVkHash =
2156+
case AF.head frag of
2157+
Left AF.AnchorGenesis ->
2158+
NoBlockIssuer
2159+
Left (AF.Anchor _s _h _b) ->
2160+
NoBlockIssuer
2161+
Right blk -> getIssuerVerificationKeyHash blk
21162162

21172163
fragmentChainDensity ::
21182164
HasHeader (Header blk)

cardano-node/test/Test/Cardano/Tracing/NewTracing/Consistency.hs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ tests = H.checkSequential
1616
$ H.Group "Configuration Consistency tests"
1717
$ test
1818
<$> [ ( []
19+
-- This file name shoud reference the current standard config with new tracing
1920
, "mainnet-config-new-tracing.json"
2021
, configPrefix)
2122
, ( []

0 commit comments

Comments
 (0)