forked from TrueCloudLab/neoneo-go
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:
parent
f0324a1230
commit
3d8d927178
1 changed files with 12 additions and 2 deletions
|
@ -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())
|
||||
|
|
Loading…
Reference in a new issue