Skip to content

Commit

Permalink
cardano-node | shutdown: suggested nomenclature changes & other downs…
Browse files Browse the repository at this point in the history
…tream changes
  • Loading branch information
deepfire committed Jun 3, 2022
1 parent ff76b5b commit b05d8f6
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 17 deletions.
28 changes: 14 additions & 14 deletions cardano-node/src/Cardano/Node/Handlers/Shutdown.hs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
{-# OPTIONS_GHC -Wno-orphans #-}

module Cardano.Node.Handlers.Shutdown
( SlotOrBlock (..)
, parseShutdownOnLimit
( ShutdownOn (..)
, parseShutdownOn

-- * Generalised shutdown handling
, ShutdownConfig (..)
Expand Down Expand Up @@ -46,17 +46,17 @@ import Ouroboros.Consensus.Util.STM (Watcher (..), forkLinkedWatcher)
import Ouroboros.Network.Block (BlockNo (..), HasHeader, SlotNo (..), pointSlot)


data SlotOrBlock
data ShutdownOn
= ASlot !SlotNo
| ABlock !BlockNo
| NoShutdownOnSlotOrBlock
| NoShutdown
deriving (Generic, Eq, Show)

deriving instance FromJSON SlotOrBlock
deriving instance ToJSON SlotOrBlock
deriving instance FromJSON ShutdownOn
deriving instance ToJSON ShutdownOn

parseShutdownOnLimit :: Opt.Parser SlotOrBlock
parseShutdownOnLimit =
parseShutdownOn :: Opt.Parser ShutdownOn
parseShutdownOn =
Opt.option (ASlot . SlotNo <$> Opt.auto) (
Opt.long "shutdown-on-slot-synced"
<> Opt.metavar "SLOT"
Expand All @@ -70,7 +70,7 @@ parseShutdownOnLimit =
<> Opt.help "Shut down the process after ChainDB is synced up to the specified block"
<> Opt.hidden
)
<|> pure NoShutdownOnSlotOrBlock
<|> pure NoShutdown

data ShutdownTrace
= ShutdownRequested
Expand All @@ -81,7 +81,7 @@ data ShutdownTrace
-- ^ Received shutdown request but found unexpected input in --shutdown-ipc FD:
| RequestingShutdown Text
-- ^ Ringing the node shutdown doorbell for reason
| ShutdownArmedAt SlotOrBlock
| ShutdownArmedAt ShutdownOn
-- ^ Will terminate upon reaching a ChainDB sync limit
deriving (Generic, FromJSON, ToJSON)

Expand All @@ -98,7 +98,7 @@ deriving instance Eq AndWithOrigin
data ShutdownConfig
= ShutdownConfig
{ scIPC :: !(Maybe Fd)
, scOnSyncLimit :: !(Maybe SlotOrBlock)
, scOnSyncLimit :: !(Maybe ShutdownOn)
}
deriving (Eq, Show)

Expand Down Expand Up @@ -145,16 +145,16 @@ maybeSpawnOnSlotSyncedShutdownHandler sc tr registry chaindb =
traceWith tr (ShutdownArmedAt lim)
spawnLimitTerminator lim
where
spawnLimitTerminator :: SlotOrBlock -> IO ()
spawnLimitTerminator :: ShutdownOn -> IO ()
spawnLimitTerminator limit =
void $ forkLinkedWatcher registry "slotLimitTerminator" Watcher {
wFingerprint = id
wFingerprint = identity
, wInitial = Nothing
, wReader =
case limit of
ASlot x -> AndWithOriginSlot . (x,) . pointSlot <$> ChainDB.getTipPoint chaindb
ABlock x -> AndWithOriginBlock . (x,) <$> ChainDB.getTipBlockNo chaindb
NoShutdownOnSlotOrBlock -> return WithoutOrigin
NoShutdown -> return WithoutOrigin
, wNotify = \case
(AndWithOriginSlot (lim, At cur)) ->
when (cur >= lim) $ do
Expand Down
2 changes: 1 addition & 1 deletion cardano-node/src/Cardano/Node/Parsers.hs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ nodeRunParser = do

validate <- lastOption parseValidateDB
shutdownIPC <- lastOption parseShutdownIPC
shutdownOnLimit <- lastOption parseShutdownOnLimit
shutdownOnLimit <- lastOption parseShutdownOn

maybeMempoolCapacityOverride <- lastOption parseMempoolCapacityOverride

Expand Down
4 changes: 2 additions & 2 deletions cardano-node/test/Test/Cardano/Node/POM.hs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ testPartialCliConfig :: PartialNodeConfiguration
testPartialCliConfig =
PartialNodeConfiguration
{ pncSocketConfig = Last . Just $ SocketConfig mempty mempty mempty mempty
, pncShutdownConfig = Last . Just $ ShutdownConfig Nothing (Just . ASlot . Identity $ SlotNo 42)
, pncShutdownConfig = Last . Just $ ShutdownConfig Nothing (Just . ASlot $ SlotNo 42)
, pncConfigFile = mempty
, pncTopologyFile = mempty
, pncDatabaseFile = mempty
Expand Down Expand Up @@ -117,7 +117,7 @@ eExpectedConfig = do
(return $ PartialTracingOnLegacy defaultPartialTraceConfiguration)
return $ NodeConfiguration
{ ncSocketConfig = SocketConfig mempty mempty mempty mempty
, ncShutdownConfig = ShutdownConfig Nothing (Just . ASlot . Identity $ SlotNo 42)
, ncShutdownConfig = ShutdownConfig Nothing (Just . ASlot $ SlotNo 42)
, ncConfigFile = ConfigYamlFilePath "configuration/cardano/mainnet-config.json"
, ncTopologyFile = TopologyFile "configuration/cardano/mainnet-topology.json"
, ncDatabaseFile = DbFile "mainnet/db/"
Expand Down

0 comments on commit b05d8f6

Please sign in to comment.