mirror of
https://github.com/OffchainLabs/prysm.git
synced 2026-01-09 15:37:56 -05:00
Remove unused blobs bundle cache and usages (#14438)
This commit is contained in:
@@ -39,6 +39,7 @@ The format is based on Keep a Changelog, and this project adheres to Semantic Ve
|
||||
|
||||
### Removed
|
||||
- removed gRPC Gateway
|
||||
- Removed unused blobs bundle cache
|
||||
|
||||
### Fixed
|
||||
|
||||
|
||||
@@ -2,60 +2,13 @@ package validator
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"sync"
|
||||
|
||||
"github.com/prysmaticlabs/prysm/v5/consensus-types/blocks"
|
||||
"github.com/prysmaticlabs/prysm/v5/consensus-types/interfaces"
|
||||
"github.com/prysmaticlabs/prysm/v5/consensus-types/primitives"
|
||||
enginev1 "github.com/prysmaticlabs/prysm/v5/proto/engine/v1"
|
||||
ethpb "github.com/prysmaticlabs/prysm/v5/proto/prysm/v1alpha1"
|
||||
"github.com/prysmaticlabs/prysm/v5/runtime/version"
|
||||
)
|
||||
|
||||
var bundleCache = &blobsBundleCache{}
|
||||
|
||||
// BlobsBundleCache holds the KZG commitments and other relevant sidecar data for a local beacon block.
|
||||
type blobsBundleCache struct {
|
||||
sync.Mutex
|
||||
slot primitives.Slot
|
||||
bundle *enginev1.BlobsBundle
|
||||
}
|
||||
|
||||
// add adds a blobs bundle to the cache.
|
||||
// same slot overwrites the previous bundle.
|
||||
func (c *blobsBundleCache) add(slot primitives.Slot, bundle *enginev1.BlobsBundle) {
|
||||
c.Lock()
|
||||
defer c.Unlock()
|
||||
|
||||
if slot >= c.slot {
|
||||
c.bundle = bundle
|
||||
c.slot = slot
|
||||
}
|
||||
}
|
||||
|
||||
// get gets a blobs bundle from the cache.
|
||||
func (c *blobsBundleCache) get(slot primitives.Slot) *enginev1.BlobsBundle {
|
||||
c.Lock()
|
||||
defer c.Unlock()
|
||||
|
||||
if c.slot == slot {
|
||||
return c.bundle
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// prune acquires the lock before pruning.
|
||||
func (c *blobsBundleCache) prune(minSlot primitives.Slot) {
|
||||
c.Lock()
|
||||
defer c.Unlock()
|
||||
|
||||
if minSlot > c.slot {
|
||||
c.slot = 0
|
||||
c.bundle = nil
|
||||
}
|
||||
}
|
||||
|
||||
// BuildBlobSidecars given a block, builds the blob sidecars for the block.
|
||||
func BuildBlobSidecars(blk interfaces.SignedBeaconBlock, blobs [][]byte, kzgProofs [][]byte) ([]*ethpb.BlobSidecar, error) {
|
||||
if blk.Version() < version.Deneb {
|
||||
|
||||
@@ -6,44 +6,11 @@ import (
|
||||
"github.com/ethereum/go-ethereum/common/hexutil"
|
||||
fieldparams "github.com/prysmaticlabs/prysm/v5/config/fieldparams"
|
||||
"github.com/prysmaticlabs/prysm/v5/consensus-types/blocks"
|
||||
"github.com/prysmaticlabs/prysm/v5/consensus-types/primitives"
|
||||
"github.com/prysmaticlabs/prysm/v5/encoding/bytesutil"
|
||||
enginev1 "github.com/prysmaticlabs/prysm/v5/proto/engine/v1"
|
||||
"github.com/prysmaticlabs/prysm/v5/testing/require"
|
||||
"github.com/prysmaticlabs/prysm/v5/testing/util"
|
||||
)
|
||||
|
||||
func TestAdd(t *testing.T) {
|
||||
slot := primitives.Slot(1)
|
||||
bundle := &enginev1.BlobsBundle{KzgCommitments: [][]byte{{'a'}}}
|
||||
bundleCache.add(slot, bundle)
|
||||
require.Equal(t, bundleCache.bundle, bundle)
|
||||
|
||||
slot = primitives.Slot(2)
|
||||
bundle = &enginev1.BlobsBundle{KzgCommitments: [][]byte{{'b'}}}
|
||||
bundleCache.add(slot, bundle)
|
||||
require.Equal(t, bundleCache.bundle, bundle)
|
||||
}
|
||||
|
||||
func TestGet(t *testing.T) {
|
||||
slot := primitives.Slot(3)
|
||||
bundle := &enginev1.BlobsBundle{KzgCommitments: [][]byte{{'a'}}}
|
||||
bundleCache.add(slot, bundle)
|
||||
require.Equal(t, bundleCache.get(slot), bundle)
|
||||
}
|
||||
|
||||
func TestPrune(t *testing.T) {
|
||||
slot1 := primitives.Slot(4)
|
||||
bundle1 := &enginev1.BlobsBundle{KzgCommitments: [][]byte{{'a'}}}
|
||||
|
||||
bundleCache.add(slot1, bundle1)
|
||||
bundleCache.prune(slot1 + 1)
|
||||
|
||||
if bundleCache.get(slot1) != nil {
|
||||
t.Errorf("Prune did not remove the bundle at slot1")
|
||||
}
|
||||
}
|
||||
|
||||
func TestServer_buildBlobSidecars(t *testing.T) {
|
||||
kzgCommitments := [][]byte{bytesutil.PadTo([]byte{'a'}, 48), bytesutil.PadTo([]byte{'b'}, 48)}
|
||||
blk, err := blocks.NewSignedBeaconBlock(util.NewBeaconBlockDeneb())
|
||||
|
||||
@@ -32,7 +32,6 @@ import (
|
||||
"github.com/prysmaticlabs/prysm/v5/network/forks"
|
||||
ethpb "github.com/prysmaticlabs/prysm/v5/proto/prysm/v1alpha1"
|
||||
"github.com/prysmaticlabs/prysm/v5/runtime/version"
|
||||
"github.com/prysmaticlabs/prysm/v5/time/slots"
|
||||
"google.golang.org/grpc/codes"
|
||||
"google.golang.org/grpc/status"
|
||||
"google.golang.org/protobuf/types/known/emptypb"
|
||||
@@ -207,25 +206,3 @@ func (vs *Server) WaitForChainStart(_ *emptypb.Empty, stream ethpb.BeaconNodeVal
|
||||
}
|
||||
return stream.Send(res)
|
||||
}
|
||||
|
||||
// PruneBlobsBundleCacheRoutine prunes the blobs bundle cache at 6s mark of the slot.
|
||||
func (vs *Server) PruneBlobsBundleCacheRoutine() {
|
||||
go func() {
|
||||
clock, err := vs.ClockWaiter.WaitForClock(vs.Ctx)
|
||||
if err != nil {
|
||||
log.WithError(err).Error("PruneBlobsBundleCacheRoutine failed to receive genesis data")
|
||||
return
|
||||
}
|
||||
|
||||
pruneInterval := time.Second * time.Duration(params.BeaconConfig().SecondsPerSlot/2)
|
||||
ticker := slots.NewSlotTickerWithIntervals(clock.GenesisTime(), []time.Duration{pruneInterval})
|
||||
for {
|
||||
select {
|
||||
case <-vs.Ctx.Done():
|
||||
return
|
||||
case slotInterval := <-ticker.C():
|
||||
bundleCache.prune(slotInterval.Slot)
|
||||
}
|
||||
}
|
||||
}()
|
||||
}
|
||||
|
||||
@@ -347,7 +347,6 @@ var _ stategen.CurrentSlotter = blockchain.ChainInfoFetcher(nil)
|
||||
// Start the gRPC server.
|
||||
func (s *Service) Start() {
|
||||
grpcprometheus.EnableHandlingTimeHistogram()
|
||||
s.validatorServer.PruneBlobsBundleCacheRoutine()
|
||||
go func() {
|
||||
if s.listener != nil {
|
||||
if err := s.grpcServer.Serve(s.listener); err != nil {
|
||||
|
||||
Reference in New Issue
Block a user