Skip to content

Commit e409603

Browse files
iohk-bors[bot]Denis Shevchenko
and
Denis Shevchenko
authored
Merge #4366
4366: cardano-node: provide default node name r=deepfire a=denisshevchenko Closes #4364 Co-authored-by: Denis Shevchenko <[email protected]>
2 parents 0681cde + 9f28213 commit e409603

File tree

2 files changed

+17
-8
lines changed

2 files changed

+17
-8
lines changed

cardano-node/src/Cardano/Node/Startup.hs

+15-5
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import Prelude
1111

1212
import Data.Aeson (FromJSON, ToJSON)
1313
import Data.Map (Map)
14+
import Data.Monoid (Last (..), getLast)
1415
import Data.Text (Text, pack)
1516
import Data.Time.Clock (NominalDiffTime, UTCTime)
1617
import Data.Version (showVersion)
@@ -45,8 +46,9 @@ import Ouroboros.Network.Subscription.Ip (IPSubscriptionTarget (..))
4546

4647
import Cardano.Api.Protocol.Types (BlockType (..), protocolInfo)
4748
import Cardano.Logging
49+
import Cardano.Node.Configuration.POM (NodeConfiguration (..), ncProtocol)
4850
import Cardano.Node.Configuration.Socket
49-
import Cardano.Node.Protocol.Types (Protocol (..), SomeConsensusProtocol (..))
51+
import Cardano.Node.Protocol.Types (SomeConsensusProtocol (..))
5052

5153
import Cardano.Git.Rev (gitRev)
5254
import Paths_cardano_node (version)
@@ -166,16 +168,16 @@ docNodeInfoTraceEvent = Documented [
166168

167169
-- | Prepare basic info about the node. This info will be sent to 'cardano-tracer'.
168170
prepareNodeInfo
169-
:: Protocol
171+
:: NodeConfiguration
170172
-> SomeConsensusProtocol
171173
-> TraceConfig
172174
-> UTCTime
173175
-> IO NodeInfo
174-
prepareNodeInfo ptcl (SomeConsensusProtocol whichP pForInfo) tc nodeStartTime = do
176+
prepareNodeInfo nc (SomeConsensusProtocol whichP pForInfo) tc nodeStartTime = do
175177
nodeName <- prepareNodeName
176178
return $ NodeInfo
177179
{ niName = nodeName
178-
, niProtocol = pack . show $ ptcl
180+
, niProtocol = pack . show . ncProtocol $ nc
179181
, niVersion = pack . showVersion $ version
180182
, niCommit = gitRev
181183
, niStartTime = nodeStartTime
@@ -208,7 +210,15 @@ prepareNodeInfo ptcl (SomeConsensusProtocol whichP pForInfo) tc nodeStartTime =
208210
prepareNodeName =
209211
case tcNodeName tc of
210212
Just aName -> return aName
211-
Nothing -> pack <$> getHostName
213+
Nothing -> do
214+
-- The user didn't specify node's name in the configuration.
215+
-- In this case we should form node's name as "host:port", where 'host' and 'port'
216+
-- are taken from '--host-addr' and '--port' CLI-parameters correspondingly.
217+
let SocketConfig hostIPv4 hostIPv6 port _ = ncSocketConfig nc
218+
hostName <- case (show <$> hostIPv6) <> (show <$> hostIPv4) of
219+
Last (Just addr) -> return addr
220+
Last Nothing -> getHostName
221+
return . pack $ hostName <> maybe "" ((":" ++) . show) (getLast port)
212222

213223
-- | This information is taken from 'BasicInfoShelleyBased'. It is required for
214224
-- 'cardano-tracer' service (particularly, for RTView).

cardano-node/src/Cardano/Node/Tracing/API.hs

+2-3
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ import Ouroboros.Network.NodeToClient (withIOManager)
3030
import Ouroboros.Network.NodeToNode (RemoteAddress)
3131

3232
import Cardano.Node.Configuration.NodeAddress (SocketPath (..))
33-
import Cardano.Node.Configuration.POM (NodeConfiguration (..), ncProtocol)
33+
import Cardano.Node.Configuration.POM (NodeConfiguration (..))
3434
import Cardano.Node.Protocol.Types
3535
import Cardano.Node.Queries
3636
import Cardano.Node.Startup
@@ -76,8 +76,7 @@ initTraceDispatcher nc p networkMagic nodeKernel p2pMode = do
7676
(fromMaybe 2000 (tcPeerFrequency trConfig))
7777

7878
now <- getCurrentTime
79-
prepareNodeInfo (ncProtocol nc) p trConfig now
80-
>>= traceWith (nodeInfoTracer tracers)
79+
prepareNodeInfo nc p trConfig now >>= traceWith (nodeInfoTracer tracers)
8180

8281
pure tracers
8382
where

0 commit comments

Comments
 (0)