Skip to content

Commit

Permalink
Merge pull request #1356 from irisnet/release0.13
Browse files Browse the repository at this point in the history
R4R: release version v0.13.0-rc0
  • Loading branch information
HaoyangLiu authored Mar 13, 2019
2 parents 6a0c96d + 5c70b32 commit 313b745
Show file tree
Hide file tree
Showing 33 changed files with 226 additions and 65 deletions.
15 changes: 15 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,20 @@
# Changelog

## 0.13.0-rc0

*March 13th, 2019*

- [iris] fix unexpect coin flow if tx is out of gas
- [iris] Improve error message for insufficient balance
- [iris] Add pagination params for lcd validators query
- [iris] Check the validator existence and validator status before getting its pubkey
- [iris] Reset the init value for metrics

- [tendermint] Fix consensus round issue
- [tendermint] Fix the bug of update the LRU cache
- [tendermint] Add maximum msg size in CheckTx


## 0.12.3

*February 27th, 2019*
Expand Down
6 changes: 3 additions & 3 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Gopkg.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
[[override]]
name = "github.com/tendermint/tendermint"
source = "https://github.com/irisnet/tendermint.git"
version = "=v0.27.3-iris7"
version = "=v0.27.3-iris8"

[[constraint]]
name = "github.com/emicklei/proto"
Expand Down
2 changes: 1 addition & 1 deletion app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ func NewIrisApp(logger log.Logger, db dbm.DB, config *cfg.InstrumentationConfig,
cmn.Exit(fmt.Sprintf("Your software doesn't support the required protocol (version %d)!", current))
}
app.BaseApp.txDecoder = auth.DefaultTxDecoder(engine.GetCurrentProtocol().GetCodec())

engine.GetCurrentProtocol().InitMetrics(app.cms)
return app
}

Expand Down
4 changes: 1 addition & 3 deletions app/baseapp.go
Original file line number Diff line number Diff line change
Expand Up @@ -736,7 +736,7 @@ func (app *BaseApp) runTx(mode RunTxMode, txBytes []byte, tx sdk.Tx) (result sdk
result = sdk.ErrInternal(log).Result()
}
}

