diff --git a/pkg/consensus/consensus.go b/pkg/consensus/consensus.go index 8120e1d161..633cda9c8f 100644 --- a/pkg/consensus/consensus.go +++ b/pkg/consensus/consensus.go @@ -48,7 +48,7 @@ type Ledger interface { GetNextBlockValidators() ([]*keys.PublicKey, error) GetStateRoot(height uint32) (*state.MPTRoot, error) GetTransaction(util.Uint256) (*transaction.Transaction, uint32, error) - GetValidators() []*keys.PublicKey + ComputeNextBlockValidators() []*keys.PublicKey PoolTx(t *transaction.Transaction, pools ...*mempool.Pool) error SubscribeForBlocks(ch chan *coreb.Block) UnsubscribeFromBlocks(ch chan *coreb.Block) @@ -679,7 +679,7 @@ func (s *service) getValidators(txes ...block.Transaction) []crypto.PublicKey { if txes == nil { pKeys, err = s.Chain.GetNextBlockValidators() } else { - pKeys = s.Chain.GetValidators() + pKeys = s.Chain.ComputeNextBlockValidators() } if err != nil { s.log.Error("error while trying to get validators", zap.Error(err)) @@ -725,7 +725,7 @@ func (s *service) newBlockFromContext(ctx *dbft.Context) block.Block { var err error cfg := s.Chain.GetConfig().ProtocolConfiguration if cfg.ShouldUpdateCommitteeAt(ctx.BlockIndex) { - validators = s.Chain.GetValidators() + validators = s.Chain.ComputeNextBlockValidators() } else { validators, err = s.Chain.GetNextBlockValidators() } diff --git a/pkg/core/blockchain.go b/pkg/core/blockchain.go index a864f36a75..de89504200 100644 --- a/pkg/core/blockchain.go +++ b/pkg/core/blockchain.go @@ -2703,18 +2703,20 @@ func (bc *Blockchain) GetCommittee() (keys.PublicKeys, error) { return pubs, nil } -// GetValidators returns current validators. Validators list returned from this -// method may be updated every block (depending on register/unregister/vote -// calls to NeoToken contract), not only once per (committee size) number of -// blocks. -func (bc *Blockchain) GetValidators() []*keys.PublicKey { +// ComputeNextBlockValidators returns current validators. Validators list +// returned from this method may be updated every block (depending on +// register/unregister/vote calls to NeoToken contract), not only once per +// (committee size) number of blocks. +func (bc *Blockchain) ComputeNextBlockValidators() []*keys.PublicKey { return bc.contracts.NEO.ComputeNextBlockValidators(bc.dao) } // GetNextBlockValidators returns next block validators. Validators list returned // from this method is the sorted top NumOfCNs number of public keys from the -// current committee, thus, validators list returned from this method is being -// updated once per (committee size) number of blocks. +// committee of the current dBFT round (that was calculated once for the +// CommitteeSize number of blocks), thus, validators list returned from this +// method is being updated once per (committee size) number of blocks, but not +// every block. func (bc *Blockchain) GetNextBlockValidators() ([]*keys.PublicKey, error) { return bc.contracts.NEO.GetNextBlockValidatorsInternal(bc.dao), nil } diff --git a/pkg/core/blockchain_core_test.go b/pkg/core/blockchain_core_test.go index e17ee7df9c..1d45c115b8 100644 --- a/pkg/core/blockchain_core_test.go +++ b/pkg/core/blockchain_core_test.go @@ -261,7 +261,7 @@ func TestChainWithVolatileNumOfValidators(t *testing.T) { priv0 := testchain.PrivateKeyByID(0) - vals := bc.GetValidators() + vals := bc.ComputeNextBlockValidators() script, err := smartcontract.CreateDefaultMultiSigRedeemScript(vals) require.NoError(t, err) curWit := transaction.Witness{ @@ -279,7 +279,7 @@ func TestChainWithVolatileNumOfValidators(t *testing.T) { } // Mimic consensus. if bc.config.ShouldUpdateCommitteeAt(uint32(i)) { - vals = bc.GetValidators() + vals = bc.ComputeNextBlockValidators() } else { vals, err = bc.GetNextBlockValidators() } diff --git a/pkg/core/native/native_test/neo_test.go b/pkg/core/native/native_test/neo_test.go index dcb9ac415c..e0a46f5d2a 100644 --- a/pkg/core/native/native_test/neo_test.go +++ b/pkg/core/native/native_test/neo_test.go @@ -138,7 +138,7 @@ func TestNEO_Vote(t *testing.T) { require.NoError(t, err) standBySorted = standBySorted[:validatorsCount] sort.Sort(standBySorted) - pubs := e.Chain.GetValidators() + pubs := e.Chain.ComputeNextBlockValidators() require.Equal(t, standBySorted, keys.PublicKeys(pubs)) // voters vote for candidates. The aim of this test is to check if voting @@ -175,7 +175,7 @@ func TestNEO_Vote(t *testing.T) { } // We still haven't voted enough validators in. - pubs = e.Chain.GetValidators() + pubs = e.Chain.ComputeNextBlockValidators() require.NoError(t, err) require.Equal(t, standBySorted, keys.PublicKeys(pubs)) @@ -266,7 +266,7 @@ func TestNEO_Vote(t *testing.T) { advanceChain(t) - pubs = e.Chain.GetValidators() + pubs = e.Chain.ComputeNextBlockValidators() for i := range pubs { require.NotEqual(t, candidates[0], pubs[i]) require.NotEqual(t, candidates[len(candidates)-1], pubs[i])