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
Show file tree
Hide file tree
Changes from 15 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
294 changes: 226 additions & 68 deletions api/cosmos/gov/v1/gov.pulsar.go

Large diffs are not rendered by default.

3 changes: 1 addition & 2 deletions client/v2/internal/offchain/msgSignArbitraryData.proto
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import "amino/amino.proto";

// MsgSignArbitraryData defines an arbitrary, general-purpose, off-chain message
message MsgSignArbitraryData {
option (amino.name) = "offchain/MsgSignArbitraryData";
option (amino.name) = "offchain/MsgSignArbitraryData";
option (cosmos.msg.v1.signer) = "signer";
// AppDomain is the application requesting off-chain message signing
string app_domain = 1;
Expand All @@ -17,4 +17,3 @@ message MsgSignArbitraryData {
// Data represents the raw bytes of the content that is signed (text, json, etc)
string data = 3;
}

18 changes: 13 additions & 5 deletions proto/cosmos/gov/v1/gov.proto
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,12 @@ message Params {
//
// Since: x/gov v1.0.0
string optimistic_rejected_threshold = 19 [(cosmos_proto.scalar) = "cosmos.Dec"];

// yes_quorum defines the minimum percentage of Yes votes in quroum for proposal to pass.
// Default value: 0 (disabled).
//
// Since: x/gov v1.0.0
string yes_quorum = 20 [(cosmos_proto.scalar) = "cosmos.Dec"];
}

// MessageBasedParams defines the parameters of specific messages in a proposal.
Expand All @@ -361,14 +367,16 @@ message MessageBasedParams {
// Duration of the voting period.
google.protobuf.Duration voting_period = 1 [(gogoproto.stdduration) = true];

// Minimum percentage of total stake needed to vote for a result to be
// considered valid.
// Minimum percentage of total stake needed to vote for a result to be considered valid.
string quorum = 2 [(cosmos_proto.scalar) = "cosmos.Dec"];

// Minimum proportion of Yes votes for proposal to pass.
// yes_quorum defines the minimum percentage of Yes votes in quroum for proposal to pass.
// If zero then the yes_quorum is disabled.
string yes_quorum = 20 [(cosmos_proto.scalar) = "cosmos.Dec"];

// Minimum proportion of Yes votes for proposal to pass.
string threshold = 3 [(cosmos_proto.scalar) = "cosmos.Dec"];

// Minimum value of Veto votes to Total votes ratio for proposal to be
// vetoed.
// Minimum value of Veto votes to Total votes ratio for proposal to be vetoed.
string veto_threshold = 4 [(cosmos_proto.scalar) = "cosmos.Dec"];
}
4 changes: 3 additions & 1 deletion x/gov/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ Ref: https://keepachangelog.com/en/1.0.0/
### Improvements

* [#18976](https://github.com/cosmos/cosmos-sdk/pull/18976) Log and send an event when a proposal deposit refund or burn has failed.
* [#18856](https://github.com/cosmos/cosmos-sdk/pull/18856) Add `ProposalCancelMaxPeriod` for modifying how long a proposal can be cancelled after it has been submitted.
* [#18856](https://github.com/cosmos/cosmos-sdk/pull/18856) Add `ProposalCancelMaxPeriod` parameter for modifying how long a proposal can be cancelled after it has been submitted.
* [#19167](https://github.com/cosmos/cosmos-sdk/pull/19167) Add `YesQuorum` parameter specifying a minimum of yes vote in the total proposal voting power for the proposal to pass.
* [#18445](https://github.com/cosmos/cosmos-sdk/pull/18445) Extend gov config.
* [#18532](https://github.com/cosmos/cosmos-sdk/pull/18532) Repurpose `govcliutils.NormalizeProposalType` to work for gov v1 proposal types.

Expand All @@ -48,6 +49,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
* [#18620](https://github.com/cosmos/cosmos-sdk/pull/18620) Add optimistic proposals.
* [#18762](https://github.com/cosmos/cosmos-sdk/pull/18762) Add multiple choice proposals.
* [#18856](https://github.com/cosmos/cosmos-sdk/pull/18856) Add `ProposalCancelMaxPeriod` parameters.
* [#19167](https://github.com/cosmos/cosmos-sdk/pull/19167) Add `YesQuorum` parameter.

### Client Breaking Changes

Expand Down
75 changes: 42 additions & 33 deletions x/gov/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,32 +35,32 @@ can be adapted to any Proof-Of-Stake blockchain by replacing *ATOM* with the nat
staking token of the chain.

* [Concepts](#concepts)
* [Proposal submission](#proposal-submission)
* [Deposit](#deposit)
* [Vote](#vote)
* [Proposal submission](#proposal-submission)
* [Deposit](#deposit)
* [Vote](#vote)
* [State](#state)
* [Proposals](#proposals)
* [Parameters and base types](#parameters-and-base-types)
* [Deposit](#deposit-1)
* [ValidatorGovInfo](#validatorgovinfo)
* [Stores](#stores)
* [Proposal Processing Queue](#proposal-processing-queue)
* [Legacy Proposal](#legacy-proposal)
* [Proposals](#proposals)
* [Parameters and base types](#parameters-and-base-types)
* [Deposit](#deposit-1)
* [ValidatorGovInfo](#validatorgovinfo)
* [Stores](#stores)
* [Proposal Processing Queue](#proposal-processing-queue)
* [Legacy Proposal](#legacy-proposal)
* [Messages](#messages)
* [Proposal Submission](#proposal-submission-1)
* [Deposit](#deposit-2)
* [Vote](#vote-1)
* [Proposal Submission](#proposal-submission-1)
* [Deposit](#deposit-2)
* [Vote](#vote-1)
* [Events](#events)
* [EndBlocker](#endblocker)
* [Handlers](#handlers)
* [EndBlocker](#endblocker)
* [Handlers](#handlers)
* [Parameters](#parameters)
* [Client](#client)
* [CLI](#cli)
* [gRPC](#grpc)
* [REST](#rest)
* [CLI](#cli)
* [gRPC](#grpc)
* [REST](#rest)
* [Metadata](#metadata)
* [Proposal](#proposal-3)
* [Vote](#vote-5)
* [Proposal](#proposal-3)
* [Vote](#vote-5)
* [Future Improvements](#future-improvements)

## Concepts
Expand Down Expand Up @@ -230,6 +230,13 @@ This means that proposals are accepted iff:

For expedited proposals, by default, the threshold is higher than with a *normal proposal*, namely, 66.7%.

### Yes Quorum
julienrbrt marked this conversation as resolved.
Show resolved Hide resolved

Yes quorum is a more restrictive quorum that is used to determine if a proposal passes.
It is defined as the minimum percentage of voting power that needs to have voted `Yes` for the proposal to pass.
It differs from `Threshold` as it takes the whole voting power into account, not only `Yes` and `No` votes.
By default, `YesQuorum` is set to 0, which means no minimum.

#### Inheritance

If a delegator does not vote, it will inherit its validator vote.
Expand Down Expand Up @@ -273,12 +280,12 @@ There are three parameters that define if the deposit of a proposal should be bu
Since this is more of a social feature than a technical feature, we'll now get into some items that may have been useful to have in a genesis constitution:

* What limitations on governance exist, if any?
* is it okay for the community to slash the wallet of a whale that they no longer feel that they want around? (viz: Juno Proposal 4 and 16)
* can governance "socially slash" a validator who is using unapproved MEV? (viz: commonwealth.im/osmosis)
* In the event of an economic emergency, what should validators do?
* Terra crash of May, 2022, saw validators choose to run a new binary with code that had not been approved by governance, because the governance token had been inflated to nothing.
* is it okay for the community to slash the wallet of a whale that they no longer feel that they want around? (viz: Juno Proposal 4 and 16)
* can governance "socially slash" a validator who is using unapproved MEV? (viz: commonwealth.im/osmosis)
* In the event of an economic emergency, what should validators do?
* Terra crash of May, 2022, saw validators choose to run a new binary with code that had not been approved by governance, because the governance token had been inflated to nothing.
* What is the purpose of the chain, specifically?
* best example of this is the Cosmos hub, where different founding groups, have different interpretations of the purpose of the network.
* best example of this is the Cosmos hub, where different founding groups, have different interpretations of the purpose of the network.

This genesis entry, "constitution" hasn't been designed for existing chains, who should likely just ratify a constitution using their governance system. Instead, this is for new chains. It will allow for validators to have a much clearer idea of purpose and the expecations placed on them while operating their nodes. Likewise, for community members, the constitution will give them some idea of what to expect from both the "chain team" and the validators, respectively.

Expand Down Expand Up @@ -489,7 +496,7 @@ The `initialDeposit` must be strictly positive and conform to the accepted denom
* Initialise `Proposal`'s attributes
* Decrease balance of sender by `InitialDeposit`
* If `MinDeposit` is reached:
* Push `proposalID` in `ProposalProcessingQueue`
* Push `proposalID` in `ProposalProcessingQueue`
* Transfer `InitialDeposit` from the `Proposer` to the governance `ModuleAccount`

### Deposit
Expand All @@ -513,7 +520,7 @@ https://github.com/cosmos/cosmos-sdk/blob/v0.47.0-rc1/proto/cosmos/gov/v1/tx.pro
* Add `deposit` of sender in `proposal.Deposits`
* Increase `proposal.TotalDeposit` by sender's `deposit`
* If `MinDeposit` is reached:
* Push `proposalID` in `ProposalProcessingQueueEnd`
* Push `proposalID` in `ProposalProcessingQueueEnd`
* Transfer `Deposit` from the `proposer` to the governance `ModuleAccount`

### Vote
Expand Down Expand Up @@ -606,6 +613,7 @@ The governance module contains the following parameters:
| max_deposit_period | string (time ns) | "172800000000000" (17280s) |
| voting_period | string (time ns) | "172800000000000" (17280s) |
| quorum | string (dec) | "0.334000000000000000" |
| yes_quorum | string (dec) | "0.4" |
| threshold | string (dec) | "0.500000000000000000" |
| veto | string (dec) | "0.334000000000000000" |
| expedited_threshold | string (time ns) | "0.667000000000000000" |
Expand All @@ -629,12 +637,13 @@ to be included and not the entire parameter object structure.

In addition to the parameters above, the governance module can also be configured to have different parameters for a given proposal message.

| Key | Type | Example |
| ------------------------------- | ----------------- | --------------------------------------- |
| voting_period | string (time ns) | "172800000000000" (17280s) |
| quorum | string (dec) | "0.334000000000000000" |
| threshold | string (dec) | "0.500000000000000000" |
| veto | string (dec) | "0.334000000000000000" |
| Key | Type | Example |
| ------------- | ---------------- | -------------------------- |
| voting_period | string (time ns) | "172800000000000" (17280s) |
| yes_quorum | string (dec) | "0.4" |
| quorum | string (dec) | "0.334000000000000000" |
| threshold | string (dec) | "0.500000000000000000" |
| veto | string (dec) | "0.334000000000000000" |

If configured, these params will take precedence over the global params for a specific proposal.

Expand Down
17 changes: 15 additions & 2 deletions x/gov/keeper/tally.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@ func (k Keeper) tallyStandard(ctx context.Context, proposal v1.Proposal, totalVo
tallyResults = v1.NewTallyResultFromMap(results)

quorumStr := params.Quorum
thresholdStr := params.GetThreshold()
yesQuorumStr := params.YesQuorum
thresholdStr := params.Threshold
vetoThresholdStr := params.VetoThreshold

if len(proposal.Messages) > 0 {
Expand All @@ -81,6 +82,7 @@ func (k Keeper) tallyStandard(ctx context.Context, proposal v1.Proposal, totalVo
quorumStr = customMessageParams.GetQuorum()
thresholdStr = customMessageParams.GetThreshold()
vetoThresholdStr = customMessageParams.GetVetoThreshold()
yesQuorumStr = customMessageParams.GetYesQuorum()
}
}

Expand All @@ -96,6 +98,12 @@ func (k Keeper) tallyStandard(ctx context.Context, proposal v1.Proposal, totalVo
return false, false, tallyResults, nil
}

// If yes quprum enabled and less than yes_quorum of voters vote Yes, proposal fails
julienrbrt marked this conversation as resolved.
Show resolved Hide resolved
yesQuorum, _ := math.LegacyNewDecFromStr(yesQuorumStr)
if yesQuorum.GT(math.LegacyZeroDec()) && results[v1.OptionYes].Quo(totalVoterPower).LT(yesQuorum) {
return false, false, tallyResults, nil
}

// If more than 1/3 of voters veto, proposal fails
vetoThreshold, _ := math.LegacyNewDecFromStr(vetoThresholdStr)
if results[v1.OptionNoWithVeto].Quo(totalVoterPower).GT(vetoThreshold) {
Expand All @@ -104,7 +112,6 @@ func (k Keeper) tallyStandard(ctx context.Context, proposal v1.Proposal, totalVo

// If more than 1/2 of non-abstaining voters vote Yes, proposal passes
threshold, _ := math.LegacyNewDecFromStr(thresholdStr)

if results[v1.OptionYes].Quo(totalVoterPower.Sub(results[v1.OptionAbstain])).GT(threshold) {
return true, false, tallyResults, nil
}
Expand Down Expand Up @@ -135,6 +142,12 @@ func (k Keeper) tallyExpedited(totalVoterPower math.LegacyDec, totalBonded math.
return false, false, tallyResults, nil
}

// If yes quprum enabled and less than yes_quorum of voters vote Yes, proposal fails
julienrbrt marked this conversation as resolved.
Show resolved Hide resolved
yesQuorum, _ := math.LegacyNewDecFromStr(params.YesQuorum)
if yesQuorum.GT(math.LegacyZeroDec()) && results[v1.OptionYes].Quo(totalVoterPower).LT(yesQuorum) {
return false, false, tallyResults, nil
}

// If more than 1/3 of voters veto, proposal fails
vetoThreshold, _ := math.LegacyNewDecFromStr(params.VetoThreshold)
if results[v1.OptionNoWithVeto].Quo(totalVoterPower).GT(vetoThreshold) {
Expand Down
1 change: 1 addition & 0 deletions x/gov/migrations/v6/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ func MigrateStore(ctx sdk.Context, paramsCollection collections.Item[v1.Params],
}

defaultParams := v1.DefaultParams()
govParams.YesQuorum = defaultParams.YesQuorum
govParams.OptimisticAuthorizedAddresses = defaultParams.OptimisticAuthorizedAddresses
govParams.OptimisticRejectedThreshold = defaultParams.OptimisticRejectedThreshold
govParams.ProposalCancelMaxPeriod = defaultParams.ProposalCancelMaxPeriod
Expand Down
11 changes: 10 additions & 1 deletion x/gov/simulation/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ const (
VotingPeriod = "voting_period"
ExpeditedVotingPeriod = "expedited_voting_period"
Quorum = "quorum"
YesQuorum = "yes_quorum"
Threshold = "threshold"
ExpeditedThreshold = "expedited_threshold"
Veto = "veto"
Expand Down Expand Up @@ -86,6 +87,11 @@ func GenQuorum(r *rand.Rand) sdkmath.LegacyDec {
return sdkmath.LegacyNewDecWithPrec(int64(simulation.RandIntBetween(r, 334, 500)), 3)
}

// GenYesQuorum returns randomized YesQuorum
func GenYesQuorum(r *rand.Rand) sdkmath.LegacyDec {
return sdkmath.LegacyNewDecWithPrec(int64(simulation.RandIntBetween(r, 0, 500)), 3)
}

// GenThreshold returns randomized Threshold
func GenThreshold(r *rand.Rand) sdkmath.LegacyDec {
return sdkmath.LegacyNewDecWithPrec(int64(simulation.RandIntBetween(r, 450, tallyNonExpeditedMax+1)), 3)
Expand Down Expand Up @@ -142,6 +148,9 @@ func RandomizedGenState(simState *module.SimulationState) {
var quorum sdkmath.LegacyDec
simState.AppParams.GetOrGenerate(Quorum, &quorum, simState.Rand, func(r *rand.Rand) { quorum = GenQuorum(r) })

var yesQuorum sdkmath.LegacyDec
simState.AppParams.GetOrGenerate(YesQuorum, &yesQuorum, simState.Rand, func(r *rand.Rand) { yesQuorum = GenQuorum(r) })

var threshold sdkmath.LegacyDec
simState.AppParams.GetOrGenerate(Threshold, &threshold, simState.Rand, func(r *rand.Rand) { threshold = GenThreshold(r) })

Expand All @@ -159,7 +168,7 @@ func RandomizedGenState(simState *module.SimulationState) {

govGenesis := v1.NewGenesisState(
startingProposalID,
v1.NewParams(minDeposit, expeditedMinDeposit, depositPeriod, votingPeriod, expeditedVotingPeriod, quorum.String(), threshold.String(), expitedVotingThreshold.String(), veto.String(), minInitialDepositRatio.String(), proposalCancelRate.String(), "", proposalMaxCancelVotingPeriod.String(), simState.Rand.Intn(2) == 0, simState.Rand.Intn(2) == 0, simState.Rand.Intn(2) == 0, minDepositRatio.String(), optimisticRejectedThreshold.String(), []string{}),
v1.NewParams(minDeposit, expeditedMinDeposit, depositPeriod, votingPeriod, expeditedVotingPeriod, quorum.String(), yesQuorum.String(), threshold.String(), expitedVotingThreshold.String(), veto.String(), minInitialDepositRatio.String(), proposalCancelRate.String(), "", proposalMaxCancelVotingPeriod.String(), simState.Rand.Intn(2) == 0, simState.Rand.Intn(2) == 0, simState.Rand.Intn(2) == 0, minDepositRatio.String(), optimisticRejectedThreshold.String(), []string{}),
)

bz, err := json.MarshalIndent(&govGenesis, "", " ")
Expand Down
8 changes: 5 additions & 3 deletions x/gov/simulation/genesis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,10 @@ func TestRandomizedGenState(t *testing.T) {

const (
tallyQuorum = "0.387000000000000000"
tallyThreshold = "0.452000000000000000"
tallyExpeditedThreshold = "0.537000000000000000"
tallyVetoThreshold = "0.276000000000000000"
tallyYesQuorum = "0.449000000000000000"
tallyThreshold = "0.464000000000000000"
tallyExpeditedThreshold = "0.506000000000000000"
tallyVetoThreshold = "0.309000000000000000"
minInitialDepositDec = "0.880000000000000000"
proposalCancelMaxPeriod = "0.110000000000000000"
)
Expand All @@ -60,6 +61,7 @@ func TestRandomizedGenState(t *testing.T) {
assert.Equal(t, float64(291928), govGenesis.Params.VotingPeriod.Seconds())
assert.Equal(t, float64(33502), govGenesis.Params.ExpeditedVotingPeriod.Seconds())
assert.Equal(t, tallyQuorum, govGenesis.Params.Quorum)
assert.Equal(t, tallyYesQuorum, govGenesis.Params.YesQuorum)
assert.Equal(t, tallyThreshold, govGenesis.Params.Threshold)
assert.Equal(t, tallyExpeditedThreshold, govGenesis.Params.ExpeditedThreshold)
assert.Equal(t, tallyVetoThreshold, govGenesis.Params.VetoThreshold)
Expand Down
Loading
Loading