Skip to content

Commit

Permalink
Update block forging configuration on SIGHUP
Browse files Browse the repository at this point in the history
Block Forging can be enabled/disabled through SIGHUP signal. Sending
such a signal will trigger the node to read the block forging credential
files. Since the credential files are passed via CLI flags one can not
remove them without restarting the node. For this effect, in order for
one to be able to disable block forging, moving/renaming/deleting the
file at the specified path (for the credential flags) and then sending
the SIGHUP signal is what needs to be done. The code will detect that
the specified files do not exist and it will disable block forging,
while tracing the appropriate log messages.

In case one wants to start a block producing node (i.e. passing the
credentials in the respective flags) but doesn't want it to actually
behave as a BP, there's a new `--start-as-non-producing-node` flag that
will run the node with credentials as a normal node. However on SIGHUP
it will read the credential files and start forging.

Refactor code to accomodate the changes

Added EnabledBlockForging type

Co-authored-by: Marcin Szamotulski <coot@coot.me>
  • Loading branch information
bolt12 and coot committed Jun 30, 2023
1 parent ef82613 commit 9350e00
Show file tree
Hide file tree
Showing 6 changed files with 199 additions and 61 deletions.
8 changes: 8 additions & 0 deletions cardano-node/src/Cardano/Node/Configuration/POM.hs
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ data NodeConfiguration
, ncValidateDB :: !Bool
, ncShutdownConfig :: !ShutdownConfig

, ncStartAsNonProducingNode :: !Bool

-- Protocol-specific parameters:
, ncProtocolConfig :: !NodeProtocolConfiguration

Expand Down Expand Up @@ -159,6 +161,8 @@ data PartialNodeConfiguration
, pncValidateDB :: !(Last Bool)
, pncShutdownConfig :: !(Last ShutdownConfig)

, pncStartAsNonProducingNode :: !(Last Bool)

-- Protocol-specific parameters:
, pncProtocolConfig :: !(Last NodeProtocolConfiguration)

Expand Down Expand Up @@ -309,6 +313,7 @@ instance FromJSON PartialNodeConfiguration where
, pncProtocolFiles = mempty
, pncValidateDB = mempty
, pncShutdownConfig = mempty
, pncStartAsNonProducingNode = Last $ Just False
, pncMaybeMempoolCapacityOverride
, pncProtocolIdleTimeout
, pncTimeWaitTimeout
Expand Down Expand Up @@ -466,6 +471,7 @@ defaultPartialNodeConfiguration =
, pncProtocolFiles = mempty
, pncValidateDB = Last $ Just False
, pncShutdownConfig = Last . Just $ ShutdownConfig Nothing Nothing
, pncStartAsNonProducingNode = Last $ Just False
, pncProtocolConfig = mempty
, pncMaxConcurrencyBulkSync = mempty
, pncMaxConcurrencyDeadline = mempty
Expand Down Expand Up @@ -500,6 +506,7 @@ makeNodeConfiguration pnc = do
topologyFile <- lastToEither "Missing TopologyFile" $ pncTopologyFile pnc
databaseFile <- lastToEither "Missing DatabaseFile" $ pncDatabaseFile pnc
validateDB <- lastToEither "Missing ValidateDB" $ pncValidateDB pnc
startAsNonProducingNode <- lastToEither "Missing StartAsNonProducingNode" $ pncStartAsNonProducingNode pnc
protocolConfig <- lastToEither "Missing ProtocolConfig" $ pncProtocolConfig pnc
loggingSwitch <- lastToEither "Missing LoggingSwitch" $ pncLoggingSwitch pnc
logMetrics <- lastToEither "Missing LogMetrics" $ pncLogMetrics pnc
Expand Down Expand Up @@ -555,6 +562,7 @@ makeNodeConfiguration pnc = do
Nothing -> ProtocolFilepaths Nothing Nothing Nothing Nothing Nothing Nothing
, ncValidateDB = validateDB
, ncShutdownConfig = shutdownConfig
, ncStartAsNonProducingNode = startAsNonProducingNode
, ncProtocolConfig = protocolConfig
, ncSocketConfig = socketConfig
, ncDiffusionMode = diffusionMode
Expand Down
10 changes: 10 additions & 0 deletions cardano-node/src/Cardano/Node/Parsers.hs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ nodeRunParser = do
shelleyVRFFile <- optional parseVrfKeyFilePath
shelleyCertFile <- optional parseOperationalCertFilePath
shelleyBulkCredsFile <- optional parseBulkCredsFilePath
startAsNonProducingNode <- lastOption parseStartAsNonProducingNode

-- Node Address
nIPv4Address <- lastOption parseHostIPv4Addr
Expand Down Expand Up @@ -102,6 +103,7 @@ nodeRunParser = do
, pncValidateDB = validate
, pncShutdownConfig =
Last . Just $ ShutdownConfig (getLast shutdownIPC) (getLast shutdownOnLimit)
, pncStartAsNonProducingNode = startAsNonProducingNode
, pncProtocolConfig = mempty
, pncMaxConcurrencyBulkSync = mempty
, pncMaxConcurrencyDeadline = mempty
Expand Down Expand Up @@ -313,6 +315,14 @@ parseVrfKeyFilePath =
<> completer (bashCompleter "file")
)

parseStartAsNonProducingNode :: Parser Bool
parseStartAsNonProducingNode =
switch (
long "start-as-non-producing-node"
<> help ("Start the node as a non block producing node even if "
++ "credentials are specified.")
)

-- TODO revisit because it sucks
parseSnapshotInterval :: Parser SnapshotInterval
parseSnapshotInterval = fmap (RequestedSnapshotInterval . secondsToDiffTime) parseDifftime
Expand Down
Loading

0 comments on commit 9350e00

Please sign in to comment.