mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2024-12-22 03:30:35 +00:00
more efficient (#10440)
This commit is contained in:
parent
071f6de559
commit
ef8bc97d3e
@ -125,6 +125,7 @@ go_library(
|
||||
"//config/fieldparams:go_default_library",
|
||||
"//config/params:go_default_library",
|
||||
"//crypto/rand:go_default_library",
|
||||
"//cache/lru:go_default_library",
|
||||
"@com_github_dgraph_io_ristretto//:go_default_library",
|
||||
"@com_github_pkg_errors//:go_default_library",
|
||||
"@com_github_supranational_blst//:go_default_library",
|
||||
@ -227,7 +228,7 @@ go_test(
|
||||
deps = [
|
||||
":go_default_library",
|
||||
"//crypto/bls/common:go_default_library",
|
||||
"//encoding/bytesutil:go_default_library",
|
||||
"//crypto/hash:go_default_library",
|
||||
"//encoding/bytesutil:go_default_library",
|
||||
],
|
||||
)
|
||||
|
@ -7,19 +7,16 @@ package blst
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/dgraph-io/ristretto"
|
||||
"github.com/pkg/errors"
|
||||
lruwrpr "github.com/prysmaticlabs/prysm/cache/lru"
|
||||
"github.com/prysmaticlabs/prysm/config/features"
|
||||
fieldparams "github.com/prysmaticlabs/prysm/config/fieldparams"
|
||||
"github.com/prysmaticlabs/prysm/config/params"
|
||||
"github.com/prysmaticlabs/prysm/crypto/bls/common"
|
||||
)
|
||||
|
||||
var maxKeys = int64(1000000)
|
||||
var pubkeyCache, _ = ristretto.NewCache(&ristretto.Config{
|
||||
NumCounters: maxKeys,
|
||||
MaxCost: 1 << 26, // ~64mb is cache max size
|
||||
BufferItems: 64,
|
||||
})
|
||||
var maxKeys = 1000000
|
||||
var pubkeyCache = lruwrpr.New(maxKeys)
|
||||
|
||||
// PublicKey used in the BLS signature scheme.
|
||||
type PublicKey struct {
|
||||
@ -34,7 +31,8 @@ func PublicKeyFromBytes(pubKey []byte) (common.PublicKey, error) {
|
||||
if len(pubKey) != params.BeaconConfig().BLSPubkeyLength {
|
||||
return nil, fmt.Errorf("public key must be %d bytes", params.BeaconConfig().BLSPubkeyLength)
|
||||
}
|
||||
if cv, ok := pubkeyCache.Get(string(pubKey)); ok {
|
||||
newKey := (*[fieldparams.BLSPubkeyLength]byte)(pubKey)
|
||||
if cv, ok := pubkeyCache.Get(*newKey); ok {
|
||||
return cv.(*PublicKey).Copy(), nil
|
||||
}
|
||||
// Subgroup check NOT done when decompressing pubkey.
|
||||
@ -49,7 +47,8 @@ func PublicKeyFromBytes(pubKey []byte) (common.PublicKey, error) {
|
||||
}
|
||||
pubKeyObj := &PublicKey{p: p}
|
||||
copiedKey := pubKeyObj.Copy()
|
||||
pubkeyCache.Set(string(pubKey), copiedKey, 48)
|
||||
cacheKey := *newKey
|
||||
pubkeyCache.Add(cacheKey, copiedKey)
|
||||
return pubKeyObj, nil
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user