Skip to content

Commit 33e9e50

Browse files
committed
Add remaining logging stuff for Peras
1 parent 875db96 commit 33e9e50

File tree

8 files changed

+626
-18
lines changed

8 files changed

+626
-18
lines changed

cardano-node/src/Cardano/Node/Tracing/Documentation.hs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ import qualified Network.Mux as Mux
117117
import qualified Network.Socket as Socket
118118
import qualified Options.Applicative as Opt
119119
import System.IO
120+
import qualified Ouroboros.Consensus.MiniProtocol.ObjectDiffusion.PerasCert as Consensus
120121

121122

122123
data TraceDocumentationCmd
@@ -371,6 +372,24 @@ docTracersFirstPhase condConfigFileName = do
371372
mempoolTrDoc <- documentTracer (mempoolTr ::
372373
Logging.Trace IO (TraceEventMempool blk))
373374

375+
perasCertDiffusionInboundTr <- mkCardanoTracer
376+
trBase trForward mbTrEKG
377+
["Peras", "CertDiffusion", "Inbound"]
378+
configureTracers configReflection trConfig [perasCertDiffusionInboundTr]
379+
perasCertDiffusionInboundTrDoc <- documentTracer (perasCertDiffusionInboundTr ::
380+
Logging.Trace IO (BlockFetch.TraceLabelPeer
381+
remotePeer
382+
(Consensus.TracePerasCertDiffusionInbound blk)))
383+
384+
perasCertDiffusionOutboundTracer <- mkCardanoTracer
385+
trBase trForward mbTrEKG
386+
["Peras", "CertDiffusion", "Outbound"]
387+
configureTracers configReflection trConfig [perasCertDiffusionOutboundTracer]
388+
perasCertDiffusionOutboundTrDoc <- documentTracer (perasCertDiffusionOutboundTracer ::
389+
Logging.Trace IO (BlockFetch.TraceLabelPeer
390+
remotePeer
391+
(Consensus.TracePerasCertDiffusionOutbound blk)))
392+
374393
forgeTr <- mkCardanoTracer
375394
trBase trForward mbTrEKG
376395
["Forge", "Loop"]
@@ -778,6 +797,8 @@ docTracersFirstPhase condConfigFileName = do
778797
<> txOutboundTrDoc
779798
<> localTxSubmissionServerTrDoc
780799
<> mempoolTrDoc
800+
<> perasCertDiffusionInboundTrDoc
801+
<> perasCertDiffusionOutboundTrDoc
781802
<> forgeTrDoc
782803
<> forgeStatsTrDoc
783804
<> blockchainTimeTrDoc

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

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,16 @@ mkConsensusTracers configReflection trBase trForward mbTrEKG _trDataPoint trConf
316316
["Mempool"]
317317
configureTracers configReflection trConfig [mempoolTr]
318318

319+
!perasCertDiffusionInboundTr <- mkCardanoTracer
320+
trBase trForward mbTrEKG
321+
["Peras", "CertDiffusion", "Inbound"]
322+
configureTracers configReflection trConfig [perasCertDiffusionInboundTr]
323+
324+
!perasCertDiffusionOutboundTr <- mkCardanoTracer
325+
trBase trForward mbTrEKG
326+
["Peras", "CertDiffusion", "Outbound"]
327+
configureTracers configReflection trConfig [perasCertDiffusionOutboundTr]
328+
319329
!forgeTr <- mkCardanoTracer
320330
trBase trForward mbTrEKG
321331
["Forge", "Loop"]
@@ -408,9 +418,8 @@ mkConsensusTracers configReflection trBase trForward mbTrEKG _trDataPoint trConf
408418
traceWith consensusCsjTr
409419
, Consensus.dbfTracer = Tracer $
410420
traceWith consensusDbfTr
411-
-- TODO plug these in
412-
, Consensus.perasCertDiffusionInboundTracer = Tracer $ \_ -> pure ()
413-
, Consensus.perasCertDiffusionOutboundTracer = Tracer $ \_ -> pure ()
421+
, Consensus.perasCertDiffusionInboundTracer = Tracer $ traceWith perasCertDiffusionInboundTr
422+
, Consensus.perasCertDiffusionOutboundTracer = Tracer $ traceWith perasCertDiffusionOutboundTr
414423
}
415424

416425
mkNodeToClientTracers :: forall blk.
@@ -495,6 +504,11 @@ mkNodeToNodeTracers configReflection trBase trForward mbTrEKG _trDataPoint trCon
495504
["TxSubmission", "Remote"]
496505
configureTracers configReflection trConfig [txSubmission2Tracer]
497506

