Skip to content

Commit

Permalink
Merge PR #2508: Fix validator power key
Browse files Browse the repository at this point in the history
  • Loading branch information
cwgoes authored Oct 16, 2018
2 parents 79ce52a + d8038fc commit b70c26a
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
1 change: 1 addition & 0 deletions PENDING.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ BREAKING CHANGES
* [x/stake] \#2412 Added an unbonding validator queue to EndBlock to automatically update validator.Status when finished Unbonding
* [x/stake] \#2500 Block conflicting redelegations until we add an index
* [x/params] Global Paramstore refactored
* [x/stake] \#2508 Utilize Tendermint power for validator power key

* Tendermint
* Update tendermint version from v0.23.0 to v0.25.0, notable changes
Expand Down
9 changes: 8 additions & 1 deletion x/stake/keeper/key.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,15 @@ func GetBondedValidatorIndexKey(operator sdk.ValAddress) []byte {
func getValidatorPowerRank(validator types.Validator) []byte {

potentialPower := validator.Tokens
powerBytes := []byte(potentialPower.ToLeftPadded(maxDigitsForAccount)) // power big-endian (more powerful validators first)

// todo: deal with cases above 2**64, ref https://github.com/cosmos/cosmos-sdk/issues/2439#issuecomment-427167556
tendermintPower := potentialPower.RoundInt64()
tendermintPowerBytes := make([]byte, 8)
binary.BigEndian.PutUint64(tendermintPowerBytes[:], uint64(tendermintPower))

powerBytes := tendermintPowerBytes
powerBytesLen := len(powerBytes)

// key is of format prefix || powerbytes || heightBytes || counterBytes
key := make([]byte, 1+powerBytesLen+8+2)

Expand Down
8 changes: 4 additions & 4 deletions x/stake/keeper/key_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@ func TestGetValidatorPowerRank(t *testing.T) {
validator types.Validator
wantHex string
}{
{val1, "05303030303030303030303030ffffffffffffffffffff"},
{val2, "05303030303030303030303031ffffffffffffffffffff"},
{val3, "05303030303030303030303130ffffffffffffffffffff"},
{val4, "0531303939353131363237373736ffffffffffffffffffff"},
{val1, "050000000000000000ffffffffffffffffffff"},
{val2, "050000000000000001ffffffffffffffffffff"},
{val3, "05000000000000000affffffffffffffffffff"},
{val4, "050000010000000000ffffffffffffffffffff"},
}
for i, tt := range tests {
got := hex.EncodeToString(getValidatorPowerRank(tt.validator))
Expand Down

0 comments on commit b70c26a

Please sign in to comment.