Skip to content
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

cardano-node: provide default node name #4366

Merged
merged 1 commit into from
Aug 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 15 additions & 5 deletions cardano-node/src/Cardano/Node/Startup.hs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import Prelude

import Data.Aeson (FromJSON, ToJSON)
import Data.Map (Map)
import Data.Monoid (Last (..), getLast)
import Data.Text (Text, pack)
import Data.Time.Clock (NominalDiffTime, UTCTime)
import Data.Version (showVersion)
Expand Down Expand Up @@ -45,8 +46,9 @@ import Ouroboros.Network.Subscription.Ip (IPSubscriptionTarget (..))

import Cardano.Api.Protocol.Types (BlockType (..), protocolInfo)
import Cardano.Logging
import Cardano.Node.Configuration.POM (NodeConfiguration (..), ncProtocol)
import Cardano.Node.Configuration.Socket
import Cardano.Node.Protocol.Types (Protocol (..), SomeConsensusProtocol (..))
import Cardano.Node.Protocol.Types (SomeConsensusProtocol (..))

import Cardano.Git.Rev (gitRev)
import Paths_cardano_node (version)
Expand Down Expand Up @@ -166,16 +168,16 @@ docNodeInfoTraceEvent = Documented [

-- | Prepare basic info about the node. This info will be sent to 'cardano-tracer'.
prepareNodeInfo
:: Protocol
:: NodeConfiguration
-> SomeConsensusProtocol
-> TraceConfig
-> UTCTime
-> IO NodeInfo
prepareNodeInfo ptcl (SomeConsensusProtocol whichP pForInfo) tc nodeStartTime = do
prepareNodeInfo nc (SomeConsensusProtocol whichP pForInfo) tc nodeStartTime = do
nodeName <- prepareNodeName
return $ NodeInfo
{ niName = nodeName
, niProtocol = pack . show $ ptcl
, niProtocol = pack . show . ncProtocol $ nc
, niVersion = pack . showVersion $ version
, niCommit = gitRev
, niStartTime = nodeStartTime
Expand Down Expand Up @@ -208,7 +210,15 @@ prepareNodeInfo ptcl (SomeConsensusProtocol whichP pForInfo) tc nodeStartTime =
prepareNodeName =
case tcNodeName tc of
Just aName -> return aName
Nothing -> pack <$> getHostName
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' and 'port'
-- are taken from '--host-addr' and '--port' CLI-parameters correspondingly.
let SocketConfig hostIPv4 hostIPv6 port _ = ncSocketConfig nc
hostName <- case (show <$> hostIPv6) <> (show <$> hostIPv4) of
Last (Just addr) -> return addr
Last Nothing -> getHostName
return . pack $ hostName <> maybe "" ((":" ++) . show) (getLast port)

-- | This information is taken from 'BasicInfoShelleyBased'. It is required for
-- 'cardano-tracer' service (particularly, for RTView).
Expand Down
5 changes: 2 additions & 3 deletions cardano-node/src/Cardano/Node/Tracing/API.hs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import Ouroboros.Network.NodeToClient (withIOManager)
import Ouroboros.Network.NodeToNode (RemoteAddress)

import Cardano.Node.Configuration.NodeAddress (SocketPath (..))
import Cardano.Node.Configuration.POM (NodeConfiguration (..), ncProtocol)
import Cardano.Node.Configuration.POM (NodeConfiguration (..))
import Cardano.Node.Protocol.Types
import Cardano.Node.Queries
import Cardano.Node.Startup
Expand Down Expand Up @@ -76,8 +76,7 @@ initTraceDispatcher nc p networkMagic nodeKernel p2pMode = do
(fromMaybe 2000 (tcPeerFrequency trConfig))

now <- getCurrentTime
prepareNodeInfo (ncProtocol nc) p trConfig now
>>= traceWith (nodeInfoTracer tracers)
prepareNodeInfo nc p trConfig now >>= traceWith (nodeInfoTracer tracers)

pure tracers
where
Expand Down