Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

R4R: Fix validator power key #2508

Merged
merged 2 commits into from
Oct 16, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can to delete ToLeftPadded now I believe

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm it could be useful in general for other serialization purposes though.


// 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))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this is the approach we want to take. Now we lose sorting past the tmpower. Instead we should make the entire Decimal/Int get marshalled in constant size for the store key, imo.

Copy link
Contributor Author

@cwgoes cwgoes Oct 16, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe... what's the benefit of sorting past TM power precision?

(I agree with changing how TM power is calculated as was discussed in the issue)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

per discussion in slack, I now agree. Lets only use tmpower everywhere.


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