From 3d8d92717887cf25c608509b0a569c4482218c6d Mon Sep 17 00:00:00 2001 From: Anna Shaleva Date: Mon, 29 Mar 2021 16:00:10 +0300 Subject: [PATCH] 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. --- pkg/core/native/native_neo.go | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/pkg/core/native/native_neo.go b/pkg/core/native/native_neo.go index e1d5d3f50..295a9d8f7 100644 --- a/pkg/core/native/native_neo.go +++ b/pkg/core/native/native_neo.go @@ -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())