From ae497228f06ef2ac466fd08ac7be0b2ef66853d0 Mon Sep 17 00:00:00 2001 From: Roman Khimov Date: Sat, 11 Jul 2020 12:29:06 +0300 Subject: [PATCH] core: use native NEO GetValidators for bc.GetValidators NextBlockValidators are updated before the new block persist, so we need to use GetValidators to get the list corresponding to the current state of the chain. --- pkg/core/blockchain.go | 2 +- pkg/core/native/native_neo.go | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/pkg/core/blockchain.go b/pkg/core/blockchain.go index bbfa38219..7446799de 100644 --- a/pkg/core/blockchain.go +++ b/pkg/core/blockchain.go @@ -1242,7 +1242,7 @@ func (bc *Blockchain) GetStandByValidators() keys.PublicKeys { // GetValidators returns next block validators. func (bc *Blockchain) GetValidators() ([]*keys.PublicKey, error) { - return bc.contracts.NEO.GetNextBlockValidatorsInternal(bc, bc.dao) + return bc.contracts.NEO.GetValidatorsInternal(bc, bc.dao) } // GetEnrollments returns all registered validators. diff --git a/pkg/core/native/native_neo.go b/pkg/core/native/native_neo.go index 6d169eaa4..75930277e 100644 --- a/pkg/core/native/native_neo.go +++ b/pkg/core/native/native_neo.go @@ -142,7 +142,7 @@ func (n *NEO) Initialize(ic *interop.Context) error { // OnPersist implements Contract interface. func (n *NEO) OnPersist(ic *interop.Context) error { - pubs, err := n.getValidatorsInternal(ic.Chain, ic.DAO) + pubs, err := n.GetValidatorsInternal(ic.Chain, ic.DAO) if err != nil { return err } @@ -385,8 +385,8 @@ func (n *NEO) getRegisteredValidatorsCall(ic *interop.Context, _ []stackitem.Ite return stackitem.NewArray(arr) } -// getValidatorsInternal returns a list of current validators. -func (n *NEO) getValidatorsInternal(bc blockchainer.Blockchainer, d dao.DAO) (keys.PublicKeys, error) { +// GetValidatorsInternal returns a list of current validators. +func (n *NEO) GetValidatorsInternal(bc blockchainer.Blockchainer, d dao.DAO) (keys.PublicKeys, error) { if vals := n.validators.Load().(keys.PublicKeys); vals != nil { return vals, nil } @@ -442,7 +442,7 @@ func (n *NEO) getValidatorsInternal(bc blockchainer.Blockchainer, d dao.DAO) (ke } func (n *NEO) getValidators(ic *interop.Context, _ []stackitem.Item) stackitem.Item { - result, err := n.getValidatorsInternal(ic.Chain, ic.DAO) + result, err := n.GetValidatorsInternal(ic.Chain, ic.DAO) if err != nil { panic(err) } @@ -470,7 +470,7 @@ func (n *NEO) GetNextBlockValidatorsInternal(bc blockchainer.Blockchainer, d dao func (n *NEO) getNextBlockValidatorsInternal(bc blockchainer.Blockchainer, d dao.DAO) (keys.PublicKeys, error) { si := d.GetStorageItem(n.ContractID, nextValidatorsKey) if si == nil { - return n.getValidatorsInternal(bc, d) + return n.GetValidatorsInternal(bc, d) } pubs := keys.PublicKeys{} err := pubs.DecodeBytes(si.Value)