-
Notifications
You must be signed in to change notification settings - Fork 165
Shelley: Move withdrawals draining from DELEGS to LEDGER #5341
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
base: master
Are you sure you want to change the base?
Conversation
551ba54
to
6b22c6f
Compare
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.
I assume there should be a CDDL change that goes along with this.
( env@(DelegsEnv slot@(SlotNo slot64) epochNo txIx pp _tx chainAccountState) | ||
, certState | ||
, certificates | ||
) <- |
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.
The indentation seems off here
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.
Looks like a problem with fourmolu or ormolu. Wanna create a minimal reproducer, see who is at fault and submit a ticket about it?
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.
I noticed the same indentation in govTransition
and conwayDelegTransition
and other places, seemingly consistent. Will definitely create a minimal reproducer 👍 and open an issue, though I'm not sure as to what the expected indentation is and what is exactly wrong with this one.
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.
I assume there should be a CDDL change that goes along with this.
Although PredicateFailure
s have CBOR instances I don't think we maintain a .cddl
specification for them. Please correct me if I'm wrong.
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.
Although PredicateFailures have CBOR instances I don't think we maintain a .cddl specification for them.
We have a long standing issue about that: #3392
One day we will implement it. Maybe we can start with Dijkstra era. I think that would be a huge step forward in terms of downstream usability
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.
I'm not sure as to what the expected indentation is and what is exactly wrong with this one.
@aniketd I'd suggest look for existing issues about that on ormolu and fourmolu and if there is nothing there, then starting a discussion about this won't hurt. I suspect there might be a reason why it is done that way. I can certainly see why, for example, it has to be done that way in the do syntax, when pattern matching on just a tuple:
foo = do
( a
, b
, c ) <- blah
pure c
Because if you don't, then it will result in an invalid syntax:
foo = do
( a
, b
, c ) <- blah
pure c
But, this is not a problem when it is with another type like here TRC (a, ....
6b22c6f
to
cd62aa5
Compare
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.
Looks good to me, but some tests are failing, they probably need to be adjusted to the changes.
(invalidWithdrawals, incompleteWithdrawals) = | ||
case withdrawalsThatDoNotDrainAccounts withdrawals network $ certState ^. certDStateL . accountsL of | ||
Nothing -> (Nothing, Nothing) | ||
Just (invalid, incomplete) -> | ||
( if null (unWithdrawals invalid) then Nothing else Just invalid | ||
, if null (unWithdrawals incomplete) then Nothing else Just incomplete | ||
) |
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.
This is duplicated in Conway but I can't come up with any meaningful name for what it's doing, since it's just calling this function and populating the Maybes, so I don't think there's any point extracting and reusing it.
Including it in the function is also not an option, since the resulting Maybe is used on its own on the other branch of the HF check.
So anyway, the duplication is a bit unpleasant, but i don't have any solution, just pointing it out.
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.
There is a very nice way to deduplicate this. Predicate injection mechanism allows us to extract both of the checks and reuse them directly in Conway too:
testIncompleteAndMissingWithdrawals = do
network <- liftSTS $ asks networkId
let accounts = certState ^. certDStateL . accountsL
withdrawals = tx ^. bodyTxL . withdrawalsTxBodyL
(invalidWithdrawals, incompleteWithdrawals) =
case withdrawalsThatDoNotDrainAccounts withdrawals network accounts of
Nothing -> (Nothing, Nothing)
Just (invalid, incomplete) ->
( if null (unWithdrawals invalid) then Nothing else Just invalid
, if null (unWithdrawals incomplete) then Nothing else Just incomplete
)
failOnJust invalidWithdrawals (injectFailure . ShelleyWithdrawalsMissingAccounts)
failOnJust incompleteWithdrawals (injectFailure . ShelleyIncompleteWithdrawals)
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.
I was able to get this to work by passing the constructors for the predicate failures as arguments, since the constructors themselves are era specific. The other way I see this can be done is by keeping the failOnJust
lines as they are (within the rule transition functions) and making testIncompleteAndMissingWithdrawals
return the missing or incomplete withdrawals, perhaps also changing its name to something like getIncompleteAndMissingWithdrawals
. What do you think?
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.
What do you think?
I think you did not look into my suggestion very carefully. The key part of the suggestion is injectFailure
.
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.
Looks great! Once duplication is removed as suggestd we should be able to merge this PR.
Thank you!
( env@(DelegsEnv slot@(SlotNo slot64) epochNo txIx pp _tx chainAccountState) | ||
, certState | ||
, certificates | ||
) <- |
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.
Looks like a problem with fourmolu or ormolu. Wanna create a minimal reproducer, see who is at fault and submit a ticket about it?
(invalidWithdrawals, incompleteWithdrawals) = | ||
case withdrawalsThatDoNotDrainAccounts withdrawals network $ certState ^. certDStateL . accountsL of | ||
Nothing -> (Nothing, Nothing) | ||
Just (invalid, incomplete) -> | ||
( if null (unWithdrawals invalid) then Nothing else Just invalid | ||
, if null (unWithdrawals incomplete) then Nothing else Just incomplete | ||
) |
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.
There is a very nice way to deduplicate this. Predicate injection mechanism allows us to extract both of the checks and reuse them directly in Conway too:
testIncompleteAndMissingWithdrawals = do
network <- liftSTS $ asks networkId
let accounts = certState ^. certDStateL . accountsL
withdrawals = tx ^. bodyTxL . withdrawalsTxBodyL
(invalidWithdrawals, incompleteWithdrawals) =
case withdrawalsThatDoNotDrainAccounts withdrawals network accounts of
Nothing -> (Nothing, Nothing)
Just (invalid, incomplete) ->
( if null (unWithdrawals invalid) then Nothing else Just invalid
, if null (unWithdrawals incomplete) then Nothing else Just incomplete
)
failOnJust invalidWithdrawals (injectFailure . ShelleyWithdrawalsMissingAccounts)
failOnJust incompleteWithdrawals (injectFailure . ShelleyIncompleteWithdrawals)
cd62aa5
to
0016f0e
Compare
* Remove `WIthdrawalsNotInRewardsDELEGS` pred-failure. * Add `ShelleyWithdrawalsMissingAccounts` and `ShelleyIncompleteWithdrawals` to `ShelleyLedgerPredFailure`.
0016f0e
to
4960c24
Compare
Description
Checklist
CHANGELOG.md
files updated for packages with externally visible changes.NOTE: New section is never added with the code changes. (See RELEASING.md).
.cabal
andCHANGELOG.md
files when necessary, according to theversioning process.
.cabal
files updated when necessary.NOTE: If bounds change in a cabal file, that package itself must have a version increase. (See RELEASING.md).
scripts/fourmolize.sh
).scripts/cabal-format.sh
).scripts/gen-cddl.sh
)hie.yaml
updated (usescripts/gen-hie.sh
).