Skip to content

Commit

Permalink
Update p2p topology configuration via the SIGHUP signal
Browse files Browse the repository at this point in the history
  • Loading branch information
bolt12 authored and coot committed Nov 30, 2021
1 parent e02fafb commit 43dabd2
Showing 1 changed file with 52 additions and 0 deletions.
52 changes: 52 additions & 0 deletions cardano-node/src/Cardano/Node/Run.hs
Expand Up @@ -38,6 +38,7 @@ 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
Expand Down Expand Up @@ -337,6 +338,15 @@ handleSimpleNode scp runP p2pMode trace nodeTracers nc onKernel = do
(localRootsVar :: StrictTVar IO [(Int, Map RelayAccessPoint PeerAdvertise)]) <- newTVarIO localRoots
publicRootsVar <- newTVarIO publicRoots
useLedgerVar <- newTVarIO (useLedgerAfterSlot nt)
#ifdef UNIX
_ <- Signals.installHandler
Signals.sigHUP
(updateTopologyConfiguration meta localRootsVar publicRootsVar useLedgerVar)
Nothing
traceNamedObject
(appendName "signal-handler" trace)
(meta, LogMessage (Text.pack "Installed signal handler"))
#endif
void $
Node.run
nodeArgs
Expand Down Expand Up @@ -426,6 +436,48 @@ handleSimpleNode scp runP p2pMode trace nodeTracers nc onKernel = do
forM_ basicInfoItems $ \(LogObject nm mt content) ->
traceNamedObject (appendName nm tr) (mt, content)

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

result <- try $ readTopologyFileOrError nc

case result of
Left (FatalError err) ->
traceNamedObject
(appendName "topology-file" trace)
(meta, LogMessage (Text.pack "Error reading topology configuration file:" <> err))
Right nt -> do
traceNamedObject
(appendName "topology-file" trace)
(meta, LogMessage (Text.pack "Successfully read topology configuration file"))

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

0 comments on commit 43dabd2

Please sign in to comment.