Skip to content

Commit

Permalink
Merge #3418
Browse files Browse the repository at this point in the history
3418: Add new analysis --count-blocks r=EncodePanda a=EncodePanda

```
cabal run ouroboros-consensus-cardano:db-analyser --\
  --db db_mainnet_with_alonzo_40217333 cardano \
  --configByron dbacfg/mainnet-byron-genesis.json \
  --configShelley dbacfg/mainnet-shelley-genesis.json \
  --nonce 1a3be38bcbb7911969283716ad7aa550250226b76a61fc51cc9a9a35d9276d81 \
  --configAlonzo dbacfg/mainnet-alonzo-genesis.json \
  --only-immutable-db \
  --analyse-from 39842441 \
  --count-blocks

About to count number of blocks processed...
Counted: 16378
```

Co-authored-by: EncodePanda <paul.szulc@gmail.com>
  • Loading branch information
iohk-bors[bot] and EncodePanda committed Oct 11, 2021
2 parents c834f35 + dca81ef commit c32bf73
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
14 changes: 14 additions & 0 deletions ouroboros-consensus-cardano/tools/db-analyser/Analysis.hs
Expand Up @@ -61,6 +61,7 @@ data AnalysisName =
| ShowEBBs
| OnlyValidation
| StoreLedgerStateAt SlotNo
| CountBlocks
deriving Show

runAnalysis ::
Expand All @@ -77,6 +78,7 @@ runAnalysis ShowBlockTxsSize = showBlockTxsSize
runAnalysis ShowEBBs = showEBBs
runAnalysis OnlyValidation = \_ -> return ()
runAnalysis (StoreLedgerStateAt slotNo) = storeLedgerStateAt slotNo
runAnalysis CountBlocks = countBlocks

type Analysis blk = AnalysisEnv blk -> IO ()

Expand Down Expand Up @@ -253,6 +255,18 @@ storeLedgerStateAt slotNo (AnalysisEnv { db, registry, initLedger, cfg, limit, l
(encodeDisk ccfg)
(encodeDisk ccfg)

countBlocks ::
forall blk .
( HasAnalysis blk
)
=> Analysis blk
countBlocks (AnalysisEnv { db, registry, initLedger, limit }) = do
putStrLn $ "About to count number of blocks ..."
counted <- processAll db registry (GetPure ()) initLedger limit 0 process
putStrLn $ "Counted: " <> show counted <> " blocks."
where
process :: Int -> () -> IO Int
process count _ = pure $ count + 1
{-------------------------------------------------------------------------------
Auxiliary: processing all blocks in the DB
-------------------------------------------------------------------------------}
Expand Down
4 changes: 4 additions & 0 deletions ouroboros-consensus-cardano/tools/db-analyser/Main.hs
Expand Up @@ -145,6 +145,10 @@ parseAnalysis = asum [
, help "Show all EBBs and their predecessors"
]
, storeLedgerParser
, flag' CountBlocks $ mconcat [
long "count-blocks"
, help "Count number of blocks processed"
]
, pure OnlyValidation
]

Expand Down

0 comments on commit c32bf73

Please sign in to comment.