Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 5 additions & 20 deletions ouroboros-consensus-cardano/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,21 +68,6 @@ A block with the corresponding slot number must exist in the ImmutableDB.
For certain analyses, a snapshot at that slot number must exist in `DB_PATH/ledger/SLOT_NUMBER_db-analyser` - where `SLOT_NUMBER` is the value provided by the user with the `--analyse-from` flag.
The user can use snapshots created by the node or they can create their own snapshots via db-analyser - see the `--store-ledger` command

#### COMMAND

There are three options: `byron`, `shelley`, `cardano`. When in doubt which one to use, use `cardano`.

* `byron`

User should run this if they are dealing with Byron only chain. When the command is `byron` then user must provide `--configByron PATH` pointing to a byron configuration file.

* `shelley`

User should run this if they are dealing with Shelley only chain (neither Byron nor Allegra or any other era that comes after). When the command is `shelley` then user must provide `--configShelley PATH` pointing to a shelley configuration file. They may also provide `--genesisHash HASH` and `--threshold THRESHOLD`

* `cardano`
User should run this if they are dealing with a `cardano` chain.

#### --num-blocks-to-process

```
Expand Down Expand Up @@ -215,7 +200,7 @@ Suppose we have a local chain database in reachable from `$NODE_HOME`, and we
want to take a snapshot of the ledger state for slot `100`. Then we can run:

```sh
cabal run exe:db-analyser -- cardano \
cabal run exe:db-analyser -- \
--config $NODE_HOME/configuration/cardano/mainnet-config.json \
--db $NODE_HOME/mainnet/db \
--store-ledger 100
Expand All @@ -225,7 +210,7 @@ If we had a previous snapshot of the ledger state, say corresponding to slot
`50`, it is possible to tell `db-analyser` to start from this snapshot:

```sh
cabal run exe:db-analyser -- cardano \
cabal run exe:db-analyser -- \
--config $NODE_HOME/configuration/cardano/mainnet-config.json \
--db $NODE_HOME/mainnet/db \
--analyse-from 50 \
Expand All @@ -238,7 +223,7 @@ To benchmark the ledger operations, using the setup mentioned in the foregoing
examples, one could run the tool as follows:

```sh
cabal run exe:db-analyser -- cardano
cabal run exe:db-analyser -- \
--config $NODE_HOME/configuration/cardano/mainnet-config.json \
--db $NODE_HOME/mainnet/db \
--analyse-from 100 \
Expand All @@ -250,7 +235,7 @@ The benchmarking command can be combined with `--num-blocks-to-process` to
specify the application of how many blocks we want to process. Eg:

