Skip to content

Commit

Permalink
cardano-tracer: Eliminate cardano-node dependency.
Browse files Browse the repository at this point in the history
  • Loading branch information
Icelandjack committed Mar 3, 2025
1 parent 6d25d88 commit d24c23d
Show file tree
Hide file tree
Showing 3 changed files with 124 additions and 121 deletions.
92 changes: 0 additions & 92 deletions cardano-node/src/Cardano/Node/Startup.hs
Original file line number Diff line number Diff line change
Expand Up @@ -169,98 +169,6 @@ data BasicInfoNetwork = BasicInfoNetwork {
, niIpProducers :: IPSubscriptionTarget
}

data NodeInfo = NodeInfo
{ niName :: Text
, niProtocol :: Text
, niVersion :: Text
, niCommit :: Text
, niStartTime :: UTCTime
, niSystemStartTime :: UTCTime
} deriving (Eq, Generic, ToJSON, FromJSON, Show)

deriving instance (NFData NodeInfo)

instance MetaTrace NodeInfo where
namespaceFor NodeInfo {} =
Namespace [] ["NodeInfo"]
severityFor (Namespace _ ["NodeInfo"]) _ =
Just Info
severityFor _ns _ =
Nothing
documentFor (Namespace _ ["NodeInfo"]) = Just
"Basic information about this node collected at startup\
\\n\
\\n _niName_: Name of the node. \
\\n _niProtocol_: Protocol which this nodes uses. \
\\n _niVersion_: Software version which this node is using. \
\\n _niStartTime_: Start time of this node. \
\\n _niSystemStartTime_: How long did the start of the node took."
documentFor _ns =
Nothing
allNamespaces = [ Namespace [] ["NodeInfo"]]


-- | Prepare basic info about the node. This info will be sent to 'cardano-tracer'.
prepareNodeInfo
:: NodeConfiguration
-> SomeConsensusProtocol
-> TraceConfig
-> UTCTime
-> IO NodeInfo
prepareNodeInfo nc (SomeConsensusProtocol whichP pForInfo) tc nodeStartTime = do
nodeName <- prepareNodeName
return $ NodeInfo
{ niName = nodeName
, niProtocol = pack . show . ncProtocol $ nc
, niVersion = pack . showVersion $ version
, niCommit = $(gitRev)
, niStartTime = nodeStartTime
, niSystemStartTime = systemStartTime
}
where
cfg = pInfoConfig $ fst $ Api.protocolInfo @IO pForInfo

systemStartTime :: UTCTime
systemStartTime =
case whichP of
Api.ByronBlockType ->
getSystemStartByron
Api.ShelleyBlockType ->
let DegenLedgerConfig cfgShelley = configLedger cfg
in getSystemStartShelley cfgShelley
Api.CardanoBlockType ->
let CardanoLedgerConfig _ cfgShelley cfgAllegra cfgMary cfgAlonzo cfgBabbage cfgConway = configLedger cfg
in minimum [ getSystemStartByron
, getSystemStartShelley cfgShelley
, getSystemStartShelley cfgAllegra
, getSystemStartShelley cfgMary
, getSystemStartShelley cfgAlonzo
, getSystemStartShelley cfgBabbage
, getSystemStartShelley cfgConway
]

getSystemStartByron = WCT.getSystemStart . getSystemStart . configBlock $ cfg
getSystemStartShelley = sgSystemStart . shelleyLedgerGenesis . shelleyLedgerConfig

prepareNodeName =
case tcNodeName tc of
Just aName -> return aName
Nothing -> do
-- The user didn't specify node's name in the configuration.
-- In this case we should form node's name as "host_port",
-- where 'host' is the machine's host name and 'port' is taken
-- from the '--port' CLI-parameter.

let suffix :: String
suffix
| SocketConfig{ncNodePortNumber = Last (Just port)} <- ncSocketConfig nc
= "_" <> show port
| otherwise
= ""

hostName <- getHostName
return (pack (hostName <> suffix))

-- | This information is taken from 'BasicInfoShelleyBased'. It is required for
-- 'cardano-tracer' service (particularly, for RTView).
data NodeStartupInfo = NodeStartupInfo {
Expand Down
2 changes: 1 addition & 1 deletion cardano-tracer/cardano-tracer.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ library
, bimap
, blaze-html
, bytestring
, cardano-node
-- , cardano-node
, cborg
, containers
, contra-tracer
Expand Down
Loading

0 comments on commit d24c23d

Please sign in to comment.