Skip to content

Commit

Permalink
refactor: add burnable params to governance (backport #15151) (#15218)
Browse files Browse the repository at this point in the history
Co-authored-by: Marko <[email protected]>
Co-authored-by: Julien Robert <[email protected]>
  • Loading branch information
3 people authored Mar 1, 2023
1 parent 546b298 commit ffedca8
Show file tree
Hide file tree
Showing 14 changed files with 538 additions and 164 deletions.
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,11 @@ Ref: https://keepachangelog.com/en/1.0.0/

## [Unreleased]

## [v0.47.0-rc3](https://github.com/cosmos/cosmos-sdk/releases/tag/v0.47.0-rc3) - 2023-02-22
## [v0.47.0-rc3](https://github.com/cosmos/cosmos-sdk/releases/tag/v0.47.0-rc3) - 2023-03-01

### Features

* (x/gov) [#15151](https://github.com/cosmos/cosmos-sdk/pull/15151) Add `burn_vote_quorum`, `burn_proposal_deposit_prevote` and `burn_vote_veto` params to allow applications to decide if they would like to burn deposits

### Improvements

Expand Down
282 changes: 240 additions & 42 deletions api/cosmos/gov/v1/gov.pulsar.go

Large diffs are not rendered by default.

9 changes: 9 additions & 0 deletions proto/cosmos/gov/v1/gov.proto
Original file line number Diff line number Diff line change
Expand Up @@ -208,4 +208,13 @@ message Params {

// The ratio representing the proportion of the deposit value that must be paid at proposal submission.
string min_initial_deposit_ratio = 7 [(cosmos_proto.scalar) = "cosmos.Dec"];

// burn deposits if a proposal does not meet quorum
bool burn_vote_quorum = 13;

// burn deposits if the proposal does not enter voting period
bool burn_proposal_deposit_prevote = 14;

// burn deposits if quorum with vote type no_veto is met
bool burn_vote_veto = 15;
}
3 changes: 1 addition & 2 deletions server/grpc/gogoreflection/serverreflection.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,7 @@ import (
"sort"
"sync"

//nolint: staticcheck
"github.com/golang/protobuf/proto"
"github.com/golang/protobuf/proto" //nolint:staticcheck
dpb "github.com/golang/protobuf/protoc-gen-go/descriptor"
"google.golang.org/grpc"
"google.golang.org/grpc/codes"
Expand Down
5 changes: 4 additions & 1 deletion tests/e2e/gov/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func (s *E2ETestSuite) TestCmdParams() {
{
"json output",
[]string{fmt.Sprintf("--%s=json", flags.FlagOutput)},
`{"voting_params":{"voting_period":"172800s"},"deposit_params":{"min_deposit":[{"denom":"stake","amount":"10000000"}],"max_deposit_period":"172800s"},"tally_params":{"quorum":"0.334000000000000000","threshold":"0.500000000000000000","veto_threshold":"0.334000000000000000"},"params":{"min_deposit":[{"denom":"stake","amount":"10000000"}],"max_deposit_period":"172800s","voting_period":"172800s","quorum":"0.334000000000000000","threshold":"0.500000000000000000","veto_threshold":"0.334000000000000000","min_initial_deposit_ratio":"0.000000000000000000"}}`,
`{"voting_params":{"voting_period":"172800s"},"deposit_params":{"min_deposit":[{"denom":"stake","amount":"10000000"}],"max_deposit_period":"172800s"},"tally_params":{"quorum":"0.334000000000000000","threshold":"0.500000000000000000","veto_threshold":"0.334000000000000000"},"params":{"min_deposit":[{"denom":"stake","amount":"10000000"}],"max_deposit_period":"172800s","voting_period":"172800s","quorum":"0.334000000000000000","threshold":"0.500000000000000000","veto_threshold":"0.334000000000000000","min_initial_deposit_ratio":"0.000000000000000000","burn_vote_quorum":false,"burn_proposal_deposit_prevote":false,"burn_vote_veto":true}}`,
},
{
"text output",
Expand All @@ -35,6 +35,9 @@ deposit_params:
- amount: "10000000"
denom: stake
params:
burn_proposal_deposit_prevote: false
burn_vote_quorum: false
burn_vote_veto: true
max_deposit_period: 172800s
min_deposit:
- amount: "10000000"
Expand Down
46 changes: 25 additions & 21 deletions x/gov/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ staking token of the chain.
* [EndBlocker](#endblocker)
* [Handlers](#handlers)
* [Parameters](#parameters)
* [SubKeys](#subkeys)
* [Client](#client)
* [CLI](#cli)
* [gRPC](#grpc)
Expand Down Expand Up @@ -255,6 +254,16 @@ new version of the software.

Validators and full nodes can use an automation tool, such as [Cosmovisor](https://docs.cosmos.network/main/tooling/cosmovisor), for automatically switching version of the chain.

#### Burnable Params

There are three parameters that define if the deposit of a proposal should be burned or returned to the depositors.

* `BurnVoteVeto` burns the proposal deposit if the proposal gets vetoed.
* `BurnVoteQuorum` burns the proposal deposit if the proposal deposit if the vote does not reach quorum.
* `BurnProposalDepositPrevote` burns the proposal deposit if it does not enter the voting phase.

> Note: These parameters are modifiable via governance.
## State

### Proposals
Expand Down Expand Up @@ -678,7 +687,7 @@ The governance module emits the following events:
### EndBlocker

| Type | Attribute Key | Attribute Value |
| ----------------- | --------------- | ---------------- |
|-------------------|-----------------|------------------|
| inactive_proposal | proposal_id | {proposalID} |
| inactive_proposal | proposal_result | {proposalResult} |
| active_proposal | proposal_id | {proposalID} |
Expand All @@ -689,7 +698,7 @@ The governance module emits the following events:
#### MsgSubmitProposal

| Type | Attribute Key | Attribute Value |
| ------------------- | ------------------- | --------------- |
|---------------------|---------------------|-----------------|
| submit_proposal | proposal_id | {proposalID} |
| submit_proposal [0] | voting_period_start | {proposalID} |
| proposal_deposit | amount | {depositAmount} |
Expand All @@ -703,7 +712,7 @@ The governance module emits the following events:
#### MsgVote

| Type | Attribute Key | Attribute Value |
| ------------- | ------------- | --------------- |
|---------------|---------------|-----------------|
| proposal_vote | option | {voteOption} |
| proposal_vote | proposal_id | {proposalID} |
| message | module | governance |
Expand All @@ -723,7 +732,7 @@ The governance module emits the following events:
#### MsgDeposit

| Type | Attribute Key | Attribute Value |
| -------------------- | ------------------- | --------------- |
|----------------------|---------------------|-----------------|
| proposal_deposit | amount | {depositAmount} |
| proposal_deposit | proposal_id | {proposalID} |
| proposal_deposit [0] | voting_period_start | {proposalID} |
Expand All @@ -737,22 +746,17 @@ The governance module emits the following events:

The governance module contains the following parameters:

| Key | Type | Example |
|---------------|--------|----------------------------------------------------------------------------------------------------|
| depositparams | object | {"min_deposit":[{"denom":"uatom","amount":"10000000"}],"max_deposit_period":"172800000000000"} |
| votingparams | object | {"voting_period":"172800000000000"} |
| tallyparams | object | {"quorum":"0.334000000000000000","threshold":"0.500000000000000000","veto":"0.334000000000000000"} |

### SubKeys

| Key | Type | Example |
|--------------------|------------------|-----------------------------------------|
| min_deposit | array (coins) | [{"denom":"uatom","amount":"10000000"}] |
| max_deposit_period | string (time ns) | "172800000000000" |
| voting_period | string (time ns) | "172800000000000" |
| quorum | string (dec) | "0.334000000000000000" |
| threshold | string (dec) | "0.500000000000000000" |
| veto | string (dec) | "0.334000000000000000" |
| Key | Type | Example |
|-------------------------------|------------------|-----------------------------------------|
| min_deposit | array (coins) | [{"denom":"uatom","amount":"10000000"}] |
| max_deposit_period | string (time ns) | "172800000000000" (17280s) |
| voting_period | string (time ns) | "172800000000000" (17280s) |
| quorum | string (dec) | "0.334000000000000000" |
| threshold | string (dec) | "0.500000000000000000" |
| veto | string (dec) | "0.334000000000000000" |
| burn_proposal_deposit_prevote | bool | false |
| burn_vote_quorum | bool | false |
| burn_vote_veto | bool | true |

**NOTE**: The governance module contains parameters that are objects unlike other
modules. If only a subset of parameters are desired to be changed, only they need
Expand Down
10 changes: 8 additions & 2 deletions x/gov/abci.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,13 @@ func EndBlocker(ctx sdk.Context, keeper *keeper.Keeper) {
// A proposal is dead when it's inactive and didn't get enough deposit on time to get into voting phase.
keeper.IterateInactiveProposalsQueue(ctx, ctx.BlockHeader().Time, func(proposal v1.Proposal) bool {
keeper.DeleteProposal(ctx, proposal.Id)
keeper.RefundAndDeleteDeposits(ctx, proposal.Id) // refund deposit if proposal got removed without getting 100% of the proposal

params := keeper.GetParams(ctx)
if !params.BurnProposalDepositPrevote {
keeper.RefundAndDeleteDeposits(ctx, proposal.Id) // refund deposit if proposal got removed without getting 100% of the proposal
} else {
keeper.DeleteAndBurnDeposits(ctx, proposal.Id) // burn the deposit if proposal got removed without getting 100% of the proposal
}

// called when proposal become inactive
keeper.Hooks().AfterProposalFailedMinDeposit(ctx, proposal.Id)
Expand All @@ -37,7 +43,7 @@ func EndBlocker(ctx sdk.Context, keeper *keeper.Keeper) {
logger.Info(
"proposal did not meet minimum deposit; deleted",
"proposal", proposal.Id,
"min_deposit", sdk.NewCoins(keeper.GetParams(ctx).MinDeposit...).String(),
"min_deposit", sdk.NewCoins(params.MinDeposit...).String(),
"total_deposit", sdk.NewCoins(proposal.TotalDeposit...).String(),
)

Expand Down
12 changes: 6 additions & 6 deletions x/gov/keeper/tally.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ func (keeper Keeper) Tally(ctx sdk.Context, proposal v1.Proposal) (passes bool,
totalVotingPower = totalVotingPower.Add(votingPower)
}

tallyParams := keeper.GetParams(ctx)
params := keeper.GetParams(ctx)
tallyResults = v1.NewTallyResultFromMap(results)

// TODO: Upgrade the spec to cover all of these cases & remove pseudocode.
Expand All @@ -100,9 +100,9 @@ func (keeper Keeper) Tally(ctx sdk.Context, proposal v1.Proposal) (passes bool,

// If there is not enough quorum of votes, the proposal fails
percentVoting := totalVotingPower.Quo(sdk.NewDecFromInt(keeper.sk.TotalBondedTokens(ctx)))
quorum, _ := sdk.NewDecFromStr(tallyParams.Quorum)
quorum, _ := sdk.NewDecFromStr(params.Quorum)
if percentVoting.LT(quorum) {
return false, false, tallyResults
return false, params.BurnVoteQuorum, tallyResults
}

// If no one votes (everyone abstains), proposal fails
Expand All @@ -111,13 +111,13 @@ func (keeper Keeper) Tally(ctx sdk.Context, proposal v1.Proposal) (passes bool,
}

// If more than 1/3 of voters veto, proposal fails
vetoThreshold, _ := sdk.NewDecFromStr(tallyParams.VetoThreshold)
vetoThreshold, _ := sdk.NewDecFromStr(params.VetoThreshold)
if results[v1.OptionNoWithVeto].Quo(totalVotingPower).GT(vetoThreshold) {
return false, true, tallyResults
return false, params.BurnVoteVeto, tallyResults
}

// If more than 1/2 of non-abstaining voters vote Yes, proposal passes
threshold, _ := sdk.NewDecFromStr(tallyParams.Threshold)
threshold, _ := sdk.NewDecFromStr(params.Threshold)
if results[v1.OptionYes].Quo(totalVotingPower.Sub(results[v1.OptionAbstain])).GT(threshold) {
return true, false, tallyResults
}
Expand Down
7 changes: 6 additions & 1 deletion x/gov/migrations/v4/json.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,19 @@ import (
// Addition of the new min initial deposit ratio parameter that is set to 0 by default.
// Proposals in voting period are tracked in a separate index.
func MigrateJSON(oldState *v1.GenesisState) (*v1.GenesisState, error) {
defaultParams := v1.DefaultParams()

params := v1.NewParams(
oldState.DepositParams.MinDeposit,
*oldState.DepositParams.MaxDepositPeriod,
*oldState.VotingParams.VotingPeriod,
oldState.TallyParams.Quorum,
oldState.TallyParams.Threshold,
oldState.TallyParams.VetoThreshold,
v1.DefaultParams().MinInitialDepositRatio,
defaultParams.MinInitialDepositRatio,
defaultParams.BurnProposalDepositPrevote,
defaultParams.BurnVoteQuorum,
defaultParams.BurnVoteVeto,
)

return &v1.GenesisState{
Expand Down
3 changes: 3 additions & 0 deletions x/gov/migrations/v4/json_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ func TestMigrateJSON(t *testing.T) {
"deposit_params": null,
"deposits": [],
"params": {
"burn_proposal_deposit_prevote": false,
"burn_vote_quorum": false,
"burn_vote_veto": true,
"max_deposit_period": "172800s",
"min_deposit": [
{
Expand Down
6 changes: 5 additions & 1 deletion x/gov/migrations/v4/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,18 @@ func migrateParams(ctx sdk.Context, storeKey storetypes.StoreKey, legacySubspace
legacySubspace.Get(ctx, govv1.ParamStoreKeyVotingParams, &vp)
legacySubspace.Get(ctx, govv1.ParamStoreKeyTallyParams, &tp)

defaultParams := govv1.DefaultParams()
params := govv1.NewParams(
dp.MinDeposit,
*dp.MaxDepositPeriod,
*vp.VotingPeriod,
tp.Quorum,
tp.Threshold,
tp.VetoThreshold,
sdk.ZeroDec().String(),
defaultParams.MinInitialDepositRatio,
defaultParams.BurnProposalDepositPrevote,
defaultParams.BurnVoteQuorum,
defaultParams.BurnVoteVeto,
)

bz, err := cdc.Marshal(&params)
Expand Down
2 changes: 1 addition & 1 deletion x/gov/simulation/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ func RandomizedGenState(simState *module.SimulationState) {

govGenesis := v1.NewGenesisState(
startingProposalID,
v1.NewParams(minDeposit, depositPeriod, votingPeriod, quorum.String(), threshold.String(), veto.String(), minInitialDepositRatio.String()),
v1.NewParams(minDeposit, depositPeriod, votingPeriod, quorum.String(), threshold.String(), veto.String(), minInitialDepositRatio.String(), simState.Rand.Intn(2) == 0, simState.Rand.Intn(2) == 0, simState.Rand.Intn(2) == 0),
)

bz, err := json.MarshalIndent(&govGenesis, "", " ")
Expand Down
Loading

0 comments on commit ffedca8

Please sign in to comment.