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

Validator Priority displayed as 32-bit int but is a 64-bit int from the chain. #530

Closed
4 tasks
SpicyLemon opened this issue Aug 13, 2024 · 1 comment · Fixed by #533
Closed
4 tasks

Validator Priority displayed as 32-bit int but is a 64-bit int from the chain. #530

SpicyLemon opened this issue Aug 13, 2024 · 1 comment · Fixed by #533

Comments

@SpicyLemon
Copy link

Summary of Bug

On the block page, (e.g. 18318664), the "Proposer Priority" values do not match what the provenanced q comet-validator-set has for each validator.

Steps to Reproduce

$ provenanced q comet-validator-set 18318664 | jq -r '.validators|sort_by(.proposer_priority|tonumber)|.[]|.address + " " + .proposer_priority' | grep 89r
pbvalcons14z3qgnjh3d2gexl33gzrcrk70y9cscllksn89r -4976622813127

That pbvalcons14z3qgnjh3d2gexl33gzrcrk70y9cscllksn89r is TreeStaker.

If you look at the block page, it'll show that TreeStaker's "Proposer Priority" for that block was 1244282937 (instead of -4976622813127).

$ printf '%s\n' $(( -4976622813127 & 4294967295 ))
1244282937

Then, since 1244282937 is still within the bounds of 32-bit int, that's the result of casting -4976622813127 into a 32-bit integer. That 1244282937 is what explorer lists as Treestakers proposer priority for that block.

If it were larger (it'll never be smaller because the sign-bit is now zero), we would want to xor it with 4294967295, add one, then put a negative sign on it.

E.g.

$ printf '%s\n' "-$(( ( ( ( 5719164737899 ) & 4294967295 ) ^ 4294967295 ) + 1 ))"
-1731700373

Those 5719164737899 and -1731700373 are Treestaker's proposer priority for block 18318663 (actual and display respectively).


For Admin Use

  • Not duplicate issue
  • Appropriate labels applied
  • Appropriate contributors tagged
  • Contributor assigned/self-assigned
@SpicyLemon
Copy link
Author

SpicyLemon commented Aug 13, 2024

Here's a shell function for converting a number to a 32-bit int:

$ to_int32 () { if [[ "$1" -le '2147483647' && "$1" -ge '-2147483648' ]]; then printf '%s\n' "$1"; return 0; fi; local v; v=$(( $1 & 4294967295 )); if [[ "$v" -gt '2147483647' ]]; then v="-$(( ( v ^ 4294967295 ) + 1 ))"; fi; printf '%s\n' "$v"; }

Example uses:

$ to_int32 -4976622813127
1244282937
$ to_int32 5719164737899
-1731700373

I'm not sure how much I trust it since I'm pretty rusty with bit math, but it's correct for all the ones I've tried so far. I wouldn't be surprised if I made it harder than it needed to be though.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant