Skip to content

Commit

Permalink
Remove unused blobs bundle cache and usages (#14438)
Browse files Browse the repository at this point in the history
  • Loading branch information
terencechain committed Sep 12, 2024
1 parent 875e3e5 commit df4ca54
Show file tree
Hide file tree
Showing 5 changed files with 1 addition and 104 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
47 changes: 0 additions & 47 deletions beacon-chain/rpc/prysm/v1alpha1/validator/proposer_deneb.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
33 changes: 0 additions & 33 deletions beacon-chain/rpc/prysm/v1alpha1/validator/proposer_deneb_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down
23 changes: 0 additions & 23 deletions beacon-chain/rpc/prysm/v1alpha1/validator/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
}
}
}()
}
1 change: 0 additions & 1 deletion beacon-chain/rpc/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit df4ca54

Please sign in to comment.