Merge PR #2943: Fix tag usage in handlers and EndBlocker

* 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
This commit is contained in:
Hendrik Hofstadt
2018-11-29 15:34:57 +01:00
committed by Christopher Goes
parent aa72e72ce4
commit ca43225851
21 changed files with 33 additions and 64 deletions
+1
View File
@@ -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
+1 -1
View File
@@ -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.
+3 -3
View File
@@ -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)
@@ -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]),
)
@@ -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)
}
+2 -1
View File
@@ -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()
+5 -6
View File
@@ -1,5 +1,3 @@
// +build cli_test
package clitest
import (
@@ -11,6 +9,7 @@ import (
"path/filepath"
"testing"
"github.com/tendermint/tendermint/crypto/ed25519"
"github.com/tendermint/tendermint/types"
"github.com/stretchr/testify/require"
@@ -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)
@@ -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")
@@ -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))
+2 -1
View File
@@ -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,
}
}
+2
View File
@@ -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)
-6
View File
@@ -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
View File
@@ -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{
@@ -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{
@@ -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()),
)
@@ -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{
-6
View File
@@ -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
View File
@@ -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,
)
@@ -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,
)
@@ -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,
)
-3
View File
@@ -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")
+2 -1
View File
@@ -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,
}
}
}
+1 -1
View File
@@ -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,
+2 -2
View File
@@ -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)
@@ -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)
+2 -1
View File
@@ -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,
}
}
}
+7 -6
View File
@@ -1,6 +1,7 @@
package rest
import (
"github.com/cosmos/cosmos-sdk/x/stake"
"net/http"
"strings"
@@ -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)
+1 -8
View File
@@ -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)
@@ -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),
@@ -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),
@@ -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()),
)
@@ -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,
@@ -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()),
+2 -1
View File
@@ -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,
}
})
-5
View File
@@ -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
-5
View File
@@ -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