add revoked prefix to key, add condition in getbypower
This commit is contained in:
parent
3fbee11ccc
commit
04d6ce6898
|
@ -167,6 +167,12 @@ func (k Keeper) GetValidatorsByPower(ctx sdk.Context) []Validator {
|
||||||
if !found {
|
if !found {
|
||||||
panic(fmt.Sprintf("validator record not found for address: %v\n", address))
|
panic(fmt.Sprintf("validator record not found for address: %v\n", address))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Reached to revoked validators, stop iterating
|
||||||
|
if validator.Revoked {
|
||||||
|
iterator.Close()
|
||||||
|
break
|
||||||
|
}
|
||||||
if validator.Status() == sdk.Bonded {
|
if validator.Status() == sdk.Bonded {
|
||||||
validators[i] = validator
|
validators[i] = validator
|
||||||
i++
|
i++
|
||||||
|
|
|
@ -51,15 +51,22 @@ func GetValidatorsByPowerKey(validator Validator, pool Pool) []byte {
|
||||||
powerBytes := []byte(power.ToLeftPadded(maxDigitsForAccount)) // power big-endian (more powerful validators first)
|
powerBytes := []byte(power.ToLeftPadded(maxDigitsForAccount)) // power big-endian (more powerful validators first)
|
||||||
|
|
||||||
// TODO ensure that the key will be a readable string.. probably should add seperators and have
|
// TODO ensure that the key will be a readable string.. probably should add seperators and have
|
||||||
|
revokedBytes := make([]byte, 1)
|
||||||
|
if validator.Revoked {
|
||||||
|
revokedBytes[0] = byte(0x01)
|
||||||
|
} else {
|
||||||
|
revokedBytes[0] = byte(0x00)
|
||||||
|
}
|
||||||
// heightBytes and counterBytes represent strings like powerBytes does
|
// heightBytes and counterBytes represent strings like powerBytes does
|
||||||
heightBytes := make([]byte, binary.MaxVarintLen64)
|
heightBytes := make([]byte, binary.MaxVarintLen64)
|
||||||
binary.BigEndian.PutUint64(heightBytes, ^uint64(validator.BondHeight)) // invert height (older validators first)
|
binary.BigEndian.PutUint64(heightBytes, ^uint64(validator.BondHeight)) // invert height (older validators first)
|
||||||
counterBytes := make([]byte, 2)
|
counterBytes := make([]byte, 2)
|
||||||
binary.BigEndian.PutUint16(counterBytes, ^uint16(validator.BondIntraTxCounter)) // invert counter (first txns have priority)
|
binary.BigEndian.PutUint16(counterBytes, ^uint16(validator.BondIntraTxCounter)) // invert counter (first txns have priority)
|
||||||
return append(ValidatorsByPowerKey,
|
return append(ValidatorsByPowerKey,
|
||||||
append(powerBytes,
|
append(revokedBytes,
|
||||||
append(heightBytes,
|
append(powerBytes,
|
||||||
append(counterBytes, validator.Owner.Bytes()...)...)...)...) // TODO don't technically need to store owner
|
append(heightBytes,
|
||||||
|
append(counterBytes, validator.Owner.Bytes()...)...)...)...)...) // TODO don't technically need to store owner
|
||||||
}
|
}
|
||||||
|
|
||||||
// get the key for the accumulated update validators
|
// get the key for the accumulated update validators
|
||||||
|
|
Loading…
Reference in New Issue