This repository has been archived by the owner on Feb 9, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 13
[#526] Implement multiple validation modes #548
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
dafcecd
[#526] Add TxValidationMode data type
intricate 4b788bb
[#526] Add BlockValidationMode data type
intricate ac24dae
[#526] Implement validation modes
intricate 4d315c4
[#526] Add tests for multiple validation modes
intricate 3265e42
[#526] Remove MonadError constraint from registerEpoch and epochTrans…
intricate b764abe
[#526] Add ValidationMode and utilize with ReaderT
intricate File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
{-# LANGUAGE FlexibleContexts #-} | ||
|
||
module Cardano.Chain.Block.ValidationMode | ||
( BlockValidationMode (..) | ||
, toTxValidationMode | ||
) where | ||
|
||
import Cardano.Prelude | ||
|
||
import Cardano.Chain.UTxO.ValidationMode (TxValidationMode (..)) | ||
|
||
-------------------------------------------------------------------------------- | ||
-- BlockValidationMode | ||
-------------------------------------------------------------------------------- | ||
|
||
-- | Indicates what sort of block validation should be performed. | ||
data BlockValidationMode | ||
= BlockValidation | ||
-- ^ Perform all block validations. | ||
| NoBlockValidation | ||
-- ^ Perform no block validations. | ||
deriving (Eq, Show) | ||
|
||
-- | Translate a 'BlockValidationMode' to an appropriate 'TxValidationMode'. | ||
toTxValidationMode :: BlockValidationMode -> TxValidationMode | ||
toTxValidationMode BlockValidation = TxValidation | ||
toTxValidationMode NoBlockValidation = NoTxValidation |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -40,6 +40,7 @@ import qualified Cardano.Chain.Genesis as Genesis | |
import Cardano.Chain.Slotting | ||
(EpochNumber, EpochAndSlotCount, slotNumberEpoch, fromSlotNumber) | ||
import Cardano.Chain.UTxO (UTxO) | ||
import Cardano.Chain.ValidationMode (ValidationMode) | ||
|
||
|
||
data EpochError | ||
|
@@ -53,19 +54,18 @@ data EpochError | |
validateEpochFile | ||
:: forall m | ||
. (MonadIO m, MonadError EpochError m) | ||
=> Genesis.Config | ||
=> ValidationMode | ||
-> Genesis.Config | ||
-> LoggingLayer | ||
-> ChainValidationState | ||
-> FilePath | ||
-> m ChainValidationState | ||
validateEpochFile config ll cvs fp = do | ||
validateEpochFile vMode config ll cvs fp = do | ||
subTrace <- llAppendName ll "epoch-validation" (llBasicTrace ll) | ||
utxoSubTrace <- llAppendName ll "utxo-stats" subTrace | ||
res <- llBracketMonadX ll subTrace Log.Info "benchmark" $ | ||
liftIO $ runResourceT $ runExceptT $ foldChainValidationState | ||
config | ||
cvs | ||
stream | ||
liftIO $ runResourceT $ (`runReaderT` vMode) $ runExceptT $ | ||
foldChainValidationState config cvs stream | ||
either throwError (logResult subTrace utxoSubTrace) res | ||
where | ||
stream = parseEpochFileWithBoundary mainnetEpochSlots fp | ||
|
@@ -105,12 +105,14 @@ validateEpochFile config ll cvs fp = do | |
|
||
-- | Check that a list of epochs 'Block's are valid. | ||
validateEpochFiles | ||
:: Genesis.Config | ||
:: ValidationMode | ||
-> Genesis.Config | ||
-> ChainValidationState | ||
-> [FilePath] | ||
-> IO (Either EpochError ChainValidationState) | ||
validateEpochFiles config cvs fps = | ||
runResourceT . runExceptT $ foldChainValidationState config cvs stream | ||
validateEpochFiles vMode config cvs fps = | ||
runResourceT $ (`runReaderT` vMode) $ runExceptT | ||
(foldChainValidationState config cvs stream) | ||
where stream = parseEpochFilesWithBoundary mainnetEpochSlots fps | ||
|
||
|
||
|
@@ -119,14 +121,14 @@ foldChainValidationState | |
:: Genesis.Config | ||
-> ChainValidationState | ||
-> Stream (Of (ABlockOrBoundary ByteString)) (ExceptT ParseError ResIO) () | ||
-> ExceptT EpochError ResIO ChainValidationState | ||
-> ExceptT EpochError (ReaderT ValidationMode ResIO) ChainValidationState | ||
foldChainValidationState config chainValState blocks = S.foldM_ | ||
(\cvs block -> | ||
withExceptT (EpochChainValidationError (blockOrBoundarySlot block)) | ||
$ updateChainBlockOrBoundary config cvs block | ||
) | ||
(pure chainValState) | ||
pure $ hoist (withExceptT EpochParseError) blocks | ||
pure (pure (hoist (withExceptT EpochParseError) blocks)) | ||
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. Like above, |
||
where | ||
blockOrBoundarySlot :: ABlockOrBoundary a -> Maybe EpochAndSlotCount | ||
blockOrBoundarySlot = \case | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Something about
pure
andhoist
being used like that strikes me as odd. Its almost as if you need a transformers version ofControl.Monad.join
.