Skip to content
This repository has been archived by the owner on Feb 9, 2021. It is now read-only.

Commit

Permalink
Add compile-time flag for enabling UTxO-related logs during epoch val…
Browse files Browse the repository at this point in the history
…idation
  • Loading branch information
intricate committed May 6, 2019
1 parent 0a7b7c5 commit 7f34aaf
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 7 deletions.
7 changes: 7 additions & 0 deletions cardano-ledger.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ flag development
default: False
manual: True

Flag debug-epoch-validation
description: Enable debug log output for epoch validation.
default: False

library
hs-source-dirs: src
exposed-modules:
Expand Down Expand Up @@ -154,6 +158,9 @@ library
if (!flag(development))
ghc-options: -Werror

if flag(debug-epoch-validation)
cpp-options: -DDEBUG_EPOCH_VALIDATION

test-suite cardano-ledger-test
hs-source-dirs: test
main-is: test.hs
Expand Down
31 changes: 24 additions & 7 deletions src/Cardano/Chain/Epoch/Validation.hs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{-# LANGUAGE CPP #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE OverloadedStrings #-}
Expand Down Expand Up @@ -25,10 +26,7 @@ import Cardano.Chain.Block
( ABlockOrBoundary(..)
, ChainValidationError
, ChainValidationState(..)
, HeapSize
, UTxOSize
, blockSlot
, calcUTxOSize
, updateChainBlockOrBoundary
)
import Cardano.Chain.Epoch.File
Expand All @@ -40,7 +38,15 @@ import Cardano.Chain.Epoch.File
import qualified Cardano.Chain.Genesis as Genesis
import Cardano.Chain.Slotting
(EpochIndex, SlotId, slotNumberEpoch, unflattenSlotId)

#ifdef DEBUG_EPOCH_VALIDATION
import Cardano.Chain.Block
( HeapSize
, UTxOSize
, calcUTxOSize
)
import Cardano.Chain.Txp (UTxO)
#endif


data EpochError
Expand Down Expand Up @@ -77,19 +83,30 @@ validateEpochFile config trace logconf cvs fp = do
(sformat
epochValidationFormat
(slotNumberEpoch (Genesis.configEpochSlots config) (cvsLastSlot cvs))
#ifdef DEBUG_EPOCH_VALIDATION
utxoSize
heapSize
#endif
)
#ifdef DEBUG_EPOCH_VALIDATION
where
sizePair = calcUTxOSize (cvsUtxo cvs')
utxoSize = snd sizePair
heapSize = fst sizePair
#endif

epochValidationFormat :: Format r (EpochIndex -> UTxOSize -> HeapSize UTxO -> r)
epochValidationFormat
#ifdef DEBUG_EPOCH_VALIDATION
:: Format r (EpochIndex -> UTxOSize -> HeapSize UTxO -> r)
#else
:: Format r (EpochIndex -> r)
#endif
epochValidationFormat =
"Succesfully validated epoch " . build . "\n" .
"Number of UTxO entries at the end of the epoch: " . build . "\n" .
"UTxO heap size in words at the end of the epoch: " . build . "\n"
"Succesfully validated epoch " . build . "\n"
#ifdef DEBUG_EPOCH_VALIDATION
. "Number of UTxO entries at the end of the epoch: " . build . "\n"
. "UTxO heap size in words at the end of the epoch: " . build . "\n"
#endif


-- | Check that a list of epochs 'Block's are valid.
Expand Down

0 comments on commit 7f34aaf

Please sign in to comment.