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() uniqueSBValidators := standByValidators.Unique()
pubKeys := keys.PublicKeys{} result := keys.PublicKeys{}
for _, validator := range validators { for _, validator := range validators {
if validator.RegisteredAndHasVotes() || uniqueSBValidators.Contains(validator.PublicKey) { 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() if result.Len() >= count {
for i := 0; i < uniqueSBValidators.Len() && result.Len() < count; i++ { result = result[:count]
if !result.Contains(uniqueSBValidators[i]) { } else {
result = append(result, uniqueSBValidators[i]) for i := 0; i < uniqueSBValidators.Len() && result.Len() < count; i++ {
if !result.Contains(uniqueSBValidators[i]) {
result = append(result, uniqueSBValidators[i])
}
} }
} }
sort.Sort(result) sort.Sort(result)