Tags Cleanup & Docs (#3137)

This commit is contained in:
Alexander Bezobchuk 2018-12-19 22:28:38 -05:00 committed by Jack Zampolin
parent 192ad58431
commit 5a13e75367
15 changed files with 207 additions and 39 deletions

View File

@ -48,6 +48,9 @@ IMPROVEMENTS
* [\#3158](https://github.com/cosmos/cosmos-sdk/pull/3158) Validate slashing genesis
* 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.

View File

@ -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)
@ -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...)

12
docs/spec/bank/tags.md Normal file
View File

@ -0,0 +1,12 @@
# Tags
The bank module emits the following events/tags:
## Handlers
### MsgSend
| Key | Value |
|-----------|---------------------------|
| sender | {senderAccountAddress} |
| recipient | {recipientAccountAddress} |

View File

@ -0,0 +1,30 @@
# Tags
The distribution module emits the following events/tags:
## Handlers
### MsgSetWithdrawAddress
| Key | Value |
|-----------|---------------------------|
| delegator | {delegatorAccountAddress} |
### MsgWithdrawDelegatorRewardsAll
| Key | Value |
|-----------|---------------------------|
| delegator | {delegatorAccountAddress} |
### MsgWithdrawDelegatorReward
| Key | Value |
|------------------|---------------------------|
| delegator | {delegatorAccountAddress} |
| source-validator | {srcOperatorAddress} |
### MsgWithdrawValidatorRewardsAll
| Key | Value |
|------------------|----------------------|
| source-validator | {srcOperatorAddress} |

View File

@ -0,0 +1,38 @@
# Tags
The governance module emits the following events/tags:
## EndBlocker
| 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} |

View File

@ -0,0 +1,12 @@
# Tags
The slashing module emits the following events/tags:
## Handlers
### MsgUnjail
| Key | Value |
|-----------|----------------------------|
| action | validator-unjailed |
| validator | {validatorOperatorAddress} |

58
docs/spec/staking/tags.md Normal file
View File

@ -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

View File

@ -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()

View File

@ -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(
@ -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(
@ -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()
@ -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()

View File

@ -88,9 +88,9 @@ 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() {
@ -98,11 +98,12 @@ func EndBlocker(ctx sdk.Context, keeper Keeper) (resTags sdk.Tags) {
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.ProposalID, []byte(fmt.Sprintf("%d", proposalID)))
resTags = resTags.AppendTag(tags.ProposalResult, tags.ActionProposalDropped)
logger.Info(
fmt.Sprintf("proposal %d (%s) didn't meet minimum deposit of %s (had only %s); deleted",
@ -124,26 +125,30 @@ 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.ProposalID, []byte(fmt.Sprintf("%d", proposalID)))
resTags = resTags.AppendTag(tags.ProposalResult, tagValue)
}
activeIterator.Close()

View File

@ -19,4 +19,5 @@ var (
VotingPeriodStart = "voting-period-start"
Depositor = "depositor"
Voter = "voter"
ProposalResult = "proposal-result"
)

View File

@ -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 {
@ -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,

13
x/slashing/tags/tags.go Normal file
View File

@ -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"
)

View File

@ -1,7 +1,6 @@
package slashing
import (
"encoding/binary"
"fmt"
abci "github.com/tendermint/tendermint/abci/types"
@ -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)
@ -37,5 +30,5 @@ func BeginBlocker(ctx sdk.Context, req abci.RequestBeginBlock, sk Keeper) (tags
}
}
return
return sdk.EmptyTags()
}

View File

@ -2,6 +2,7 @@ package stake
import (
"bytes"
"time"
abci "github.com/tendermint/tendermint/abci/types"
"github.com/tendermint/tendermint/libs/common"
@ -34,7 +35,9 @@ func NewHandler(k keeper.Keeper) sdk.Handler {
}
// Called every block, update validator set
func EndBlocker(ctx sdk.Context, k keeper.Keeper) (validatorUpdates []abci.ValidatorUpdate, endBlockerTags sdk.Tags) {
func EndBlocker(ctx sdk.Context, k keeper.Keeper) ([]abci.ValidatorUpdate, sdk.Tags) {
resTags := sdk.NewTags()
// Calculate validator set changes.
//
// NOTE: ApplyAndReturnValidatorSetUpdates has to come before
@ -44,7 +47,7 @@ func EndBlocker(ctx sdk.Context, k keeper.Keeper) (validatorUpdates []abci.Valid
// unbonded after the Endblocker (go from Bonded -> Unbonding during
// ApplyAndReturnValidatorSetUpdates and then Unbonding -> Unbonded during
// UnbondAllMatureValidatorQueue).
validatorUpdates = k.ApplyAndReturnValidatorSetUpdates(ctx)
validatorUpdates := k.ApplyAndReturnValidatorSetUpdates(ctx)
// Unbond all mature validators from the unbonding queue.
k.UnbondAllMatureValidatorQueue(ctx)
@ -56,7 +59,8 @@ func EndBlocker(ctx sdk.Context, k keeper.Keeper) (validatorUpdates []abci.Valid
if err != nil {
continue
}
endBlockerTags.AppendTags(sdk.NewTags(
resTags.AppendTags(sdk.NewTags(
tags.Action, ActionCompleteUnbonding,
tags.Delegator, []byte(dvPair.DelegatorAddr.String()),
tags.SrcValidator, []byte(dvPair.ValidatorAddr.String()),
@ -70,14 +74,16 @@ func EndBlocker(ctx sdk.Context, k keeper.Keeper) (validatorUpdates []abci.Valid
if err != nil {
continue
}
endBlockerTags.AppendTags(sdk.NewTags(
resTags.AppendTags(sdk.NewTags(
tags.Action, tags.ActionCompleteRedelegation,
tags.Delegator, []byte(dvvTriplet.DelegatorAddr.String()),
tags.SrcValidator, []byte(dvvTriplet.ValidatorSrcAddr.String()),
tags.DstValidator, []byte(dvvTriplet.ValidatorDstAddr.String()),
))
}
return
return validatorUpdates, resTags
}
//_____________________________________________________________________
@ -215,12 +221,12 @@ func handleMsgBeginUnbonding(ctx sdk.Context, msg types.MsgBeginUnbonding, k kee
}
finishTime := types.MsgCdc.MustMarshalBinaryLengthPrefixed(ubd.MinTime)
tags := sdk.NewTags(
tags.Delegator, []byte(msg.DelegatorAddr.String()),
tags.SrcValidator, []byte(msg.ValidatorAddr.String()),
tags.EndTime, finishTime,
tags.EndTime, []byte(ubd.MinTime.Format(time.RFC3339)),
)
return sdk.Result{Data: finishTime, Tags: tags}
}
@ -232,12 +238,12 @@ func handleMsgBeginRedelegate(ctx sdk.Context, msg types.MsgBeginRedelegate, k k
}
finishTime := types.MsgCdc.MustMarshalBinaryLengthPrefixed(red.MinTime)
tags := sdk.NewTags(
resTags := sdk.NewTags(
tags.Delegator, []byte(msg.DelegatorAddr.String()),
tags.SrcValidator, []byte(msg.ValidatorSrcAddr.String()),
tags.DstValidator, []byte(msg.ValidatorDstAddr.String()),
tags.EndTime, finishTime,
tags.EndTime, []byte(red.MinTime.Format(time.RFC3339)),
)
return sdk.Result{Data: finishTime, Tags: tags}
return sdk.Result{Data: finishTime, Tags: resTags}
}