Skip to content

Commit

Permalink
Merge #2746
Browse files Browse the repository at this point in the history
2746: CAD-2907 tracing:  improve usability of the ChainSync server traces r=deepfire a=deepfire

Instead of going through the Tip/Point serialisations
this allows a more direct access to things that matter:

1. block hash
2. slot number
3. block number

We only convert immediately necessary traces, but the portal has been opened and the call is out.

Release-relevant information (cc @LaurenceIO): this PR changes structure of some of the traces configured by `TraceChainSyncHeaderServer` and `TraceChainSyncClient` config options.

Co-authored-by: Kosyrev Serge <serge.kosyrev@iohk.io>
  • Loading branch information
iohk-bors[bot] and deepfire committed May 27, 2021
2 parents b4382b6 + 356fd7b commit 7d8ab95
Showing 1 changed file with 34 additions and 26 deletions.
60 changes: 34 additions & 26 deletions cardano-node/src/Cardano/Tracing/OrphanInstances/Consensus.hs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import Cardano.Tracing.OrphanInstances.Network ()
import Cardano.Tracing.Render (renderChainHash, renderChunkNo, renderHeaderHash,
renderHeaderHashForVerbosity, renderPoint, renderPointAsPhrase,
renderPointForVerbosity, renderRealPoint, renderRealPointAsPhrase,
renderTipBlockNo, renderTipForVerbosity, renderTipHash, renderWithOrigin)
renderTipBlockNo, renderTipHash, renderWithOrigin)
import Cardano.Slotting.Slot (fromWithOrigin)

import Ouroboros.Consensus.Block (BlockProtocol, CannotForge, ConvertRawHash (..),
Expand Down Expand Up @@ -59,7 +59,7 @@ import Ouroboros.Consensus.Util.Orphans ()

import qualified Ouroboros.Network.AnchoredFragment as AF
import Ouroboros.Network.Block (BlockNo (..), ChainUpdate (..), SlotNo (..), StandardHash,
blockHash, pointSlot)
Tip (..), blockHash, pointSlot, legacyTip)
import Ouroboros.Network.Point (withOrigin)

import qualified Ouroboros.Consensus.Storage.ChainDB as ChainDB
Expand Down Expand Up @@ -974,13 +974,26 @@ instance ConvertRawHash blk => ToObject (TraceBlockFetchServerEvent blk) where
, "block" .= String (renderChainHash @blk (renderHeaderHash (Proxy @blk)) $ pointHash blk)
]

tipToObject :: forall blk. ConvertRawHash blk => Tip blk -> [(Text, Value)]
tipToObject = \case
TipGenesis ->
[ "slot" .= toJSON (0 :: Int)
, "block" .= String "genesis"
, "blockNo" .= toJSON ((-1) :: Int)
]
Tip slot hash blockno ->
[ "slot" .= slot
, "block" .= String (renderHeaderHash (Proxy @blk) hash)
, "blockNo" .= blockno
]

instance (ConvertRawHash blk, LedgerSupportsProtocol blk)
=> ToObject (TraceChainSyncClientEvent blk) where
toObject verb ev = case ev of
TraceDownloadedHeader pt ->
mkObject [ "kind" .= String "ChainSyncClientEvent.TraceDownloadedHeader"
, "block" .= toObject verb (headerPoint pt) ]
TraceDownloadedHeader h ->
mkObject $
[ "kind" .= String "ChainSyncClientEvent.TraceDownloadedHeader"
] <> tipToObject (legacyTip (headerPoint h) (blockNo h))
TraceRolledBack tip ->
mkObject [ "kind" .= String "ChainSyncClientEvent.TraceRolledBack"
, "tip" .= toObject verb tip ]
Expand All @@ -992,30 +1005,25 @@ instance (ConvertRawHash blk, LedgerSupportsProtocol blk)
TraceTermination _ ->
mkObject [ "kind" .= String "ChainSyncClientEvent.TraceTermination" ]


instance ConvertRawHash blk
=> ToObject (TraceChainSyncServerEvent blk) where
toObject verb ev = case ev of
TraceChainSyncServerRead tip (AddBlock hdr) ->
mkObject [ "kind" .= String "ChainSyncServerEvent.TraceChainSyncServerRead.AddBlock"
, "tip" .= String (renderTipForVerbosity verb tip)
, "addedBlock" .= String (renderPointForVerbosity verb hdr)
]
TraceChainSyncServerRead tip (RollBack pt) ->
mkObject [ "kind" .= String "ChainSyncServerEvent.TraceChainSyncServerRead.RollBack"
, "tip" .= String (renderTipForVerbosity verb tip)
, "rolledBackBlock" .= String (renderPointForVerbosity verb pt)
]
TraceChainSyncServerReadBlocked tip (AddBlock hdr) ->
mkObject [ "kind" .= String "ChainSyncServerEvent.TraceChainSyncServerReadBlocked.AddBlock"
, "tip" .= String (renderTipForVerbosity verb tip)
, "addedBlock" .= String (renderPointForVerbosity verb hdr)
]
TraceChainSyncServerReadBlocked tip (RollBack pt) ->
mkObject [ "kind" .= String "ChainSyncServerEvent.TraceChainSyncServerReadBlocked.RollBack"
, "tip" .= String (renderTipForVerbosity verb tip)
, "rolledBackBlock" .= String (renderPointForVerbosity verb pt)
]
TraceChainSyncServerRead tip AddBlock{} ->
mkObject $
[ "kind" .= String "ChainSyncServerEvent.TraceChainSyncServerRead.AddBlock"
] <> tipToObject tip
TraceChainSyncServerRead tip RollBack{} ->
mkObject $
[ "kind" .= String "ChainSyncServerEvent.TraceChainSyncServerRead.RollBack"
] <> tipToObject tip
TraceChainSyncServerReadBlocked tip AddBlock{} ->
mkObject $
[ "kind" .= String "ChainSyncServerEvent.TraceChainSyncServerReadBlocked.AddBlock"
] <> tipToObject tip
TraceChainSyncServerReadBlocked tip RollBack{} ->
mkObject $
[ "kind" .= String "ChainSyncServerEvent.TraceChainSyncServerReadBlocked.RollBack"
] <> tipToObject tip

TraceChainSyncRollForward point ->
mkObject [ "kind" .= String "ChainSyncServerEvent.TraceChainSyncRollForward"
Expand Down

0 comments on commit 7d8ab95

Please sign in to comment.