Skip to content

Commit

Permalink
Prysm rpc: submit signed execution payload header
Browse files Browse the repository at this point in the history
  • Loading branch information
terencechain committed Sep 12, 2024
1 parent fdccbb5 commit 3692c44
Show file tree
Hide file tree
Showing 8 changed files with 260 additions and 133 deletions.
12 changes: 12 additions & 0 deletions beacon-chain/rpc/prysm/v1alpha1/validator/proposer_epbs.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"google.golang.org/protobuf/types/known/emptypb"
)

// SubmitSignedExecutionPayloadEnvelope submits a signed execution payload envelope to the network.
func (vs *Server) SubmitSignedExecutionPayloadEnvelope(ctx context.Context, env *enginev1.SignedExecutionPayloadEnvelope) (*emptypb.Empty, error) {
if err := vs.P2P.Broadcast(ctx, env); err != nil {
return nil, status.Errorf(codes.Internal, "failed to broadcast signed execution payload envelope: %v", err)
Expand All @@ -26,3 +27,14 @@ func (vs *Server) SubmitSignedExecutionPayloadEnvelope(ctx context.Context, env

return nil, nil
}

// SubmitSignedExecutionPayloadHeader submits a signed execution payload header to the beacon node.
func (vs *Server) SubmitSignedExecutionPayloadHeader(ctx context.Context, h *enginev1.SignedExecutionPayloadHeader) (*emptypb.Empty, error) {
if vs.TimeFetcher.CurrentSlot() != h.Message.Slot {
return nil, status.Errorf(codes.InvalidArgument, "current slot mismatch: expected %d, got %d", vs.TimeFetcher.CurrentSlot(), h.Message.Slot)
}

vs.signedExecutionPayloadHeader = h

return nil, nil
}
25 changes: 25 additions & 0 deletions beacon-chain/rpc/prysm/v1alpha1/validator/proposer_epbs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"github.com/pkg/errors"
mockChain "github.com/prysmaticlabs/prysm/v5/beacon-chain/blockchain/testing"
p2ptest "github.com/prysmaticlabs/prysm/v5/beacon-chain/p2p/testing"
"github.com/prysmaticlabs/prysm/v5/consensus-types/primitives"
enginev1 "github.com/prysmaticlabs/prysm/v5/proto/engine/v1"
"github.com/prysmaticlabs/prysm/v5/testing/require"
"github.com/prysmaticlabs/prysm/v5/testing/util"
Expand Down Expand Up @@ -41,3 +42,27 @@ func TestServer_SubmitSignedExecutionPayloadEnvelope(t *testing.T) {
require.ErrorContains(t, "failed to receive execution payload envelope: receive failed", err)
})
}

