Skip to content

Commit

Permalink
Merge PR #2943: Fix tag usage in handlers and EndBlocker
Browse files Browse the repository at this point in the history
* Fix tag usage in handlers and EndBlocker
* Prepend action tag in baseApp
* Fix LCD
* Remove unnecessary conversion
* Fix invalid consensus pubkey in CLI tests
* Fix tag usage in cli_test
* Shorten bechify in test
* Update docs and PENDING
  • Loading branch information
hendrikhofstadt authored and cwgoes committed Nov 29, 2018
1 parent aa72e72 commit ca43225
Show file tree
Hide file tree
Showing 21 changed files with 33 additions and 64 deletions.
1 change: 1 addition & 0 deletions PENDING.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ BREAKING CHANGES
* [\#2019](https://github.com/cosmos/cosmos-sdk/issues/2019) Cap total number of signatures. Current per-transaction limit is 7, and if that is exceeded transaction is rejected.
* [\#2801](https://github.com/cosmos/cosmos-sdk/pull/2801) Remove AppInit structure.
* [\#2798](https://github.com/cosmos/cosmos-sdk/issues/2798) Governance API has miss-spelled English word in JSON response ('depositer' -> 'depositor')
* [\#2943](https://github.com/cosmos/cosmos-sdk/pull/2943) Transaction action tags equal the message type. Stake EndBlocker tags are included.

* Tendermint
- Update to Tendermint 0.27.0
Expand Down
2 changes: 1 addition & 1 deletion baseapp/baseapp.go
Original file line number Diff line number Diff line change
Expand Up @@ -615,13 +615,13 @@ func (app *BaseApp) runMsgs(ctx sdk.Context, msgs []sdk.Msg, mode runTxMode) (re
if mode != runTxModeCheck {
msgResult = handler(ctx, msg)
}
msgResult.Tags = append(msgResult.Tags, sdk.MakeTag("action", []byte(msg.Type())))

// NOTE: GasWanted is determined by ante handler and
// GasUsed by the GasMeter

// Append Data and Tags
data = append(data, msgResult.Data...)
tags = append(tags, sdk.MakeTag(sdk.TagAction, []byte(msg.Type())))
tags = append(tags, msgResult.Tags...)

// Stop execution and return on first failed message.
Expand Down
6 changes: 3 additions & 3 deletions client/lcd/lcd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -564,7 +564,7 @@ func TestBonding(t *testing.T) {

// query tx
txs = getTransactions(t, port,
fmt.Sprintf("action=begin-unbonding&delegator=%s", addr),
fmt.Sprintf("action=begin_unbonding&delegator=%s", addr),
fmt.Sprintf("source-validator=%s", operAddrs[0]),
)
require.Len(t, txs, 1)
Expand All @@ -582,7 +582,7 @@ func TestBonding(t *testing.T) {

// query tx
txs = getTransactions(t, port,
fmt.Sprintf("action=begin-redelegation&delegator=%s", addr),
fmt.Sprintf("action=begin_redelegate&delegator=%s", addr),
fmt.Sprintf("source-validator=%s", operAddrs[0]),
fmt.Sprintf("destination-validator=%s", operAddrs[1]),
)
Expand Down Expand Up @@ -649,7 +649,7 @@ func TestSubmitProposal(t *testing.T) {
require.Equal(t, "Test", proposal.GetTitle())

// query tx
txs := getTransactions(t, port, fmt.Sprintf("action=submit-proposal&proposer=%s", addr))
txs := getTransactions(t, port, fmt.Sprintf("action=submit_proposal&proposer=%s", addr))
require.Len(t, txs, 1)
require.Equal(t, resultTx.Height, txs[0].Height)
}
Expand Down
3 changes: 2 additions & 1 deletion cmd/gaia/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,8 @@ func (app *GaiaApp) BeginBlocker(ctx sdk.Context, req abci.RequestBeginBlock) ab
func (app *GaiaApp) EndBlocker(ctx sdk.Context, req abci.RequestEndBlock) abci.ResponseEndBlock {

tags := gov.EndBlocker(ctx, app.govKeeper)
validatorUpdates := stake.EndBlocker(ctx, app.stakeKeeper)
validatorUpdates, endBlockerTags := stake.EndBlocker(ctx, app.stakeKeeper)
tags = append(tags, endBlockerTags...)

app.assertRuntimeInvariants()

Expand Down
11 changes: 5 additions & 6 deletions cmd/gaia/cli_test/cli_test.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// +build cli_test

package clitest

import (
Expand All @@ -11,6 +9,7 @@ import (
"path/filepath"
"testing"

"github.com/tendermint/tendermint/crypto/ed25519"
"github.com/tendermint/tendermint/types"

"github.com/stretchr/testify/require"
Expand Down Expand Up @@ -222,8 +221,8 @@ func TestGaiaCLICreateValidator(t *testing.T) {
tests.WaitForNextNBlocksTM(2, port)

fooAddr, _ := executeGetAddrPK(t, fmt.Sprintf("gaiacli keys show foo --output=json --home=%s", gaiacliHome))
barAddr, barPubKey := executeGetAddrPK(t, fmt.Sprintf("gaiacli keys show bar --output=json --home=%s", gaiacliHome))
barCeshPubKey := sdk.MustBech32ifyConsPub(barPubKey)
barAddr, _ := executeGetAddrPK(t, fmt.Sprintf("gaiacli keys show bar --output=json --home=%s", gaiacliHome))
consPubKey := sdk.MustBech32ifyConsPub(ed25519.GenPrivKey().PubKey())

executeWrite(t, fmt.Sprintf("gaiacli tx send %v --amount=10%s --to=%s --from=foo", flags, stakeTypes.DefaultBondDenom, barAddr), app.DefaultKeyPass)
tests.WaitForNextNBlocksTM(2, port)
Expand All @@ -240,7 +239,7 @@ func TestGaiaCLICreateValidator(t *testing.T) {
// create validator
cvStr := fmt.Sprintf("gaiacli tx stake create-validator %v", flags)
cvStr += fmt.Sprintf(" --from=%s", "bar")
cvStr += fmt.Sprintf(" --pubkey=%s", barCeshPubKey)
cvStr += fmt.Sprintf(" --pubkey=%s", consPubKey)
cvStr += fmt.Sprintf(" --amount=%v", fmt.Sprintf("2%s", stakeTypes.DefaultBondDenom))
cvStr += fmt.Sprintf(" --moniker=%v", "bar-vally")
cvStr += fmt.Sprintf(" --commission-rate=%v", "0.05")
Expand Down Expand Up @@ -355,7 +354,7 @@ func TestGaiaCLISubmitProposal(t *testing.T) {
executeWrite(t, spStr, app.DefaultKeyPass)
tests.WaitForNextNBlocksTM(2, port)

txs := executeGetTxs(t, fmt.Sprintf("gaiacli query txs --tags='action:submit-proposal&proposer:%s' %v", fooAddr, flags))
txs := executeGetTxs(t, fmt.Sprintf("gaiacli query txs --tags='action:submit_proposal&proposer:%s' %v", fooAddr, flags))
require.Len(t, txs, 1)

fooAcc = executeGetAccount(t, fmt.Sprintf("gaiacli query account %s %v", fooAddr, flags))
Expand Down
3 changes: 2 additions & 1 deletion cmd/gaia/cmd/gaiadebug/hack.go
Original file line number Diff line number Diff line change
Expand Up @@ -225,10 +225,11 @@ 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 {
validatorUpdates := stake.EndBlocker(ctx, app.stakeKeeper)
validatorUpdates, tags := stake.EndBlocker(ctx, app.stakeKeeper)

return abci.ResponseEndBlock{
ValidatorUpdates: validatorUpdates,
Tags: tags,
}
}

Expand Down
2 changes: 2 additions & 0 deletions docs/gaia/gaiacli.md
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,8 @@ gaiacli query txs --tags='<tag1>:<value1>&<tag2>:<value2>'

::: tip Note

The action tag always equals the message type returned by the `Type()` function of the relevant message.

You can find a list of available `tags` on each of the SDK modules:

- [Common tags](https://github.com/cosmos/cosmos-sdk/blob/d1e76221d8e28824bb4791cb4ad8662d2ae9051e/types/tags.go#L57-L63)
Expand Down
6 changes: 0 additions & 6 deletions x/distribution/alias.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,6 @@ var (
ErrNilWithdrawAddr = types.ErrNilWithdrawAddr
ErrNilValidatorAddr = types.ErrNilValidatorAddr

ActionModifyWithdrawAddress = tags.ActionModifyWithdrawAddress
ActionWithdrawDelegatorRewardsAll = tags.ActionWithdrawDelegatorRewardsAll
ActionWithdrawDelegatorReward = tags.ActionWithdrawDelegatorReward
ActionWithdrawValidatorRewardsAll = tags.ActionWithdrawValidatorRewardsAll

TagAction = tags.Action
TagValidator = tags.Validator
TagDelegator = tags.Delegator
)
4 changes: 0 additions & 4 deletions x/distribution/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ func handleMsgModifyWithdrawAddress(ctx sdk.Context, msg types.MsgSetWithdrawAdd
k.SetDelegatorWithdrawAddr(ctx, msg.DelegatorAddr, msg.WithdrawAddr)

tags := sdk.NewTags(
tags.Action, tags.ActionModifyWithdrawAddress,
tags.Delegator, []byte(msg.DelegatorAddr.String()),
)
return sdk.Result{
Expand All @@ -48,7 +47,6 @@ func handleMsgWithdrawDelegatorRewardsAll(ctx sdk.Context, msg types.MsgWithdraw
k.WithdrawDelegationRewardsAll(ctx, msg.DelegatorAddr)

tags := sdk.NewTags(
tags.Action, tags.ActionWithdrawDelegatorRewardsAll,
tags.Delegator, []byte(msg.DelegatorAddr.String()),
)
return sdk.Result{
Expand All @@ -64,7 +62,6 @@ func handleMsgWithdrawDelegatorReward(ctx sdk.Context, msg types.MsgWithdrawDele
}

tags := sdk.NewTags(
tags.Action, tags.ActionWithdrawDelegatorReward,
tags.Delegator, []byte(msg.DelegatorAddr.String()),
tags.Validator, []byte(msg.ValidatorAddr.String()),
)
Expand All @@ -81,7 +78,6 @@ func handleMsgWithdrawValidatorRewardsAll(ctx sdk.Context, msg types.MsgWithdraw
}

tags := sdk.NewTags(
tags.Action, tags.ActionWithdrawValidatorRewardsAll,
tags.Validator, []byte(msg.ValidatorAddr.String()),
)
return sdk.Result{
Expand Down
6 changes: 0 additions & 6 deletions x/distribution/tags/tags.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,6 @@ import (
)

var (
ActionModifyWithdrawAddress = []byte("modify-withdraw-address")
ActionWithdrawDelegatorRewardsAll = []byte("withdraw-delegator-rewards-all")
ActionWithdrawDelegatorReward = []byte("withdraw-delegator-reward")
ActionWithdrawValidatorRewardsAll = []byte("withdraw-validator-rewards-all")

Action = sdk.TagAction
Validator = sdk.TagSrcValidator
Delegator = sdk.TagDelegator
)
3 changes: 0 additions & 3 deletions x/gov/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ func handleMsgSubmitProposal(ctx sdk.Context, keeper Keeper, msg MsgSubmitPropos
proposalIDBytes := keeper.cdc.MustMarshalBinaryLengthPrefixed(proposal.GetProposalID())

resTags := sdk.NewTags(
tags.Action, tags.ActionSubmitProposal,
tags.Proposer, []byte(msg.Proposer.String()),
tags.ProposalID, proposalIDBytes,
)
Expand All @@ -62,7 +61,6 @@ func handleMsgDeposit(ctx sdk.Context, keeper Keeper, msg MsgDeposit) sdk.Result

// TODO: Add tag for if voting period started
resTags := sdk.NewTags(
tags.Action, tags.ActionDeposit,
tags.Depositor, []byte(msg.Depositor.String()),
tags.ProposalID, proposalIDBytes,
)
Expand All @@ -86,7 +84,6 @@ func handleMsgVote(ctx sdk.Context, keeper Keeper, msg MsgVote) sdk.Result {
proposalIDBytes := keeper.cdc.MustMarshalBinaryBare(msg.ProposalID)

resTags := sdk.NewTags(
tags.Action, tags.ActionVote,
tags.Voter, []byte(msg.Voter.String()),
tags.ProposalID, proposalIDBytes,
)
Expand Down
3 changes: 0 additions & 3 deletions x/gov/tags/tags.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@ import (
)

var (
ActionSubmitProposal = []byte("submit-proposal")
ActionDeposit = []byte("deposit")
ActionVote = []byte("vote")
ActionProposalDropped = []byte("proposal-dropped")
ActionProposalPassed = []byte("proposal-passed")
ActionProposalRejected = []byte("proposal-rejected")
Expand Down
3 changes: 2 additions & 1 deletion x/slashing/app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,10 @@ func getMockApp(t *testing.T) (*mock.App, stake.Keeper, Keeper) {
// stake endblocker
func getEndBlocker(keeper stake.Keeper) sdk.EndBlocker {
return func(ctx sdk.Context, req abci.RequestEndBlock) abci.ResponseEndBlock {
validatorUpdates := stake.EndBlocker(ctx, keeper)
validatorUpdates, tags := stake.EndBlocker(ctx, keeper)
return abci.ResponseEndBlock{
ValidatorUpdates: validatorUpdates,
Tags: tags,
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion x/slashing/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func handleMsgUnjail(ctx sdk.Context, msg MsgUnjail, k Keeper) sdk.Result {
// unjail the validator
k.validatorSet.Unjail(ctx, consAddr)

tags := sdk.NewTags("action", []byte("unjail"), "validator", []byte(msg.ValidatorAddr.String()))
tags := sdk.NewTags("validator", []byte(msg.ValidatorAddr.String()))

return sdk.Result{
Tags: tags,
Expand Down
4 changes: 2 additions & 2 deletions x/slashing/keeper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,7 @@ func TestValidatorDippingInAndOut(t *testing.T) {
newAmt := int64(101)
got = sh(ctx, NewTestMsgCreateValidator(addrs[1], pks[1], sdk.NewInt(newAmt)))
require.True(t, got.IsOK())
validatorUpdates := stake.EndBlocker(ctx, sk)
validatorUpdates, _ := stake.EndBlocker(ctx, sk)
require.Equal(t, 2, len(validatorUpdates))
validator, _ := sk.GetValidator(ctx, addr)
require.Equal(t, sdk.Unbonding, validator.Status)
Expand All @@ -421,7 +421,7 @@ func TestValidatorDippingInAndOut(t *testing.T) {
// validator added back in
got = sh(ctx, newTestMsgDelegate(sdk.AccAddress(addrs[2]), addrs[0], sdk.NewInt(2)))
require.True(t, got.IsOK())
validatorUpdates = stake.EndBlocker(ctx, sk)
validatorUpdates, _ = stake.EndBlocker(ctx, sk)
require.Equal(t, 2, len(validatorUpdates))
validator, _ = sk.GetValidator(ctx, addr)
require.Equal(t, sdk.Bonded, validator.Status)
Expand Down
3 changes: 2 additions & 1 deletion x/stake/app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,11 @@ func getMockApp(t *testing.T) (*mock.App, Keeper) {
// getEndBlocker returns a stake endblocker.
func getEndBlocker(keeper Keeper) sdk.EndBlocker {
return func(ctx sdk.Context, req abci.RequestEndBlock) abci.ResponseEndBlock {
validatorUpdates := EndBlocker(ctx, keeper)
validatorUpdates, tags := EndBlocker(ctx, keeper)

return abci.ResponseEndBlock{
ValidatorUpdates: validatorUpdates,
Tags: tags,
}
}
}
Expand Down
13 changes: 7 additions & 6 deletions x/stake/client/rest/query.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package rest

import (
"github.com/cosmos/cosmos-sdk/x/stake"
"net/http"
"strings"

Expand Down Expand Up @@ -161,18 +162,18 @@ func delegatorTxsHandlerFn(cliCtx context.CLIContext, cdc *codec.Codec) http.Han

switch {
case isBondTx:
actions = append(actions, string(tags.ActionDelegate))
actions = append(actions, stake.MsgDelegate{}.Type())
case isUnbondTx:
actions = append(actions, string(tags.ActionBeginUnbonding))
actions = append(actions, stake.MsgBeginUnbonding{}.Type())
actions = append(actions, string(tags.ActionCompleteUnbonding))
case isRedTx:
actions = append(actions, string(tags.ActionBeginRedelegation))
actions = append(actions, stake.MsgBeginRedelegate{}.Type())
actions = append(actions, string(tags.ActionCompleteRedelegation))
case noQuery:
actions = append(actions, string(tags.ActionDelegate))
actions = append(actions, string(tags.ActionBeginUnbonding))
actions = append(actions, stake.MsgDelegate{}.Type())
actions = append(actions, stake.MsgBeginUnbonding{}.Type())
actions = append(actions, string(tags.ActionCompleteUnbonding))
actions = append(actions, string(tags.ActionBeginRedelegation))
actions = append(actions, stake.MsgBeginRedelegate{}.Type())
actions = append(actions, string(tags.ActionCompleteRedelegation))
default:
w.WriteHeader(http.StatusNoContent)
Expand Down
9 changes: 1 addition & 8 deletions x/stake/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,7 @@ 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.EmptyTags()

func EndBlocker(ctx sdk.Context, k keeper.Keeper) (validatorUpdates []abci.ValidatorUpdate, endBlockerTags sdk.Tags) {
// Reset the intra-transaction counter.
k.SetIntraTxCounter(ctx, 0)

Expand Down Expand Up @@ -127,7 +125,6 @@ func handleMsgCreateValidator(ctx sdk.Context, msg types.MsgCreateValidator, k k
}

tags := sdk.NewTags(
tags.Action, tags.ActionCreateValidator,
tags.DstValidator, []byte(msg.ValidatorAddr.String()),
tags.Moniker, []byte(msg.Description.Moniker),
tags.Identity, []byte(msg.Description.Identity),
Expand Down Expand Up @@ -165,7 +162,6 @@ func handleMsgEditValidator(ctx sdk.Context, msg types.MsgEditValidator, k keepe
k.SetValidator(ctx, validator)

tags := sdk.NewTags(
tags.Action, tags.ActionEditValidator,
tags.DstValidator, []byte(msg.ValidatorAddr.String()),
tags.Moniker, []byte(description.Moniker),
tags.Identity, []byte(description.Identity),
Expand Down Expand Up @@ -196,7 +192,6 @@ func handleMsgDelegate(ctx sdk.Context, msg types.MsgDelegate, k keeper.Keeper)
}

tags := sdk.NewTags(
tags.Action, tags.ActionDelegate,
tags.Delegator, []byte(msg.DelegatorAddr.String()),
tags.DstValidator, []byte(msg.ValidatorAddr.String()),
)
Expand All @@ -215,7 +210,6 @@ func handleMsgBeginUnbonding(ctx sdk.Context, msg types.MsgBeginUnbonding, k kee
finishTime := types.MsgCdc.MustMarshalBinaryLengthPrefixed(ubd.MinTime)

tags := sdk.NewTags(
tags.Action, tags.ActionBeginUnbonding,
tags.Delegator, []byte(msg.DelegatorAddr.String()),
tags.SrcValidator, []byte(msg.ValidatorAddr.String()),
tags.EndTime, finishTime,
Expand All @@ -233,7 +227,6 @@ func handleMsgBeginRedelegate(ctx sdk.Context, msg types.MsgBeginRedelegate, k k
finishTime := types.MsgCdc.MustMarshalBinaryLengthPrefixed(red.MinTime)

tags := sdk.NewTags(
tags.Action, tags.ActionBeginRedelegation,
tags.Delegator, []byte(msg.DelegatorAddr.String()),
tags.SrcValidator, []byte(msg.ValidatorSrcAddr.String()),
tags.DstValidator, []byte(msg.ValidatorDstAddr.String()),
Expand Down
3 changes: 2 additions & 1 deletion x/stake/simulation/sim_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,10 @@ func TestStakeWithRandomMessages(t *testing.T) {
distrKeeper := distribution.NewKeeper(mapp.Cdc, distrKey, paramstore.Subspace(distribution.DefaultParamspace), bankKeeper, stakeKeeper, feeCollectionKeeper, distribution.DefaultCodespace)
mapp.Router().AddRoute("stake", stake.NewHandler(stakeKeeper))
mapp.SetEndBlocker(func(ctx sdk.Context, req abci.RequestEndBlock) abci.ResponseEndBlock {
validatorUpdates := stake.EndBlocker(ctx, stakeKeeper)
validatorUpdates, tags := stake.EndBlocker(ctx, stakeKeeper)
return abci.ResponseEndBlock{
ValidatorUpdates: validatorUpdates,
Tags: tags,
}
})

Expand Down
5 changes: 0 additions & 5 deletions x/stake/stake.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,12 +151,7 @@ var (
)

var (
ActionCreateValidator = tags.ActionCreateValidator
ActionEditValidator = tags.ActionEditValidator
ActionDelegate = tags.ActionDelegate
ActionBeginUnbonding = tags.ActionBeginUnbonding
ActionCompleteUnbonding = tags.ActionCompleteUnbonding
ActionBeginRedelegation = tags.ActionBeginRedelegation
ActionCompleteRedelegation = tags.ActionCompleteRedelegation

TagAction = tags.Action
Expand Down
5 changes: 0 additions & 5 deletions x/stake/tags/tags.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,7 @@ import (
)

var (
ActionCreateValidator = []byte("create-validator")
ActionEditValidator = []byte("edit-validator")
ActionDelegate = []byte("delegate")
ActionBeginUnbonding = []byte("begin-unbonding")
ActionCompleteUnbonding = []byte("complete-unbonding")
ActionBeginRedelegation = []byte("begin-redelegation")
ActionCompleteRedelegation = []byte("complete-redelegation")

Action = sdk.TagAction
Expand Down

0 comments on commit ca43225

Please sign in to comment.