Skip to content

Commit

Permalink
Account for consensus and ledger changes (WIP)
Browse files Browse the repository at this point in the history
  • Loading branch information
Lucsanszky committed Apr 29, 2024
1 parent b9c79e4 commit 1e5a8ac
Show file tree
Hide file tree
Showing 7 changed files with 75 additions and 68 deletions.
9 changes: 9 additions & 0 deletions cardano-node/src/Cardano/Node/Tracing/Era/Shelley.hs
Original file line number Diff line number Diff line change
Expand Up @@ -1175,6 +1175,15 @@ instance
, "actualPolicyHash" .= actualPolicyHash
, "expectedPolicyHash" .= expectedPolicyHash
]
forMachine _ (Conway.DisallowedProposalDuringBootstrap proposal) =
mconcat [ "kind" .= String "DisallowedProposalDuringBootstrap"
, "proposal" .= proposal
]
forMachine _ (Conway.DisallowedVotesDuringBootstrap votes) =
mconcat [ "kind" .= String "DisallowedVotesDuringBootstrap"
, "votes" .= votes
]


instance
( Consensus.ShelleyBasedEra era
Expand Down
30 changes: 23 additions & 7 deletions cardano-node/src/Cardano/Node/Tracing/Tracers/ChainDB.hs
Original file line number Diff line number Diff line change
Expand Up @@ -504,10 +504,17 @@ instance ( LogFormatting (Header blk)
forMachine _dtal ChainDB.PoppedReprocessLoEBlocksFromQueue =
mconcat [ "kind" .= String "PoppedReprocessLoEBlocksFromQueue" ]
forMachine dtal (ChainDB.ChainSelectionLoEDebug curChain loeFrag) =
mconcat [ "kind" .= String "ChainSelectionLoEDebug"
, "curChain" .= headAndAnchor curChain
, "loeFrag" .= headAndAnchor loeFrag
]
case loeFrag of
ChainDB.LoEEnabled loeF ->
mconcat [ "kind" .= String "ChainSelectionLoEDebug"
, "curChain" .= headAndAnchor curChain
, "loeFrag" .= headAndAnchor loeF
]
ChainDB.LoEDisabled ->
mconcat [ "kind" .= String "ChainSelectionLoEDebug"
, "curChain" .= headAndAnchor curChain
, "loeFrag" .= String "LoE is disabled"
]
where
headAndAnchor frag = object
[ "anchor" .= forMachine dtal (AF.anchorPoint frag)
Expand Down Expand Up @@ -1179,7 +1186,8 @@ instance ConvertRawHash blk
forHuman (ChainDB.OpenedImmutableDB immTip chunk) =
"Opened imm db with immutable tip at " <> renderPointAsPhrase immTip <>
" and chunk " <> showT chunk
forHuman ChainDB.OpenedVolatileDB = "Opened vol db"
forHuman (ChainDB.OpenedVolatileDB maxSlotN) =
"Opened vol db with max slot number " <> showT maxSlotN
forHuman ChainDB.OpenedLgrDB = "Opened lgr db"
forHuman ChainDB.StartedOpeningDB = "Started opening Chain DB"
forHuman ChainDB.StartedOpeningImmutableDB = "Started opening Immutable DB"
Expand All @@ -1198,8 +1206,9 @@ instance ConvertRawHash blk
mconcat [ "kind" .= String "OpenedImmutableDB"
, "immtip" .= forMachine dtal immTip
, "epoch" .= String ((Text.pack . show) epoch) ]
forMachine _dtal ChainDB.OpenedVolatileDB =
mconcat [ "kind" .= String "OpenedVolatileDB" ]
forMachine _dtal (ChainDB.OpenedVolatileDB maxSlotN) =
mconcat [ "kind" .= String "OpenedVolatileDB"
, "maxSlotNo" .= String (showT maxSlotN) ]
forMachine _dtal ChainDB.OpenedLgrDB =
mconcat [ "kind" .= String "OpenedLgrDB" ]
forMachine _dtal ChainDB.StartedOpeningDB =
Expand Down Expand Up @@ -1989,17 +1998,21 @@ instance StandardHash blk => LogFormatting (VolDB.TraceEvent blk) where
mconcat [ "kind" .= String "InvalidFileNames"
, "files" .= String (Text.pack . show $ map show fsPaths)
]
forMachine _dtal VolDB.DBClosed =
mconcat [ "kind" .= String "DBClosed" ]

instance MetaTrace (VolDB.TraceEvent blk) where
namespaceFor VolDB.DBAlreadyClosed {} = Namespace [] ["DBAlreadyClosed"]
namespaceFor VolDB.BlockAlreadyHere {} = Namespace [] ["BlockAlreadyHere"]
namespaceFor VolDB.Truncate {} = Namespace [] ["Truncate"]
namespaceFor VolDB.InvalidFileNames {} = Namespace [] ["InvalidFileNames"]
namespaceFor VolDB.DBClosed {} = Namespace [] ["DBClosed"]

severityFor (Namespace _ ["DBAlreadyClosed"]) _ = Just Debug
severityFor (Namespace _ ["BlockAlreadyHere"]) _ = Just Debug
severityFor (Namespace _ ["Truncate"]) _ = Just Debug
severityFor (Namespace _ ["InvalidFileNames"]) _ = Just Debug
severityFor (Namespace _ ["DBClosed"]) _ = Just Debug
severityFor _ _ = Nothing

documentFor (Namespace _ ["DBAlreadyClosed"]) = Just
Expand All @@ -2010,13 +2023,16 @@ instance MetaTrace (VolDB.TraceEvent blk) where
"Truncates a file up to offset because of the error."
documentFor (Namespace _ ["InvalidFileNames"]) = Just
"Reports a list of invalid file paths."
documentFor (Namespace _ ["DBClosed"]) = Just
"Closing the volatile DB"
documentFor _ = Nothing

allNamespaces =
[ Namespace [] ["DBAlreadyClosed"]
, Namespace [] ["BlockAlreadyHere"]
, Namespace [] ["Truncate"]
, Namespace [] ["InvalidFileNames"]
, Namespace [] ["DBClosed"]
]


Expand Down
13 changes: 6 additions & 7 deletions cardano-node/src/Cardano/Node/Tracing/Tracers/Peer.hs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import Cardano.Logging hiding (traceWith)
import Cardano.Node.Orphans ()
import Cardano.Node.Queries
import Ouroboros.Consensus.Block (Header)
import Ouroboros.Consensus.Util.NormalForm.StrictTVar (StrictTVar, readTVar)
import Ouroboros.Consensus.MiniProtocol.ChainSync.Client (viewChainSyncState, csCandidate)
import Ouroboros.Consensus.Util.Orphans ()
import qualified Ouroboros.Network.AnchoredFragment as Net
import Ouroboros.Network.Block (unSlotNo)
Expand All @@ -33,7 +33,6 @@ import "contra-tracer" Control.Tracer
import Data.Aeson (ToJSON (..), Value (..), toJSON, (.=))
import Data.Functor ((<&>))
import qualified Data.List as List
import Data.Map.Strict (Map)
import qualified Data.Map.Strict as Map
import qualified Data.Set as Set
import Data.Text (Text)
Expand Down Expand Up @@ -101,10 +100,10 @@ getCurrentPeers nkd = mapNodeKernelDataIO extractPeers nkd
tuple3pop :: (a, b, c) -> (a, b)
tuple3pop (a, b, _) = (a, b)

getCandidates
:: StrictTVar IO (Map peer (StrictTVar IO (Net.AnchoredFragment (Header blk))))
-> STM.STM IO (Map peer (Net.AnchoredFragment (Header blk)))
getCandidates var = readTVar var >>= traverse readTVar
-- getCandidates
-- :: StrictTVar IO (Map peer (StrictTVar IO (Net.AnchoredFragment (Header blk))))
-- -> STM.STM IO (Map peer (Net.AnchoredFragment (Header blk)))
getCandidates handle = viewChainSyncState handle csCandidate

extractPeers :: NodeKernel IO RemoteAddress LocalConnectionId blk
-> IO [PeerT blk]
Expand All @@ -114,7 +113,7 @@ getCurrentPeers nkd = mapNodeKernelDataIO extractPeers nkd
. Net.readFetchClientsStateVars
. getFetchClientRegistry $ kernel
)
candidates <- STM.atomically . getCandidates . getNodeCandidates $ kernel
candidates <- STM.atomically . getCandidates . getChainSyncHandles $ kernel

let peers = flip Map.mapMaybeWithKey candidates $ \cid af ->
maybe Nothing
Expand Down
28 changes: 20 additions & 8 deletions cardano-node/src/Cardano/Tracing/OrphanInstances/Consensus.hs
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ instance HasSeverityAnnotation (ChainDB.TraceEvent blk) where
ChainDB.OpenedDB {} -> Info
ChainDB.ClosedDB {} -> Info
ChainDB.OpenedImmutableDB {} -> Info
ChainDB.OpenedVolatileDB -> Info
ChainDB.OpenedVolatileDB {} -> Info
ChainDB.OpenedLgrDB -> Info
ChainDB.StartedOpeningDB -> Info
ChainDB.StartedOpeningImmutableDB -> Info
Expand Down Expand Up @@ -217,6 +217,7 @@ instance HasSeverityAnnotation (ChainDB.TraceEvent blk) where
VolDb.BlockAlreadyHere{} -> Debug
VolDb.Truncate{} -> Error
VolDb.InvalidFileNames{} -> Warning
VolDb.DBClosed{} -> Info

instance HasSeverityAnnotation (LedgerEvent blk) where
getSeverityAnnotation (LedgerUpdate _) = Notice
Expand Down Expand Up @@ -610,7 +611,8 @@ instance ( ConvertRawHash blk
ChainDB.OpenedImmutableDB immTip chunk ->
"Opened imm db with immutable tip at " <> renderPointAsPhrase immTip <>
" and chunk " <> showT chunk
ChainDB.OpenedVolatileDB -> "Opened vol db"
ChainDB.OpenedVolatileDB maxSlotN ->
"Opened vol db with max slot number " <> showT maxSlotN
ChainDB.OpenedLgrDB -> "Opened lgr db"
ChainDB.TraceFollowerEvent ev -> case ev of
ChainDB.NewFollower -> "New follower was created"
Expand Down Expand Up @@ -723,6 +725,7 @@ instance ( ConvertRawHash blk
VolDb.BlockAlreadyHere bh -> "Block " <> showT bh <> " was already in the Volatile DB."
VolDb.Truncate e pth offs -> "Truncating the file at " <> showT pth <> " at offset " <> showT offs <> ": " <> showT e
VolDb.InvalidFileNames fs -> "Invalid Volatile DB files: " <> showT fs
VolDb.DBClosed -> "Closed Volatile DB."
where showProgressT :: Int -> Int -> Text
showProgressT chunkNo outOf =
pack (showFFloat (Just 2) (100 * fromIntegral chunkNo / fromIntegral outOf :: Float) mempty)
Expand Down Expand Up @@ -1000,10 +1003,17 @@ instance ( ConvertRawHash blk
ChainDB.PoppedReprocessLoEBlocksFromQueue ->
mconcat [ "kind" .= String "PoppedReprocessLoEBlocksFromQueue" ]
ChainDB.ChainSelectionLoEDebug curChain loeFrag ->
mconcat [ "kind" .= String "ChainSelectionLoEDebug"
, "curChain" .= headAndAnchor curChain
, "loeFrag" .= headAndAnchor loeFrag
]
case loeFrag of
ChainDB.LoEEnabled loeF ->
mconcat [ "kind" .= String "ChainSelectionLoEDebug"
, "curChain" .= headAndAnchor curChain
, "loeFrag" .= headAndAnchor loeF
]
ChainDB.LoEDisabled ->
mconcat [ "kind" .= String "ChainSelectionLoEDebug"
, "curChain" .= headAndAnchor curChain
, "loeFrag" .= String "LoE is disabled"
]
where
headAndAnchor frag = Aeson.object
[ "anchor" .= renderPointForVerbosity verb (AF.anchorPoint frag)
Expand Down Expand Up @@ -1087,8 +1097,9 @@ instance ( ConvertRawHash blk
mconcat [ "kind" .= String "TraceOpenEvent.OpenedImmutableDB"
, "immtip" .= toObject verb immTip
, "epoch" .= String ((pack . show) epoch) ]
ChainDB.OpenedVolatileDB ->
mconcat [ "kind" .= String "TraceOpenEvent.OpenedVolatileDB" ]
ChainDB.OpenedVolatileDB maxSlotN ->
mconcat [ "kind" .= String "TraceOpenEvent.OpenedVolatileDB"
, "maxSlotNo" .= String (showT maxSlotN) ]
ChainDB.OpenedLgrDB ->
mconcat [ "kind" .= String "TraceOpenEvent.OpenedLgrDB" ]

Expand Down Expand Up @@ -1236,6 +1247,7 @@ instance ( ConvertRawHash blk
mconcat [ "kind" .= String "TraceVolatileDBEvent.InvalidFileNames"
, "files" .= String (Text.pack . show $ map show fsPaths)
]
VolDb.DBClosed -> mconcat [ "kind" .= String "TraceVolatileDbEvent.DBClosed"]

instance ConvertRawHash blk => ToObject (ImmDB.TraceChunkValidation blk ChunkNo) where
toObject verb ev = case ev of
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,7 @@ instance ( ToJSON (BlockNodeToClientVersion x)
instance ToJSON HardForkSpecificNodeToClientVersion where
toJSON HardForkSpecificNodeToClientVersion1 = String "HardForkSpecificNodeToClientVersion1"
toJSON HardForkSpecificNodeToClientVersion2 = String "HardForkSpecificNodeToClientVersion2"
toJSON HardForkSpecificNodeToClientVersion3 = String "HardForkSpecificNodeToClientVersion3"

instance (ToJSON (BlockNodeToClientVersion blk)) => ToJSON (EraNodeToClientVersion blk) where
toJSON EraNodeToClientDisabled = String "EraNodeToClientDisabled"
Expand Down
49 changes: 10 additions & 39 deletions cardano-node/src/Cardano/Tracing/OrphanInstances/Shelley.hs
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,10 @@ import qualified Cardano.Crypto.Hash.Class as Crypto
import qualified Cardano.Crypto.VRF.Class as Crypto
import Cardano.Ledger.Allegra.Rules (AllegraUtxoPredFailure)
import qualified Cardano.Ledger.Allegra.Rules as Allegra
import qualified Cardano.Ledger.Allegra.Scripts as Allegra
import qualified Cardano.Ledger.Alonzo.Plutus.Evaluate as Alonzo
import Cardano.Ledger.Alonzo.Rules (AlonzoBbodyPredFailure (..), AlonzoUtxoPredFailure,
AlonzoUtxosPredFailure, AlonzoUtxowPredFailure (..))
import qualified Cardano.Ledger.Alonzo.Rules as Alonzo
import qualified Cardano.Ledger.Alonzo.Tx as Alonzo
import qualified Cardano.Ledger.Api as Ledger
import Cardano.Ledger.Babbage.Rules (BabbageUtxoPredFailure, BabbageUtxowPredFailure)
import qualified Cardano.Ledger.Babbage.Rules as Babbage
Expand Down Expand Up @@ -78,7 +76,7 @@ import Ouroboros.Consensus.Util.Condense (condense)
import Ouroboros.Network.Block (SlotNo (..), blockHash, blockNo, blockSlot)
import Ouroboros.Network.Point (WithOrigin, withOriginToMaybe)

import Data.Aeson (Value (..), object)
import Data.Aeson (Value (..))
import qualified Data.Aeson as Aeson
import qualified Data.ByteString.Base16 as B16
import qualified Data.List.NonEmpty as NonEmpty
Expand Down Expand Up @@ -398,6 +396,15 @@ instance Ledger.EraPParams era => ToObject (Conway.ConwayGovPredFailure era) whe
, "actualPolicyHash" .= actualPolicyHash
, "expectedPolicyHash" .= expectedPolicyHash
]
toObject _ (Conway.DisallowedProposalDuringBootstrap proposal) =
mconcat [ "kind" .= String "DisallowedProposalDuringBootstrap"
, "proposal" .= proposal
]

toObject _ (Conway.DisallowedVotesDuringBootstrap votes) =
mconcat [ "kind" .= String "DisallowedVotesDuringBootstrap"
, "votes" .= votes
]

instance
( Core.Crypto (Consensus.EraCrypto era)
Expand Down Expand Up @@ -571,16 +578,6 @@ instance
, "addrs" .= addrs
]


instance ToJSON Allegra.ValidityInterval where
toJSON vi =
Aeson.object $
[ "invalidBefore" .= x | x <- mbfield (Allegra.invalidBefore vi) ]
++ [ "invalidHereafter" .= x | x <- mbfield (Allegra.invalidHereafter vi) ]
where
mbfield SNothing = []
mbfield (SJust x) = [x]

instance
( ToObject (Ledger.EraRuleFailure "PPUP" ledgerera)
, ToJSON (Ledger.TxOut ledgerera)
Expand Down Expand Up @@ -1150,32 +1147,6 @@ instance
toObject verb (Alonzo.UpdateFailure pFailure) =
toObject verb pFailure

deriving newtype instance ToJSON Alonzo.IsValid

instance ToJSON Alonzo.TagMismatchDescription where
toJSON tmd = case tmd of
Alonzo.PassedUnexpectedly ->
object
[ "kind" .= String "TagMismatchDescription"
, "error" .= String "PassedUnexpectedly"
]
Alonzo.FailedUnexpectedly forReasons ->
object
[ "kind" .= String "TagMismatchDescription"
, "error" .= String "FailedUnexpectedly"
, "reconstruction" .= forReasons
]

instance ToJSON Alonzo.FailureDescription where
toJSON f = case f of
Alonzo.PlutusFailure t _bs ->
object
[ "kind" .= String "FailureDescription"
, "error" .= String "PlutusFailure"
, "description" .= t
-- , "reconstructionDetail" .= bs
]

instance
( Ledger.Era ledgerera
, Show (PredicateFailure (Ledger.EraRule "LEDGERS" ledgerera))
Expand Down
13 changes: 6 additions & 7 deletions cardano-node/src/Cardano/Tracing/Peer.hs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import Cardano.BM.Tracing
import Cardano.Node.Orphans ()
import Cardano.Node.Queries
import Ouroboros.Consensus.Block (Header)
import Ouroboros.Consensus.Util.NormalForm.StrictTVar (StrictTVar, readTVar)
import Ouroboros.Consensus.MiniProtocol.ChainSync.Client (viewChainSyncState, csCandidate)
import Ouroboros.Consensus.Util.Orphans ()
import qualified Ouroboros.Network.AnchoredFragment as Net
import Ouroboros.Network.Block (unSlotNo)
Expand All @@ -33,7 +33,6 @@ import Control.DeepSeq (NFData (..))
import Data.Aeson (ToJSON (..), Value (..), toJSON, (.=))
import Data.Functor ((<&>))
import qualified Data.List as List
import Data.Map.Strict (Map)
import qualified Data.Map.Strict as Map
import qualified Data.Set as Set
import Data.Text (Text)
Expand Down Expand Up @@ -94,10 +93,10 @@ getCurrentPeers nkd = mapNodeKernelDataIO extractPeers nkd
tuple3pop :: (a, b, c) -> (a, b)
tuple3pop (a, b, _) = (a, b)

getCandidates
:: StrictTVar IO (Map peer (StrictTVar IO (Net.AnchoredFragment (Header blk))))
-> STM.STM IO (Map peer (Net.AnchoredFragment (Header blk)))
getCandidates var = readTVar var >>= traverse readTVar
-- getCandidates
-- :: StrictTVar IO (Map peer (StrictTVar IO (Net.AnchoredFragment (Header blk)))) ->
-- STM.STM IO (Map peer (Net.AnchoredFragment (Header blk)))
getCandidates handle = viewChainSyncState handle csCandidate

extractPeers :: NodeKernel IO RemoteAddress LocalConnectionId blk
-> IO [Peer blk]
Expand All @@ -107,7 +106,7 @@ getCurrentPeers nkd = mapNodeKernelDataIO extractPeers nkd
. Net.readFetchClientsStateVars
. getFetchClientRegistry $ kernel
)
candidates <- STM.atomically . getCandidates . getNodeCandidates $ kernel
candidates <- STM.atomically . getCandidates . getChainSyncHandles $ kernel

let peers = flip Map.mapMaybeWithKey candidates $ \cid af ->
maybe Nothing
Expand Down

0 comments on commit 1e5a8ac

Please sign in to comment.