Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 11 additions & 11 deletions beacon-chain/execution/engine_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ type EngineCaller interface {
ForkchoiceUpdated(
ctx context.Context, state *pb.ForkchoiceState, attrs payloadattribute.Attributer,
) (*pb.PayloadIDBytes, []byte, error)
GetPayload(ctx context.Context, payloadId [8]byte, slot primitives.Slot) (interfaces.ExecutionData, *pb.BlobsBundle, error)
GetPayload(ctx context.Context, payloadId [8]byte, slot primitives.Slot) (interfaces.ExecutionData, *pb.BlobsBundle, bool, error)
ExchangeTransitionConfiguration(
ctx context.Context, cfg *pb.TransitionConfiguration,
) error
Expand Down Expand Up @@ -231,7 +231,7 @@ func (s *Service) ForkchoiceUpdated(

// GetPayload calls the engine_getPayloadVX method via JSON-RPC.
// It returns the execution data as well as the blobs bundle.
func (s *Service) GetPayload(ctx context.Context, payloadId [8]byte, slot primitives.Slot) (interfaces.ExecutionData, *pb.BlobsBundle, error) {
func (s *Service) GetPayload(ctx context.Context, payloadId [8]byte, slot primitives.Slot) (interfaces.ExecutionData, *pb.BlobsBundle, bool, error) {
ctx, span := trace.StartSpan(ctx, "powchain.engine-api-client.GetPayload")
defer span.End()
start := time.Now()
Expand All @@ -247,38 +247,38 @@ func (s *Service) GetPayload(ctx context.Context, payloadId [8]byte, slot primit
result := &pb.ExecutionPayloadDenebWithValueAndBlobsBundle{}
err := s.rpcClient.CallContext(ctx, result, GetPayloadMethodV3, pb.PayloadIDBytes(payloadId))
if err != nil {
return nil, nil, handleRPCError(err)
return nil, nil, false, handleRPCError(err)
}
ed, err := blocks.WrappedExecutionPayloadDeneb(result.Payload, blocks.PayloadValueToGwei(result.Value))
if err != nil {
return nil, nil, err
return nil, nil, false, err
}
return ed, result.BlobsBundle, nil
return ed, result.BlobsBundle, result.ShouldOverrideBuilder, nil
}

if slots.ToEpoch(slot) >= params.BeaconConfig().CapellaForkEpoch {
result := &pb.ExecutionPayloadCapellaWithValue{}
err := s.rpcClient.CallContext(ctx, result, GetPayloadMethodV2, pb.PayloadIDBytes(payloadId))
if err != nil {
return nil, nil, handleRPCError(err)
return nil, nil, false, handleRPCError(err)
}
ed, err := blocks.WrappedExecutionPayloadCapella(result.Payload, blocks.PayloadValueToGwei(result.Value))
if err != nil {
return nil, nil, err
return nil, nil, false, err
}
return ed, nil, nil
return ed, nil, false, nil
}

result := &pb.ExecutionPayload{}
err := s.rpcClient.CallContext(ctx, result, GetPayloadMethod, pb.PayloadIDBytes(payloadId))
if err != nil {
return nil, nil, handleRPCError(err)
return nil, nil, false, handleRPCError(err)
}
ed, err := blocks.WrappedExecutionPayload(result)
if err != nil {
return nil, nil, err
return nil, nil, false, err
}
return ed, nil, nil
return ed, nil, false, nil
}

// ExchangeTransitionConfiguration calls the engine_exchangeTransitionConfigurationV1 method via JSON-RPC.
Expand Down
16 changes: 11 additions & 5 deletions beacon-chain/execution/engine_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,9 @@ func TestClient_IPC(t *testing.T) {
want, ok := fix["ExecutionPayload"].(*pb.ExecutionPayload)
require.Equal(t, true, ok)
payloadId := [8]byte{1}
resp, _, err := srv.GetPayload(ctx, payloadId, 1)
resp, _, override, err := srv.GetPayload(ctx, payloadId, 1)
require.NoError(t, err)
require.Equal(t, false, override)
resPb, err := resp.PbBellatrix()
require.NoError(t, err)
require.DeepEqual(t, want, resPb)
Expand All @@ -85,8 +86,9 @@ func TestClient_IPC(t *testing.T) {
want, ok := fix["ExecutionPayloadCapellaWithValue"].(*pb.ExecutionPayloadCapellaWithValue)
require.Equal(t, true, ok)
payloadId := [8]byte{1}
resp, _, err := srv.GetPayload(ctx, payloadId, params.BeaconConfig().SlotsPerEpoch)
resp, _, override, err := srv.GetPayload(ctx, payloadId, params.BeaconConfig().SlotsPerEpoch)
require.NoError(t, err)
require.Equal(t, false, override)
resPb, err := resp.PbCapella()
require.NoError(t, err)
require.DeepEqual(t, want, resPb)
Expand Down Expand Up @@ -204,8 +206,9 @@ func TestClient_HTTP(t *testing.T) {
client.rpcClient = rpcClient

// We call the RPC method via HTTP and expect a proper result.
resp, _, err := client.GetPayload(ctx, payloadId, 1)
resp, _, override, err := client.GetPayload(ctx, payloadId, 1)
require.NoError(t, err)
require.Equal(t, false, override)
pb, err := resp.PbBellatrix()
require.NoError(t, err)
require.DeepEqual(t, want, pb)
Expand Down Expand Up @@ -248,8 +251,9 @@ func TestClient_HTTP(t *testing.T) {
client.rpcClient = rpcClient

// We call the RPC method via HTTP and expect a proper result.
resp, _, err := client.GetPayload(ctx, payloadId, params.BeaconConfig().SlotsPerEpoch)
resp, _, override, err := client.GetPayload(ctx, payloadId, params.BeaconConfig().SlotsPerEpoch)
require.NoError(t, err)
require.Equal(t, false, override)
pb, err := resp.PbCapella()
require.NoError(t, err)
require.DeepEqual(t, want.ExecutionPayload.BlockHash.Bytes(), pb.BlockHash)
Expand Down Expand Up @@ -301,8 +305,9 @@ func TestClient_HTTP(t *testing.T) {
client.rpcClient = rpcClient

// We call the RPC method via HTTP and expect a proper result.
resp, blobsBundle, err := client.GetPayload(ctx, payloadId, 2*params.BeaconConfig().SlotsPerEpoch)
resp, blobsBundle, override, err := client.GetPayload(ctx, payloadId, 2*params.BeaconConfig().SlotsPerEpoch)
require.NoError(t, err)
require.Equal(t, true, override)
g, err := resp.ExcessDataGas()
require.NoError(t, err)
require.DeepEqual(t, uint64(3), g)
Expand Down Expand Up @@ -1459,6 +1464,7 @@ func fixtures() map[string]interface{} {
dgu := hexutil.Uint64(2)
edg := hexutil.Uint64(3)
executionPayloadWithValueFixtureDeneb := &pb.GetPayloadV3ResponseJson{
ShouldOverrideBuilder: true,
ExecutionPayload: &pb.ExecutionPayloadDenebJSON{
ParentHash: &common.Hash{'a'},
FeeRecipient: &common.Address{'b'},
Expand Down
15 changes: 8 additions & 7 deletions beacon-chain/execution/testing/mock_engine_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ type EngineClient struct {
NumReconstructedPayloads uint64
TerminalBlockHash []byte
TerminalBlockHashExists bool
BuilderOverride bool
OverrideValidHash [32]byte
BlockValue uint64
BlobsBundle *pb.BlobsBundle
Expand All @@ -60,26 +61,26 @@ func (e *EngineClient) ForkchoiceUpdated(
}

// GetPayload --
func (e *EngineClient) GetPayload(_ context.Context, _ [8]byte, s primitives.Slot) (interfaces.ExecutionData, *pb.BlobsBundle, error) {
func (e *EngineClient) GetPayload(_ context.Context, _ [8]byte, s primitives.Slot) (interfaces.ExecutionData, *pb.BlobsBundle, bool, error) {
if slots.ToEpoch(s) >= params.BeaconConfig().DenebForkEpoch {
ed, err := blocks.WrappedExecutionPayloadDeneb(e.ExecutionPayloadDeneb, math.Gwei(e.BlockValue))
if err != nil {
return nil, nil, err
return nil, nil, false, err
}
return ed, e.BlobsBundle, nil
return ed, e.BlobsBundle, e.BuilderOverride, nil
}
if slots.ToEpoch(s) >= params.BeaconConfig().CapellaForkEpoch {
ed, err := blocks.WrappedExecutionPayloadCapella(e.ExecutionPayloadCapella, math.Gwei(e.BlockValue))
if err != nil {
return nil, nil, err
return nil, nil, false, err
}
return ed, nil, nil
return ed, nil, e.BuilderOverride, nil
}
p, err := blocks.WrappedExecutionPayload(e.ExecutionPayload)
if err != nil {
return nil, nil, err
return nil, nil, false, err
}
return p, nil, e.ErrGetPayload
return p, nil, e.BuilderOverride, e.ErrGetPayload
}

// ExchangeTransitionConfiguration --
Expand Down
16 changes: 11 additions & 5 deletions beacon-chain/rpc/prysm/v1alpha1/validator/proposer.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"github.com/prysmaticlabs/prysm/v4/consensus-types/blocks"
"github.com/prysmaticlabs/prysm/v4/consensus-types/interfaces"
"github.com/prysmaticlabs/prysm/v4/consensus-types/primitives"
enginev1 "github.com/prysmaticlabs/prysm/v4/proto/engine/v1"
ethpb "github.com/prysmaticlabs/prysm/v4/proto/prysm/v1alpha1"
"github.com/prysmaticlabs/prysm/v4/runtime/version"
"github.com/prysmaticlabs/prysm/v4/time/slots"
Expand Down Expand Up @@ -143,15 +144,20 @@ func (vs *Server) GetBeaconBlock(ctx context.Context, req *ethpb.BlockRequest) (
vs.setBlsToExecData(sBlk, head)
}()

localPayload, blobsBundle, err := vs.getLocalPayloadAndBlobs(ctx, sBlk.Block(), head)
localPayload, blobsBundle, overrideBuilder, err := vs.getLocalPayloadAndBlobs(ctx, sBlk.Block(), head)
if err != nil {
return nil, status.Errorf(codes.Internal, "Could not get local payload: %v", err)
}

builderPayload, blindBlobsBundle, err := vs.getBuilderPayloadAndBlobs(ctx, sBlk.Block().Slot(), sBlk.Block().ProposerIndex())
if err != nil {
builderGetPayloadMissCount.Inc()
log.WithError(err).Error("Could not get builder payload")
// There's no reason to try to get a builder bid if local override is true.
var builderPayload interfaces.ExecutionData
var blindBlobsBundle *enginev1.BlindedBlobsBundle
if !overrideBuilder {
builderPayload, blindBlobsBundle, err = vs.getBuilderPayloadAndBlobs(ctx, sBlk.Block().Slot(), sBlk.Block().ProposerIndex())
if err != nil {
builderGetPayloadMissCount.Inc()
log.WithError(err).Error("Could not get builder payload")
}
}

if err := setExecutionData(ctx, sBlk, localPayload, builderPayload); err != nil {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ func TestServer_setExecutionData(t *testing.T) {
blk, err := blocks.NewSignedBeaconBlock(util.NewBeaconBlockCapella())
require.NoError(t, err)
b := blk.Block()
localPayload, _, err := vs.getLocalPayloadAndBlobs(ctx, b, capellaTransitionState)
localPayload, _, _, err := vs.getLocalPayloadAndBlobs(ctx, b, capellaTransitionState)
require.NoError(t, err)
builderPayload, _, err := vs.getBuilderPayloadAndBlobs(ctx, b.Slot(), b.ProposerIndex())
require.NoError(t, err)
Expand Down Expand Up @@ -137,7 +137,7 @@ func TestServer_setExecutionData(t *testing.T) {
vs.HeadFetcher = chain
b := blk.Block()

localPayload, _, err := vs.getLocalPayloadAndBlobs(ctx, b, capellaTransitionState)
localPayload, _, _, err := vs.getLocalPayloadAndBlobs(ctx, b, capellaTransitionState)
require.NoError(t, err)
builderPayload, _, err := vs.getBuilderPayloadAndBlobs(ctx, b.Slot(), b.ProposerIndex())
require.NoError(t, err)
Expand Down Expand Up @@ -199,7 +199,7 @@ func TestServer_setExecutionData(t *testing.T) {
vs.HeadFetcher = chain

b := blk.Block()
localPayload, _, err := vs.getLocalPayloadAndBlobs(ctx, b, capellaTransitionState)
localPayload, _, _, err := vs.getLocalPayloadAndBlobs(ctx, b, capellaTransitionState)
require.NoError(t, err)
builderPayload, _, err := vs.getBuilderPayloadAndBlobs(ctx, b.Slot(), b.ProposerIndex())
require.NoError(t, err)
Expand All @@ -213,7 +213,7 @@ func TestServer_setExecutionData(t *testing.T) {
require.NoError(t, err)
vs.ExecutionEngineCaller = &powtesting.EngineClient{PayloadIDBytes: id, ExecutionPayloadCapella: &v1.ExecutionPayloadCapella{BlockNumber: 3}, BlockValue: 2}
b := blk.Block()
localPayload, _, err := vs.getLocalPayloadAndBlobs(ctx, b, capellaTransitionState)
localPayload, _, _, err := vs.getLocalPayloadAndBlobs(ctx, b, capellaTransitionState)
require.NoError(t, err)
builderPayload, _, err := vs.getBuilderPayloadAndBlobs(ctx, b.Slot(), b.ProposerIndex())
require.NoError(t, err)
Expand All @@ -233,7 +233,7 @@ func TestServer_setExecutionData(t *testing.T) {
require.NoError(t, err)
vs.ExecutionEngineCaller = &powtesting.EngineClient{PayloadIDBytes: id, ExecutionPayloadCapella: &v1.ExecutionPayloadCapella{BlockNumber: 3}, BlockValue: 1}
b := blk.Block()
localPayload, _, err := vs.getLocalPayloadAndBlobs(ctx, b, capellaTransitionState)
localPayload, _, _, err := vs.getLocalPayloadAndBlobs(ctx, b, capellaTransitionState)
require.NoError(t, err)
builderPayload, _, err := vs.getBuilderPayloadAndBlobs(ctx, b.Slot(), b.ProposerIndex())
require.NoError(t, err)
Expand All @@ -254,7 +254,7 @@ func TestServer_setExecutionData(t *testing.T) {
}
vs.ExecutionEngineCaller = &powtesting.EngineClient{PayloadIDBytes: id, ExecutionPayloadCapella: &v1.ExecutionPayloadCapella{BlockNumber: 4}, BlockValue: 0}
b := blk.Block()
localPayload, _, err := vs.getLocalPayloadAndBlobs(ctx, b, capellaTransitionState)
localPayload, _, _, err := vs.getLocalPayloadAndBlobs(ctx, b, capellaTransitionState)
require.NoError(t, err)
builderPayload, _, err := vs.getBuilderPayloadAndBlobs(ctx, b.Slot(), b.ProposerIndex())
require.ErrorIs(t, consensus_types.ErrNilObjectWrapped, err) // Builder returns fault. Use local block
Expand Down Expand Up @@ -285,7 +285,7 @@ func TestServer_setExecutionData(t *testing.T) {
ExecutionPayloadDeneb: &v1.ExecutionPayloadDeneb{BlockNumber: 4},
BlockValue: 0}
blk.SetSlot(primitives.Slot(params.BeaconConfig().DenebForkEpoch) * params.BeaconConfig().SlotsPerEpoch)
localPayload, bb, err := vs.getLocalPayloadAndBlobs(ctx, blk.Block(), capellaTransitionState)
localPayload, bb, _, err := vs.getLocalPayloadAndBlobs(ctx, blk.Block(), capellaTransitionState)
require.NoError(t, err)
require.Equal(t, uint64(4), localPayload.BlockNumber())
require.DeepEqual(t, bb, blobsBundle)
Expand Down
Loading