From 971f43cdda80d356575e7aab871af25d0bbe30c8 Mon Sep 17 00:00:00 2001 From: Drazen Popovic Date: Mon, 29 Jun 2026 13:34:41 +0200 Subject: [PATCH] New traces and metrics for optimistic Mempool --- cabal.project | 4 +-- .../Cardano/Node/Tracing/Tracers/Consensus.hs | 27 +++++++++++++++++++ .../Tracing/OrphanInstances/Consensus.hs | 12 +++++++++ 3 files changed, 41 insertions(+), 2 deletions(-) diff --git a/cabal.project b/cabal.project index f008f229230..e0eaf96a879 100644 --- a/cabal.project +++ b/cabal.project @@ -93,8 +93,8 @@ allow-newer: source-repository-package type: git location: https://github.com/IntersectMBO/ouroboros-consensus - tag: e3803b0c86fc0b5f0a7b8f3a977aebf5afe31b8b - --sha256: sha256-PxhS4cB4pnP+izLMOTfsyjrEUCsW2aSEMUKl603Bpk4= + tag: 52eb268ae0fa22c6f1b35fd3cf7642dedd6f63cc + --sha256: sha256-8gY1Ux96k/ghBg2njjvVlCfo/MIFLc6kE3F+47hpSIE= -- Points to cardano-ledger/leios-prototype source-repository-package diff --git a/cardano-node/src/Cardano/Node/Tracing/Tracers/Consensus.hs b/cardano-node/src/Cardano/Node/Tracing/Tracers/Consensus.hs index 7a1878b13c7..c739d8fa22b 100644 --- a/cardano-node/src/Cardano/Node/Tracing/Tracers/Consensus.hs +++ b/cardano-node/src/Cardano/Node/Tracing/Tracers/Consensus.hs @@ -1168,6 +1168,16 @@ instance mconcat [ "kind" .= String "TraceMempoolTipMovedBetweenSTMBlocks" ] + forMachine dtal (TraceMempoolCacheHit point)= + mconcat + [ "kind" .= String "TraceMempoolCacheHit" + , "point" .= forMachine dtal point + ] + forMachine dtal (TraceMempoolCacheMiss point)= + mconcat + [ "kind" .= String "TraceMempoolCacheMiss" + , "point" .= forMachine dtal point + ] asMetrics (TraceMempoolAddedTx _tx _mpSzBefore mpSz) = [ IntM "txsInMempool" (fromIntegral $ msNumTxs mpSz) @@ -1201,6 +1211,8 @@ instance asMetrics TraceMempoolAttemptingAdd {} = [] asMetrics TraceMempoolTipMovedBetweenSTMBlocks {} = [] + asMetrics TraceMempoolCacheHit {} = [ CounterM "mempool.cache-hit-count" (Just 1) ] + asMetrics TraceMempoolCacheMiss {} = [ CounterM "mempool.cache-miss-count" (Just 1) ] instance LogFormatting MempoolSize where forMachine _dtal MempoolSize{msNumTxs, msNumBytes} = @@ -1219,6 +1231,8 @@ instance MetaTrace (TraceEventMempool blk) where namespaceFor TraceMempoolSyncNotNeeded {} = Namespace [] ["SyncNotNeeded"] namespaceFor TraceMempoolAttemptingAdd {} = Namespace [] ["AttemptAdd"] namespaceFor TraceMempoolTipMovedBetweenSTMBlocks {} = Namespace [] ["TipMovedBetweenSTMBlocks"] + namespaceFor TraceMempoolCacheHit {} = Namespace [] ["CacheHit"] + namespaceFor TraceMempoolCacheMiss {} = Namespace [] ["CacheMiss"] severityFor (Namespace _ ["AddedTx"]) _ = Just Info @@ -1229,6 +1243,8 @@ instance MetaTrace (TraceEventMempool blk) where severityFor (Namespace _ ["SyncNotNeeded"]) _ = Just Debug severityFor (Namespace _ ["AttemptAdd"]) _ = Just Debug severityFor (Namespace [] ["TipMovedBetweenSTMBlocks"]) _ = Just Debug + severityFor (Namespace [] ["CacheHit"]) _ = Just Info + severityFor (Namespace [] ["CacheMiss"]) _ = Just Info severityFor _ _ = Nothing metricsDocFor (Namespace _ ["AddedTx"]) = @@ -1253,6 +1269,11 @@ instance MetaTrace (TraceEventMempool blk) where [ ("txsSyncDuration", "Latest time to sync the mempool in ms after block adoption") , (txsSyncDurationTotalCounterName, "Cumulative time spent syncing the mempool in ms after block adoption") ] + metricsDocFor (Namespace _ ["CacheHit"]) = + [ ("mempool.cache-hit-count", "Total count of cache hits") ] + metricsDocFor (Namespace _ ["CacheMiss"]) = + [ ("mempool.cache-miss-count", "Total count of cache hits") + ] metricsDocFor _ = [] documentFor (Namespace _ ["AddedTx"]) = Just @@ -1276,6 +1297,10 @@ instance MetaTrace (TraceEventMempool blk) where "Mempool is about to try to validate and add a transaction." documentFor (Namespace _ ["TipMovedBetweenSTMBlocks"]) = Just "LedgerDB moved to an alternative fork between two reads during re-sync." + documentFor (Namespace _ ["CacheHit"]) = Just + "Forge got a cache hit." + documentFor (Namespace _ ["CacheMiss"]) = Just + "Forge got a cache miss." documentFor _ = Nothing allNamespaces = @@ -1287,6 +1312,8 @@ instance MetaTrace (TraceEventMempool blk) where , Namespace [] ["SyncNotNeeded"] , Namespace [] ["AttemptAdd"] , Namespace [] ["TipMovedBetweenSTMBlocks"] + , Namespace [] ["CacheHit"] + , Namespace [] ["CacheMiss"] ] -------------------------------------------------------------------------------- diff --git a/cardano-node/src/Cardano/Tracing/OrphanInstances/Consensus.hs b/cardano-node/src/Cardano/Tracing/OrphanInstances/Consensus.hs index a0342fffcb3..13c67b78773 100644 --- a/cardano-node/src/Cardano/Tracing/OrphanInstances/Consensus.hs +++ b/cardano-node/src/Cardano/Tracing/OrphanInstances/Consensus.hs @@ -305,6 +305,8 @@ instance HasSeverityAnnotation (TraceEventMempool blk) where getSeverityAnnotation TraceMempoolSyncNotNeeded{} = Debug getSeverityAnnotation TraceMempoolSynced{} = Debug getSeverityAnnotation TraceMempoolAttemptingAdd{} = Debug + getSeverityAnnotation TraceMempoolCacheHit{} = Info + getSeverityAnnotation TraceMempoolCacheMiss{} = Info instance HasPrivacyAnnotation () instance HasSeverityAnnotation () where @@ -1623,6 +1625,16 @@ instance ( ToObject (ApplyTxErr blk), ToObject (GenTx blk) mconcat [ "kind" .= String "TraceMempoolTipMovedBetweenSTMBlocks" ] + toObject verb (TraceMempoolCacheHit point)= + mconcat + [ "kind" .= String "TraceMempoolCacheHit" + , "point" .= toObject verb point + ] + toObject verb (TraceMempoolCacheMiss point)= + mconcat + [ "kind" .= String "TraceMempoolCacheMiss" + , "point" .= toObject verb point + ] instance ToObject MempoolSize where toObject _verb MempoolSize{msNumTxs, msNumBytes} =