From 8550d87319968c877a9a0ce4cc54e37bf896d940 Mon Sep 17 00:00:00 2001 From: Federico Kunze <31522760+fedekunze@users.noreply.github.com> Date: Wed, 10 Apr 2019 19:03:44 +0200 Subject: [PATCH] unified sender tag (#4057) Closes: #3775 --- .pending/breaking/sdk/3775-unify-sender-tag | 1 + client/lcd/lcd_test.go | 12 +++++----- client/lcd/swagger-ui/swagger.yaml | 2 +- cmd/gaia/cli_test/cli_test.go | 6 ++--- docs/spec/distribution/06_tags.md | 22 ++++++++--------- docs/spec/governance/04_tags.md | 6 ++--- docs/spec/slashing/06_tags.md | 10 ++++---- docs/spec/staking/06_tags.md | 26 ++++++++++----------- types/tags.go | 1 + x/crisis/handler.go | 9 +++---- x/crisis/tags/tags.go | 11 +++++++++ x/distribution/alias.go | 1 - x/distribution/handler.go | 6 ++--- x/distribution/tags/tags.go | 2 +- x/gov/client/utils/query.go | 4 ++-- x/gov/handler.go | 6 ++--- x/gov/tags/tags.go | 4 +--- x/slashing/handler.go | 2 +- x/slashing/tags/tags.go | 4 ++-- x/staking/client/rest/utils.go | 2 +- x/staking/handler.go | 11 +++++---- x/staking/tags/tags.go | 1 + 22 files changed, 81 insertions(+), 68 deletions(-) create mode 100644 .pending/breaking/sdk/3775-unify-sender-tag create mode 100644 x/crisis/tags/tags.go diff --git a/.pending/breaking/sdk/3775-unify-sender-tag b/.pending/breaking/sdk/3775-unify-sender-tag new file mode 100644 index 0000000000..94e7f702c5 --- /dev/null +++ b/.pending/breaking/sdk/3775-unify-sender-tag @@ -0,0 +1 @@ +#3775 unify sender transaction tag for ease of querying diff --git a/client/lcd/lcd_test.go b/client/lcd/lcd_test.go index 580d6eaede..f65f69063f 100644 --- a/client/lcd/lcd_test.go +++ b/client/lcd/lcd_test.go @@ -336,7 +336,7 @@ func TestTxs(t *testing.T) { txs = getTransactions(t, port, fmt.Sprintf("sender=%s", addr.String())) require.Equal(t, emptyTxs, txs) - txs = getTransactions(t, port, fmt.Sprintf("action=submit%%20proposal&proposer=%s", addr.String())) + txs = getTransactions(t, port, fmt.Sprintf("action=submit%%20proposal&sender=%s", addr.String())) require.Equal(t, emptyTxs, txs) // create tx @@ -455,7 +455,7 @@ func TestBonding(t *testing.T) { // query tx txs := getTransactions(t, port, - fmt.Sprintf("action=delegate&delegator=%s", addr), + fmt.Sprintf("action=delegate&sender=%s", addr), fmt.Sprintf("destination-validator=%s", operAddrs[0]), ) require.Len(t, txs, 1) @@ -508,7 +508,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&sender=%s", addr), fmt.Sprintf("source-validator=%s", operAddrs[0]), ) require.Len(t, txs, 1) @@ -545,7 +545,7 @@ func TestBonding(t *testing.T) { // query tx txs = getTransactions(t, port, - fmt.Sprintf("action=begin_redelegate&delegator=%s", addr), + fmt.Sprintf("action=begin_redelegate&sender=%s", addr), fmt.Sprintf("source-validator=%s", operAddrs[0]), fmt.Sprintf("destination-validator=%s", operAddrs[1]), ) @@ -669,7 +669,7 @@ func TestDeposit(t *testing.T) { require.Equal(t, expectedBalance.Amount.Sub(depositTokens), acc.GetCoins().AmountOf(sdk.DefaultBondDenom)) // query tx - txs := getTransactions(t, port, fmt.Sprintf("action=deposit&depositor=%s", addr)) + txs := getTransactions(t, port, fmt.Sprintf("action=deposit&sender=%s", addr)) require.Len(t, txs, 1) require.Equal(t, resultTx.Height, txs[0].Height) @@ -728,7 +728,7 @@ func TestVote(t *testing.T) { expectedBalance = coins[0] // query tx - txs := getTransactions(t, port, fmt.Sprintf("action=vote&voter=%s", addr)) + txs := getTransactions(t, port, fmt.Sprintf("action=vote&sender=%s", addr)) require.Len(t, txs, 1) require.Equal(t, resultTx.Height, txs[0].Height) diff --git a/client/lcd/swagger-ui/swagger.yaml b/client/lcd/swagger-ui/swagger.yaml index cb479a63f3..e1c11a0062 100644 --- a/client/lcd/swagger-ui/swagger.yaml +++ b/client/lcd/swagger-ui/swagger.yaml @@ -236,7 +236,7 @@ paths: - in: query name: tag type: string - description: "transaction tags such as 'action=submit-proposal' and 'proposer=cosmos1g9ahr6xhht5rmqven628nklxluzyv8z9jqjcmc' which results in the following endpoint: 'GET /txs?action=submit-proposal&proposer=cosmos1g9ahr6xhht5rmqven628nklxluzyv8z9jqjcmc'" + description: "transaction tags such as 'action=submit-proposal' and 'sender=cosmos1g9ahr6xhht5rmqven628nklxluzyv8z9jqjcmc' which results in the following endpoint: 'GET /txs?action=submit-proposal&sender=cosmos1g9ahr6xhht5rmqven628nklxluzyv8z9jqjcmc'" required: true x-example: 'TODO' - in: query diff --git a/cmd/gaia/cli_test/cli_test.go b/cmd/gaia/cli_test/cli_test.go index 1aa52816b7..82b661d7c0 100644 --- a/cmd/gaia/cli_test/cli_test.go +++ b/cmd/gaia/cli_test/cli_test.go @@ -468,7 +468,7 @@ func TestGaiaCLISubmitProposal(t *testing.T) { tests.WaitForNextNBlocksTM(1, f.Port) // Ensure transaction tags can be queried - txs := f.QueryTxs(1, 50, "action:submit_proposal", fmt.Sprintf("proposer:%s", fooAddr)) + txs := f.QueryTxs(1, 50, "action:submit_proposal", fmt.Sprintf("sender:%s", fooAddr)) require.Len(t, txs, 1) // Ensure deposit was deducted @@ -512,7 +512,7 @@ func TestGaiaCLISubmitProposal(t *testing.T) { require.Equal(t, proposalTokens.Add(depositTokens), deposit.Amount.AmountOf(denom)) // Ensure tags are set on the transaction - txs = f.QueryTxs(1, 50, "action:deposit", fmt.Sprintf("depositor:%s", fooAddr)) + txs = f.QueryTxs(1, 50, "action:deposit", fmt.Sprintf("sender:%s", fooAddr)) require.Len(t, txs, 1) // Ensure account has expected amount of funds @@ -549,7 +549,7 @@ func TestGaiaCLISubmitProposal(t *testing.T) { require.Equal(t, gov.OptionYes, votes[0].Option) // Ensure tags are applied to voting transaction properly - txs = f.QueryTxs(1, 50, "action:vote", fmt.Sprintf("voter:%s", fooAddr)) + txs = f.QueryTxs(1, 50, "action:vote", fmt.Sprintf("sender:%s", fooAddr)) require.Len(t, txs, 1) // Ensure no proposals in deposit period diff --git a/docs/spec/distribution/06_tags.md b/docs/spec/distribution/06_tags.md index 418d662ad8..5e0592f008 100644 --- a/docs/spec/distribution/06_tags.md +++ b/docs/spec/distribution/06_tags.md @@ -6,11 +6,11 @@ The distribution module emits the following events/tags: ### MsgSetWithdrawAddress -| Key | Value | -|-------------|---------------------------| -| `action` | `set_withdraw_address` | -| `category` | `distribution` | -| `delegator` | {delegatorAccountAddress} | +| Key | Value | +|------------|---------------------------| +| `action` | `set_withdraw_address` | +| `category` | `distribution` | +| `sender` | {delegatorAccountAddress} | ### MsgWithdrawDelegatorReward @@ -18,13 +18,13 @@ The distribution module emits the following events/tags: |--------------------|-----------------------------| | `action` | `withdraw_delegator_reward` | | `category` | `distribution` | -| `delegator` | {delegatorAccountAddress} | +| `sender` | {delegatorAccountAddress} | | `source-validator` | {srcOperatorAddress} | ### MsgWithdrawValidatorCommission -| Key | Value | -|--------------------|---------------------------------| -| `action` | `withdraw_validator_commission` | -| `category` | `distribution` | -| `source-validator` | {srcOperatorAddress} | +| Key | Value | +|------------|---------------------------------| +| `action` | `withdraw_validator_commission` | +| `category` | `distribution` | +| `sender` | {srcOperatorAddress} | diff --git a/docs/spec/governance/04_tags.md b/docs/spec/governance/04_tags.md index a803e248e3..fb547e0ee8 100644 --- a/docs/spec/governance/04_tags.md +++ b/docs/spec/governance/04_tags.md @@ -16,7 +16,7 @@ The governance module emits the following events/tags: |---------------------------|--------------------------| | `action` | `submit_proposal` | | `category` | `governance` | -| `proposer` | {proposerAccountAddress} | +| `sender` | {proposerAccountAddress} | | `proposal-id` | {proposalID} | | `voting-period-start` [0] | {proposalID} | @@ -28,7 +28,7 @@ The governance module emits the following events/tags: |---------------|-----------------------| | `action` | `vote` | | `category` | `governance` | -| `voter` | {voterAccountAddress} | +| `sender` | {voterAccountAddress} | | `proposal-id` | {proposalID} | ### MsgDeposit @@ -37,5 +37,5 @@ The governance module emits the following events/tags: |---------------|---------------------------| | `action` | `deposit` | | `category` | `governance` | -| `depositor` | {depositorAccountAddress} | +| `sender` | {depositorAccountAddress} | | `proposal-id` | {proposalID} | diff --git a/docs/spec/slashing/06_tags.md b/docs/spec/slashing/06_tags.md index cb4d74bbc1..8ba7e1db98 100644 --- a/docs/spec/slashing/06_tags.md +++ b/docs/spec/slashing/06_tags.md @@ -6,8 +6,8 @@ The slashing module emits the following events/tags: ### MsgUnjail -| Key | Value | -|-------------|----------------------------| -| `action` | `unjail` | -| `category` | `slashing` | -| `validator` | {validatorOperatorAddress} | +| Key | Value | +|------------|----------------------------| +| `action` | `unjail` | +| `category` | `slashing` | +| `sender` | {validatorOperatorAddress} | diff --git a/docs/spec/staking/06_tags.md b/docs/spec/staking/06_tags.md index 32f74364d1..bf64b9d560 100644 --- a/docs/spec/staking/06_tags.md +++ b/docs/spec/staking/06_tags.md @@ -16,19 +16,19 @@ The staking module emits the following events/tags: ### MsgCreateValidator -| Key | Value | -|-------------------------|----------------------| -| `action` | `create_validator` | -| `category` | `staking` | -| `destination-validator` | {dstOperatorAddress} | +| Key | Value | +|------------|----------------------| +| `action` | `create_validator` | +| `category` | `staking` | +| `sender` | {dstOperatorAddress} | ### MsgEditValidator -| Key | Value | -|-------------------------|----------------------| -| `action` | `edit_validator` | -| `category` | `staking` | -| `destination-validator` | {dstOperatorAddress} | +| Key | Value | +|------------|----------------------| +| `action` | `edit_validator` | +| `category` | `staking` | +| `sender` | {dstOperatorAddress} | ### MsgDelegate @@ -36,7 +36,7 @@ The staking module emits the following events/tags: |-------------------------|---------------------------| | `action` | `delegate` | | `category` | `staking` | -| `delegator` | {delegatorAccountAddress} | +| `sender` | {delegatorAccountAddress} | | `destination-validator` | {dstOperatorAddress} | ### MsgBeginRedelegate @@ -45,7 +45,7 @@ The staking module emits the following events/tags: |-------------------------|---------------------------| | `action` | `begin_redelegate` | | `category` | `staking` | -| `delegator` | {delegatorAccountAddress} | +| `sender` | {delegatorAccountAddress} | | `source-validator` | {srcOperatorAddress} | | `destination-validator` | {dstOperatorAddress} | | `end-time` [0] | {delegationFinishTime} | @@ -58,7 +58,7 @@ The staking module emits the following events/tags: |--------------------|---------------------------| | `action` | `begin_unbonding` | | `category` | `staking` | -| `delegator` | {delegatorAccountAddress} | +| `sender` | {delegatorAccountAddress} | | `source-validator` | {srcOperatorAddress} | | `end-time` [0] | {delegationFinishTime} | diff --git a/types/tags.go b/types/tags.go index aa98eddba8..c203f53ac7 100644 --- a/types/tags.go +++ b/types/tags.go @@ -72,6 +72,7 @@ func MakeTag(k string, v string) Tag { var ( TagAction = "action" TagCategory = "category" + TagSender = "sender" TagSrcValidator = "source-validator" TagDstValidator = "destination-validator" TagDelegator = "delegator" diff --git a/x/crisis/handler.go b/x/crisis/handler.go index 0f69dbc27b..6373949500 100644 --- a/x/crisis/handler.go +++ b/x/crisis/handler.go @@ -2,6 +2,7 @@ package crisis import ( sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/x/crisis/tags" ) // ModuleName is the module name for this module @@ -70,11 +71,11 @@ func handleMsgVerifyInvariant(ctx sdk.Context, msg MsgVerifyInvariant, k Keeper) panic(invarianceErr) } - tags := sdk.NewTags( - "sender", msg.Sender.String(), - "invariant", msg.InvariantRoute, + resTags := sdk.NewTags( + tags.Sender, msg.Sender.String(), + tags.Invariant, msg.InvariantRoute, ) return sdk.Result{ - Tags: tags, + Tags: resTags, } } diff --git a/x/crisis/tags/tags.go b/x/crisis/tags/tags.go new file mode 100644 index 0000000000..da3c667936 --- /dev/null +++ b/x/crisis/tags/tags.go @@ -0,0 +1,11 @@ +package tags + +import ( + sdk "github.com/cosmos/cosmos-sdk/types" +) + +// Crisis module tags +var ( + Sender = sdk.TagSender + Invariant = "invariant" +) diff --git a/x/distribution/alias.go b/x/distribution/alias.go index 616991a47a..2b4bad2db8 100644 --- a/x/distribution/alias.go +++ b/x/distribution/alias.go @@ -44,7 +44,6 @@ var ( ErrNilValidatorAddr = types.ErrNilValidatorAddr TagValidator = tags.Validator - TagDelegator = tags.Delegator NewMsgSetWithdrawAddress = types.NewMsgSetWithdrawAddress NewMsgWithdrawDelegatorReward = types.NewMsgWithdrawDelegatorReward diff --git a/x/distribution/handler.go b/x/distribution/handler.go index 782aa02773..3cb1a40c8d 100644 --- a/x/distribution/handler.go +++ b/x/distribution/handler.go @@ -34,7 +34,7 @@ func handleMsgModifyWithdrawAddress(ctx sdk.Context, msg types.MsgSetWithdrawAdd resTags := sdk.NewTags( tags.Category, tags.TxCategory, - tags.Delegator, msg.DelegatorAddress.String(), + tags.Sender, msg.DelegatorAddress.String(), ) return sdk.Result{ Tags: resTags, @@ -50,7 +50,7 @@ func handleMsgWithdrawDelegatorReward(ctx sdk.Context, msg types.MsgWithdrawDele resTags := sdk.NewTags( tags.Category, tags.TxCategory, - tags.Delegator, msg.DelegatorAddress.String(), + tags.Sender, msg.DelegatorAddress.String(), tags.Validator, msg.ValidatorAddress.String(), ) return sdk.Result{ @@ -67,7 +67,7 @@ func handleMsgWithdrawValidatorCommission(ctx sdk.Context, msg types.MsgWithdraw resTags := sdk.NewTags( tags.Category, tags.TxCategory, - tags.Validator, msg.ValidatorAddress.String(), + tags.Sender, msg.ValidatorAddress.String(), ) return sdk.Result{ Tags: resTags, diff --git a/x/distribution/tags/tags.go b/x/distribution/tags/tags.go index 5d9fc070d2..8c84cddeae 100644 --- a/x/distribution/tags/tags.go +++ b/x/distribution/tags/tags.go @@ -8,6 +8,6 @@ var ( TxCategory = "distribution" Validator = sdk.TagSrcValidator - Delegator = sdk.TagDelegator Category = sdk.TagCategory + Sender = sdk.TagSender ) diff --git a/x/gov/client/utils/query.go b/x/gov/client/utils/query.go index dadd7dd534..351c831435 100644 --- a/x/gov/client/utils/query.go +++ b/x/gov/client/utils/query.go @@ -129,7 +129,7 @@ func QueryVoteByTxQuery( tags := []string{ fmt.Sprintf("%s='%s'", tags.Action, gov.MsgVote{}.Type()), fmt.Sprintf("%s='%s'", tags.ProposalID, []byte(fmt.Sprintf("%d", params.ProposalID))), - fmt.Sprintf("%s='%s'", tags.Voter, []byte(params.Voter.String())), + fmt.Sprintf("%s='%s'", tags.Sender, []byte(params.Voter.String())), } // NOTE: SearchTxs is used to facilitate the txs query which does not currently @@ -172,7 +172,7 @@ func QueryDepositByTxQuery( tags := []string{ fmt.Sprintf("%s='%s'", tags.Action, gov.MsgDeposit{}.Type()), fmt.Sprintf("%s='%s'", tags.ProposalID, []byte(fmt.Sprintf("%d", params.ProposalID))), - fmt.Sprintf("%s='%s'", tags.Depositor, []byte(params.Depositor.String())), + fmt.Sprintf("%s='%s'", tags.Sender, []byte(params.Depositor.String())), } // NOTE: SearchTxs is used to facilitate the txs query which does not currently diff --git a/x/gov/handler.go b/x/gov/handler.go index 81592ba38e..8a60cb9ed8 100644 --- a/x/gov/handler.go +++ b/x/gov/handler.go @@ -49,7 +49,7 @@ func handleMsgSubmitProposal(ctx sdk.Context, keeper Keeper, msg MsgSubmitPropos resTags := sdk.NewTags( tags.ProposalID, proposalIDStr, tags.Category, tags.TxCategory, - tags.Proposer, msg.Proposer.String(), + tags.Sender, msg.Proposer.String(), ) if votingStarted { @@ -73,7 +73,7 @@ func handleMsgDeposit(ctx sdk.Context, keeper Keeper, msg MsgDeposit) sdk.Result resTags := sdk.NewTags( tags.ProposalID, proposalIDStr, tags.Category, tags.TxCategory, - tags.Depositor, msg.Depositor.String(), + tags.Sender, msg.Depositor.String(), ) if votingStarted { @@ -97,7 +97,7 @@ func handleMsgVote(ctx sdk.Context, keeper Keeper, msg MsgVote) sdk.Result { Tags: sdk.NewTags( tags.ProposalID, proposalIDStr, tags.Category, tags.TxCategory, - tags.Voter, msg.Voter.String(), + tags.Sender, msg.Voter.String(), ), } } diff --git a/x/gov/tags/tags.go b/x/gov/tags/tags.go index 15e94de7fb..5960c6efdd 100644 --- a/x/gov/tags/tags.go +++ b/x/gov/tags/tags.go @@ -13,10 +13,8 @@ var ( Action = sdk.TagAction Category = sdk.TagCategory - Proposer = "proposer" + Sender = sdk.TagSender ProposalID = "proposal-id" VotingPeriodStart = "voting-period-start" - Depositor = "depositor" - Voter = "voter" ProposalResult = "proposal-result" ) diff --git a/x/slashing/handler.go b/x/slashing/handler.go index 7a04829f75..7e5594c44c 100644 --- a/x/slashing/handler.go +++ b/x/slashing/handler.go @@ -62,7 +62,7 @@ func handleMsgUnjail(ctx sdk.Context, msg MsgUnjail, k Keeper) sdk.Result { tags := sdk.NewTags( tags.Category, tags.TxCategory, - tags.Validator, msg.ValidatorAddr.String(), + tags.Sender, msg.ValidatorAddr.String(), ) return sdk.Result{ diff --git a/x/slashing/tags/tags.go b/x/slashing/tags/tags.go index 328324be03..48e5bcba2f 100644 --- a/x/slashing/tags/tags.go +++ b/x/slashing/tags/tags.go @@ -8,6 +8,6 @@ import ( var ( TxCategory = "slashing" - Category = sdk.TagCategory - Validator = "validator" + Category = sdk.TagCategory + Sender = sdk.TagSender ) diff --git a/x/staking/client/rest/utils.go b/x/staking/client/rest/utils.go index a34864e604..f6d4be4932 100644 --- a/x/staking/client/rest/utils.go +++ b/x/staking/client/rest/utils.go @@ -31,7 +31,7 @@ func queryTxs(cliCtx context.CLIContext, cdc *codec.Codec, tag string, delegator limit := 100 tags := []string{ fmt.Sprintf("%s='%s'", tags.Action, tag), - fmt.Sprintf("%s='%s'", tags.Delegator, delegatorAddr), + fmt.Sprintf("%s='%s'", tags.Sender, delegatorAddr), } return tx.SearchTxs(cliCtx, cdc, tags, page, limit) diff --git a/x/staking/handler.go b/x/staking/handler.go index fd8408e27b..d51413d5cc 100644 --- a/x/staking/handler.go +++ b/x/staking/handler.go @@ -145,8 +145,8 @@ func handleMsgCreateValidator(ctx sdk.Context, msg types.MsgCreateValidator, k k resTags := sdk.NewTags( tags.Category, tags.TxCategory, + tags.Sender, msg.DelegatorAddress.String(), tags.DstValidator, msg.ValidatorAddress.String(), - tags.Delegator, msg.DelegatorAddress.String(), ) return sdk.Result{ @@ -194,7 +194,8 @@ func handleMsgEditValidator(ctx sdk.Context, msg types.MsgEditValidator, k keepe k.SetValidator(ctx, validator) resTags := sdk.NewTags( - tags.DstValidator, msg.ValidatorAddress.String(), + tags.Category, tags.TxCategory, + tags.Sender, msg.ValidatorAddress.String(), ) return sdk.Result{ @@ -219,7 +220,7 @@ func handleMsgDelegate(ctx sdk.Context, msg types.MsgDelegate, k keeper.Keeper) resTags := sdk.NewTags( tags.Category, tags.TxCategory, - tags.Delegator, msg.DelegatorAddress.String(), + tags.Sender, msg.DelegatorAddress.String(), tags.DstValidator, msg.ValidatorAddress.String(), ) @@ -244,7 +245,7 @@ func handleMsgUndelegate(ctx sdk.Context, msg types.MsgUndelegate, k keeper.Keep finishTime := types.MsgCdc.MustMarshalBinaryLengthPrefixed(completionTime) resTags := sdk.NewTags( tags.Category, tags.TxCategory, - tags.Delegator, msg.DelegatorAddress.String(), + tags.Sender, msg.DelegatorAddress.String(), tags.SrcValidator, msg.ValidatorAddress.String(), tags.EndTime, completionTime.Format(time.RFC3339), ) @@ -270,7 +271,7 @@ func handleMsgBeginRedelegate(ctx sdk.Context, msg types.MsgBeginRedelegate, k k finishTime := types.MsgCdc.MustMarshalBinaryLengthPrefixed(completionTime) resTags := sdk.NewTags( tags.Category, tags.TxCategory, - tags.Delegator, msg.DelegatorAddress.String(), + tags.Sender, msg.DelegatorAddress.String(), tags.SrcValidator, msg.ValidatorSrcAddress.String(), tags.DstValidator, msg.ValidatorDstAddress.String(), tags.EndTime, completionTime.Format(time.RFC3339), diff --git a/x/staking/tags/tags.go b/x/staking/tags/tags.go index 442a84ecf5..8468748dbb 100644 --- a/x/staking/tags/tags.go +++ b/x/staking/tags/tags.go @@ -12,6 +12,7 @@ var ( Action = sdk.TagAction Category = sdk.TagCategory + Sender = sdk.TagSender SrcValidator = sdk.TagSrcValidator DstValidator = sdk.TagDstValidator Delegator = sdk.TagDelegator