mirror of
https://github.com/OffchainLabs/prysm.git
synced 2026-01-09 15:37:56 -05:00
Passing block as arugment for sidecar validation (#13062)
This commit is contained in:
@@ -197,7 +197,7 @@ func (s *Service) processAndBroadcastBlock(ctx context.Context, b interfaces.Rea
|
||||
peers := s.getBestPeers()
|
||||
peerCount := len(peers)
|
||||
if peerCount > 0 {
|
||||
if err := s.requestPendingBlobs(ctx, b.Block(), blkRoot, peers[rand.NewGenerator().Int()%peerCount]); err != nil {
|
||||
if err := s.requestPendingBlobs(ctx, b, blkRoot, peers[rand.NewGenerator().Int()%peerCount]); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,7 +13,6 @@ import (
|
||||
"github.com/prysmaticlabs/prysm/v4/config/params"
|
||||
"github.com/prysmaticlabs/prysm/v4/consensus-types/blocks"
|
||||
"github.com/prysmaticlabs/prysm/v4/consensus-types/interfaces"
|
||||
"github.com/prysmaticlabs/prysm/v4/encoding/bytesutil"
|
||||
eth "github.com/prysmaticlabs/prysm/v4/proto/prysm/v1alpha1"
|
||||
"github.com/prysmaticlabs/prysm/v4/runtime/version"
|
||||
)
|
||||
@@ -46,7 +45,7 @@ func (s *Service) sendRecentBeaconBlocksRequest(ctx context.Context, blockRoots
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if err := s.requestPendingBlobs(ctx, blk.Block(), blkRoot, id); err != nil {
|
||||
if err := s.requestPendingBlobs(ctx, blk, blkRoot, id); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
@@ -118,12 +117,12 @@ func (s *Service) beaconBlocksRootRPCHandler(ctx context.Context, msg interface{
|
||||
}
|
||||
|
||||
// requestPendingBlobs handles the request for pending blobs based on the given beacon block.
|
||||
func (s *Service) requestPendingBlobs(ctx context.Context, block interfaces.ReadOnlyBeaconBlock, blockRoot [32]byte, peerID peer.ID) error {
|
||||
func (s *Service) requestPendingBlobs(ctx context.Context, block interfaces.ReadOnlySignedBeaconBlock, blockRoot [32]byte, peerID peer.ID) error {
|
||||
if block.Version() < version.Deneb {
|
||||
return nil // Block before deneb has no blob.
|
||||
}
|
||||
|
||||
commitments, err := block.Body().BlobKzgCommitments()
|
||||
commitments, err := block.Block().Body().BlobKzgCommitments()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -142,11 +141,11 @@ func (s *Service) requestPendingBlobs(ctx context.Context, block interfaces.Read
|
||||
return err
|
||||
}
|
||||
|
||||
return s.sendAndSaveBlobSidecars(ctx, request, contextByte, peerID)
|
||||
return s.sendAndSaveBlobSidecars(ctx, request, contextByte, peerID, block)
|
||||
}
|
||||
|
||||
// sendAndSaveBlobSidecars sends the blob request and saves received sidecars.
|
||||
func (s *Service) sendAndSaveBlobSidecars(ctx context.Context, request types.BlobSidecarsByRootReq, contextByte ContextByteVersions, peerID peer.ID) error {
|
||||
func (s *Service) sendAndSaveBlobSidecars(ctx context.Context, request types.BlobSidecarsByRootReq, contextByte ContextByteVersions, peerID peer.ID, block interfaces.ReadOnlySignedBeaconBlock) error {
|
||||
if len(request) == 0 {
|
||||
return nil
|
||||
}
|
||||
@@ -156,10 +155,6 @@ func (s *Service) sendAndSaveBlobSidecars(ctx context.Context, request types.Blo
|
||||
return err
|
||||
}
|
||||
|
||||
block, err := s.cfg.beaconDB.Block(ctx, bytesutil.ToBytes32(request[0].BlockRoot))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
RoBlock, err := blocks.NewROBlock(block)
|
||||
if err != nil {
|
||||
return err
|
||||
|
||||
@@ -295,12 +295,12 @@ func TestRecentBeaconBlocksRPCHandler_HandleZeroBlocks(t *testing.T) {
|
||||
func TestRequestPendingBlobs(t *testing.T) {
|
||||
s := &Service{}
|
||||
t.Run("old block should not fail", func(t *testing.T) {
|
||||
b, err := blocks.NewBeaconBlock(util.NewBeaconBlock().Block)
|
||||
b, err := blocks.NewSignedBeaconBlock(util.NewBeaconBlock())
|
||||
require.NoError(t, err)
|
||||
require.NoError(t, s.requestPendingBlobs(context.Background(), b, [32]byte{}, "test"))
|
||||
})
|
||||
t.Run("empty commitment block should not fail", func(t *testing.T) {
|
||||
b, err := blocks.NewBeaconBlock(util.NewBeaconBlockDeneb().Block)
|
||||
b, err := blocks.NewSignedBeaconBlock(util.NewBeaconBlock())
|
||||
require.NoError(t, err)
|
||||
require.NoError(t, s.requestPendingBlobs(context.Background(), b, [32]byte{}, "test"))
|
||||
})
|
||||
@@ -330,7 +330,7 @@ func TestRequestPendingBlobs(t *testing.T) {
|
||||
}
|
||||
b := util.NewBeaconBlockDeneb()
|
||||
b.Block.Body.BlobKzgCommitments = make([][]byte, 1)
|
||||
b1, err := blocks.NewBeaconBlock(b.Block)
|
||||
b1, err := blocks.NewSignedBeaconBlock(b)
|
||||
require.NoError(t, err)
|
||||
require.ErrorContains(t, "protocols not supported", s.requestPendingBlobs(context.Background(), b1, [32]byte{}, p2.PeerID()))
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user