mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2024-12-22 03:30:35 +00:00
Integrate Read-Only-Lock-on-Get LRU Cache for Public Keys (#12646)
* use new lru cache * update build --------- Co-authored-by: Nishant Das <nishdas93@gmail.com> Co-authored-by: prylabs-bulldozer[bot] <58059840+prylabs-bulldozer[bot]@users.noreply.github.com>
This commit is contained in:
parent
9c250dd4c2
commit
e9c8e84618
@ -17,7 +17,7 @@ go_library(
|
||||
importpath = "github.com/prysmaticlabs/prysm/v4/crypto/bls/blst",
|
||||
visibility = ["//visibility:public"],
|
||||
deps = [
|
||||
"//cache/lru:go_default_library",
|
||||
"//cache/nonblocking:go_default_library",
|
||||
"//config/fieldparams:go_default_library",
|
||||
"//config/params:go_default_library",
|
||||
"//crypto/bls/common:go_default_library",
|
||||
|
@ -3,8 +3,11 @@
|
||||
package blst
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"runtime"
|
||||
|
||||
"github.com/prysmaticlabs/prysm/v4/cache/nonblocking"
|
||||
"github.com/prysmaticlabs/prysm/v4/crypto/bls/common"
|
||||
blst "github.com/supranational/blst/bindings/go"
|
||||
)
|
||||
|
||||
@ -15,4 +18,10 @@ func init() {
|
||||
maxProcs = 1
|
||||
}
|
||||
blst.SetMaxProcs(maxProcs)
|
||||
onEvict := func(_ [48]byte, _ common.PublicKey) {}
|
||||
keysCache, err := nonblocking.NewLRU(maxKeys, onEvict)
|
||||
if err != nil {
|
||||
panic(fmt.Sprintf("Could not initiate public keys cache: %v", err))
|
||||
}
|
||||
pubkeyCache = keysCache
|
||||
}
|
||||
|
@ -6,14 +6,14 @@ import (
|
||||
"fmt"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
lruwrpr "github.com/prysmaticlabs/prysm/v4/cache/lru"
|
||||
"github.com/prysmaticlabs/prysm/v4/cache/nonblocking"
|
||||
fieldparams "github.com/prysmaticlabs/prysm/v4/config/fieldparams"
|
||||
"github.com/prysmaticlabs/prysm/v4/config/params"
|
||||
"github.com/prysmaticlabs/prysm/v4/crypto/bls/common"
|
||||
)
|
||||
|
||||
var maxKeys = 1_000_000
|
||||
var pubkeyCache = lruwrpr.New(maxKeys)
|
||||
var pubkeyCache *nonblocking.LRU[[48]byte, common.PublicKey]
|
||||
|
||||
// PublicKey used in the BLS signature scheme.
|
||||
type PublicKey struct {
|
||||
@ -27,7 +27,7 @@ func PublicKeyFromBytes(pubKey []byte) (common.PublicKey, error) {
|
||||
}
|
||||
newKey := (*[fieldparams.BLSPubkeyLength]byte)(pubKey)
|
||||
if cv, ok := pubkeyCache.Get(*newKey); ok {
|
||||
return cv.(*PublicKey).Copy(), nil
|
||||
return cv.Copy(), nil
|
||||
}
|
||||
// Subgroup check NOT done when decompressing pubkey.
|
||||
p := new(blstPublicKey).Uncompress(pubKey)
|
||||
|
Loading…
Reference in New Issue
Block a user