Skip to content

Commit

Permalink
Merge #4366
Browse files Browse the repository at this point in the history
4366: cardano-node: provide default node name r=deepfire a=denisshevchenko

Closes #4364 

Co-authored-by: Denis Shevchenko <[email protected]>
  • Loading branch information
iohk-bors[bot] and Denis Shevchenko authored Aug 24, 2022
2 parents 0681cde + 9f28213 commit e409603
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 8 deletions.
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

0 comments on commit e409603

Please sign in to comment.