-
Notifications
You must be signed in to change notification settings - Fork 493
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
Removed hard-coded constant in sortition.go
.
#3558
Conversation
Remove a hardcoded constant in sortition.go which was used as the denominator in determining the selection ratio. This clarifies what the maximum possible output size is of the output VRF based on the SHA algorithm used to generate it. Due to the usage of C src code, a simple `go test -v ./data/committee/sortition/` cannot be executed without the proper configurations. However, circle CI should be able to execute the unit tests automatically and verify the changes.
precision := uint(8 * (len(vrfOutput) + 1)) | ||
max, b, err := big.ParseFloat("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", 0, precision, big.ToNearestEven) | ||
maxFloatString := fmt.Sprintf("0x%s", strings.Repeat("f", crypto.DigestSize*2+1)) |
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.
This can't be right, can it? Surely an odd number of hex digits is not what you want.
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.
You are correct. This was something I added while manually testing. Thanks!
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.
Per the update in my comment, might be easier to add Dockerfile so all the dependencies don't have to be installed locally to run the unit tests. I'm relying on circle CI right now.
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.
I'd prefer to see the fmt.Sprintf
done once, rather than each time, as well.
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.
Added a local var since you can't assign the output of formatting to a constant.
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.
For that matter, perhaps you could move max
out of the function as well, so it's not reparsed each time. I suspect the PR would be more palatable if it had a performance improvement, rather than only making the constant explicit. (On the explicitness front, why not strings.Repeat("ff", crypto.DIgestSize)
?)
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.
Done!
@Olshansk - you'll need to sign the CLAassistant before the proposed code changes could be merged in. |
@tsachiherman Thanks for the suggestion! TIL about Also signed the agreement. |
Codecov Report
@@ Coverage Diff @@
## master #3558 +/- ##
==========================================
- Coverage 47.58% 47.58% -0.01%
==========================================
Files 370 370
Lines 60118 60121 +3
==========================================
Hits 28606 28606
- Misses 28198 28203 +5
+ Partials 3314 3312 -2
Continue to review full report at Codecov.
|
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.
This looks good to me.
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.
Thanks for the changes.
@tsachiherman @jannotti I was wondering if either of you could help me understand the logic behind I've looked at the paper and read through some online articles (example) but am still struggling to understand this: In short, I understand that we use VRF to compute a proof and a hash, which is normalized to a value in [0, 1) using the hashlen (i.e. the
However, I'm still struggling to understand the significance of |
It's not something I'm super familiar with, but I think you've got the idea. Suppose I have 1M algos. I don't "win" the VRF lottery will all of them, or lose with all of them. Some fraction of them win and some fraction loses, based on the outcome of the VRF. |
Yea, the high level idea makes sense and even most of the intricacies except for that one… Maybe it's something we could figure out together? I've looked at section 5 of the whitepaper and my understanding is: Assume / let the following:
The binomial distribution is set to:
After re-reading it, I actually think the core of the “magic” is here:
The maximum value for j is the maximum number of their sub-users that may be selected. However, if exactly j sub-users are not selected (based on the normalized VRF output), it doesn’t mean that a value less than j might not be selected. E.g. if the total voting power is 1000 ALGO, and a single node has 100, they should still have an opportunity to be a potential committee member if only 50 of their ALGO is elected as their voting round for that view change. My understanding is that this is the reason we’re using a CDF of the binomial distribution and accepting any value of j smaller than their individual voting power as the value to be a candidate. |
## Summary Following up on #3558, this PR update the THANKS.md file. ## Test Plan Not required for this change.
Summary
Remove a hardcoded constant in sortition.go which was
used as the denominator in determining the selection ratio.
This clarifies what the maximum possible output size is of
the output VRF based on the SHA algorithm used to generate it.
Purpose
This is simply a code quality change to make it easier to read and
understand without any focus on new functionality or performance.
It is unlikely that the VRF SHA length used by Algorand will changed,
so the generalization to a dynamic length based on the length of the
Crypto digest is only for the reader.
The use of an
init
function to initialize themaxFloat
once rather thananytime
sortition
runs is a minor optimization, but likely to be neglibilein the grand scheme of things.
Test Plan
Due to the usage of C src code, a simple
go test -v ./data/committee/sortition/
cannot be executed without the proper configurations. However, circle CI
should be able to execute the unit tests automatically and verify the changes.
Recommendation: Running the recommended make targets to test the changes
did not automatically due to missing dependencies, so potentially a Dockerfile
could help resolve this for future contributors.