[state] Do not add reward to banned validator (#2626)

pull/2633/head
Edgar Aroutiounian 5 years ago committed by GitHub
parent 0e5e72f941
commit ce44eeb710
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 13
      core/state/statedb.go

@ -29,8 +29,10 @@ import (
"github.com/ethereum/go-ethereum/trie" "github.com/ethereum/go-ethereum/trie"
"github.com/harmony-one/harmony/core/types" "github.com/harmony-one/harmony/core/types"
common2 "github.com/harmony-one/harmony/internal/common" common2 "github.com/harmony-one/harmony/internal/common"
"github.com/harmony-one/harmony/internal/utils"
"github.com/harmony-one/harmony/numeric" "github.com/harmony-one/harmony/numeric"
"github.com/harmony-one/harmony/staking" "github.com/harmony-one/harmony/staking"
"github.com/harmony-one/harmony/staking/effective"
stk "github.com/harmony-one/harmony/staking/types" stk "github.com/harmony-one/harmony/staking/types"
"github.com/pkg/errors" "github.com/pkg/errors"
) )
@ -748,12 +750,19 @@ func (db *DB) IsValidator(addr common.Address) bool {
// AddReward distributes the reward to all the delegators based on stake percentage. // AddReward distributes the reward to all the delegators based on stake percentage.
func (db *DB) AddReward(snapshot *stk.ValidatorWrapper, reward *big.Int) error { func (db *DB) AddReward(snapshot *stk.ValidatorWrapper, reward *big.Int) error {
rewardPool := big.NewInt(0).Set(reward)
curValidator, err := db.ValidatorWrapper(snapshot.Address) curValidator, err := db.ValidatorWrapper(snapshot.Address)
if err != nil { if err != nil {
return errors.Wrapf(err, "failed to distribute rewards: validator does not exist") return errors.Wrapf(err, "failed to distribute rewards: validator does not exist")
} }
if curValidator.Status == effective.Banned {
utils.Logger().Info().
RawJSON("slashed-validator", []byte(curValidator.String())).
Msg("cannot add reward to banned validator")
return nil
}
rewardPool := big.NewInt(0).Set(reward)
curValidator.BlockReward.Add(curValidator.BlockReward, reward) curValidator.BlockReward.Add(curValidator.BlockReward, reward)
// Payout commission // Payout commission
commissionInt := snapshot.Validator.CommissionRates.Rate.MulInt(reward).RoundInt() commissionInt := snapshot.Validator.CommissionRates.Rate.MulInt(reward).RoundInt()
@ -778,5 +787,5 @@ func (db *DB) AddReward(snapshot *stk.ValidatorWrapper, reward *big.Int) error {
curValidator.Delegations[0].Reward.Add(curValidator.Delegations[0].Reward, rewardPool) curValidator.Delegations[0].Reward.Add(curValidator.Delegations[0].Reward, rewardPool)
} }
return db.UpdateValidatorWrapper(curValidator.Validator.Address, curValidator) return db.UpdateValidatorWrapper(curValidator.Address, curValidator)
} }

Loading…
Cancel
Save