-
Notifications
You must be signed in to change notification settings - Fork 16
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
New debug log-epoch-state
command
#775
Changes from all commits
b45952f
38e9fe7
f326ad3
116a342
2a51ce5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
name: Actionlint | ||
|
||
on: | ||
merge_group: | ||
pull_request: | ||
|
||
jobs: | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,7 @@ name: Shellcheck | |
# is consistent with the one of developers. | ||
|
||
on: | ||
merge_group: | ||
pull_request: | ||
|
||
jobs: | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
{-# LANGUAGE GADTs #-} | ||
|
||
module Cardano.CLI.Commands | ||
( ClientCommand(..) | ||
) where | ||
|
||
import Cardano.CLI.Byron.Commands (ByronCommand) | ||
import Cardano.CLI.Commands.Debug | ||
import Cardano.CLI.Commands.Ping (PingCmd (..)) | ||
import Cardano.CLI.EraBased.Commands | ||
import Cardano.CLI.Legacy.Commands | ||
|
||
import Options.Applicative.Types (ParserInfo (..), ParserPrefs (..)) | ||
|
||
-- | Sub-commands of 'cardano-cli'. | ||
data ClientCommand = | ||
AnyEraCommand AnyEraCommand | ||
|
||
-- | Byron Related Commands | ||
| ByronCommand ByronCommand | ||
|
||
-- | Legacy shelley-based Commands | ||
| LegacyCmds LegacyCmds | ||
|
||
| CliPingCommand PingCmd | ||
| CliDebugCmds DebugCmds | ||
|
||
| forall a. Help ParserPrefs (ParserInfo a) | ||
| DisplayVersion |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
module Cardano.CLI.Commands.Debug | ||
( DebugCmds (..) | ||
) where | ||
|
||
import Cardano.CLI.Commands.Debug.LogEpochState | ||
|
||
newtype DebugCmds = | ||
DebugLogEpochStateCmd LogEpochStateCmdArgs |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
{-# LANGUAGE DataKinds #-} | ||
|
||
module Cardano.CLI.Commands.Debug.LogEpochState | ||
( LogEpochStateCmdArgs(..) | ||
, Configuration | ||
) where | ||
|
||
import Cardano.Api | ||
|
||
import Cardano.CLI.Orphans () | ||
|
||
-- | A phantom type to represent the configuration file. | ||
data Configuration | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A haddock here saying this is a file type level tag would be useful. |
||
|
||
-- | The arguments for the 'debug log-epoch-state' command. | ||
-- | ||
-- This command will connect to a local node and log the epoch state. | ||
data LogEpochStateCmdArgs = LogEpochStateCmdArgs | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A brief haddock here describing the command would be useful. |
||
{ nodeSocketPath :: !SocketPath | ||
, configurationFile :: !(NodeConfigFile 'In) | ||
, outputFilePath :: !(File Configuration 'Out) | ||
} deriving Show |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
module Cardano.CLI.Commands.Ping | ||
( EndPoint(..) | ||
, PingCmd(..) | ||
) where | ||
|
||
import Data.Word | ||
|
||
data EndPoint = | ||
HostEndPoint String | ||
| UnixSockEndPoint String | ||
deriving (Eq, Show) | ||
|
||
data PingCmd = PingCmd | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 Not necessarily for this PR but haddocks would be good here. |
||
{ pingCmdCount :: !Word32 | ||
, pingCmdEndPoint :: !EndPoint | ||
, pingCmdPort :: !String | ||
, pingCmdMagic :: !Word32 | ||
, pingCmdJson :: !Bool | ||
, pingCmdQuiet :: !Bool | ||
, pingOptsHandshakeQuery :: !Bool | ||
} deriving (Eq, Show) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
{-# LANGUAGE DataKinds #-} | ||
{-# LANGUAGE FlexibleContexts #-} | ||
{-# LANGUAGE GADTs #-} | ||
{-# LANGUAGE ScopedTypeVariables #-} | ||
|
||
{- HLINT ignore "Use <$>" -} | ||
{- HLINT ignore "Move brackets to avoid $" -} | ||
|
||
module Cardano.CLI.Options.Debug | ||
( parseDebugCmds | ||
) where | ||
|
||
import Cardano.Api.Shelley hiding (QueryInShelleyBasedEra (..)) | ||
|
||
import Cardano.CLI.Commands.Debug | ||
import Cardano.CLI.Commands.Debug.LogEpochState | ||
import Cardano.CLI.Environment | ||
import Cardano.CLI.EraBased.Options.Common | ||
|
||
import Data.Foldable | ||
import Options.Applicative hiding (help, str) | ||
import qualified Options.Applicative as Opt | ||
|
||
parseDebugCmds :: EnvCli -> Parser DebugCmds | ||
parseDebugCmds envCli = | ||
Opt.hsubparser $ mconcat | ||
[ Opt.metavar "debug commands" | ||
, Opt.commandGroup "debug commands" | ||
, Opt.command "debug" | ||
$ Opt.info (pDebugCmds envCli) | ||
$ Opt.progDesc "Debug commands" | ||
] | ||
|
||
pDebugCmds :: EnvCli -> Parser DebugCmds | ||
pDebugCmds envCli = | ||
asum | ||
[ subParser "log-epoch-state" | ||
$ Opt.info pLogEpochStateCmdArgs | ||
$ Opt.progDesc | ||
$ mconcat | ||
[ "Log epoch state of a running node." | ||
, " This command will connect to a local node and log the epoch state to a file." | ||
, " The log file format is line delimited JSON." | ||
, " The command will not terminate." | ||
] | ||
] | ||
where | ||
pLogEpochStateCmdArgs :: Parser DebugCmds | ||
pLogEpochStateCmdArgs = | ||
fmap DebugLogEpochStateCmd $ | ||
LogEpochStateCmdArgs | ||
<$> pSocketPath envCli | ||
<*> pNodeConfigurationFileIn | ||
<*> pFileOutDirection "out-file" "Output filepath of the log file. The log file format is line delimited JSON." | ||
|
||
pNodeConfigurationFileIn :: Parser (NodeConfigFile In) | ||
pNodeConfigurationFileIn = | ||
fmap File $ Opt.strOption $ mconcat | ||
[ Opt.long "node-configuration-file" | ||
, Opt.metavar "FILE" | ||
, Opt.help "Input filepath of the node configuration file." | ||
, Opt.completer (Opt.bashCompleter "file") | ||
] |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
{-# LANGUAGE TypeApplications #-} | ||
|
||
{- HLINT ignore "Move brackets to avoid $" -} | ||
|
||
module Cardano.CLI.Options.Ping | ||
( parsePingCmd | ||
) where | ||
|
||
import Cardano.CLI.Commands.Ping | ||
import qualified Cardano.Network.Ping as CNP | ||
|
||
import Control.Applicative ((<|>)) | ||
import qualified Options.Applicative as Opt | ||
import qualified Prettyprinter as PP | ||
|
||
parsePingCmd :: Opt.Parser PingCmd | ||
parsePingCmd = Opt.hsubparser $ mconcat | ||
[ Opt.metavar "ping" | ||
, Opt.command "ping" $ Opt.info pPing $ Opt.progDescDoc $ Just $ mconcat | ||
[ PP.pretty @String "Ping a cardano node either using node-to-node or node-to-client protocol. " | ||
, PP.pretty @String "It negotiates a handshake and keeps sending keep alive messages." | ||
] | ||
] | ||
|
||
pHost :: Opt.Parser String | ||
pHost = | ||
Opt.strOption $ mconcat | ||
[ Opt.long "host" | ||
, Opt.short 'h' | ||
, Opt.metavar "HOST" | ||
, Opt.help "Hostname/IP, e.g. relay.iohk.example." | ||
] | ||
|
||
pUnixSocket :: Opt.Parser String | ||
pUnixSocket = | ||
Opt.strOption $ mconcat | ||
[ Opt.long "unixsock" | ||
, Opt.short 'u' | ||
, Opt.metavar "SOCKET" | ||
, Opt.help "Unix socket, e.g. file.socket." | ||
] | ||
|
||
pEndPoint :: Opt.Parser EndPoint | ||
pEndPoint = fmap HostEndPoint pHost <|> fmap UnixSockEndPoint pUnixSocket | ||
|
||
pPing :: Opt.Parser PingCmd | ||
pPing = PingCmd | ||
<$> ( Opt.option Opt.auto $ mconcat | ||
[ Opt.long "count" | ||
, Opt.short 'c' | ||
, Opt.metavar "COUNT" | ||
, Opt.help $ mconcat | ||
[ "Stop after sending count requests and receiving count responses. " | ||
, "If this option is not specified, ping will operate until interrupted. " | ||
] | ||
, Opt.value maxBound | ||
] | ||
) | ||
|
||
<*> pEndPoint | ||
<*> ( Opt.strOption $ mconcat | ||
[ Opt.long "port" | ||
, Opt.short 'p' | ||
, Opt.metavar "PORT" | ||
, Opt.help "Port number, e.g. 1234." | ||
, Opt.value "3001" | ||
] | ||
) | ||
|
||
<*> ( Opt.option Opt.auto $ mconcat | ||
[ Opt.long "magic" | ||
, Opt.short 'm' | ||
, Opt.metavar "MAGIC" | ||
, Opt.help "Network magic." | ||
, Opt.value CNP.mainnetMagic | ||
] | ||
) | ||
|
||
<*> ( Opt.switch $ mconcat | ||
[ Opt.long "json" | ||
, Opt.short 'j' | ||
, Opt.help "JSON output flag." | ||
] | ||
) | ||
|
||
<*> ( Opt.switch $ mconcat | ||
[ Opt.long "quiet" | ||
, Opt.short 'q' | ||
, Opt.help "Quiet flag, CSV/JSON only output" | ||
] | ||
) | ||
|
||
<*> ( Opt.switch $ mconcat | ||
[ Opt.long "query-versions" | ||
, Opt.short 'Q' | ||
, Opt.help "Query the supported protocol versions using the handshake protocol and terminate the connection." | ||
] | ||
) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
{-# OPTIONS_GHC -Wno-orphans #-} | ||
|
||
module Cardano.CLI.Orphans | ||
( | ||
) where | ||
|
||
import Cardano.Api | ||
|
||
import qualified Cardano.Ledger.Api as L | ||
import qualified Cardano.Ledger.Shelley.LedgerState as L | ||
|
||
import Data.Aeson | ||
|
||
-- TODO upstream this orphaned instance to the ledger | ||
instance (L.EraTxOut ledgerera, L.EraGov ledgerera) => ToJSON (L.NewEpochState ledgerera) where | ||
newhoggy marked this conversation as resolved.
Show resolved
Hide resolved
|
||
toJSON (L.NewEpochState nesEL nesBprev nesBCur nesEs nesRu nesPd _stashedAvvm)= | ||
object | ||
[ "currentEpoch" .= nesEL | ||
, "priorBlocks" .= nesBprev | ||
, "currentEpochBlocks" .= nesBCur | ||
, "currentEpochState" .= nesEs | ||
, "rewardUpdate" .= nesRu | ||
, "currentStakeDistribution" .= nesPd | ||
] |
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.
👍