Skip to content

Commit

Permalink
Merge pull request cosmos#1155 from cosmos/joon/1015-revoked-candidates
Browse files Browse the repository at this point in the history
1015 Revoked Candidates in Stake
  • Loading branch information
rigelrozanski authored Jun 7, 2018
2 parents 3fbee11 + 04d6ce6 commit 3c17fa2
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
6 changes: 6 additions & 0 deletions x/stake/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,12 @@ func (k Keeper) GetValidatorsByPower(ctx sdk.Context) []Validator {
if !found {
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 {
validators[i] = validator
i++
Expand Down
13 changes: 10 additions & 3 deletions x/stake/keeper_keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,22 @@ func GetValidatorsByPowerKey(validator Validator, pool Pool) []byte {
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
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 := make([]byte, binary.MaxVarintLen64)
binary.BigEndian.PutUint64(heightBytes, ^uint64(validator.BondHeight)) // invert height (older validators first)
counterBytes := make([]byte, 2)
binary.BigEndian.PutUint16(counterBytes, ^uint16(validator.BondIntraTxCounter)) // invert counter (first txns have priority)
return append(ValidatorsByPowerKey,
append(powerBytes,
append(heightBytes,
append(counterBytes, validator.Owner.Bytes()...)...)...)...) // TODO don't technically need to store owner
append(revokedBytes,
append(powerBytes,
append(heightBytes,
append(counterBytes, validator.Owner.Bytes()...)...)...)...)...) // TODO don't technically need to store owner
}

// get the key for the accumulated update validators
Expand Down

0 comments on commit 3c17fa2

Please sign in to comment.