core: always sort the result of GetValidators

It wasn't sorted when all validators were elected. There is also no need to do
`Unique()` on the result because validators are distinguished by the key, so
no two registered validators can have the same key.
This commit is contained in:
Roman Khimov 2020-02-14 15:51:51 +03:00
parent b5ec94bdb2
commit b41a5239c6

View file

@ -1409,20 +1409,20 @@ func (bc *Blockchain) GetValidators(txes ...*transaction.Transaction) ([]*keys.P
}
uniqueSBValidators := standByValidators.Unique()
pubKeys := keys.PublicKeys{}
result := keys.PublicKeys{}
for _, validator := range validators {
if validator.RegisteredAndHasVotes() || uniqueSBValidators.Contains(validator.PublicKey) {
pubKeys = append(pubKeys, validator.PublicKey)
result = append(result, validator.PublicKey)
}
}
if pubKeys.Len() >= count {
return pubKeys[:count], nil
}
result := pubKeys.Unique()
for i := 0; i < uniqueSBValidators.Len() && result.Len() < count; i++ {
if !result.Contains(uniqueSBValidators[i]) {
result = append(result, uniqueSBValidators[i])
if result.Len() >= count {
result = result[:count]
} else {
for i := 0; i < uniqueSBValidators.Len() && result.Len() < count; i++ {
if !result.Contains(uniqueSBValidators[i]) {
result = append(result, uniqueSBValidators[i])
}
}
}
sort.Sort(result)