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: Tags Cleanup & Docs #3137

Merged
merged 15 commits into from
Dec 20, 2018
3 changes: 3 additions & 0 deletions PENDING.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ IMPROVEMENTS
* Gaia

* SDK
* [\#3137](https://github.com/cosmos/cosmos-sdk/pull/3137) Add tag documentation
for each module along with cleaning up a few existing tags in the governance,
slashing, and staking modules.
* [\#3093](https://github.com/cosmos/cosmos-sdk/issues/3093) Ante handler does no longer read all accounts in one go when processing signatures as signature
verification may fail before last signature is checked.

Expand Down
2 changes: 0 additions & 2 deletions cmd/gaia/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,6 @@ func MakeCodec() *codec.Codec {

// application updates every end block
func (app *GaiaApp) BeginBlocker(ctx sdk.Context, req abci.RequestBeginBlock) abci.ResponseBeginBlock {

// mint new tokens for the previous block
mint.BeginBlocker(ctx, app.mintKeeper)

Expand All @@ -215,7 +214,6 @@ func (app *GaiaApp) BeginBlocker(ctx sdk.Context, req abci.RequestBeginBlock) ab
// application updates every end block
// nolint: unparam
func (app *GaiaApp) EndBlocker(ctx sdk.Context, req abci.RequestEndBlock) abci.ResponseEndBlock {

tags := gov.EndBlocker(ctx, app.govKeeper)
validatorUpdates, endBlockerTags := stake.EndBlocker(ctx, app.stakeKeeper)
tags = append(tags, endBlockerTags...)
Expand Down
12 changes: 12 additions & 0 deletions docs/spec/bank/tags.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Tags

The bank module emits the following events/tags:

## Handlers

### MsgSend

| Key | Value |
|-----------|---------------------------|
| sender | {senderAccountAddress} |
| recipient | {recipientAccountAddress} |
30 changes: 30 additions & 0 deletions docs/spec/distribution/tags.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Tags

The distribution module emits the following events/tags:

## Handlers

### MsgSetWithdrawAddress

| Key | Value |
|-----------|---------------------------|
| delegator | {delegatorAccountAddress} |
Copy link
Member

Choose a reason for hiding this comment

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

Is there a reason why we don't tag every message with it's type? Or do we and that isn't mentioned here?

Copy link
Contributor Author

@alexanderbez alexanderbez Dec 19, 2018

Choose a reason for hiding this comment

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

We do:

# baseapp.go#L:624
tags = append(tags, sdk.MakeTag(sdk.TagAction, []byte(msg.Type())))

I will be changing this in #3171 to be message-type instead of action so I'd rather do that in the aforementioned PR (i.e have this merged first).


### MsgWithdrawDelegatorRewardsAll

| Key | Value |
|-----------|---------------------------|
| delegator | {delegatorAccountAddress} |

### MsgWithdrawDelegatorReward

| Key | Value |
|------------------|---------------------------|
| delegator | {delegatorAccountAddress} |
| source-validator | {srcOperatorAddress} |

### MsgWithdrawValidatorRewardsAll

| Key | Value |
|------------------|----------------------|
| source-validator | {srcOperatorAddress} |
38 changes: 38 additions & 0 deletions docs/spec/governance/tags.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# Tags

The governance module emits the following events/tags:

## EndBlocker
Copy link
Member

Choose a reason for hiding this comment

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

What does this mean? All governance events are tagged with these?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Exactly.


| Key | Value |
|-----------------|------------------------------------------------------|
| proposal-result | proposal-passed\|proposal-rejected\|proposal-dropped |

## Handlers

### MsgSubmitProposal

| Key | Value |
|-------------------------|--------------------------|
| action | proposal-vote |
| proposer | {proposerAccountAddress} |
| proposal-id | {proposalID} |
| voting-period-start [0] | {proposalID} |

* [0] Tag only emitted if the voting period starts during the submission.

### MsgVote

| Key | Value |
|-------------|-----------------------|
| action | proposal-vote |
| voter | {voterAccountAddress} |
| proposal-id | {proposalID} |

### MsgDeposit

| Key | Value |
|-------------|---------------------------|
| action | proposal-vote |
| depositor | {depositorAccountAddress} |
| proposal-id | {proposalID} |
12 changes: 12 additions & 0 deletions docs/spec/slashing/tags.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Tags

The slashing module emits the following events/tags:

## Handlers

### MsgUnjail
alexanderbez marked this conversation as resolved.
Show resolved Hide resolved

| Key | Value |
|-----------|----------------------------|
| action | validator-unjailed |
| validator | {validatorOperatorAddress} |
58 changes: 58 additions & 0 deletions docs/spec/staking/tags.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# Tags

The staking module emits the following events/tags:

## EndBlocker

| Key | Value |
|-----------------------|-------------------------------------------|
| action | complete-unbonding\|complete-redelegation |
| delegator | {delegatorAccountAddress} |
| source-validator | {srcOperatorAddress} |
| destination-validator | {dstOperatorAddress} |

## Handlers

### MsgCreateValidator

| Key | Value |
|-----------------------|----------------------|
| destination-validator | {dstOperatorAddress} |
| moniker | {validatorMoniker} |
| identity | {validatorIdentity} |

### MsgEditValidator

| Key | Value |
|-----------------------|----------------------|
| destination-validator | {dstOperatorAddress} |
| moniker | {validatorMoniker} |
| identity | {validatorIdentity} |

### MsgDelegate

| Key | Value |
|-----------------------|-------------------------------------------|
| delegator | {delegatorAccountAddress} |
| destination-validator | {dstOperatorAddress} |

### MsgBeginRedelegate

| Key | Value |
|-----------------------|-------------------------------------------|
| delegator | {delegatorAccountAddress} |
| source-validator | {srcOperatorAddress} |
| destination-validator | {dstOperatorAddress} |
| end-time [0] | {delegationFinishTime} |

* [0] Time is formatted in the RFC3339 standard

### MsgBeginUnbonding

| Key | Value |
|------------------|---------------------------|
| delegator | {delegatorAccountAddress} |
| source-validator | {srcOperatorAddress} |
| end-time [0] | {delegationFinishTime} |

* [0] Time is formatted in the RFC3339 standard
1 change: 0 additions & 1 deletion x/bank/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ func NewHandler(k Keeper) sdk.Handler {
// Handle MsgSend.
func handleMsgSend(ctx sdk.Context, k Keeper, msg MsgSend) sdk.Result {
// NOTE: totalIn == totalOut should already have been checked

tags, err := k.InputOutputCoins(ctx, msg.Inputs, msg.Outputs)
if err != nil {
return err.Result()
Expand Down
4 changes: 0 additions & 4 deletions x/distribution/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ func NewHandler(k keeper.Keeper) sdk.Handler {
// now we just perform action and save

func handleMsgModifyWithdrawAddress(ctx sdk.Context, msg types.MsgSetWithdrawAddress, k keeper.Keeper) sdk.Result {

k.SetDelegatorWithdrawAddr(ctx, msg.DelegatorAddr, msg.WithdrawAddr)

tags := sdk.NewTags(
Expand All @@ -43,7 +42,6 @@ func handleMsgModifyWithdrawAddress(ctx sdk.Context, msg types.MsgSetWithdrawAdd
}

func handleMsgWithdrawDelegatorRewardsAll(ctx sdk.Context, msg types.MsgWithdrawDelegatorRewardsAll, k keeper.Keeper) sdk.Result {

k.WithdrawDelegationRewardsAll(ctx, msg.DelegatorAddr)

tags := sdk.NewTags(
Expand All @@ -55,7 +53,6 @@ func handleMsgWithdrawDelegatorRewardsAll(ctx sdk.Context, msg types.MsgWithdraw
}

func handleMsgWithdrawDelegatorReward(ctx sdk.Context, msg types.MsgWithdrawDelegatorReward, k keeper.Keeper) sdk.Result {

err := k.WithdrawDelegationReward(ctx, msg.DelegatorAddr, msg.ValidatorAddr)
if err != nil {
return err.Result()
Expand All @@ -71,7 +68,6 @@ func handleMsgWithdrawDelegatorReward(ctx sdk.Context, msg types.MsgWithdrawDele
}

func handleMsgWithdrawValidatorRewardsAll(ctx sdk.Context, msg types.MsgWithdrawValidatorRewardsAll, k keeper.Keeper) sdk.Result {

err := k.WithdrawValidatorRewardsAll(ctx, msg.ValidatorAddr)
if err != nil {
return err.Result()
Expand Down
25 changes: 14 additions & 11 deletions x/gov/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,21 +88,21 @@ func handleMsgVote(ctx sdk.Context, keeper Keeper, msg MsgVote) sdk.Result {
}

// Called every block, process inflation, update validator set
func EndBlocker(ctx sdk.Context, keeper Keeper) (resTags sdk.Tags) {
func EndBlocker(ctx sdk.Context, keeper Keeper) sdk.Tags {
logger := ctx.Logger().With("module", "x/gov")
resTags = sdk.NewTags()
resTags := sdk.NewTags()

inactiveIterator := keeper.InactiveProposalQueueIterator(ctx, ctx.BlockHeader().Time)
for ; inactiveIterator.Valid(); inactiveIterator.Next() {
var proposalID uint64

keeper.cdc.MustUnmarshalBinaryLengthPrefixed(inactiveIterator.Value(), &proposalID)
inactiveProposal := keeper.GetProposal(ctx, proposalID)

keeper.DeleteProposal(ctx, proposalID)
keeper.DeleteDeposits(ctx, proposalID) // delete any associated deposits (burned)

resTags = resTags.AppendTag(tags.Action, tags.ActionProposalDropped)
resTags = resTags.AppendTag(tags.ProposalID, []byte(string(proposalID)))
resTags = resTags.AppendTag(tags.ProposalResult, tags.ActionProposalDropped)
alexanderbez marked this conversation as resolved.
Show resolved Hide resolved

logger.Info(
fmt.Sprintf("proposal %d (%s) didn't meet minimum deposit of %s (had only %s); deleted",
Expand All @@ -124,26 +124,29 @@ func EndBlocker(ctx sdk.Context, keeper Keeper) (resTags sdk.Tags) {
activeProposal := keeper.GetProposal(ctx, proposalID)
passes, tallyResults := tally(ctx, keeper, activeProposal)

var action []byte
var tagValue []byte
if passes {
keeper.RefundDeposits(ctx, activeProposal.GetProposalID())
activeProposal.SetStatus(StatusPassed)
action = tags.ActionProposalPassed
tagValue = tags.ActionProposalPassed
} else {
keeper.DeleteDeposits(ctx, activeProposal.GetProposalID())
activeProposal.SetStatus(StatusRejected)
action = tags.ActionProposalRejected
tagValue = tags.ActionProposalRejected
}

activeProposal.SetTallyResult(tallyResults)
keeper.SetProposal(ctx, activeProposal)
keeper.RemoveFromActiveProposalQueue(ctx, activeProposal.GetVotingEndTime(), activeProposal.GetProposalID())

logger.Info(fmt.Sprintf("proposal %d (%s) tallied; passed: %v",
activeProposal.GetProposalID(), activeProposal.GetTitle(), passes))
logger.Info(
fmt.Sprintf(
"proposal %d (%s) tallied; passed: %v",
activeProposal.GetProposalID(), activeProposal.GetTitle(), passes,
),
)

resTags = resTags.AppendTag(tags.Action, action)
resTags = resTags.AppendTag(tags.ProposalID, []byte(string(proposalID)))
resTags = resTags.AppendTag(tags.ProposalResult, tagValue)
alexanderbez marked this conversation as resolved.
Show resolved Hide resolved
}

activeIterator.Close()
Expand Down
1 change: 1 addition & 0 deletions x/gov/tags/tags.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,5 @@ var (
VotingPeriodStart = "voting-period-start"
Depositor = "depositor"
Voter = "voter"
ProposalResult = "proposal-result"
)
6 changes: 5 additions & 1 deletion x/slashing/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package slashing

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

func NewHandler(k Keeper) sdk.Handler {
Expand Down Expand Up @@ -49,7 +50,10 @@ func handleMsgUnjail(ctx sdk.Context, msg MsgUnjail, k Keeper) sdk.Result {
// unjail the validator
k.validatorSet.Unjail(ctx, consAddr)

tags := sdk.NewTags("validator", []byte(msg.ValidatorAddr.String()))
tags := sdk.NewTags(
tags.Action, tags.ActionValidatorUnjailed,
tags.Validator, []byte(msg.ValidatorAddr.String()),
)

return sdk.Result{
Tags: tags,
Expand Down
13 changes: 13 additions & 0 deletions x/slashing/tags/tags.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package tags

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

// Slashing tags
var (
ActionValidatorUnjailed = []byte("validator-unjailed")

Action = sdk.TagAction
Validator = "validator"
)
11 changes: 2 additions & 9 deletions x/slashing/tick.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package slashing

import (
"encoding/binary"
"fmt"

abci "github.com/tendermint/tendermint/abci/types"
Expand All @@ -11,13 +10,7 @@ import (
)

// slashing begin block functionality
func BeginBlocker(ctx sdk.Context, req abci.RequestBeginBlock, sk Keeper) (tags sdk.Tags) {

// Tag the height
heightBytes := make([]byte, 8)
binary.LittleEndian.PutUint64(heightBytes, uint64(req.Header.Height))
tags = sdk.NewTags("height", heightBytes)

func BeginBlocker(ctx sdk.Context, req abci.RequestBeginBlock, sk Keeper) sdk.Tags {
// Iterate over all the validators which *should* have signed this block
// store whether or not they have actually signed it and slash/unbond any
// which have missed too many blocks in a row (downtime slashing)
Expand All @@ -37,5 +30,5 @@ func BeginBlocker(ctx sdk.Context, req abci.RequestBeginBlock, sk Keeper) (tags
}
}

return
return sdk.EmptyTags()
}
Loading