Skip to content

Commit

Permalink
Merge pull request #1507 from irisnet/release0.14
Browse files Browse the repository at this point in the history
Merge release0.14 to master
  • Loading branch information
zhangyelong authored May 31, 2019
2 parents 913b1d5 + 5aa7dfd commit 3f353ab
Show file tree
Hide file tree
Showing 15 changed files with 175 additions and 55 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
# Changelog

## 0.14.1

### LCD (REST API)
* [\#1486](https://github.com/irisnet/irishub/issues/1486) Ensure `/bank/account/{address}` has consistent json output
* [\#1495](https://github.com/irisnet/irishub/issues/1495) Improve error handling for query parameters

### Application
* [\#1506](https://github.com/irisnet/irishub/issues/1506) Enforce `unbonding_time` regardless of validator status

## 0.14.0

### LCD (REST API)
Expand Down
11 changes: 0 additions & 11 deletions app/protocol/patches.go

This file was deleted.

10 changes: 2 additions & 8 deletions client/bank/lcd/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func QueryAccountRequestHandlerFn(cdc *codec.Codec, decoder auth.AccountDecoder,

addr, err := sdk.AccAddressFromBech32(bech32addr)
if err != nil {
utils.WriteErrorResponse(w, http.StatusInternalServerError, err.Error())
utils.WriteErrorResponse(w, http.StatusBadRequest, err.Error())
return
}

Expand All @@ -50,13 +50,7 @@ func QueryAccountRequestHandlerFn(cdc *codec.Codec, decoder auth.AccountDecoder,
return
}

accountRes, err := bank.ConvertAccountCoin(cliCtx, account)
if err != nil {
utils.WriteErrorResponse(w, http.StatusInternalServerError, err.Error())
return
}

utils.PostProcessResponse(w, cdc, accountRes, cliCtx.Indent)
utils.PostProcessResponse(w, cdc, account, cliCtx.Indent)
}
}

Expand Down
4 changes: 2 additions & 2 deletions client/bank/lcd/sendtx.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ func SendRequestHandlerFn(cdc *codec.Codec, cliCtx context.CLIContext) http.Hand
}
to, err := sdk.AccAddressFromBech32(m.Recipient)
if err != nil {
w.WriteHeader(http.StatusInternalServerError)
w.Write([]byte(fmt.Sprintf("Couldn't decode delegator. Error: %s", err.Error())))
w.WriteHeader(http.StatusBadRequest)
w.Write([]byte(fmt.Sprintf("Couldn't decode address. Error: %s", err.Error())))
return
}
msg := bank.BuildBankSendMsg(sender, to, amount)
Expand Down
9 changes: 7 additions & 2 deletions client/distribution/lcd/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ import (
"net/http"

"github.com/gorilla/mux"
"github.com/irisnet/irishub/app/protocol"
"github.com/irisnet/irishub/client/context"
distrClient "github.com/irisnet/irishub/client/distribution"
"github.com/irisnet/irishub/client/utils"
"github.com/irisnet/irishub/modules/distribution"
distrClient "github.com/irisnet/irishub/client/distribution"
sdk "github.com/irisnet/irishub/types"
"github.com/irisnet/irishub/app/protocol"
)

// QueryWithdrawAddressHandlerFn performs withdraw address query
Expand Down Expand Up @@ -152,6 +152,11 @@ func QueryRewardsHandlerFn(cliCtx context.CLIContext) http.HandlerFunc {

AddrStr := vars["address"]
accAddress, err := sdk.AccAddressFromBech32(AddrStr)
if err != nil {
utils.WriteErrorResponse(w, http.StatusBadRequest, err.Error())
return
}

params := distribution.NewQueryRewardsParams(accAddress)
bz, err := cliCtx.Codec.MarshalJSON(params)
if err != nil {
Expand Down
5 changes: 5 additions & 0 deletions client/stake/lcd/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,11 @@ func queryBonds(cliCtx context.CLIContext, cdc *codec.Codec, endpoint string) ht
bech32validator := vars["validatorAddr"]

delegatorAddr, err := sdk.AccAddressFromBech32(bech32delegator)
if err != nil {
utils.WriteErrorResponse(w, http.StatusBadRequest, err.Error())
return
}

validatorAddr, err := sdk.ValAddressFromBech32(bech32validator)
if err != nil {
utils.WriteErrorResponse(w, http.StatusBadRequest, err.Error())
Expand Down
14 changes: 14 additions & 0 deletions docs/light-client/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,19 @@
# IRISLCD Change Log

## v0.14.1

*May 30th, 2019*

### BREAKING CHANGES:

- Change some api interfaces of `IRISLCD`

#### Bank module APIs

| [v0.14.0] | [v0.14.1] | input changed | output changed |
| --------------- | --------------- | --------------- | --------------- |
| GET /bank/accounts/{address} | GET /bank/accounts/{address} | No | Yes |

## v0.14.0

*May 20th, 2019*
Expand Down
4 changes: 2 additions & 2 deletions docs/software/How-to-install-irishub.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# How to install `iris`

### The Latest version of IRIShub : v0.14.0
### The Latest version of IRIShub : v0.14.1
refer to : https://github.com/irisnet/irishub/releases/latest
```
Please replace <latest_iris_version> with v0.14.0 while using "git checkout"
Please replace <latest_iris_version> with v0.14.1 while using "git checkout"
```

You can download the source code from github and compile it locally.
Expand Down
14 changes: 14 additions & 0 deletions docs/zh/light-client/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,19 @@
# IRISLCD 更新日志

## v0.14.1

*May 30th, 2019*

### 不兼容修改:

- 修改 一些IRISLCD的API接口

#### Bank 模块

| [v0.14.0] | [v0.14.1] | 输入改变 | 输出改变 |
| --------------- | --------------- | --------------- | --------------- |
| GET /bank/accounts/{address} | GET /bank/accounts/{address} | No | Yes |

## v0.14.0

*May 20th, 2019*
Expand Down
4 changes: 2 additions & 2 deletions docs/zh/software/How-to-install-irishub.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# 如何安装`iris`

### 当前IRIShub最新版本为v0.14.0
### 当前IRIShub最新版本为v0.14.1
获取最新版本 https://github.com/irisnet/irishub/releases/latest
```
注意:使用 git checkout 命令时,请将 <latest_iris_version> 替换成 v0.14.0
注意:使用 git checkout 命令时,请将 <latest_iris_version> 替换成 v0.14.1
```

### 源码编译安装
Expand Down
9 changes: 7 additions & 2 deletions lite/swagger-ui/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ info:
description: >-
A REST interface for state queries, transaction generation, signing, and
broadcast.
version: "0.14.0"
version: "0.14.1"
title: IRISLCD Swagger-UI
termsOfService: 'https://www.irisnet.org'
contact:
Expand Down Expand Up @@ -546,7 +546,12 @@ paths:
items:
$ref: '#/components/schemas/Coin'
public_key:
type: string
type: object
properties:
type:
type: string
value:
type: string
sequence:
type: string
'204':
Expand Down
67 changes: 60 additions & 7 deletions modules/stake/handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ import (
"testing"
"time"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

sdk "github.com/irisnet/irishub/types"
keep "github.com/irisnet/irishub/modules/stake/keeper"
"github.com/irisnet/irishub/modules/stake/types"
sdk "github.com/irisnet/irishub/types"
"github.com/irisnet/irishub/version"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
abci "github.com/tendermint/tendermint/abci/types"
"github.com/tendermint/tendermint/crypto/secp256k1"
tmtypes "github.com/tendermint/tendermint/types"
Expand Down Expand Up @@ -722,9 +722,62 @@ func TestUnbondingFromUnbondingValidator(t *testing.T) {
// Run the EndBlocker
EndBlocker(ctx, keeper)

// unbond the validators bond portion
msgBeginUnbondingValidator := NewMsgBeginUnbonding(sdk.AccAddress(validatorAddr), validatorAddr, sdk.NewDecFromInt(sdk.NewIntWithDecimal(10, 18)))
got = handleMsgBeginUnbonding(ctx, msgBeginUnbondingValidator, keeper)
// validate the unbonding object does not exist as it was never created
_, found := keeper.GetUnbondingDelegation(ctx, delegatorAddr, validatorAddr)
require.False(t, found, "unbonding object should not exist")

// reproduce same sequence except past fork height
ctx, _, keeper = keep.CreateTestInput(t, false, sdk.NewInt(1000))
validatorAddr, delegatorAddr = sdk.ValAddress(keep.Addrs[0]), keep.Addrs[1]
ctx = ctx.WithBlockHeight(version.H001_UNDELEGATE_PATCH)

// create the validator
msgCreateValidator = NewTestMsgCreateValidator(validatorAddr, keep.PKs[0], sdk.NewInt(10))
got = handleMsgCreateValidator(ctx, msgCreateValidator, keeper)
require.True(t, got.IsOK(), "expected no error on runMsgCreateValidator")

// bond a delegator
msgDelegate = NewTestMsgDelegate(delegatorAddr, validatorAddr, sdk.NewInt(10))
got = handleMsgDelegate(ctx, msgDelegate, keeper)
require.True(t, got.IsOK(), "expected ok, got %v", got)

// unbond the delegator from the validator
msgUndelegateDelegator := NewMsgBeginUnbonding(delegatorAddr, validatorAddr, sdk.NewDec(10))
got = handleMsgBeginUnbonding(ctx, msgUndelegateDelegator, keeper)
require.True(t, got.IsOK(), "expected no error")

EndBlocker(ctx, keeper)

// validate the unbonding object exists prior to the unbonding period expiring
_, found = keeper.GetUnbondingDelegation(ctx, delegatorAddr, validatorAddr)
require.True(t, found, "unbonding object should exist")

// move to past unbonding period
ctx = ctx.WithBlockTime(ctx.BlockHeader().Time.Add(keeper.UnbondingTime(ctx)))
EndBlocker(ctx, keeper)

// validate the unbonding object no longer exists as the unbonding period has expired
_, found = keeper.GetUnbondingDelegation(ctx, delegatorAddr, validatorAddr)
require.False(t, found, "unbonding object should not exist")
}

func TestUnbondingFork(t *testing.T) {
ctx, _, keeper := keep.CreateTestInput(t, false, sdk.NewInt(1000))
validatorAddr, delegatorAddr := sdk.ValAddress(keep.Addrs[0]), keep.Addrs[1]

// create the validator
msgCreateValidator := NewTestMsgCreateValidator(validatorAddr, keep.PKs[0], sdk.NewInt(10))
got := handleMsgCreateValidator(ctx, msgCreateValidator, keeper)
require.True(t, got.IsOK(), "expected no error on runMsgCreateValidator")

// bond a delegator
msgDelegate := NewTestMsgDelegate(delegatorAddr, validatorAddr, sdk.NewInt(10))
got = handleMsgDelegate(ctx, msgDelegate, keeper)
require.True(t, got.IsOK(), "expected ok, got %v", got)

// unbond the delegator from the validator
msgUndelegateDelegator := NewMsgBeginUnbonding(delegatorAddr, validatorAddr, sdk.NewDec(10))
got = handleMsgBeginUnbonding(ctx, msgUndelegateDelegator, keeper)
require.True(t, got.IsOK(), "expected no error")

// Run the EndBlocker
Expand Down
58 changes: 40 additions & 18 deletions modules/stake/keeper/delegation.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ import (
"bytes"
"time"

sdk "github.com/irisnet/irishub/types"
"github.com/irisnet/irishub/modules/stake/types"
sdk "github.com/irisnet/irishub/types"
"github.com/irisnet/irishub/version"
)

// return a specific delegation
Expand Down Expand Up @@ -526,7 +527,41 @@ func (k Keeper) BeginUnbonding(ctx sdk.Context,
}

// create the unbonding delegation
minTime, height, completeNow := k.getBeginInfo(ctx, valAddr)
if ctx.BlockHeight() < version.H001_UNDELEGATE_PATCH {
minTime, height, completeNow := k.getBeginInfo(ctx, valAddr)

returnAmount, err := k.unbond(ctx, delAddr, valAddr, sharesAmount)
if err != nil {
return types.UnbondingDelegation{}, err
}

rounded := returnAmount.TruncateInt()
balance := sdk.NewCoin(k.BondDenom(), rounded)

// no need to create the ubd object just complete now
if completeNow {
if !balance.IsZero() {
ctx.CoinFlowTags().AppendCoinFlowTag(ctx, valAddr.String(), delAddr.String(), balance.String(), sdk.UndelegationFlow, ctx.CoinFlowTrigger())
}
_, _, err := k.bankKeeper.AddCoins(ctx, delAddr, sdk.Coins{balance})
if err != nil {
return types.UnbondingDelegation{}, err
}
return types.UnbondingDelegation{MinTime: minTime, Balance: balance}, nil
}
ubd := types.UnbondingDelegation{
TxHash: ctx.CoinFlowTrigger(), //tx hash
DelegatorAddr: delAddr,
ValidatorAddr: valAddr,
CreationHeight: height,
MinTime: minTime,
Balance: balance,
InitialBalance: balance,
}
k.SetUnbondingDelegation(ctx, ubd)
k.InsertUnbondingQueue(ctx, ubd)
return ubd, nil
}

returnAmount, err := k.unbond(ctx, delAddr, valAddr, sharesAmount)
if err != nil {
Expand All @@ -535,31 +570,18 @@ func (k Keeper) BeginUnbonding(ctx sdk.Context,

rounded := returnAmount.TruncateInt()
balance := sdk.NewCoin(k.BondDenom(), rounded)

// no need to create the ubd object just complete now
if completeNow {
if !balance.IsZero() {
ctx.CoinFlowTags().AppendCoinFlowTag(ctx, valAddr.String(), delAddr.String(), balance.String(), sdk.UndelegationFlow, ctx.CoinFlowTrigger())
}
_, _, err := k.bankKeeper.AddCoins(ctx, delAddr, sdk.Coins{balance})
if err != nil {
return types.UnbondingDelegation{}, err
}
return types.UnbondingDelegation{MinTime: minTime, Balance: balance}, nil
}

completionTime := ctx.BlockHeader().Time.Add(k.UnbondingTime(ctx))
ubd := types.UnbondingDelegation{
TxHash: ctx.CoinFlowTrigger(), //tx hash
DelegatorAddr: delAddr,
ValidatorAddr: valAddr,
CreationHeight: height,
MinTime: minTime,
CreationHeight: ctx.BlockHeight(),
MinTime: completionTime,
Balance: balance,
InitialBalance: balance,
}
k.SetUnbondingDelegation(ctx, ubd)
k.InsertUnbondingQueue(ctx, ubd)

return ubd, nil
}

Expand Down
10 changes: 10 additions & 0 deletions version/patches.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package version

/*
For each patch (a.k.a. class3 upgrade), define the corresponding height
at which the software switches to the patched logic
*/
const (
// 001: 0 - protocol version, 01 - patch number for protocol v0
H001_UNDELEGATE_PATCH = 1159800
)
2 changes: 1 addition & 1 deletion version/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (

// Version - Iris Version
const ProtocolVersion = 0
const Version = "0.14.0"
const Version = "0.14.1"
// GitCommit set by build flags
var GitCommit = ""

Expand Down

0 comments on commit 3f353ab

Please sign in to comment.