-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) | ||
|
||
|
There was a problem hiding this comment.
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 believeThere was a problem hiding this comment.
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.