-
Notifications
You must be signed in to change notification settings - Fork 721
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
cardano-node: implement --shutdown-on-block-synced #3932
Conversation
373511c
to
0982bfc
Compare
@@ -51,14 +50,18 @@ data ShutdownTrace | |||
-- ^ Received shutdown request but found unexpected input in --shutdown-ipc FD: | |||
| RequestingShutdown Text | |||
-- ^ Ringing the node shutdown doorbell for reason | |||
| ShutdownArmedAtSlot SlotNo | |||
-- ^ Will terminate upon reaching maxSlot | |||
| ShutdownArmedAtSlotBlock (Maybe SlotNo) (Maybe BlockNo) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rather than (Maybe SlotNo) (Maybe BlockNo)
this would be better with a sum type e.g data ShutdownMethod = ShutdownAtSlot SlotNo | ShutdownAtBlock BlockNo | NoShutdown
and we can rename ShutdownArmedAtSlot
to ShutdownNodeAt
or something like that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Jimbo4350, good point -- I was considering that as well!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Jimbo4350, done.
86f0236
to
5660b57
Compare
void $ forkLinkedWatcher registry "slotLimitTerminator" Watcher { | ||
wFingerprint = id | ||
wFingerprint = identity |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why the change to identity
? This doesn't look necessary.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Jimbo4350, sorry, Cardano.Prelude
import confused me, undone.
Because I had to change the prelude to Cardano.Prelude
, which has it as identity
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why did you have to make this change (importing Cardano.Prelude)? You shouldn't have to.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I needed Generic
, and so instead of adding GHC.Generics
, I switched the prelude, which allowed dumping a bunch of imports: 2c020c8#diff-9a71b006f6ddf2ab12e67e4d7e2951abf353bc8841f8a2638a1336a76b2ae43bL23-L32
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A couple of comments
import Ouroboros.Network.Block (HasHeader, BlockNo (..), SlotNo (..), pointSlot) | ||
|
||
|
||
data SlotOrBlock f |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I understand you are trying to reuse SlotOrBlock
but I would argue you still have to create the AndWithOrigin
type. I think this makes the code a little more difficult to understand vs the following:
diff --git a/cardano-node/src/Cardano/Node/Handlers/Shutdown.hs b/cardano-node/src/Cardano/Node/Handlers/Shutdown.hs
index 39f028deb..83457bbcc 100644
--- a/cardano-node/src/Cardano/Node/Handlers/Shutdown.hs
+++ b/cardano-node/src/Cardano/Node/Handlers/Shutdown.hs
@@ -26,9 +26,9 @@ module Cardano.Node.Handlers.Shutdown
)
where
+import Cardano.Prelude
import Data.Aeson (FromJSON, ToJSON)
import Generic.Data.Orphans ()
-import Cardano.Prelude
import Data.Text (pack)
import qualified GHC.IO.Handle.FD as IO (fdToHandle)
@@ -43,29 +43,27 @@ import Ouroboros.Consensus.Block (Header)
import qualified Ouroboros.Consensus.Storage.ChainDB as ChainDB
import Ouroboros.Consensus.Util.ResourceRegistry (ResourceRegistry)
import Ouroboros.Consensus.Util.STM (Watcher (..), forkLinkedWatcher)
-import Ouroboros.Network.Block (HasHeader, BlockNo (..), SlotNo (..), pointSlot)
+import Ouroboros.Network.Block (BlockNo (..), HasHeader, SlotNo (..), pointSlot)
-data SlotOrBlock f
- = ASlot !(f SlotNo)
- | ABlock !(f BlockNo)
- deriving (Generic)
+data SlotOrBlock
+ = ASlot !SlotNo
+ | ABlock !BlockNo
+ deriving (Generic, Eq, Show)
-deriving instance Eq (SlotOrBlock Identity)
-deriving instance Show (SlotOrBlock Identity)
-deriving instance FromJSON (SlotOrBlock Identity)
-deriving instance ToJSON (SlotOrBlock Identity)
+deriving instance FromJSON SlotOrBlock
+deriving instance ToJSON SlotOrBlock
-parseShutdownOnLimit :: Opt.Parser (Maybe (SlotOrBlock Identity))
+parseShutdownOnLimit :: Opt.Parser (Maybe SlotOrBlock)
parseShutdownOnLimit =
- optional (Opt.option (ASlot . Identity . SlotNo <$> Opt.auto) (
+ optional (Opt.option (ASlot . SlotNo <$> Opt.auto) (
Opt.long "shutdown-on-slot-synced"
<> Opt.metavar "SLOT"
<> Opt.help "Shut down the process after ChainDB is synced up to the specified slot"
<> Opt.hidden
))
<|>
- optional (Opt.option (ABlock . Identity . BlockNo <$> Opt.auto) (
+ optional (Opt.option (ABlock . BlockNo <$> Opt.auto) (
Opt.long "shutdown-on-block-synced"
<> Opt.metavar "BLOCK"
<> Opt.help "Shut down the process after ChainDB is synced up to the specified block"
@@ -81,21 +79,23 @@ data ShutdownTrace
-- ^ Received shutdown request but found unexpected input in --shutdown-ipc FD:
| RequestingShutdown Text
-- ^ Ringing the node shutdown doorbell for reason
- | ShutdownArmedAt (SlotOrBlock Identity)
+ | ShutdownArmedAt SlotOrBlock
-- ^ Will terminate upon reaching a ChainDB sync limit
deriving (Generic, FromJSON, ToJSON)
deriving instance FromJSON BlockNo
deriving instance ToJSON BlockNo
-newtype AndWithOrigin a = AndWithOrigin (a, WithOrigin a) deriving (Eq)
+data AndWithOrigin
+ = AndWithOriginBlock (BlockNo, WithOrigin BlockNo)
+ | AndWithOriginSlot (SlotNo, WithOrigin SlotNo)
-deriving instance Eq (SlotOrBlock AndWithOrigin)
+deriving instance Eq AndWithOrigin
data ShutdownConfig
= ShutdownConfig
{ scIPC :: !(Maybe Fd)
- , scOnSyncLimit :: !(Maybe (SlotOrBlock Identity))
+ , scOnSyncLimit :: !(Maybe SlotOrBlock)
}
deriving (Eq, Show)
@@ -142,24 +142,22 @@ maybeSpawnOnSlotSyncedShutdownHandler sc tr registry chaindb =
traceWith tr (ShutdownArmedAt lim)
spawnLimitTerminator lim
where
- spawnLimitTerminator :: SlotOrBlock Identity -> IO ()
+ spawnLimitTerminator :: SlotOrBlock -> IO ()
spawnLimitTerminator limit =
void $ forkLinkedWatcher registry "slotLimitTerminator" Watcher {
wFingerprint = identity
, wInitial = Nothing
, wReader =
case limit of
- ASlot (Identity x) -> ASlot . AndWithOrigin . (x,) <$>
- (pointSlot <$> ChainDB.getTipPoint chaindb)
- ABlock (Identity x) -> ABlock . AndWithOrigin . (x,) <$>
- ChainDB.getTipBlockNo chaindb
+ ASlot x -> AndWithOriginSlot . (x,) . pointSlot <$> ChainDB.getTipPoint chaindb
+ ABlock x -> AndWithOriginBlock . (x,) <$> ChainDB.getTipBlockNo chaindb
, wNotify = \case
- ASlot (AndWithOrigin (lim, At cur)) ->
+ (AndWithOriginSlot (lim, At cur)) ->
when (cur >= lim) $ do
traceWith tr (RequestingShutdown $ "spawnLimitTerminator: reached target slot "
<> (pack . show) cur)
throwIO ExitSuccess
- ABlock (AndWithOrigin (lim, At cur)) ->
+ (AndWithOriginBlock (lim, At cur)) ->
when (cur >= lim) $ do
traceWith tr (RequestingShutdown $ "spawnLimitTerminator: reached target block "
<> (pack . show) cur)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also the name SlotOrBlock
doesn't really indicate immediately what it's going to be used for. Why not ShutdownOnSlotOrBlock
? Or something similar.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Jimbo4350, done.
@@ -93,7 +91,7 @@ nodeRunParser = do | |||
} | |||
, pncValidateDB = validate | |||
, pncShutdownConfig = | |||
Last . Just $ ShutdownConfig (getLast shutdownIPC) (getLast shutdownOnSlot) | |||
Last . Just $ ShutdownConfig (getLast shutdownIPC) (join $ getLast shutdownOnLimit) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would also recommend this to avoid join
and follow the pattern of the other options being parsed:
diff --git a/cardano-node/src/Cardano/Node/Handlers/Shutdown.hs b/cardano-node/src/Cardano/Node/Handlers/Shutdown.hs
index 5e5324dae..3fba11ae6 100644
--- a/cardano-node/src/Cardano/Node/Handlers/Shutdown.hs
+++ b/cardano-node/src/Cardano/Node/Handlers/Shutdown.hs
@@ -49,27 +49,28 @@ import Ouroboros.Network.Block (BlockNo (..), HasHeader, SlotNo (..),
data SlotOrBlock
= ASlot !SlotNo
| ABlock !BlockNo
- | NoShutdown
+ | NoShutdownOnSlotOrBlock
deriving (Generic, Eq, Show)
deriving instance FromJSON SlotOrBlock
deriving instance ToJSON SlotOrBlock
-parseShutdownOnLimit :: Opt.Parser (Maybe SlotOrBlock)
+parseShutdownOnLimit :: Opt.Parser SlotOrBlock
parseShutdownOnLimit =
- optional (Opt.option (ASlot . SlotNo <$> Opt.auto) (
+ Opt.option (ASlot . SlotNo <$> Opt.auto) (
Opt.long "shutdown-on-slot-synced"
<> Opt.metavar "SLOT"
<> Opt.help "Shut down the process after ChainDB is synced up to the specified slot"
<> Opt.hidden
- ))
+ )
<|>
- optional (Opt.option (ABlock . BlockNo <$> Opt.auto) (
+ Opt.option (ABlock . BlockNo <$> Opt.auto) (
Opt.long "shutdown-on-block-synced"
<> Opt.metavar "BLOCK"
<> Opt.help "Shut down the process after ChainDB is synced up to the specified block"
<> Opt.hidden
- ))
+ )
+ <|> pure NoShutdownOnSlotOrBlock
data ShutdownTrace
= ShutdownRequested
@@ -90,6 +91,7 @@ deriving instance ToJSON BlockNo
data AndWithOrigin
= AndWithOriginBlock (BlockNo, WithOrigin BlockNo)
| AndWithOriginSlot (SlotNo, WithOrigin SlotNo)
+ | WithoutOrigin
deriving instance Eq AndWithOrigin
@@ -152,6 +154,7 @@ maybeSpawnOnSlotSyncedShutdownHandler sc tr registry chaindb =
case limit of
ASlot x -> AndWithOriginSlot . (x,) . pointSlot <$> ChainDB.getTipPoint chaindb
ABlock x -> AndWithOriginBlock . (x,) <$> ChainDB.getTipBlockNo chaindb
+ NoShutdownOnSlotOrBlock -> return WithoutOrigin
, wNotify = \case
(AndWithOriginSlot (lim, At cur)) ->
when (cur >= lim) $ do
@@ -163,5 +166,6 @@ maybeSpawnOnSlotSyncedShutdownHandler sc tr registry chaindb =
traceWith tr (RequestingShutdown $ "spawnLimitTerminator: reached target block "
<> (pack . show) cur)
throwIO ExitSuccess
+ WithoutOrigin -> pure ()
_ -> pure ()
}
diff --git a/cardano-node/src/Cardano/Node/Parsers.hs b/cardano-node/src/Cardano/Node/Parsers.hs
index a7cdbfb65..dd3389b43 100644
--- a/cardano-node/src/Cardano/Node/Parsers.hs
+++ b/cardano-node/src/Cardano/Node/Parsers.hs
@@ -23,7 +23,8 @@ import Ouroboros.Consensus.Mempool.API (MempoolCapacityBytes (..),
MempoolCapacityBytesOverride (..))
import Ouroboros.Consensus.Storage.LedgerDB.DiskPolicy (SnapshotInterval (..))
-import Cardano.Node.Configuration.NodeAddress
+import Cardano.Node.Configuration.NodeAddress (NodeHostIPv4Address (NodeHostIPv4Address),
+ NodeHostIPv6Address (NodeHostIPv6Address), PortNumber, SocketPath (SocketPath))
import Cardano.Node.Configuration.POM (PartialNodeConfiguration (..), lastOption)
import Cardano.Node.Configuration.Socket
import Cardano.Node.Handlers.Shutdown
@@ -91,7 +92,7 @@ nodeRunParser = do
}
, pncValidateDB = validate
, pncShutdownConfig =
- Last . Just $ ShutdownConfig (getLast shutdownIPC) (join $ getLast shutdownOnLimit)
+ Last . Just $ ShutdownConfig (getLast shutdownIPC) (getLast shutdownOnLimit)
, pncProtocolConfig = mempty
, pncMaxConcurrencyBulkSync = mempty
, pncMaxConcurrencyDeadline = mempty
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Jimbo4350, done!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
..and thank you for an actionable suggestion, too!
I think you are using a different formatter to cardano-node. We use stylish-haskell. |
b05d8f6
to
fb042c6
Compare
Ok, I need to integrate |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
bors r+ |
fb042c6
to
f3e379b
Compare
Canceled. |
bors r+ |
3932: cardano-node: implement --shutdown-on-block-synced r=deepfire a=deepfire This: 1. adds `--shutdown-on-block-synced BLOCKNO` option, in parallel to `--shutdown-on-slot-synced SLOTNO` 2. integrates it into the workbench Co-authored-by: Marcin Szamotulski <[email protected]> Co-authored-by: iohk-bors[bot] <43231472+iohk-bors[bot]@users.noreply.github.com> Co-authored-by: Kosyrev Serge <[email protected]> Co-authored-by: Jordan Millar <[email protected]>
Timed out. |
f3e379b
to
a3a58c7
Compare
All checks passed, node-side review green -- merging. |
This:
--shutdown-on-block-synced BLOCKNO
option, in parallel to--shutdown-on-slot-synced SLOTNO