-
Notifications
You must be signed in to change notification settings - Fork 43
Add ouroboros-consensus:tracing sublibrary
#2244
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
38 commits
Select commit
Hold shift + click to select a range
9eb5536
Add ouroboros-consensus:tracing sublibrary
jasagredo b351ace
Fix ouroboros-consensus:tracing compilation
jasagredo eaa5d32
Implement HasIssuer
jasagredo bf26128
Move ChainDB tracer into ouroboros-consensus:tracing
jasagredo a8ddc75
Move Consensus tracer into ouroboros-consensus:tracing
jasagredo f3a87f2
Add Ouroboros.Consensus.Tracing.Era.Shelley.Render
jasagredo b8e2bcf
Move Byron era tracing instances into ouroboros-consensus:tracing
jasagredo dc762a2
Move Shelley era tracing instances into ouroboros-consensus:tracing
jasagredo 447fd64
Move the KES tracing instances into ouroboros-consensus:tracing
jasagredo fb1ea96
Add the Ouroboros.Consensus.Tracing umbrella module
jasagredo d0607c3
Don't render an unmatched plutus purpose as null
jasagredo f46d552
Key the object diffusion tracing instances on the object-id type
jasagredo c7d4b2f
Trace the Peras cert inclusion and vote forging events
jasagredo 5f0ad98
Correct the rationale for the non-empty container helpers
jasagredo fc717ae
Add a test suite checking the MetaTrace instances for consistency
jasagredo 2afa3c3
Pin the Shelley rendering helpers with a golden file
jasagredo e5e855a
Check the per-peer and KES agent tracers too
jasagredo 894d247
Stop checking the storage DB tracers twice
jasagredo f302908
Fix hlint
jasagredo 03b348b
Fix Nix compilation
jasagredo 1caa909
Fix cabal-gild
jasagredo 7568cdb
Fix fourmolu
jasagredo 63c3421
Drop the cardano-prelude dependency from the tracing sublibrary
jasagredo 8e9bde2
Render the Dijkstra guarding plutus purpose
jasagredo 09278a8
Pin every plutus purpose and renderTxIn in the render golden
jasagredo 9ed4bfd
Drop the dead FetchDecision list tracing instances
jasagredo 577f965
Say what the MetaTrace checks do and do not cover
jasagredo cc49c5a
Compare the tracing golden file in the Nix check
jasagredo 3c75316
Ask for a changelog fragment when the tracing sublibrary changes
jasagredo 06edba0
Add a changelog fragment for the tracing sublibrary
jasagredo b6a99d0
Conway failure predicates integrations
jasagredo 9d0a47e
Cleanup of comments and location of golden files
jasagredo e5ff12d
Cleanup of unused functions from Render.hs
jasagredo 5ae8736
Don't log transactions but log their hex CBOR instead
jasagredo edf5e70
Show the source of rejection in the mempool unconditionally
jasagredo 8d42e8f
Fix inconsistencies on existing tracers
jasagredo 30e5210
Add changelog for deviations from cardano-node
jasagredo a95d5fa
Add TraceMempoolCapacityChanged trace
jasagredo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
32 changes: 32 additions & 0 deletions
32
changelog.d/20260908_120000_javier.sagredo_tracing_sublibrary.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| ### Non-Breaking | ||
|
|
||
| - Added a new public sublibrary `ouroboros-consensus:tracing`, holding the | ||
| `LogFormatting` and `MetaTrace` instances for Consensus types. These were in | ||
| `cardano-node`, and now live next to the types they describe, so that a change | ||
| to a traced type and the change to its rendering land in the same commit. | ||
|
|
||
| The sublibrary also exports `Ouroboros.Consensus.Tracing.HasIssuer`, the | ||
| `HasIssuer` class and its instances, and `Ouroboros.Consensus.Tracing.KESInfo`, | ||
| moved over from `cardano-node` for the same reason. | ||
|
|
||
| Compared to the instances in `cardano-node`: | ||
|
|
||
| - At `DDetailed`, the `tx` field of a transaction is now the hex-encoded CBOR | ||
| of the transaction instead of its `Show` rendering. For Shelley-based eras | ||
| this is the ledger `Tx` serialised at the era's protocol version, which | ||
| reproduces the received bytes of the body, witnesses and auxiliary data. For | ||
| Byron it is the annotated bytes of the mempool payload, which are its | ||
| canonical encoding. This affects every mempool trace that carries a | ||
| transaction. | ||
| - `TraceMempoolRejectedTx` now includes `errdetails`, the source of the | ||
| rejection, at every detail level, not only at `DDetailed`. | ||
| - `Point` and `RealPoint` now have a `forHuman` rendering, "<hash> at slot | ||
| <slot>". | ||
| - `Ouroboros.Consensus.Tracing.Render` no longer exports `renderTip`, | ||
| `renderTipForDetails` or `renderSlotNo`, which no instance used, nor | ||
| re-exports `showT`, which is available from `Cardano.Logging`. | ||
| - Fixed `MetaTrace` delegation to nested namespaces. The LSM backend | ||
| namespaces under `LedgerEvent.Flavor.V2.BackendTrace` are now documented, | ||
| and the privacy and detail level of `AddBlockEvent.AddBlockValidation`, | ||
| `ImmDbEvent.ChunkValidation` and `ImmDbEvent.CacheEvent` namespaces are now | ||
| taken from the nested tracer instead of the default. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| renderScriptHash = 4d50a11e297e7783383bf06dd6e4e481230323bd96cd8b8d9ee3888d | ||
| renderScriptIntegrityHash Nothing = null | ||
| renderScriptIntegrityHash (Just _) = "31237cdb79ae1dfa7ffb87cde7ea8a80352d300ee5ac758a6cddd19d671925ec" | ||
| renderRewardAccount mainnet/key = stake1u9r87kyn9d2fzpvy5r5w5fdzyhsx59znpvhfd6fcc5ar7gs7uwm3p | ||
| renderRewardAccount testnet/key = stake_test1upr87kyn9d2fzpvy5r5w5fdzyhsx59znpvhfd6fcc5ar7gsekye4u | ||
| renderRewardAccount mainnet/script = stake17x85vx25lch33lhpmj3r8u6cjplxg0lc88k3lx27f0ejtcc83spxq | ||
| renderTxIn = 8928aae63c84d87ea098564d1e03ad813f107add474e56aedd286349c0c03ea4#0 | ||
| renderScriptIndex spending = {"kind":"ScriptWitnessIndexTxIn","value":0} | ||
| renderScriptIndex minting = {"kind":"ScriptWitnessIndexMint","value":1} | ||
| renderScriptIndex certifying = {"kind":"ScriptWitnessIndexCertificate","value":2} | ||
| renderScriptIndex withdrawing = {"kind":"ScriptWitnessIndexWithdrawal","value":3} | ||
| renderScriptIndex voting = {"kind":"ScriptWitnessIndexVoting","value":4} | ||
| renderScriptIndex proposing = {"kind":"ScriptWitnessIndexProposing","value":5} | ||
| renderScriptPurpose spending = {"spending":"8928aae63c84d87ea098564d1e03ad813f107add474e56aedd286349c0c03ea4#0"} | ||
| renderScriptPurpose minting = {"minting":{"item":"2db8410d969b6ad6b6969703c77ebf6c44061aa51c5d6ceba46557e2"}} | ||
| renderScriptPurpose certifying = {"certifying":{"item":{"credential":{"keyHash":"dea21a2507d38c552e24df8c4d722e81e1e63de8755d808925deaf9d"},"deposit":null,"kind":"RegCert"}}} | ||
| renderScriptPurpose withdrawing = {"rewarding":"stake1uyg94rcmk4jyfjkvscmce92zrt8wkvntp7mhg0jf86uzl4gynahcu"} | ||
| renderScriptPurpose voting = {"voting":{"item":{"contents":"8761dc36fca24f0f3d78ae5a6c2787af7730a9e9eafdc250eb1fffb1","tag":"StakePoolVoter"}}} | ||
| renderScriptPurpose proposing = {"proposing":{"item":{"anchor":{"dataHash":"8d234302aeb06f2a7effb905e43f037e4dca1c2a0f050e82175328c5ce8d31f4","url":"https://example.com"},"deposit":1000,"govAction":{"tag":"InfoAction"},"returnAddr":{"credential":{"keyHash":"4752e70e4f651479d186955c57142dae87b279ff2c77ef5720af7282"},"network":"Mainnet"}}}} | ||
| renderScriptIndex guarding = {"kind":"ScriptWitnessIndexGuarding","value":6} | ||
| renderScriptPurpose guarding = {"guarding":"d1b3884173424c627f4bac9957ef28b8027dcd13f560c42088aa1fbf"} | ||
| renderMissingRedeemers = {"245d5a7a06fe18358242e81281cd5ba9e6abe4efc54e7b659f25abae":{"spending":"8928aae63c84d87ea098564d1e03ad813f107add474e56aedd286349c0c03ea4#0"},"b0c53e2bf180858da4b64eb5598c5615bba7d723d2b604a83b7f9165":{"minting":{"item":"4a1c412d8e2b3015a7fb7d382808fb7cb721bf93a56e8bb6661cdebe"}}} | ||
| renderIncompleteWithdrawals = {"stake1uykhy5fggpkusvhtwnz8pxk2q5fynxeu0vt7qrtuktndrvgxnyhra":"Mismatch (RelEQ) {supplied: 1, expected: 2}"} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| module Ouroboros.Consensus.Tracing | ||
| ( module Ouroboros.Consensus.Tracing.BlockReplayProgress | ||
| , module Ouroboros.Consensus.Tracing.ChainDB | ||
| , module Ouroboros.Consensus.Tracing.Consensus | ||
| , module Ouroboros.Consensus.Tracing.ConsensusStartupException | ||
| , module Ouroboros.Consensus.Tracing.ConvertTxId | ||
| , module Ouroboros.Consensus.Tracing.HasIssuer | ||
| , module Ouroboros.Consensus.Tracing.KESInfo | ||
| , module Ouroboros.Consensus.Tracing.Render | ||
| ) where | ||
|
|
||
| import Ouroboros.Consensus.Tracing.BlockReplayProgress | ||
| import Ouroboros.Consensus.Tracing.ChainDB | ||
| import Ouroboros.Consensus.Tracing.Consensus | ||
| import Ouroboros.Consensus.Tracing.ConsensusStartupException | ||
| import Ouroboros.Consensus.Tracing.ConvertTxId | ||
| import Ouroboros.Consensus.Tracing.Era.Byron () | ||
| import Ouroboros.Consensus.Tracing.Era.HardFork () | ||
| import Ouroboros.Consensus.Tracing.Era.Shelley () | ||
| import Ouroboros.Consensus.Tracing.Formatting () | ||
| import Ouroboros.Consensus.Tracing.HasIssuer | ||
| import Ouroboros.Consensus.Tracing.KESInfo | ||
| import Ouroboros.Consensus.Tracing.Render |
134 changes: 134 additions & 0 deletions
134
tracing/Ouroboros/Consensus/Tracing/BlockReplayProgress.hs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,134 @@ | ||
| {-# LANGUAGE BangPatterns #-} | ||
| {-# LANGUAGE OverloadedStrings #-} | ||
| {-# LANGUAGE RecordWildCards #-} | ||
| {-# LANGUAGE TupleSections #-} | ||
|
|
||
| module Ouroboros.Consensus.Tracing.BlockReplayProgress | ||
| ( withReplayedBlock | ||
| , ReplayBlockStats (..) | ||
| ) where | ||
|
|
||
| import Cardano.Logging | ||
| import Control.Concurrent.MVar | ||
| import Data.Aeson (Value (String), (.=)) | ||
| import Data.Text (Text, pack) | ||
| import Numeric (showFFloat) | ||
| import Ouroboros.Consensus.Block (SlotNo, realPointSlot) | ||
| import qualified Ouroboros.Consensus.Storage.ChainDB as ChainDB | ||
| import qualified Ouroboros.Consensus.Storage.LedgerDB as LedgerDB | ||
| import Ouroboros.Network.Block (pointSlot, unSlotNo) | ||
| import Ouroboros.Network.Point (withOrigin) | ||
|
|
||
| textShow :: Show a => a -> Text | ||
| textShow = pack . show | ||
|
|
||
| newtype ReplayBlockState = ReplayBlockState | ||
| { rpsLastSlot :: Maybe SlotNo | ||
| -- ^ Last slot for which a `ReplayBlockStats` message has been issued. | ||
| } | ||
|
|
||
| data ReplayBlockStats = ReplayBlockStats | ||
| { rpsCurSlot :: SlotNo | ||
| , rpsGoalSlot :: SlotNo | ||
| } | ||
|
|
||
| initialReplayBlockState :: ReplayBlockState | ||
| initialReplayBlockState = ReplayBlockState{rpsLastSlot = Nothing} | ||
|
|
||
| progressForMachine :: ReplayBlockStats -> Double | ||
| progressForMachine (ReplayBlockStats curSlot goalSlot) = | ||
| (fromIntegral (unSlotNo curSlot) * 100.0) / fromIntegral (unSlotNo $ max curSlot goalSlot) | ||
|
|
||
| progressForHuman :: ReplayBlockStats -> Double | ||
| progressForHuman = round2 . progressForMachine | ||
| where | ||
| round2 :: Double -> Double | ||
| round2 num = | ||
| let | ||
| f :: Int | ||
| f = round $ num * 100 | ||
| in | ||
| fromIntegral f / 100 | ||
|
|
||
| -------------------------------------------------------------------------------- | ||
| -- ReplayBlockStats Tracer | ||
| -------------------------------------------------------------------------------- | ||
|
|
||
| instance LogFormatting ReplayBlockStats where | ||
| forMachine _ stats = | ||
| mconcat | ||
| [ "kind" .= String "ReplayBlockStats" | ||
| , "progress" .= String (pack $ show $ progressForMachine stats) | ||
| ] | ||
|
|
||
| forHuman stats@ReplayBlockStats{..} = | ||
| "Replayed block: slot " | ||
| <> textShow (unSlotNo rpsCurSlot) | ||
| <> " out of " | ||
| <> textShow (unSlotNo rpsGoalSlot) | ||
| <> ". Progress: " | ||
| <> pack (showFFloat (Just 2) (progressForHuman stats) mempty) | ||
| <> "%" | ||
|
|
||
| asMetrics stats = | ||
| [DoubleM "blockReplayProgress" (progressForMachine stats)] | ||
|
|
||
| instance MetaTrace ReplayBlockStats where | ||
| namespaceFor ReplayBlockStats{} = Namespace [] ["LedgerReplay"] | ||
|
|
||
| severityFor (Namespace _ ["LedgerReplay"]) _ = Just Info | ||
| severityFor _ _ = Nothing | ||
|
|
||
| documentFor (Namespace _ ["LedgerReplay"]) = | ||
| Just | ||
| "Counts block replays and calculates the percent." | ||
| documentFor _ = Nothing | ||
|
|
||
| metricsDocFor (Namespace _ ["LedgerReplay"]) = | ||
| [("blockReplayProgress", "Progress in percent")] | ||
| metricsDocFor _ = [] | ||
|
|
||
| allNamespaces = | ||
| [ Namespace [] ["LedgerReplay"] | ||
| ] | ||
|
|
||
| withReplayedBlock :: | ||
| Trace IO ReplayBlockStats -> | ||
| IO (Trace IO (ChainDB.TraceEvent blk)) | ||
| withReplayedBlock tr = do | ||
| var <- newMVar initialReplayBlockState | ||
| contramapMCond tr (process var) | ||
| where | ||
| process :: | ||
| MVar ReplayBlockState -> | ||
| (LoggingContext, Either TraceControl (ChainDB.TraceEvent blk)) -> | ||
| IO (Maybe (LoggingContext, Either TraceControl ReplayBlockStats)) | ||
| process var (ctx, Right msg) = modifyMVar var $ \st -> do | ||
| let !(!st', mbStats) = mbProduceBlockStats msg st | ||
| pure (st', fmap ((ctx,) . Right) mbStats) | ||
| process _ (ctx, Left control) = pure (Just (ctx, Left control)) | ||
|
|
||
| mbProduceBlockStats :: | ||
| ChainDB.TraceEvent blk -> ReplayBlockState -> (ReplayBlockState, Maybe ReplayBlockStats) | ||
| mbProduceBlockStats | ||
| ( ChainDB.TraceLedgerDBEvent | ||
| ( LedgerDB.LedgerReplayEvent | ||
| ( LedgerDB.TraceReplayProgressEvent | ||
| (LedgerDB.ReplayedBlock curSlot [] _ (LedgerDB.ReplayGoal replayToSlot)) | ||
| ) | ||
| ) | ||
| ) | ||
| st@(ReplayBlockState mLastSlot) = | ||
| let curSlotNo = realPointSlot curSlot | ||
| goalSlotNo = withOrigin 0 id $ pointSlot replayToSlot | ||
| stats = ReplayBlockStats curSlotNo goalSlotNo | ||
| progressFor soFar goal = progressForHuman (ReplayBlockStats soFar goal) | ||
| shouldEmit = | ||
| maybe | ||
| True | ||
| (\lastSlot -> progressFor curSlotNo goalSlotNo - progressFor lastSlot goalSlotNo >= 0.01) | ||
| mLastSlot | ||
| in if shouldEmit | ||
| then (ReplayBlockState (Just curSlotNo), Just stats) | ||
| else (st, Nothing) | ||
| mbProduceBlockStats _ st = (st, Nothing) |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.