Skip to content

Commit

Permalink
Add a --debug flag to marconi-chain-index and marconi-sidechain-exp (#…
Browse files Browse the repository at this point in the history
…286)


---------

Co-authored-by: brendanrbrown <brendan.brown@iohk.io>
  • Loading branch information
berewt and brendanrbrown committed Jan 8, 2024
1 parent 9440fba commit a85b1a1
Show file tree
Hide file tree
Showing 40 changed files with 109 additions and 63 deletions.
14 changes: 12 additions & 2 deletions marconi-cardano-chain-index/src/Marconi/Cardano/ChainIndex/CLI.hs
Original file line number Diff line number Diff line change
Expand Up @@ -164,13 +164,16 @@ multiAddressesParser = fmap (NESet.fromList . NEList.fromList . concat) . some .
39920450|679a55b523ff8d61942b2583b76e5d49498468164802ef1ebe513c685d6fb5c2|X(002f9787436835852ea78d3c45fc3d436b324184
-}
data CommonOptions = CommonOptions
{ optionsSocketPath :: !String
{ debugMode :: !Bool
-- ^ verbose logging
, optionsSocketPath :: !String
-- ^ POSIX socket file to communicate with cardano node
, optionsNetworkId :: !NetworkId
-- ^ cardano network id
, optionsChainPoint :: !StartingPoint
-- ^ The starting point of the indexers
, optionsRetryConfig :: !RetryConfig
-- ^ set up retry configuration when the node socket is unavailable
}
deriving stock (Show, Generic)
deriving anyclass (FromJSON, ToJSON)
Expand Down Expand Up @@ -228,7 +231,8 @@ snapshotProgramParser =
commonOptionsParser :: Opt.Parser CommonOptions
commonOptionsParser =
CommonOptions
<$> commonSocketPathParser
<$> commonDebugModeParser
<*> commonSocketPathParser
<*> commonNetworkIdParser
<*> commonStartFromParser
<*> commonRetryConfigParser
Expand Down Expand Up @@ -301,6 +305,12 @@ mintBurnDbPath o =

-- * Common CLI parsers for other derived programs.

commonDebugModeParser :: Opt.Parser Bool
commonDebugModeParser =
Opt.switch $
Opt.long "debug"
<> Opt.help "Verbose logging"

commonSocketPathParser :: Opt.Parser String
commonSocketPathParser =
Opt.strOption $
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ module Marconi.Cardano.ChainIndex.Run where
import Cardano.Api qualified as C
import Cardano.BM.Setup qualified as BM
import Cardano.BM.Trace (logError, logInfo)
import Cardano.BM.Tracing qualified as BM
import Control.Concurrent.Async (race_)
import Control.Exception (finally)
import Control.Monad (unless)
Expand Down Expand Up @@ -58,11 +59,16 @@ import qualified Marconi.Cardano.Core.Extract.WithDistance as Distance

run :: Text -> IO ()
run appName = withGracefulTermination_ $ do
(trace, sb) <- defaultStdOutLogger appName
let marconiTrace = mkMarconiTrace trace

o <- Cli.parseOptions

let logLevel =
if Cli.debugMode $ Cli.commonOptions o
then BM.Debug
else BM.Info
(trace, sb) <- defaultStdOutLogger appName logLevel

let marconiTrace = mkMarconiTrace trace

logInfo trace $ appName <> "-" <> Text.pack Cli.getVersion
logInfo trace $ Text.toStrict . pShowDarkBg $ o

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ module Marconi.Cardano.ChainIndex.Snapshot.Run (
import Cardano.Api qualified as C
import Cardano.BM.Setup qualified as BM
import Cardano.BM.Trace (logError)
import Cardano.BM.Tracing qualified as BM
import Control.Monad (unless)
import Control.Monad.Except (runExceptT)
import Data.Text (Text)
Expand Down Expand Up @@ -43,7 +44,7 @@ appName = "marconi-chain-snapshot"
-}
run :: IO ()
run = do
(trace, sb) <- defaultStdOutLogger appName
(trace, sb) <- defaultStdOutLogger appName BM.Info
options <- parseSnapshotOptions
nodeConfigPath <- getNodeConfigPath options sb trace

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
option --addresses-to-index: Invalid address (not a valid Bech32 address representation): "x8phkx6acpnf78fuvxn0mkew3l0fd058hzquvz7w36x4gt7r0vd4msrxnuwnccdxlhdjar77j6lg0wypcc9uar5d2shskhj42g"

Usage: marconi-cardano-chain-index [--version] (-s|--socket-path FILE-PATH)
Usage: marconi-cardano-chain-index [--version] [--debug]
(-s|--socket-path FILE-PATH)
(--mainnet | --testnet-magic NATURAL)
[--start-from-genesis |
--start-from-last-sync-points |
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
option --addresses-to-index: Invalid address (not a valid Bech32 address representation): "notAnAddress"

Usage: marconi-cardano-chain-index [--version] (-s|--socket-path FILE-PATH)
Usage: marconi-cardano-chain-index [--version] [--debug]
(-s|--socket-path FILE-PATH)
(--mainnet | --testnet-magic NATURAL)
[--start-from-genesis |
--start-from-last-sync-points |
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
option --addresses-to-index: Invalid address (not a valid Bech32 address representation): "stake1uyehkck0lajq8gr28t9uxnuvgcqrc6070x3k9r8048z8y5gh6ffgw"

Usage: marconi-cardano-chain-index [--version] (-s|--socket-path FILE-PATH)
Usage: marconi-cardano-chain-index [--version] [--debug]
(-s|--socket-path FILE-PATH)
(--mainnet | --testnet-magic NATURAL)
[--start-from-genesis |
--start-from-last-sync-points |
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
option --addresses-to-index: Invalid address (not a valid Bech32 address representation): "stake_test17rphkx6acpnf78fuvxn0mkew3l0fd058hzquvz7w36x4gtcljw6kf"

Usage: marconi-cardano-chain-index [--version] (-s|--socket-path FILE-PATH)
Usage: marconi-cardano-chain-index [--version] [--debug]
(-s|--socket-path FILE-PATH)
(--mainnet | --testnet-magic NATURAL)
[--start-from-genesis |
--start-from-last-sync-points |
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
option --addresses-to-index: Invalid address (not a valid Bech32 address representation): "addr1x8phkx6acpnf78fuvxn0mkew3l0fd058hzquvz7w36x4gt7r0vd4msrxnuwnccdxlhdjar77j6lg0wypcc9uar5d2shskhj42"

Usage: marconi-cardano-chain-index [--version] (-s|--socket-path FILE-PATH)
Usage: marconi-cardano-chain-index [--version] [--debug]
(-s|--socket-path FILE-PATH)
(--mainnet | --testnet-magic NATURAL)
[--start-from-genesis |
--start-from-last-sync-points |
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
option --match-asset-id: Expected Base16-encoded bytestring, but got 0000notAToken0; invalid character at offset: 4

Usage: marconi-cardano-chain-index [--version] (-s|--socket-path FILE-PATH)
Usage: marconi-cardano-chain-index [--version] [--debug]
(-s|--socket-path FILE-PATH)
(--mainnet | --testnet-magic NATURAL)
[--start-from-genesis |
--start-from-last-sync-points |
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
option --match-asset-id: Expected Base16-encoded bytestring, but got deadbeeef; invalid bytestring size

Usage: marconi-cardano-chain-index [--version] (-s|--socket-path FILE-PATH)
Usage: marconi-cardano-chain-index [--version] [--debug]
(-s|--socket-path FILE-PATH)
(--mainnet | --testnet-magic NATURAL)
[--start-from-genesis |
--start-from-last-sync-points |
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
option --match-asset-id: Failed to deserialise deadbeef0000000000000000000000000000000000000000000000000000000000 as AssetName. Unable to deserialise AssetName (the bytestring should be no longer than 32 bytes long which corresponds to a hex representation of 64 characters)

Usage: marconi-cardano-chain-index [--version] (-s|--socket-path FILE-PATH)
Usage: marconi-cardano-chain-index [--version] [--debug]
(-s|--socket-path FILE-PATH)
(--mainnet | --testnet-magic NATURAL)
[--start-from-genesis |
--start-from-last-sync-points |
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
option --match-asset-id: Failed to deserialise 1cdc58c3b6d1ab11dd047ac9e3a2ec26aabf0839abe37b791cb810f2f2 as PolicyId. Incorrect number of bytes

Usage: marconi-cardano-chain-index [--version] (-s|--socket-path FILE-PATH)
Usage: marconi-cardano-chain-index [--version] [--debug]
(-s|--socket-path FILE-PATH)
(--mainnet | --testnet-magic NATURAL)
[--start-from-genesis |
--start-from-last-sync-points |
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
option --match-asset-id: Failed to deserialise 1cdc58c3b6d1ab11dd047ac9e3a2ec26aabf0839abe37b791cb810 as PolicyId. Incorrect number of bytes

Usage: marconi-cardano-chain-index [--version] (-s|--socket-path FILE-PATH)
Usage: marconi-cardano-chain-index [--version] [--debug]
(-s|--socket-path FILE-PATH)
(--mainnet | --testnet-magic NATURAL)
[--start-from-genesis |
--start-from-last-sync-points |
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
option --match-asset-id: Expected Base16-encoded bytestring, but got 1cdc58c3b6d1ab11dd047ac9e3a2ec26aabf0839abe37b791cb810f2f; invalid bytestring size

Usage: marconi-cardano-chain-index [--version] (-s|--socket-path FILE-PATH)
Usage: marconi-cardano-chain-index [--version] [--debug]
(-s|--socket-path FILE-PATH)
(--mainnet | --testnet-magic NATURAL)
[--start-from-genesis |
--start-from-last-sync-points |
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
option --match-asset-id: Expected Base16-encoded bytestring, but got 1cdc58c3b6d1ab11dd047ac9e3a2ec26aabf0839abe37b791cb810f; invalid bytestring size

Usage: marconi-cardano-chain-index [--version] (-s|--socket-path FILE-PATH)
Usage: marconi-cardano-chain-index [--version] [--debug]
(-s|--socket-path FILE-PATH)
(--mainnet | --testnet-magic NATURAL)
[--start-from-genesis |
--start-from-last-sync-points |
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
option --match-asset-id: Expected Base16-encoded bytestring, but got 00aPolicyIdOfCorrectLength000000000000000000000000000000000000; invalid character at offset: 3

Usage: marconi-cardano-chain-index [--version] (-s|--socket-path FILE-PATH)
Usage: marconi-cardano-chain-index [--version] [--debug]
(-s|--socket-path FILE-PATH)
(--mainnet | --testnet-magic NATURAL)
[--start-from-genesis |
--start-from-last-sync-points |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ Invalid option `--disable-address-data'
Did you mean this?
--disable-address-datum

Usage: marconi-cardano-chain-index [--version] (-s|--socket-path FILE-PATH)
Usage: marconi-cardano-chain-index [--version] [--debug]
(-s|--socket-path FILE-PATH)
(--mainnet | --testnet-magic NATURAL)
[--start-from-genesis |
--start-from-last-sync-points |
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
marconi - a lightweight customizable solution for indexing and querying the
Cardano blockchain

Usage: marconi-cardano-chain-index [--version] (-s|--socket-path FILE-PATH)
Usage: marconi-cardano-chain-index [--version] [--debug]
(-s|--socket-path FILE-PATH)
(--mainnet | --testnet-magic NATURAL)
[--start-from-genesis |
--start-from-last-sync-points |
Expand All @@ -23,6 +24,7 @@ Usage: marconi-cardano-chain-index [--version] (-s|--socket-path FILE-PATH)
Available options:
-h,--help Show this help text
--version Show marconi version
--debug Verbose logging
-s,--socket-path FILE-PATH
Path to node socket.
--mainnet Use the mainnet magic id.
Expand Down
6 changes: 3 additions & 3 deletions marconi-cardano-core/src/Marconi/Cardano/Core/Logger.hs
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ import Prettyprinter qualified as Pretty
import Prettyprinter.Render.Text qualified as Pretty

-- | StdOut logger, only log stuff above the Info level
defaultStdOutLogger :: Text -> IO (Trace IO Text, BM.Switchboard Text)
defaultStdOutLogger appName = do
defaultStdOutLogger :: Text -> BM.Severity -> IO (Trace IO Text, BM.Switchboard Text)
defaultStdOutLogger appName logLevel = do
cfg <- BM.defaultConfigStdout
BM.setMinSeverity cfg BM.Info
BM.setMinSeverity cfg logLevel
BM.setupTrace_ cfg appName

-- | Builds a 'MarconiTrace' from a base tracer.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ import Prettyprinter (Pretty (pretty), (<+>))
import Text.Printf (printf)

{- | Creates a simple pretty-printing backend which prints the number of processed blocks and
the number of rollbacks to a given tracer.
the number of rollbacks to a given tracer.
Takes a @NominalDiffTime@ which determines how frequently we send stats to Prometheus and a
@MarconiTrace IO@ with which it performs the tracing.
Takes a @NominalDiffTime@ which determines how frequently we send stats to Prometheus and a
@MarconiTrace IO@ with which it performs the tracing.
-}
mkLogBackend :: MarconiTrace IO -> NominalDiffTime -> StatsBackend
mkLogBackend tracer timeBetween =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ module Spec.Marconi.Cardano.Indexers.BlockInfo (
) where

import Cardano.Api qualified as C
import Cardano.BM.Tracing qualified as BM
import Control.Concurrent (readMVar, threadDelay)
import Control.Concurrent.Async qualified as Async
import Control.Exception (throwIO)
Expand Down Expand Up @@ -119,7 +120,7 @@ propTrippingBlockInfoJSON = Hedgehog.property $ do
endToEndBlockInfo :: Hedgehog.Property
endToEndBlockInfo = Helpers.unitTestWithTmpDir "." $ \tempPath -> do
-- Setup
(trace, _) <- liftIO $ defaultStdOutLogger "endToEndBlockInfo"
(trace, _) <- liftIO $ defaultStdOutLogger "endToEndBlockInfo" BM.Info
let marconiTrace = mkMarconiTrace trace

-- Local node config and connect info, with slots of length 100ms
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ module Spec.Marconi.Cardano.Indexers.MintTokenEvent (

import Cardano.Api qualified as C
import Cardano.Api.Extended.Gen qualified as CEGen
import Cardano.BM.Tracing qualified as BM
import Control.Concurrent (readMVar, threadDelay)
import Control.Concurrent qualified as Concurrent
import Control.Concurrent.Async qualified as Async
Expand Down Expand Up @@ -653,7 +654,7 @@ queryListIndexerEventsMatchingTargetAssetIds assetIds indexer = do
endToEndMintTokenEvent :: H.Property
endToEndMintTokenEvent = Helpers.unitTestWithTmpDir "." $ \tempPath -> do
-- Setup
(trace, _) <- liftIO $ defaultStdOutLogger "endToEndMintTokenEvent"
(trace, _) <- liftIO $ defaultStdOutLogger "endToEndMintTokenEvent" BM.Info
let marconiTrace = mkMarconiTrace trace

-- Local node config and connect info, with slots of length 100ms
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ import Options.Applicative qualified as Opt

-- | Type represents http port for JSON-RPC
data CliArgs = CliArgs
{ socketFilePath :: !FilePath
{ debugMode :: !Bool
-- ^ verbose logging
, socketFilePath :: !FilePath
-- ^ POSIX socket file to communicate with cardano node
, nodeConfigPath :: !FilePath
-- ^ Path to the node config
Expand All @@ -38,7 +40,9 @@ data CliArgs = CliArgs
, targetAssets :: !(Maybe (NonEmpty (C.PolicyId, Maybe C.AssetName)))
-- ^ a list of asset to track
, optionsRetryConfig :: !RetryConfig
-- ^ set up retry configuration when the node socket is unavailable
, optionsChainPoint :: !Cli.StartingPoint
-- ^ synchronisation start point
}
deriving (Show, Generic, FromJSON, ToJSON)

Expand All @@ -57,7 +61,8 @@ programParser =
parserCliArgs :: Opt.Parser CliArgs
parserCliArgs =
CliArgs
<$> Cli.commonSocketPathParser
<$> Cli.commonDebugModeParser
<*> Cli.commonSocketPathParser
<*> Cli.commonNodeConfigPathParser
<*> Cli.commonDbDirParser
<*> Cli.commonPortParser
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ module Marconi.Sidechain.Experimental.Run where

import Cardano.BM.Setup qualified as BM
import Cardano.BM.Trace (logInfo)
import Cardano.BM.Tracing qualified as BM
import Control.Exception (finally)
import Control.Lens ((^.))
import Control.Monad.Reader (runReaderT)
Expand All @@ -13,6 +14,7 @@ import Marconi.Cardano.Core.Logger (defaultStdOutLogger)
import Marconi.Core (IndexerError)
import Marconi.Sidechain.Experimental.Api.HttpServer (runHttpServer)
import Marconi.Sidechain.Experimental.CLI (
CliArgs (debugMode),
getVersion,
parseCli,
)
Expand All @@ -32,8 +34,9 @@ import Text.Pretty.Simple (pShowDarkBg)
run :: IO ()
run =
do
(trace, sb) <- defaultStdOutLogger "marconi-sidechain-experimental"
cliArgs <- parseCli
let logLevel = if debugMode cliArgs then BM.Debug else BM.Info
(trace, sb) <- defaultStdOutLogger "marconi-sidechain-experimental" logLevel

logInfo trace $ "marconi-sidechain-" <> Text.pack getVersion
logInfo trace . Text.toStrict $ pShowDarkBg cliArgs
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
option --addresses-to-index: Invalid address (not a valid Bech32 address representation): "x8phkx6acpnf78fuvxn0mkew3l0fd058hzquvz7w36x4gt7r0vd4msrxnuwnccdxlhdjar77j6lg0wypcc9uar5d2shskhj42g"

Usage: marconi-sidechain-experimental
[--version] (-s|--socket-path FILE-PATH) --node-config-path ARG
(-d|--db-dir DIR) [--http-port INT]
[--version] [--debug] (-s|--socket-path FILE-PATH)
--node-config-path ARG (-d|--db-dir DIR) [--http-port INT]
(--mainnet | --testnet-magic NATURAL)
[(-a|--addresses-to-index BECH32-ADDRESS)]
[(--match-asset-id POLICY_ID[.ASSET_NAME])]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
option --addresses-to-index: Invalid address (not a valid Bech32 address representation): "notAnAddress"

Usage: marconi-sidechain-experimental
[--version] (-s|--socket-path FILE-PATH) --node-config-path ARG
(-d|--db-dir DIR) [--http-port INT]
[--version] [--debug] (-s|--socket-path FILE-PATH)
--node-config-path ARG (-d|--db-dir DIR) [--http-port INT]
(--mainnet | --testnet-magic NATURAL)
[(-a|--addresses-to-index BECH32-ADDRESS)]
[(--match-asset-id POLICY_ID[.ASSET_NAME])]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
option --addresses-to-index: Invalid address (not a valid Bech32 address representation): "stake1uyehkck0lajq8gr28t9uxnuvgcqrc6070x3k9r8048z8y5gh6ffgw"

Usage: marconi-sidechain-experimental
[--version] (-s|--socket-path FILE-PATH) --node-config-path ARG
(-d|--db-dir DIR) [--http-port INT]
[--version] [--debug] (-s|--socket-path FILE-PATH)
--node-config-path ARG (-d|--db-dir DIR) [--http-port INT]
(--mainnet | --testnet-magic NATURAL)
[(-a|--addresses-to-index BECH32-ADDRESS)]
[(--match-asset-id POLICY_ID[.ASSET_NAME])]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
option --addresses-to-index: Invalid address (not a valid Bech32 address representation): "stake_test17rphkx6acpnf78fuvxn0mkew3l0fd058hzquvz7w36x4gtcljw6kf"

Usage: marconi-sidechain-experimental
[--version] (-s|--socket-path FILE-PATH) --node-config-path ARG
(-d|--db-dir DIR) [--http-port INT]
[--version] [--debug] (-s|--socket-path FILE-PATH)
--node-config-path ARG (-d|--db-dir DIR) [--http-port INT]
(--mainnet | --testnet-magic NATURAL)
[(-a|--addresses-to-index BECH32-ADDRESS)]
[(--match-asset-id POLICY_ID[.ASSET_NAME])]
Expand Down

0 comments on commit a85b1a1

Please sign in to comment.