Skip to content

Commit f0e43cd

Browse files
cootJimbo4350
authored andcommitted
StartAsNonProducingNode: configuration option
The configuration option `StartAsNonProducingNode` was ignored, one could only use the switch `--non-producing-node` to set it. In this patch we fix this, and now it can be set either with the switch or if it's not given, it can be set in the configuration file.
1 parent 32510c3 commit f0e43cd

File tree

2 files changed

+18
-7
lines changed

2 files changed

+18
-7
lines changed

cardano-node/src/Cardano/Node/Configuration/POM.hs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,7 @@ instance Semigroup PartialNodeConfiguration where
314314
instance FromJSON PartialNodeConfiguration where
315315
parseJSON =
316316
withObject "PartialNodeConfiguration" $ \v -> do
317+
pncStartAsNonProducingNode <- Last <$> v .:? "StartAsNonProducingNode"
317318

318319
-- Node parameters, not protocol-specific
319320
pncSocketPath <- Last <$> v .:? "SocketPath"
@@ -435,7 +436,7 @@ instance FromJSON PartialNodeConfiguration where
435436
, pncProtocolFiles = mempty
436437
, pncValidateDB = mempty
437438
, pncShutdownConfig = mempty
438-
, pncStartAsNonProducingNode = Last $ Just False
439+
, pncStartAsNonProducingNode
439440
, pncMaybeMempoolCapacityOverride
440441
, pncLedgerDbConfig
441442
, pncProtocolIdleTimeout

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

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,11 @@ import Data.Foldable
2727
import Data.Maybe (fromMaybe)
2828
import Data.Monoid (Last (..))
2929
import Data.Text (Text)
30-
import Data.Word (Word32)
31-
import Options.Applicative hiding (str)
30+
import qualified Data.Text as Text
31+
import Data.Word (Word16, Word32)
32+
import Options.Applicative hiding (str, switch)
33+
-- Don't use switch. It will not allow to set an option in a configuration
34+
-- file. See `parseStartAsNonProducingNode` and `parseValidateDB`.
3235
import qualified Options.Applicative as Opt
3336
import qualified Options.Applicative.Help as OptI
3437
import System.Posix.Types (Fd (..))
@@ -60,7 +63,7 @@ nodeRunParser = do
6063
shelleyVRFFile <- optional parseVrfKeyFilePath
6164
shelleyCertFile <- optional parseOperationalCertFilePath
6265
shelleyBulkCredsFile <- optional parseBulkCredsFilePath
63-
startAsNonProducingNode <- lastOption parseStartAsNonProducingNode
66+
startAsNonProducingNode <- Last <$> parseStartAsNonProducingNode
6467

6568
-- Node Address
6669
nIPv4Address <- lastOption parseHostIPv4Addr
@@ -266,9 +269,13 @@ parseImmutableDbPath = strOption $
266269
]
267270

268271

272+
-- | This parser will always override configuration option, even if the
273+
-- `--validate-db` is not present. This is fine for `--validate-db` switch,
274+
-- but might not be for something else. See `parseStartAsNonProducingNode` for
275+
-- an alternative solution.
269276
parseValidateDB :: Parser Bool
270277
parseValidateDB =
271-
switch (
278+
Opt.switch (
272279
long "validate-db"
273280
<> help "Validate all on-disk database files"
274281
)
@@ -353,9 +360,12 @@ parseVrfKeyFilePath =
353360
<> completer (bashCompleter "file")
354361
)
355362

356-
parseStartAsNonProducingNode :: Parser Bool
363+
-- | A parser which returns `Nothing` or `Just True`; the default value is set
364+
-- in `defaultPartialNodeConfiguration`. This allows to set this option either
365+
-- in the configuration file or as command line flag.
366+
parseStartAsNonProducingNode :: Parser (Maybe Bool)
357367
parseStartAsNonProducingNode =
358-
switch $ mconcat
368+
flag Nothing (Just True) $ mconcat
359369
[ long "non-producing-node"
360370
, help $ mconcat
361371
[ "Start the node as a non block producing node even if "

0 commit comments

Comments
 (0)