-
Notifications
You must be signed in to change notification settings - Fork 87
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
Conversation
This includes #1928 until it is merged. UPDATE: merged |
8c96bc2
to
682f893
Compare
newtype ShelleyOtherHeaderEnvelopeError c = ShelleyOtherHeaderEnvelopeError { | ||
unShelleyOtherHeaderEnvelopeError :: STS.PredicateFailure (STS.CHAIN c) | ||
} | ||
deriving (Eq, Show) | ||
-- TODO fix thunks | ||
deriving NoUnexpectedThunks | ||
via OnlyCheckIsWHNF "ShelleyOtherHeaderEnvelopeError" (ShelleyOtherHeaderEnvelopeError c) |
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.
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
.
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.
Nice, much better.
682f893
to
f39c686
Compare
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`.
f39c686
to
5b20469
Compare
bors merge |
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 byapplyExtLedgerState
:applyChainTick
: executes theTICK
transitionvalidateHeader
:validateEnvelope
: default checksupdateConsensusState
: executes thePRTCL
transitionapplyLedgerBlock
: executes theBBODY
transition and the remaining checks that are part of theCHAIN
transitionThe 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 theTICK
transitionvalidateHeader
:validateEnvelope
: default checks + executes thechainChecks
updateConsensusState
: executes thePRTCL
transitionapplyLedgerBlock
: executes theBBODY
transitionNow 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 withapplyExtLedgerState
.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-specificOtherHeaderEnvelopeError
. We'll use this ability to do more header checks for Shelley without having to convert the errors toText
.HeaderValidation: pass more info to validateEnvelope
In particular, replace
BlockConfig
withTopLevelConfig
, and addLedgerView
. We need this extra data to do some more checks for Shelley.