From 0df5bc81892bd58cc1be2f747282d6c4d5743c09 Mon Sep 17 00:00:00 2001 From: Alexander Esgen Date: Sun, 6 Jul 2025 16:28:20 +0200 Subject: [PATCH 1/4] Integrate Consensus --- .../Cardano/Node/Tracing/Tracers/ChainDB.hs | 55 +++++++++---------- 1 file changed, 27 insertions(+), 28 deletions(-) diff --git a/cardano-node/src/Cardano/Node/Tracing/Tracers/ChainDB.hs b/cardano-node/src/Cardano/Node/Tracing/Tracers/ChainDB.hs index 1bf1c7a1284..0edaf6259d1 100644 --- a/cardano-node/src/Cardano/Node/Tracing/Tracers/ChainDB.hs +++ b/cardano-node/src/Cardano/Node/Tracing/Tracers/ChainDB.hs @@ -2223,40 +2223,39 @@ instance MetaTrace V1.BackingStoreValueHandleTrace where ] instance LogFormatting V2.FlavorImplSpecificTrace where - forMachine _dtal V2.FlavorImplSpecificTraceInMemory = - mconcat [ "kind" .= String "InMemory" ] - forMachine _dtal V2.FlavorImplSpecificTraceOnDisk = - mconcat [ "kind" .= String "OnDisk" ] + forMachine _dtal V2.TraceLedgerTablesHandleCreate = + mconcat [ "kind" .= String "LedgerTablesHandleCreate" ] + forMachine _dtal V2.TraceLedgerTablesHandleClose = + mconcat [ "kind" .= String "LedgerTablesHandleClose" ] - forHuman V2.FlavorImplSpecificTraceInMemory = - "An in-memory backing store event was traced" - forHuman V2.FlavorImplSpecificTraceOnDisk = - "An on-disk backing store event was traced" + forHuman V2.TraceLedgerTablesHandleCreate = + "A ledger tables handle was created" + forHuman V2.TraceLedgerTablesHandleClose = + "A ledger tables handle was closed" instance MetaTrace V2.FlavorImplSpecificTrace where - namespaceFor V2.FlavorImplSpecificTraceInMemory = - Namespace [] ["InMemory"] - namespaceFor V2.FlavorImplSpecificTraceOnDisk = - Namespace [] ["OnDisk"] - - severityFor (Namespace _ ["InMemory"]) _ = Just Info - severityFor (Namespace _ ["OnDisk"]) _ = Just Info - severityFor _ _ = Nothing - - -- suspicious - privacyFor (Namespace _ ["InMemory"]) _ = Just Public - privacyFor (Namespace _ ["OnDisk"]) _ = Just Public - privacyFor _ _ = Just Public - - documentFor (Namespace _ ["InMemory"]) = - Just "An in-memory backing store event" - documentFor (Namespace _ ["OnDisk"]) = - Just "An on-disk backing store event" + namespaceFor V2.TraceLedgerTablesHandleCreate = + Namespace [] ["LedgerTablesHandleCreate"] + namespaceFor V2.TraceLedgerTablesHandleClose = + Namespace [] ["LedgerTablesHandleClose"] + + severityFor (Namespace _ ["LedgerTablesHandleCreate"]) _ = Just Debug + severityFor (Namespace _ ["LedgerTablesHandleClose"]) _ = Just Debug + severityFor _ _ = Nothing + + privacyFor (Namespace _ ["LedgerTablesHandleCreate"]) _ = Just Public + privacyFor (Namespace _ ["LedgerTablesHandleClose"]) _ = Just Public + privacyFor _ _ = Just Public + + documentFor (Namespace _ ["LedgerTablesHandleCreate"]) = + Just "A ledger tables handle was created" + documentFor (Namespace _ ["LedgerTablesHandleClose"]) = + Just "A ledger tables handle was closed" documentFor _ = Nothing allNamespaces = - [ Namespace [] ["InMemory"] - , Namespace [] ["OnDisk"] + [ Namespace [] ["LedgerTablesHandleCreate"] + , Namespace [] ["LedgerTablesHandleClose"] ] -------------------------------------------------------------------------------- From 5068c7eda95221d13a7e13939169dc03e75a7a84 Mon Sep 17 00:00:00 2001 From: Alexander Esgen Date: Wed, 17 Sep 2025 11:46:48 +0200 Subject: [PATCH 2/4] Integrate Consensus further --- .../src/Cardano/Node/Tracing/Era/Byron.hs | 7 ++- .../src/Cardano/Node/Tracing/Era/HardFork.hs | 29 +++++++------ .../src/Cardano/Node/Tracing/Era/Shelley.hs | 26 ++++++----- .../Cardano/Node/Tracing/Tracers/ChainDB.hs | 43 ++++++++++--------- .../Cardano/Tracing/OrphanInstances/Byron.hs | 9 ++-- .../Tracing/OrphanInstances/Consensus.hs | 26 +++++------ .../Tracing/OrphanInstances/HardFork.hs | 31 +++++++------ .../Tracing/OrphanInstances/Shelley.hs | 26 ++++++----- cardano-node/src/Cardano/Tracing/Tracers.hs | 20 ++++----- 9 files changed, 107 insertions(+), 110 deletions(-) diff --git a/cardano-node/src/Cardano/Node/Tracing/Era/Byron.hs b/cardano-node/src/Cardano/Node/Tracing/Era/Byron.hs index ef3d1eb3729..df831ee9a98 100644 --- a/cardano-node/src/Cardano/Node/Tracing/Era/Byron.hs +++ b/cardano-node/src/Cardano/Node/Tracing/Era/Byron.hs @@ -29,7 +29,7 @@ import Ouroboros.Consensus.Byron.Ledger (ByronBlock (..), import Ouroboros.Consensus.Byron.Ledger.Inspect (ByronLedgerUpdate (..), ProtocolUpdate (..), UpdateState (..)) import Ouroboros.Consensus.Ledger.SupportsMempool (GenTx, txId) -import Ouroboros.Consensus.Protocol.PBFT (PBftSelectView (..)) +import Ouroboros.Consensus.Protocol.PBFT (PBft, PBftTiebreakerView (..)) import Ouroboros.Consensus.Util.Condense (condense) import Ouroboros.Network.Block (blockHash, blockNo, blockSlot) @@ -213,10 +213,9 @@ instance LogFormatting ByronOtherHeaderEnvelopeError where , "slot" .= slot ] -instance LogFormatting PBftSelectView where - forMachine _dtal (PBftSelectView blkNo isEBB) = +instance LogFormatting PBftTiebreakerView where + forMachine _dtal (PBftTiebreakerView isEBB) = mconcat [ "kind" .= String "PBftSelectView" - , "blockNo" .= blkNo , "isEBB" .= fromIsEBB isEBB ] diff --git a/cardano-node/src/Cardano/Node/Tracing/Era/HardFork.hs b/cardano-node/src/Cardano/Node/Tracing/Era/HardFork.hs index 51f4eceb83f..4dcd4f51c22 100644 --- a/cardano-node/src/Cardano/Node/Tracing/Era/HardFork.hs +++ b/cardano-node/src/Cardano/Node/Tracing/Era/HardFork.hs @@ -26,7 +26,7 @@ import Ouroboros.Consensus.HardFork.Combinator import Ouroboros.Consensus.HardFork.Combinator.AcrossEras (EraMismatch (..), OneEraCannotForge (..), OneEraEnvelopeErr (..), OneEraForgeStateInfo (..), OneEraForgeStateUpdateError (..), OneEraLedgerError (..), - OneEraLedgerUpdate (..), OneEraLedgerWarning (..), OneEraSelectView (..), + OneEraLedgerUpdate (..), OneEraLedgerWarning (..), OneEraTiebreakerView (..), OneEraValidationErr (..), mkEraMismatch) import Ouroboros.Consensus.HardFork.Combinator.Condense () import Ouroboros.Consensus.HardFork.History @@ -36,7 +36,8 @@ import Ouroboros.Consensus.HeaderValidation (OtherHeaderEnvelopeError) import Ouroboros.Consensus.Ledger.Abstract (LedgerError) import Ouroboros.Consensus.Ledger.Inspect (LedgerUpdate, LedgerWarning) import Ouroboros.Consensus.Ledger.SupportsMempool (ApplyTxErr) -import Ouroboros.Consensus.Protocol.Abstract (SelectView, ValidationErr) +import Ouroboros.Consensus.Protocol.Abstract (SelectView (..), TiebreakerView (..), + ValidationErr) import Ouroboros.Consensus.TypeFamilyWrappers import Ouroboros.Consensus.Util.Condense (Condense (..)) @@ -349,19 +350,21 @@ instance LogFormatting (ForgeStateUpdateError blk) => LogFormatting (WrapForgeSt -- instances for HardForkSelectView -- -instance All (LogFormatting `Compose` WrapSelectView) xs => LogFormatting (HardForkSelectView xs) where - -- elide BlockNo as it is already contained in every per-era SelectView - -- TODO: use level DMinimal for a textual representation without the block number, - -- like this: `forMachine DMinimal . getHardForkSelectView`, and update the different SelectView instances - -- to not print the blockNr - forMachine dtal = forMachine dtal . dropBlockNo . getHardForkSelectView +instance All (LogFormatting `Compose` WrapTiebreakerView) xs => LogFormatting (HardForkTiebreakerView xs) where + forMachine dtal = forMachine dtal . getHardForkTiebreakerView -instance All (LogFormatting `Compose` WrapSelectView) xs => LogFormatting (OneEraSelectView xs) where +instance LogFormatting (TiebreakerView protocol) => LogFormatting (SelectView protocol) where + forMachine dtal sv = mconcat + [ "blockNo" .= svBlockNo sv + , forMachine dtal (svTiebreakerView sv) + ] + +instance All (LogFormatting `Compose` WrapTiebreakerView) xs => LogFormatting (OneEraTiebreakerView xs) where forMachine dtal = hcollapse - . hcmap (Proxy @(LogFormatting `Compose` WrapSelectView)) + . hcmap (Proxy @(LogFormatting `Compose` WrapTiebreakerView)) (K . forMachine dtal) - . getOneEraSelectView + . getOneEraTiebreakerView -instance LogFormatting (SelectView (BlockProtocol blk)) => LogFormatting (WrapSelectView blk) where - forMachine dtal = forMachine dtal . unwrapSelectView +instance LogFormatting (TiebreakerView (BlockProtocol blk)) => LogFormatting (WrapTiebreakerView blk) where + forMachine dtal = forMachine dtal . unwrapTiebreakerView diff --git a/cardano-node/src/Cardano/Node/Tracing/Era/Shelley.hs b/cardano-node/src/Cardano/Node/Tracing/Era/Shelley.hs index 0b85ad51932..d8e78014906 100644 --- a/cardano-node/src/Cardano/Node/Tracing/Era/Shelley.hs +++ b/cardano-node/src/Cardano/Node/Tracing/Era/Shelley.hs @@ -59,7 +59,7 @@ import Cardano.Tracing.OrphanInstances.Shelley () import Ouroboros.Consensus.Ledger.SupportsMempool (txId) import qualified Ouroboros.Consensus.Ledger.SupportsMempool as SupportsMempool import qualified Ouroboros.Consensus.Protocol.Praos as Praos -import Ouroboros.Consensus.Protocol.Praos.Common (PraosChainSelectView (..)) +import Ouroboros.Consensus.Protocol.Praos.Common (PraosTiebreakerView (..)) import Ouroboros.Consensus.Protocol.TPraos (TPraosCannotForge (..)) import Ouroboros.Consensus.Shelley.Ledger hiding (TxId) import qualified Ouroboros.Consensus.Shelley.Ledger as Consensus @@ -1292,20 +1292,18 @@ instance LogFormatting Praos.PraosEnvelopeError where , "blockSize" .= blockSize ] -instance Ledger.Crypto c => LogFormatting (PraosChainSelectView c) where - forMachine _ PraosChainSelectView { - csvChainLength - , csvSlotNo - , csvIssuer - , csvIssueNo - , csvTieBreakVRF +instance Ledger.Crypto c => LogFormatting (PraosTiebreakerView c) where + forMachine _ PraosTiebreakerView { + ptvSlotNo + , ptvIssuer + , ptvIssueNo + , ptvTieBreakVRF } = - mconcat [ "kind" .= String "PraosChainSelectView" - , "chainLength" .= csvChainLength - , "slotNo" .= csvSlotNo - , "issuerHash" .= hashKey csvIssuer - , "issueNo" .= csvIssueNo - , "tieBreakVRF" .= renderVRF csvTieBreakVRF + mconcat [ "kind" .= String "PraosTiebreakerView" + , "slotNo" .= ptvSlotNo + , "issuerHash" .= hashKey ptvIssuer + , "issueNo" .= ptvIssueNo + , "tieBreakVRF" .= renderVRF ptvTieBreakVRF ] where renderVRF = Text.decodeUtf8 . B16.encode . Crypto.getOutputVRFBytes diff --git a/cardano-node/src/Cardano/Node/Tracing/Tracers/ChainDB.hs b/cardano-node/src/Cardano/Node/Tracing/Tracers/ChainDB.hs index 0edaf6259d1..d0be1104678 100644 --- a/cardano-node/src/Cardano/Node/Tracing/Tracers/ChainDB.hs +++ b/cardano-node/src/Cardano/Node/Tracing/Tracers/ChainDB.hs @@ -399,7 +399,7 @@ instance ( LogFormatting (Header blk) , InspectLedger blk , HasIssuer blk ) => LogFormatting (ChainDB.TraceAddBlockEvent blk) where - forHuman (ChainDB.IgnoreBlockOlderThanK pt) = + forHuman (ChainDB.IgnoreBlockOlderThanImmTip pt) = "Ignoring block older than K: " <> renderRealPointAsPhrase pt forHuman (ChainDB.IgnoreBlockAlreadyInVolatileDB pt) = "Ignoring block already in DB: " <> renderRealPointAsPhrase pt @@ -411,11 +411,8 @@ instance ( LogFormatting (Header blk) "About to add block to queue: " <> renderRealPointAsPhrase pt FallingEdgeWith sz -> "Block added to queue: " <> renderRealPointAsPhrase pt <> ", queue size " <> condenseT sz - forHuman (ChainDB.PoppedBlockFromQueue edgePt) = - case edgePt of - RisingEdge -> - "Popping block from queue" - FallingEdgeWith pt -> + forHuman ChainDB.PoppingFromQueue = "Popping from queue" + forHuman (ChainDB.PoppedBlockFromQueue pt) = "Popped block from queue: " <> renderRealPointAsPhrase pt forHuman (ChainDB.StoreButDontChange pt) = "Ignoring block: " <> renderRealPointAsPhrase pt @@ -437,14 +434,14 @@ instance ( LogFormatting (Header blk) RisingEdge -> "Chain about to add block " <> renderRealPointAsPhrase pt FallingEdge -> "Chain added block " <> renderRealPointAsPhrase pt forHuman (ChainDB.PipeliningEvent ev') = forHumanOrMachine ev' - forHuman ChainDB.AddedReprocessLoEBlocksToQueue = + forHuman ChainDB.AddedReprocessLoEBlocksToQueue{} = "Added request to queue to reprocess blocks postponed by LoE." forHuman ChainDB.PoppedReprocessLoEBlocksFromQueue = "Poppped request from queue to reprocess blocks postponed by LoE." forHuman ChainDB.ChainSelectionLoEDebug{} = "ChainDB LoE debug event" - forMachine dtal (ChainDB.IgnoreBlockOlderThanK pt) = - mconcat [ "kind" .= String "IgnoreBlockOlderThanK" + forMachine dtal (ChainDB.IgnoreBlockOlderThanImmTip pt) = + mconcat [ "kind" .= String "IgnoreBlockOlderThanImmTip" , "block" .= forMachine dtal pt ] forMachine dtal (ChainDB.IgnoreBlockAlreadyInVolatileDB pt) = mconcat [ "kind" .= String "IgnoreBlockAlreadyInVolatileDB" @@ -459,11 +456,12 @@ instance ( LogFormatting (Header blk) , case edgeSz of RisingEdge -> "risingEdge" .= True FallingEdgeWith sz -> "queueSize" .= toJSON sz ] - forMachine dtal (ChainDB.PoppedBlockFromQueue edgePt) = + forMachine _ ChainDB.PoppingFromQueue = + mconcat [ "kind" .= String "TraceAddBlockEvent.PoppingFromQueue" + ] + forMachine dtal (ChainDB.PoppedBlockFromQueue pt) = mconcat [ "kind" .= String "TraceAddBlockEvent.PoppedBlockFromQueue" - , case edgePt of - RisingEdge -> "risingEdge" .= True - FallingEdgeWith pt -> "block" .= forMachine dtal pt ] + , "block" .= forMachine dtal pt ] forMachine dtal (ChainDB.StoreButDontChange pt) = mconcat [ "kind" .= String "StoreButDontChange" , "block" .= forMachine dtal pt ] @@ -556,7 +554,7 @@ instance ( LogFormatting (Header blk) <> [ "risingEdge" .= True | RisingEdge <- [enclosing] ] forMachine dtal (ChainDB.PipeliningEvent ev') = forMachine dtal ev' - forMachine _dtal ChainDB.AddedReprocessLoEBlocksToQueue = + forMachine _dtal ChainDB.AddedReprocessLoEBlocksToQueue{} = mconcat [ "kind" .= String "AddedReprocessLoEBlocksToQueue" ] forMachine _dtal ChainDB.PoppedReprocessLoEBlocksFromQueue = mconcat [ "kind" .= String "PoppedReprocessLoEBlocksFromQueue" ] @@ -619,14 +617,16 @@ instance ( LogFormatting (Header blk) instance MetaTrace (ChainDB.TraceAddBlockEvent blk) where - namespaceFor ChainDB.IgnoreBlockOlderThanK {} = - Namespace [] ["IgnoreBlockOlderThanK"] + namespaceFor ChainDB.IgnoreBlockOlderThanImmTip {} = + Namespace [] ["IgnoreBlockOlderThanImmTip"] namespaceFor ChainDB.IgnoreBlockAlreadyInVolatileDB {} = Namespace [] ["IgnoreBlockAlreadyInVolatileDB"] namespaceFor ChainDB.IgnoreInvalidBlock {} = Namespace [] ["IgnoreInvalidBlock"] namespaceFor ChainDB.AddedBlockToQueue {} = Namespace [] ["AddedBlockToQueue"] + namespaceFor ChainDB.PoppingFromQueue = + Namespace [] ["PoppingFromQueue"] namespaceFor ChainDB.PoppedBlockFromQueue {} = Namespace [] ["PoppedBlockFromQueue"] namespaceFor ChainDB.AddedBlockToVolatileDB {} = @@ -647,14 +647,14 @@ instance MetaTrace (ChainDB.TraceAddBlockEvent blk) where nsPrependInner "AddBlockValidation" (namespaceFor ev') namespaceFor (ChainDB.PipeliningEvent ev') = nsPrependInner "PipeliningEvent" (namespaceFor ev') - namespaceFor ChainDB.AddedReprocessLoEBlocksToQueue = + namespaceFor ChainDB.AddedReprocessLoEBlocksToQueue{} = Namespace [] ["AddedReprocessLoEBlocksToQueue"] namespaceFor ChainDB.PoppedReprocessLoEBlocksFromQueue = Namespace [] ["PoppedReprocessLoEBlocksFromQueue"] namespaceFor ChainDB.ChainSelectionLoEDebug {} = Namespace [] ["ChainSelectionLoEDebug"] - severityFor (Namespace _ ["IgnoreBlockOlderThanK"]) _ = Just Info + severityFor (Namespace _ ["IgnoreBlockOlderThanImmTip"]) _ = Just Info severityFor (Namespace _ ["IgnoreBlockAlreadyInVolatileDB"]) _ = Just Info severityFor (Namespace _ ["IgnoreInvalidBlock"]) _ = Just Info severityFor (Namespace _ ["AddedBlockToQueue"]) _ = Just Debug @@ -764,7 +764,7 @@ instance MetaTrace (ChainDB.TraceAddBlockEvent blk) where ] metricsDocFor _ = [] - documentFor (Namespace _ ["IgnoreBlockOlderThanK"]) = Just $ mconcat + documentFor (Namespace _ ["IgnoreBlockOlderThanImmTip"]) = Just $ mconcat [ "A block with a 'BlockNo' more than @k@ back than the current tip" , " was ignored." ] @@ -814,7 +814,7 @@ instance MetaTrace (ChainDB.TraceAddBlockEvent blk) where allNamespaces = - [ Namespace [] ["IgnoreBlockOlderThanK"] + [ Namespace [] ["IgnoreBlockOlderThanImmTip"] , Namespace [] ["IgnoreBlockAlreadyInVolatileDB"] , Namespace [] ["IgnoreInvalidBlock"] , Namespace [] ["AddedBlockToQueue"] @@ -1821,6 +1821,7 @@ instance LogFormatting LedgerDB.TraceForkerEvent where forMachine _dtals LedgerDB.ForkerReadStatistics = mempty forMachine _dtals LedgerDB.ForkerPushStart = mempty forMachine _dtals LedgerDB.ForkerPushEnd = mempty + forMachine _dtals LedgerDB.DanglingForkerClosed = mempty forHuman LedgerDB.ForkerOpen = "Opened forker" forHuman LedgerDB.ForkerCloseUncommitted = "Forker closed without committing" @@ -1832,6 +1833,7 @@ instance LogFormatting LedgerDB.TraceForkerEvent where forHuman LedgerDB.ForkerReadStatistics = "Gathering statistics" forHuman LedgerDB.ForkerPushStart = "Started to push" forHuman LedgerDB.ForkerPushEnd = "Pushed" + forHuman LedgerDB.DanglingForkerClosed = "Dangling forker closed" instance MetaTrace LedgerDB.TraceForkerEventWithKey where namespaceFor (LedgerDB.TraceForkerEventWithKey _ ev) = @@ -1854,6 +1856,7 @@ instance MetaTrace LedgerDB.TraceForkerEvent where namespaceFor LedgerDB.ForkerReadStatistics = Namespace [] ["Statistics"] namespaceFor LedgerDB.ForkerPushStart = Namespace [] ["StartPush"] namespaceFor LedgerDB.ForkerPushEnd = Namespace [] ["FinishPush"] + namespaceFor LedgerDB.DanglingForkerClosed = Namespace [] ["DanglingForkerClosed"] severityFor _ _ = Just Debug diff --git a/cardano-node/src/Cardano/Tracing/OrphanInstances/Byron.hs b/cardano-node/src/Cardano/Tracing/OrphanInstances/Byron.hs index 5112a7e3891..914617e76fb 100644 --- a/cardano-node/src/Cardano/Tracing/OrphanInstances/Byron.hs +++ b/cardano-node/src/Cardano/Tracing/OrphanInstances/Byron.hs @@ -28,7 +28,7 @@ import Ouroboros.Consensus.Byron.Ledger (ByronBlock (..), ByronNodeToC import Ouroboros.Consensus.Byron.Ledger.Inspect (ByronLedgerUpdate (..), ProtocolUpdate (..), UpdateState (..)) import Ouroboros.Consensus.Ledger.SupportsMempool (GenTx, txId) -import Ouroboros.Consensus.Protocol.PBFT (PBftSelectView (..)) +import Ouroboros.Consensus.Protocol.PBFT (PBftTiebreakerView (..)) import Ouroboros.Consensus.Util.Condense (condense) import Ouroboros.Network.Block (blockHash, blockNo, blockSlot) @@ -221,10 +221,9 @@ instance ToJSON ByronNodeToNodeVersion where toJSON ByronNodeToNodeVersion1 = String "ByronNodeToNodeVersion1" toJSON ByronNodeToNodeVersion2 = String "ByronNodeToNodeVersion2" -instance ToObject PBftSelectView where - toObject _verb (PBftSelectView blkNo isEBB) = +instance ToObject PBftTiebreakerView where + toObject _verb (PBftTiebreakerView isEBB) = mconcat - [ "kind" .= String "PBftSelectView" - , "blockNo" .= blkNo + [ "kind" .= String "PBftTiebreakerView" , "isEBB" .= fromIsEBB isEBB ] diff --git a/cardano-node/src/Cardano/Tracing/OrphanInstances/Consensus.hs b/cardano-node/src/Cardano/Tracing/OrphanInstances/Consensus.hs index 587ac517702..2d0ff97d437 100644 --- a/cardano-node/src/Cardano/Tracing/OrphanInstances/Consensus.hs +++ b/cardano-node/src/Cardano/Tracing/OrphanInstances/Consensus.hs @@ -147,7 +147,7 @@ instance ConvertRawHash blk => ConvertRawHash (HeaderWithTime blk) where instance HasPrivacyAnnotation (ChainDB.TraceEvent blk) instance HasSeverityAnnotation (ChainDB.TraceEvent blk) where getSeverityAnnotation (ChainDB.TraceAddBlockEvent ev) = case ev of - ChainDB.IgnoreBlockOlderThanK {} -> Info + ChainDB.IgnoreBlockOlderThanImmTip {} -> Info ChainDB.IgnoreBlockAlreadyInVolatileDB {} -> Info ChainDB.IgnoreInvalidBlock {} -> Info ChainDB.AddedBlockToQueue {} -> Debug @@ -166,7 +166,7 @@ instance HasSeverityAnnotation (ChainDB.TraceEvent blk) where ChainDB.ValidCandidate {} -> Info ChainDB.UpdateLedgerDbTraceEvent {} -> Debug ChainDB.PipeliningEvent {} -> Debug - ChainDB.AddedReprocessLoEBlocksToQueue -> Debug + ChainDB.AddedReprocessLoEBlocksToQueue _ -> Debug ChainDB.PoppedReprocessLoEBlocksFromQueue -> Debug ChainDB.ChainSelectionLoEDebug _ _ -> Debug @@ -528,7 +528,7 @@ instance ( ConvertRawHash blk formatText tev _obj = case tev of ChainDB.TraceLastShutdownUnclean -> "ChainDB is not clean. Validating all immutable chunks" ChainDB.TraceAddBlockEvent ev -> case ev of - ChainDB.IgnoreBlockOlderThanK pt -> + ChainDB.IgnoreBlockOlderThanImmTip pt -> "Ignoring block older than K: " <> renderRealPointAsPhrase pt ChainDB.IgnoreBlockAlreadyInVolatileDB pt -> "Ignoring block already in DB: " <> renderRealPointAsPhrase pt @@ -540,18 +540,14 @@ instance ( ConvertRawHash blk "About to add block to queue: " <> renderRealPointAsPhrase pt FallingEdgeWith sz -> "Block added to queue: " <> renderRealPointAsPhrase pt <> " queue size " <> condenseT sz - ChainDB.AddedReprocessLoEBlocksToQueue -> + ChainDB.AddedReprocessLoEBlocksToQueue _ -> "Added request to queue to reprocess blocks postponed by LoE." ChainDB.PoppedReprocessLoEBlocksFromQueue -> "Poppped request from queue to reprocess blocks postponed by LoE." ChainDB.ChainSelectionLoEDebug {} -> "ChainDB LoE debug event" - ChainDB.PoppedBlockFromQueue edgePt -> - case edgePt of - RisingEdge -> - "Popping block from queue" - FallingEdgeWith pt -> + ChainDB.PoppedBlockFromQueue pt -> "Popped block from queue: " <> renderRealPointAsPhrase pt ChainDB.StoreButDontChange pt -> "Ignoring block: " <> renderRealPointAsPhrase pt @@ -931,8 +927,8 @@ instance ( ConvertRawHash blk toObject _verb ChainDB.TraceLastShutdownUnclean = mconcat [ "kind" .= String "TraceLastShutdownUnclean" ] toObject verb (ChainDB.TraceAddBlockEvent ev) = case ev of - ChainDB.IgnoreBlockOlderThanK pt -> - mconcat [ "kind" .= String "TraceAddBlockEvent.IgnoreBlockOlderThanK" + ChainDB.IgnoreBlockOlderThanImmTip pt -> + mconcat [ "kind" .= String "TraceAddBlockEvent.IgnoreBlockOlderThanImmTip" , "block" .= toObject verb pt ] ChainDB.IgnoreBlockAlreadyInVolatileDB pt -> mconcat [ "kind" .= String "TraceAddBlockEvent.IgnoreBlockAlreadyInVolatileDB" @@ -947,11 +943,9 @@ instance ( ConvertRawHash blk , case edgeSz of RisingEdge -> "risingEdge" .= True FallingEdgeWith sz -> "queueSize" .= toJSON sz ] - ChainDB.PoppedBlockFromQueue edgePt -> + ChainDB.PoppedBlockFromQueue pt -> mconcat [ "kind" .= String "TraceAddBlockEvent.PoppedBlockFromQueue" - , case edgePt of - RisingEdge -> "risingEdge" .= True - FallingEdgeWith pt -> "block" .= toObject verb pt ] + , "block" .= toObject verb pt ] ChainDB.StoreButDontChange pt -> mconcat [ "kind" .= String "TraceAddBlockEvent.StoreButDontChange" , "block" .= toObject verb pt ] @@ -1027,7 +1021,7 @@ instance ( ConvertRawHash blk mconcat [ "kind" .= String "TraceAddBlockEvent.PipeliningEvent.OutdatedTentativeHeader" , "block" .= renderPointForVerbosity verb (blockPoint hdr) ] - ChainDB.AddedReprocessLoEBlocksToQueue -> + ChainDB.AddedReprocessLoEBlocksToQueue _ -> mconcat [ "kind" .= String "AddedReprocessLoEBlocksToQueue" ] ChainDB.PoppedReprocessLoEBlocksFromQueue -> mconcat [ "kind" .= String "PoppedReprocessLoEBlocksFromQueue" ] diff --git a/cardano-node/src/Cardano/Tracing/OrphanInstances/HardFork.hs b/cardano-node/src/Cardano/Tracing/OrphanInstances/HardFork.hs index 6b625395fd8..105ccf2faec 100644 --- a/cardano-node/src/Cardano/Tracing/OrphanInstances/HardFork.hs +++ b/cardano-node/src/Cardano/Tracing/OrphanInstances/HardFork.hs @@ -29,13 +29,12 @@ import Ouroboros.Consensus.HardFork.Combinator import Ouroboros.Consensus.HardFork.Combinator.AcrossEras (EraMismatch (..), OneEraCannotForge (..), OneEraEnvelopeErr (..), OneEraForgeStateInfo (..), OneEraForgeStateUpdateError (..), OneEraLedgerError (..), - OneEraLedgerUpdate (..), OneEraLedgerWarning (..), OneEraSelectView (..), + OneEraLedgerUpdate (..), OneEraLedgerWarning (..), OneEraTiebreakerView (..), OneEraValidationErr (..), mkEraMismatch) import Ouroboros.Consensus.HardFork.Combinator.Condense () import Ouroboros.Consensus.HardFork.Combinator.Serialisation.Common - (EraNodeToClientVersion (..), - HardForkNodeToNodeVersion (..), HardForkSpecificNodeToClientVersion (..), - HardForkSpecificNodeToNodeVersion (..)) + (EraNodeToClientVersion (..), HardForkNodeToNodeVersion (..), + HardForkSpecificNodeToClientVersion (..), HardForkSpecificNodeToNodeVersion (..)) import Ouroboros.Consensus.HardFork.History.EraParams (EraParams (..), SafeZone) import Ouroboros.Consensus.HeaderValidation (OtherHeaderEnvelopeError) import Ouroboros.Consensus.Ledger.Abstract (LedgerError) @@ -43,7 +42,8 @@ import Ouroboros.Consensus.Ledger.Inspect (LedgerUpdate, LedgerWarning import Ouroboros.Consensus.Ledger.SupportsMempool (ApplyTxErr) import Ouroboros.Consensus.Node.NetworkProtocolVersion (BlockNodeToClientVersion, BlockNodeToNodeVersion) -import Ouroboros.Consensus.Protocol.Abstract (SelectView, ValidationErr) +import Ouroboros.Consensus.Protocol.Abstract (ConsensusProtocol (TiebreakerView), + SelectView (svBlockNo, svTiebreakerView), ValidationErr) import Ouroboros.Consensus.TypeFamilyWrappers import Ouroboros.Consensus.Util.Condense (Condense (..)) @@ -431,16 +431,21 @@ instance (ToJSON (BlockNodeToNodeVersion blk)) => ToJSON (WrapNodeToNodeVersion -- instances for HardForkSelectView -- -instance All (ToObject `Compose` WrapSelectView) xs => ToObject (HardForkSelectView xs) where - -- elide BlockNo as it is already contained in every per-era SelectView - toObject verb = toObject verb . dropBlockNo . getHardForkSelectView +instance All (ToObject `Compose` WrapTiebreakerView) xs => ToObject (HardForkTiebreakerView xs) where + toObject verb = toObject verb . getHardForkTiebreakerView -instance All (ToObject `Compose` WrapSelectView) xs => ToObject (OneEraSelectView xs) where +instance ToObject (TiebreakerView protocol) => ToObject (SelectView protocol) where + toObject verb sv = mconcat + [ "blockNo" .= svBlockNo sv + , toObject verb (svTiebreakerView sv) + ] + +instance All (ToObject `Compose` WrapTiebreakerView) xs => ToObject (OneEraTiebreakerView xs) where toObject verb = hcollapse - . hcmap (Proxy @(ToObject `Compose` WrapSelectView)) + . hcmap (Proxy @(ToObject `Compose` WrapTiebreakerView)) (K . toObject verb) - . getOneEraSelectView + . getOneEraTiebreakerView -instance ToObject (SelectView (BlockProtocol blk)) => ToObject (WrapSelectView blk) where - toObject verb = toObject verb . unwrapSelectView +instance ToObject (TiebreakerView (BlockProtocol blk)) => ToObject (WrapTiebreakerView blk) where + toObject verb = toObject verb . unwrapTiebreakerView diff --git a/cardano-node/src/Cardano/Tracing/OrphanInstances/Shelley.hs b/cardano-node/src/Cardano/Tracing/OrphanInstances/Shelley.hs index ba8f0140710..522f4eb37d0 100644 --- a/cardano-node/src/Cardano/Tracing/OrphanInstances/Shelley.hs +++ b/cardano-node/src/Cardano/Tracing/OrphanInstances/Shelley.hs @@ -64,7 +64,7 @@ import Ouroboros.Consensus.Ledger.SupportsMempool (txId) import qualified Ouroboros.Consensus.Ledger.SupportsMempool as SupportsMempool import qualified Ouroboros.Consensus.Protocol.Ledger.HotKey as HotKey import qualified Ouroboros.Consensus.Protocol.Praos as Praos -import Ouroboros.Consensus.Protocol.Praos.Common (PraosChainSelectView (..)) +import Ouroboros.Consensus.Protocol.Praos.Common (PraosTiebreakerView (..)) import Ouroboros.Consensus.Protocol.TPraos (TPraosCannotForge (..)) import Ouroboros.Consensus.Shelley.Ledger hiding (TxId) import Ouroboros.Consensus.Shelley.Ledger.Inspect @@ -1327,20 +1327,18 @@ instance ToJSON ShelleyNodeToClientVersion where toJSON ShelleyNodeToClientVersion11 = String "ShelleyNodeToClientVersion11" toJSON ShelleyNodeToClientVersion12 = String "ShelleyNodeToClientVersion12" -instance Core.Crypto c => ToObject (PraosChainSelectView c) where - toObject _ PraosChainSelectView { - csvChainLength - , csvSlotNo - , csvIssuer - , csvIssueNo - , csvTieBreakVRF +instance Core.Crypto c => ToObject (PraosTiebreakerView c) where + toObject _ PraosTiebreakerView { + ptvSlotNo + , ptvIssuer + , ptvIssueNo + , ptvTieBreakVRF } = - mconcat [ "kind" .= String "PraosChainSelectView" - , "chainLength" .= csvChainLength - , "slotNo" .= csvSlotNo - , "issuerHash" .= hashKey csvIssuer - , "issueNo" .= csvIssueNo - , "tieBreakVRF" .= renderVRF csvTieBreakVRF + mconcat [ "kind" .= String "PraosTiebreakerView" + , "slotNo" .= ptvSlotNo + , "issuerHash" .= hashKey ptvIssuer + , "issueNo" .= ptvIssueNo + , "tieBreakVRF" .= renderVRF ptvTieBreakVRF ] where renderVRF = Text.decodeUtf8 . B16.encode . Crypto.getOutputVRFBytes diff --git a/cardano-node/src/Cardano/Tracing/Tracers.hs b/cardano-node/src/Cardano/Tracing/Tracers.hs index 8a8d9bab3f6..0c4ddf9e80f 100644 --- a/cardano-node/src/Cardano/Tracing/Tracers.hs +++ b/cardano-node/src/Cardano/Tracing/Tracers.hs @@ -43,6 +43,7 @@ import Cardano.BM.Data.Transformers import Cardano.BM.Internal.ElidingTracer import Cardano.BM.Trace (traceNamedObject) import Cardano.BM.Tracing +import Cardano.Network.PeerSelection.PeerTrustable (PeerTrustable) import Cardano.Node.Configuration.Logging import Cardano.Node.Protocol.Byron () import Cardano.Node.Protocol.Shelley () @@ -61,6 +62,9 @@ import Cardano.Tracing.OrphanInstances.Network () import Cardano.Tracing.Render (renderChainHash, renderHeaderHash) import Cardano.Tracing.Shutdown () import Cardano.Tracing.Startup () +import qualified Ouroboros.Cardano.Network.PeerSelection.Governor.PeerSelectionState as Cardano +import qualified Ouroboros.Cardano.Network.PeerSelection.Governor.Types as Cardano +import qualified Ouroboros.Cardano.Network.PublicRootPeers as Cardano.PublicRootPeers import Ouroboros.Consensus.Block (BlockConfig, BlockProtocol, CannotForge, ConvertRawHash (..), ForgeStateInfo, ForgeStateUpdateError, Header, realPointHash, realPointSlot) @@ -71,8 +75,8 @@ import Ouroboros.Consensus.Ledger.Abstract (LedgerErr, LedgerState) import Ouroboros.Consensus.Ledger.Extended (ledgerState) import Ouroboros.Consensus.Ledger.Inspect (InspectLedger, LedgerEvent) import Ouroboros.Consensus.Ledger.Query (BlockQuery, Query) -import Ouroboros.Consensus.Ledger.SupportsMempool (ApplyTxErr, GenTx, GenTxId, HasTxs, - LedgerSupportsMempool, ByteSize32 (..)) +import Ouroboros.Consensus.Ledger.SupportsMempool (ApplyTxErr, ByteSize32 (..), GenTx, + GenTxId, HasTxs, LedgerSupportsMempool) import Ouroboros.Consensus.Ledger.SupportsProtocol (LedgerSupportsProtocol) import Ouroboros.Consensus.Mempool (MempoolSize (..), TraceEventMempool (..)) import Ouroboros.Consensus.MiniProtocol.BlockFetch.Server @@ -87,12 +91,6 @@ import qualified Ouroboros.Consensus.Protocol.Ledger.HotKey as HotKey import qualified Ouroboros.Consensus.Storage.ChainDB as ChainDB import qualified Ouroboros.Consensus.Storage.LedgerDB as LedgerDB import Ouroboros.Consensus.Util.Enclose - -import Cardano.Network.PeerSelection.PeerTrustable (PeerTrustable) -import qualified Ouroboros.Cardano.Network.PeerSelection.Governor.PeerSelectionState as Cardano -import qualified Ouroboros.Cardano.Network.PeerSelection.Governor.Types as Cardano -import qualified Ouroboros.Cardano.Network.PublicRootPeers as Cardano.PublicRootPeers - import qualified Ouroboros.Network.AnchoredFragment as AF import Ouroboros.Network.Block (BlockNo (..), ChainUpdate (..), HasHeader (..), Point, StandardHash, blockNo, pointSlot, unBlockNo) @@ -113,8 +111,8 @@ import Ouroboros.Network.InboundGovernor.State as InboundGovernor import Ouroboros.Network.NodeToClient (LocalAddress) import Ouroboros.Network.NodeToNode (RemoteAddress) import Ouroboros.Network.PeerSelection.Churn (ChurnCounters (..)) -import Ouroboros.Network.PeerSelection.Governor ( - PeerSelectionCounters, PeerSelectionView (..)) +import Ouroboros.Network.PeerSelection.Governor (PeerSelectionCounters, + PeerSelectionView (..)) import qualified Ouroboros.Network.PeerSelection.Governor as Governor import Ouroboros.Network.Point (fromWithOrigin) import Ouroboros.Network.Protocol.LocalStateQuery.Type (LocalStateQuery, ShowQuery) @@ -271,7 +269,7 @@ instance ElidingTracer (WithSeverity (ChainDB.TraceEvent blk)) where doelide (WithSeverity _ (ChainDB.TraceLedgerDBEvent LedgerDB.LedgerDBFlavorImplEvent{})) = True doelide (WithSeverity _ (ChainDB.TraceGCEvent _)) = True - doelide (WithSeverity _ (ChainDB.TraceAddBlockEvent (ChainDB.IgnoreBlockOlderThanK _))) = False + doelide (WithSeverity _ (ChainDB.TraceAddBlockEvent (ChainDB.IgnoreBlockOlderThanImmTip _))) = False doelide (WithSeverity _ (ChainDB.TraceAddBlockEvent (ChainDB.IgnoreInvalidBlock _ _))) = False doelide (WithSeverity _ (ChainDB.TraceAddBlockEvent (ChainDB.StoreButDontChange _))) = False doelide (WithSeverity _ (ChainDB.TraceAddBlockEvent (ChainDB.TrySwitchToAFork _ _))) = False From 875db9696630bf9bd80348635a48399eadb7ce9e Mon Sep 17 00:00:00 2001 From: Alexander Esgen Date: Wed, 17 Sep 2025 13:18:26 +0200 Subject: [PATCH 3/4] Integrate Peras-related stuff --- .../src/Cardano/Node/TraceConstraints.hs | 5 ++- .../src/Cardano/Node/Tracing/Era/HardFork.hs | 13 +++--- .../src/Cardano/Node/Tracing/Tracers.hs | 5 +++ .../Cardano/Node/Tracing/Tracers/ChainDB.hs | 42 ++++++++++++------- .../Cardano/Node/Tracing/Tracers/Startup.hs | 2 + .../Tracing/OrphanInstances/Consensus.hs | 17 ++++---- .../Tracing/OrphanInstances/HardFork.hs | 12 +++--- .../Tracing/OrphanInstances/Network.hs | 31 +++++++------- cardano-node/src/Cardano/Tracing/Tracers.hs | 15 +++++-- 9 files changed, 88 insertions(+), 54 deletions(-) diff --git a/cardano-node/src/Cardano/Node/TraceConstraints.hs b/cardano-node/src/Cardano/Node/TraceConstraints.hs index ec4b9f61034..9ba6e7ef726 100644 --- a/cardano-node/src/Cardano/Node/TraceConstraints.hs +++ b/cardano-node/src/Cardano/Node/TraceConstraints.hs @@ -23,6 +23,7 @@ import Ouroboros.Consensus.Ledger.SupportsMempool (ApplyTxErr, HasTxId import Ouroboros.Consensus.Node.NetworkProtocolVersion (HasNetworkProtocolVersion (BlockNodeToClientVersion, BlockNodeToNodeVersion)) import Ouroboros.Consensus.Node.Run (RunNode, SerialiseNodeToNodeConstraints) +import Ouroboros.Consensus.Peras.SelectView import Ouroboros.Consensus.Protocol.Abstract (SelectView, ValidationErr) import Ouroboros.Consensus.Shelley.Ledger.Mempool (GenTx, TxId) import Ouroboros.Network.Block (Serialised) @@ -51,7 +52,7 @@ type TraceConstraints blk = , ToObject (LedgerError blk) , ToObject (LedgerEvent blk) , ToObject (OtherHeaderEnvelopeError blk) - , ToObject (SelectView (BlockProtocol blk)) + , ToObject (WeightedSelectView (BlockProtocol blk)) , ToObject (ValidationErr (BlockProtocol blk)) , ToObject (CannotForge blk) , ToObject (ForgeStateUpdateError blk) @@ -66,7 +67,7 @@ type TraceConstraints blk = , LogFormatting (LedgerUpdate blk) , LogFormatting (LedgerWarning blk) , LogFormatting (OtherHeaderEnvelopeError blk) - , LogFormatting (SelectView (BlockProtocol blk)) + , LogFormatting (WeightedSelectView (BlockProtocol blk)) , LogFormatting (ValidationErr (BlockProtocol blk)) , LogFormatting (CannotForge blk) , LogFormatting (ForgeStateUpdateError blk) diff --git a/cardano-node/src/Cardano/Node/Tracing/Era/HardFork.hs b/cardano-node/src/Cardano/Node/Tracing/Era/HardFork.hs index 4dcd4f51c22..7d02352c0bb 100644 --- a/cardano-node/src/Cardano/Node/Tracing/Era/HardFork.hs +++ b/cardano-node/src/Cardano/Node/Tracing/Era/HardFork.hs @@ -19,7 +19,7 @@ import Cardano.Logging import Cardano.Slotting.Slot (EpochSize (..)) import Cardano.Tracing.OrphanInstances.HardFork () import Ouroboros.Consensus.Block (BlockProtocol, CannotForge, ForgeStateInfo, - ForgeStateUpdateError) + ForgeStateUpdateError, PerasWeight (..)) import Ouroboros.Consensus.BlockchainTime (getSlotLength) import Ouroboros.Consensus.Cardano.Condense () import Ouroboros.Consensus.HardFork.Combinator @@ -36,8 +36,8 @@ import Ouroboros.Consensus.HeaderValidation (OtherHeaderEnvelopeError) import Ouroboros.Consensus.Ledger.Abstract (LedgerError) import Ouroboros.Consensus.Ledger.Inspect (LedgerUpdate, LedgerWarning) import Ouroboros.Consensus.Ledger.SupportsMempool (ApplyTxErr) -import Ouroboros.Consensus.Protocol.Abstract (SelectView (..), TiebreakerView (..), - ValidationErr) +import Ouroboros.Consensus.Peras.SelectView +import Ouroboros.Consensus.Protocol.Abstract (TiebreakerView (..), ValidationErr) import Ouroboros.Consensus.TypeFamilyWrappers import Ouroboros.Consensus.Util.Condense (Condense (..)) @@ -353,10 +353,11 @@ instance LogFormatting (ForgeStateUpdateError blk) => LogFormatting (WrapForgeSt instance All (LogFormatting `Compose` WrapTiebreakerView) xs => LogFormatting (HardForkTiebreakerView xs) where forMachine dtal = forMachine dtal . getHardForkTiebreakerView -instance LogFormatting (TiebreakerView protocol) => LogFormatting (SelectView protocol) where +instance LogFormatting (TiebreakerView protocol) => LogFormatting (WeightedSelectView protocol) where forMachine dtal sv = mconcat - [ "blockNo" .= svBlockNo sv - , forMachine dtal (svTiebreakerView sv) + [ "length" .= wsvLength sv + , "weightBoost" .= unPerasWeight (wsvWeightBoost sv) + , forMachine dtal (wsvTiebreaker sv) ] instance All (LogFormatting `Compose` WrapTiebreakerView) xs => LogFormatting (OneEraTiebreakerView xs) where diff --git a/cardano-node/src/Cardano/Node/Tracing/Tracers.hs b/cardano-node/src/Cardano/Node/Tracing/Tracers.hs index da4c82fd265..36b9968aa44 100644 --- a/cardano-node/src/Cardano/Node/Tracing/Tracers.hs +++ b/cardano-node/src/Cardano/Node/Tracing/Tracers.hs @@ -408,6 +408,9 @@ mkConsensusTracers configReflection trBase trForward mbTrEKG _trDataPoint trConf traceWith consensusCsjTr , Consensus.dbfTracer = Tracer $ traceWith consensusDbfTr + -- TODO plug these in + , Consensus.perasCertDiffusionInboundTracer = Tracer $ \_ -> pure () + , Consensus.perasCertDiffusionOutboundTracer = Tracer $ \_ -> pure () } mkNodeToClientTracers :: forall blk. @@ -517,6 +520,8 @@ mkNodeToNodeTracers configReflection trBase trForward mbTrEKG _trDataPoint trCon traceWith keepAliveTracer , NtN.tPeerSharingTracer = Tracer $ traceWith peerSharingTracer + -- TODO plug in + , NtN.tPerasCertDiffusionTracer = Tracer $ \_ -> pure () } mkDiffusionTracers diff --git a/cardano-node/src/Cardano/Node/Tracing/Tracers/ChainDB.hs b/cardano-node/src/Cardano/Node/Tracing/Tracers/ChainDB.hs index d0be1104678..97cdc2f6233 100644 --- a/cardano-node/src/Cardano/Node/Tracing/Tracers/ChainDB.hs +++ b/cardano-node/src/Cardano/Node/Tracing/Tracers/ChainDB.hs @@ -28,7 +28,8 @@ import Ouroboros.Consensus.Ledger.Abstract (LedgerError) import Ouroboros.Consensus.Ledger.Extended (ExtValidationError (..)) import Ouroboros.Consensus.Ledger.Inspect (InspectLedger, LedgerEvent (..)) import Ouroboros.Consensus.Ledger.SupportsProtocol (LedgerSupportsProtocol) -import Ouroboros.Consensus.Protocol.Abstract (SelectView, ValidationErr) +import Ouroboros.Consensus.Peras.SelectView +import Ouroboros.Consensus.Protocol.Abstract (ValidationErr) import qualified Ouroboros.Consensus.Protocol.PBFT as PBFT import qualified Ouroboros.Consensus.Storage.ChainDB as ChainDB import qualified Ouroboros.Consensus.Storage.ImmutableDB as ImmDB @@ -79,7 +80,7 @@ withAddedToCurrentChainEmptyLimited tr = do instance ( LogFormatting (Header blk) , LogFormatting (LedgerEvent blk) , LogFormatting (RealPoint blk) - , LogFormatting (SelectView (BlockProtocol blk)) + , LogFormatting (WeightedSelectView (BlockProtocol blk)) , ConvertRawHash blk , ConvertRawHash (Header blk) , LedgerSupportsProtocol blk @@ -103,6 +104,7 @@ instance ( LogFormatting (Header blk) "Chain Selection was starved." ChainDB.ChainSelStarvation (FallingEdgeWith pt) -> "Chain Selection was unstarved by " <> renderRealPoint pt + forHuman _ = "TODO" forMachine _ ChainDB.TraceLastShutdownUnclean = mconcat [ "kind" .= String "LastShutdownUnclean" ] @@ -132,6 +134,10 @@ instance ( LogFormatting (Header blk) forMachine details v forMachine details (ChainDB.TraceVolatileDBEvent v) = forMachine details v + forMachine _details (ChainDB.TracePerasCertDbEvent _v) = + mempty -- TODO fill in + forMachine _details (ChainDB.TraceAddPerasCertEvent _v) = + mempty -- TODO fill in asMetrics ChainDB.TraceLastShutdownUnclean = [] asMetrics (ChainDB.TraceChainSelStarvationEvent _) = [] @@ -145,6 +151,9 @@ instance ( LogFormatting (Header blk) asMetrics (ChainDB.TraceLedgerDBEvent v) = asMetrics v asMetrics (ChainDB.TraceImmutableDBEvent v) = asMetrics v asMetrics (ChainDB.TraceVolatileDBEvent v) = asMetrics v + -- TODO defer to v + asMetrics (ChainDB.TracePerasCertDbEvent _v) = [] + asMetrics (ChainDB.TraceAddPerasCertEvent _v) = [] instance MetaTrace (ChainDB.TraceEvent blk) where @@ -172,6 +181,9 @@ instance MetaTrace (ChainDB.TraceEvent blk) where nsPrependInner "ImmDbEvent" (namespaceFor ev) namespaceFor (ChainDB.TraceVolatileDBEvent ev) = nsPrependInner "VolatileDbEvent" (namespaceFor ev) + -- TODO defer to ev + namespaceFor (ChainDB.TracePerasCertDbEvent _ev) = Namespace [] ["PerasCertDbEvent"] + namespaceFor (ChainDB.TraceAddPerasCertEvent _ev) = Namespace [] ["AddPerasCertEvent"] severityFor (Namespace _ ["LastShutdownUnclean"]) _ = Just Info severityFor (Namespace _ ["ChainSelStarvationEvent"]) _ = Just Debug @@ -392,7 +404,7 @@ instance MetaTrace (ChainDB.TraceEvent blk) where instance ( LogFormatting (Header blk) , LogFormatting (LedgerEvent blk) , LogFormatting (RealPoint blk) - , LogFormatting (SelectView (BlockProtocol blk)) + , LogFormatting (WeightedSelectView (BlockProtocol blk)) , ConvertRawHash blk , ConvertRawHash (Header blk) , LedgerSupportsProtocol blk @@ -486,10 +498,10 @@ instance ( LogFormatting (Header blk) in mconcat $ [ "kind" .= String "AddedToCurrentChain" , "newtip" .= renderPointForDetails DDetailed (AF.headPoint extended) - , "newTipSelectView" .= forMachine DDetailed (ChainDB.newTipSelectView selChangedInfo) + , "newSuffixSelectView" .= forMachine DDetailed (ChainDB.newSuffixSelectView selChangedInfo) ] - ++ [ "oldTipSelectView" .= forMachine DDetailed oldTipSelectView - | Just oldTipSelectView <- [ChainDB.oldTipSelectView selChangedInfo] + ++ [ "oldSuffixSelectView" .= forMachine DDetailed oldSuffixSelectView + | Just oldSuffixSelectView <- [ChainDB.oldSuffixSelectView selChangedInfo] ] ++ [ "headers" .= toJSON (forMachine DDetailed `map` addedHdrsNewChain base extended) ] @@ -502,10 +514,10 @@ instance ( LogFormatting (Header blk) mconcat $ [ "kind" .= String "AddedToCurrentChain" , "newtip" .= renderPointForDetails dtal (AF.headPoint extended) - , "newTipSelectView" .= forMachine dtal (ChainDB.newTipSelectView selChangedInfo) + , "newSuffixSelectView" .= forMachine dtal (ChainDB.newSuffixSelectView selChangedInfo) ] - ++ [ "oldTipSelectView" .= forMachine dtal oldTipSelectView - | Just oldTipSelectView <- [ChainDB.oldTipSelectView selChangedInfo] + ++ [ "oldSuffixSelectView" .= forMachine dtal oldSuffixSelectView + | Just oldSuffixSelectView <- [ChainDB.oldSuffixSelectView selChangedInfo] ] ++ [ "events" .= toJSON (map (forMachine dtal) events) | not (null events) ] @@ -521,10 +533,10 @@ instance ( LogFormatting (Header blk) in mconcat $ [ "kind" .= String "TraceAddBlockEvent.SwitchedToAFork" , "newtip" .= renderPointForDetails DDetailed (AF.headPoint new) - , "newTipSelectView" .= forMachine DDetailed (ChainDB.newTipSelectView selChangedInfo) + , "newSuffixSelectView" .= forMachine DDetailed (ChainDB.newSuffixSelectView selChangedInfo) ] - ++ [ "oldTipSelectView" .= forMachine DDetailed oldTipSelectView - | Just oldTipSelectView <- [ChainDB.oldTipSelectView selChangedInfo] + ++ [ "oldSuffixSelectView" .= forMachine DDetailed oldSuffixSelectView + | Just oldSuffixSelectView <- [ChainDB.oldSuffixSelectView selChangedInfo] ] ++ [ "headers" .= toJSON (forMachine DDetailed `map` addedHdrsNewChain old new) ] @@ -537,10 +549,10 @@ instance ( LogFormatting (Header blk) mconcat $ [ "kind" .= String "TraceAddBlockEvent.SwitchedToAFork" , "newtip" .= renderPointForDetails dtal (AF.headPoint new) - , "newTipSelectView" .= forMachine dtal (ChainDB.newTipSelectView selChangedInfo) + , "newSuffixSelectView" .= forMachine dtal (ChainDB.newSuffixSelectView selChangedInfo) ] - ++ [ "oldTipSelectView" .= forMachine dtal oldTipSelectView - | Just oldTipSelectView <- [ChainDB.oldTipSelectView selChangedInfo] + ++ [ "oldSuffixSelectView" .= forMachine dtal oldSuffixSelectView + | Just oldSuffixSelectView <- [ChainDB.oldSuffixSelectView selChangedInfo] ] ++ [ "events" .= toJSON (map (forMachine dtal) events) | not (null events) ] diff --git a/cardano-node/src/Cardano/Node/Tracing/Tracers/Startup.hs b/cardano-node/src/Cardano/Node/Tracing/Tracers/Startup.hs index 21050bb0ed6..a88ea612469 100644 --- a/cardano-node/src/Cardano/Node/Tracing/Tracers/Startup.hs +++ b/cardano-node/src/Cardano/Node/Tracing/Tracers/Startup.hs @@ -475,6 +475,8 @@ nodeToClientVersionToInt = \case nodeToNodeVersionToInt :: NodeToNodeVersion -> Int nodeToNodeVersionToInt = \case NodeToNodeV_14 -> 14 + NodeToNodeV_15 -> 15 + NodeToNodeV_16 -> 16 -- | Pretty print 'StartupInfoTrace' -- diff --git a/cardano-node/src/Cardano/Tracing/OrphanInstances/Consensus.hs b/cardano-node/src/Cardano/Tracing/OrphanInstances/Consensus.hs index 2d0ff97d437..29a9944b72e 100644 --- a/cardano-node/src/Cardano/Tracing/OrphanInstances/Consensus.hs +++ b/cardano-node/src/Cardano/Tracing/OrphanInstances/Consensus.hs @@ -58,6 +58,7 @@ import Ouroboros.Consensus.Node.GSM import Ouroboros.Consensus.Node.Run (RunNode, estimateBlockSize) import Ouroboros.Consensus.Node.Tracers (TraceForgeEvent (..)) import qualified Ouroboros.Consensus.Node.Tracers as Consensus +import Ouroboros.Consensus.Peras.SelectView import Ouroboros.Consensus.Protocol.Abstract import qualified Ouroboros.Consensus.Protocol.BFT as BFT import qualified Ouroboros.Consensus.Protocol.PBFT as PBFT @@ -517,7 +518,7 @@ instance ( ConvertRawHash blk , InspectLedger blk , ToObject (Header blk) , ToObject (LedgerEvent blk) - , ToObject (SelectView (BlockProtocol blk))) + , ToObject (WeightedSelectView (BlockProtocol blk))) => Transformable Text IO (ChainDB.TraceEvent blk) where trTransformer = trStructuredText @@ -922,7 +923,7 @@ instance ( ConvertRawHash blk , LedgerSupportsProtocol blk , ToObject (Header blk) , ToObject (LedgerEvent blk) - , ToObject (SelectView (BlockProtocol blk))) + , ToObject (WeightedSelectView (BlockProtocol blk))) => ToObject (ChainDB.TraceEvent blk) where toObject _verb ChainDB.TraceLastShutdownUnclean = mconcat [ "kind" .= String "TraceLastShutdownUnclean" ] @@ -963,10 +964,10 @@ instance ( ConvertRawHash blk [ "kind" .= String "TraceAddBlockEvent.AddedToCurrentChain" , "newtip" .= renderPointForVerbosity verb (AF.headPoint extended) , "chainLengthDelta" .= extended `chainLengthΔ` base - , "newTipSelectView" .= toObject verb (ChainDB.newTipSelectView selChangedInfo) + , "newSuffixSelectView" .= toObject verb (ChainDB.newSuffixSelectView selChangedInfo) ] - ++ [ "oldTipSelectView" .= toObject verb oldTipSelectView - | Just oldTipSelectView <- [ChainDB.oldTipSelectView selChangedInfo] + ++ [ "oldSuffixSelectView" .= toObject verb oldSuffixSelectView + | Just oldSuffixSelectView <- [ChainDB.oldSuffixSelectView selChangedInfo] ] ++ [ "headers" .= toJSON (toObject verb `map` addedHdrsNewChain base extended) | verb == MaximalVerbosity ] @@ -979,10 +980,10 @@ instance ( ConvertRawHash blk , "chainLengthDelta" .= new `chainLengthΔ` old -- Check that the SwitchedToAFork event was triggered by a proper fork. , "realFork" .= not (AF.withinFragmentBounds (AF.headPoint old) new) - , "newTipSelectView" .= toObject verb (ChainDB.newTipSelectView selChangedInfo) + , "newSuffixSelectView" .= toObject verb (ChainDB.newSuffixSelectView selChangedInfo) ] - ++ [ "oldTipSelectView" .= toObject verb oldTipSelectView - | Just oldTipSelectView <- [ChainDB.oldTipSelectView selChangedInfo] + ++ [ "oldSuffixSelectView" .= toObject verb oldSuffixSelectView + | Just oldSuffixSelectView <- [ChainDB.oldSuffixSelectView selChangedInfo] ] ++ [ "headers" .= toJSON (toObject verb `map` addedHdrsNewChain old new) | verb == MaximalVerbosity ] diff --git a/cardano-node/src/Cardano/Tracing/OrphanInstances/HardFork.hs b/cardano-node/src/Cardano/Tracing/OrphanInstances/HardFork.hs index 105ccf2faec..3296fec8ac4 100644 --- a/cardano-node/src/Cardano/Tracing/OrphanInstances/HardFork.hs +++ b/cardano-node/src/Cardano/Tracing/OrphanInstances/HardFork.hs @@ -22,7 +22,7 @@ import Cardano.Slotting.Slot (EpochSize (..)) import Cardano.Tracing.OrphanInstances.Common import Cardano.Tracing.OrphanInstances.Consensus () import Ouroboros.Consensus.Block (BlockProtocol, CannotForge, ForgeStateInfo, - ForgeStateUpdateError) + ForgeStateUpdateError, PerasWeight (..)) import Ouroboros.Consensus.BlockchainTime (getSlotLength) import Ouroboros.Consensus.Cardano.Condense () import Ouroboros.Consensus.HardFork.Combinator @@ -42,8 +42,9 @@ import Ouroboros.Consensus.Ledger.Inspect (LedgerUpdate, LedgerWarning import Ouroboros.Consensus.Ledger.SupportsMempool (ApplyTxErr) import Ouroboros.Consensus.Node.NetworkProtocolVersion (BlockNodeToClientVersion, BlockNodeToNodeVersion) +import Ouroboros.Consensus.Peras.SelectView import Ouroboros.Consensus.Protocol.Abstract (ConsensusProtocol (TiebreakerView), - SelectView (svBlockNo, svTiebreakerView), ValidationErr) + ValidationErr) import Ouroboros.Consensus.TypeFamilyWrappers import Ouroboros.Consensus.Util.Condense (Condense (..)) @@ -434,10 +435,11 @@ instance (ToJSON (BlockNodeToNodeVersion blk)) => ToJSON (WrapNodeToNodeVersion instance All (ToObject `Compose` WrapTiebreakerView) xs => ToObject (HardForkTiebreakerView xs) where toObject verb = toObject verb . getHardForkTiebreakerView -instance ToObject (TiebreakerView protocol) => ToObject (SelectView protocol) where +instance ToObject (TiebreakerView protocol) => ToObject (WeightedSelectView protocol) where toObject verb sv = mconcat - [ "blockNo" .= svBlockNo sv - , toObject verb (svTiebreakerView sv) + [ "length" .= wsvLength sv + , "weightBoost" .= unPerasWeight (wsvWeightBoost sv) + , toObject verb (wsvTiebreaker sv) ] instance All (ToObject `Compose` WrapTiebreakerView) xs => ToObject (OneEraTiebreakerView xs) where diff --git a/cardano-node/src/Cardano/Tracing/OrphanInstances/Network.hs b/cardano-node/src/Cardano/Tracing/OrphanInstances/Network.hs index 5e3398c9174..f654e09a37b 100644 --- a/cardano-node/src/Cardano/Tracing/OrphanInstances/Network.hs +++ b/cardano-node/src/Cardano/Tracing/OrphanInstances/Network.hs @@ -27,20 +27,20 @@ module Cardano.Tracing.OrphanInstances.Network , FetchDecisionToJSON (..) ) where +import Cardano.Network.PeerSelection.Bootstrap (UseBootstrapPeers (..)) +import Cardano.Network.PeerSelection.PeerTrustable (PeerTrustable (..)) +import Cardano.Network.Types (LedgerStateJudgement (..)) import Cardano.Node.Queries (ConvertTxId) import Cardano.Tracing.OrphanInstances.Common import Cardano.Tracing.Render +import qualified Ouroboros.Cardano.Network.PeerSelection.Governor.PeerSelectionState as Cardano +import qualified Ouroboros.Cardano.Network.PeerSelection.Governor.Types as Cardano +import qualified Ouroboros.Cardano.Network.PublicRootPeers as Cardano.PublicRootPeers import Ouroboros.Consensus.Block (ConvertRawHash (..), Header, getHeader) import Ouroboros.Consensus.Ledger.Query (BlockQuery, Query) import Ouroboros.Consensus.Ledger.SupportsMempool (ApplyTxErr, GenTx, GenTxId, HasTxs (..), TxId, txId) import Ouroboros.Consensus.Node.Run (RunNode, estimateBlockSize) -import Cardano.Network.PeerSelection.Bootstrap (UseBootstrapPeers(..)) -import Cardano.Network.PeerSelection.PeerTrustable (PeerTrustable(..)) -import Cardano.Network.Types (LedgerStateJudgement(..)) -import qualified Ouroboros.Cardano.Network.PeerSelection.Governor.PeerSelectionState as Cardano -import qualified Ouroboros.Cardano.Network.PeerSelection.Governor.Types as Cardano -import qualified Ouroboros.Cardano.Network.PublicRootPeers as Cardano.PublicRootPeers import qualified Ouroboros.Network.AnchoredFragment as AF import qualified Ouroboros.Network.AnchoredSeq as AS import Ouroboros.Network.Block @@ -51,15 +51,14 @@ import Ouroboros.Network.BlockFetch.Decision (FetchDecision, FetchDecl import qualified Ouroboros.Network.BlockFetch.Decision.Trace as BlockFetch import Ouroboros.Network.ConnectionHandler (ConnectionHandlerTrace (..)) import Ouroboros.Network.ConnectionId (ConnectionId (..)) -import Ouroboros.Network.ConnectionManager.Core as ConnMgr (Trace (..)) import Ouroboros.Network.ConnectionManager.ConnMap (ConnMap (..), LocalAddr (..)) +import Ouroboros.Network.ConnectionManager.Core as ConnMgr (Trace (..)) import Ouroboros.Network.ConnectionManager.State (ConnStateId (..)) import Ouroboros.Network.ConnectionManager.Types (AbstractState (..), - ConnectionManagerCounters (..), - OperationResult (..)) + ConnectionManagerCounters (..), OperationResult (..)) import qualified Ouroboros.Network.ConnectionManager.Types as ConnMgr -import qualified Ouroboros.Network.Diffusion.Common as Diffusion import Ouroboros.Network.DeltaQ (GSV (..), PeerGSV (..)) +import qualified Ouroboros.Network.Diffusion.Common as Diffusion import Ouroboros.Network.Driver.Limits (ProtocolLimitFailure (..)) import qualified Ouroboros.Network.Driver.Stateful as Stateful import Ouroboros.Network.ExitPolicy (RepromoteDelay (..)) @@ -73,10 +72,10 @@ import qualified Ouroboros.Network.NodeToClient as NtC import Ouroboros.Network.NodeToNode (ErrorPolicyTrace (..), NodeToNodeVersion (..), NodeToNodeVersionData (..), RemoteAddress, TraceSendRecv (..), WithAddr (..)) import qualified Ouroboros.Network.NodeToNode as NtN -import Ouroboros.Network.PeerSelection.Governor (AssociationMode (..), DebugPeerSelection (..), - DebugPeerSelectionState (..), PeerSelectionCounters, PeerSelectionState (..), - PeerSelectionTargets (..), PeerSelectionView (..), TracePeerSelection (..), - peerSelectionStateToCounters) +import Ouroboros.Network.PeerSelection.Governor (AssociationMode (..), + DebugPeerSelection (..), DebugPeerSelectionState (..), PeerSelectionCounters, + PeerSelectionState (..), PeerSelectionTargets (..), PeerSelectionView (..), + TracePeerSelection (..), peerSelectionStateToCounters) import Ouroboros.Network.PeerSelection.LedgerPeers import Ouroboros.Network.PeerSelection.PeerSharing (PeerSharing (..)) import Ouroboros.Network.PeerSelection.PeerStateActions (PeerSelectionActionsTrace (..)) @@ -89,7 +88,7 @@ import Ouroboros.Network.PeerSelection.RootPeersDNS.PublicRootPeers import Ouroboros.Network.PeerSelection.State.KnownPeers (KnownPeerInfo (..)) import qualified Ouroboros.Network.PeerSelection.State.KnownPeers as KnownPeers import Ouroboros.Network.PeerSelection.State.LocalRootPeers (HotValency (..), - LocalRootPeers, WarmValency (..), LocalRootConfig (..)) + LocalRootConfig (..), LocalRootPeers, WarmValency (..)) import qualified Ouroboros.Network.PeerSelection.State.LocalRootPeers as LocalRootPeers import Ouroboros.Network.PeerSelection.Types (PeerStatus (..)) import Ouroboros.Network.Protocol.BlockFetch.Type (BlockFetch, Message (..)) @@ -2376,6 +2375,8 @@ instance Show vNumber => ToJSON (HandshakeException vNumber) where instance ToJSON NodeToNodeVersion where toJSON NodeToNodeV_14 = Number 14 + toJSON NodeToNodeV_15 = Number 15 + toJSON NodeToNodeV_16 = Number 16 instance FromJSON NodeToNodeVersion where parseJSON (Number 14) = return NodeToNodeV_14 diff --git a/cardano-node/src/Cardano/Tracing/Tracers.hs b/cardano-node/src/Cardano/Tracing/Tracers.hs index 0c4ddf9e80f..41b81715cc8 100644 --- a/cardano-node/src/Cardano/Tracing/Tracers.hs +++ b/cardano-node/src/Cardano/Tracing/Tracers.hs @@ -86,7 +86,8 @@ import qualified Ouroboros.Consensus.Network.NodeToNode as NodeToNode import Ouroboros.Consensus.Node (NetworkP2PMode (..)) import qualified Ouroboros.Consensus.Node.Run as Consensus (RunNode) import qualified Ouroboros.Consensus.Node.Tracers as Consensus -import Ouroboros.Consensus.Protocol.Abstract (SelectView, ValidationErr) +import Ouroboros.Consensus.Peras.SelectView +import Ouroboros.Consensus.Protocol.Abstract (ValidationErr) import qualified Ouroboros.Consensus.Protocol.Ledger.HotKey as HotKey import qualified Ouroboros.Consensus.Storage.ChainDB as ChainDB import qualified Ouroboros.Consensus.Storage.LedgerDB as LedgerDB @@ -554,6 +555,8 @@ mkTracers _ _ _ _ _ enableP2P = , Consensus.gsmTracer = nullTracer , Consensus.csjTracer = nullTracer , Consensus.dbfTracer = nullTracer + , Consensus.perasCertDiffusionInboundTracer = nullTracer + , Consensus.perasCertDiffusionOutboundTracer = nullTracer } , nodeToClientTracers = NodeToClient.Tracers { NodeToClient.tChainSyncTracer = nullTracer @@ -569,6 +572,7 @@ mkTracers _ _ _ _ _ enableP2P = , NodeToNode.tTxSubmission2Tracer = nullTracer , NodeToNode.tKeepAliveTracer = nullTracer , NodeToNode.tPeerSharingTracer = nullTracer + , NodeToNode.tPerasCertDiffusionTracer = nullTracer } , diffusionTracers = Diffusion.nullTracers , diffusionTracersExtra = @@ -597,7 +601,7 @@ teeTraceChainTip , InspectLedger blk , ToObject (Header blk) , ToObject (LedgerEvent blk) - , ToObject (SelectView (BlockProtocol blk)) + , ToObject (WeightedSelectView (BlockProtocol blk)) ) => BlockConfig blk -> ForgingStats @@ -621,7 +625,7 @@ teeTraceChainTipElide , InspectLedger blk , ToObject (Header blk) , ToObject (LedgerEvent blk) - , ToObject (SelectView (BlockProtocol blk)) + , ToObject (WeightedSelectView (BlockProtocol blk)) ) => TracingVerbosity -> MVar (Maybe (WithSeverity (ChainDB.TraceEvent blk)), Integer) @@ -860,6 +864,9 @@ mkConsensusTracers mbEKGDirect trSel verb tr nodeKern fStats = do , Consensus.gsmTracer = tracerOnOff (traceGsm trSel) verb "GSM" tr , Consensus.csjTracer = tracerOnOff (traceCsj trSel) verb "CSJ" tr , Consensus.dbfTracer = tracerOnOff (traceDevotedBlockFetch trSel) verb "DevotedBlockFetch" tr + -- TODO plug in + , Consensus.perasCertDiffusionInboundTracer = Tracer $ \_ -> pure () + , Consensus.perasCertDiffusionOutboundTracer = Tracer $ \_ -> pure () } where mkForgeTracers :: IO ForgeTracers @@ -1511,6 +1518,8 @@ nodeToNodeTracers' trSel verb tr = , NodeToNode.tPeerSharingTracer = tracerOnOff (tracePeerSharingProtocol trSel) verb "PeerSharingPrototocol" tr + -- TODO plug in + , NodeToNode.tPerasCertDiffusionTracer = Tracer $ \_ -> pure () } -- TODO @ouroboros-network From 4469a9385096511699d734d4701ef1f12b9fe5eb Mon Sep 17 00:00:00 2001 From: Thomas BAGREL Date: Fri, 26 Sep 2025 14:40:39 +0200 Subject: [PATCH 4/4] Add remaining logging stuff for Peras --- .../src/Cardano/Node/Tracing/Documentation.hs | 21 ++ .../src/Cardano/Node/Tracing/Tracers.hs | 24 +- .../Cardano/Node/Tracing/Tracers/ChainDB.hs | 239 ++++++++++++++- .../Cardano/Node/Tracing/Tracers/Consensus.hs | 278 ++++++++++++++++++ cardano-node/src/Cardano/Tracing/Config.hs | 30 ++ .../Tracing/OrphanInstances/Consensus.hs | 106 +++++++ .../Tracing/OrphanInstances/Network.hs | 34 +++ cardano-node/src/Cardano/Tracing/Tracers.hs | 10 +- 8 files changed, 721 insertions(+), 21 deletions(-) diff --git a/cardano-node/src/Cardano/Node/Tracing/Documentation.hs b/cardano-node/src/Cardano/Node/Tracing/Documentation.hs index 8a751708cb5..f3259ce48f7 100644 --- a/cardano-node/src/Cardano/Node/Tracing/Documentation.hs +++ b/cardano-node/src/Cardano/Node/Tracing/Documentation.hs @@ -117,6 +117,7 @@ import qualified Network.Mux as Mux import qualified Network.Socket as Socket import qualified Options.Applicative as Opt import System.IO +import qualified Ouroboros.Consensus.MiniProtocol.ObjectDiffusion.PerasCert as Consensus data TraceDocumentationCmd @@ -371,6 +372,24 @@ docTracersFirstPhase condConfigFileName = do mempoolTrDoc <- documentTracer (mempoolTr :: Logging.Trace IO (TraceEventMempool blk)) + perasCertDiffusionInboundTr <- mkCardanoTracer + trBase trForward mbTrEKG + ["Peras", "CertDiffusion", "Inbound"] + configureTracers configReflection trConfig [perasCertDiffusionInboundTr] + perasCertDiffusionInboundTrDoc <- documentTracer (perasCertDiffusionInboundTr :: + Logging.Trace IO (BlockFetch.TraceLabelPeer + remotePeer + (Consensus.TracePerasCertDiffusionInbound blk))) + + perasCertDiffusionOutboundTracer <- mkCardanoTracer + trBase trForward mbTrEKG + ["Peras", "CertDiffusion", "Outbound"] + configureTracers configReflection trConfig [perasCertDiffusionOutboundTracer] + perasCertDiffusionOutboundTrDoc <- documentTracer (perasCertDiffusionOutboundTracer :: + Logging.Trace IO (BlockFetch.TraceLabelPeer + remotePeer + (Consensus.TracePerasCertDiffusionOutbound blk))) + forgeTr <- mkCardanoTracer trBase trForward mbTrEKG ["Forge", "Loop"] @@ -778,6 +797,8 @@ docTracersFirstPhase condConfigFileName = do <> txOutboundTrDoc <> localTxSubmissionServerTrDoc <> mempoolTrDoc + <> perasCertDiffusionInboundTrDoc + <> perasCertDiffusionOutboundTrDoc <> forgeTrDoc <> forgeStatsTrDoc <> blockchainTimeTrDoc diff --git a/cardano-node/src/Cardano/Node/Tracing/Tracers.hs b/cardano-node/src/Cardano/Node/Tracing/Tracers.hs index 36b9968aa44..20a1f1ac46b 100644 --- a/cardano-node/src/Cardano/Node/Tracing/Tracers.hs +++ b/cardano-node/src/Cardano/Node/Tracing/Tracers.hs @@ -316,6 +316,16 @@ mkConsensusTracers configReflection trBase trForward mbTrEKG _trDataPoint trConf ["Mempool"] configureTracers configReflection trConfig [mempoolTr] + !perasCertDiffusionInboundTr <- mkCardanoTracer + trBase trForward mbTrEKG + ["Peras", "CertDiffusion", "Inbound"] + configureTracers configReflection trConfig [perasCertDiffusionInboundTr] + + !perasCertDiffusionOutboundTr <- mkCardanoTracer + trBase trForward mbTrEKG + ["Peras", "CertDiffusion", "Outbound"] + configureTracers configReflection trConfig [perasCertDiffusionOutboundTr] + !forgeTr <- mkCardanoTracer trBase trForward mbTrEKG ["Forge", "Loop"] @@ -408,9 +418,8 @@ mkConsensusTracers configReflection trBase trForward mbTrEKG _trDataPoint trConf traceWith consensusCsjTr , Consensus.dbfTracer = Tracer $ traceWith consensusDbfTr - -- TODO plug these in - , Consensus.perasCertDiffusionInboundTracer = Tracer $ \_ -> pure () - , Consensus.perasCertDiffusionOutboundTracer = Tracer $ \_ -> pure () + , Consensus.perasCertDiffusionInboundTracer = Tracer $ traceWith perasCertDiffusionInboundTr + , Consensus.perasCertDiffusionOutboundTracer = Tracer $ traceWith perasCertDiffusionOutboundTr } mkNodeToClientTracers :: forall blk. @@ -495,6 +504,11 @@ mkNodeToNodeTracers configReflection trBase trForward mbTrEKG _trDataPoint trCon ["TxSubmission", "Remote"] configureTracers configReflection trConfig [txSubmission2Tracer] + !perasCertDiffusionTracer <- mkCardanoTracer + trBase trForward mbTrEKG + ["Peras", "CertDiffusion", "Remote"] + configureTracers configReflection trConfig [perasCertDiffusionTracer] + !keepAliveTracer <- mkCardanoTracer trBase trForward mbTrEKG ["KeepAlive", "Remote"] @@ -520,8 +534,8 @@ mkNodeToNodeTracers configReflection trBase trForward mbTrEKG _trDataPoint trCon traceWith keepAliveTracer , NtN.tPeerSharingTracer = Tracer $ traceWith peerSharingTracer - -- TODO plug in - , NtN.tPerasCertDiffusionTracer = Tracer $ \_ -> pure () + , NtN.tPerasCertDiffusionTracer = Tracer $ + traceWith perasCertDiffusionTracer } mkDiffusionTracers diff --git a/cardano-node/src/Cardano/Node/Tracing/Tracers/ChainDB.hs b/cardano-node/src/Cardano/Node/Tracing/Tracers/ChainDB.hs index 97cdc2f6233..c435225d7bb 100644 --- a/cardano-node/src/Cardano/Node/Tracing/Tracers/ChainDB.hs +++ b/cardano-node/src/Cardano/Node/Tracing/Tracers/ChainDB.hs @@ -39,6 +39,7 @@ import qualified Ouroboros.Consensus.Storage.LedgerDB as LedgerDB import qualified Ouroboros.Consensus.Storage.LedgerDB.Snapshots as LedgerDB import qualified Ouroboros.Consensus.Storage.LedgerDB.V1.BackingStore as V1 import qualified Ouroboros.Consensus.Storage.LedgerDB.V2.Args as V2 +import qualified Ouroboros.Consensus.Storage.PerasCertDB.Impl as PerasCertDB import qualified Ouroboros.Consensus.Storage.VolatileDB as VolDB import Ouroboros.Consensus.Util.Condense (condense) import Ouroboros.Consensus.Util.Enclose @@ -104,7 +105,8 @@ instance ( LogFormatting (Header blk) "Chain Selection was starved." ChainDB.ChainSelStarvation (FallingEdgeWith pt) -> "Chain Selection was unstarved by " <> renderRealPoint pt - forHuman _ = "TODO" + forHuman (ChainDB.TracePerasCertDbEvent ev) = forHuman ev + forHuman (ChainDB.TraceAddPerasCertEvent ev) = forHuman ev forMachine _ ChainDB.TraceLastShutdownUnclean = mconcat [ "kind" .= String "LastShutdownUnclean" ] @@ -134,10 +136,10 @@ instance ( LogFormatting (Header blk) forMachine details v forMachine details (ChainDB.TraceVolatileDBEvent v) = forMachine details v - forMachine _details (ChainDB.TracePerasCertDbEvent _v) = - mempty -- TODO fill in - forMachine _details (ChainDB.TraceAddPerasCertEvent _v) = - mempty -- TODO fill in + forMachine details (ChainDB.TracePerasCertDbEvent v) = + forMachine details v + forMachine details (ChainDB.TraceAddPerasCertEvent v) = + forMachine details v asMetrics ChainDB.TraceLastShutdownUnclean = [] asMetrics (ChainDB.TraceChainSelStarvationEvent _) = [] @@ -151,9 +153,8 @@ instance ( LogFormatting (Header blk) asMetrics (ChainDB.TraceLedgerDBEvent v) = asMetrics v asMetrics (ChainDB.TraceImmutableDBEvent v) = asMetrics v asMetrics (ChainDB.TraceVolatileDBEvent v) = asMetrics v - -- TODO defer to v - asMetrics (ChainDB.TracePerasCertDbEvent _v) = [] - asMetrics (ChainDB.TraceAddPerasCertEvent _v) = [] + asMetrics (ChainDB.TracePerasCertDbEvent v) = asMetrics v + asMetrics (ChainDB.TraceAddPerasCertEvent v) = asMetrics v instance MetaTrace (ChainDB.TraceEvent blk) where @@ -181,9 +182,10 @@ instance MetaTrace (ChainDB.TraceEvent blk) where nsPrependInner "ImmDbEvent" (namespaceFor ev) namespaceFor (ChainDB.TraceVolatileDBEvent ev) = nsPrependInner "VolatileDbEvent" (namespaceFor ev) - -- TODO defer to ev - namespaceFor (ChainDB.TracePerasCertDbEvent _ev) = Namespace [] ["PerasCertDbEvent"] - namespaceFor (ChainDB.TraceAddPerasCertEvent _ev) = Namespace [] ["AddPerasCertEvent"] + namespaceFor (ChainDB.TracePerasCertDbEvent ev) = + nsPrependInner "PerasCertDbEvent" (namespaceFor ev) + namespaceFor (ChainDB.TraceAddPerasCertEvent ev) = + nsPrependInner "AddPerasCertEvent" (namespaceFor ev) severityFor (Namespace _ ["LastShutdownUnclean"]) _ = Just Info severityFor (Namespace _ ["ChainSelStarvationEvent"]) _ = Just Debug @@ -227,6 +229,14 @@ instance MetaTrace (ChainDB.TraceEvent blk) where severityFor (Namespace out tl) (Just ev') severityFor (Namespace out ("VolatileDbEvent" : tl)) Nothing = severityFor (Namespace out tl :: Namespace (VolDB.TraceEvent blk)) Nothing + severityFor (Namespace out ("PerasCertDbEvent" : tl)) (Just (ChainDB.TracePerasCertDbEvent ev')) = + severityFor (Namespace out tl) (Just ev') + severityFor (Namespace out ("PerasCertDbEvent" : tl)) Nothing = + severityFor (Namespace out tl :: Namespace (PerasCertDB.TraceEvent blk)) Nothing + severityFor (Namespace out ("AddPerasCertEvent" : tl)) (Just (ChainDB.TraceAddPerasCertEvent ev')) = + severityFor (Namespace out tl) (Just ev') + severityFor (Namespace out ("AddPerasCertEvent" : tl)) Nothing = + severityFor (Namespace out tl :: Namespace (ChainDB.TraceAddPerasCertEvent blk)) Nothing severityFor _ns _ = Nothing privacyFor (Namespace _ ["LastShutdownUnclean"]) _ = Just Public @@ -271,6 +281,14 @@ instance MetaTrace (ChainDB.TraceEvent blk) where privacyFor (Namespace out tl) (Just ev') privacyFor (Namespace out ("VolatileDbEvent" : tl)) Nothing = privacyFor (Namespace out tl :: Namespace (VolDB.TraceEvent blk)) Nothing + privacyFor (Namespace out ("PerasCertDbEvent" : tl)) (Just (ChainDB.TracePerasCertDbEvent ev')) = + privacyFor (Namespace out tl) (Just ev') + privacyFor (Namespace out ("PerasCertDbEvent" : tl)) Nothing = + privacyFor (Namespace out tl :: Namespace (PerasCertDB.TraceEvent blk)) Nothing + privacyFor (Namespace out ("AddPerasCertEvent" : tl)) (Just (ChainDB.TraceAddPerasCertEvent ev')) = + privacyFor (Namespace out tl) (Just ev') + privacyFor (Namespace out ("AddPerasCertEvent" : tl)) Nothing = + privacyFor (Namespace out tl :: Namespace (ChainDB.TraceAddPerasCertEvent blk)) Nothing privacyFor _ _ = Nothing detailsFor (Namespace _ ["LastShutdownUnclean"]) _ = Just DNormal @@ -315,6 +333,14 @@ instance MetaTrace (ChainDB.TraceEvent blk) where detailsFor (Namespace out tl) (Just ev') detailsFor (Namespace out ("VolatileDbEvent" : tl)) Nothing = detailsFor (Namespace out tl :: (Namespace (VolDB.TraceEvent blk))) Nothing + detailsFor (Namespace out ("PerasCertDbEvent" : tl)) (Just (ChainDB.TracePerasCertDbEvent ev')) = + detailsFor (Namespace out tl) (Just ev') + detailsFor (Namespace out ("PerasCertDbEvent" : tl)) Nothing = + detailsFor (Namespace out tl :: Namespace (PerasCertDB.TraceEvent blk)) Nothing + detailsFor (Namespace out ("AddPerasCertEvent" : tl)) (Just (ChainDB.TraceAddPerasCertEvent ev')) = + detailsFor (Namespace out tl) (Just ev') + detailsFor (Namespace out ("AddPerasCertEvent" : tl)) Nothing = + detailsFor (Namespace out tl :: Namespace (ChainDB.TraceAddPerasCertEvent blk)) Nothing detailsFor _ _ = Nothing metricsDocFor (Namespace out ("AddBlockEvent" : tl)) = @@ -368,6 +394,10 @@ instance MetaTrace (ChainDB.TraceEvent blk) where documentFor (Namespace out tl :: Namespace (ImmDB.TraceEvent blk)) documentFor (Namespace out ("VolatileDbEvent" : tl)) = documentFor (Namespace out tl :: Namespace (VolDB.TraceEvent blk)) + documentFor (Namespace out ("PerasCertDbEvent" : tl)) = + documentFor (Namespace out tl :: Namespace (PerasCertDB.TraceEvent blk)) + documentFor (Namespace out ("AddPerasCertEvent" : tl)) = + documentFor (Namespace out tl :: Namespace (ChainDB.TraceAddPerasCertEvent blk)) documentFor _ = Nothing allNamespaces = @@ -393,6 +423,10 @@ instance MetaTrace (ChainDB.TraceEvent blk) where (allNamespaces :: [Namespace (ImmDB.TraceEvent blk)]) ++ map (nsPrependInner "VolatileDbEvent") (allNamespaces :: [Namespace (VolDB.TraceEvent blk)]) + ++ map (nsPrependInner "PerasCertDbEvent") + (allNamespaces :: [Namespace (PerasCertDB.TraceEvent blk)]) + ++ map (nsPrependInner "AddPerasCertEvent") + (allNamespaces :: [Namespace (ChainDB.TraceAddPerasCertEvent blk)]) ) @@ -2887,3 +2921,186 @@ instance (Show (PBFT.PBftVerKeyHash c)) [ "kind" .= String "PBftCannotForgeThresholdExceeded" , "numForged" .= numForged ] + +-- PerasCertDB.TraceEvent instances +instance LogFormatting (PerasCertDB.TraceEvent blk) where + forHuman (PerasCertDB.AddedPerasCert _cert _peer) = "Added Peras certificate to database" + forHuman (PerasCertDB.IgnoredCertAlreadyInDB _cert _peer) = "Ignored Peras certificate already in database" + forHuman PerasCertDB.OpenedPerasCertDB = "Opened Peras certificate database" + forHuman PerasCertDB.ClosedPerasCertDB = "Closed Peras certificate database" + forHuman (PerasCertDB.AddingPerasCert _cert _peer) = "Adding Peras certificate to database" + + forMachine _dtal (PerasCertDB.AddedPerasCert cert _peer) = + mconcat ["kind" .= String "AddedPerasCert", + "cert" .= String (Text.pack $ show cert)] + forMachine _dtal (PerasCertDB.IgnoredCertAlreadyInDB cert _peer) = + mconcat ["kind" .= String "IgnoredCertAlreadyInDB", + "cert" .= String (Text.pack $ show cert)] + forMachine _dtal PerasCertDB.OpenedPerasCertDB = + mconcat ["kind" .= String "OpenedPerasCertDB"] + forMachine _dtal PerasCertDB.ClosedPerasCertDB = + mconcat ["kind" .= String "ClosedPerasCertDB"] + forMachine _dtal (PerasCertDB.AddingPerasCert cert _peer) = + mconcat ["kind" .= String "AddingPerasCert", + "cert" .= String (Text.pack $ show cert)] + + asMetrics _ = [] + +-- ChainDB.TraceAddPerasCertEvent instances +instance ConvertRawHash blk => LogFormatting (ChainDB.TraceAddPerasCertEvent blk) where + forHuman (ChainDB.AddedPerasCertToQueue roundNo boostedBlock _queueSize) = + "Added Peras certificate for round " <> Text.pack (show roundNo) <> + " boosting block " <> renderPoint boostedBlock <> " to queue" + forHuman (ChainDB.PoppedPerasCertFromQueue roundNo boostedBlock) = + "Popped Peras certificate for round " <> Text.pack (show roundNo) <> + " boosting block " <> renderPoint boostedBlock <> " from queue" + forHuman (ChainDB.IgnorePerasCertTooOld roundNo boostedBlock immutableSlot) = + "Ignored Peras certificate for round " <> Text.pack (show roundNo) <> + " boosting block " <> renderPoint boostedBlock <> + " (too old, immutable slot: " <> renderPoint immutableSlot <> ")" + forHuman (ChainDB.PerasCertBoostsCurrentChain roundNo boostedBlock) = + "Peras certificate for round " <> Text.pack (show roundNo) <> + " boosts current chain block " <> renderPoint boostedBlock + forHuman (ChainDB.PerasCertBoostsGenesis roundNo) = + "Peras certificate for round " <> Text.pack (show roundNo) <> " boosts Genesis" + forHuman (ChainDB.PerasCertBoostsBlockNotYetReceived roundNo boostedBlock) = + "Peras certificate for round " <> Text.pack (show roundNo) <> + " boosts block " <> renderPoint boostedBlock <> " not yet received" + forHuman (ChainDB.ChainSelectionForBoostedBlock roundNo boostedBlock) = + "Chain selection for block " <> renderPoint boostedBlock <> + " boosted by Peras certificate from round " <> Text.pack (show roundNo) + + forMachine _dtal (ChainDB.AddedPerasCertToQueue roundNo boostedBlock queueSize) = + mconcat ["kind" .= String "AddedPerasCertToQueue", + "round" .= String (Text.pack $ show roundNo), + "boostedBlock" .= String (renderPoint boostedBlock), + "queueSize" .= toJSON queueSize] + forMachine _dtal (ChainDB.PoppedPerasCertFromQueue roundNo boostedBlock) = + mconcat ["kind" .= String "PoppedPerasCertFromQueue", + "round" .= String (Text.pack $ show roundNo), + "boostedBlock" .= String (renderPoint boostedBlock)] + forMachine _dtal (ChainDB.IgnorePerasCertTooOld roundNo boostedBlock immutableSlot) = + mconcat ["kind" .= String "IgnorePerasCertTooOld", + "round" .= String (Text.pack $ show roundNo), + "boostedBlock" .= String (renderPoint boostedBlock), + "immutableSlot" .= String (renderPoint immutableSlot)] + forMachine _dtal (ChainDB.PerasCertBoostsCurrentChain roundNo boostedBlock) = + mconcat ["kind" .= String "PerasCertBoostsCurrentChain", + "round" .= String (Text.pack $ show roundNo), + "boostedBlock" .= String (renderPoint boostedBlock)] + forMachine _dtal (ChainDB.PerasCertBoostsGenesis roundNo) = + mconcat ["kind" .= String "PerasCertBoostsGenesis", + "round" .= String (Text.pack $ show roundNo)] + forMachine _dtal (ChainDB.PerasCertBoostsBlockNotYetReceived roundNo boostedBlock) = + mconcat ["kind" .= String "PerasCertBoostsBlockNotYetReceived", + "round" .= String (Text.pack $ show roundNo), + "boostedBlock" .= String (renderPoint boostedBlock)] + forMachine _dtal (ChainDB.ChainSelectionForBoostedBlock roundNo boostedBlock) = + mconcat ["kind" .= String "ChainSelectionForBoostedBlock", + "round" .= String (Text.pack $ show roundNo), + "boostedBlock" .= String (renderPoint boostedBlock)] + + asMetrics _ = [] + +-- PerasCertDB.TraceEvent MetaTrace instance +instance MetaTrace (PerasCertDB.TraceEvent blk) where + namespaceFor (PerasCertDB.AddedPerasCert _ _) = + Namespace [] ["AddedPerasCert"] + namespaceFor (PerasCertDB.IgnoredCertAlreadyInDB _ _) = + Namespace [] ["IgnoredCertAlreadyInDB"] + namespaceFor PerasCertDB.OpenedPerasCertDB = + Namespace [] ["OpenedPerasCertDB"] + namespaceFor PerasCertDB.ClosedPerasCertDB = + Namespace [] ["ClosedPerasCertDB"] + namespaceFor (PerasCertDB.AddingPerasCert _ _) = + Namespace [] ["AddingPerasCert"] + + severityFor (Namespace _ ["AddedPerasCert"]) _ = Just Info + severityFor (Namespace _ ["IgnoredCertAlreadyInDB"]) _ = Just Info + severityFor (Namespace _ ["OpenedPerasCertDB"]) _ = Just Info + severityFor (Namespace _ ["ClosedPerasCertDB"]) _ = Just Info + severityFor (Namespace _ ["AddingPerasCert"]) _ = Just Debug + severityFor _ _ = Nothing + + privacyFor (Namespace _ ["AddedPerasCert"]) _ = Just Public + privacyFor (Namespace _ ["IgnoredCertAlreadyInDB"]) _ = Just Public + privacyFor (Namespace _ ["OpenedPerasCertDB"]) _ = Just Public + privacyFor (Namespace _ ["ClosedPerasCertDB"]) _ = Just Public + privacyFor (Namespace _ ["AddingPerasCert"]) _ = Just Public + privacyFor _ _ = Nothing + + detailsFor (Namespace _ ["AddedPerasCert"]) _ = Just DNormal + detailsFor (Namespace _ ["IgnoredCertAlreadyInDB"]) _ = Just DNormal + detailsFor (Namespace _ ["OpenedPerasCertDB"]) _ = Just DNormal + detailsFor (Namespace _ ["ClosedPerasCertDB"]) _ = Just DNormal + detailsFor (Namespace _ ["AddingPerasCert"]) _ = Just DDetailed + detailsFor _ _ = Nothing + + documentFor (Namespace _ ["AddedPerasCert"]) = Just "Certificate added to Peras certificate database" + documentFor (Namespace _ ["IgnoredCertAlreadyInDB"]) = Just "Certificate ignored as it was already in the database" + documentFor (Namespace _ ["OpenedPerasCertDB"]) = Just "Peras certificate database opened" + documentFor (Namespace _ ["ClosedPerasCertDB"]) = Just "Peras certificate database closed" + documentFor (Namespace _ ["AddingPerasCert"]) = Just "Adding certificate to Peras certificate database" + documentFor _ = Nothing + + allNamespaces = + [Namespace [] ["AddedPerasCert"], + Namespace [] ["IgnoredCertAlreadyInDB"], + Namespace [] ["OpenedPerasCertDB"], + Namespace [] ["ClosedPerasCertDB"], + Namespace [] ["AddingPerasCert"]] + +-- ChainDB.TraceAddPerasCertEvent MetaTrace instance +instance MetaTrace (ChainDB.TraceAddPerasCertEvent blk) where + namespaceFor (ChainDB.AddedPerasCertToQueue _ _ _) = Namespace [] ["AddedPerasCertToQueue"] + namespaceFor (ChainDB.PoppedPerasCertFromQueue _ _) = Namespace [] ["PoppedPerasCertFromQueue"] + namespaceFor (ChainDB.IgnorePerasCertTooOld _ _ _) = Namespace [] ["IgnorePerasCertTooOld"] + namespaceFor (ChainDB.PerasCertBoostsCurrentChain _ _) = Namespace [] ["PerasCertBoostsCurrentChain"] + namespaceFor (ChainDB.PerasCertBoostsGenesis _) = Namespace [] ["PerasCertBoostsGenesis"] + namespaceFor (ChainDB.PerasCertBoostsBlockNotYetReceived _ _) = Namespace [] ["PerasCertBoostsBlockNotYetReceived"] + namespaceFor (ChainDB.ChainSelectionForBoostedBlock _ _) = Namespace [] ["ChainSelectionForBoostedBlock"] + + severityFor (Namespace _ ["AddedPerasCertToQueue"]) _ = Just Debug + severityFor (Namespace _ ["PoppedPerasCertFromQueue"]) _ = Just Debug + severityFor (Namespace _ ["IgnorePerasCertTooOld"]) _ = Just Info + severityFor (Namespace _ ["PerasCertBoostsCurrentChain"]) _ = Just Info + severityFor (Namespace _ ["PerasCertBoostsGenesis"]) _ = Just Info + severityFor (Namespace _ ["PerasCertBoostsBlockNotYetReceived"]) _ = Just Info + severityFor (Namespace _ ["ChainSelectionForBoostedBlock"]) _ = Just Info + severityFor _ _ = Nothing + + privacyFor (Namespace _ ["AddedPerasCertToQueue"]) _ = Just Public + privacyFor (Namespace _ ["PoppedPerasCertFromQueue"]) _ = Just Public + privacyFor (Namespace _ ["IgnorePerasCertTooOld"]) _ = Just Public + privacyFor (Namespace _ ["PerasCertBoostsCurrentChain"]) _ = Just Public + privacyFor (Namespace _ ["PerasCertBoostsGenesis"]) _ = Just Public + privacyFor (Namespace _ ["PerasCertBoostsBlockNotYetReceived"]) _ = Just Public + privacyFor (Namespace _ ["ChainSelectionForBoostedBlock"]) _ = Just Public + privacyFor _ _ = Nothing + + detailsFor (Namespace _ ["AddedPerasCertToQueue"]) _ = Just DDetailed + detailsFor (Namespace _ ["PoppedPerasCertFromQueue"]) _ = Just DDetailed + detailsFor (Namespace _ ["IgnorePerasCertTooOld"]) _ = Just DNormal + detailsFor (Namespace _ ["PerasCertBoostsCurrentChain"]) _ = Just DNormal + detailsFor (Namespace _ ["PerasCertBoostsGenesis"]) _ = Just DNormal + detailsFor (Namespace _ ["PerasCertBoostsBlockNotYetReceived"]) _ = Just DNormal + detailsFor (Namespace _ ["ChainSelectionForBoostedBlock"]) _ = Just DNormal + detailsFor _ _ = Nothing + + documentFor (Namespace _ ["AddedPerasCertToQueue"]) = Just "Peras certificate added to processing queue" + documentFor (Namespace _ ["PoppedPerasCertFromQueue"]) = Just "Peras certificate popped from processing queue" + documentFor (Namespace _ ["IgnorePerasCertTooOld"]) = Just "Peras certificate ignored as it is too old compared to immutable slot" + documentFor (Namespace _ ["PerasCertBoostsCurrentChain"]) = Just "Peras certificate boosts a block on the current selection" + documentFor (Namespace _ ["PerasCertBoostsGenesis"]) = Just "Peras certificate boosts the Genesis point" + documentFor (Namespace _ ["PerasCertBoostsBlockNotYetReceived"]) = Just "Peras certificate boosts a block not yet received" + documentFor (Namespace _ ["ChainSelectionForBoostedBlock"]) = Just "Perform chain selection for block boosted by Peras certificate" + documentFor _ = Nothing + + allNamespaces = + [Namespace [] ["AddedPerasCertToQueue"], + Namespace [] ["PoppedPerasCertFromQueue"], + Namespace [] ["IgnorePerasCertTooOld"], + Namespace [] ["PerasCertBoostsCurrentChain"], + Namespace [] ["PerasCertBoostsGenesis"], + Namespace [] ["PerasCertBoostsBlockNotYetReceived"], + Namespace [] ["ChainSelectionForBoostedBlock"]] diff --git a/cardano-node/src/Cardano/Node/Tracing/Tracers/Consensus.hs b/cardano-node/src/Cardano/Node/Tracing/Tracers/Consensus.hs index 3daec1eb691..9ac0672d46e 100644 --- a/cardano-node/src/Cardano/Node/Tracing/Tracers/Consensus.hs +++ b/cardano-node/src/Cardano/Node/Tracing/Tracers/Consensus.hs @@ -80,6 +80,11 @@ import qualified Data.Text as Text import Data.Time (NominalDiffTime) import Data.Word (Word32, Word64) import Network.TypedProtocol.Core +import Network.TypedProtocol.Codec (AnyMessage (AnyMessageAndAgency)) +import Ouroboros.Consensus.MiniProtocol.ObjectDiffusion.PerasCert +import Ouroboros.Consensus.MiniProtocol.ObjectDiffusion.Inbound (TraceObjectDiffusionInbound(..), NumObjectsProcessed (..)) +import Ouroboros.Consensus.MiniProtocol.ObjectDiffusion.Outbound (TraceObjectDiffusionOutbound(..)) +import Ouroboros.Network.Protocol.ObjectDiffusion.Type (NumObjectIdsReq(..), NumObjectIdsAck(..), ObjectDiffusion(..), Message(..), BlockingReplyList(..)) instance (LogFormatting adr, Show adr) => LogFormatting (ConnectionId adr) where @@ -1428,6 +1433,279 @@ instance MetaTrace (TraceEventMempool blk) where , Namespace [] ["LedgerFound"] ] +-------------------------------------------------------------------------------- +-- PerasCertDiffusionInbound Tracer +-------------------------------------------------------------------------------- + +instance MetaTrace (TracePerasCertDiffusionInbound blk) where + namespaceFor TraceObjectDiffusionCollected {} = + Namespace [] ["Collected"] + namespaceFor TraceObjectDiffusionProcessed {} = + Namespace [] ["Processed"] + namespaceFor TraceObjectDiffusionControlMessage {} = + Namespace [] ["ControlMessage"] + namespaceFor TraceObjectInboundCanRequestMoreObjects {} = + Namespace [] ["CanRequestMoreObjects"] + namespaceFor TraceObjectInboundCannotRequestMoreObjects {} = + Namespace [] ["CannotRequestMoreObjects"] + + severityFor (Namespace _ ["Collected"]) _ = Just Info + severityFor (Namespace _ ["Processed"]) _ = Just Info + severityFor (Namespace _ ["ControlMessage"]) _ = Just Info + severityFor (Namespace _ ["CanRequestMoreObjects"]) _ = Just Info + severityFor (Namespace _ ["CannotRequestMoreObjects"]) _ = Just Info + severityFor _ _ = Nothing + + documentFor (Namespace _ ["Collected"]) = Just + "Objects have been collected from the peer." + documentFor (Namespace _ ["Processed"]) = Just + "Objects have been processed and added to the pool." + documentFor (Namespace _ ["ControlMessage"]) = Just + "A control message has been received." + documentFor (Namespace _ ["CanRequestMoreObjects"]) = Just + "More objects can be requested from the peer." + documentFor (Namespace _ ["CannotRequestMoreObjects"]) = Just + "No more objects can be requested from the peer at this time." + documentFor _ = Nothing + + allNamespaces = + [ Namespace [] ["Collected"] + , Namespace [] ["Processed"] + , Namespace [] ["ControlMessage"] + , Namespace [] ["CanRequestMoreObjects"] + , Namespace [] ["CannotRequestMoreObjects"] + ] + +-------------------------------------------------------------------------------- +-- PerasCertDiffusionInbound LogFormatting +-------------------------------------------------------------------------------- + +instance LogFormatting (TracePerasCertDiffusionInbound blk) where + forMachine _dtal = \case + TraceObjectDiffusionCollected n -> + mconcat + [ "kind" .= String "Collected" + , "count" .= n + ] + TraceObjectDiffusionProcessed (NumObjectsProcessed n) -> + mconcat + [ "kind" .= String "Processed" + , "count" .= n + ] + TraceObjectDiffusionControlMessage msg -> + mconcat + [ "kind" .= String "ControlMessage" + , "message" .= String (Text.pack $ show msg) + ] + TraceObjectInboundCanRequestMoreObjects {} -> + mconcat + [ "kind" .= String "CanRequestMoreObjects" + ] + TraceObjectInboundCannotRequestMoreObjects {} -> + mconcat + [ "kind" .= String "CannotRequestMoreObjects" + ] + + forHuman = \case + TraceObjectDiffusionCollected n -> + "Collected " <> showT n <> " Peras certificates" + TraceObjectDiffusionProcessed n -> + "Processed " <> showT n <> " Peras certificates" + TraceObjectDiffusionControlMessage msg -> + "Received control message: " <> showT msg + TraceObjectInboundCanRequestMoreObjects {} -> + "Can request more Peras certificates from peer" + TraceObjectInboundCannotRequestMoreObjects {} -> + "Cannot request more Peras certificates from peer at this time" + +-------------------------------------------------------------------------------- +-- PerasCertDiffusionOutbound Tracer +-------------------------------------------------------------------------------- + +instance MetaTrace (TracePerasCertDiffusionOutbound blk) where + namespaceFor TraceObjectDiffusionOutboundTerminated {} = + Namespace [] ["Terminated"] + namespaceFor TraceObjectDiffusionOutboundRecvMsgRequestObjectIds {} = + Namespace [] ["RecvMsgRequestObjectIds"] + namespaceFor TraceObjectDiffusionOutboundSendMsgReplyObjectIds {} = + Namespace [] ["SendMsgReplyObjectIds"] + namespaceFor TraceObjectDiffusionOutboundRecvMsgRequestObjects {} = + Namespace [] ["RecvMsgRequestObjects"] + namespaceFor TraceObjectDiffusionOutboundSendMsgReplyObjects {} = + Namespace [] ["SendMsgReplyObjects"] + + severityFor (Namespace _ ["Terminated"]) _ = Just Info + severityFor (Namespace _ ["RecvMsgRequestObjectIds"]) _ = Just Info + severityFor (Namespace _ ["SendMsgReplyObjectIds"]) _ = Just Info + severityFor (Namespace _ ["RecvMsgRequestObjects"]) _ = Just Info + severityFor (Namespace _ ["SendMsgReplyObjects"]) _ = Just Info + severityFor _ _ = Nothing + + documentFor (Namespace _ ["Terminated"]) = Just + "The object diffusion mini-protocol has been terminated by the inbound peer." + documentFor (Namespace _ ["RecvMsgRequestObjectIds"]) = Just + "Received a request for object IDs from the inbound peer." + documentFor (Namespace _ ["SendMsgReplyObjectIds"]) = Just + "Sending a reply with object IDs to the inbound peer." + documentFor (Namespace _ ["RecvMsgRequestObjects"]) = Just + "Received a request for specific objects from the inbound peer." + documentFor (Namespace _ ["SendMsgReplyObjects"]) = Just + "Sending a reply with specific objects to the inbound peer." + documentFor _ = Nothing + + allNamespaces = + [ Namespace [] ["Terminated"] + , Namespace [] ["RecvMsgRequestObjectIds"] + , Namespace [] ["SendMsgReplyObjectIds"] + , Namespace [] ["RecvMsgRequestObjects"] + , Namespace [] ["SendMsgReplyObjects"] + ] + +-------------------------------------------------------------------------------- +-- PerasCertDiffusionOutbound LogFormatting +-------------------------------------------------------------------------------- + +instance LogFormatting (TracePerasCertDiffusionOutbound blk) where + forMachine _dtal = \case + TraceObjectDiffusionOutboundTerminated -> + mconcat + [ "kind" .= String "Terminated" + ] + TraceObjectDiffusionOutboundRecvMsgRequestObjectIds (NumObjectIdsReq n) -> + mconcat + [ "kind" .= String "RecvMsgRequestObjectIds" + , "count" .= n + ] + TraceObjectDiffusionOutboundSendMsgReplyObjectIds roundNos -> + mconcat + [ "kind" .= String "SendMsgReplyObjectIds" + , "count" .= length roundNos + ] + TraceObjectDiffusionOutboundRecvMsgRequestObjects objIds -> + mconcat + [ "kind" .= String "RecvMsgRequestObjects" + , "count" .= length objIds + ] + TraceObjectDiffusionOutboundSendMsgReplyObjects objs -> + mconcat + [ "kind" .= String "SendMsgReplyObjects" + , "count" .= length objs + ] + + forHuman = \case + TraceObjectDiffusionOutboundTerminated -> + "Peras certificate diffusion mini-protocol has been terminated" + TraceObjectDiffusionOutboundRecvMsgRequestObjectIds n -> + "Received request for " <> showT n <> " Peras certificate IDs" + TraceObjectDiffusionOutboundSendMsgReplyObjectIds roundNos -> + "Sending " <> showT (length roundNos) <> " Peras certificate IDs" + TraceObjectDiffusionOutboundRecvMsgRequestObjects objIds -> + "Received request for " <> showT (length objIds) <> " Peras certificates" + TraceObjectDiffusionOutboundSendMsgReplyObjects objs -> + "Sending " <> showT (length objs) <> " Peras certificates to inbound peer" + + + +-------------------------------------------------------------------------------- +-- ObjectDiffusion Protocol Tracer (AnyMessage) +-------------------------------------------------------------------------------- + +instance LogFormatting (AnyMessage (ObjectDiffusion objectId object)) where + forMachine _dtal (AnyMessageAndAgency _stok MsgInit) = + mconcat + [ "kind" .= String "MsgInit" + ] + forMachine _dtal (AnyMessageAndAgency _stok (MsgRequestObjectIds _ ack req)) = + mconcat + [ "kind" .= String "MsgRequestObjectIds" + , "ack" .= getNumObjectIdsAck ack + , "req" .= getNumObjectIdsReq req + ] + forMachine _dtal (AnyMessageAndAgency _stok (MsgReplyObjectIds objIds)) = + let count = case objIds of + BlockingReply xs -> length xs + NonBlockingReply xs -> length xs + in mconcat + [ "kind" .= String "MsgReplyObjectIds" + , "count" .= (count :: Int) + ] + forMachine _dtal (AnyMessageAndAgency _stok (MsgRequestObjects objIds)) = + mconcat + [ "kind" .= String "MsgRequestObjects" + , "count" .= length objIds + ] + forMachine _dtal (AnyMessageAndAgency _stok (MsgReplyObjects objects)) = + mconcat + [ "kind" .= String "MsgReplyObjects" + , "count" .= length objects + ] + forMachine _dtal (AnyMessageAndAgency _stok MsgDone) = + mconcat + [ "kind" .= String "MsgDone" + ] + + forHuman (AnyMessageAndAgency _stok MsgInit) = + "ObjectDiffusion protocol initialized" + forHuman (AnyMessageAndAgency _stok (MsgRequestObjectIds _ ack req)) = + "Requested " <> showT (getNumObjectIdsReq req) <> " object IDs, acknowledging " <> showT (getNumObjectIdsAck ack) + forHuman (AnyMessageAndAgency _stok (MsgReplyObjectIds objIds)) = + let count = case objIds of + BlockingReply xs -> length xs + NonBlockingReply xs -> length xs + in "Replied with " <> showT (count :: Int) <> " object IDs" + forHuman (AnyMessageAndAgency _stok (MsgRequestObjects objIds)) = + "Requested " <> showT (length objIds) <> " objects" + forHuman (AnyMessageAndAgency _stok (MsgReplyObjects objects)) = + "Replied with " <> showT (length objects) <> " objects" + forHuman (AnyMessageAndAgency _stok MsgDone) = + "ObjectDiffusion protocol terminated" + +instance MetaTrace (AnyMessage (ObjectDiffusion objectId object)) where + namespaceFor (AnyMessageAndAgency _stok MsgInit) = + Namespace [] ["MsgInit"] + namespaceFor (AnyMessageAndAgency _stok (MsgRequestObjectIds _ _ _)) = + Namespace [] ["MsgRequestObjectIds"] + namespaceFor (AnyMessageAndAgency _stok (MsgReplyObjectIds _)) = + Namespace [] ["MsgReplyObjectIds"] + namespaceFor (AnyMessageAndAgency _stok (MsgRequestObjects _)) = + Namespace [] ["MsgRequestObjects"] + namespaceFor (AnyMessageAndAgency _stok (MsgReplyObjects _)) = + Namespace [] ["MsgReplyObjects"] + namespaceFor (AnyMessageAndAgency _stok MsgDone) = + Namespace [] ["MsgDone"] + + severityFor (Namespace _ ["MsgInit"]) _ = Just Info + severityFor (Namespace _ ["MsgRequestObjectIds"]) _ = Just Debug + severityFor (Namespace _ ["MsgReplyObjectIds"]) _ = Just Debug + severityFor (Namespace _ ["MsgRequestObjects"]) _ = Just Debug + severityFor (Namespace _ ["MsgReplyObjects"]) _ = Just Debug + severityFor (Namespace _ ["MsgDone"]) _ = Just Info + severityFor _ _ = Nothing + + documentFor (Namespace _ ["MsgInit"]) = Just + "ObjectDiffusion protocol initialization message." + documentFor (Namespace _ ["MsgRequestObjectIds"]) = Just + "Request for object identifiers with acknowledgement count." + documentFor (Namespace _ ["MsgReplyObjectIds"]) = Just + "Reply with available object identifiers." + documentFor (Namespace _ ["MsgRequestObjects"]) = Just + "Request for specific objects by their identifiers." + documentFor (Namespace _ ["MsgReplyObjects"]) = Just + "Reply with the requested objects." + documentFor (Namespace _ ["MsgDone"]) = Just + "ObjectDiffusion protocol termination message." + documentFor _ = Nothing + + allNamespaces = + [ Namespace [] ["MsgInit"] + , Namespace [] ["MsgRequestObjectIds"] + , Namespace [] ["MsgReplyObjectIds"] + , Namespace [] ["MsgRequestObjects"] + , Namespace [] ["MsgReplyObjects"] + , Namespace [] ["MsgDone"] + ] + + -------------------------------------------------------------------------------- -- ForgeEvent Tracer -------------------------------------------------------------------------------- diff --git a/cardano-node/src/Cardano/Tracing/Config.hs b/cardano-node/src/Cardano/Tracing/Config.hs index b71e90f52aa..c4fbc9d7a27 100644 --- a/cardano-node/src/Cardano/Tracing/Config.hs +++ b/cardano-node/src/Cardano/Tracing/Config.hs @@ -70,6 +70,9 @@ module Cardano.Tracing.Config , TraceTxOutbound , TraceTxSubmissionProtocol , TraceTxSubmission2Protocol + , TracePerasCertDiffusionInbound + , TracePerasCertDiffusionOutbound + , TracePerasCertDiffusionProtocol , TraceKeepAliveProtocol , TracePeerSharingProtocol , proxyName @@ -178,6 +181,9 @@ type TraceTxInbound = ("TraceTxInbound" :: Symbol) type TraceTxOutbound = ("TraceTxOutbound" :: Symbol) type TraceTxSubmissionProtocol = ("TraceTxSubmissionProtocol" :: Symbol) type TraceTxSubmission2Protocol = ("TraceTxSubmission2Protocol" :: Symbol) +type TracePerasCertDiffusionInbound = ("TracePerasCertDiffusionInbound" :: Symbol) +type TracePerasCertDiffusionOutbound = ("TracePerasCertDiffusionOutbound" :: Symbol) +type TracePerasCertDiffusionProtocol = ("TracePerasCertDiffusionProtocol" :: Symbol) type TraceKeepAliveProtocol = ("TraceKeepAliveProtocol" :: Symbol) type TracePeerSharingProtocol = ("TracePeerSharingProtocol" :: Symbol) type TraceGsm = ("TraceGsm" :: Symbol) @@ -254,6 +260,9 @@ data TraceSelection , traceTxOutbound :: OnOff TraceTxOutbound , traceTxSubmissionProtocol :: OnOff TraceTxSubmissionProtocol , traceTxSubmission2Protocol :: OnOff TraceTxSubmission2Protocol + , tracePerasCertDiffusionInbound :: OnOff TracePerasCertDiffusionInbound + , tracePerasCertDiffusionOutbound :: OnOff TracePerasCertDiffusionOutbound + , tracePerasCertDiffusionProtocol :: OnOff TracePerasCertDiffusionProtocol , traceKeepAliveProtocol :: OnOff TraceKeepAliveProtocol , tracePeerSharingProtocol :: OnOff TracePeerSharingProtocol , traceGsm :: OnOff TraceGsm @@ -324,6 +333,9 @@ data PartialTraceSelection , pTraceTxOutbound :: Last (OnOff TraceTxOutbound) , pTraceTxSubmissionProtocol :: Last (OnOff TraceTxSubmissionProtocol) , pTraceTxSubmission2Protocol :: Last (OnOff TraceTxSubmission2Protocol) + , pTracePerasCertDiffusionInbound :: Last (OnOff TracePerasCertDiffusionInbound) + , pTracePerasCertDiffusionOutbound :: Last (OnOff TracePerasCertDiffusionOutbound) + , pTracePerasCertDiffusionProtocol :: Last (OnOff TracePerasCertDiffusionProtocol) , pTraceKeepAliveProtocol :: Last (OnOff TraceKeepAliveProtocol) , pTracePeerSharingProtocol :: Last (OnOff TracePeerSharingProtocol) , pTraceGsm :: Last (OnOff TraceGsm) @@ -395,6 +407,9 @@ instance FromJSON PartialTraceSelection where <*> parseTracer (Proxy @TraceTxOutbound) v <*> parseTracer (Proxy @TraceTxSubmissionProtocol) v <*> parseTracer (Proxy @TraceTxSubmission2Protocol) v + <*> parseTracer (Proxy @TracePerasCertDiffusionInbound) v + <*> parseTracer (Proxy @TracePerasCertDiffusionOutbound) v + <*> parseTracer (Proxy @TracePerasCertDiffusionProtocol) v <*> parseTracer (Proxy @TraceKeepAliveProtocol) v <*> parseTracer (Proxy @TracePeerSharingProtocol) v <*> parseTracer (Proxy @TraceGsm) v @@ -463,6 +478,9 @@ defaultPartialTraceConfiguration = , pTraceTxOutbound = pure $ OnOff False , pTraceTxSubmissionProtocol = pure $ OnOff False , pTraceTxSubmission2Protocol = pure $ OnOff False + , pTracePerasCertDiffusionInbound = pure $ OnOff False + , pTracePerasCertDiffusionOutbound = pure $ OnOff False + , pTracePerasCertDiffusionProtocol = pure $ OnOff False , pTraceKeepAliveProtocol = pure $ OnOff False , pTracePeerSharingProtocol = pure $ OnOff False , pTraceGsm = pure $ OnOff True @@ -533,6 +551,9 @@ partialTraceSelectionToEither (Last (Just (PartialTraceDispatcher pTraceSelectio traceTxOutbound <- proxyLastToEither (Proxy @TraceTxOutbound) pTraceTxOutbound traceTxSubmissionProtocol <- proxyLastToEither (Proxy @TraceTxSubmissionProtocol) pTraceTxSubmissionProtocol traceTxSubmission2Protocol <- proxyLastToEither (Proxy @TraceTxSubmission2Protocol) pTraceTxSubmission2Protocol + tracePerasCertDiffusionInbound <- proxyLastToEither (Proxy @TracePerasCertDiffusionInbound) pTracePerasCertDiffusionInbound + tracePerasCertDiffusionOutbound <- proxyLastToEither (Proxy @TracePerasCertDiffusionOutbound) pTracePerasCertDiffusionOutbound + tracePerasCertDiffusionProtocol <- proxyLastToEither (Proxy @TracePerasCertDiffusionProtocol) pTracePerasCertDiffusionProtocol traceKeepAliveProtocol <- proxyLastToEither (Proxy @TraceKeepAliveProtocol) pTraceKeepAliveProtocol tracePeerSharingProtocol <- proxyLastToEither (Proxy @TracePeerSharingProtocol) pTracePeerSharingProtocol traceGsm <- proxyLastToEither (Proxy @TraceGsm) pTraceGsm @@ -596,6 +617,9 @@ partialTraceSelectionToEither (Last (Just (PartialTraceDispatcher pTraceSelectio , traceTxOutbound = traceTxOutbound , traceTxSubmissionProtocol = traceTxSubmissionProtocol , traceTxSubmission2Protocol = traceTxSubmission2Protocol + , tracePerasCertDiffusionInbound = tracePerasCertDiffusionInbound + , tracePerasCertDiffusionOutbound = tracePerasCertDiffusionOutbound + , tracePerasCertDiffusionProtocol = tracePerasCertDiffusionProtocol , traceKeepAliveProtocol = traceKeepAliveProtocol , tracePeerSharingProtocol = tracePeerSharingProtocol , traceGsm = traceGsm @@ -663,6 +687,9 @@ partialTraceSelectionToEither (Last (Just (PartialTracingOnLegacy pTraceSelectio traceTxOutbound <- proxyLastToEither (Proxy @TraceTxOutbound) pTraceTxOutbound traceTxSubmissionProtocol <- proxyLastToEither (Proxy @TraceTxSubmissionProtocol) pTraceTxSubmissionProtocol traceTxSubmission2Protocol <- proxyLastToEither (Proxy @TraceTxSubmission2Protocol) pTraceTxSubmission2Protocol + tracePerasCertDiffusionInbound <- proxyLastToEither (Proxy @TracePerasCertDiffusionInbound) pTracePerasCertDiffusionInbound + tracePerasCertDiffusionOutbound <- proxyLastToEither (Proxy @TracePerasCertDiffusionOutbound) pTracePerasCertDiffusionOutbound + tracePerasCertDiffusionProtocol <- proxyLastToEither (Proxy @TracePerasCertDiffusionProtocol) pTracePerasCertDiffusionProtocol traceKeepAliveProtocol <- proxyLastToEither (Proxy @TraceKeepAliveProtocol) pTraceKeepAliveProtocol tracePeerSharingProtocol <- proxyLastToEither (Proxy @TracePeerSharingProtocol) pTracePeerSharingProtocol traceGsm <- proxyLastToEither (Proxy @TraceGsm) pTraceGsm @@ -726,6 +753,9 @@ partialTraceSelectionToEither (Last (Just (PartialTracingOnLegacy pTraceSelectio , traceTxOutbound = traceTxOutbound , traceTxSubmissionProtocol = traceTxSubmissionProtocol , traceTxSubmission2Protocol = traceTxSubmission2Protocol + , tracePerasCertDiffusionInbound = tracePerasCertDiffusionInbound + , tracePerasCertDiffusionOutbound = tracePerasCertDiffusionOutbound + , tracePerasCertDiffusionProtocol = tracePerasCertDiffusionProtocol , traceKeepAliveProtocol = traceKeepAliveProtocol , tracePeerSharingProtocol = tracePeerSharingProtocol , traceGsm = traceGsm diff --git a/cardano-node/src/Cardano/Tracing/OrphanInstances/Consensus.hs b/cardano-node/src/Cardano/Tracing/OrphanInstances/Consensus.hs index 29a9944b72e..eb48aa1faa2 100644 --- a/cardano-node/src/Cardano/Tracing/OrphanInstances/Consensus.hs +++ b/cardano-node/src/Cardano/Tracing/OrphanInstances/Consensus.hs @@ -71,6 +71,10 @@ import Ouroboros.Consensus.Storage.LedgerDB (PushGoal (..), PushStart import qualified Ouroboros.Consensus.Storage.LedgerDB as LedgerDB import qualified Ouroboros.Consensus.Storage.LedgerDB.Snapshots as LedgerDB import qualified Ouroboros.Consensus.Storage.VolatileDB.Impl as VolDb +import qualified Ouroboros.Consensus.MiniProtocol.ObjectDiffusion.PerasCert as PerasCert +import Ouroboros.Consensus.MiniProtocol.ObjectDiffusion.Inbound (TraceObjectDiffusionInbound(..), NumObjectsProcessed (..)) +import Ouroboros.Consensus.MiniProtocol.ObjectDiffusion.Outbound (TraceObjectDiffusionOutbound(..)) +import Ouroboros.Network.Protocol.ObjectDiffusion.Type (NumObjectIdsReq(..)) import Ouroboros.Consensus.Util.Condense import Ouroboros.Consensus.Util.Enclose import Ouroboros.Consensus.Util.Orphans () @@ -249,6 +253,9 @@ instance HasSeverityAnnotation (ChainDB.TraceEvent blk) where getSeverityAnnotation ChainDB.TraceChainSelStarvationEvent{} = Debug + getSeverityAnnotation ChainDB.TraceAddPerasCertEvent{} = Info + getSeverityAnnotation ChainDB.TracePerasCertDbEvent{} = Info + instance HasSeverityAnnotation (LedgerEvent blk) where getSeverityAnnotation (LedgerUpdate _) = Notice getSeverityAnnotation (LedgerWarning _) = Critical @@ -782,6 +789,8 @@ instance ( ConvertRawHash blk ChainDB.TraceChainSelStarvationEvent ev -> case ev of ChainDB.ChainSelStarvation RisingEdge -> "Chain Selection was starved." ChainDB.ChainSelStarvation (FallingEdgeWith pt) -> "Chain Selection was unstarved by " <> renderRealPoint pt + ChainDB.TracePerasCertDbEvent ev -> showT ev + ChainDB.TraceAddPerasCertEvent ev -> showT ev where showProgressT :: Int -> Int -> Text showProgressT chunkNo outOf = pack (showFFloat (Just 2) (100 * fromIntegral chunkNo / fromIntegral outOf :: Float) mempty) @@ -1278,6 +1287,14 @@ instance ( ConvertRawHash blk RisingEdge -> "risingEdge" .= True FallingEdgeWith pt -> "fallingEdge" .= toObject verb pt ] + toObject _verb (ChainDB.TracePerasCertDbEvent ev) = + mconcat [ "kind" .= String "TracePerasCertDbEvent" + , "event" .= show ev + ] + toObject _verb (ChainDB.TraceAddPerasCertEvent ev) = + mconcat [ "kind" .= String "TraceAddPerasCertEvent" + , "event" .= show ev + ] instance ConvertRawHash blk => ToObject (ImmDB.TraceChunkValidation blk ChunkNo) where toObject verb ev = case ev of @@ -1851,3 +1868,92 @@ instance ConvertRawHash blk => ToObject (Tip blk) where , "tipHash" .= renderHeaderHash (Proxy @blk) hash , "tipBlockNo" .= toJSON bNo ] + +-- | Peras Certificate Diffusion Tracers +-- These instances are needed to support the Peras certificate diffusion tracing + +-- Basic privacy and severity annotations for Peras cert diffusion events +instance HasPrivacyAnnotation (PerasCert.TracePerasCertDiffusionInbound blk) +instance HasSeverityAnnotation (PerasCert.TracePerasCertDiffusionInbound blk) where + getSeverityAnnotation _ = Info + +instance HasPrivacyAnnotation (PerasCert.TracePerasCertDiffusionOutbound blk) +instance HasSeverityAnnotation (PerasCert.TracePerasCertDiffusionOutbound blk) where + getSeverityAnnotation _ = Info + +-- ToObject instances for basic JSON serialization +instance ToObject (PerasCert.TracePerasCertDiffusionInbound blk) where + toObject _verb = \case + TraceObjectDiffusionCollected n -> + mconcat + [ "kind" .= String "Collected" + , "count" .= n + ] + TraceObjectDiffusionProcessed (NumObjectsProcessed n) -> + mconcat + [ "kind" .= String "Processed" + , "count" .= n + ] + TraceObjectDiffusionControlMessage msg -> + mconcat + [ "kind" .= String "ControlMessage" + , "message" .= String (Text.pack $ show msg) + ] + TraceObjectInboundCanRequestMoreObjects {} -> + mconcat + [ "kind" .= String "CanRequestMoreObjects" + ] + TraceObjectInboundCannotRequestMoreObjects {} -> + mconcat + [ "kind" .= String "CannotRequestMoreObjects" + ] + +instance ToObject (PerasCert.TracePerasCertDiffusionOutbound blk) where + toObject _verb = \case + TraceObjectDiffusionOutboundTerminated -> + mconcat + [ "kind" .= String "Terminated" + ] + TraceObjectDiffusionOutboundRecvMsgRequestObjectIds (NumObjectIdsReq n) -> + mconcat + [ "kind" .= String "RecvMsgRequestObjectIds" + , "count" .= n + ] + TraceObjectDiffusionOutboundSendMsgReplyObjectIds roundNos -> + mconcat + [ "kind" .= String "SendMsgReplyObjectIds" + , "count" .= length roundNos + ] + TraceObjectDiffusionOutboundRecvMsgRequestObjects objIds -> + mconcat + [ "kind" .= String "RecvMsgRequestObjects" + , "count" .= length objIds + ] + TraceObjectDiffusionOutboundSendMsgReplyObjects objs -> + mconcat + [ "kind" .= String "SendMsgReplyObjects" + , "count" .= length objs + ] + +-- Transformable instances for the basic event types +instance Transformable Text IO (PerasCert.TracePerasCertDiffusionInbound blk) where + trTransformer = trStructured + +instance Transformable Text IO (PerasCert.TracePerasCertDiffusionOutbound blk) where + trTransformer = trStructured + +-- TraceLabelPeer wrapper instances +instance (ToObject peer, ToObject (PerasCert.TracePerasCertDiffusionInbound blk)) + => Transformable Text IO (TraceLabelPeer peer (PerasCert.TracePerasCertDiffusionInbound blk)) where + trTransformer = trStructured + +instance (ToObject peer, ToObject (PerasCert.TracePerasCertDiffusionOutbound blk)) + => Transformable Text IO (TraceLabelPeer peer (PerasCert.TracePerasCertDiffusionOutbound blk)) where + trTransformer = trStructured + +-- HasTextFormatter instances +instance HasTextFormatter (TraceLabelPeer peer (PerasCert.TracePerasCertDiffusionInbound blk)) where + formatText _ = pack . show . toList + +instance HasTextFormatter (TraceLabelPeer peer (PerasCert.TracePerasCertDiffusionOutbound blk)) where + formatText _ = pack . show . toList diff --git a/cardano-node/src/Cardano/Tracing/OrphanInstances/Network.hs b/cardano-node/src/Cardano/Tracing/OrphanInstances/Network.hs index f654e09a37b..38eacc4e718 100644 --- a/cardano-node/src/Cardano/Tracing/OrphanInstances/Network.hs +++ b/cardano-node/src/Cardano/Tracing/OrphanInstances/Network.hs @@ -107,6 +107,8 @@ import Ouroboros.Network.Protocol.PeerSharing.Type (PeerSharingAmount PeerSharingResult (..)) import qualified Ouroboros.Network.Protocol.PeerSharing.Type as PeerSharing import Ouroboros.Network.Protocol.TxSubmission2.Type as TxSubmission2 +import Ouroboros.Consensus.MiniProtocol.ObjectDiffusion.PerasCert (PerasCertDiffusion) +import qualified Ouroboros.Network.Protocol.ObjectDiffusion.Type as ObjectDiffusion import Ouroboros.Network.RethrowPolicy (ErrorCommand (..)) import Ouroboros.Network.Server2 as Server import Ouroboros.Network.Snocket (LocalAddress (..)) @@ -712,6 +714,10 @@ instance (ToObject peer, Show (TxId (GenTx blk)), Show (GenTx blk)) => Transformable Text IO (TraceLabelPeer peer (NtN.TraceSendRecv (TxSubmission2 (GenTxId blk) (GenTx blk)))) where trTransformer = trStructured +instance ToObject peer + => Transformable Text IO (TraceLabelPeer peer (NtN.TraceSendRecv (PerasCertDiffusion blk))) where + trTransformer = trStructured + instance (ToObject peer, Show (TxId (GenTx blk)), Show (GenTx blk)) => Transformable Text IO (TraceLabelPeer peer (TraceTxSubmissionOutbound (GenTxId blk) (GenTx blk))) where trTransformer = trStructured @@ -1147,6 +1153,34 @@ instance ToJSON peerAddr => ToObject (AnyMessage (PeerSharing.PeerSharing peerAd , "agency" .= String (pack $ show stok) ] +instance ToObject (AnyMessage (ObjectDiffusion.ObjectDiffusion objectId object)) where + toObject _verb (AnyMessageAndAgency _stok ObjectDiffusion.MsgInit) = + mconcat [ "kind" .= String "MsgInit" ] + toObject _verb (AnyMessageAndAgency _stok (ObjectDiffusion.MsgRequestObjectIds _ _ack _req)) = + mconcat + [ "kind" .= String "MsgRequestObjectIds" + ] + toObject _verb (AnyMessageAndAgency _stok (ObjectDiffusion.MsgReplyObjectIds objIds)) = + let count = case objIds of + ObjectDiffusion.BlockingReply xs -> length xs + ObjectDiffusion.NonBlockingReply xs -> length xs + in mconcat + [ "kind" .= String "MsgReplyObjectIds" + , "count" .= (count :: Int) + ] + toObject _verb (AnyMessageAndAgency _stok (ObjectDiffusion.MsgRequestObjects objIds)) = + mconcat + [ "kind" .= String "MsgRequestObjects" + , "count" .= length objIds + ] + toObject _verb (AnyMessageAndAgency _stok (ObjectDiffusion.MsgReplyObjects objects)) = + mconcat + [ "kind" .= String "MsgReplyObjects" + , "count" .= length objects + ] + toObject _verb (AnyMessageAndAgency _stok ObjectDiffusion.MsgDone) = + mconcat [ "kind" .= String "MsgDone" ] + instance ToJSON peerAddr => ToJSON (ConnectionId peerAddr) where toJSON ConnectionId { localAddress, remoteAddress } = diff --git a/cardano-node/src/Cardano/Tracing/Tracers.hs b/cardano-node/src/Cardano/Tracing/Tracers.hs index 41b81715cc8..cd0056b27d9 100644 --- a/cardano-node/src/Cardano/Tracing/Tracers.hs +++ b/cardano-node/src/Cardano/Tracing/Tracers.hs @@ -864,9 +864,8 @@ mkConsensusTracers mbEKGDirect trSel verb tr nodeKern fStats = do , Consensus.gsmTracer = tracerOnOff (traceGsm trSel) verb "GSM" tr , Consensus.csjTracer = tracerOnOff (traceCsj trSel) verb "CSJ" tr , Consensus.dbfTracer = tracerOnOff (traceDevotedBlockFetch trSel) verb "DevotedBlockFetch" tr - -- TODO plug in - , Consensus.perasCertDiffusionInboundTracer = Tracer $ \_ -> pure () - , Consensus.perasCertDiffusionOutboundTracer = Tracer $ \_ -> pure () + , Consensus.perasCertDiffusionInboundTracer = tracerOnOff (tracePerasCertDiffusionInbound trSel) verb "PerasCertDiffusionInbound" tr + , Consensus.perasCertDiffusionOutboundTracer = tracerOnOff (tracePerasCertDiffusionOutbound trSel) verb "PerasCertDiffusionOutbound" tr } where mkForgeTracers :: IO ForgeTracers @@ -1518,8 +1517,9 @@ nodeToNodeTracers' trSel verb tr = , NodeToNode.tPeerSharingTracer = tracerOnOff (tracePeerSharingProtocol trSel) verb "PeerSharingPrototocol" tr - -- TODO plug in - , NodeToNode.tPerasCertDiffusionTracer = Tracer $ \_ -> pure () + , NodeToNode.tPerasCertDiffusionTracer = + tracerOnOff (tracePerasCertDiffusionProtocol trSel) + verb "PerasCertDiffusionProtocol" tr } -- TODO @ouroboros-network