Skip to content

Commit

Permalink
Topology configuration update via unix signals!
Browse files Browse the repository at this point in the history
Updated Network Topology configuration to use optional top level fields

Added tracing to signal handler local config changes

Added explanation on how to update local configuration on the fly to the docs
  • Loading branch information
bolt12 authored and coot committed May 13, 2021
1 parent ec983a5 commit 27fe0cb
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 6 deletions.
6 changes: 3 additions & 3 deletions cardano-node/src/Cardano/Node/Configuration/TopologyP2P.hs
Expand Up @@ -144,9 +144,9 @@ data NetworkTopology = RealNodeTopology !LocalRootPeersGroups ![PublicRootPeers]

instance FromJSON NetworkTopology where
parseJSON = withObject "NetworkTopology" $ \o ->
RealNodeTopology <$> o .: "LocalRoots"
<*> o .: "PublicRoots"
<*> (o .:? "useLedgerAfterSlot" .!= (UseLedger DontUseLedger))
RealNodeTopology <$> (o .:? "LocalRoots" .!= LocalRootPeersGroups [])
<*> (o .:? "PublicRoots" .!= [])
<*> (o .:? "useLedgerAfterSlot" .!= UseLedger DontUseLedger)

instance ToJSON NetworkTopology where
toJSON top =
Expand Down
49 changes: 48 additions & 1 deletion cardano-node/src/Cardano/Node/Run.hs
Expand Up @@ -36,12 +36,13 @@ import System.Environment (lookupEnv)
#ifdef UNIX
import System.Posix.Files
import System.Posix.Types (FileMode)
import qualified System.Posix.Signals as Signals
#else
import System.Win32.File
#endif

import Cardano.BM.Data.LogItem (LOContent (..), LogObject (..), PrivacyAnnotation (..),
mkLOMeta)
mkLOMeta, LOMeta)
import Cardano.BM.Data.Tracer (ToLogObject (..), TracingVerbosity (..))
import Cardano.BM.Data.Transformers (setHostname)
import Cardano.BM.Trace
Expand Down Expand Up @@ -230,6 +231,16 @@ handleSimpleNode p trace nodeTracers nc onKernel = do
publicRootsVar <- newTVarIO publicRoots
useLedgerVar <- newTVarIO (useLedgerAfterSlot nt)

#ifdef UNIX
_ <- Signals.installHandler
Signals.sigHUP
(updateVars meta localRootsVar publicRootsVar useLedgerVar)
Nothing
#endif
traceNamedObject
(appendName "signal-handler" trace)
(meta, LogMessage (Text.pack "Installed signal handler"))

let
diffusionArguments :: DiffusionArguments IO
diffusionArguments =
Expand Down Expand Up @@ -257,6 +268,9 @@ handleSimpleNode p trace nodeTracers nc onKernel = do
traceNamedObject
(appendName "public-roots" trace)
(meta, LogMessage . Text.pack . show $ publicRoots)
traceNamedObject
(appendName "use-ledger-after-slot" trace)
(meta, LogMessage . Text.pack . show $ useLedgerAfterSlot nt)
traceNamedObject
(appendName "local-socket" trace)
(meta, LogMessage . Text.pack . show $ localSocketOrPath)
Expand Down Expand Up @@ -315,6 +329,39 @@ handleSimpleNode p trace nodeTracers nc onKernel = do
forM_ basicInfoItems $ \(LogObject nm mt content) ->
traceNamedObject (appendName nm tr) (mt, content)

#ifdef UNIX
updateVars :: LOMeta
-> StrictTVar IO [(Int, Map RelayAddress PeerAdvertise)]
-> StrictTVar IO [RelayAddress]
-> StrictTVar IO UseLedgerAfter
-> Signals.Handler
updateVars meta localRootsVar publicRootsVar useLedgerVar =
Signals.Catch $ do
traceNamedObject
(appendName "signal-handler" trace)
(meta, LogMessage (Text.pack "SIGHUP signal received - Performing topology configuration update"))

eitherTopology <- readTopologyFile nc
nt <- either (\err -> panic $ "Cardano.Node.Run.handleSimpleNode.readTopologyFile: " <> err) pure eitherTopology

let (localRoots, publicRoots) = producerAddresses nt

atomically $ do
writeTVar localRootsVar localRoots
writeTVar publicRootsVar publicRoots
writeTVar useLedgerVar (useLedgerAfterSlot nt)

traceNamedObject
(appendName "local-roots" trace)
(meta, LogMessage . Text.pack . show $ localRoots)
traceNamedObject
(appendName "public-roots" trace)
(meta, LogMessage . Text.pack . show $ publicRoots)
traceNamedObject
(appendName "use-ledger-after-slot" trace)
(meta, LogMessage . Text.pack . show $ useLedgerAfterSlot nt)
#endif

--------------------------------------------------------------------------------
-- Helper functions
--------------------------------------------------------------------------------
Expand Down
7 changes: 5 additions & 2 deletions doc/getting-started/understanding-config-files.md
Expand Up @@ -50,12 +50,15 @@ Tells your node to which nodes in the network it should talk to. A minimal versi
dns domain `y.y.y.y` (assuming they are), and try to maintain a connection with at least `1` of the
resolved ips.

* `isDomain` tells if a given address is a dns address or not. If true and object `domain: { domain, port }` should be specified instead.

* `valency` tells the node how many connections your node should try to pick from the given group. If a dns address is given, valency governs to how many resolved ip addresses should we maintain active (hot) connection.

Your __block-producing__ node must __ONLY__ talk to your __relay nodes__, and the relay node should talk to other relay nodes in the network.

You __can__ tell the node that the topology configuration file changed by sending a SIGHUP
signal to the `cardano-node` process, e.g. `pkill -HUP cardano-node`. After receiving the
signal, `cardano-node` will re-read the file and restart all dns resolution. Please
**note** that this only applies to the topology configuration file!

#### The genesis.json file

The genesis file is generated with the `cardano-cli` by reading a `genesis.spec.json` file, which is out of scope for this document.
Expand Down

0 comments on commit 27fe0cb

Please sign in to comment.