507+
!perasCertDiffusionTracer <- mkCardanoTracer
508+
trBase trForward mbTrEKG
509+
["Peras", "CertDiffusion", "Remote"]
510+
configureTracers configReflection trConfig [perasCertDiffusionTracer]
511+
498512
!keepAliveTracer <- mkCardanoTracer
499513
trBase trForward mbTrEKG
500514
["KeepAlive", "Remote"]
@@ -520,8 +534,8 @@ mkNodeToNodeTracers configReflection trBase trForward mbTrEKG _trDataPoint trCon
520534
traceWith keepAliveTracer
521535
, NtN.tPeerSharingTracer = Tracer $
522536
traceWith peerSharingTracer
523-
-- TODO plug in
524-
, NtN.tPerasCertDiffusionTracer = Tracer $ \_ -> pure ()
537+
, NtN.tPerasCertDiffusionTracer = Tracer $
538+
traceWith perasCertDiffusionTracer
525539
}
526540

527541
mkDiffusionTracers

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

Lines changed: 228 additions & 11 deletions
Large diffs are not rendered by default.

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

Lines changed: 278 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,11 @@ import qualified Data.Text as Text
8080
import Data.Time (NominalDiffTime)
8181
import Data.Word (Word32, Word64)
8282
import Network.TypedProtocol.Core
83+
import Network.TypedProtocol.Codec (AnyMessage (AnyMessageAndAgency))
84+
import Ouroboros.Consensus.MiniProtocol.ObjectDiffusion.PerasCert
85+
import Ouroboros.Consensus.MiniProtocol.ObjectDiffusion.Inbound (TraceObjectDiffusionInbound(..), NumObjectsProcessed (..))
86+
import Ouroboros.Consensus.MiniProtocol.ObjectDiffusion.Outbound (TraceObjectDiffusionOutbound(..))
87+
import Ouroboros.Network.Protocol.ObjectDiffusion.Type (NumObjectIdsReq(..), NumObjectIdsAck(..), ObjectDiffusion(..), Message(..), BlockingReplyList(..))
8388

8489

8590
instance (LogFormatting adr, Show adr) => LogFormatting (ConnectionId adr) where
@@ -1428,6 +1433,279 @@ instance MetaTrace (TraceEventMempool blk) where
14281433
, Namespace [] ["LedgerFound"]
14291434
]
14301435