```sh
cabal run exe:db-analyser -- cardano
cabal run exe:db-analyser -- \
--config $NODE_HOME/configuration/cardano/mainnet-config.json \
--db $NODE_HOME/mainnet/db \
--analyse-from 100 \
Expand Down Expand Up @@ -284,7 +269,7 @@ First, run the following command for both of your ChainDBs:

```
db-analyser --analyse-from 1234 --db /path/to/dbX --show-slot-block-no \
cardano --config /path/to/config.json | cut -d ' ' -f 2- > dbX.log
--config /path/to/config.json | cut -d ' ' -f 2- > dbX.log
```

Note that specificying `--analyse-from` is optional; it means that you are
Expand Down
91 changes: 5 additions & 86 deletions ouroboros-consensus-cardano/app/DBAnalyser/Parsers.hs
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,25 @@
{-# LANGUAGE LambdaCase #-}

module DBAnalyser.Parsers
( BlockType (..)
, blockTypeParser
, parseCmdLine
( parseCmdLine
, parseCardanoArgs
, CardanoBlockArgs
) where

import Cardano.Crypto (RequiresNetworkMagic (..))
import Cardano.Tools.DBAnalyser.Analysis
import Cardano.Tools.DBAnalyser.Block.Byron
import Cardano.Tools.DBAnalyser.Block.Cardano
import Cardano.Tools.DBAnalyser.Block.Shelley
import Cardano.Tools.DBAnalyser.Types
import qualified Data.Foldable as Foldable
import Options.Applicative
import Ouroboros.Consensus.Block (SlotNo (..), WithOrigin (..))
import Ouroboros.Consensus.Byron.Node (PBftSignatureThreshold (..))
import Ouroboros.Consensus.Shelley.Node (Nonce (..))

{-------------------------------------------------------------------------------
Parsing
-------------------------------------------------------------------------------}

parseCmdLine :: Parser (DBAnalyserConfig, BlockType)
parseCmdLine = (,) <$> parseDBAnalyserConfig <*> blockTypeParser
parseCmdLine :: Parser (DBAnalyserConfig, CardanoBlockArgs)
parseCmdLine = (,) <$> parseDBAnalyserConfig <*> parseCardanoArgs

parseDBAnalyserConfig :: Parser DBAnalyserConfig
parseDBAnalyserConfig =
Expand Down Expand Up @@ -259,65 +255,12 @@ pMaybeOutputFile =
Parse BlockType-specific arguments
-------------------------------------------------------------------------------}

data BlockType
= ByronBlock ByronBlockArgs
| ShelleyBlock ShelleyBlockArgs
| CardanoBlock CardanoBlockArgs

blockTypeParser :: Parser BlockType
blockTypeParser =
subparser $
mconcat
[ command
"byron"
(info (parseByronType <**> helper) (progDesc "Analyse a Byron-only DB"))
, command
"shelley"
(info (parseShelleyType <**> helper) (progDesc "Analyse a Shelley-only DB"))
, command
"cardano"
(info (parseCardanoType <**> helper) (progDesc "Analyse a Cardano DB"))
]

parseByronType :: Parser BlockType
parseByronType = ByronBlock <$> parseByronArgs

parseShelleyType :: Parser BlockType
parseShelleyType = ShelleyBlock <$> parseShelleyArgs

parseCardanoType :: Parser BlockType
parseCardanoType = CardanoBlock <$> parseCardanoArgs

parseCardanoArgs :: Parser CardanoBlockArgs
parseCardanoArgs =
CardanoBlockArgs
<$> parseConfigFile
<*> parsePBftSignatureThreshold

parseShelleyArgs :: Parser ShelleyBlockArgs
parseShelleyArgs =
ShelleyBlockArgs
<$> strOption
( mconcat
[ long "configShelley"
, help "Path to config file"
, metavar "PATH"
]
)
<*> Foldable.asum
[ Nonce <$> parseNonce
, pure NeutralNonce
]
where
parseNonce =
strOption
( mconcat
[ long "nonce"
, help "Initial nonce, i.e., hash of the genesis config file"
, metavar "NONCE"
]
)

parseConfigFile :: Parser FilePath
parseConfigFile =
strOption $
Expand All @@ -337,27 +280,3 @@ parsePBftSignatureThreshold =
, help "PBftSignatureThreshold"
, metavar "THRESHOLD"
]

parseByronArgs :: Parser ByronBlockArgs
parseByronArgs =
ByronBlockArgs
<$> parseConfigFile
<*> flag
RequiresNoMagic
RequiresMagic
( mconcat
[ long "requires-magic"
, help "The DB contains blocks from a testnet, requiring network magic, rather than mainnet"
]
)
<*> optional
( option
auto
( mconcat
[ long "genesisHash"
, help "Expected genesis hash"
, metavar "HASH"
]
)
)
<*> parsePBftSignatureThreshold
5 changes: 3 additions & 2 deletions ouroboros-consensus-cardano/app/DBTruncater/Parsers.hs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import DBAnalyser.Parsers
import Options.Applicative
import Ouroboros.Consensus.Block.Abstract

commandLineParser :: Parser (DBTruncaterConfig, BlockType)
commandLineParser = (,) <$> parseDBTruncaterConfig <*> blockTypeParser
commandLineParser :: Parser (DBTruncaterConfig, CardanoBlockArgs)
commandLineParser = (,) <$> parseDBTruncaterConfig <*> parseCardanoArgs

parseDBTruncaterConfig :: Parser DBTruncaterConfig
parseDBTruncaterConfig =
Expand All @@ -23,6 +23,7 @@ parseDBTruncaterConfig =
, metavar "PATH"
]
parseVerbose = switch (long "verbose" <> help "Enable verbose logging")

parseTruncateAfter :: Parser TruncateAfter
parseTruncateAfter =
fmap TruncateAfterSlot slotNoOption <|> fmap TruncateAfterBlock blockNoOption
Expand Down
21 changes: 3 additions & 18 deletions ouroboros-consensus-cardano/app/db-analyser.hs
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,10 @@
{-# LANGUAGE ScopedTypeVariables #-}

-- | Database analysis tool.
--
-- Usage: db-analyser --db PATH [--verbose] [--analyse-from SLOT_NUMBER]
-- [--db-validation ARG]
-- [--show-slot-block-no | --count-tx-outputs |
-- --show-block-header-size | --show-block-txs-size |
-- --show-ebbs | --store-ledger SLOT_NUMBER
-- [--full-ledger-validation] |
-- --count-blocks | --checkThunks BLOCK_COUNT |
-- --trace-ledger | --repro-mempool-and-forge INT |
-- --benchmark-ledger-ops [--out-file FILE] [--reapply] |
-- --get-block-application-metrics NUM [--out-file FILE]]
-- [--num-blocks-to-process INT] COMMAND
module Main (main) where

import Cardano.Crypto.Init (cryptoInit)
import Cardano.Tools.DBAnalyser.Block.Cardano
import Cardano.Tools.DBAnalyser.Run
import Cardano.Tools.DBAnalyser.Types
import Cardano.Tools.GitRev (gitRev)
Expand All @@ -38,13 +27,9 @@ import Options.Applicative
main :: IO ()
main = withStdTerminalHandles $ do
cryptoInit
(conf, blocktype) <- getCmdLine
void $ case blocktype of
ByronBlock args -> analyse conf args
ShelleyBlock args -> analyse conf args
CardanoBlock args -> analyse conf args
void $ uncurry analyse =<< getCmdLine

getCmdLine :: IO (DBAnalyserConfig, BlockType)
getCmdLine :: IO (DBAnalyserConfig, CardanoBlockArgs)
getCmdLine = execParser opts
where
opts =
Expand Down
10 changes: 3 additions & 7 deletions ouroboros-consensus-cardano/app/db-truncater.hs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module Main (main) where
import Cardano.Crypto.Init (cryptoInit)
import Cardano.Tools.DBTruncater.Run
import Cardano.Tools.DBTruncater.Types
import DBAnalyser.Parsers (BlockType (..))
import DBAnalyser.Parsers
import qualified DBTruncater.Parsers as DBTruncater
import Main.Utf8 (withStdTerminalHandles)
import Options.Applicative
Expand All @@ -20,13 +20,9 @@ import Prelude hiding (truncate)
main :: IO ()
main = withStdTerminalHandles $ do
cryptoInit
(conf, blocktype) <- getCommandLineConfig
case blocktype of
ByronBlock args -> truncate conf args
ShelleyBlock args -> truncate conf args
CardanoBlock args -> truncate conf args
uncurry truncate =<< getCommandLineConfig

getCommandLineConfig :: IO (DBTruncaterConfig, BlockType)
getCommandLineConfig :: IO (DBTruncaterConfig, CardanoBlockArgs)
getCommandLineConfig = execParser opts
where
opts =
Expand Down
10 changes: 3 additions & 7 deletions ouroboros-consensus-cardano/app/snapshot-converter.hs
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,11 @@ data Config = Config
-- ^ Path to the output snapshot
}

getCommandLineConfig :: IO (Config, BlockType)
getCommandLineConfig :: IO (Config, CardanoBlockArgs)
getCommandLineConfig =
execParser $
info
((,) <$> parseConfig <*> blockTypeParser <**> helper)
((,) <$> parseConfig <*> parseCardanoArgs <**> helper)
(fullDesc <> progDesc "Utility for converting snapshots to and from UTxO-HD")

parseConfig :: Parser Config
Expand Down Expand Up @@ -260,11 +260,7 @@ store _ _ _ _ = error "Malformed output path!"
main :: IO ()
main = withStdTerminalHandles $ do
cryptoInit
(conf, blocktype) <- getCommandLineConfig
case blocktype of
ByronBlock args -> run conf args
ShelleyBlock args -> run conf args
CardanoBlock args -> run conf args
uncurry run =<< getCommandLineConfig
where
run conf args = do
ccfg <- configCodec . pInfoConfig <$> mkProtocolInfo args
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<!--
A new scriv changelog fragment.
Uncomment the section that is right (remove the HTML comment wrapper).
For top level release notes, leave all the headers commented out.
-->

<!--
### Patch
- A bullet item for the Patch category.
-->
<!--
### Non-Breaking
- A bullet item for the Non-Breaking category.
-->
<!--
### Breaking
- A bullet item for the Breaking category.
-->
Original file line number Diff line number Diff line change
Expand Up @@ -505,9 +505,6 @@ library unstable-cardano-tools
hs-source-dirs: src/unstable-cardano-tools
exposed-modules:
Cardano.Api.Any
Cardano.Api.Protocol.Types
Cardano.Node.Protocol
Cardano.Node.Protocol.Types
Cardano.Node.Types
Cardano.Tools.DBAnalyser.Analysis
Cardano.Tools.DBAnalyser.Analysis.BenchmarkLedgerOps.FileWriting
Expand Down Expand Up @@ -608,7 +605,6 @@ executable db-analyser
build-depends:
base,
cardano-crypto-class,
cardano-crypto-wrapper,
optparse-applicative,
ouroboros-consensus,
ouroboros-consensus-cardano:{ouroboros-consensus-cardano, unstable-cardano-tools},
Expand Down Expand Up @@ -666,7 +662,6 @@ executable db-truncater
build-depends:
base,
cardano-crypto-class,
cardano-crypto-wrapper,
optparse-applicative,
ouroboros-consensus,
ouroboros-consensus-cardano:{ouroboros-consensus-cardano, unstable-cardano-tools},
Expand Down Expand Up @@ -697,7 +692,6 @@ executable snapshot-converter
base,
bytestring,
cardano-crypto-class,
cardano-crypto-wrapper,
contra-tracer,
filepath,
fs-api,
Expand Down
Loading
Loading