Skip to content

Commit

Permalink
Merge pull request #95 from irisnet/irisnet/hotfix-v0.23.0-iris2
Browse files Browse the repository at this point in the history
merge Irisnet/hotfix v0.23.0 iris2 into master
  • Loading branch information
wukongcheng authored Aug 31, 2018
2 parents c69a00d + cc085aa commit bd1cb52
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
11 changes: 11 additions & 0 deletions x/stake/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"github.com/cosmos/cosmos-sdk/x/stake/tags"
"github.com/cosmos/cosmos-sdk/x/stake/types"
abci "github.com/tendermint/tendermint/abci/types"
"math"
)

func NewHandler(k keeper.Keeper) sdk.Handler {
Expand Down Expand Up @@ -76,6 +77,16 @@ func handleMsgCreateValidator(ctx sdk.Context, msg types.MsgCreateValidator, k k
return ErrBadDenom(k.Codespace()).Result()
}

precisionNumber := math.Pow10(int(k.GetParams(ctx).DenomPrecision))
if precisionNumber > math.MaxInt64 {
panic("precision is too high, int64 is overflow")
}
tokenPrecision := int64(precisionNumber)
equivalentPower := msg.Delegation.Amount.Div(sdk.NewInt(tokenPrecision))
if equivalentPower.Equal(sdk.NewInt(0)) {
return sdk.ErrInsufficientCoins("delegate token amount for new created validator is too small, voting power is zero, this validator creation doesn't make sense").Result()
}

validator := NewValidator(msg.ValidatorAddr, msg.PubKey, msg.Description)
validator.TokenPrecision = k.GetParams(ctx).DenomPrecision
k.SetValidator(ctx, validator)
Expand Down
11 changes: 11 additions & 0 deletions x/stake/keeper/slash.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
sdk "github.com/cosmos/cosmos-sdk/types"
types "github.com/cosmos/cosmos-sdk/x/stake/types"
"github.com/tendermint/tendermint/crypto"
"math"
)

// Slash a validator for an infraction committed at a known height
Expand Down Expand Up @@ -33,6 +34,16 @@ func (k Keeper) Slash(ctx sdk.Context, pubkey crypto.PubKey, infractionHeight in
// ref https://github.com/cosmos/cosmos-sdk/issues/1471

validator, found := k.GetValidatorByPubKey(ctx, pubkey)

//////////////////// iris/cosmos-sdk begin ///////////////////////////
precisionNumber := math.Pow10(int(validator.TokenPrecision))
if precisionNumber > math.MaxInt64 {
panic(fmt.Errorf("precision is too high, int64 is overflow"))
}
tokenPrecision := sdk.NewInt(int64(precisionNumber))
slashAmount = slashAmount.Mul(sdk.NewRatFromInt(tokenPrecision))
//////////////////// iris/cosmos-sdk end ///////////////////////////

if !found {
// If not found, the validator must have been overslashed and removed - so we don't need to do anything
// NOTE: Correctness dependent on invariant that unbonding delegations / redelegations must also have been completely
Expand Down

0 comments on commit bd1cb52

Please sign in to comment.