Skip to content

Commit

Permalink
Merge PR cosmos#4266: Release v0.34.4 (RC1)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexanderbez authored May 4, 2019
1 parent 1127446 commit 62fa99e
Show file tree
Hide file tree
Showing 17 changed files with 115 additions and 78 deletions.
25 changes: 25 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,30 @@
# Changelog

## 0.34.4

### Bug Fixes

#### SDK

* [#4234](https://github.com/cosmos/cosmos-sdk/pull/4234) Allow `tx send --generate-only` to
actually work offline.

#### Gaia

* [\#4219](https://github.com/cosmos/cosmos-sdk/issues/4219) Return an error when an empty mnemonic is provided during key recovery.

### Improvements

#### Gaia

* [\#2007](https://github.com/cosmos/cosmos-sdk/issues/2007) Return 200 status code on empty results

### New features

#### SDK

* [\#3850](https://github.com/cosmos/cosmos-sdk/issues/3850) Add `rewards` and `commission` to distribution tx tags.

## 0.34.3

### Bug Fixes
Expand Down
17 changes: 5 additions & 12 deletions client/keys/add.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package keys

import (
"bytes"
"errors"
"fmt"
"os"
"sort"
Expand All @@ -11,8 +12,6 @@ import (
"github.com/cosmos/cosmos-sdk/crypto/keys"
sdk "github.com/cosmos/cosmos-sdk/types"

"errors"

"github.com/spf13/cobra"
"github.com/spf13/viper"

Expand All @@ -34,11 +33,6 @@ const (
flagNoSort = "nosort"
)

const (
maxValidAccountValue = int(0x80000000 - 1)
maxValidIndexalue = int(0x80000000 - 1)
)

func addKeyCommand() *cobra.Command {
cmd := &cobra.Command{
Use: "add <name>",
Expand Down Expand Up @@ -201,6 +195,10 @@ func runAddCmd(_ *cobra.Command, args []string) error {
if err != nil {
return err
}

if !bip39.IsMnemonicValid(mnemonic) {
return errors.New("invalid mnemonic")
}
}

if len(mnemonic) == 0 {
Expand All @@ -216,11 +214,6 @@ func runAddCmd(_ *cobra.Command, args []string) error {
}
}

if !bip39.IsMnemonicValid(mnemonic) {
fmt.Fprintf(os.Stderr, "Error: Mnemonic is not valid.\n")
return nil
}

// override bip39 passphrase
if interactive {
bip39Passphrase, err = client.GetString(
Expand Down
25 changes: 24 additions & 1 deletion client/lcd/lcd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ func TestCoinSend(t *testing.T) {

// query empty
res, body := Request(t, port, "GET", fmt.Sprintf("/auth/accounts/%s", someFakeAddr), nil)
require.Equal(t, http.StatusNoContent, res.StatusCode, body)
require.Equal(t, http.StatusOK, res.StatusCode, body)

acc := getAccount(t, port, addr)
initialBalance := acc.GetCoins()
Expand Down Expand Up @@ -1045,3 +1045,26 @@ func TestMintingQueries(t *testing.T) {
var annualProvisions sdk.Dec
require.NoError(t, cdc.UnmarshalJSON([]byte(body), &annualProvisions))
}

func TestAccountBalanceQuery(t *testing.T) {
kb, err := keys.NewKeyBaseFromDir(InitClientHome(t, ""))
require.NoError(t, err)
addr, _ := CreateAddr(t, name1, pw, kb)
cleanup, _, _, port := InitializeTestLCD(t, 1, []sdk.AccAddress{addr}, true)
defer cleanup()

bz, err := hex.DecodeString("8FA6AB57AD6870F6B5B2E57735F38F2F30E73CB6")
require.NoError(t, err)
someFakeAddr := sdk.AccAddress(bz)

// empty account
res, body := Request(t, port, "GET", fmt.Sprintf("/auth/accounts/%s", someFakeAddr), nil)
require.Equal(t, http.StatusOK, res.StatusCode, body)
require.Contains(t, body, `"type":"auth/Account"`)

// empty account balance
res, body = Request(t, port, "GET", fmt.Sprintf("/bank/balances/%s", someFakeAddr), nil)
require.Equal(t, http.StatusOK, res.StatusCode, body)
require.Contains(t, body, "[]")

}
4 changes: 2 additions & 2 deletions cmd/gaia/app/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,14 +84,14 @@ func (app *GaiaApp) prepForZeroHeightGenesis(ctx sdk.Context, jailWhiteList []st

// withdraw all validator commission
app.stakingKeeper.IterateValidators(ctx, func(_ int64, val sdk.Validator) (stop bool) {
_ = app.distrKeeper.WithdrawValidatorCommission(ctx, val.GetOperator())
_, _ = app.distrKeeper.WithdrawValidatorCommission(ctx, val.GetOperator())
return false
})

// withdraw all delegator rewards
dels := app.stakingKeeper.GetAllDelegations(ctx)
for _, delegation := range dels {
_ = app.distrKeeper.WithdrawDelegationRewards(ctx, delegation.DelegatorAddress, delegation.ValidatorAddress)
_, _ = app.distrKeeper.WithdrawDelegationRewards(ctx, delegation.DelegatorAddress, delegation.ValidatorAddress)
}

// clear validator slash events
Expand Down
6 changes: 5 additions & 1 deletion cmd/gaia/cli_test/cli_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,11 @@ func TestGaiaCLIKeysAddRecover(t *testing.T) {
t.Parallel()
f := InitFixtures(t)

f.KeysAddRecover("test-recover", "dentist task convince chimney quality leave banana trade firm crawl eternal easily")
exitSuccess, _, _ := f.KeysAddRecover("empty-mnemonic", "")
require.False(t, exitSuccess)

exitSuccess, _, _ = f.KeysAddRecover("test-recover", "dentist task convince chimney quality leave banana trade firm crawl eternal easily")
require.True(t, exitSuccess)
require.Equal(t, "cosmos1qcfdf69js922qrdr4yaww3ax7gjml6pdds46f4", f.KeyAddress("test-recover").String())
}

Expand Down
4 changes: 2 additions & 2 deletions cmd/gaia/cli_test/test_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -249,9 +249,9 @@ func (f *Fixtures) KeysAdd(name string, flags ...string) {
}

// KeysAddRecover prepares gaiacli keys add --recover
func (f *Fixtures) KeysAddRecover(name, mnemonic string, flags ...string) {
func (f *Fixtures) KeysAddRecover(name, mnemonic string, flags ...string) (exitSuccess bool, stdout, stderr string) {
cmd := fmt.Sprintf("../../../build/gaiacli keys add --home=%s --recover %s", f.GCLIHome, name)
executeWriteCheckErr(f.T, addFlags(cmd, flags), app.DefaultKeyPass, mnemonic)
return executeWriteRetStdStreams(f.T, addFlags(cmd, flags), app.DefaultKeyPass, mnemonic)
}

// KeysAddRecoverHDPath prepares gaiacli keys add --recover --account --index
Expand Down
14 changes: 5 additions & 9 deletions docs/spec/distribution/06_tags.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,20 @@ The distribution module emits the following events/tags:
### MsgSetWithdrawAddress

| Key | Value |
|-----------|---------------------------|
| delegator | {delegatorAccountAddress} |

### MsgWithdrawDelegatorRewardsAll

| Key | Value |
|-----------|---------------------------|
| --------- | ------------------------- |
| delegator | {delegatorAccountAddress} |

### MsgWithdrawDelegatorReward

| Key | Value |
|------------------|---------------------------|
| ---------------- | ------------------------- |
| rewards | {rewards} |
| delegator | {delegatorAccountAddress} |
| source-validator | {srcOperatorAddress} |

### MsgWithdrawValidatorRewardsAll

| Key | Value |
|------------------|----------------------|
| ---------------- | -------------------- |
| commission | {commission} |
| source-validator | {srcOperatorAddress} |
6 changes: 3 additions & 3 deletions x/auth/client/rest/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@ func QueryAccountRequestHandlerFn(
return
}

// the query will return empty if there is no data for this account
// the query will return empty account if there is no data
if len(res) == 0 {
w.WriteHeader(http.StatusNoContent)
rest.PostProcessResponse(w, cdc, auth.BaseAccount{}, cliCtx.Indent)
return
}

Expand Down Expand Up @@ -88,7 +88,7 @@ func QueryBalancesRequestHandlerFn(

// the query will return empty if there is no data for this account
if len(res) == 0 {
w.WriteHeader(http.StatusNoContent)
rest.PostProcessResponse(w, cdc, sdk.Coins{}, cliCtx.Indent)
return
}

Expand Down
4 changes: 0 additions & 4 deletions x/bank/client/cli/sendtx.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,6 @@ func SendTxCmd(cdc *codec.Codec) *cobra.Command {
WithCodec(cdc).
WithAccountDecoder(cdc)

if err := cliCtx.EnsureAccountExists(); err != nil {
return err
}

to, err := sdk.AccAddressFromBech32(args[0])
if err != nil {
return err
Expand Down
24 changes: 11 additions & 13 deletions x/distribution/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,32 +41,30 @@ func handleMsgModifyWithdrawAddress(ctx sdk.Context, msg types.MsgSetWithdrawAdd
}

func handleMsgWithdrawDelegatorReward(ctx sdk.Context, msg types.MsgWithdrawDelegatorReward, k keeper.Keeper) sdk.Result {

err := k.WithdrawDelegationRewards(ctx, msg.DelegatorAddress, msg.ValidatorAddress)
rewards, err := k.WithdrawDelegationRewards(ctx, msg.DelegatorAddress, msg.ValidatorAddress)
if err != nil {
return err.Result()
}

tags := sdk.NewTags(
tags.Delegator, []byte(msg.DelegatorAddress.String()),
tags.Validator, []byte(msg.ValidatorAddress.String()),
)
return sdk.Result{
Tags: tags,
Tags: sdk.NewTags(
tags.Rewards, rewards.String(),
tags.Delegator, []byte(msg.DelegatorAddress.String()),
tags.Validator, []byte(msg.ValidatorAddress.String()),
),
}
}

func handleMsgWithdrawValidatorCommission(ctx sdk.Context, msg types.MsgWithdrawValidatorCommission, k keeper.Keeper) sdk.Result {

err := k.WithdrawValidatorCommission(ctx, msg.ValidatorAddress)
commission, err := k.WithdrawValidatorCommission(ctx, msg.ValidatorAddress)
if err != nil {
return err.Result()
}

tags := sdk.NewTags(
tags.Validator, []byte(msg.ValidatorAddress.String()),
)
return sdk.Result{
Tags: tags,
Tags: sdk.NewTags(
tags.Commission, commission.String(),
tags.Validator, []byte(msg.ValidatorAddress.String()),
),
}
}
9 changes: 4 additions & 5 deletions x/distribution/keeper/delegation.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,11 +115,10 @@ func (k Keeper) calculateDelegationRewards(ctx sdk.Context, val sdk.Validator, d
return rewards
}

func (k Keeper) withdrawDelegationRewards(ctx sdk.Context, val sdk.Validator, del sdk.Delegation) sdk.Error {

func (k Keeper) withdrawDelegationRewards(ctx sdk.Context, val sdk.Validator, del sdk.Delegation) (sdk.Coins, sdk.Error) {
// check existence of delegator starting info
if !k.HasDelegatorStartingInfo(ctx, del.GetValidatorAddr(), del.GetDelegatorAddr()) {
return types.ErrNoDelegationDistInfo(k.codespace)
return nil, types.ErrNoDelegationDistInfo(k.codespace)
}

// end current period and calculate rewards
Expand Down Expand Up @@ -154,12 +153,12 @@ func (k Keeper) withdrawDelegationRewards(ctx sdk.Context, val sdk.Validator, de
if !coins.IsZero() {
withdrawAddr := k.GetDelegatorWithdrawAddr(ctx, del.GetDelegatorAddr())
if _, _, err := k.bankKeeper.AddCoins(ctx, withdrawAddr, coins); err != nil {
return err
return nil, err
}
}

// remove delegator starting info
k.DeleteDelegatorStartingInfo(ctx, del.GetValidatorAddr(), del.GetDelegatorAddr())

return nil
return coins, nil
}
6 changes: 4 additions & 2 deletions x/distribution/keeper/delegation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,8 @@ func TestWithdrawDelegationRewardsBasic(t *testing.T) {
require.Equal(t, uint64(2), k.GetValidatorHistoricalReferenceCount(ctx))

// withdraw rewards
require.Nil(t, k.WithdrawDelegationRewards(ctx, sdk.AccAddress(valOpAddr1), valOpAddr1))
_, err := k.WithdrawDelegationRewards(ctx, sdk.AccAddress(valOpAddr1), valOpAddr1)
require.Nil(t, err)

// historical count should still be 2 (added one record, cleared one)
require.Equal(t, uint64(2), k.GetValidatorHistoricalReferenceCount(ctx))
Expand All @@ -316,7 +317,8 @@ func TestWithdrawDelegationRewardsBasic(t *testing.T) {
)

// withdraw commission
require.Nil(t, k.WithdrawValidatorCommission(ctx, valOpAddr1))
_, err = k.WithdrawValidatorCommission(ctx, valOpAddr1)
require.Nil(t, err)

// assert correct balance
exp = balanceTokens.Sub(valTokens).Add(initial)
Expand Down
2 changes: 1 addition & 1 deletion x/distribution/keeper/hooks.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ func (h Hooks) BeforeDelegationSharesModified(ctx sdk.Context, delAddr sdk.AccAd
del := h.k.stakingKeeper.Delegation(ctx, delAddr, valAddr)

// withdraw delegation rewards (which also increments period)
if err := h.k.withdrawDelegationRewards(ctx, val, del); err != nil {
if _, err := h.k.withdrawDelegationRewards(ctx, val, del); err != nil {
panic(err)
}
}
Expand Down
4 changes: 2 additions & 2 deletions x/distribution/keeper/invariants.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,12 @@ func CanWithdrawInvariant(k Keeper, sk types.StakingKeeper) sdk.Invariant {

// iterate over all validators
sk.IterateValidators(ctx, func(_ int64, val sdk.Validator) (stop bool) {
_ = k.WithdrawValidatorCommission(ctx, val.GetOperator())
_, _ = k.WithdrawValidatorCommission(ctx, val.GetOperator())

delegationAddrs, ok := valDelegationAddrs[val.GetOperator().String()]
if ok {
for _, delAddr := range delegationAddrs {
if err := k.WithdrawDelegationRewards(ctx, delAddr, val.GetOperator()); err != nil {
if _, err := k.WithdrawDelegationRewards(ctx, delAddr, val.GetOperator()); err != nil {
panic(err)
}
}
Expand Down
22 changes: 11 additions & 11 deletions x/distribution/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,35 +47,35 @@ func (k Keeper) SetWithdrawAddr(ctx sdk.Context, delegatorAddr sdk.AccAddress, w
}

// withdraw rewards from a delegation
func (k Keeper) WithdrawDelegationRewards(ctx sdk.Context, delAddr sdk.AccAddress, valAddr sdk.ValAddress) sdk.Error {
func (k Keeper) WithdrawDelegationRewards(ctx sdk.Context, delAddr sdk.AccAddress, valAddr sdk.ValAddress) (sdk.Coins, sdk.Error) {
val := k.stakingKeeper.Validator(ctx, valAddr)
if val == nil {
return types.ErrNoValidatorDistInfo(k.codespace)
return nil, types.ErrNoValidatorDistInfo(k.codespace)
}

del := k.stakingKeeper.Delegation(ctx, delAddr, valAddr)
if del == nil {
return types.ErrNoDelegationDistInfo(k.codespace)
return nil, types.ErrNoDelegationDistInfo(k.codespace)
}

// withdraw rewards
if err := k.withdrawDelegationRewards(ctx, val, del); err != nil {
return err
rewards, err := k.withdrawDelegationRewards(ctx, val, del)
if err != nil {
return nil, err
}

// reinitialize the delegation
k.initializeDelegation(ctx, valAddr, delAddr)

return nil
return rewards, nil
}

// withdraw validator commission
func (k Keeper) WithdrawValidatorCommission(ctx sdk.Context, valAddr sdk.ValAddress) sdk.Error {

func (k Keeper) WithdrawValidatorCommission(ctx sdk.Context, valAddr sdk.ValAddress) (sdk.Coins, sdk.Error) {
// fetch validator accumulated commission
commission := k.GetValidatorAccumulatedCommission(ctx, valAddr)
if commission.IsZero() {
return types.ErrNoValidatorCommission(k.codespace)
return nil, types.ErrNoValidatorCommission(k.codespace)
}

coins, remainder := commission.TruncateDecimal()
Expand All @@ -90,9 +90,9 @@ func (k Keeper) WithdrawValidatorCommission(ctx sdk.Context, valAddr sdk.ValAddr
withdrawAddr := k.GetDelegatorWithdrawAddr(ctx, accAddr)

if _, _, err := k.bankKeeper.AddCoins(ctx, withdrawAddr, coins); err != nil {
return err
return nil, err
}
}

return nil
return coins, nil
}
Loading

0 comments on commit 62fa99e

Please sign in to comment.