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

[#526] Implement multiple validation modes #548

Merged
merged 6 commits into from
Jun 20, 2019

Conversation

intricate
Copy link
Contributor

@intricate intricate commented Jun 11, 2019

Closes #526

@intricate intricate self-assigned this Jun 11, 2019
@intricate intricate force-pushed the intricate/validation-modes branch from 5706b8e to bcffa9a Compare June 11, 2019 22:20
cardano-ledger/src/Cardano/Chain/Block/Validation.hs Outdated Show resolved Hide resolved
, Update.ppMaxBlockSize = 748 * pps ^. maxBkSz
, Update.ppMaxHeaderSize = 95 * pps ^. maxHdrSz
, Update.ppMaxBlockSize = 832 * pps ^. maxBkSz
, Update.ppMaxHeaderSize = 569 * pps ^. maxHdrSz
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What are these changes about?

Copy link
Contributor Author

@intricate intricate Jun 11, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll have to add a comment explaining these. These seem to be the minimum constant multipliers that I can use for elaborating abstract size limits such that all tests still pass without returning "block too large" or "block header too large" errors.

In cardano-ledger-specs, Sizes are represented differently than they are in the concrete implementation (where they're represented in actual bytes) and I'm unsure as to how we can accurately convert between the two.

@intricate intricate force-pushed the intricate/validation-modes branch from bcffa9a to 0b64a31 Compare June 11, 2019 22:31
@intricate intricate force-pushed the intricate/validation-modes branch from 0b64a31 to d6deeb1 Compare June 12, 2019 01:49
@intricate intricate changed the title Implement multiple validation modes [#526] Implement multiple validation modes Jun 12, 2019
abstractTxWits

-- Validate the generated concrete transaction
let pm = Dummy.aProtocolMagic
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will address these Dummy.aProtocolMagics tomorrow.

@dnadales
Copy link
Contributor

I'm a bit confused by this, so sorry for the silly question:

There should be three scenarios: NewSignal/NewState, OldSignal/NewState, OldSignal/OldState

Do we care about these scenarios? I thought this was about checking whether we would perform validation or not when applying a block.

Copy link
Contributor

@ruhatch ruhatch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, so quite a few changes here, but the general structure is good.

cardano-ledger/src/Cardano/Chain/Block/Validation.hs Outdated Show resolved Hide resolved
cardano-ledger/src/Cardano/Chain/Block/Validation.hs Outdated Show resolved Hide resolved
cardano-ledger/src/Cardano/Chain/Block/Validation.hs Outdated Show resolved Hide resolved
cardano-ledger/src/Cardano/Chain/Block/ValidationMode.hs Outdated Show resolved Hide resolved
cardano-ledger/src/Cardano/Chain/Block/ValidationMode.hs Outdated Show resolved Hide resolved
cardano-ledger/src/Cardano/Chain/Epoch/Validation.hs Outdated Show resolved Hide resolved
cardano-ledger/src/Cardano/Chain/UTxO/ValidationMode.hs Outdated Show resolved Hide resolved
@intricate intricate force-pushed the intricate/validation-modes branch 6 times, most recently from 4b4445f to da3046c Compare June 14, 2019 02:20
foldUTxO env utxo blocks = S.foldM_
(foldUTxOBlock env)
(pure utxo)
pure
(hoist (withExceptT ErrorParseError) blocks)
(pure (hoist (withExceptT ErrorParseError) blocks))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Something about pure and hoist being used like that strikes me as odd. Its almost as if you need a transformers version of Control.Monad.join.

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))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Like above, pure . pure . hoist seems weird.

@intricate intricate force-pushed the intricate/validation-modes branch from da3046c to ff7c06b Compare June 14, 2019 03:41
@intricate intricate force-pushed the intricate/validation-modes branch 2 times, most recently from 791ad88 to bd6b851 Compare June 17, 2019 01:59
--
-- If we could find some way to convert the error type in a 'MonadError' then
-- we could re-write 'wrapError' in a more abstract way.
wrapExceptTError :: MonadError e' m => ExceptT e m a -> (e -> e') -> m a
Copy link
Contributor Author

