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 2 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
266 changes: 232 additions & 34 deletions api/cosmos/gov/v1/gov.pulsar.go

Large diffs are not rendered by default.

7 changes: 7 additions & 0 deletions proto/cosmos/gov/v1/gov.proto
Original file line number Diff line number Diff line change
Expand Up @@ -243,4 +243,11 @@ 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 qourum
tac0turtle marked this conversation as resolved.
Show resolved Hide resolved
bool burn_vote_quorum = 13;
// burn deposits if the proposal does not get enough deposits
bool burn_proposal_deposit = 14;
Copy link
Contributor

@atheeshp atheeshp Feb 24, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This param name might mislead the dev, as they might get it as burning the proposal deposits in any case. wdyt?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated the comment. do you have a suggestion for the name?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

appended prevote, do you think that is better?

Copy link
Contributor

@atheeshp atheeshp Feb 27, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do you think that is better?

much better than the previous :)

// burn deposits if qourum with vote type no_veto is met
tac0turtle marked this conversation as resolved.
Show resolved Hide resolved
bool burn_vote_veto = 15;
tac0turtle marked this conversation as resolved.
Show resolved Hide resolved
}
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).BurnProposalDeposit {
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.BurnProposalDeposit,
defaultParams.BurnVoteQuorum,
defaultParams.BurnVoteVeto,
)

return &v1.GenesisState{
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.BurnProposalDeposit,
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.BurnProposalDeposit = defaultParams.BurnProposalDeposit
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(), "", false, false, true), //TODO: randomize
tac0turtle marked this conversation as resolved.
Show resolved Hide resolved
)

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