Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Shelley: do the chainChecks in validateEnvelope #1963

Merged
merged 4 commits into from
Apr 17, 2020

Conversation

mrBliss
Copy link
Contributor

@mrBliss mrBliss commented Apr 16, 2020

In the Shelley ledger, the CHAIN rule is used to apply a whole block. In consensus, we split up the application of a block to the ledger into separate steps that are performed together by applyExtLedgerState:

  • applyChainTick: executes the TICK transition
  • validateHeader:
    • validateEnvelope: default checks
    • updateConsensusState: executes the PRTCL transition
  • applyLedgerBlock: executes the BBODY transition and the remaining checks that are part of the CHAIN transition

The unfortunate thing was that we had to copy-paste some checks part of the CHAIN transition that were not part of any subtransition.

The Shelley has recently factored out these checks into the chainChecks function. This commit takes advantage of this change. The new situation:

  • applyChainTick: executes the TICK transition
  • validateHeader:
    • validateEnvelope: default checks + executes the chainChecks
    • updateConsensusState: executes the PRTCL transition
  • applyLedgerBlock: executes the BBODY transition

Now all checks and transitions of the CHAIN rule nicely map onto separate steps in consensus.

Note that chainChecks can be done on the header, so this change means that we do these checks earlier, in the ChainSyncClient, instead of after downloading the block and applying it to the ledger with applyExtLedgerState.


To make this possible, some refactorings were needed:

  • HeaderValidation: export defaultValidateEnvelope

  • HeaderValidation: replace OtherEnvelopeError with a type family

    Instead of Text, we now allow a block-specific OtherHeaderEnvelopeError. We'll use this ability to do more header checks for Shelley without having to convert the errors to Text.

  • HeaderValidation: pass more info to validateEnvelope

    In particular, replace BlockConfig with TopLevelConfig, and add LedgerView. We need this extra data to do some more checks for Shelley.

@mrBliss mrBliss added the consensus issues related to ouroboros-consensus label Apr 16, 2020
@mrBliss mrBliss requested a review from edsko April 16, 2020 12:26
@mrBliss
Copy link
Contributor Author

mrBliss commented Apr 16, 2020

This includes #1928 until it is merged.

UPDATE: merged

@mrBliss mrBliss force-pushed the mrBliss/shelley-chainChecks branch from 8c96bc2 to 682f893 Compare April 16, 2020 16:01
@mrBliss mrBliss marked this pull request as ready for review April 16, 2020 16:03
Comment on lines 323 to 329
newtype ShelleyOtherHeaderEnvelopeError c = ShelleyOtherHeaderEnvelopeError {
unShelleyOtherHeaderEnvelopeError :: STS.PredicateFailure (STS.CHAIN c)
}
deriving (Eq, Show)
-- TODO fix thunks
deriving NoUnexpectedThunks
via OnlyCheckIsWHNF "ShelleyOtherHeaderEnvelopeError" (ShelleyOtherHeaderEnvelopeError c)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Let's make this an orphan instance of NoUnexpectedThunks instead, so that I'm forced to remove it when I add the right one in cardano-ledger-specs.

Copy link
Contributor

@edsko edsko left a comment

Choose a reason for hiding this comment

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

Nice, much better.

@mrBliss mrBliss force-pushed the mrBliss/shelley-chainChecks branch from 682f893 to f39c686 Compare April 17, 2020 12:08
Instead of `Text`, we now allow a block-specific `OtherHeaderEnvelopeError`.
We'll use this ability to do more header checks for Shelley without having to
convert the errors to `Text`.
In particular, replace `BlockConfig` with `TopLevelConfig`, and add
`LedgerView`. We need this extra data to do some more checks for Shelley.
In the Shelley ledger, the `CHAIN` rule is used to apply a whole block. In
consensus, we split up the application of a block to the ledger into separate
steps that are performed together by `applyExtLedgerState`:

* `applyChainTick`: executes the `TICK` transition
* `validateHeader`:
  - `validateEnvelope`: default checks
  - `updateConsensusState`: executes the `PRTCL` transition
* `applyLedgerBlock`: executes the `BBODY` transition and the remaining checks
   that are part of the `CHAIN` transition

The unfortunate thing was that we had to copy-paste some checks part of the
`CHAIN` transition that were not part of any subtransition.

The Shelley has recently factored out these checks into the `chainChecks`
function. This commit takes advantage of this change. The new situation:

* `applyChainTick`: executes the `TICK` transition
* `validateHeader`:
  - `validateEnvelope`: default checks + executes the `chainChecks`
  - `updateConsensusState`: executes the `PRTCL` transition
* `applyLedgerBlock`: executes the `BBODY` transition

Now all checks and transitions of the `CHAIN` rule nicely map onto separate
steps in consensus.

Note that `chainChecks` can be done on the header, so this change means that
we do these checks earlier, in the ChainSyncClient, instead of after
downloading the block and applying it to the ledger with
`applyExtLedgerState`.
@mrBliss mrBliss force-pushed the mrBliss/shelley-chainChecks branch from f39c686 to 5b20469 Compare April 17, 2020 12:09
@mrBliss
Copy link
Contributor Author

mrBliss commented Apr 17, 2020

bors merge

@iohk-bors
Copy link
Contributor

iohk-bors bot commented Apr 17, 2020

@iohk-bors iohk-bors bot merged commit 3ace637 into master Apr 17, 2020
@iohk-bors iohk-bors bot deleted the mrBliss/shelley-chainChecks branch April 17, 2020 12:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
consensus issues related to ouroboros-consensus
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants