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

refactor(x/gov): swap vote alias #19718

Merged
merged 2 commits into from
Mar 12, 2024
Merged

refactor(x/gov): swap vote alias #19718

merged 2 commits into from
Mar 12, 2024

Conversation

julienrbrt
Copy link
Member

@julienrbrt julienrbrt commented Mar 11, 2024

Description

ref: #19228

The rationale of this change is to not introduce a signing change in textual until we fix #19228 for all platforms.
Swapping the alias vs default only changes how the enum is marshalled, but a user can still sign (using sign mode direct) using both options.

This allows us as well to use the latest api in v0.50 without unforeseen consequences.


Author Checklist

All items are required. Please add a note to the item if the item is not applicable and
please add links to any relevant follow up issues.

I have...

  • included the correct type prefix in the PR title
  • confirmed ! in the type prefix if API or client breaking change
  • targeted the correct branch (see PR Targeting)
  • provided a link to the relevant issue or specification
  • reviewed "Files changed" and left comments if necessary
  • included the necessary unit and integration tests
  • added a changelog entry to CHANGELOG.md
  • updated the relevant documentation or specification, including comments for documenting Go code
  • confirmed all CI checks have passed

Reviewers Checklist

All items are required. Please add a note if the item is not applicable and please add
your handle next to the items reviewed if you only reviewed selected items.

I have...

  • confirmed the correct type prefix in the PR title
  • confirmed all author checklist items have been addressed
  • reviewed state machine logic, API design and naming, documentation is accurate, tests and test coverage

Summary by CodeRabbit

  • New Features

    • Enhanced voting clarity in governance module with descriptive vote option names like "YES" and "NO".
  • Refactor

    • Reordered and renamed vote options for improved readability and consistency in governance proposals.
  • Bug Fixes

    • Updated test cases to reflect changes in vote option names and weights, ensuring accurate error messages and vote normalization.
  • Tests

    • Added new test cases for validating voting messages, focusing on correct decoding and error handling.

@julienrbrt julienrbrt requested a review from a team as a code owner March 11, 2024 13:36
Copy link
Contributor

coderabbitai bot commented Mar 11, 2024

Walkthrough

Walkthrough

The changes focus on enhancing the Cosmos SDK's voting experience by reordering and renaming vote options for better clarity and consistency across different voting modes. These adjustments include updating names to descriptive ones, revising test cases and error messages to align with the changes, and ensuring compatibility and interchangeability of voting options in multiple choice proposals.

Changes

Files Change Summary
api/cosmos/gov/v1/gov.pulsar.go Reordered and renamed VoteOption constants, adjusted their values and mappings.
x/gov/client/utils/utils_test.go Updated normalization of weighted vote options with descriptive names.
x/gov/keeper/msg_server_test.go Updated expected error messages and weights in test cases for voting.
x/gov/proto/cosmos/gov/v1/gov.proto Adjusted the VoteOption enum values to match the new order.
x/gov/types/v1/gov.pb.go, x/gov/types/v1/vote_test.go Removed outdated options, reordered VoteOption constants, and added tests for voting messages.

Assessment against linked issues