1436+
--------------------------------------------------------------------------------
1437+
-- PerasCertDiffusionInbound Tracer
1438+
--------------------------------------------------------------------------------
1439+
1440+
instance MetaTrace (TracePerasCertDiffusionInbound blk) where
1441+
namespaceFor TraceObjectDiffusionCollected {} =
1442+
Namespace [] ["Collected"]
1443+
namespaceFor TraceObjectDiffusionProcessed {} =
1444+
Namespace [] ["Processed"]
1445+
namespaceFor TraceObjectDiffusionControlMessage {} =
1446+
Namespace [] ["ControlMessage"]
1447+
namespaceFor TraceObjectInboundCanRequestMoreObjects {} =
1448+
Namespace [] ["CanRequestMoreObjects"]
1449+
namespaceFor TraceObjectInboundCannotRequestMoreObjects {} =
1450+
Namespace [] ["CannotRequestMoreObjects"]
1451+
1452+
severityFor (Namespace _ ["Collected"]) _ = Just Info
1453+
severityFor (Namespace _ ["Processed"]) _ = Just Info
1454+
severityFor (Namespace _ ["ControlMessage"]) _ = Just Info
1455+
severityFor (Namespace _ ["CanRequestMoreObjects"]) _ = Just Info
1456+
severityFor (Namespace _ ["CannotRequestMoreObjects"]) _ = Just Info
1457+
severityFor _ _ = Nothing
1458+
1459+
documentFor (Namespace _ ["Collected"]) = Just
1460+
"Objects have been collected from the peer."
1461+
documentFor (Namespace _ ["Processed"]) = Just
1462+
"Objects have been processed and added to the pool."
1463+
documentFor (Namespace _ ["ControlMessage"]) = Just
1464+
"A control message has been received."
1465+
documentFor (Namespace _ ["CanRequestMoreObjects"]) = Just
1466+
"More objects can be requested from the peer."
1467+
documentFor (Namespace _ ["CannotRequestMoreObjects"]) = Just
1468+
"No more objects can be requested from the peer at this time."
1469+
documentFor _ = Nothing
1470+
1471+
allNamespaces =
1472+
[ Namespace [] ["Collected"]
1473+
, Namespace [] ["Processed"]
1474+
, Namespace [] ["ControlMessage"]
1475+
, Namespace [] ["CanRequestMoreObjects"]
1476+
, Namespace [] ["CannotRequestMoreObjects"]
1477+
]
1478+
1479+
--------------------------------------------------------------------------------
1480+
-- PerasCertDiffusionInbound LogFormatting
1481+
--------------------------------------------------------------------------------
1482+
1483+
instance LogFormatting (TracePerasCertDiffusionInbound blk) where
1484+
forMachine _dtal = \case
1485+
TraceObjectDiffusionCollected n ->
1486+
mconcat
1487+
[ "kind" .= String "Collected"
1488+
, "count" .= n
1489+
]
1490+
TraceObjectDiffusionProcessed (NumObjectsProcessed n) ->
1491+
mconcat
1492+
[ "kind" .= String "Processed"
1493+
, "count" .= n
1494+
]
1495+
TraceObjectDiffusionControlMessage msg ->
1496+
mconcat
1497+
[ "kind" .= String "ControlMessage"
1498+
, "message" .= String (Text.pack $ show msg)
1499+
]
1500+
TraceObjectInboundCanRequestMoreObjects {} ->
1501+
mconcat
1502+
[ "kind" .= String "CanRequestMoreObjects"
1503+
]
1504+
TraceObjectInboundCannotRequestMoreObjects {} ->
1505+
mconcat
1506+
[ "kind" .= String "CannotRequestMoreObjects"
1507+
]
1508+
1509+
forHuman = \case
1510+
TraceObjectDiffusionCollected n ->
1511+
"Collected " <> showT n <> " Peras certificates"
1512+
TraceObjectDiffusionProcessed n ->
1513+
"Processed " <> showT n <> " Peras certificates"
1514+
TraceObjectDiffusionControlMessage msg ->
1515+
"Received control message: " <> showT msg
1516+
TraceObjectInboundCanRequestMoreObjects {} ->
1517+
"Can request more Peras certificates from peer"
1518+
TraceObjectInboundCannotRequestMoreObjects {} ->
1519+
"Cannot request more Peras certificates from peer at this time"
1520+
1521+
--------------------------------------------------------------------------------
1522+
-- PerasCertDiffusionOutbound Tracer
1523+
--------------------------------------------------------------------------------
1524+
1525+
instance MetaTrace (TracePerasCertDiffusionOutbound blk) where
1526+
namespaceFor TraceObjectDiffusionOutboundTerminated {} =
1527+
Namespace [] ["Terminated"]
1528+
namespaceFor TraceObjectDiffusionOutboundRecvMsgRequestObjectIds {} =
1529+
Namespace [] ["RecvMsgRequestObjectIds"]
1530+
namespaceFor TraceObjectDiffusionOutboundSendMsgReplyObjectIds {} =
1531+
Namespace [] ["SendMsgReplyObjectIds"]
1532+
namespaceFor TraceObjectDiffusionOutboundRecvMsgRequestObjects {} =
1533+
Namespace [] ["RecvMsgRequestObjects"]
1534+
namespaceFor TraceObjectDiffusionOutboundSendMsgReplyObjects {} =
1535+
Namespace [] ["SendMsgReplyObjects"]
1536+
1537+
severityFor (Namespace _ ["Terminated"]) _ = Just Info
1538+
severityFor (Namespace _ ["RecvMsgRequestObjectIds"]) _ = Just Info
1539+
severityFor (Namespace _ ["SendMsgReplyObjectIds"]) _ = Just Info
1540+
severityFor (Namespace _ ["RecvMsgRequestObjects"]) _ = Just Info
1541+
severityFor (Namespace _ ["SendMsgReplyObjects"]) _ = Just Info
1542+
severityFor _ _ = Nothing
1543+
1544+
documentFor (Namespace _ ["Terminated"]) = Just
1545+
"The object diffusion mini-protocol has been terminated by the inbound peer."
1546+
documentFor (Namespace _ ["RecvMsgRequestObjectIds"]) = Just
1547+
"Received a request for object IDs from the inbound peer."
1548+
documentFor (Namespace _ ["SendMsgReplyObjectIds"]) = Just
1549+
"Sending a reply with object IDs to the inbound peer."
1550+
documentFor (Namespace _ ["RecvMsgRequestObjects"]) = Just
1551+
"Received a request for specific objects from the inbound peer."
1552+
documentFor (Namespace _ ["SendMsgReplyObjects"]) = Just
1553+
"Sending a reply with specific objects to the inbound peer."
1554+
documentFor _ = Nothing
1555+
1556+
allNamespaces =
1557+
[ Namespace [] ["Terminated"]
1558+
, Namespace [] ["RecvMsgRequestObjectIds"]
1559+
, Namespace [] ["SendMsgReplyObjectIds"]
1560+
, Namespace [] ["RecvMsgRequestObjects"]
1561+
, Namespace [] ["SendMsgReplyObjects"]
1562+
]
1563+
1564+
--------------------------------------------------------------------------------
1565+
-- PerasCertDiffusionOutbound LogFormatting
1566+
--------------------------------------------------------------------------------
1567+
1568+
instance LogFormatting (TracePerasCertDiffusionOutbound blk) where
1569+
forMachine _dtal = \case
1570+
TraceObjectDiffusionOutboundTerminated ->
1571+
mconcat
1572+
[ "kind" .= String "Terminated"
1573+
]
1574+
TraceObjectDiffusionOutboundRecvMsgRequestObjectIds (NumObjectIdsReq n) ->
1575+
mconcat
1576+
[ "kind" .= String "RecvMsgRequestObjectIds"
1577+
, "count" .= n
1578+
]
1579+
TraceObjectDiffusionOutboundSendMsgReplyObjectIds roundNos ->
1580+
mconcat
1581+
[ "kind" .= String "SendMsgReplyObjectIds"
1582+
, "count" .= length roundNos
1583+
]
1584+
TraceObjectDiffusionOutboundRecvMsgRequestObjects objIds ->
1585+
mconcat
1586+
[ "kind" .= String "RecvMsgRequestObjects"
1587+
, "count" .= length objIds
1588+
]
1589+
TraceObjectDiffusionOutboundSendMsgReplyObjects objs ->
1590+
mconcat
1591+
[ "kind" .= String "SendMsgReplyObjects"
1592+
, "count" .= length objs
1593+
]
1594+
1595+
forHuman = \case
1596+
TraceObjectDiffusionOutboundTerminated ->
1597+
"Peras certificate diffusion mini-protocol has been terminated"
1598+
TraceObjectDiffusionOutboundRecvMsgRequestObjectIds n ->
1599+
"Received request for " <> showT n <> " Peras certificate IDs"
1600+
TraceObjectDiffusionOutboundSendMsgReplyObjectIds roundNos ->
1601+
"Sending " <> showT (length roundNos) <> " Peras certificate IDs"
1602+
TraceObjectDiffusionOutboundRecvMsgRequestObjects objIds ->
1603+
"Received request for " <> showT (length objIds) <> " Peras certificates"
1604+
TraceObjectDiffusionOutboundSendMsgReplyObjects objs ->
1605+
"Sending " <> showT (length objs) <> " Peras certificates to inbound peer"
1606+
1607+
1608+
1609+
--------------------------------------------------------------------------------
1610+
-- ObjectDiffusion Protocol Tracer (AnyMessage)
1611+
--------------------------------------------------------------------------------
1612+
1613+
instance LogFormatting (AnyMessage (ObjectDiffusion objectId object)) where
1614+
forMachine _dtal (AnyMessageAndAgency _stok MsgInit) =
1615+
mconcat
1616+
[ "kind" .= String "MsgInit"
1617+
]
1618+
forMachine _dtal (AnyMessageAndAgency _stok (MsgRequestObjectIds _ ack req)) =
1619+
mconcat
1620+
[ "kind" .= String "MsgRequestObjectIds"
1621+
, "ack" .= getNumObjectIdsAck ack
1622+
, "req" .= getNumObjectIdsReq req
1623+
]
1624+
forMachine _dtal (AnyMessageAndAgency _stok (MsgReplyObjectIds objIds)) =
1625+
let count = case objIds of
1626+
BlockingReply xs -> length xs
1627+
NonBlockingReply xs -> length xs
1628+
in mconcat
1629+
[ "kind" .= String "MsgReplyObjectIds"
1630+
, "count" .= (count :: Int)
1631+
]
1632+
forMachine _dtal (AnyMessageAndAgency _stok (MsgRequestObjects objIds)) =
1633+
mconcat
1634+
[ "kind" .= String "MsgRequestObjects"
1635+
, "count" .= length objIds
1636+
]
1637+
forMachine _dtal (AnyMessageAndAgency _stok (MsgReplyObjects objects)) =
1638+
mconcat
1639+
[ "kind" .= String "MsgReplyObjects"
1640+
, "count" .= length objects
1641+
]
1642+
forMachine _dtal (AnyMessageAndAgency _stok MsgDone) =
1643+
mconcat
1644+
[ "kind" .= String "MsgDone"
1645+
]
1646+
1647+
forHuman (AnyMessageAndAgency _stok MsgInit) =
1648+
"ObjectDiffusion protocol initialized"
1649+
forHuman (AnyMessageAndAgency _stok (MsgRequestObjectIds _ ack req)) =
1650+
"Requested " <> showT (getNumObjectIdsReq req) <> " object IDs, acknowledging " <> showT (getNumObjectIdsAck ack)
1651+
forHuman (AnyMessageAndAgency _stok (MsgReplyObjectIds objIds)) =
1652+
let count = case objIds of
1653+
BlockingReply xs -> length xs
1654+
NonBlockingReply xs -> length xs
1655+
in "Replied with " <> showT (count :: Int) <> " object IDs"
1656+
forHuman (AnyMessageAndAgency _stok (MsgRequestObjects objIds)) =
1657+
"Requested " <> showT (length objIds) <> " objects"
1658+
forHuman (AnyMessageAndAgency _stok (MsgReplyObjects objects)) =
1659+
"Replied with " <> showT (length objects) <> " objects"
1660+
forHuman (AnyMessageAndAgency _stok MsgDone) =
1661+
"ObjectDiffusion protocol terminated"
1662+
1663+
instance MetaTrace (AnyMessage (ObjectDiffusion objectId object)) where
1664+
namespaceFor (AnyMessageAndAgency _stok MsgInit) =
1665+
Namespace [] ["MsgInit"]
1666+
namespaceFor (AnyMessageAndAgency _stok (MsgRequestObjectIds _ _ _)) =
1667+
Namespace [] ["MsgRequestObjectIds"]
1668+
namespaceFor (AnyMessageAndAgency _stok (MsgReplyObjectIds _)) =
1669+
Namespace [] ["MsgReplyObjectIds"]
1670+
namespaceFor (AnyMessageAndAgency _stok (MsgRequestObjects _)) =
1671+
Namespace [] ["MsgRequestObjects"]
1672+
namespaceFor (AnyMessageAndAgency _stok (MsgReplyObjects _)) =
1673+
Namespace [] ["MsgReplyObjects"]
1674+
namespaceFor (AnyMessageAndAgency _stok MsgDone) =
1675+
Namespace [] ["MsgDone"]
1676+
1677+
severityFor (Namespace _ ["MsgInit"]) _ = Just Info
1678+
severityFor (Namespace _ ["MsgRequestObjectIds"]) _ = Just Debug
1679+
severityFor (Namespace _ ["MsgReplyObjectIds"]) _ = Just Debug
1680+
severityFor (Namespace _ ["MsgRequestObjects"]) _ = Just Debug
1681+
severityFor (Namespace _ ["MsgReplyObjects"]) _ = Just Debug
1682+
severityFor (Namespace _ ["MsgDone"]) _ = Just Info
1683+
severityFor _ _ = Nothing
1684+
1685+
documentFor (Namespace _ ["MsgInit"]) = Just
1686+
"ObjectDiffusion protocol initialization message."
1687+
documentFor (Namespace _ ["MsgRequestObjectIds"]) = Just
1688+
"Request for object identifiers with acknowledgement count."
1689+
documentFor (Namespace _ ["MsgReplyObjectIds"]) = Just
1690+
"Reply with available object identifiers."
1691+
documentFor (Namespace _ ["MsgRequestObjects"]) = Just
1692+
"Request for specific objects by their identifiers."
1693+
documentFor (Namespace _ ["MsgReplyObjects"]) = Just
1694+
"Reply with the requested objects."
1695+
documentFor (Namespace _ ["MsgDone"]) = Just
1696+
"ObjectDiffusion protocol termination message."
1697+
documentFor _ = Nothing
1698+
1699+
allNamespaces =
1700+
[ Namespace [] ["MsgInit"]
1701+
, Namespace [] ["MsgRequestObjectIds"]
1702+
, Namespace [] ["MsgReplyObjectIds"]
1703+
, Namespace [] ["MsgRequestObjects"]
1704+
, Namespace [] ["MsgReplyObjects"]
1705+
, Namespace [] ["MsgDone"]
1706+
]
1707+
1708+
14311709
--------------------------------------------------------------------------------
14321710
-- ForgeEvent Tracer
14331711
--------------------------------------------------------------------------------

0 commit comments

Comments
 (0)