From 807309a0de2e5a3fa834d02b92540180f456cfe6 Mon Sep 17 00:00:00 2001 From: Roman Khimov Date: Wed, 12 Feb 2020 18:10:23 +0300 Subject: [PATCH] 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. --- pkg/core/blockchain.go | 2 +- pkg/core/state/validator.go | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/pkg/core/blockchain.go b/pkg/core/blockchain.go index 1f3866ee2..e88cdd08b 100644 --- a/pkg/core/blockchain.go +++ b/pkg/core/blockchain.go @@ -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 } diff --git a/pkg/core/state/validator.go b/pkg/core/state/validator.go index bd3414a1f..3f8ba51d8 100644 --- a/pkg/core/state/validator.go +++ b/pkg/core/state/validator.go @@ -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)