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

v0.37.8-RC1 Cherry Picks #5777

Merged
merged 7 commits into from
Mar 11, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,21 @@ Ref: https://keepachangelog.com/en/1.0.0/

## [Unreleased]

## [v0.37.78] - TBD

### Bug Fixes

* (rest) [\#5508](https://github.com/cosmos/cosmos-sdk/pull/5508) Fix `x/distribution` endpoints to properly return height in the response.
* (x/genutil) [\#5499](https://github.com/cosmos/cosmos-sdk/pull/) Ensure `DefaultGenesis` returns valid and non-nil default genesis state.
* (x/genutil) [\#5775](https://github.com/cosmos/cosmos-sdk/pull/5775) Fix `ExportGenesis` in `x/genutil` to export default genesis state (`[]`) instead of `null`.
* (genesis) [\#5086](https://github.com/cosmos/cosmos-sdk/issues/5086) Ensure `gentxs` are always an empty array instead of `nil`.

### Improvements

* (rest) [\#5648](https://github.com/cosmos/cosmos-sdk/pull/5648) Enhance /txs usability:
* Add `tx.minheight` key to filter transaction with an inclusive minimum block height
* Add `tx.maxheight` key to filter transaction with an inclusive maximum block height

## [v0.37.7] - 2020-02-10

### Improvements
Expand Down Expand Up @@ -2619,7 +2634,8 @@ BUG FIXES:

<!-- Release links -->

[Unreleased]: https://github.com/cosmos/cosmos-sdk/compare/v0.37.7...HEAD
[Unreleased]: https://github.com/cosmos/cosmos-sdk/compare/v0.37.8...HEAD
[v0.37.8]: https://github.com/cosmos/cosmos-sdk/releases/tag/v0.37.8
[v0.37.7]: https://github.com/cosmos/cosmos-sdk/releases/tag/v0.37.7
[v0.37.6]: https://github.com/cosmos/cosmos-sdk/releases/tag/v0.37.6
[v0.37.5]: https://github.com/cosmos/cosmos-sdk/releases/tag/v0.37.5
Expand Down
10 changes: 10 additions & 0 deletions client/lcd/swagger-ui/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,16 @@ paths:
description: Maximum number of items per page
type: integer
x-example: 1
- in: query
name: tx.minheight
type: integer
description: "transactions on blocks with height greater or equal this value"
x-example: 25
- in: query
name: tx.maxheight
type: integer
description: "transactions on blocks with height less than or equal this value"
x-example: 800000
responses:
200:
description: All txs matching the provided events
Expand Down
6 changes: 6 additions & 0 deletions types/rest/rest.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ import (
const (
DefaultPage = 1
DefaultLimit = 30 // should be consistent with tendermint/tendermint/rpc/core/pipe.go:19
TxMinHeightKey = "tx.minheight" // Inclusive minimum height filter
TxMaxHeightKey = "tx.maxheight" // Inclusive maximum height filter
)

// ResponseWithHeight defines a response object type that wraps an original
Expand Down Expand Up @@ -337,6 +339,10 @@ func ParseHTTPArgsWithLimit(r *http.Request, defaultLimit int) (tags []string, p
var tag string
if key == types.TxHeightKey {
tag = fmt.Sprintf("%s=%s", key, value)
} else if key == TxMinHeightKey {
tag = fmt.Sprintf("%s>=%s", types.TxHeightKey, value)
} else if key == TxMaxHeightKey {
tag = fmt.Sprintf("%s<=%s", types.TxHeightKey, value)
} else {
tag = fmt.Sprintf("%s='%s'", key, value)
}
Expand Down
7 changes: 7 additions & 0 deletions types/rest/rest_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"io/ioutil"
"net/http"
"net/http/httptest"
"sort"
"testing"

"github.com/stretchr/testify/require"
Expand Down Expand Up @@ -72,6 +73,8 @@ func TestParseHTTPArgs(t *testing.T) {
reqE2 := mustNewRequest(t, "", "/?limit=-1", nil)
req4 := mustNewRequest(t, "", "/?foo=faa", nil)

reqTxH := mustNewRequest(t, "", "/?tx.minheight=12&tx.maxheight=14", nil)

tests := []struct {
name string
req *http.Request
Expand All @@ -90,10 +93,14 @@ func TestParseHTTPArgs(t *testing.T) {
{"error limit 0", reqE2, httptest.NewRecorder(), []string{}, DefaultPage, DefaultLimit, true},

{"tags", req4, httptest.NewRecorder(), []string{"foo='faa'"}, DefaultPage, DefaultLimit, false},
{"tags", reqTxH, httptest.NewRecorder(), []string{"tx.height<=14", "tx.height>=12"}, DefaultPage, DefaultLimit, false},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
tags, page, limit, err := ParseHTTPArgs(tt.req)

sort.Strings(tags)

if tt.err {
require.NotNil(t, err)
} else {
Expand Down
7 changes: 4 additions & 3 deletions x/auth/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package auth

import (
"encoding/json"
"fmt"

"github.com/gorilla/mux"
"github.com/spf13/cobra"
Expand Down Expand Up @@ -42,10 +43,10 @@ func (AppModuleBasic) DefaultGenesis() json.RawMessage {
// module validate genesis
func (AppModuleBasic) ValidateGenesis(bz json.RawMessage) error {
var data types.GenesisState
err := types.ModuleCdc.UnmarshalJSON(bz, &data)
if err != nil {
return err
if err := types.ModuleCdc.UnmarshalJSON(bz, &data); err != nil {
return fmt.Errorf("failed to unmarshal %s genesis state: %w", types.ModuleName, err)
}

return types.ValidateGenesis(data)
}

Expand Down
8 changes: 4 additions & 4 deletions x/bank/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ package bank

import (
"encoding/json"
"fmt"

"github.com/gorilla/mux"
"github.com/spf13/cobra"

abci "github.com/tendermint/tendermint/abci/types"

"github.com/cosmos/cosmos-sdk/client/context"
Expand Down Expand Up @@ -40,10 +40,10 @@ func (AppModuleBasic) DefaultGenesis() json.RawMessage {
// module validate genesis
func (AppModuleBasic) ValidateGenesis(bz json.RawMessage) error {
var data GenesisState
err := ModuleCdc.UnmarshalJSON(bz, &data)
if err != nil {
return err
if err := ModuleCdc.UnmarshalJSON(bz, &data); err != nil {
return fmt.Errorf("failed to unmarshal %s genesis state: %w", ModuleName, err)
}

return ValidateGenesis(data)
}

Expand Down
4 changes: 3 additions & 1 deletion x/crisis/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package crisis

import (
"encoding/json"
"fmt"

"github.com/gorilla/mux"
"github.com/spf13/cobra"
Expand Down Expand Up @@ -45,8 +46,9 @@ func (AppModuleBasic) DefaultGenesis() json.RawMessage {
func (AppModuleBasic) ValidateGenesis(bz json.RawMessage) error {
var data types.GenesisState
if err := types.ModuleCdc.UnmarshalJSON(bz, &data); err != nil {
return err
return fmt.Errorf("failed to unmarshal %s genesis state: %w", ModuleName, err)
}

return types.ValidateGenesis(data)
}

Expand Down
28 changes: 23 additions & 5 deletions x/distribution/client/cli/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -208,26 +208,44 @@ $ %s query distr rewards cosmos1gghjut3ccd8ay0zduzj64hwre2fxs9ld75ru9p cosmosval
RunE: func(cmd *cobra.Command, args []string) error {
cliCtx := context.NewCLIContext().WithCodec(cdc)

// query for rewards from a particular delegation
if len(args) == 2 {
// query for rewards from a particular delegation
resp, err := common.QueryDelegationRewards(cliCtx, queryRoute, args[0], args[1])
resp, _, err := common.QueryDelegationRewards(cliCtx, queryRoute, args[0], args[1])
if err != nil {
return err
}

var result sdk.DecCoins
cdc.MustUnmarshalJSON(resp, &result)
if err = cdc.UnmarshalJSON(resp, &result); err != nil {
return fmt.Errorf("failed to unmarshal response: %w", err)
}

return cliCtx.PrintOutput(result)
}

delegatorAddr, err := sdk.AccAddressFromBech32(args[0])
if err != nil {
return err
}

params := types.NewQueryDelegatorParams(delegatorAddr)
bz, err := cdc.MarshalJSON(params)
if err != nil {
return fmt.Errorf("failed to marshal params: %w", err)
}

// query for delegator total rewards
resp, err := common.QueryDelegatorTotalRewards(cliCtx, queryRoute, args[0])
route := fmt.Sprintf("custom/%s/%s", queryRoute, types.QueryDelegatorTotalRewards)
res, _, err := cliCtx.QueryWithData(route, bz)
if err != nil {
return err
}

var result types.QueryDelegatorTotalRewardsResponse
cdc.MustUnmarshalJSON(resp, &result)
if err = cdc.UnmarshalJSON(res, &result); err != nil {
return fmt.Errorf("failed to unmarshal response: %w", err)
}

return cliCtx.PrintOutput(result)
},
}
Expand Down
32 changes: 11 additions & 21 deletions x/distribution/client/common/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,37 +40,27 @@ func QueryParams(cliCtx context.CLIContext, queryRoute string) (PrettyParams, er
), nil
}

// QueryDelegatorTotalRewards queries delegator total rewards.
func QueryDelegatorTotalRewards(cliCtx context.CLIContext, queryRoute, delAddr string) ([]byte, error) {
// QueryDelegationRewards queries a delegation rewards between a delegator and a
// validator.
func QueryDelegationRewards(cliCtx context.CLIContext, queryRoute, delAddr, valAddr string) ([]byte, int64, error) {
delegatorAddr, err := sdk.AccAddressFromBech32(delAddr)
if err != nil {
return nil, err
return nil, 0, err
}

res, _, err := cliCtx.QueryWithData(
fmt.Sprintf("custom/%s/%s", queryRoute, types.QueryDelegatorTotalRewards),
cliCtx.Codec.MustMarshalJSON(types.NewQueryDelegatorParams(delegatorAddr)),
)
return res, err
}

// QueryDelegationRewards queries a delegation rewards.
func QueryDelegationRewards(cliCtx context.CLIContext, queryRoute, delAddr, valAddr string) ([]byte, error) {
delegatorAddr, err := sdk.AccAddressFromBech32(delAddr)
validatorAddr, err := sdk.ValAddressFromBech32(valAddr)
if err != nil {
return nil, err
return nil, 0, err
}

validatorAddr, err := sdk.ValAddressFromBech32(valAddr)
params := types.NewQueryDelegationRewardsParams(delegatorAddr, validatorAddr)
bz, err := cliCtx.Codec.MarshalJSON(params)
if err != nil {
return nil, err
return nil, 0, fmt.Errorf("failed to marshal params: %w", err)
}

res, _, err := cliCtx.QueryWithData(
fmt.Sprintf("custom/%s/%s", queryRoute, types.QueryDelegationRewards),
cliCtx.Codec.MustMarshalJSON(types.NewQueryDelegationRewardsParams(delegatorAddr, validatorAddr)),
)
return res, err
route := fmt.Sprintf("custom/%s/%s", queryRoute, types.QueryDelegationRewards)
return cliCtx.QueryWithData(route, bz)
}

// QueryDelegatorValidators returns delegator's list of validators
Expand Down
2 changes: 1 addition & 1 deletion x/distribution/client/common/common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func TestQueryDelegationRewardsAddrValidation(t *testing.T) {
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
_, err := QueryDelegationRewards(ctx, "", tt.args.delAddr, tt.args.valAddr)
_, _, err := QueryDelegationRewards(ctx, "", tt.args.delAddr, tt.args.valAddr)
require.True(t, err != nil, tt.wantErr)
})
}
Expand Down
Loading