func TestServer_SubmitSignedExecutionPayloadHeader(t *testing.T) {
h := &enginev1.SignedExecutionPayloadHeader{
Message: &enginev1.ExecutionPayloadHeaderEPBS{
Slot: 1,
},
}
slot := primitives.Slot(1)
server := &Server{
TimeFetcher: &mockChain.ChainService{Slot: &slot},
}

t.Run("Happy case", func(t *testing.T) {
_, err := server.SubmitSignedExecutionPayloadHeader(context.Background(), h)
require.NoError(t, err)
require.DeepEqual(t, server.signedExecutionPayloadHeader, h)
})

t.Run("Incorrect slot", func(t *testing.T) {
h.Message.Slot = 2
_, err := server.SubmitSignedExecutionPayloadHeader(context.Background(), h)
require.ErrorContains(t, "current slot mismatch: expected 1, got 2", err)
})
}
78 changes: 40 additions & 38 deletions beacon-chain/rpc/prysm/v1alpha1/validator/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import (
"github.com/prysmaticlabs/prysm/v5/config/params"
"github.com/prysmaticlabs/prysm/v5/encoding/bytesutil"
"github.com/prysmaticlabs/prysm/v5/network/forks"
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"
"github.com/prysmaticlabs/prysm/v5/time/slots"
Expand All @@ -43,44 +44,45 @@ import (
// and committees in which particular validators need to perform their responsibilities,
// and more.
type Server struct {
Ctx context.Context
PayloadIDCache *cache.PayloadIDCache
TrackedValidatorsCache *cache.TrackedValidatorsCache
HeadFetcher blockchain.HeadFetcher
ForkFetcher blockchain.ForkFetcher
ForkchoiceFetcher blockchain.ForkchoiceFetcher
GenesisFetcher blockchain.GenesisFetcher
FinalizationFetcher blockchain.FinalizationFetcher
TimeFetcher blockchain.TimeFetcher
BlockFetcher execution.POWBlockFetcher
DepositFetcher cache.DepositFetcher
ChainStartFetcher execution.ChainStartFetcher
Eth1InfoFetcher execution.ChainInfoFetcher
OptimisticModeFetcher blockchain.OptimisticModeFetcher
SyncChecker sync.Checker
StateNotifier statefeed.Notifier
BlockNotifier blockfeed.Notifier
P2P p2p.Broadcaster
AttPool attestations.Pool
SlashingsPool slashings.PoolManager
ExitPool voluntaryexits.PoolManager
SyncCommitteePool synccommittee.Pool
BlockReceiver blockchain.BlockReceiver
BlobReceiver blockchain.BlobReceiver
PayloadAttestationReceiver blockchain.PayloadAttestationReceiver
ExecutionPayloadReceiver blockchain.ExecutionPayloadReceiver
MockEth1Votes bool
Eth1BlockFetcher execution.POWBlockFetcher
PendingDepositsFetcher depositsnapshot.PendingDepositsFetcher
OperationNotifier opfeed.Notifier
StateGen stategen.StateManager
ReplayerBuilder stategen.ReplayerBuilder
BeaconDB db.HeadAccessDatabase
ExecutionEngineCaller execution.EngineCaller
BlockBuilder builder.BlockBuilder
BLSChangesPool blstoexec.PoolManager
ClockWaiter startup.ClockWaiter
CoreService *core.Service
Ctx context.Context
PayloadIDCache *cache.PayloadIDCache
TrackedValidatorsCache *cache.TrackedValidatorsCache
HeadFetcher blockchain.HeadFetcher
ForkFetcher blockchain.ForkFetcher
ForkchoiceFetcher blockchain.ForkchoiceFetcher
GenesisFetcher blockchain.GenesisFetcher
FinalizationFetcher blockchain.FinalizationFetcher
TimeFetcher blockchain.TimeFetcher
BlockFetcher execution.POWBlockFetcher
DepositFetcher cache.DepositFetcher
ChainStartFetcher execution.ChainStartFetcher
Eth1InfoFetcher execution.ChainInfoFetcher
OptimisticModeFetcher blockchain.OptimisticModeFetcher
SyncChecker sync.Checker
StateNotifier statefeed.Notifier
BlockNotifier blockfeed.Notifier
P2P p2p.Broadcaster
AttPool attestations.Pool
SlashingsPool slashings.PoolManager
ExitPool voluntaryexits.PoolManager
SyncCommitteePool synccommittee.Pool
BlockReceiver blockchain.BlockReceiver
BlobReceiver blockchain.BlobReceiver
PayloadAttestationReceiver blockchain.PayloadAttestationReceiver
ExecutionPayloadReceiver blockchain.ExecutionPayloadReceiver
MockEth1Votes bool
Eth1BlockFetcher execution.POWBlockFetcher
PendingDepositsFetcher depositsnapshot.PendingDepositsFetcher
OperationNotifier opfeed.Notifier
StateGen stategen.StateManager
ReplayerBuilder stategen.ReplayerBuilder
BeaconDB db.HeadAccessDatabase
ExecutionEngineCaller execution.EngineCaller
BlockBuilder builder.BlockBuilder
BLSChangesPool blstoexec.PoolManager
ClockWaiter startup.ClockWaiter
CoreService *core.Service
signedExecutionPayloadHeader *enginev1.SignedExecutionPayloadHeader
}

// WaitForActivation checks if a validator public key exists in the active validator registry of the current
Expand Down
Loading

0 comments on commit 3692c44

Please sign in to comment.