ctx.CoinFlowTags().TagClean()
result.GasWanted = gasWanted
result.GasUsed = ctx.GasMeter().GasConsumed()
}()
Expand Down Expand Up @@ -836,8 +836,6 @@ func (app *BaseApp) runTx(mode RunTxMode, txBytes []byte, tx sdk.Tx) (result sdk
if result.IsOK() {
msCache.Write()
ctx.CoinFlowTags().TagWrite()
} else {
ctx.CoinFlowTags().TagClean()
}

return
Expand Down
1 change: 1 addition & 0 deletions app/protocol/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,5 @@ type Protocol interface {
Load()
Init()
GetCodec() *codec.Codec
InitMetrics(store sdk.CommitMultiStore) // init metrics
}
5 changes: 5 additions & 0 deletions app/v0/protocol_v0.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,11 @@ func (p *ProtocolV0) GetCodec() *codec.Codec {
return p.cdc
}

func (p *ProtocolV0) InitMetrics(store sdk.CommitMultiStore){
p.StakeKeeper.InitMetrics(store.GetKVStore(protocol.KeyStake))
p.serviceKeeper.InitMetrics(store.GetKVStore(protocol.KeyService))
}

func (p *ProtocolV0) configCodec() {
p.cdc = MakeCodec()
}
Expand Down
21 changes: 20 additions & 1 deletion client/stake/lcd/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,26 @@ func delegatorValidatorHandlerFn(cliCtx context.CLIContext, cdc *codec.Codec) ht
// HTTP request handler to query list of validators
func validatorsHandlerFn(cliCtx context.CLIContext, cdc *codec.Codec) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
res, err := cliCtx.QueryWithData("custom/stake/validators", nil)
err := r.ParseForm()
if err != nil {
utils.WriteErrorResponse(w, http.StatusBadRequest, sdk.AppendMsgToErr("could not parse query parameters", err.Error()))
return
}
pageStr := r.FormValue("page")
sizeStr := r.FormValue("size")
params, err := ConvertPaginationParams(pageStr, sizeStr)
if err != nil {
utils.WriteErrorResponse(w, http.StatusBadRequest, err.Error())
return
}

bz, err := cdc.MarshalJSON(params)
if err != nil {
utils.WriteErrorResponse(w, http.StatusBadRequest, err.Error())
return
}

res, err := cliCtx.QueryWithData("custom/stake/validators", bz)
if err != nil {
utils.WriteErrorResponse(w, http.StatusInternalServerError, err.Error())
return
Expand Down
23 changes: 23 additions & 0 deletions client/stake/lcd/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package lcd
import (
"fmt"
"net/http"
"strconv"

"github.com/gorilla/mux"
"github.com/irisnet/irishub/client/context"
Expand Down Expand Up @@ -315,3 +316,25 @@ func queryValidator(cliCtx context.CLIContext, cdc *codec.Codec, endpoint string
utils.PostProcessResponse(w, cdc, res, cliCtx.Indent)
}
}

func ConvertPaginationParams(pageString, sizeString string) (paginationParams sdk.PaginationParams, err error) {
page := uint64(0)
size := uint16(100)
if pageString != "" {
page, err = strconv.ParseUint(pageString, 10, 64)
if err != nil {
err = fmt.Errorf("page '%s' is not a valid uint64", pageString)
return paginationParams, err
}
}
if sizeString != "" {
sizeUint64, err := strconv.ParseUint(sizeString, 10, 16)
if err != nil {
err = fmt.Errorf("size '%s' is not a valid uint16", sizeString)
return paginationParams, err
}
size = uint16(sizeUint64)
}
paginationParams = sdk.NewPaginationParams(page, size)
return paginationParams, err
}
2 changes: 1 addition & 1 deletion client/tendermint/tx/searchtx.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func SearchTxCmd(cdc *codec.Codec) *cobra.Command {
Long: strings.TrimSpace(`
Search for transactions that match exactly the given tags. For example:
$ iriscli query txs --tags '<tag1>:<value1>&<tag2>:<value2>'
$ iriscli tendermint txs --tags '<tag1>:<value1>&<tag2>:<value2>'
`),
RunE: func(cmd *cobra.Command, args []string) error {
tagsStr := viper.GetString(flagTags)
Expand Down
2 changes: 1 addition & 1 deletion docs/cli-client/tendermint/txs.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ iriscli tendermint txs [flags]
### Search transactions

```shell
iriscli tendermint txs --tags `action=send&sender=iaa1c6al0vufl8efggzsvw34hszua9pr4qqymthxjw` --chain-id=<chain-id> --trust-node=true
iriscli tendermint txs --tags `action:send&sender:iaa1c6al0vufl8efggzsvw34hszua9pr4qqymthxjw` --chain-id=<chain-id> --trust-node=true
```

You will get the following result.
Expand Down
2 changes: 1 addition & 1 deletion docs/zh/cli-client/tendermint/txs.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ iriscli tendermint txs [flags]
### 查询交易

```shell
iriscli tendermint txs --tags `action=send&sender=iaa1c6al0vufl8efggzsvw34hszua9pr4qqymthxjw` --chain-id=<chain-id> --trust-node=true
iriscli tendermint txs --tags `action:send&sender:iaa1c6al0vufl8efggzsvw34hszua9pr4qqymthxjw` --chain-id=<chain-id> --trust-node=true
```

示例结果
Expand Down
13 changes: 12 additions & 1 deletion lite/swagger-ui/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1415,9 +1415,20 @@ paths:
description: Internal Server Error
/stake/validators:
get:
summary: Get all validator candidates
summary: Get validators
tags:
- ICS21
parameters:
- in: query
name: page
description: 'Pagination page, default value 1'
schema:
type: integer
- in: query
name: size
description: 'Pagination size, default value 100'
schema:
type: integer
responses:
'200':
description: OK
Expand Down
2 changes: 1 addition & 1 deletion modules/auth/ante.go
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ func deductFees(acc Account, fee StdFee) (Account, sdk.Result) {
}
newCoins, ok := coins.SafeMinus(feeAmount)
if ok {
errMsg := fmt.Sprintf("%s is less than %s", coins, feeAmount)
errMsg := fmt.Sprintf("account balance (%s) is less than %s", coins, feeAmount)
return nil, sdk.ErrInsufficientFunds(errMsg).Result()
}
err := acc.SetCoins(newCoins)
Expand Down
6 changes: 2 additions & 4 deletions modules/distribution/keeper/allocation.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,7 @@ func (k Keeper) AllocateTokens(ctx sdk.Context, percentVotes sdk.Dec, proposer s
communityFunding := feesCollectedDec.MulDec(communityTax)
feePool.CommunityPool = feePool.CommunityPool.Plus(communityFunding)

tokenPrecision := sdk.NewIntWithDecimal(1, 18)
communityTaxAmount, err := strconv.ParseFloat(feePool.CommunityPool.AmountOf(sdk.NativeTokenMinDenom).QuoInt(tokenPrecision).String(), 64)
communityTaxAmount, err := strconv.ParseFloat(feePool.CommunityPool.AmountOf(sdk.NativeTokenMinDenom).QuoInt(sdk.AttoPrecision).String(), 64)
if err == nil {
k.metrics.CommunityTax.Set(communityTaxAmount)
}
Expand All @@ -93,8 +92,7 @@ func (k Keeper) AllocateFeeTax(ctx sdk.Context, destAddr sdk.AccAddress, percent
allocateCoins, _ := communityPool.MulDec(percent).TruncateDecimal()
feePool.CommunityPool = communityPool.Minus(types.NewDecCoins(allocateCoins))

tokenPrecision := sdk.NewIntWithDecimal(1, 18)
communityTaxAmount, err := strconv.ParseFloat(feePool.CommunityPool.AmountOf(sdk.NativeTokenMinDenom).QuoInt(tokenPrecision).String(), 64)
communityTaxAmount, err := strconv.ParseFloat(feePool.CommunityPool.AmountOf(sdk.NativeTokenMinDenom).QuoInt(sdk.AttoPrecision).String(), 64)
if err == nil {
k.metrics.CommunityTax.Set(communityTaxAmount)
}
Expand Down
13 changes: 13 additions & 0 deletions modules/service/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,11 @@ func (k Keeper) ActiveRequestQueueIterator(ctx sdk.Context, height int64) sdk.It
return sdk.KVStorePrefixIterator(store, GetRequestsByExpirationPrefix(height))
}

// Returns an iterator for all the request in the Active Queue
func (k Keeper) ActiveAllRequestQueueIterator(store sdk.KVStore) sdk.Iterator {
return sdk.KVStorePrefixIterator(store, activeRequestKey)
}

//__________________________________________________________________________

func (k Keeper) AddResponse(ctx sdk.Context, resp SvcResponse) {
Expand Down Expand Up @@ -557,3 +562,11 @@ func (k Keeper) getMinDeposit(ctx sdk.Context, prices []sdk.Coin) (sdk.Coins, sd
}
return minDeposit, nil
}

func (k Keeper) InitMetrics(store sdk.KVStore) {
activeIterator := k.ActiveAllRequestQueueIterator(store)
defer activeIterator.Close()
for ; activeIterator.Valid(); activeIterator.Next() {
k.metrics.ActiveRequests.Add(1)
}
}
2 changes: 1 addition & 1 deletion modules/service/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ func validateArbitrationTimeLimit(v time.Duration) sdk.Error {
return sdk.NewError(params.DefaultCodespace, params.CodeInvalidArbitrationTimeLimit, fmt.Sprintf("Invalid ArbitrationTimeLimit [%s] should be between [5days, 10days]", v.String()))
}
} else if v < 20*time.Second {
return sdk.NewError(params.DefaultCodespace, params.CodeComplaintRetrospect, fmt.Sprintf("Invalid ComplaintRetrospect [%s] should be between [20seconds, )", v.String()))
return sdk.NewError(params.DefaultCodespace, params.CodeInvalidArbitrationTimeLimit, fmt.Sprintf("Invalid ArbitrationTimeLimit [%s] should be between [20seconds, )", v.String()))
}
return nil
}
Expand Down
18 changes: 10 additions & 8 deletions modules/slashing/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,20 +42,22 @@ func (k Keeper) handleDoubleSign(ctx sdk.Context, addr crypto.Address, infractio
time := ctx.BlockHeader().Time
age := ctx.BlockHeight() - infractionHeight
consAddr := sdk.ConsAddress(addr)
pubkey, err := k.getPubkey(ctx, addr)
if err != nil {
panic(fmt.Sprintf("Validator consensus-address %v not found", consAddr))
}

// Get validator.
// To resolve https://github.com/irisnet/irishub/issues/1334
// Unbonding period is calculated by time however evidence age is calculated by height.
// It is possible that the unbonding period is completed, but evidence is still valid
// If a validator is removed once unbonding period is completed, then its pubkey will be deleted, which will result in panic and consensus halt
// So here we check the validator existence and validator status first
validator := k.validatorSet.ValidatorByConsAddr(ctx, consAddr)
if validator == nil || validator.GetStatus() == sdk.Unbonded {
// Defensive.
// Simulation doesn't take unbonding periods into account, and
// Tendermint might break this assumption at some point.
return
}

pubkey, err := k.getPubkey(ctx, addr)
if err != nil {
panic(fmt.Sprintf("Validator consensus-address %v not found", consAddr))
}

// Double sign too old
maxEvidenceAge := k.MaxEvidenceAge(ctx)
if age > maxEvidenceAge {
Expand Down
4 changes: 2 additions & 2 deletions modules/stake/handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -492,7 +492,7 @@ func TestMultipleMsgCreateValidator(t *testing.T) {
require.True(t, got.IsOK(), "expected msg %d to be ok, got %v", i, got)

//Check that the account is bonded
validators := keeper.GetValidators(ctx, 100)
validators := keeper.GetValidators(ctx, 0,100)
require.Equal(t, (i + 1), len(validators))
val := validators[i]
balanceExpd := initBond.Sub(sdk.NewIntWithDecimal(10, 18))
Expand All @@ -516,7 +516,7 @@ func TestMultipleMsgCreateValidator(t *testing.T) {
EndBlocker(ctx, keeper)

// Check that the validator is deleted from state
validators := keeper.GetValidators(ctx, 100)
validators := keeper.GetValidators(ctx, 0,100)
require.Equal(t, len(validatorAddrs)-(i+1), len(validators),
"expected %d validators got %d", len(validatorAddrs)-(i+1), len(validators))

Expand Down
5 changes: 2 additions & 3 deletions modules/stake/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,13 +158,12 @@ func (k Keeper) BondDenom() string {
}

func (k Keeper) UpdateMetrics(ctx sdk.Context) {
tokenPrecision := sdk.NewIntWithDecimal(1, 18)
burnedToken, err := strconv.ParseFloat(sdk.NewDecFromInt(k.bankKeeper.GetBurnedCoins(ctx).AmountOf(types.StakeDenom)).QuoInt(tokenPrecision).String(), 64)
burnedToken, err := strconv.ParseFloat(sdk.NewDecFromInt(k.bankKeeper.GetBurnedCoins(ctx).AmountOf(types.StakeDenom)).QuoInt(sdk.AttoPrecision).String(), 64)
if err == nil {
k.metrics.BurnedToken.Set(burnedToken)
}

loosenToken, err := strconv.ParseFloat(sdk.NewDecFromInt(k.bankKeeper.GetLoosenCoins(ctx).AmountOf(types.StakeDenom)).QuoInt(tokenPrecision).String(), 64)
loosenToken, err := strconv.ParseFloat(sdk.NewDecFromInt(k.bankKeeper.GetLoosenCoins(ctx).AmountOf(types.StakeDenom)).QuoInt(sdk.AttoPrecision).String(), 64)
if err == nil {
k.metrics.LoosenToken.Set(loosenToken)
}
Expand Down
6 changes: 2 additions & 4 deletions modules/stake/keeper/slash.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,7 @@ func (k Keeper) Slash(ctx sdk.Context, consAddr sdk.ConsAddress, infractionHeigh
// ref https://github.com/irisnet/irishub/issues/1348
// ref https://github.com/irisnet/irishub/issues/1471
//Multiply 1*10^18 to calculate equivalent stake denom amount
tokenPrecision := sdk.NewIntWithDecimal(1, 18)
slashAmount = slashAmount.MulInt(tokenPrecision).TruncateDec()
slashAmount = slashAmount.MulInt(sdk.AttoPrecision).TruncateDec()

validator, found := k.GetValidatorByConsAddr(ctx, consAddr)
if !found {
Expand Down Expand Up @@ -122,7 +121,7 @@ func (k Keeper) Slash(ctx sdk.Context, consAddr sdk.ConsAddress, infractionHeigh
panic("slash decimal token in redelegation")
}
k.bankKeeper.DecreaseLoosenToken(ctx, sdk.Coins{sdk.NewCoin(types.StakeDenom, tokensToBurn.TruncateInt())})
slashToken, err := strconv.ParseFloat(tokensToBurn.QuoInt(tokenPrecision).String(), 64)
slashToken, err := strconv.ParseFloat(tokensToBurn.QuoInt(sdk.AttoPrecision).String(), 64)
if err == nil {
k.metrics.SlashedToken.With("validator_address", validator.GetConsAddr().String()).Add(slashToken)
}
Expand All @@ -137,7 +136,6 @@ func (k Keeper) Slash(ctx sdk.Context, consAddr sdk.ConsAddress, infractionHeigh
func (k Keeper) Jail(ctx sdk.Context, consAddr sdk.ConsAddress) {
validator := k.mustGetValidatorByConsAddr(ctx, consAddr)
k.jailValidator(ctx, validator)
k.metrics.Jailed.With("validator_address", validator.GetConsAddr().String()).Set(1)
// TODO Return event(s), blocked on https://github.com/tendermint/tendermint/pull/1803
return
}
Expand Down
1 change: 1 addition & 0 deletions modules/stake/keeper/val_state_change.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ func (k Keeper) jailValidator(ctx sdk.Context, validator types.Validator) {
if validator.Jailed {
panic(fmt.Sprintf("cannot jail already jailed validator, validator: %v\n", validator))
}
k.metrics.Jailed.With("validator_address", validator.GetConsAddr().String()).Set(1)
ctx.Logger().Info("Validator jailed", "consensus_address", validator.ConsAddress().String(), "operator_address", validator.OperatorAddr.String())
pool := k.GetPool(ctx)
validator.Jailed = true
Expand Down
Loading

0 comments on commit 313b745

Please sign in to comment.