mirror of
https://github.com/nspcc-dev/neo-go.git
synced 2024-11-23 03:38:35 +00:00
native: remove getValidators
method
Follow https://github.com/neo-project/neo/pull/1920 .
This commit is contained in:
parent
83e94d3bbc
commit
81a11c629a
3 changed files with 11 additions and 26 deletions
|
@ -1380,7 +1380,7 @@ func (bc *Blockchain) GetCommittee() (keys.PublicKeys, error) {
|
|||
|
||||
// GetValidators returns current validators.
|
||||
func (bc *Blockchain) GetValidators() ([]*keys.PublicKey, error) {
|
||||
return bc.contracts.NEO.GetValidatorsInternal(bc, bc.dao)
|
||||
return bc.contracts.NEO.ComputeNextBlockValidators(bc, bc.dao)
|
||||
}
|
||||
|
||||
// GetNextBlockValidators returns next block validators.
|
||||
|
|
|
@ -132,10 +132,6 @@ func NewNEO() *NEO {
|
|||
md = newMethodAndPrice(n.getCommittee, 100000000, smartcontract.AllowStates)
|
||||
n.AddMethod(md, desc, true)
|
||||
|
||||
desc = newDescriptor("getValidators", smartcontract.ArrayType)
|
||||
md = newMethodAndPrice(n.getValidators, 100000000, smartcontract.AllowStates)
|
||||
n.AddMethod(md, desc, true)
|
||||
|
||||
desc = newDescriptor("getNextBlockValidators", smartcontract.ArrayType)
|
||||
md = newMethodAndPrice(n.getNextBlockValidators, 100000000, smartcontract.AllowStates)
|
||||
n.AddMethod(md, desc, true)
|
||||
|
@ -585,30 +581,21 @@ func (n *NEO) getCandidatesCall(ic *interop.Context, _ []stackitem.Item) stackit
|
|||
return stackitem.NewArray(arr)
|
||||
}
|
||||
|
||||
// GetValidatorsInternal returns a list of current validators.
|
||||
func (n *NEO) GetValidatorsInternal(bc blockchainer.Blockchainer, d dao.DAO) (keys.PublicKeys, error) {
|
||||
// ComputeNextBlockValidators returns an actual list of current validators.
|
||||
func (n *NEO) ComputeNextBlockValidators(bc blockchainer.Blockchainer, d dao.DAO) (keys.PublicKeys, error) {
|
||||
if vals := n.validators.Load().(keys.PublicKeys); vals != nil {
|
||||
return vals.Copy(), nil
|
||||
}
|
||||
result := n.GetCommitteeMembers()
|
||||
count := bc.GetConfig().ValidatorsCount
|
||||
if len(result) < count {
|
||||
count = len(result)
|
||||
result, err := n.ComputeCommitteeMembers(bc, d)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
result = result[:count]
|
||||
result = result[:bc.GetConfig().ValidatorsCount]
|
||||
sort.Sort(result)
|
||||
n.validators.Store(result)
|
||||
return result, nil
|
||||
}
|
||||
|
||||
func (n *NEO) getValidators(ic *interop.Context, _ []stackitem.Item) stackitem.Item {
|
||||
result, err := n.GetValidatorsInternal(ic.Chain, ic.DAO)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return pubsToArray(result)
|
||||
}
|
||||
|
||||
func (n *NEO) getCommittee(ic *interop.Context, _ []stackitem.Item) stackitem.Item {
|
||||
pubs := n.GetCommitteeMembers()
|
||||
sort.Sort(pubs)
|
||||
|
|
|
@ -37,7 +37,7 @@ func TestNEO_Vote(t *testing.T) {
|
|||
|
||||
standBySorted := bc.GetStandByValidators()
|
||||
sort.Sort(standBySorted)
|
||||
pubs, err := neo.GetValidatorsInternal(bc, ic.DAO)
|
||||
pubs, err := neo.ComputeNextBlockValidators(bc, ic.DAO)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, standBySorted, pubs)
|
||||
|
||||
|
@ -68,10 +68,8 @@ func TestNEO_Vote(t *testing.T) {
|
|||
require.NoError(t, neo.VoteInternal(ic, h, candidates[i]))
|
||||
}
|
||||
|
||||
require.NoError(t, neo.OnPersist(ic))
|
||||
|
||||
// We still haven't voted enough validators in.
|
||||
pubs, err = neo.GetValidatorsInternal(bc, ic.DAO)
|
||||
pubs, err = neo.ComputeNextBlockValidators(bc, ic.DAO)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, standBySorted, pubs)
|
||||
|
||||
|
@ -93,7 +91,7 @@ func TestNEO_Vote(t *testing.T) {
|
|||
}
|
||||
|
||||
require.NoError(t, neo.OnPersist(ic))
|
||||
pubs, err = neo.GetValidatorsInternal(bc, ic.DAO)
|
||||
pubs, err = neo.ComputeNextBlockValidators(bc, ic.DAO)
|
||||
require.NoError(t, err)
|
||||
sortedCandidates := candidates.Copy()
|
||||
sort.Sort(sortedCandidates)
|
||||
|
@ -106,7 +104,7 @@ func TestNEO_Vote(t *testing.T) {
|
|||
require.Error(t, neo.VoteInternal(ic, h, candidates[0]))
|
||||
require.NoError(t, neo.OnPersist(ic))
|
||||
|
||||
pubs, err = neo.GetValidatorsInternal(bc, ic.DAO)
|
||||
pubs, err = neo.ComputeNextBlockValidators(bc, ic.DAO)
|
||||
require.NoError(t, err)
|
||||
for i := range pubs {
|
||||
require.NotEqual(t, candidates[0], pubs[i])
|
||||
|
|
Loading…
Reference in a new issue