Objective Addressed Explanation
Maintain backward compatibility, alias voting options in multiple choice proposals (#19228)
Ensure voting options are interchangeable in sign mode direct for multiple choice proposals (#19228)
Address aliasing issues in sign mode textual for multiple choice proposals (#19228) The changes do not explicitly mention addressing aliasing issues in sign mode textual.
Investigate custom message render option for government voting to resolve aliasing issue (#19228) There's no indication of a custom message render option being investigated or implemented.
Propose a quick solution by inverting the alias to have "yes, no, abstain" as default and options as aliases (#19228)
Consider the drawback of voting for a multiple choice proposal using textual mode may display default options instead of actual options (#19228) While the changes aim at improving clarity, it's unclear how the drawback is addressed or considered.

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share

Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit-tests for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit tests for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit tests.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • The JSON schema for the configuration file is available here.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/coderabbit-overrides.v2.json

CodeRabbit Discord Community

Join our Discord Community to get help, request features, and share feedback.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Review Status

Actionable comments generated: 5

Configuration used: .coderabbit.yml

Commits Files that changed from the base of the PR and between defab1a and 044b123.
Files selected for processing (6)
  • api/cosmos/gov/v1/gov.pulsar.go (3 hunks)
  • x/gov/client/utils/utils_test.go (1 hunks)
  • x/gov/keeper/msg_server_test.go (5 hunks)
  • x/gov/proto/cosmos/gov/v1/gov.proto (1 hunks)
  • x/gov/types/v1/gov.pb.go (3 hunks)
  • x/gov/types/v1/vote_test.go (1 hunks)
Additional comments: 10
x/gov/types/v1/vote_test.go (1)
  • 14-61: The test function TestVoteAlias is well-structured and covers scenarios for valid votes, valid vote aliases, and invalid votes. However, there are a couple of points to consider:
  • The test case for "valid vote alias" (lines 33-42) uses VOTE_OPTION_ONE as an option, which according to the PR objectives and summaries, should have been removed or replaced. This might indicate either an inconsistency in the PR's implementation or an outdated test case. Please verify the current state of vote options and update the test case accordingly.
  • It's good practice to also include a test case for deserialization success, where you assert the deserialized object (vote) against the expected field of the test case to ensure that the unmarshalling not only doesn't produce an error but also results in the correct object state.
x/gov/proto/cosmos/gov/v1/gov.proto (1)
  • 38-51: The changes to the VoteOption enum introduce aliases for vote options, allowing "VOTE_OPTION_ONE", "VOTE_OPTION_TWO", etc., to have the same numeric values as "VOTE_OPTION_YES", "VOTE_OPTION_ABSTAIN", and so on. This approach aligns with the PR's objective to improve the voting experience by making vote options interchangeable. However, there are a few considerations:
  • Ensure that the introduction of aliases does not introduce ambiguity or confusion for developers and users. Clear documentation and comments in the code explaining the rationale and usage of these aliases would be beneficial.
  • Verify that all parts of the system that consume these vote options can handle aliases correctly, especially in serialization and deserialization logic, to prevent any unexpected behavior.
x/gov/keeper/msg_server_test.go (5)
  • 729-729: The error message for a zero weight vote option seems to be hardcoded with specific values. Consider using dynamic values based on the test case inputs to make the test more flexible and maintainable.
  • 741-741: Similar to the previous comment, the error message for a negative weight vote option is hardcoded. It's advisable to use dynamic values derived from the test inputs for better test maintainability.
  • 754-754: The error message for an individual weight greater than 1 but with a total weight equal to 1 is hardcoded. Using dynamic values from the test inputs would enhance the test's flexibility and maintainability.
  • 1371-1371: The error message for a zero weight in the TestLegacyVoteWeighted test is hardcoded. Consider using dynamic values based on the test case inputs for improved test maintainability.
  • 1386-1386: Similar to previous comments, the error message for a negative weight in the TestLegacyVoteWeighted test is hardcoded. Using dynamic values from the test inputs would make the test more maintainable.
x/gov/types/v1/gov.pb.go (3)
  • 84-97: The constants VOTE_OPTION_ONE, VOTE_OPTION_TWO, VOTE_OPTION_THREE, and VOTE_OPTION_FOUR have been removed as part of the refactor. This change aligns with the PR's objective to simplify the vote options by using more descriptive names and removing less meaningful numerical options. This should enhance clarity and usability in the governance module.
  • 104-124: The mappings in VoteOption_name and VoteOption_value have been updated to reflect the removal of numerical vote options and the reordering of existing options. This update is crucial for ensuring that the enum values and their string representations remain consistent and accurate, which is essential for both internal processing and user interfaces.
  • 1424-1444: > 📝 NOTE

This review was outside the diff hunks and was mapped to the diff hunk with the greatest overlap. Original lines [1325-1441]

The decrease in the size of the fileDescriptor_e05cb1c0d030febb byte slice is a direct result of the changes made to the VoteOption enum, including the removal of certain options and the update to mappings. This change is expected and indicates that the generated file descriptor accurately reflects the current state of the .proto file.

x/gov/client/utils/utils_test.go Show resolved Hide resolved
api/cosmos/gov/v1/gov.pulsar.go Outdated Show resolved Hide resolved
api/cosmos/gov/v1/gov.pulsar.go Outdated Show resolved Hide resolved
api/cosmos/gov/v1/gov.pulsar.go Outdated Show resolved Hide resolved
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Review Status

Actionable comments generated: 0

Configuration used: .coderabbit.yml

Commits Files that changed from the base of the PR and between 044b123 and 73bca9d.
Files selected for processing (1)
  • x/gov/types/v1/vote_test.go (1 hunks)
Files skipped from review as they are similar to previous changes (1)
  • x/gov/types/v1/vote_test.go

@julienrbrt
Copy link
Member Author

@coderabbitai shut up

Copy link
Contributor

coderabbitai bot commented Mar 11, 2024

Tip

For best results, initiate chat on the files or code changes.

I understand. If you have any further questions or need assistance in the future, feel free to reach out.

Copy link
Contributor

@likhita-809 likhita-809 left a comment

Choose a reason for hiding this comment

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

lgtm

@julienrbrt julienrbrt added this pull request to the merge queue Mar 12, 2024
Merged via the queue into main with commit d808ef8 Mar 12, 2024
62 of 63 checks passed
@julienrbrt julienrbrt deleted the julien/gov-alias branch March 12, 2024 08:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Textual and Voting Options
4 participants