-
Notifications
You must be signed in to change notification settings - Fork 217
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
[ADP-3212] Add voting certificates to primitive lib #4427
Conversation
f8b7a65
to
cda730c
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.
of course from my point of view everything is good here. But would be good for @HeinrichApfelmus to do his due dilligence :-)
d22b1f2
to
5f1bc71
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.
Thanks for the split PR. 😊 Much easier to review.
@paweljakubas Could you rename the types to DRep
and DRepID
as I describe in the comments? I believe it's important that we use the exact same naming conventions as in the specification in order to avoid cognitive overhead — whenever we see the type DRep
in our code, we can be sure that it's the same DRep as mentioned in the specification, and some homegrown variant of it that may or may not work.
lib/primitive/lib/Cardano/Wallet/Primitive/Ledger/Read/Tx/Features/Certificates.hs
Outdated
Show resolved
Hide resolved
lib/primitive/lib/Cardano/Wallet/Primitive/Types/Certificates.hs
Outdated
Show resolved
Hide resolved
lib/primitive/lib/Cardano/Wallet/Primitive/Types/Certificates.hs
Outdated
Show resolved
Hide resolved
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.
Another request concerning the DelegationCertificate
type.
@@ -76,6 +80,8 @@ data DelegationCertificate | |||
= CertDelegateNone RewardAccount | |||
| CertDelegateFull RewardAccount PoolId | |||
| CertRegisterKey RewardAccount | |||
| CertVoteFull RewardAccount VoteAction | |||
| CertDelegateAndVoteFull RewardAccount PoolId VoteAction |
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.
| CertDelegateAndVoteFull RewardAccount PoolId VoteAction | |
| CertVoteAndDelegate RewardAccount (Maybe DRep) (Maybe PoolId) |
The formal specification for Conway uses the following constructor for the DCert
state transition datum:
Here, both voting and delegation are joined into a single constructor.
Again, in order to stick to existing naming conventions, I would follow their example here.
Using a single constructor is likely to slightly simplify our code. We could remove the CertDelegateFull
constructor as well, but that would involve changes to our code that are beyond the scope of this pull request.
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.
used CertVoteAndDelegate and removed other two that are handled here after adding optional pool and vote
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. 👍 I originally thought that CertVoteFull
had a wider impact on the code, but nice to see that it's blast radius is very limited.
I think the name changes are important in order to reduce cognitive load when comparing the specification to our code. Other than these changes, I'm happy to approve the pull request. 👍 |
5f1bc71
to
b3fc551
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.
Thanks! 😊 Only minor comments. I recommend to inline the definition of ApiDRep
in the swagger API specification again.
Right $ VoteTo $ DRepFromScriptHash scripthash | ||
Left _ -> Left $ TextDecodingError $ unwords | ||
[ "I couldn't parse the given vote action." | ||
, "I am expecting either 'abstain', 'no confidence'" |
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.
slipped away 😅
specifications/api/swagger.yaml
Outdated
x-noVote: &noVote | ||
type: string | ||
enum: | ||
- abstain | ||
- no_confidence | ||
|
||
x-anyVoting: &anyVoting | ||
nullable: false | ||
oneOf: | ||
- <<: *drepKeyHash | ||
title: vote to a drep represented by key hash | ||
- <<: *drepScriptHash | ||
title: vote to a drep represented by script hash | ||
- <<: *noVote | ||
title: casting no vote |
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.
x-noVote: &noVote | |
type: string | |
enum: | |
- abstain | |
- no_confidence | |
x-anyVoting: &anyVoting | |
nullable: false | |
oneOf: | |
- <<: *drepKeyHash | |
title: vote to a drep represented by key hash | |
- <<: *drepScriptHash | |
title: vote to a drep represented by script hash | |
- <<: *noVote | |
title: casting no vote |
I recommend that we mirror the definition of DRep
from the specification (and now from the code as well) in the ApiDRep
type, i.e. inline everything there.
specifications/api/swagger.yaml
Outdated
@@ -3717,18 +3729,13 @@ components: | |||
asset_name: *assetName | |||
operation: *ApiMintBurnOperation | |||
|
|||
ApiVoteAction: &ApiVoteAction | |||
ApiDRep: &ApiDRep | |||
<<: *anyVoting |
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.
<<: *anyVoting |
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.
good suggestion, thanks 💯
specifications/api/swagger.yaml
Outdated
Voting can be done together with delegation action or as a standalone action. | ||
type: string |
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.
Voting can be done together with delegation action or as a standalone action. | |
type: string | |
ApiDRep: &ApiDRep | |
description: | | |
Decentralized representative (DRep) | |
that the wallet is delegating its vote to. | |
One can abstain, give no confidence vote, | |
or vote for a representative specified by a key hash or script hash. | |
Vote delegation can be done together with stake delegation action. | |
nullable: false | |
type: string | |
oneOf: | |
- enum: | |
- abstain | |
- no_confidence | |
title: casting a default vote | |
- <<: *drepKeyHash | |
title: vote to a drep represented by key hash | |
- <<: *drepScriptHash | |
title: vote to a drep represented by script hash |
Inlined, and amended the formulation slightly.
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.
yes, sir
@@ -76,6 +80,8 @@ data DelegationCertificate | |||
= CertDelegateNone RewardAccount | |||
| CertDelegateFull RewardAccount PoolId | |||
| CertRegisterKey RewardAccount | |||
| CertVoteFull RewardAccount VoteAction | |||
| CertDelegateAndVoteFull RewardAccount PoolId VoteAction |
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. 👍 I originally thought that CertVoteFull
had a wider impact on the code, but nice to see that it's blast radius is very limited.
ADP-3212
All credits to Pawel