mirror of
https://github.com/OffchainLabs/prysm.git
synced 2026-01-11 06:18:05 -05:00
Compare commits
7 Commits
v4.0.4-rc.
...
replaceWit
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a8572352e1 | ||
|
|
1848d76796 | ||
|
|
b4f1fea029 | ||
|
|
f1b88d005d | ||
|
|
ee612d958a | ||
|
|
09e22538f9 | ||
|
|
3b9e974a45 |
@@ -4,14 +4,14 @@
|
||||
[](https://goreportcard.com/report/github.com/prysmaticlabs/prysm)
|
||||
[](https://github.com/ethereum/consensus-specs/tree/v1.3.0)
|
||||
[](https://github.com/ethereum/execution-apis/tree/v1.0.0-beta.2/src/engine)
|
||||
[](https://discord.gg/CTYGPUJ)
|
||||
[](https://discord.gg/prysmaticlabs)
|
||||
[](https://www.gitpoap.io/gh/prysmaticlabs/prysm)
|
||||
|
||||
This is the core repository for Prysm, a [Golang](https://golang.org/) implementation of the [Ethereum Consensus](https://ethereum.org/en/eth2/) specification, developed by [Prysmatic Labs](https://prysmaticlabs.com). See the [Changelog](https://github.com/prysmaticlabs/prysm/releases) for details of the latest releases and upcoming breaking changes.
|
||||
|
||||
### Getting Started
|
||||
|
||||
A detailed set of installation and usage instructions as well as breakdowns of each individual component are available in the [official documentation portal](https://docs.prylabs.network). If you still have questions, feel free to stop by our [Discord](https://discord.gg/CTYGPUJ).
|
||||
A detailed set of installation and usage instructions as well as breakdowns of each individual component are available in the [official documentation portal](https://docs.prylabs.network). If you still have questions, feel free to stop by our [Discord](https://discord.gg/prysmaticlabs).
|
||||
|
||||
### Staking on Mainnet
|
||||
|
||||
|
||||
@@ -69,7 +69,7 @@ func (s *Service) getAttPreState(ctx context.Context, c *ethpb.Checkpoint) (stat
|
||||
return nil, errors.Wrap(err, "could not check checkpoint condition in forkchoice")
|
||||
}
|
||||
if !ok {
|
||||
return nil, ErrNotCheckpoint
|
||||
return nil, errors.Wrap(ErrNotCheckpoint, fmt.Sprintf("epoch %d root %#x", c.Epoch, c.Root))
|
||||
}
|
||||
|
||||
// Fallback to state regeneration.
|
||||
|
||||
@@ -180,7 +180,7 @@ func TestStore_SaveCheckpointState(t *testing.T) {
|
||||
require.NoError(t, service.cfg.BeaconDB.SaveStateSummary(ctx, ðpb.StateSummary{Root: bytesutil.PadTo([]byte{'B'}, fieldparams.RootLength)}))
|
||||
|
||||
s2, err := service.getAttPreState(ctx, cp2)
|
||||
require.ErrorIs(t, ErrNotCheckpoint, err)
|
||||
require.ErrorContains(t, "epoch 2 root 0x4200000000000000000000000000000000000000000000000000000000000000: not a checkpoint in forkchoice", err)
|
||||
|
||||
st, root, err = prepareForkchoiceState(ctx, 33, [32]byte(cp2.Root), [32]byte(cp1.Root), [32]byte{'R'}, cp2, cp2)
|
||||
require.NoError(t, err)
|
||||
|
||||
@@ -742,6 +742,7 @@ func (b *BeaconNode) registerSlasherService() error {
|
||||
SlashingPoolInserter: b.slashingsPool,
|
||||
SyncChecker: syncService,
|
||||
HeadStateFetcher: chainService,
|
||||
ClockWaiter: b.clockWaiter,
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
|
||||
@@ -4,16 +4,16 @@ package blst
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"sync"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
lruwrpr "github.com/prysmaticlabs/prysm/v4/cache/lru"
|
||||
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 pubkeyLock sync.RWMutex
|
||||
var pubkeyMap = make(map[[48]byte]*PublicKey)
|
||||
|
||||
// PublicKey used in the BLS signature scheme.
|
||||
type PublicKey struct {
|
||||
@@ -26,9 +26,13 @@ func PublicKeyFromBytes(pubKey []byte) (common.PublicKey, error) {
|
||||
return nil, fmt.Errorf("public key must be %d bytes", params.BeaconConfig().BLSPubkeyLength)
|
||||
}
|
||||
newKey := (*[fieldparams.BLSPubkeyLength]byte)(pubKey)
|
||||
if cv, ok := pubkeyCache.Get(*newKey); ok {
|
||||
return cv.(*PublicKey).Copy(), nil
|
||||
pubkeyLock.RLock()
|
||||
if cv, ok := pubkeyMap[*newKey]; ok {
|
||||
pubkeyLock.RUnlock()
|
||||
return cv.Copy(), nil
|
||||
}
|
||||
pubkeyLock.RUnlock()
|
||||
|
||||
// Subgroup check NOT done when decompressing pubkey.
|
||||
p := new(blstPublicKey).Uncompress(pubKey)
|
||||
if p == nil {
|
||||
@@ -41,8 +45,16 @@ func PublicKeyFromBytes(pubKey []byte) (common.PublicKey, error) {
|
||||
}
|
||||
pubKeyObj := &PublicKey{p: p}
|
||||
copiedKey := pubKeyObj.Copy()
|
||||
assertedKey, ok := (copiedKey).(*PublicKey)
|
||||
// Should be impossible to happen, this is checked
|
||||
// to satisfy lint tools.
|
||||
if !ok {
|
||||
return pubKeyObj, nil
|
||||
}
|
||||
cacheKey := *newKey
|
||||
pubkeyCache.Add(cacheKey, copiedKey)
|
||||
pubkeyLock.Lock()
|
||||
pubkeyMap[cacheKey] = assertedKey
|
||||
pubkeyLock.Unlock()
|
||||
return pubKeyObj, nil
|
||||
}
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@ package blst_test
|
||||
import (
|
||||
"bytes"
|
||||
"errors"
|
||||
"sync"
|
||||
"testing"
|
||||
|
||||
"github.com/prysmaticlabs/prysm/v4/crypto/bls/blst"
|
||||
@@ -98,26 +99,51 @@ func TestPublicKeysEmpty(t *testing.T) {
|
||||
require.ErrorContains(t, "nil or empty public keys", err)
|
||||
}
|
||||
|
||||
func TestPublicKeyMap(t *testing.T) {
|
||||
priv, err := blst.RandKey()
|
||||
require.NoError(t, err)
|
||||
pubkeyA := priv.PublicKey().Marshal()
|
||||
|
||||
priv2, err := blst.RandKey()
|
||||
require.NoError(t, err)
|
||||
pubkeyB := priv2.PublicKey().Marshal()
|
||||
km := blst.KeyMap()
|
||||
_, ok := km[[48]byte(pubkeyA)]
|
||||
require.Equal(t, false, ok, "pubkey a exists")
|
||||
_, ok = km[[48]byte(pubkeyB)]
|
||||
require.Equal(t, false, ok, "pubkey b exists")
|
||||
wg := new(sync.WaitGroup)
|
||||
wg.Add(1)
|
||||
go func() {
|
||||
_, err := blst.PublicKeyFromBytes(pubkeyA)
|
||||
require.NoError(t, err)
|
||||
wg.Done()
|
||||
}()
|
||||
|
||||
wg.Add(1)
|
||||
go func() {
|
||||
_, err := blst.PublicKeyFromBytes(pubkeyB)
|
||||
require.NoError(t, err)
|
||||
wg.Done()
|
||||
}()
|
||||
wg.Wait()
|
||||
|
||||
km = blst.KeyMap()
|
||||
_, ok = km[[48]byte(pubkeyA)]
|
||||
require.Equal(t, true, ok, "pubkey a does not exist")
|
||||
_, ok = km[[48]byte(pubkeyB)]
|
||||
require.Equal(t, true, ok, "pubkey b does not exist")
|
||||
|
||||
}
|
||||
|
||||
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)
|
||||
}
|
||||
})
|
||||
|
||||
for i := 0; i < b.N; i++ {
|
||||
_, err := blst.PublicKeyFromBytes(pubkeyBytes)
|
||||
require.NoError(b, err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,13 +1,8 @@
|
||||
package blst
|
||||
|
||||
// Note: These functions are for tests to access private globals, such as pubkeyCache.
|
||||
// Note: These functions are for tests to access private globals, such as pubkeyMap.
|
||||
|
||||
// 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)
|
||||
// KeyMap returns the pubkey cache.
|
||||
func KeyMap() map[[48]byte]*PublicKey {
|
||||
return pubkeyMap
|
||||
}
|
||||
|
||||
@@ -18,3 +18,7 @@ latest_version_tag=$(./hack/latest_version_tag.sh)
|
||||
echo "STABLE_VERSION_TAG $latest_version_tag"
|
||||
echo "STABLE_COMMIT_SHA $commit_sha"
|
||||
echo "STABLE_GIT_TAG $latest_version_tag"
|
||||
|
||||
echo DOCKER_TAG "$(git rev-parse --abbrev-ref HEAD)-$(git rev-parse --short=6 HEAD)"
|
||||
echo DATE "$(date --rfc-3339=seconds --utc)"
|
||||
echo DATE_UNIX "$(date --utc +%s)"
|
||||
|
||||
@@ -4,6 +4,7 @@ import (
|
||||
"context"
|
||||
"flag"
|
||||
"fmt"
|
||||
"math"
|
||||
"time"
|
||||
|
||||
"github.com/prysmaticlabs/prysm/v4/config/params"
|
||||
@@ -25,7 +26,7 @@ func main() {
|
||||
flag.Parse()
|
||||
ctx := context.Background()
|
||||
|
||||
cc, err := grpc.DialContext(ctx, *beacon, grpc.WithInsecure())
|
||||
cc, err := grpc.DialContext(ctx, *beacon, grpc.WithInsecure(), grpc.WithDefaultCallOptions(grpc.MaxCallRecvMsgSize(math.MaxInt64)))
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
@@ -82,6 +83,8 @@ func wrapBlock(b *v1alpha1.BeaconBlockContainer) interfaces.ReadOnlyBeaconBlock
|
||||
wb, err = blocks.NewSignedBeaconBlock(bb.AltairBlock)
|
||||
case *v1alpha1.BeaconBlockContainer_BellatrixBlock:
|
||||
wb, err = blocks.NewSignedBeaconBlock(bb.BellatrixBlock)
|
||||
case *v1alpha1.BeaconBlockContainer_CapellaBlock:
|
||||
wb, err = blocks.NewSignedBeaconBlock(bb.CapellaBlock)
|
||||
}
|
||||
if err != nil {
|
||||
panic("no block")
|
||||
|
||||
Reference in New Issue
Block a user