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: add burnable params to governance #15151

Merged
merged 20 commits into from
Feb 28, 2023
Merged
Show file tree
Hide file tree
Changes from 13 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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
* (x/bank) [#14894](https://github.com/cosmos/cosmos-sdk/pull/14894) Return a human readable denomination for IBC vouchers when querying bank balances. Added a `ResolveDenom` parameter to `types.QueryAllBalancesRequest` and `--resolve-denom` flag to `GetBalancesCmd()`.
* (x/groups) [#14879](https://github.com/cosmos/cosmos-sdk/pull/14879) Add `Query/Groups` query to get all the groups.
* (x/genutil,cli) [#15147](https://github.com/cosmos/cosmos-sdk/pull/15147) Add `--initial-height` flag to cli init cmd to provide `genesis.json` with user defined initial block height
* (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
299 changes: 252 additions & 47 deletions api/cosmos/gov/v1/gov.pulsar.go

Large diffs are not rendered by default.

425 changes: 215 additions & 210 deletions api/cosmos/tx/v1beta1/service.pulsar.go

Large diffs are not rendered by default.

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

// Minimum expedited deposit for a proposal to enter voting period.
repeated cosmos.base.v1beta1.Coin expedited_min_deposit = 12 [(gogoproto.nullable) = false, (amino.dont_omitempty) = true];

// burn deposits if a proposal does not meet quorum
//
// Since: cosmos-sdk 0.47
bool burn_vote_quorum = 13;
// burn deposits if the proposal does not enter voting period
//
// Since: cosmos-sdk 0.47
bool burn_proposal_deposit_prevote = 14;
// burn deposits if quorum with vote type no_veto is met
//
// Since: cosmos-sdk 0.47
bool burn_vote_veto = 15;
tac0turtle marked this conversation as resolved.
Show resolved Hide resolved
}
4 changes: 2 additions & 2 deletions tests/integration/gov/keeper/keeper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,15 @@ func initFixture(t *testing.T) *fixture {
queryHelper := baseapp.NewQueryServerTestHelper(ctx, app.InterfaceRegistry())
v1.RegisterQueryServer(queryHelper, app.GovKeeper)
legacyQueryHelper := baseapp.NewQueryServerTestHelper(ctx, app.InterfaceRegistry())
v1beta1.RegisterQueryServer(legacyQueryHelper, keeper.NewLegacyQueryServer(app.GovKeeper))
v1beta1.RegisterQueryServer(legacyQueryHelper, keeper.NewLegacyQueryServer(&app.GovKeeper))
queryClient := v1.NewQueryClient(queryHelper)
legacyQueryClient := v1beta1.NewQueryClient(legacyQueryHelper)

f.app = app
f.ctx = ctx
f.queryClient = queryClient
f.legacyQueryClient = legacyQueryClient
f.msgSrvr = keeper.NewMsgServerImpl(f.app.GovKeeper)
f.msgSrvr = keeper.NewMsgServerImpl(&f.app.GovKeeper)

govAcct := f.app.GovKeeper.GetGovernanceAccount(f.ctx).GetAddress()
f.legacyMsgSrvr = keeper.NewLegacyMsgServerImpl(govAcct.String(), f.msgSrvr)
Expand Down
153 changes: 78 additions & 75 deletions types/tx/service.pb.go

Large diffs are not rendered by default.

56 changes: 34 additions & 22 deletions x/gov/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ staking token of the chain.
* [EndBlocker](#endblocker)
* [Handlers](#handlers)
* [Parameters](#parameters)
* [SubKeys](#subkeys)
* [Client](#client)
* [CLI](#cli)
* [gRPC](#grpc)
Expand Down Expand Up @@ -260,6 +259,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

### Constitution
Expand All @@ -274,12 +283,12 @@ Validators and full nodes can use an automation tool, such as [Cosmovisor](https
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 interpertations of the purpose of the network.
* best example of this is the Cosmos hub, where different founding groups, have different interpertations 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 thier 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 @@ -716,7 +725,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 @@ -727,7 +736,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 @@ -741,7 +750,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 @@ -751,7 +760,7 @@ The governance module emits the following events:
#### MsgVoteWeighted

| Type | Attribute Key | Attribute Value |
| ------------- | ------------- | --------------------- |
|---------------|---------------|-----------------------|
| proposal_vote | option | {weightedVoteOptions} |
| proposal_vote | proposal_id | {proposalID} |
| message | module | governance |
Expand All @@ -761,7 +770,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 @@ -775,17 +784,20 @@ The governance module emits the following events:

The governance module contains the following parameters:

| 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" |
| expedited_threshold | string (time ns) | "0.667000000000000000" |
| expedited_voting_period | string (time ns) | "86400000000000" (8600s) |
| expedited_min_deposit | array (coins) | [{"denom":"uatom","amount":"50000000"}] |
| 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" |
| expedited_threshold | string (time ns) | "0.667000000000000000" |
| expedited_voting_period | string (time ns) | "86400000000000" (8600s) |
| expedited_min_deposit | array (coins) | [{"denom":"uatom","amount":"50000000"}] |
| 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
9 changes: 7 additions & 2 deletions x/gov/abci.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,12 @@ 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

if !keeper.GetParams(ctx).BurnProposalDepositPrevote {
keeper.RefundAndDeleteDeposits(ctx, proposal.Id) // refund deposit if proposal got removed without getting 100% of the proposal

Check warning

Code scanning / CodeQL

Panic in BeginBock or EndBlock consensus methods

Possible panics in BeginBock- or EndBlock-related consensus methods could cause a chain halt
} else {
keeper.DeleteAndBurnDeposits(ctx, proposal.Id) // burn the deposit if proposal got removed without getting 100% of the proposal

Check warning

Code scanning / CodeQL

Panic in BeginBock or EndBlock consensus methods

Possible panics in BeginBock- or EndBlock-related consensus methods could cause a chain halt
likhita-809 marked this conversation as resolved.
Show resolved Hide resolved
}

// called when proposal become inactive
keeper.Hooks().AfterProposalFailedMinDeposit(ctx, proposal.Id)
Expand Down Expand Up @@ -53,7 +58,7 @@ func EndBlocker(ctx sdk.Context, keeper *keeper.Keeper) {

// If an expedited proposal fails, we do not want to update
// the deposit at this point since the proposal is converted to regular.
// As a result, the deposits are either deleted or refunded in all casses
// As a result, the deposits are either deleted or refunded in all cases
// EXCEPT when an expedited proposal fails.
if !(proposal.Expedited && !passes) {
if burnDeposits {
Expand Down
4 changes: 2 additions & 2 deletions x/gov/keeper/tally.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ func (keeper Keeper) Tally(ctx sdk.Context, proposal v1.Proposal) (passes bool,
percentVoting := totalVotingPower.Quo(sdk.NewDecFromInt(keeper.sk.TotalBondedTokens(ctx)))
quorum, _ := sdk.NewDecFromStr(params.Quorum)
if percentVoting.LT(quorum) {
return false, false, tallyResults
return false, keeper.GetParams(ctx).BurnVoteQuorum, tallyResults
}

// If no one votes (everyone abstains), proposal fails
Expand All @@ -113,7 +113,7 @@ 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(params.VetoThreshold)
if results[v1.OptionNoWithVeto].Quo(totalVotingPower).GT(vetoThreshold) {
return false, true, tallyResults
return false, keeper.GetParams(ctx).BurnVoteVeto, tallyResults
}

// If more than 1/2 of non-abstaining voters vote Yes, proposal passes
Expand Down
3 changes: 3 additions & 0 deletions x/gov/migrations/v4/json.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ func MigrateJSON(oldState *v1.GenesisState) (*v1.GenesisState, error) {
defaultParams.MinInitialDepositRatio,
defaultParams.ProposalCancelRatio,
defaultParams.ProposalCancelDest,
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 @@ -60,6 +60,9 @@ func TestMigrateJSON(t *testing.T) {
"deposit_params": null,
"deposits": [],
"params": {
"burn_proposal_deposit_prevote": false,
"burn_vote_quorum": false,
"burn_vote_veto": true,
"expedited_min_deposit": [
{
"amount": "50000000",
Expand Down
10 changes: 7 additions & 3 deletions x/gov/migrations/v4/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,23 @@ 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,
govv1.DefaultParams().ExpeditedMinDeposit,
defaultParams.ExpeditedMinDeposit,
*dp.MaxDepositPeriod,
*vp.VotingPeriod,
*govv1.DefaultParams().ExpeditedVotingPeriod,
*defaultParams.ExpeditedVotingPeriod,
tp.Quorum,
tp.Threshold,
govv1.DefaultParams().ExpeditedThreshold,
defaultParams.ExpeditedThreshold,
tp.VetoThreshold,
sdk.ZeroDec().String(),
sdk.ZeroDec().String(),
"",
defaultParams.BurnProposalDepositPrevote,
defaultParams.BurnVoteQuorum,
defaultParams.BurnVoteVeto,
)

bz, err := cdc.Marshal(&params)
Expand Down
3 changes: 3 additions & 0 deletions x/gov/migrations/v5/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ func MigrateStore(ctx sdk.Context, storeKey storetypes.StoreKey, cdc codec.Binar
params.ExpeditedMinDeposit = defaultParams.ExpeditedMinDeposit
params.ExpeditedVotingPeriod = defaultParams.ExpeditedVotingPeriod
params.ExpeditedThreshold = defaultParams.ExpeditedThreshold
params.BurnProposalDepositPrevote = defaultParams.BurnProposalDepositPrevote
params.BurnVoteQuorum = defaultParams.BurnVoteQuorum
params.BurnVoteVeto = defaultParams.BurnVoteVeto

bz, err := cdc.Marshal(&params)
if err != nil {
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 @@ -166,7 +166,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(), ""),
v1.NewParams(minDeposit, expeditedMinDeposit, depositPeriod, votingPeriod, expeditedVotingPeriod, quorum.String(), threshold.String(), expitedVotingThreshold.String(), veto.String(), minInitialDepositRatio.String(), proposalCancelRate.String(), "", simState.Rand.Intn(2) == 0, simState.Rand.Intn(2) == 0, simState.Rand.Intn(2) == 0),
)

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