From b05d8f6433d2682e411a12e40681802498f4959f Mon Sep 17 00:00:00 2001 From: Kosyrev Serge Date: Fri, 3 Jun 2022 03:18:36 +0300 Subject: [PATCH] cardano-node | shutdown: suggested nomenclature changes & other downstream changes --- .../src/Cardano/Node/Handlers/Shutdown.hs | 28 +++++++++---------- cardano-node/src/Cardano/Node/Parsers.hs | 2 +- cardano-node/test/Test/Cardano/Node/POM.hs | 4 +-- 3 files changed, 17 insertions(+), 17 deletions(-) diff --git a/cardano-node/src/Cardano/Node/Handlers/Shutdown.hs b/cardano-node/src/Cardano/Node/Handlers/Shutdown.hs index 01568c6e1f1..b7ab8c163c1 100644 --- a/cardano-node/src/Cardano/Node/Handlers/Shutdown.hs +++ b/cardano-node/src/Cardano/Node/Handlers/Shutdown.hs @@ -11,8 +11,8 @@ {-# OPTIONS_GHC -Wno-orphans #-} module Cardano.Node.Handlers.Shutdown - ( SlotOrBlock (..) - , parseShutdownOnLimit + ( ShutdownOn (..) + , parseShutdownOn -- * Generalised shutdown handling , ShutdownConfig (..) @@ -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" @@ -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 @@ -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) @@ -98,7 +98,7 @@ deriving instance Eq AndWithOrigin data ShutdownConfig = ShutdownConfig { scIPC :: !(Maybe Fd) - , scOnSyncLimit :: !(Maybe SlotOrBlock) + , scOnSyncLimit :: !(Maybe ShutdownOn) } deriving (Eq, Show) @@ -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 diff --git a/cardano-node/src/Cardano/Node/Parsers.hs b/cardano-node/src/Cardano/Node/Parsers.hs index dd3389b4361..cf401140e12 100644 --- a/cardano-node/src/Cardano/Node/Parsers.hs +++ b/cardano-node/src/Cardano/Node/Parsers.hs @@ -65,7 +65,7 @@ nodeRunParser = do validate <- lastOption parseValidateDB shutdownIPC <- lastOption parseShutdownIPC - shutdownOnLimit <- lastOption parseShutdownOnLimit + shutdownOnLimit <- lastOption parseShutdownOn maybeMempoolCapacityOverride <- lastOption parseMempoolCapacityOverride diff --git a/cardano-node/test/Test/Cardano/Node/POM.hs b/cardano-node/test/Test/Cardano/Node/POM.hs index 17c3a4a9198..51b154bb2cd 100644 --- a/cardano-node/test/Test/Cardano/Node/POM.hs +++ b/cardano-node/test/Test/Cardano/Node/POM.hs @@ -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 @@ -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/"