Small fixes on staking log and error (#2158)

* Small fixes on staking log and error

* Fix lint
pull/2223/head
Rongjian Lan 5 years ago committed by GitHub
parent dce008c19e
commit 4c9ec7329e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 13
      core/state_transition.go
  2. 8
      staking/types/validator.go

@ -39,8 +39,8 @@ var (
errValidatorExist = errors.New("staking validator already exists")
errValidatorNotExist = errors.New("staking validator does not exist")
errNoDelegationToUndelegate = errors.New("no delegation to undelegate")
errCommissionRateChangeTooFast = errors.New("commission rate can not be changed more than MaxChangeRate within the same epoch")
errCommissionRateChangeTooHigh = errors.New("commission rate can not be higher than MaxCommissionRate")
errCommissionRateChangeTooFast = errors.New("change on commission rate can not be more than max change rate within the same epoch")
errCommissionRateChangeTooHigh = errors.New("commission rate can not be higher than maximum commission rate")
errNoRewardsToCollect = errors.New("no rewards to collect")
errNegativeAmount = errors.New("amount can not be negative")
)
@ -491,11 +491,16 @@ func (st *StateTransition) applyDelegateTx(delegate *staking.Delegate) error {
delegation.Amount.Add(delegation.Amount, delegate.Amount)
err := stateDB.UpdateStakingInfo(wrapper.Validator.Address, wrapper)
if err != nil {
return err
}
// Secondly, if all locked token are used, try use the balance.
if err == nil && delegateBalance.Cmp(big.NewInt(0)) > 0 {
if delegateBalance.Cmp(big.NewInt(0)) > 0 {
stateDB.SubBalance(delegate.DelegatorAddress, delegateBalance)
return nil
}
return err
// This shouldn't really happen
return errInsufficientBalanceForStake
}
return errors.Wrapf(
errInsufficientBalanceForStake,

@ -34,7 +34,7 @@ var (
errMinSelfDelegationTooSmall = errors.New("min_self_delegation has to be greater than 1 ONE")
errInvalidMaxTotalDelegation = errors.New("max_total_delegation can not be less than min_self_delegation")
errCommissionRateTooLarge = errors.New("commission rate and change rate can not be larger than max commission rate")
errInvalidComissionRate = errors.New("commission rate, change rate and max rate should be within 0-100 percent")
errInvalidCommissionRate = errors.New("commission rate, change rate and max rate should be within 0-100 percent")
errNeedAtLeastOneSlotKey = errors.New("need at least one slot key")
errBLSKeysNotMatchSigs = errors.New("bls keys and corresponding signatures could not be verified")
errNilMinSelfDelegation = errors.New("MinSelfDelegation can not be nil")
@ -234,19 +234,19 @@ func (w *ValidatorWrapper) SanityCheck() error {
if w.Validator.Rate.LT(zeroPercent) || w.Validator.Rate.GT(hundredPercent) {
return errors.Wrapf(
errInvalidComissionRate, "rate:%s", w.Validator.Rate.String(),
errInvalidCommissionRate, "rate:%s", w.Validator.Rate.String(),
)
}
if w.Validator.MaxRate.LT(zeroPercent) || w.Validator.MaxRate.GT(hundredPercent) {
return errors.Wrapf(
errInvalidComissionRate, "rate:%s", w.Validator.MaxRate.String(),
errInvalidCommissionRate, "rate:%s", w.Validator.MaxRate.String(),
)
}
if w.Validator.MaxChangeRate.LT(zeroPercent) || w.Validator.MaxChangeRate.GT(hundredPercent) {
return errors.Wrapf(
errInvalidComissionRate, "rate:%s", w.Validator.MaxChangeRate.String(),
errInvalidCommissionRate, "rate:%s", w.Validator.MaxChangeRate.String(),
)
}

Loading…
Cancel
Save