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

feat(x/gov): add yes_quorum parameter #19167

Merged
merged 23 commits into from
Jan 30, 2024
Merged

Conversation

julienrbrt
Copy link
Member

@julienrbrt julienrbrt commented Jan 23, 2024

Description

Closes: #11461

Based on #19101 as it is a good parameter to add to msg based params.
#19101 must be merged first.


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

This comment has been minimized.

Copy link
Contributor

@alexanderbez alexanderbez left a comment

Choose a reason for hiding this comment

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

LGTM. Is this covered in simulations at all?

@julienrbrt
Copy link
Member Author

julienrbrt commented Jan 25, 2024

LGTM. Is this covered in simulations at all?

I haven't added any tests here yet, waiting for #19101 to be merged first for avoiding merge conflicts.

x/gov/README.md Show resolved Hide resolved
x/gov/README.md Outdated Show resolved Hide resolved
Co-authored-by: Robert Zaremba <[email protected]>
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.

code looks great!
can you also add tests please ?

Base automatically changed from julien/gov-mbp to main January 30, 2024 09:22
@github-actions github-actions bot added the C:CLI label Jan 30, 2024
Copy link
Contributor

coderabbitai bot commented Jan 30, 2024

Warning

Rate Limit Exceeded

@julienrbrt has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 17 minutes and 2 seconds before requesting another review.

How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.
Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.
Please see our FAQ for further information.

Commits Files that changed from the base of the PR and between 6559329 and 1c62399.

Walkthrough

The Cosmos governance module has undergone significant updates, introducing new parameters like YesQuorum and ProposalCancelMaxPeriod, alongside state machine and client breaking changes. These changes aim to refine the governance process by specifying a minimum yes vote requirement, introducing message-based params configuration, and adding new proposal types. The adjustments ensure a more dynamic and flexible governance framework, addressing concerns over vote tallying and proposal management.

Changes

Files Change Summary
proto/cosmos/gov/v1/gov.proto Added yes_quorum parameter.
x/gov/CHANGELOG.md, x/gov/README.md Documented additions (ProposalCancelMaxPeriod, YesQuorum) and breaking changes (proposal types, params configuration). Updated document structure and content.
x/gov/keeper/tally.go, x/gov/migrations/v6/store.go Modified tally logic to use YesQuorum for vote calculations. Set YesQuorum field to defaultParams.YesQuorum.
x/gov/simulation/genesis.go, x/gov/simulation/genesis_test.go Introduced YesQuorum handling in genesis state generation and testing.
x/gov/types/v1/params.go Introduced yesQuorum parameter and default setting.
client/v2/internal/offchain/msgSignArbitraryData.proto Reformatted option (amino.name) declaration.
x/gov/keeper/tally_test.go Added a new test case for "quorum reached, yes quorum not reached" scenario.

Assessment against linked issues

