Skip to content

Commit

Permalink
Merge PR: (TESTNET)add sanity check (#217)
Browse files Browse the repository at this point in the history
* FIX: add sanity check

* OPTIMIZE: expression of annotation
  • Loading branch information
RevelationOfTuring authored Jun 18, 2020
1 parent f665e0b commit ce89d3c
Show file tree
Hide file tree
Showing 10 changed files with 39 additions and 24 deletions.
2 changes: 1 addition & 1 deletion app/app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ func TestExportAppStateAndValidators_abci_postEndBlocker(t *testing.T) {
_, _, _ = app.ExportAppStateAndValidators(true, jailWhiteList)
})

// situation 4 : validator in the jail white list is not existed in the skakingKeeper
// situation 4 : validator in the jail white list doesn't exist in the stakingKeeper
jailWhiteList = []string{"okchainvaloper1qryc3z7jxlk7ma56qcaz75ksely65havrmtufv"}
require.Panics(t, func() {
_, _, _ = app.ExportAppStateAndValidators(true, jailWhiteList)
Expand Down
8 changes: 5 additions & 3 deletions x/dex/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,10 @@ func (k Keeper) GetUserTokenPairs(ctx sdk.Context, owner sdk.AccAddress) (tokenP
key := iter.Key()
tokenPairName := string(key[prefixLen:])

tokenPairs = append(tokenPairs, k.GetTokenPairFromStore(ctx, tokenPairName))
tokenPair := k.GetTokenPairFromStore(ctx, tokenPairName)
if tokenPair != nil {
tokenPairs = append(tokenPairs, tokenPair)
}
}

return tokenPairs
Expand Down Expand Up @@ -236,8 +239,7 @@ func (k Keeper) UpdateTokenPair(ctx sdk.Context, product string, tokenPair *type
func (k Keeper) CheckTokenPairUnderDexDelist(ctx sdk.Context, product string) (isDelisting bool, err error) {
tp := k.GetTokenPair(ctx, product)
if tp != nil {
isDelisting = k.GetTokenPair(ctx, product).Delisting
err = nil
isDelisting = tp.Delisting
} else {
isDelisting = true
err = errors.Errorf("product %s doesn't exist", product)
Expand Down
12 changes: 9 additions & 3 deletions x/dex/keeper/proposal.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,12 @@ func (k Keeper) RejectedHandler(ctx sdk.Context, content govTypes.Content) {
tokenPairName := fmt.Sprintf("%s_%s", content.BaseAsset, content.QuoteAsset)
//update the token info from the store
tokenPair := k.GetTokenPair(ctx, tokenPairName)
if nil != tokenPair {
tokenPair.Delisting = false
k.UpdateTokenPair(ctx, tokenPairName, tokenPair)
if tokenPair == nil {
ctx.Logger().Error(fmt.Sprintf("token pair %s does not exist", tokenPairName))
return
}
tokenPair.Delisting = false
k.UpdateTokenPair(ctx, tokenPairName, tokenPair)
}
}

Expand All @@ -111,6 +113,10 @@ func (k Keeper) AfterDepositPeriodPassed(ctx sdk.Context, proposal govTypes.Prop
tokenPairName := fmt.Sprintf("%s_%s", content.BaseAsset, content.QuoteAsset)
// change the status of the token pair in the store
tokenPair := k.GetTokenPair(ctx, tokenPairName)
if tokenPair == nil {
ctx.Logger().Error(fmt.Sprintf("token pair %s does not exist", tokenPairName))
return
}
tokenPair.Delisting = true
k.UpdateTokenPair(ctx, tokenPairName, tokenPair)
}
Expand Down
13 changes: 10 additions & 3 deletions x/order/keeper/keeper.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package keeper

import (
"fmt"
"log"
"sync"

Expand Down Expand Up @@ -386,9 +387,12 @@ func (k Keeper) GetCoins(ctx sdk.Context, addr sdk.AccAddress) sdk.DecCoins {
}

// GetProductOwner gets the OwnerAddress of specified product from dexKeeper
func (k Keeper) GetProductOwner(ctx sdk.Context, product string) sdk.AccAddress {
func (k Keeper) GetProductOwner(ctx sdk.Context, product string) (sdk.AccAddress, error) {
tokenPair := k.GetDexKeeper().GetTokenPair(ctx, product)
return tokenPair.Owner
if tokenPair == nil {
return sdk.AccAddress{}, fmt.Errorf("failed. token pair %s doesn't exist", product)
}
return tokenPair.Owner, nil
}

// AddFeeDetail adds detail message of fee to tokenKeeper
Expand All @@ -406,7 +410,10 @@ func (k Keeper) SendFeesToProductOwner(ctx sdk.Context, coins sdk.DecCoins, from
if coins.IsZero() {
return nil
}
to := k.GetProductOwner(ctx, product)
to, err := k.GetProductOwner(ctx, product)
if err != nil {
return err
}
k.tokenKeeper.AddFeeDetail(ctx, from.String(), coins, feeType)
if err := k.tokenKeeper.SendCoinsFromAccountToAccount(ctx, from, to, coins); err != nil {
log.Printf("Send fee(%s) to address(%s) failed\n", coins.String(), to.String())
Expand Down
4 changes: 2 additions & 2 deletions x/staking/handler_vote.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ func handleMsgVote(ctx sdk.Context, msg types.MsgVote, k keeper.Keeper) sdk.Resu
delegator.ProxyAddress.String()).Result()
}

// 1. get last validators voted existed in the store
// 1. get last validators voted existing in the store
lastVals, lastVotes := k.GetLastValsVotedExisted(ctx, msg.DelAddr)

// 2. withdraw the votes last time
Expand Down Expand Up @@ -302,7 +302,7 @@ func handleMsgUndelegate(ctx sdk.Context, msg types.MsgUndelegate, k keeper.Keep

func handleMsgDestroyValidator(ctx sdk.Context, msg types.MsgDestroyValidator, k keeper.Keeper) (result sdk.Result) {
valAddr := sdk.ValAddress(msg.DelAddr)
// 0.check to see if the validator which belongs to the delegator is existed
// 0.check to see if the validator which belongs to the delegator exists
validator, found := k.GetValidator(ctx, valAddr)
if !found {
return ErrNoValidatorFound(types.DefaultCodespace, valAddr.String()).Result()
Expand Down
2 changes: 1 addition & 1 deletion x/staking/keeper/invariants.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func RegisterInvariantsCustom(ir sdk.InvariantRegistry, k Keeper) {
}

// DelegatorVotesInvariant checks whether all the votes which persist
// in the store add up to the correct total votes amount stored in each existed validator
// in the store add up to the correct total votes amount stored in each existing validator
//TODO:if the self-votes based on msd is related with time-calculating, this DelegatorVotesInvariant will not pass
// because we can't calculate the votes number base on msd of a validator afterwards
func DelegatorVotesInvariant(k Keeper) sdk.Invariant {
Expand Down
2 changes: 1 addition & 1 deletion x/staking/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ func (k Keeper) IsValidator(ctx sdk.Context, addr sdk.AccAddress) bool {
}

// GetOperAddrFromValidatorAddr returns the validator address according to the consensus pubkey
// the validator has to be existed
// the validator has to exist
func (k Keeper) GetOperAddrFromValidatorAddr(ctx sdk.Context, va string) (sdk.ValAddress, bool) {
validators := k.GetAllValidators(ctx)

Expand Down
4 changes: 2 additions & 2 deletions x/staking/keeper/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func (k Keeper) IterateProxy(ctx sdk.Context, proxyAddr sdk.AccAddress, isClear

// UpdateVotes withdraws and votes continuously on the same validator set with different amount of votes
func (k Keeper) UpdateVotes(ctx sdk.Context, delAddr sdk.AccAddress, tokens sdk.Dec) sdk.Error {
// get last validators voted existed in the store
// get last validators voted existing in the store
vals, lastVotes := k.GetLastValsVotedExisted(ctx, delAddr)
if vals == nil {
// if the delegator never votes, just pass
Expand Down Expand Up @@ -157,7 +157,7 @@ func (k Keeper) GetLastValsVotedExisted(ctx sdk.Context, voterAddr sdk.AccAddres
return nil, sdk.ZeroDec()
}

// 2.get validators voted existed in the store
// 2.get validators voted existing in the store
lenVals := len(delegator.ValidatorAddresses)
var vals types.Validators
for i := 0; i < lenVals; i++ {
Expand Down
14 changes: 7 additions & 7 deletions x/staking/types/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func ErrBadValidatorAddr(codespace sdk.CodespaceType) sdk.Error {
return sdk.NewError(codespace, CodeInvalidAddress, "validator address is invalid")
}

// ErrNoValidatorFound returns an error when a validator isn't existed
// ErrNoValidatorFound returns an error when a validator doesn't exist
func ErrNoValidatorFound(codespace sdk.CodespaceType, valAddr string) sdk.Error {
return sdk.NewError(codespace, CodeInvalidValidator, "validator %s does not exist", valAddr)
}
Expand Down Expand Up @@ -129,7 +129,7 @@ func ErrInsufficientShares(codespace sdk.CodespaceType) sdk.Error {
return sdk.NewError(codespace, CodeInvalidDelegation, "insufficient delegation shares")
}

// ErrNoUnbondingDelegation returns an error when the unbonding delegation isn't existed
// ErrNoUnbondingDelegation returns an error when the unbonding delegation doesn't exist
func ErrNoUnbondingDelegation(codespace sdk.CodespaceType) sdk.Error {
return sdk.NewError(codespace, CodeInvalidDelegation, "no unbonding delegation found")
}
Expand Down Expand Up @@ -177,7 +177,7 @@ func ErrDoubleProxy(codespace sdk.CodespaceType, delegator string) sdk.Error {
"failed. proxy isn't allowed to bind with other proxy %s", delegator)
}

// ErrNotFoundProxy returns an error when the proxy is not existed
// ErrNotFoundProxy returns an error when the proxy doesn't exist
func ErrNotFoundProxy(codespace sdk.CodespaceType, delegator string) sdk.Error {
return sdk.NewError(codespace, CodeInvalidDelegation,
"failed. no proxy with %s", delegator)
Expand Down Expand Up @@ -207,7 +207,7 @@ func ErrNoDelegationVote(codespace sdk.CodespaceType, voter string) sdk.Error {
"failed. there's no delegation of %s", voter)
}

// ErrNotInDelegating returns an error when the UndelegationInfo was not existed during it's unbonding period
// ErrNotInDelegating returns an error when the UndelegationInfo doesn't exist during it's unbonding period
func ErrNotInDelegating(codespace sdk.CodespaceType, addr string) sdk.Error {
return sdk.NewError(codespace, CodeInvalidDelegation,
"failed. the addr %s is not in the status of undelegating", addr)
Expand Down Expand Up @@ -249,16 +249,16 @@ func ErrInvalidProxyUpdating(codespace sdk.CodespaceType) sdk.Error {
"failed. the total delegated tokens on the proxy will be negative after this update")
}

// ErrAlreadyVoted returns an error when a delegator trys to bind proxy after voting
// ErrAlreadyVoted returns an error when a delegator tries to bind proxy after voting
func ErrAlreadyVoted(codespace sdk.CodespaceType, delAddr string) sdk.Error {
return sdk.NewError(codespace, CodeInvalidProxy,
"failed. delegator %s isn't allowed to bind proxy while it has voted. please unbond the delegation first", delAddr)
}

// ErrNoDelegatorExisted returns an error when the info if a certain delegator isn't existed
// ErrNoDelegatorExisted returns an error when the info if a certain delegator doesn't exist
func ErrNoDelegatorExisted(codespace sdk.CodespaceType, delAddr string) sdk.Error {
return sdk.NewError(codespace, CodeInvalidDelegation,
"failed. delegator %s isn't existed", delAddr)
"failed. delegator %s doesn't exist", delAddr)
}

// ErrTargetValsDuplicate returns an error when the target validators in voting list are duplicate
Expand Down
2 changes: 1 addition & 1 deletion x/upgrade/keeper/keeper_deprecated.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
func (k Keeper) SetAppUpgradeConfig(ctx sdk.Context, proposalID, version, upgradeHeight uint64, software string,
) sdk.Error {
if _, found := k.GetAppUpgradeConfig(ctx); found {
return sdk.ErrInternal("failed. an app upgrade config is existed, only one entry is permitted")
return sdk.ErrInternal("failed. an app upgrade config has existed, only one entry is permitted")
}

appUpgradeConfig := proto.NewAppUpgradeConfig(
Expand Down

0 comments on commit ce89d3c

Please sign in to comment.