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

R4R: Gov tags cleanup #1781

Merged
merged 4 commits into from
Jul 21, 2018
Merged
Show file tree
Hide file tree
Changes from all 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 PENDING.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ BREAKING CHANGES
* `gaiacli gov submit-proposal --proposer`
* `gaiacli gov deposit --depositer`
* `gaiacli gov vote --voter`
* [x/gov] Added tags sub-package, changed tags to use dash-case

FEATURES
* [lcd] Can now query governance proposals by ProposalStatus
Expand Down
90 changes: 49 additions & 41 deletions x/gov/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package gov

import (
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/gov/tags"
)

// Handle all "gov" type messages.
Expand Down Expand Up @@ -32,19 +33,19 @@ func handleMsgSubmitProposal(ctx sdk.Context, keeper Keeper, msg MsgSubmitPropos

proposalIDBytes := keeper.cdc.MustMarshalBinaryBare(proposal.GetProposalID())

tags := sdk.NewTags(
"action", []byte("submitProposal"),
"proposer", []byte(msg.Proposer.String()),
"proposalId", proposalIDBytes,
resTags := sdk.NewTags(
tags.Action, tags.ActionSubmitProposal,
tags.Proposer, []byte(msg.Proposer.String()),
tags.ProposalID, proposalIDBytes,
)

if votingStarted {
tags.AppendTag("votingPeriodStart", proposalIDBytes)
resTags.AppendTag(tags.VotingPeriodStart, proposalIDBytes)
}

return sdk.Result{
Data: proposalIDBytes,
Tags: tags,
Tags: resTags,
}
}

Expand All @@ -58,18 +59,18 @@ func handleMsgDeposit(ctx sdk.Context, keeper Keeper, msg MsgDeposit) sdk.Result
proposalIDBytes := keeper.cdc.MustMarshalBinaryBare(msg.ProposalID)

// TODO: Add tag for if voting period started
tags := sdk.NewTags(
"action", []byte("deposit"),
"depositer", []byte(msg.Depositer.String()),
"proposalId", proposalIDBytes,
resTags := sdk.NewTags(
tags.Action, tags.ActionDeposit,
tags.Depositer, []byte(msg.Depositer.String()),
tags.ProposalID, proposalIDBytes,
)

if votingStarted {
tags.AppendTag("votingPeriodStart", proposalIDBytes)
resTags.AppendTag(tags.VotingPeriodStart, proposalIDBytes)
}

return sdk.Result{
Tags: tags,
Tags: resTags,
}
}

Expand All @@ -82,30 +83,32 @@ func handleMsgVote(ctx sdk.Context, keeper Keeper, msg MsgVote) sdk.Result {

proposalIDBytes := keeper.cdc.MustMarshalBinaryBare(msg.ProposalID)

tags := sdk.NewTags(
"action", []byte("vote"),
"voter", []byte(msg.Voter.String()),
"proposalId", proposalIDBytes,
resTags := sdk.NewTags(
tags.Action, tags.ActionVote,
tags.Voter, []byte(msg.Voter.String()),
tags.ProposalID, proposalIDBytes,
)
return sdk.Result{
Tags: tags,
Tags: resTags,
}
}

// Called every block, process inflation, update validator set
func EndBlocker(ctx sdk.Context, keeper Keeper) (tags sdk.Tags, nonVotingVals []sdk.AccAddress) {
func EndBlocker(ctx sdk.Context, keeper Keeper) (resTags sdk.Tags, nonVotingVals []sdk.AccAddress) {

tags = sdk.NewTags()
resTags = sdk.NewTags()

// Delete proposals that haven't met minDeposit
for shouldPopInactiveProposalQueue(ctx, keeper) {
inactiveProposal := keeper.InactiveProposalQueuePop(ctx)
if inactiveProposal.GetStatus() == StatusDepositPeriod {
proposalIDBytes := keeper.cdc.MustMarshalBinaryBare(inactiveProposal.GetProposalID())
keeper.DeleteProposal(ctx, inactiveProposal)
tags.AppendTag("action", []byte("proposalDropped"))
tags.AppendTag("proposalId", proposalIDBytes)
if inactiveProposal.GetStatus() != StatusDepositPeriod {
continue
}

proposalIDBytes := keeper.cdc.MustMarshalBinaryBare(inactiveProposal.GetProposalID())
keeper.DeleteProposal(ctx, inactiveProposal)
resTags.AppendTag(tags.Action, tags.ActionProposalDropped)
resTags.AppendTag(tags.ProposalID, proposalIDBytes)
}

var passes bool
Expand All @@ -114,26 +117,31 @@ func EndBlocker(ctx sdk.Context, keeper Keeper) (tags sdk.Tags, nonVotingVals []
for shouldPopActiveProposalQueue(ctx, keeper) {
activeProposal := keeper.ActiveProposalQueuePop(ctx)

if ctx.BlockHeight() >= activeProposal.GetVotingStartBlock()+keeper.GetVotingProcedure().VotingPeriod {
passes, nonVotingVals = tally(ctx, keeper, activeProposal)
proposalIDBytes := keeper.cdc.MustMarshalBinaryBare(activeProposal.GetProposalID())
if passes {
keeper.RefundDeposits(ctx, activeProposal.GetProposalID())
activeProposal.SetStatus(StatusPassed)
tags.AppendTag("action", []byte("proposalPassed"))
tags.AppendTag("proposalId", proposalIDBytes)
} else {
keeper.DeleteDeposits(ctx, activeProposal.GetProposalID())
activeProposal.SetStatus(StatusRejected)
tags.AppendTag("action", []byte("proposalRejected"))
tags.AppendTag("proposalId", proposalIDBytes)
}

keeper.SetProposal(ctx, activeProposal)
proposalStartBlock := activeProposal.GetVotingStartBlock()
votingPeriod := keeper.GetVotingProcedure().VotingPeriod
if ctx.BlockHeight() < proposalStartBlock+votingPeriod {
continue
}

passes, nonVotingVals = tally(ctx, keeper, activeProposal)
proposalIDBytes := keeper.cdc.MustMarshalBinaryBare(activeProposal.GetProposalID())
var action []byte
if passes {
keeper.RefundDeposits(ctx, activeProposal.GetProposalID())
activeProposal.SetStatus(StatusPassed)
action = tags.ActionProposalPassed
} else {
keeper.DeleteDeposits(ctx, activeProposal.GetProposalID())
activeProposal.SetStatus(StatusRejected)
action = tags.ActionProposalRejected
}
keeper.SetProposal(ctx, activeProposal)

resTags.AppendTag(tags.Action, action)
resTags.AppendTag(tags.ProposalID, proposalIDBytes)
}

return tags, nonVotingVals
return resTags, nonVotingVals
}
func shouldPopInactiveProposalQueue(ctx sdk.Context, keeper Keeper) bool {
depositProcedure := keeper.GetDepositProcedure()
Expand Down
22 changes: 22 additions & 0 deletions x/gov/tags/tags.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// nolint
package tags

import (
sdk "github.com/cosmos/cosmos-sdk/types"
)

var (
ActionSubmitProposal = []byte("submit-proposal")
ActionDeposit = []byte("deposit")
ActionVote = []byte("vote")
ActionProposalDropped = []byte("proposal-dropped")
ActionProposalPassed = []byte("proposal-passed")
ActionProposalRejected = []byte("proposal-rejected")

Action = sdk.TagAction
Proposer = "proposer"
ProposalID = "proposal-id"
VotingPeriodStart = "voting-period-start"
Depositer = "depositer"
Voter = "voter"
)
12 changes: 6 additions & 6 deletions x/stake/tags/tags.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
package tags

import (
"github.com/cosmos/cosmos-sdk/types"
sdk "github.com/cosmos/cosmos-sdk/types"
)

var (
Expand All @@ -14,10 +14,10 @@ var (
ActionBeginRedelegation = []byte("begin-redelegation")
ActionCompleteRedelegation = []byte("complete-redelegation")

Action = types.TagAction
SrcValidator = types.TagSrcValidator
DstValidator = types.TagDstValidator
Delegator = types.TagDelegator
Action = sdk.TagAction
SrcValidator = sdk.TagSrcValidator
DstValidator = sdk.TagDstValidator
Delegator = sdk.TagDelegator
Moniker = "moniker"
Identity = "Identity"
Identity = "identity"
)