core/state: only drop unregistered non-voted validators

Simple as that: UnregisteredAndHasNoVotes != !RegisteredAndHasVotes

Registered validators should stay in the DB, we might be in the process of
updating votes for them and that starts with subtraction.
This commit is contained in:
Roman Khimov 2020-02-12 18:10:23 +03:00
parent 32a064aa31
commit 807309a0de
2 changed files with 6 additions and 1 deletions

View file

@ -659,7 +659,7 @@ func processTXWithValidatorsSubtract(account *state.Account, dao *cachedDao, toS
return err
}
validator.Votes -= toSubtract
if !validator.RegisteredAndHasVotes() {
if validator.UnregisteredAndHasNoVotes() {
if err := dao.DeleteValidatorState(validator); err != nil {
return err
}

View file

@ -18,6 +18,11 @@ func (vs *Validator) RegisteredAndHasVotes() bool {
return vs.Registered && vs.Votes > util.Fixed8(0)
}
// UnregisteredAndHasNoVotes returns true when Validator is not registered and has no votes.
func (vs *Validator) UnregisteredAndHasNoVotes() bool {
return !vs.Registered && vs.Votes == 0
}
// EncodeBinary encodes Validator to the given BinWriter.
func (vs *Validator) EncodeBinary(bw *io.BinWriter) {
vs.PublicKey.EncodeBinary(bw)