Update Bazel Grail Toolchain SHA and Protect Digest Map with Lock (#11939)

* lock digest map

* imports

* toolchain update
This commit is contained in:
Raul Jordan 2023-01-30 17:40:48 -05:00 committed by GitHub
parent e8c25effb0
commit 950d0c0282
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 1 deletions

View File

@ -15,7 +15,7 @@ http_archive(
http_archive(
name = "com_grail_bazel_toolchain",
sha256 = "b210fc8e58782ef171f428bfc850ed7179bdd805543ebd1aa144b9c93489134f",
sha256 = "6889426c946f1b948a22468aaa73252d477c306cb550d5db09c330af9a810cee",
strip_prefix = "bazel-toolchain-83e69ba9e4b4fdad0d1d057fcb87addf77c281c9",
urls = ["https://github.com/grailbio/bazel-toolchain/archive/83e69ba9e4b4fdad0d1d057fcb87addf77c281c9.tar.gz"],
)

View File

@ -1,6 +1,8 @@
package signing
import (
"sync"
"github.com/pkg/errors"
fssz "github.com/prysmaticlabs/fastssz"
"github.com/prysmaticlabs/prysm/v3/beacon-chain/state"
@ -19,6 +21,7 @@ const DomainByteLength = 4
// digestMap maps the fork version and genesis validator root to the
// resultant fork digest.
var digestMapLock sync.RWMutex
var digestMap = make(map[string][32]byte)
// ErrSigFailedToVerify returns when a signature of a block object(ie attestation, slashing, exit... etc)
@ -244,9 +247,12 @@ func domain(domainType [DomainByteLength]byte, forkDataRoot []byte) []byte {
// genesis_validators_root=genesis_validators_root,
// ))
func computeForkDataRoot(version, root []byte) ([32]byte, error) {
digestMapLock.RLock()
if val, ok := digestMap[string(version)+string(root)]; ok {
digestMapLock.RUnlock()
return val, nil
}
digestMapLock.RUnlock()
r, err := (&ethpb.ForkData{
CurrentVersion: version,
GenesisValidatorsRoot: root,
@ -257,7 +263,9 @@ func computeForkDataRoot(version, root []byte) ([32]byte, error) {
// Cache result of digest computation
// as this is a hot path and doesn't need
// to be constantly computed.
digestMapLock.Lock()
digestMap[string(version)+string(root)] = r
digestMapLock.Unlock()
return r, nil
}