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 10 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` and `burn_vote_veto` params to allow applications to decide if they would like to burn deposits
tac0turtle marked this conversation as resolved.
Show resolved Hide resolved

### 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.

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