From 93fc7b7153e636b05eab189307a7385dfd8f8030 Mon Sep 17 00:00:00 2001 From: Karl Knutsson Date: Wed, 11 Mar 2020 09:33:45 +0000 Subject: [PATCH] Handshake and LocalHandshake tracers Add handshake and localhandshake tracer with config options. --- cardano-config/src/Cardano/Config/Types.hs | 4 +++ .../src/Cardano/Tracing/ToObjectOrphans.hs | 30 +++++++++++++++++++ cardano-node/src/Cardano/Node/Run.hs | 4 +-- cardano-node/src/Cardano/Tracing/Tracers.hs | 21 +++++++++++-- configuration/configuration-mainnet.yaml | 6 ++++ 5 files changed, 60 insertions(+), 5 deletions(-) diff --git a/cardano-config/src/Cardano/Config/Types.hs b/cardano-config/src/Cardano/Config/Types.hs index b46fcde5c9f..650d4c51771 100644 --- a/cardano-config/src/Cardano/Config/Types.hs +++ b/cardano-config/src/Cardano/Config/Types.hs @@ -199,6 +199,8 @@ instance FromJSON NodeConfiguration where <*> v .:? "TraceTxInbound" .!= False <*> v .:? "TraceTxOutbound" .!= False <*> v .:? "TraceTxSubmissionProtocol" .!= False + <*> v .:? "TraceHandshake" .!= False + <*> v .:? "TraceLocalHandshake" .!= False pure $ NodeConfiguration { ncProtocol = ptcl @@ -328,6 +330,8 @@ data TraceOptions = TraceOptions , traceTxInbound :: !Bool , traceTxOutbound :: !Bool , traceTxSubmissionProtocol :: !Bool + , traceHandshake :: !Bool + , traceLocalHandshake :: !Bool } deriving (Eq, Show) -------------------------------------------------------------------------------- diff --git a/cardano-config/src/Cardano/Tracing/ToObjectOrphans.hs b/cardano-config/src/Cardano/Tracing/ToObjectOrphans.hs index fdd829b3da7..b0a66282638 100644 --- a/cardano-config/src/Cardano/Tracing/ToObjectOrphans.hs +++ b/cardano-config/src/Cardano/Tracing/ToObjectOrphans.hs @@ -66,6 +66,8 @@ import Ouroboros.Network.BlockFetch.ClientState (TraceFetchClientState (..), TraceLabelPeer (..)) import Ouroboros.Network.BlockFetch.Decision (FetchDecision) import Ouroboros.Network.Codec (AnyMessage (..)) +import qualified Ouroboros.Network.NodeToClient as NtC +import qualified Ouroboros.Network.NodeToNode as NtN import Ouroboros.Network.NodeToNode (WithAddr(..), ErrorPolicyTrace(..), TraceSendRecv (..)) import Ouroboros.Network.Protocol.TxSubmission.Type @@ -227,6 +229,14 @@ instance DefineSeverity (WithMuxBearer peer MuxTrace) where MuxTraceRecvDeltaQObservation {} -> Debug MuxTraceRecvDeltaQSample {} -> Info +instance DefinePrivacyAnnotation NtN.HandshakeTr +instance DefineSeverity NtN.HandshakeTr where + defineSeverity _ = Info + +instance DefinePrivacyAnnotation NtC.HandshakeTr +instance DefineSeverity NtC.HandshakeTr where + defineSeverity _ = Info + instance DefinePrivacyAnnotation (WithTip blk (ChainDB.TraceEvent blk)) instance DefineSeverity (WithTip blk (ChainDB.TraceEvent blk)) where defineSeverity (WithTip _tip ev) = defineSeverity ev @@ -465,6 +475,14 @@ instance (Show peer) => Transformable Text IO (WithMuxBearer peer MuxTrace) where trTransformer = defaultTextTransformer +-- transform @NtN.HandshakeTrace@ +instance Transformable Text IO NtN.HandshakeTr where + trTransformer = defaultTextTransformer + +-- transform @NtC.HandshakeTrace@ +instance Transformable Text IO NtC.HandshakeTr where + trTransformer = defaultTextTransformer + -- transform @TraceEvent@ instance (Condense (HeaderHash blk), LedgerSupportsProtocol blk) => Transformable Text IO (WithTip blk (ChainDB.TraceEvent blk)) where @@ -655,6 +673,18 @@ instance (Show peer) , "bearer" .= show b , "event" .= show ev ] +instance ToObject NtN.HandshakeTr where + toObject _verb (WithMuxBearer b ev) = + mkObject [ "kind" .= String "HandshakeTrace" + , "bearer" .= show b + , "event" .= show ev ] + +instance ToObject NtC.HandshakeTr where + toObject _verb (WithMuxBearer b ev) = + mkObject [ "kind" .= String "LocalHandshakeTrace" + , "bearer" .= show b + , "event" .= show ev ] + instance (Condense (HeaderHash blk), LedgerSupportsProtocol blk) => ToObject (WithTip blk (ChainDB.TraceEvent blk)) where -- example: turn off any tracing of @TraceEvent@s when minimal verbosity level is set diff --git a/cardano-node/src/Cardano/Node/Run.hs b/cardano-node/src/Cardano/Node/Run.hs index 737550027ba..d1f2d5da526 100644 --- a/cardano-node/src/Cardano/Node/Run.hs +++ b/cardano-node/src/Cardano/Node/Run.hs @@ -255,8 +255,8 @@ handleSimpleNode p trace nodeTracers npm onKernel = do , dtLocalErrorPolicyTracer = localErrorPolicyTracer nodeTracers' , dtMuxTracer = muxTracer nodeTracers' , dtMuxLocalTracer = nullTracer - , dtHandshakeTracer = nullTracer - , dtHandshakeLocalTracer = nullTracer + , dtHandshakeTracer = handshakeTracer nodeTracers' + , dtHandshakeLocalTracer = localHandshakeTracer nodeTracers' } createTracers diff --git a/cardano-node/src/Cardano/Tracing/Tracers.hs b/cardano-node/src/Cardano/Tracing/Tracers.hs index 44d2b4ce84a..651da922a7b 100644 --- a/cardano-node/src/Cardano/Tracing/Tracers.hs +++ b/cardano-node/src/Cardano/Tracing/Tracers.hs @@ -60,7 +60,8 @@ import Ouroboros.Network.Block (Point, BlockNo(..), blockNo, unBlockNo, unSlotNo) import Ouroboros.Network.BlockFetch.Decision (FetchDecision) import Ouroboros.Network.BlockFetch.ClientState (TraceLabelPeer (..)) -import Ouroboros.Network.NodeToNode (WithAddr, ErrorPolicyTrace) +import qualified Ouroboros.Network.NodeToClient as NtC +import qualified Ouroboros.Network.NodeToNode as NtN import Ouroboros.Network.Point (fromWithOrigin) import Ouroboros.Network.Subscription @@ -88,11 +89,13 @@ data Tracers peer localPeer blk = Tracers -- | Trace the DNS resolver , dnsResolverTracer :: Tracer IO (WithDomainName DnsTrace) -- | Trace error policy resolution - , errorPolicyTracer :: Tracer IO (WithAddr Socket.SockAddr ErrorPolicyTrace) + , errorPolicyTracer :: Tracer IO (NtN.WithAddr Socket.SockAddr NtN.ErrorPolicyTrace) -- | Trace local error policy resolution - , localErrorPolicyTracer :: Tracer IO (WithAddr Socket.SockAddr ErrorPolicyTrace) + , localErrorPolicyTracer :: Tracer IO (NtN.WithAddr Socket.SockAddr NtN.ErrorPolicyTrace) -- | Trace the Mux , muxTracer :: Tracer IO (WithMuxBearer peer MuxTrace) + , handshakeTracer :: Tracer IO NtN.HandshakeTr + , localHandshakeTracer :: Tracer IO NtC.HandshakeTr } data ForgeTracers = ForgeTracers @@ -119,6 +122,8 @@ nullTracers = Tracers , errorPolicyTracer = nullTracer , localErrorPolicyTracer = nullTracer , muxTracer = nullTracer + , handshakeTracer = nullTracer + , localHandshakeTracer = nullTracer } @@ -231,6 +236,16 @@ mkTracers traceOptions tracer = do $ annotateSeverity $ toLogObject' StructuredLogging tracingVerbosity $ appendName "Mux" tracer + , handshakeTracer + = tracerOnOff (traceHandshake traceOptions) + $ annotateSeverity + $ toLogObject' StructuredLogging tracingVerbosity + $ appendName "Handshake" tracer + , localHandshakeTracer + = tracerOnOff (traceLocalHandshake traceOptions) + $ annotateSeverity + $ toLogObject' StructuredLogging tracingVerbosity + $ appendName "LocalHandshake" tracer } where -- Turn on/off a tracer depending on what was parsed from the command line. diff --git a/configuration/configuration-mainnet.yaml b/configuration/configuration-mainnet.yaml index 3e5ad00301a..00434d262fc 100644 --- a/configuration/configuration-mainnet.yaml +++ b/configuration/configuration-mainnet.yaml @@ -177,3 +177,9 @@ TraceTxOutbound: False # Trace TxSubmission protocol messages. TraceTxSubmissionProtocol: False + +# Trace Handshake protocol messages. +TraceHandshake: False + +# Trace Local Handshake protocol messages. +TraceLocalHandshake: False