cosmos-sdk icon indicating copy to clipboard operation
cosmos-sdk copied to clipboard

feat(gov): allow variable governance proposal durations with dynamic quorum

Open DuongNguyen62025 opened this issue 7 months ago • 6 comments

Description

Closes: https://github.com/cosmos/cosmos-sdk/issues/24535


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. Your PR will not be merged unless you satisfy all of these items.

I have...

  • [ ] included the correct type prefix in the PR title, you can find examples of the prefixes below:
  • [ ] 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

Summary by CodeRabbit

  • New Features

    • Added support for specifying a custom proposal duration when submitting governance proposals.
    • Proposal duration now influences the required quorum and minimum deposit, with dynamic calculation based on the specified duration.
  • Bug Fixes

    • None.
  • Tests

    • Updated and added tests to cover dynamic threshold and minimum deposit calculations based on proposal duration.
    • Adjusted test cases and helper functions to support the new duration parameter.
  • Documentation

    • None.
  • Chores

    • Refactored internal logic and method signatures to accommodate the proposal duration feature.

DuongNguyen62025 avatar Apr 25 '25 08:04 DuongNguyen62025

Ironbird - launch a network To use Ironbird, you can use the following commands:
  • /ironbird start OR /ironbird start --load-test-config= - Launch a testnet with the specified chain and load test configuration.
  • /ironbird chains - List of chain images that ironbird can use to spin-up testnet
  • /ironbird loadtests - List of load test modes that ironbird can run against testnet
Custom Load Test Configuration You can provide a custom load test configuration using the `--load-test-config=` flag:
/ironbird start cosmos --load-test-config={
  "block_gas_limit_target": 0.75,
  "num_of_blocks": 50,
  "msgs": [
    {"weight": 0.3, "type": "MsgSend"},
    {"weight": 0.3, "type": "MsgMultiSend"},
	{"weight": 0.4, "type": "MsgArr", "ContainedType": "MsgSend", "NumMsgs": 3300}
  ]
}

Use /ironbird loadtests to see more examples.

ironbird-prod[bot] avatar Apr 25 '25 08:04 ironbird-prod[bot]

📝 Walkthrough

Walkthrough

This change introduces support for variable governance proposal durations in the Cosmos SDK governance module. The protobuf definitions for proposals and proposal submission messages are extended with a new optional duration field. The codebase is updated to propagate this field through message constructors, keeper methods, and CLI utilities. A new method interpolates voting thresholds and minimum deposits based on the custom duration, allowing the required quorum and deposit to scale with the proposal's timeline. All relevant logic, validation, and test cases are updated to handle the new duration parameter, ensuring backward compatibility and correct integration throughout the governance workflow.

Changes

File(s) Change Summary
proto/cosmos/gov/v1/gov.proto, proto/cosmos/gov/v1/tx.proto Added optional duration field (type: google.protobuf.Duration) to Proposal and MsgSubmitProposal messages.
x/gov/types/v1/params.go, x/gov/types/v1/params_test.go Added CalculateThresholdAndMinDeposit method to interpolate threshold and deposit based on duration; added corresponding unit tests.
x/gov/types/v1/proposal.go, x/gov/types/v1/msgs.go Updated NewProposal and NewMsgSubmitProposal constructors to accept and set the new duration parameter.
x/gov/keeper/proposal.go, x/gov/keeper/msg_server.go, x/gov/keeper/deposit.go Updated keeper methods to accept and utilize the duration parameter for proposal creation, validation, and voting period calculation.
x/gov/keeper/tally.go Modified tallying logic to use interpolated threshold for expedited proposals with a custom duration.
x/gov/client/cli/util.go, x/gov/client/cli/tx.go Extended CLI proposal struct and submission logic to support parsing and passing proposal duration.
x/bank/app_test.go, x/gov/keeper/.go, x/gov/keeper/.test.go, x/gov/simulation/*.go, x/gov/types/v1/msgs_test.go, x/gov/types/v1/proposals_test.go, x/gov/migrations/v4/store_test.go Updated all affected test code and simulation logic to pass the new duration argument (typically as nil) to constructors and keeper methods.

Sequence Diagram(s)

sequenceDiagram
    participant CLI/User
    participant CLI
    participant MsgSubmitProposal
    participant Keeper
    participant Params

    CLI/User->>CLI: Submit proposal with duration
    CLI->>MsgSubmitProposal: Construct MsgSubmitProposal(duration)
    MsgSubmitProposal->>Keeper: SubmitProposal(..., duration)
    Keeper->>Params: CalculateThresholdAndMinDeposit(duration)
    Params-->>Keeper: threshold, minDeposit
    Keeper->>Keeper: Validate initial deposit (uses minDeposit)
    Keeper->>Keeper: Set proposal voting period (uses duration)
    Keeper-->>CLI/User: Proposal created with custom duration/quorum

Assessment against linked issues

Objective Addressed Explanation
Allow governance proposals to specify a custom duration field (issue #24535)
Use proposal duration to interpolate required quorum and minimum deposit (issue #24535)
Update all relevant message types, constructors, and keeper logic for duration support (#24535)
Ensure tests and CLI tooling handle the new duration parameter (issue #24535)
✨ Finishing Touches
  • [ ] 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

‼️ IMPORTANT Auto-reply has been disabled for this repository in the CodeRabbit settings. The CodeRabbit bot will not respond to your replies 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 testing code 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 gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

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 using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • 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/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

coderabbitai[bot] avatar Apr 25 '25 08:04 coderabbitai[bot]

@aaronc assigning you for review for this:

  • is the function we are giving simple and extendable enough?
  • does this introduce any bugs such as bypassing quorum / too-quick voting periods
  • is this a backwards compatible change (just adding logic, not modifying existing logic)

aljo242 avatar Apr 29 '25 13:04 aljo242

@aaronc assigning you for review for this:

  • is the function we are giving simple and extendable enough?

  • does this introduce any bugs such as bypassing quorum / too-quick voting periods

  • is this a backwards compatible change (just adding logic, not modifying existing logic)

Just seeing this @aljo242. Already left my initial review. Trying to first make sure that we get clarification on the specified behavior. It does appear backwards compatible.

aaronc avatar Apr 29 '25 15:04 aaronc

Thanks for working on this @DuongNguyen62025 !

If I understand correctly, this allows for specifying a duration between the regular and expedited voting periods and scales it linearly. Is that right?

That's right, this is backwards compatible, a period of time that is not too fast or too slow that the proposer desires

DuongNguyen62025 avatar May 02 '25 04:05 DuongNguyen62025

Logic mostly looks good in terms of how this will be working. I assume that the dynamic amounts will be hard to reason about when constructing a gov prop, so I think it would be nice to include some client/CLI functions to allow simulation to show you what the calculated values will be before you submit a prop.

I can add a query to preview Threshold and MinDeposit from suggested duration. What do you think?


type QueryThresholdAndMinDepositFromDurationRequest struct {
	Duration time.Duration `protobuf:"varint,1,opt,name=duration,json=duration,proto3" json:"duration,omitempty"`
}

type QueryThresholdAndMinDepositFromDurationResponse struct {
	MinDeposit []types.Coin `protobuf:"bytes,1,rep,name=min_deposit,json=minDeposit,proto3" json:"min_deposit"`
        Threshold string `protobuf:"bytes,2,opt,name=threshold,proto3" json:"threshold,omitempty"`
}

DuongNguyen62025 avatar May 05 '25 04:05 DuongNguyen62025

closing as this is out of date

aljo242 avatar Nov 01 '25 17:11 aljo242