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

[ADP-3212] Add voting certificates to primitive lib #4427

Merged
merged 9 commits into from
Feb 5, 2024

Conversation

paolino
Copy link
Collaborator

@paolino paolino commented Feb 1, 2024

  • Add Conway certificates support to primitive lib

ADP-3212

All credits to Pawel

@paolino paolino self-assigned this Feb 1, 2024
@paolino paolino force-pushed the paweljakubas/ADP-3212/voting-primitives branch from f8b7a65 to cda730c Compare February 1, 2024 18:55
Copy link
Contributor

@paweljakubas paweljakubas left a 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 :-)

@paolino paolino force-pushed the paweljakubas/ADP-3212/voting-primitives branch 2 times, most recently from d22b1f2 to 5f1bc71 Compare February 2, 2024 14:04
Copy link
Contributor

@HeinrichApfelmus HeinrichApfelmus left a 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/Types/DRep.hs Outdated Show resolved Hide resolved
lib/primitive/lib/Cardano/Wallet/Primitive/Types/DRep.hs Outdated Show resolved Hide resolved
lib/primitive/lib/Cardano/Wallet/Primitive/Types/DRep.hs Outdated Show resolved Hide resolved
lib/primitive/lib/Cardano/Wallet/Primitive/Types/DRep.hs Outdated Show resolved Hide resolved
lib/primitive/lib/Cardano/Wallet/Primitive/Types/DRep.hs Outdated Show resolved Hide resolved
lib/primitive/lib/Cardano/Wallet/Primitive/Types/DRep.hs Outdated Show resolved Hide resolved
lib/primitive/lib/Cardano/Wallet/Primitive/Types/DRep.hs Outdated Show resolved Hide resolved
lib/primitive/lib/Cardano/Wallet/Primitive/Types/DRep.hs Outdated Show resolved Hide resolved
lib/primitive/lib/Cardano/Wallet/Primitive/Types/DRep.hs Outdated Show resolved Hide resolved
Copy link
Contributor

@HeinrichApfelmus HeinrichApfelmus left a 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
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
| 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:

DCert

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.

Copy link
Contributor

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

Copy link
Contributor

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.

@HeinrichApfelmus
Copy link
Contributor

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. 👍

Copy link
Contributor

@HeinrichApfelmus HeinrichApfelmus left a 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'"
Copy link
Contributor

Choose a reason for hiding this comment

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

slipped away 😅

lib/primitive/lib/Cardano/Wallet/Primitive/Types/DRep.hs Outdated Show resolved Hide resolved
Comment on lines 396 to 410
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
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
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.

@@ -3717,18 +3729,13 @@ components:
asset_name: *assetName
operation: *ApiMintBurnOperation

ApiVoteAction: &ApiVoteAction
ApiDRep: &ApiDRep
<<: *anyVoting
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
<<: *anyVoting

Copy link
Contributor

Choose a reason for hiding this comment

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

good suggestion, thanks 💯

Comment on lines 3737 to 3738
Voting can be done together with delegation action or as a standalone action.
type: string
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
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.

Copy link
Contributor

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
Copy link
Contributor

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.

@paweljakubas paweljakubas added this pull request to the merge queue Feb 5, 2024
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Feb 5, 2024
@paweljakubas paweljakubas added this pull request to the merge queue Feb 5, 2024
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Feb 5, 2024
@paweljakubas paweljakubas added this pull request to the merge queue Feb 5, 2024
Merged via the queue into master with commit 30dc6ab Feb 5, 2024
3 checks passed
@paweljakubas paweljakubas deleted the paweljakubas/ADP-3212/voting-primitives branch February 5, 2024 16:51
WilliamKingNoel-Bot pushed a commit that referenced this pull request Feb 5, 2024
…x] Add Conway certificates support to primitive lib ADP-3212 All credits to Pawel Source commit: 30dc6ab
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants