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
Change database *Index() to use slice #4466
Conversation
@@ -27,6 +28,13 @@ func init() { | |||
params.OverrideBeaconConfig(params.MinimalSpecConfig()) | |||
} | |||
|
|||
// _pubKey is a helper to generate a well-formed public key. | |||
func _pubKey(i uint64) []byte { |
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.
Please remove the underscore. Go naming convention is mixedCase
and lower case functions are considered private.
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.
Reason I did that is because the test is in the aggregator
package and I didn't want a function used only for testing and in a _test
file to potentially be used by functions in the non-test package. Will change it if you're okay with this (there's another one out there in another package I'll change 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.
The compiler enforces that you can't use code from _test files in non test files so it is safe to do this.
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.
Cool; never knew that. Updated.
* Change database *Index() to use slice * Remove underscore from helper name
* Change database *Index() to use slice * Remove underscore from helper name
This patch change the signature of the validator-related methods in
beacon-chain/db/iface/interface.go
from taking arrays to taking slices as their argument for the public key.There are a few reasons for doing this. First, every instance of the code that called these functions outside of tests held slices, so wrapped all of the keys in
bytesutil.ToBytes48()
to pass the argument which were then all accessed with[:]
as the downstream functions also use slices. So this change reduces unnecessary allocations.Second, wrapping the keys hid potential issues with keys of incorrect lengths, as
ToBytes48()
will always provide a 48-byte array regardless of the length of the slice. Storing and retrieving keys will now error if they are of an incorrect size.Third, arrays are hard-coded to 48 bytes when we store this value in our configuration parameters and would prefer to use that. The code now checks length against
params.BeaconConfig().BLSPubkeyLength
The patch also fixes up a number of tests where invalid public keys (e.g.
[]byte{'A'}
) were used.