Objective Addressed Explanation
Identify and address the issue with governance result when majority votes on abstain (#11461)
Highlight concern over abstain majority leading to undesirable proposal results (#11461)
Propose extending proposal time or introducing a follow-up proposal for undecided outcomes (#11461) The changes focus on the introduction of YesQuorum and do not explicitly mention extending proposal times or follow-up proposals.
Advocate for excluding abstain votes from quorum calculation (#11461) The documentation does not clearly specify whether abstain votes are excluded from the quorum calculation with the introduction of YesQuorum.
Request input from specific individuals on governance improvements (#11461) The code changes do not indicate any specific requests for input from the individuals mentioned.

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:

Note: Auto-reply has been disabled for this repository by the repository owner. The CodeRabbit bot will not respond to your comments unless it is explicitly tagged.

  • 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 from git 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.

julienrbrt and others added 2 commits January 30, 2024 12:23
Co-authored-by: Facundo Medica <[email protected]>
Comment on lines 21 to 49
func TestMigrateStore(t *testing.T) {
cdc := moduletestutil.MakeTestEncodingConfig(gov.AppModuleBasic{}).Codec
govKey := storetypes.NewKVStoreKey("gov")
ctx := testutil.DefaultContext(govKey, storetypes.NewTransientStoreKey("transient_test"))
storeService := runtime.NewKVStoreService(govKey)
sb := collections.NewSchemaBuilder(storeService)
paramsCollection := collections.NewItem(sb, types.ParamsKey, "params", codec.CollValue[v1.Params](cdc))
proposalCollection := collections.NewMap(sb, types.ProposalsKeyPrefix, "proposals", collections.Uint64Key, codec.CollValue[v1.Proposal](cdc))

// set defaults without newly added fields
previousParams := v1.DefaultParams()
previousParams.YesQuorum = ""
previousParams.ProposalCancelMaxPeriod = ""
previousParams.OptimisticAuthorizedAddresses = nil
previousParams.OptimisticRejectedThreshold = ""
paramsCollection.Set(ctx, previousParams)

// Run migrations.
err := v6.MigrateStore(ctx, paramsCollection, proposalCollection)
require.NoError(t, err)

// Check params
newParams, err := paramsCollection.Get(ctx)
require.NoError(t, err)
require.Equal(t, v1.DefaultParams().YesQuorum, newParams.YesQuorum)
require.Equal(t, v1.DefaultParams().ProposalCancelMaxPeriod, newParams.ProposalCancelMaxPeriod)
require.Equal(t, v1.DefaultParams().OptimisticAuthorizedAddresses, newParams.OptimisticAuthorizedAddresses)
require.Equal(t, v1.DefaultParams().OptimisticRejectedThreshold, newParams.OptimisticRejectedThreshold)
}
Copy link
Contributor

Choose a reason for hiding this comment

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

The test function TestMigrateStore is well-structured and follows best practices for testing migrations. However, it's important to ensure that the test covers all relevant scenarios, including edge cases and failure modes. Consider adding tests that:

  • Verify behavior when the store is empty or contains unexpected data formats.
  • Check for proper handling of invalid or borderline parameter values.
  • Ensure that the migration is idempotent, meaning running it multiple times does not alter the outcome after the first successful migration.

Adding these tests will enhance the robustness of the migration process and ensure that edge cases are properly handled.

Would you like assistance in implementing these additional test scenarios?

@julienrbrt julienrbrt enabled auto-merge January 30, 2024 21:25
Comment on lines 352 to 382
SpamCount: "6000000",
},
},
{
name: "quorum reached, yes quorum not reached: prop fails/burn deposit",
setup: func(s tallyFixture) {
params, _ := s.keeper.Params.Get(s.ctx)
params.YesQuorum = "0.7"
_ = s.keeper.Params.Set(s.ctx, params)

setTotalBonded(s, 10000000)
validatorVote(s, s.valAddrs[0], v1.VoteOption_VOTE_OPTION_ONE)
validatorVote(s, s.valAddrs[1], v1.VoteOption_VOTE_OPTION_THREE)
validatorVote(s, s.valAddrs[2], v1.VoteOption_VOTE_OPTION_TWO)
validatorVote(s, s.valAddrs[4], v1.VoteOption_VOTE_OPTION_ONE)
validatorVote(s, s.valAddrs[5], v1.VoteOption_VOTE_OPTION_ONE)
validatorVote(s, s.valAddrs[6], v1.VoteOption_VOTE_OPTION_TWO)
},
expectedPass: false,
expectedBurn: false,
expectedTally: v1.TallyResult{
YesCount: "3000000",
AbstainCount: "2000000",
NoCount: "1000000",
NoWithVetoCount: "0",
SpamCount: "0",
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Copy link
Contributor

Choose a reason for hiding this comment

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

📝 NOTE
This review was outside the diff hunks and was mapped to the diff hunk with the greatest overlap. Original lines [1-766]

Overall, the test file modifications introduce comprehensive scenarios to validate the new yes_quorum parameter's behavior across different proposal types. It's essential to ensure that these tests cover all edge cases and accurately reflect the intended governance logic, especially regarding the handling of abstain votes and the calculation of quorums. Additionally, consider adding tests that specifically target edge cases around the yes_quorum threshold, such as exactly meeting the threshold and just falling short, to ensure robust coverage.

@julienrbrt julienrbrt added this pull request to the merge queue Jan 30, 2024
Merged via the queue into main with commit 13780bd Jan 30, 2024
56 of 63 checks passed
@julienrbrt julienrbrt deleted the julien/gov-yes-threshold branch January 30, 2024 22:05
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.

Potential issue with gov result when majority chose abstain
5 participants