consensus: use GetNextBlockValidators where appropriate

GetValidators without parameter is called upon DBFT initialization and it
should receive validators for the next block (that will create it),
parameterized GetValidators is used for NextConsensus calculation where we
need a list for the current state of the chain.
This commit is contained in:
Roman Khimov 2020-07-11 13:10:57 +03:00
parent 2278cd5700
commit 7eef895061
4 changed files with 16 additions and 3 deletions

View file

@ -446,12 +446,16 @@ func (s *service) getVerifiedTx() []block.Transaction {
return res
}
func (s *service) getValidators(_ ...block.Transaction) []crypto.PublicKey {
func (s *service) getValidators(txes ...block.Transaction) []crypto.PublicKey {
var (
pKeys []*keys.PublicKey
err error
)
pKeys, err = s.Chain.GetValidators()
if txes == nil {
pKeys, err = s.Chain.GetNextBlockValidators()
} else {
pKeys, err = s.Chain.GetValidators()
}
if err != nil {
s.log.Error("error while trying to get validators", zap.Error(err))
}

View file

@ -1240,11 +1240,16 @@ func (bc *Blockchain) GetStandByValidators() keys.PublicKeys {
return bc.sbValidators.Copy()
}
// GetValidators returns next block validators.
// GetValidators returns current validators.
func (bc *Blockchain) GetValidators() ([]*keys.PublicKey, error) {
return bc.contracts.NEO.GetValidatorsInternal(bc, bc.dao)
}
// GetNextBlockValidators returns next block validators.
func (bc *Blockchain) GetNextBlockValidators() ([]*keys.PublicKey, error) {
return bc.contracts.NEO.GetNextBlockValidatorsInternal(bc, bc.dao)
}
// GetEnrollments returns all registered validators.
func (bc *Blockchain) GetEnrollments() ([]state.Validator, error) {
return bc.contracts.NEO.GetRegisteredValidators(bc.dao)

View file

@ -36,6 +36,7 @@ type Blockchainer interface {
HasTransaction(util.Uint256) bool
GetAccountState(util.Uint160) *state.Account
GetAppExecResult(util.Uint256) (*state.AppExecResult, error)
GetNextBlockValidators() ([]*keys.PublicKey, error)
GetNEP5TransferLog(util.Uint160) *state.NEP5TransferLog
GetNEP5Balances(util.Uint160) *state.NEP5Balances
GetValidators() ([]*keys.PublicKey, error)

View file

@ -77,6 +77,9 @@ func (chain testChain) GetHeader(hash util.Uint256) (*block.Header, error) {
func (chain testChain) GetAccountState(util.Uint160) *state.Account {
panic("TODO")
}
func (chain testChain) GetNextBlockValidators() ([]*keys.PublicKey, error) {
panic("TODO")
}
func (chain testChain) GetNEP5TransferLog(util.Uint160) *state.NEP5TransferLog {
panic("TODO")
}