@intricate intricate Jun 17, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ruhatch @dnadales: Is it cool if I move this into cardano-prelude or do you guys perhaps have a more clever way of doing this (see comment above this function definition)?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

@ruhatch ruhatch Jun 17, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@intricate what about:

wrapErrorWithValidationMode
  :: (MonadError e' m, MonadReader ValidationMode m) 
  => ReaderT ValidationMode (Either e a) 
  -> (e -> e') 
  -> m a
wrapErrorWithValidationMode readerAction = do
  validationMode <- ask
  runReaderT readerAction validationMode >>= \case
    Left err -> throwError $ wrapper err
    Right x -> pure x

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let me know if there are any type errors with that, but I think it should work

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

Only had to make a slight change to type sig

wrapErrorWithValidationMode
  :: (MonadError e' m, MonadReader ValidationMode m) 
  => ReaderT ValidationMode (Either e) a 
  -> (e -> e') 
  -> m a

cardano-ledger/src/Cardano/Chain/ValidationMode.hs Outdated Show resolved Hide resolved
cardano-ledger/src/Cardano/Chain/ValidationMode.hs Outdated Show resolved Hide resolved
cardano-ledger/src/Cardano/Chain/ValidationMode.hs Outdated Show resolved Hide resolved
cardano-ledger/src/Cardano/Chain/ValidationMode.hs Outdated Show resolved Hide resolved
cardano-ledger/src/Cardano/Chain/ValidationMode.hs Outdated Show resolved Hide resolved
--
-- If we could find some way to convert the error type in a 'MonadError' then
-- we could re-write 'wrapError' in a more abstract way.
wrapExceptTError :: MonadError e' m => ExceptT e m a -> (e -> e') -> m a
Copy link
Contributor

@ruhatch ruhatch Jun 17, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@intricate what about:

wrapErrorWithValidationMode
  :: (MonadError e' m, MonadReader ValidationMode m) 
  => ReaderT ValidationMode (Either e a) 
  -> (e -> e') 
  -> m a
wrapErrorWithValidationMode readerAction = do
  validationMode <- ask
  runReaderT readerAction validationMode >>= \case
    Left err -> throwError $ wrapper err
    Right x -> pure x

--
-- If we could find some way to convert the error type in a 'MonadError' then
-- we could re-write 'wrapError' in a more abstract way.
wrapExceptTError :: MonadError e' m => ExceptT e m a -> (e -> e') -> m a
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let me know if there are any type errors with that, but I think it should work

@intricate intricate force-pushed the intricate/validation-modes branch 2 times, most recently from 1ec04bb to 5a0c845 Compare June 17, 2019 23:26
@intricate intricate force-pushed the intricate/validation-modes branch from 5a0c845 to 0737b86 Compare June 18, 2019 06:35
@intricate intricate marked this pull request as ready for review June 18, 2019 06:35
@intricate intricate force-pushed the intricate/validation-modes branch 3 times, most recently from 1418098 to 80a4361 Compare June 18, 2019 06:47
@intricate intricate requested a review from ruhatch June 18, 2019 13:56
@intricate intricate force-pushed the intricate/validation-modes branch from 80a4361 to b764abe Compare June 18, 2019 22:25
Copy link
Contributor

@ruhatch ruhatch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks really good I think - worth several rounds of review :)

@ruhatch
Copy link
Contributor

ruhatch commented Jun 20, 2019

bors r+

iohk-bors bot added a commit that referenced this pull request Jun 20, 2019
548: [#526] Implement multiple validation modes r=ruhatch a=intricate

Closes #526 

Co-authored-by: Luke Nadur <[email protected]>
@iohk-bors
Copy link
Contributor

iohk-bors bot commented Jun 20, 2019

@iohk-bors iohk-bors bot merged commit b764abe into master Jun 20, 2019
@iohk-bors iohk-bors bot deleted the intricate/validation-modes branch June 20, 2019 10:25
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Implement multiple validation modes
4 participants