mirror of
https://github.com/OffchainLabs/prysm.git
synced 2026-01-08 23:18:15 -05:00
stategen: Pre-populate bls pubkey cache as part of stategen's Resume function (#11482)
* Pre-populate bls pubkey cache as part of state gen's Resume function. This adds some helpers and a benchmark to blst * Do it async * fix missing import * lint --------- Co-authored-by: prylabs-bulldozer[bot] <58059840+prylabs-bulldozer[bot]@users.noreply.github.com> Co-authored-by: rauljordan <raul@prysmaticlabs.com>
This commit is contained in:
@@ -34,6 +34,7 @@ go_test(
|
||||
"public_key_test.go",
|
||||
"secret_key_test.go",
|
||||
"signature_test.go",
|
||||
"test_helper_test.go",
|
||||
],
|
||||
embed = [":go_default_library"],
|
||||
deps = [
|
||||
|
||||
@@ -12,7 +12,7 @@ import (
|
||||
"github.com/prysmaticlabs/prysm/v4/crypto/bls/common"
|
||||
)
|
||||
|
||||
var maxKeys = 1000000
|
||||
var maxKeys = 1_000_000
|
||||
var pubkeyCache = lruwrpr.New(maxKeys)
|
||||
|
||||
// PublicKey used in the BLS signature scheme.
|
||||
|
||||
@@ -97,3 +97,27 @@ func TestPublicKeysEmpty(t *testing.T) {
|
||||
_, err := blst.AggregatePublicKeys(pubs)
|
||||
require.ErrorContains(t, "nil or empty public keys", err)
|
||||
}
|
||||
|
||||
func BenchmarkPublicKeyFromBytes(b *testing.B) {
|
||||
priv, err := blst.RandKey()
|
||||
require.NoError(b, err)
|
||||
pubkey := priv.PublicKey()
|
||||
pubkeyBytes := pubkey.Marshal()
|
||||
|
||||
b.Run("cache on", func(b *testing.B) {
|
||||
blst.EnableCaches()
|
||||
for i := 0; i < b.N; i++ {
|
||||
_, err := blst.PublicKeyFromBytes(pubkeyBytes)
|
||||
require.NoError(b, err)
|
||||
}
|
||||
})
|
||||
|
||||
b.Run("cache off", func(b *testing.B) {
|
||||
blst.DisableCaches()
|
||||
for i := 0; i < b.N; i++ {
|
||||
_, err := blst.PublicKeyFromBytes(pubkeyBytes)
|
||||
require.NoError(b, err)
|
||||
}
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
13
crypto/bls/blst/test_helper_test.go
Normal file
13
crypto/bls/blst/test_helper_test.go
Normal file
@@ -0,0 +1,13 @@
|
||||
package blst
|
||||
|
||||
// Note: These functions are for tests to access private globals, such as pubkeyCache.
|
||||
|
||||
// DisableCaches sets the cache sizes to 0.
|
||||
func DisableCaches() {
|
||||
pubkeyCache.Resize(0)
|
||||
}
|
||||
|
||||
// EnableCaches sets the cache sizes to the default values.
|
||||
func EnableCaches() {
|
||||
pubkeyCache.Resize(maxKeys)
|
||||
}
|
||||
Reference in New Issue
Block a user