core: check candidate is registered at the start of voiting

C# node returns an error if the candidate is not registered. We have this
check inside the ModifyAccountVotes, but (*NEO).vote doesn't panics and
just return bool on stack, so we should match exactly the C#'s
algorithm.
This commit is contained in:
Anna Shaleva 2021-03-29 16:00:10 +03:00
parent f0324a1230
commit 3d8d927178

View file

@ -726,6 +726,18 @@ func (n *NEO) VoteInternal(ic *interop.Context, h util.Uint160, pub *keys.Public
if err != nil {
return err
}
if pub != nil {
valKey := makeValidatorKey(pub)
valSi := ic.DAO.GetStorageItem(n.ID, valKey)
if valSi == nil {
return errors.New("unknown validator")
}
cd := new(candidate).FromBytes(valSi)
if !cd.Registered {
return errors.New("validator must be registered")
}
}
if (acc.VoteTo == nil) != (pub == nil) {
val := &acc.Balance
if pub == nil {
@ -765,8 +777,6 @@ func (n *NEO) ModifyAccountVotes(acc *state.NEOBalanceState, d dao.DAO, value *b
if ok {
return err
}
} else if !cd.Registered {
return errors.New("validator must be registered")
}
n.validators.Store(keys.PublicKeys(nil))
return d.PutStorageItem(n.ID, key, cd.Bytes())