@@ -25,6 +25,7 @@ import Data.Bifunctor (second)
2525import Data.List (intersperse )
2626import qualified Data.List.NonEmpty as NE
2727import Data.Time.Clock (DiffTime , diffTimeToPicoseconds )
28+ import Network.TypedProtocol.Codec (AnyMessage (.. ))
2829import Ouroboros.Consensus.Block (GenesisWindow (.. ), Header , Point ,
2930 WithOrigin (NotOrigin , Origin ), succWithOrigin )
3031import Ouroboros.Consensus.Genesis.Governor (DensityBounds (.. ),
@@ -49,6 +50,9 @@ import Ouroboros.Network.AnchoredFragment (AnchoredFragment,
4950 headPoint )
5051import qualified Ouroboros.Network.AnchoredFragment as AF
5152import Ouroboros.Network.Block (SlotNo (SlotNo ), Tip , castPoint )
53+ import Ouroboros.Network.Driver.Simple (TraceSendRecv (.. ))
54+ import Ouroboros.Network.Protocol.ChainSync.Type (ChainSync ,
55+ Message (.. ))
5256import Test.Consensus.PointSchedule.NodeState (NodeState )
5357import Test.Consensus.PointSchedule.Peers (Peer (Peer ), PeerId )
5458import Test.Util.TersePrinting (terseAnchor , terseBlock ,
@@ -130,6 +134,7 @@ data TraceEvent blk
130134 | TraceChainSyncClientTerminationEvent PeerId TraceChainSyncClientTerminationEvent
131135 | TraceBlockFetchClientTerminationEvent PeerId TraceBlockFetchClientTerminationEvent
132136 | TraceGenesisDDEvent (TraceGDDEvent PeerId blk )
137+ | TraceChainSyncSendRecvEvent PeerId String (TraceSendRecv (ChainSync (Header blk ) (Point blk ) (Tip blk )))
133138 | TraceOther String
134139
135140-- * 'TestBlock'-specific tracers for the peer simulator
@@ -182,6 +187,7 @@ traceEventTestBlockWith setTickTime tracer0 tracer = \case
182187 TraceChainSyncClientTerminationEvent peerId traceEvent -> traceChainSyncClientTerminationEventTestBlockWith peerId tracer traceEvent
183188 TraceBlockFetchClientTerminationEvent peerId traceEvent -> traceBlockFetchClientTerminationEventTestBlockWith peerId tracer traceEvent
184189 TraceGenesisDDEvent gddEvent -> traceWith tracer (terseGDDEvent gddEvent)
190+ TraceChainSyncSendRecvEvent peerId peerType traceEvent -> traceChainSyncSendRecvEventTestBlockWith peerId peerType tracer traceEvent
185191 TraceOther msg -> traceWith tracer msg
186192
187193traceSchedulerEventTestBlockWith ::
@@ -464,6 +470,33 @@ traceBlockFetchClientTerminationEventTestBlockWith pid tracer = \case
464470 where
465471 trace = traceUnitWith tracer (" BlockFetchClient " ++ condense pid)
466472
473+ -- | Trace all the SendRecv events of the ChainSync mini-protocol.
474+ traceChainSyncSendRecvEventTestBlockWith ::
475+ Applicative m =>
476+ PeerId ->
477+ String ->
478+ Tracer m String ->
479+ TraceSendRecv (ChainSync (Header TestBlock ) (Point TestBlock ) (Tip TestBlock )) ->
480+ m ()
481+ traceChainSyncSendRecvEventTestBlockWith pid ptp tracer = \ case
482+ TraceSendMsg amsg -> traceMsg " send" amsg
483+ TraceRecvMsg amsg -> traceMsg " recv" amsg
484+ where
485+ -- This can be very verbose and is only useful in rare situations, so it
486+ -- does nothing by default.
487+ -- trace = traceUnitWith tracer ("ChainSync " ++ condense pid) . ((ptp ++ " ") ++)
488+ trace = (\ _ _ _ -> const (pure () )) pid ptp tracer
489+ traceMsg kd amsg = trace $ kd ++ " " ++ case amsg of
490+ AnyMessage msg -> case msg of
491+ MsgRequestNext -> " MsgRequestNext"
492+ MsgAwaitReply -> " MsgAwaitReply"
493+ MsgRollForward header tip -> " MsgRollForward " ++ terseHeader header ++ " " ++ terseTip tip
494+ MsgRollBackward point tip -> " MsgRollBackward " ++ tersePoint point ++ " " ++ terseTip tip
495+ MsgFindIntersect points -> " MsgFindIntersect [" ++ unwords (map tersePoint points) ++ " ]"
496+ MsgIntersectFound point tip -> " MsgIntersectFound " ++ tersePoint point ++ " " ++ terseTip tip
497+ MsgIntersectNotFound tip -> " MsgIntersectNotFound " ++ terseTip tip
498+ MsgDone -> " MsgDone"
499+
467500prettyDensityBounds :: [(PeerId , DensityBounds TestBlock )] -> [String ]
468501prettyDensityBounds bounds =
469502 showPeers (second showBounds <$> bounds)
0 commit comments