Merge PR #2508: Fix validator power key

This commit is contained in:
Christopher Goes 2018-10-16 22:08:56 +02:00 committed by GitHub
commit b70c26af8a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 13 additions and 5 deletions

View File

@ -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

View File

@ -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)

View File

@ -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))