prysm-pulse/crypto/bls/blst/init.go
Raul Jordan e9c8e84618
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>
2023-07-22 04:37:53 +00:00

28 lines
730 B
Go

//go:build ((linux && amd64) || (linux && arm64) || (darwin && amd64) || (darwin && arm64) || (windows && amd64)) && !blst_disabled
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"
)
func init() {
// Reserve 1 core for general application work
maxProcs := runtime.GOMAXPROCS(0) - 1
if maxProcs <= 0 {
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
}