mirror of
https://github.com/OffchainLabs/prysm.git
synced 2026-02-01 08:35:24 -05:00
Compare commits
26 Commits
e2e-debugg
...
builder-1
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7ff0f801c8 | ||
|
|
5e462b90f7 | ||
|
|
9c75f463fc | ||
|
|
84488d2c8a | ||
|
|
c7e1108ce4 | ||
|
|
b2ef039246 | ||
|
|
37193be4a6 | ||
|
|
e242eb006a | ||
|
|
1a06daa005 | ||
|
|
bd094693a0 | ||
|
|
2e1e9bfa4c | ||
|
|
8340c013f2 | ||
|
|
7309758dc6 | ||
|
|
e2aa4b16d2 | ||
|
|
ca71dc03e8 | ||
|
|
d1fc8166c6 | ||
|
|
81a6c3f3cb | ||
|
|
7f718f90a7 | ||
|
|
e4dcbc4297 | ||
|
|
ffb3ef2feb | ||
|
|
eeb4e576ad | ||
|
|
c8a0ad66f8 | ||
|
|
8a725ac454 | ||
|
|
0a834efd46 | ||
|
|
0973e08056 | ||
|
|
fabd6f26d3 |
7
beacon-chain/builder/error.go
Normal file
7
beacon-chain/builder/error.go
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
package builder
|
||||||
|
|
||||||
|
import "github.com/pkg/errors"
|
||||||
|
|
||||||
|
var (
|
||||||
|
ErrNotRunning = errors.New("builder is not running")
|
||||||
|
)
|
||||||
30
beacon-chain/builder/metric.go
Normal file
30
beacon-chain/builder/metric.go
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
package builder
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/prometheus/client_golang/prometheus"
|
||||||
|
"github.com/prometheus/client_golang/prometheus/promauto"
|
||||||
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
submitBlindedBlockLatency = promauto.NewHistogram(
|
||||||
|
prometheus.HistogramOpts{
|
||||||
|
Name: "submit_blinded_block_latency_milliseconds",
|
||||||
|
Help: "Captures RPC latency for submitting blinded block in milliseconds",
|
||||||
|
Buckets: []float64{1, 2, 5, 10, 20, 50, 100, 200, 500, 1000},
|
||||||
|
},
|
||||||
|
)
|
||||||
|
getHeaderLatency = promauto.NewHistogram(
|
||||||
|
prometheus.HistogramOpts{
|
||||||
|
Name: "get_header_latency_milliseconds",
|
||||||
|
Help: "Captures RPC latency for get header in milliseconds",
|
||||||
|
Buckets: []float64{1, 2, 5, 10, 20, 50, 100, 200, 500, 1000},
|
||||||
|
},
|
||||||
|
)
|
||||||
|
registerValidatorLatency = promauto.NewHistogram(
|
||||||
|
prometheus.HistogramOpts{
|
||||||
|
Name: "register_validator_latency_milliseconds",
|
||||||
|
Help: "Captures RPC latency for register validator in milliseconds",
|
||||||
|
Buckets: []float64{1, 2, 5, 10, 20, 50, 100, 200, 500, 1000},
|
||||||
|
},
|
||||||
|
)
|
||||||
|
)
|
||||||
58
beacon-chain/builder/options.go
Normal file
58
beacon-chain/builder/options.go
Normal file
@@ -0,0 +1,58 @@
|
|||||||
|
package builder
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/prysmaticlabs/prysm/cmd/beacon-chain/flags"
|
||||||
|
"github.com/prysmaticlabs/prysm/network"
|
||||||
|
"github.com/prysmaticlabs/prysm/network/authorization"
|
||||||
|
"github.com/urfave/cli/v2"
|
||||||
|
)
|
||||||
|
|
||||||
|
type Option func(s *Service) error
|
||||||
|
|
||||||
|
// FlagOptions for builder service flag configurations.
|
||||||
|
func FlagOptions(c *cli.Context) ([]Option, error) {
|
||||||
|
endpoints := parseBuilderEndpoints(c)
|
||||||
|
opts := []Option{
|
||||||
|
WithBuilderEndpoints(endpoints),
|
||||||
|
}
|
||||||
|
return opts, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func WithBuilderEndpoints(endpoints []string) Option {
|
||||||
|
return func(s *Service) error {
|
||||||
|
stringEndpoints := dedupEndpoints(endpoints)
|
||||||
|
endpoints := make([]network.Endpoint, len(stringEndpoints))
|
||||||
|
for i, e := range stringEndpoints {
|
||||||
|
endpoints[i] = covertEndPoint(e)
|
||||||
|
}
|
||||||
|
s.cfg.builderEndpoint = endpoints[0] // Use the first one as the default.
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func covertEndPoint(ep string) network.Endpoint {
|
||||||
|
return network.Endpoint{
|
||||||
|
Url: ep,
|
||||||
|
Auth: network.AuthorizationData{ // Not sure about authorization for now.
|
||||||
|
Method: authorization.None,
|
||||||
|
Value: "",
|
||||||
|
}}
|
||||||
|
}
|
||||||
|
|
||||||
|
func parseBuilderEndpoints(c *cli.Context) []string {
|
||||||
|
// Goal is to support multiple end points later.
|
||||||
|
return []string{c.String(flags.MevBuilderFlag.Name)}
|
||||||
|
}
|
||||||
|
|
||||||
|
func dedupEndpoints(endpoints []string) []string {
|
||||||
|
selectionMap := make(map[string]bool)
|
||||||
|
newEndpoints := make([]string, 0, len(endpoints))
|
||||||
|
for _, point := range endpoints {
|
||||||
|
if selectionMap[point] {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
newEndpoints = append(newEndpoints, point)
|
||||||
|
selectionMap[point] = true
|
||||||
|
}
|
||||||
|
return newEndpoints
|
||||||
|
}
|
||||||
29
beacon-chain/builder/verify.go
Normal file
29
beacon-chain/builder/verify.go
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
package builder
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/pkg/errors"
|
||||||
|
"github.com/prysmaticlabs/prysm/beacon-chain/core/signing"
|
||||||
|
types "github.com/prysmaticlabs/prysm/consensus-types/primitives"
|
||||||
|
ethpb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1"
|
||||||
|
"github.com/prysmaticlabs/prysm/time/slots"
|
||||||
|
)
|
||||||
|
|
||||||
|
func VerifyRegistrationSignature(
|
||||||
|
slot types.Slot,
|
||||||
|
fork *ethpb.Fork,
|
||||||
|
signed *ethpb.SignedValidatorRegistrationV1,
|
||||||
|
genesisRoot []byte,
|
||||||
|
) error {
|
||||||
|
if signed == nil || signed.Message == nil {
|
||||||
|
return errors.New("nil signed registration")
|
||||||
|
}
|
||||||
|
domain, err := signing.Domain(fork, slots.ToEpoch(slot), [4]byte{} /*TODO: Use registration signing domain */, genesisRoot)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := signing.VerifySigningRoot(signed, signed.Message.Pubkey, signed.Signature, domain); err != nil {
|
||||||
|
return signing.ErrSigFailedToVerify
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
@@ -228,6 +228,11 @@ func New(cliCtx *cli.Context, opts ...Option) (*BeaconNode, error) {
|
|||||||
log.Debugln("Starting Fork Choice")
|
log.Debugln("Starting Fork Choice")
|
||||||
beacon.startForkChoice()
|
beacon.startForkChoice()
|
||||||
|
|
||||||
|
log.Debugln("Registering builder service")
|
||||||
|
if err := beacon.registerBuilderService(); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
log.Debugln("Registering Blockchain Service")
|
log.Debugln("Registering Blockchain Service")
|
||||||
if err := beacon.registerBlockchainService(); err != nil {
|
if err := beacon.registerBlockchainService(); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@@ -568,6 +573,14 @@ func (b *BeaconNode) fetchP2P() p2p.P2P {
|
|||||||
return p
|
return p
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (b *BeaconNode) fetchBuilderService() *builder.Service {
|
||||||
|
var s *builder.Service
|
||||||
|
if err := b.services.FetchService(&s); err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return s
|
||||||
|
}
|
||||||
|
|
||||||
func (b *BeaconNode) registerAttestationPool() error {
|
func (b *BeaconNode) registerAttestationPool() error {
|
||||||
s, err := attestations.NewService(b.ctx, &attestations.Config{
|
s, err := attestations.NewService(b.ctx, &attestations.Config{
|
||||||
Pool: b.attestationPool,
|
Pool: b.attestationPool,
|
||||||
@@ -806,6 +819,7 @@ func (b *BeaconNode) registerRPCService() error {
|
|||||||
AttestationReceiver: chainService,
|
AttestationReceiver: chainService,
|
||||||
GenesisTimeFetcher: chainService,
|
GenesisTimeFetcher: chainService,
|
||||||
GenesisFetcher: chainService,
|
GenesisFetcher: chainService,
|
||||||
|
BlockBuilder: b.fetchBuilderService(),
|
||||||
OptimisticModeFetcher: chainService,
|
OptimisticModeFetcher: chainService,
|
||||||
AttestationsPool: b.attestationPool,
|
AttestationsPool: b.attestationPool,
|
||||||
ExitPool: b.exitPool,
|
ExitPool: b.exitPool,
|
||||||
@@ -970,3 +984,12 @@ func (b *BeaconNode) registerValidatorMonitorService() error {
|
|||||||
}
|
}
|
||||||
return b.services.RegisterService(svc)
|
return b.services.RegisterService(svc)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (b *BeaconNode) registerBuilderService() error {
|
||||||
|
options := b.serviceFlagOpts.builderOpts
|
||||||
|
svc, err := builder.NewService(b.ctx, options...)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return b.services.RegisterService(svc)
|
||||||
|
}
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ go_library(
|
|||||||
visibility = ["//beacon-chain:__subpackages__"],
|
visibility = ["//beacon-chain:__subpackages__"],
|
||||||
deps = [
|
deps = [
|
||||||
"//beacon-chain/blockchain:go_default_library",
|
"//beacon-chain/blockchain:go_default_library",
|
||||||
|
"//beacon-chain/builder:go_default_library",
|
||||||
"//beacon-chain/cache:go_default_library",
|
"//beacon-chain/cache:go_default_library",
|
||||||
"//beacon-chain/cache/depositcache:go_default_library",
|
"//beacon-chain/cache/depositcache:go_default_library",
|
||||||
"//beacon-chain/core/feed/block:go_default_library",
|
"//beacon-chain/core/feed/block:go_default_library",
|
||||||
|
|||||||
@@ -27,6 +27,7 @@ go_library(
|
|||||||
deps = [
|
deps = [
|
||||||
"//async/event:go_default_library",
|
"//async/event:go_default_library",
|
||||||
"//beacon-chain/blockchain:go_default_library",
|
"//beacon-chain/blockchain:go_default_library",
|
||||||
|
"//beacon-chain/builder:go_default_library",
|
||||||
"//beacon-chain/cache:go_default_library",
|
"//beacon-chain/cache:go_default_library",
|
||||||
"//beacon-chain/cache/depositcache:go_default_library",
|
"//beacon-chain/cache/depositcache:go_default_library",
|
||||||
"//beacon-chain/core/altair:go_default_library",
|
"//beacon-chain/core/altair:go_default_library",
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ import (
|
|||||||
"github.com/prysmaticlabs/prysm/consensus-types/wrapper"
|
"github.com/prysmaticlabs/prysm/consensus-types/wrapper"
|
||||||
"github.com/prysmaticlabs/prysm/encoding/bytesutil"
|
"github.com/prysmaticlabs/prysm/encoding/bytesutil"
|
||||||
ethpb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1"
|
ethpb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1"
|
||||||
|
"github.com/prysmaticlabs/prysm/runtime/version"
|
||||||
"github.com/prysmaticlabs/prysm/time/slots"
|
"github.com/prysmaticlabs/prysm/time/slots"
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
"go.opencensus.io/trace"
|
"go.opencensus.io/trace"
|
||||||
@@ -57,12 +58,7 @@ func (vs *Server) GetBeaconBlock(ctx context.Context, req *ethpb.BlockRequest) (
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
blk, err := vs.getBellatrixBeaconBlock(ctx, req)
|
return vs.getBellatrixBeaconBlock(ctx, req)
|
||||||
if err != nil {
|
|
||||||
return nil, status.Errorf(codes.Internal, "Could not fetch Bellatrix beacon block: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
return ðpb.GenericBeaconBlock{Block: ðpb.GenericBeaconBlock_Bellatrix{Bellatrix: blk}}, nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetBlock is called by a proposer during its assigned slot to request a block to sign
|
// GetBlock is called by a proposer during its assigned slot to request a block to sign
|
||||||
@@ -133,9 +129,20 @@ func (vs *Server) PrepareBeaconProposer(
|
|||||||
return &emptypb.Empty{}, nil
|
return &emptypb.Empty{}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// SubmitValidatorRegistration submits validator registration.
|
||||||
|
func (vs *Server) SubmitValidatorRegistration(context.Context, *ethpb.SignedValidatorRegistrationV1) (*emptypb.Empty, error) {
|
||||||
|
return &emptypb.Empty{}, nil
|
||||||
|
}
|
||||||
|
|
||||||
func (vs *Server) proposeGenericBeaconBlock(ctx context.Context, blk interfaces.SignedBeaconBlock) (*ethpb.ProposeResponse, error) {
|
func (vs *Server) proposeGenericBeaconBlock(ctx context.Context, blk interfaces.SignedBeaconBlock) (*ethpb.ProposeResponse, error) {
|
||||||
ctx, span := trace.StartSpan(ctx, "ProposerServer.proposeGenericBeaconBlock")
|
ctx, span := trace.StartSpan(ctx, "ProposerServer.proposeGenericBeaconBlock")
|
||||||
defer span.End()
|
defer span.End()
|
||||||
|
|
||||||
|
blk, err := vs.getBuilderBlock(ctx, blk)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
root, err := blk.Block().HashTreeRoot()
|
root, err := blk.Block().HashTreeRoot()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("could not tree hash block: %v", err)
|
return nil, fmt.Errorf("could not tree hash block: %v", err)
|
||||||
@@ -168,6 +175,75 @@ func (vs *Server) proposeGenericBeaconBlock(ctx context.Context, blk interfaces.
|
|||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (vs *Server) getBuilderBlock(ctx context.Context, b interfaces.SignedBeaconBlock) (interfaces.SignedBeaconBlock, error) {
|
||||||
|
if b.Version() != version.BellatrixBlind {
|
||||||
|
return b, nil
|
||||||
|
}
|
||||||
|
if vs.BlockBuilder.Status() != nil {
|
||||||
|
return nil, status.Errorf(codes.FailedPrecondition, "Block builder is not running")
|
||||||
|
}
|
||||||
|
agg, err := b.Block().Body().SyncAggregate()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
h, err := b.Block().Body().ExecutionPayloadHeader()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
sb := ðpb.SignedBlindedBeaconBlockBellatrix{
|
||||||
|
Block: ðpb.BlindedBeaconBlockBellatrix{
|
||||||
|
Slot: b.Block().Slot(),
|
||||||
|
ProposerIndex: b.Block().ProposerIndex(),
|
||||||
|
ParentRoot: b.Block().ParentRoot(),
|
||||||
|
StateRoot: b.Block().StateRoot(),
|
||||||
|
Body: ðpb.BlindedBeaconBlockBodyBellatrix{
|
||||||
|
RandaoReveal: b.Block().Body().RandaoReveal(),
|
||||||
|
Eth1Data: b.Block().Body().Eth1Data(),
|
||||||
|
Graffiti: b.Block().Body().Graffiti(),
|
||||||
|
ProposerSlashings: b.Block().Body().ProposerSlashings(),
|
||||||
|
AttesterSlashings: b.Block().Body().AttesterSlashings(),
|
||||||
|
Attestations: b.Block().Body().Attestations(),
|
||||||
|
Deposits: b.Block().Body().Deposits(),
|
||||||
|
VoluntaryExits: b.Block().Body().VoluntaryExits(),
|
||||||
|
SyncAggregate: agg,
|
||||||
|
ExecutionPayloadHeader: h,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
Signature: nil,
|
||||||
|
}
|
||||||
|
|
||||||
|
payload, err := vs.BlockBuilder.SubmitBlindedBlock(ctx, sb)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
bb := ðpb.SignedBeaconBlockBellatrix{
|
||||||
|
Block: ðpb.BeaconBlockBellatrix{
|
||||||
|
Slot: sb.Block.Slot,
|
||||||
|
ProposerIndex: sb.Block.ProposerIndex,
|
||||||
|
ParentRoot: sb.Block.ParentRoot,
|
||||||
|
StateRoot: sb.Block.StateRoot,
|
||||||
|
Body: ðpb.BeaconBlockBodyBellatrix{
|
||||||
|
RandaoReveal: sb.Block.Body.RandaoReveal,
|
||||||
|
Eth1Data: sb.Block.Body.Eth1Data,
|
||||||
|
Graffiti: sb.Block.Body.Graffiti,
|
||||||
|
ProposerSlashings: sb.Block.Body.ProposerSlashings,
|
||||||
|
AttesterSlashings: sb.Block.Body.AttesterSlashings,
|
||||||
|
Attestations: sb.Block.Body.Attestations,
|
||||||
|
Deposits: sb.Block.Body.Deposits,
|
||||||
|
VoluntaryExits: sb.Block.Body.VoluntaryExits,
|
||||||
|
SyncAggregate: agg,
|
||||||
|
ExecutionPayload: payload,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
Signature: nil,
|
||||||
|
}
|
||||||
|
wb, err := wrapper.WrappedSignedBeaconBlock(bb)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return wb, nil
|
||||||
|
}
|
||||||
|
|
||||||
// computeStateRoot computes the state root after a block has been processed through a state transition and
|
// computeStateRoot computes the state root after a block has been processed through a state transition and
|
||||||
// returns it to the validator client.
|
// returns it to the validator client.
|
||||||
func (vs *Server) computeStateRoot(ctx context.Context, block interfaces.SignedBeaconBlock) ([]byte, error) {
|
func (vs *Server) computeStateRoot(ctx context.Context, block interfaces.SignedBeaconBlock) ([]byte, error) {
|
||||||
|
|||||||
@@ -4,18 +4,59 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
|
"github.com/prysmaticlabs/prysm/beacon-chain/core/blocks"
|
||||||
"github.com/prysmaticlabs/prysm/beacon-chain/core/transition/interop"
|
"github.com/prysmaticlabs/prysm/beacon-chain/core/transition/interop"
|
||||||
"github.com/prysmaticlabs/prysm/config/params"
|
"github.com/prysmaticlabs/prysm/config/params"
|
||||||
|
types "github.com/prysmaticlabs/prysm/consensus-types/primitives"
|
||||||
"github.com/prysmaticlabs/prysm/consensus-types/wrapper"
|
"github.com/prysmaticlabs/prysm/consensus-types/wrapper"
|
||||||
|
"github.com/prysmaticlabs/prysm/encoding/bytesutil"
|
||||||
ethpb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1"
|
ethpb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (vs *Server) getBellatrixBeaconBlock(ctx context.Context, req *ethpb.BlockRequest) (*ethpb.BeaconBlockBellatrix, error) {
|
func (vs *Server) getBellatrixBeaconBlock(ctx context.Context, req *ethpb.BlockRequest) (*ethpb.GenericBeaconBlock, error) {
|
||||||
altairBlk, err := vs.buildAltairBeaconBlock(ctx, req)
|
altairBlk, err := vs.buildAltairBeaconBlock(ctx, req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
h, exists, err := vs.getBuilderHeader(ctx, req.Slot, altairBlk.ProposerIndex)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if exists {
|
||||||
|
blk := ðpb.BlindedBeaconBlockBellatrix{
|
||||||
|
Slot: altairBlk.Slot,
|
||||||
|
ProposerIndex: altairBlk.ProposerIndex,
|
||||||
|
ParentRoot: altairBlk.ParentRoot,
|
||||||
|
StateRoot: params.BeaconConfig().ZeroHash[:],
|
||||||
|
Body: ðpb.BlindedBeaconBlockBodyBellatrix{
|
||||||
|
RandaoReveal: altairBlk.Body.RandaoReveal,
|
||||||
|
Eth1Data: altairBlk.Body.Eth1Data,
|
||||||
|
Graffiti: altairBlk.Body.Graffiti,
|
||||||
|
ProposerSlashings: altairBlk.Body.ProposerSlashings,
|
||||||
|
AttesterSlashings: altairBlk.Body.AttesterSlashings,
|
||||||
|
Attestations: altairBlk.Body.Attestations,
|
||||||
|
Deposits: altairBlk.Body.Deposits,
|
||||||
|
VoluntaryExits: altairBlk.Body.VoluntaryExits,
|
||||||
|
SyncAggregate: altairBlk.Body.SyncAggregate,
|
||||||
|
ExecutionPayloadHeader: h,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
wsb, err := wrapper.WrappedSignedBeaconBlock(
|
||||||
|
ðpb.SignedBlindedBeaconBlockBellatrix{Block: blk, Signature: make([]byte, 96)},
|
||||||
|
)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
stateRoot, err := vs.computeStateRoot(ctx, wsb)
|
||||||
|
if err != nil {
|
||||||
|
interop.WriteBlockToDisk(wsb, true /*failed*/)
|
||||||
|
return nil, fmt.Errorf("could not compute state root: %v", err)
|
||||||
|
}
|
||||||
|
blk.StateRoot = stateRoot
|
||||||
|
return ðpb.GenericBeaconBlock{Block: ðpb.GenericBeaconBlock_BlindedBellatrix{BlindedBellatrix: blk}}, nil
|
||||||
|
}
|
||||||
|
|
||||||
payload, err := vs.getExecutionPayload(ctx, req.Slot, altairBlk.ProposerIndex)
|
payload, err := vs.getExecutionPayload(ctx, req.Slot, altairBlk.ProposerIndex)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@@ -52,5 +93,33 @@ func (vs *Server) getBellatrixBeaconBlock(ctx context.Context, req *ethpb.BlockR
|
|||||||
return nil, fmt.Errorf("could not compute state root: %v", err)
|
return nil, fmt.Errorf("could not compute state root: %v", err)
|
||||||
}
|
}
|
||||||
blk.StateRoot = stateRoot
|
blk.StateRoot = stateRoot
|
||||||
return blk, nil
|
return ðpb.GenericBeaconBlock{Block: ðpb.GenericBeaconBlock_Bellatrix{Bellatrix: blk}}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (vs *Server) getBuilderHeader(ctx context.Context, slot types.Slot, idx types.ValidatorIndex) (*ethpb.ExecutionPayloadHeader, bool, error) {
|
||||||
|
if vs.BlockBuilder.Status() != nil {
|
||||||
|
log.WithError(vs.BlockBuilder.Status()).Error("Could not get builder status")
|
||||||
|
return nil, false, nil
|
||||||
|
}
|
||||||
|
b, err := vs.HeadFetcher.HeadBlock(ctx)
|
||||||
|
if err != nil {
|
||||||
|
return nil, false, err
|
||||||
|
}
|
||||||
|
if blocks.IsPreBellatrixVersion(b.Version()) {
|
||||||
|
return nil, false, nil
|
||||||
|
}
|
||||||
|
h, err := b.Block().Body().ExecutionPayload()
|
||||||
|
if err != nil {
|
||||||
|
return nil, false, err
|
||||||
|
}
|
||||||
|
pk, err := vs.HeadFetcher.HeadValidatorIndexToPublicKey(ctx, idx)
|
||||||
|
if err != nil {
|
||||||
|
return nil, false, err
|
||||||
|
}
|
||||||
|
bid, err := vs.BlockBuilder.GetHeader(ctx, slot, bytesutil.ToBytes32(h.BlockHash), pk)
|
||||||
|
if err != nil {
|
||||||
|
log.WithError(err).Error("Could not get builder header")
|
||||||
|
return nil, false, nil
|
||||||
|
}
|
||||||
|
return bid.Message.Header, true, nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import (
|
|||||||
|
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
"github.com/prysmaticlabs/prysm/beacon-chain/blockchain"
|
"github.com/prysmaticlabs/prysm/beacon-chain/blockchain"
|
||||||
|
"github.com/prysmaticlabs/prysm/beacon-chain/builder"
|
||||||
"github.com/prysmaticlabs/prysm/beacon-chain/cache"
|
"github.com/prysmaticlabs/prysm/beacon-chain/cache"
|
||||||
"github.com/prysmaticlabs/prysm/beacon-chain/cache/depositcache"
|
"github.com/prysmaticlabs/prysm/beacon-chain/cache/depositcache"
|
||||||
"github.com/prysmaticlabs/prysm/beacon-chain/core/feed"
|
"github.com/prysmaticlabs/prysm/beacon-chain/core/feed"
|
||||||
@@ -69,6 +70,7 @@ type Server struct {
|
|||||||
ReplayerBuilder stategen.ReplayerBuilder
|
ReplayerBuilder stategen.ReplayerBuilder
|
||||||
BeaconDB db.HeadAccessDatabase
|
BeaconDB db.HeadAccessDatabase
|
||||||
ExecutionEngineCaller powchain.EngineCaller
|
ExecutionEngineCaller powchain.EngineCaller
|
||||||
|
BlockBuilder builder.BlockBuilder
|
||||||
}
|
}
|
||||||
|
|
||||||
// WaitForActivation checks if a validator public key exists in the active validator registry of the current
|
// WaitForActivation checks if a validator public key exists in the active validator registry of the current
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ import (
|
|||||||
grpc_opentracing "github.com/grpc-ecosystem/go-grpc-middleware/tracing/opentracing"
|
grpc_opentracing "github.com/grpc-ecosystem/go-grpc-middleware/tracing/opentracing"
|
||||||
grpc_prometheus "github.com/grpc-ecosystem/go-grpc-prometheus"
|
grpc_prometheus "github.com/grpc-ecosystem/go-grpc-prometheus"
|
||||||
"github.com/prysmaticlabs/prysm/beacon-chain/blockchain"
|
"github.com/prysmaticlabs/prysm/beacon-chain/blockchain"
|
||||||
|
"github.com/prysmaticlabs/prysm/beacon-chain/builder"
|
||||||
"github.com/prysmaticlabs/prysm/beacon-chain/cache"
|
"github.com/prysmaticlabs/prysm/beacon-chain/cache"
|
||||||
"github.com/prysmaticlabs/prysm/beacon-chain/cache/depositcache"
|
"github.com/prysmaticlabs/prysm/beacon-chain/cache/depositcache"
|
||||||
blockfeed "github.com/prysmaticlabs/prysm/beacon-chain/core/feed/block"
|
blockfeed "github.com/prysmaticlabs/prysm/beacon-chain/core/feed/block"
|
||||||
@@ -90,6 +91,7 @@ type Config struct {
|
|||||||
POWChainInfoFetcher powchain.ChainInfoFetcher
|
POWChainInfoFetcher powchain.ChainInfoFetcher
|
||||||
GenesisTimeFetcher blockchain.TimeFetcher
|
GenesisTimeFetcher blockchain.TimeFetcher
|
||||||
GenesisFetcher blockchain.GenesisFetcher
|
GenesisFetcher blockchain.GenesisFetcher
|
||||||
|
BlockBuilder builder.BlockBuilder
|
||||||
EnableDebugRPCEndpoints bool
|
EnableDebugRPCEndpoints bool
|
||||||
MockEth1Votes bool
|
MockEth1Votes bool
|
||||||
AttestationsPool attestations.Pool
|
AttestationsPool attestations.Pool
|
||||||
@@ -216,6 +218,7 @@ func (s *Service) Start() {
|
|||||||
ExecutionEngineCaller: s.cfg.ExecutionEngineCaller,
|
ExecutionEngineCaller: s.cfg.ExecutionEngineCaller,
|
||||||
BeaconDB: s.cfg.BeaconDB,
|
BeaconDB: s.cfg.BeaconDB,
|
||||||
ProposerSlotIndexCache: s.cfg.ProposerIdsCache,
|
ProposerSlotIndexCache: s.cfg.ProposerIdsCache,
|
||||||
|
BlockBuilder: s.cfg.BlockBuilder,
|
||||||
}
|
}
|
||||||
validatorServerV1 := &validator.Server{
|
validatorServerV1 := &validator.Server{
|
||||||
HeadFetcher: s.cfg.HeadFetcher,
|
HeadFetcher: s.cfg.HeadFetcher,
|
||||||
|
|||||||
89
validator/client/builder_registration.go
Normal file
89
validator/client/builder_registration.go
Normal file
@@ -0,0 +1,89 @@
|
|||||||
|
package client
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"github.com/pkg/errors"
|
||||||
|
"github.com/prysmaticlabs/prysm/beacon-chain/core/signing"
|
||||||
|
"github.com/prysmaticlabs/prysm/config/params"
|
||||||
|
types "github.com/prysmaticlabs/prysm/consensus-types/primitives"
|
||||||
|
ethpb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1"
|
||||||
|
validatorpb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1/validator-client"
|
||||||
|
"github.com/prysmaticlabs/prysm/time/slots"
|
||||||
|
"go.opencensus.io/trace"
|
||||||
|
"google.golang.org/protobuf/types/known/emptypb"
|
||||||
|
)
|
||||||
|
|
||||||
|
// SubmitBuilderValidatorRegistration submits builder validator registration
|
||||||
|
func SubmitBuilderValidatorRegistration(
|
||||||
|
ctx context.Context,
|
||||||
|
validatorClient ethpb.BeaconNodeValidatorClient,
|
||||||
|
nodeClient ethpb.NodeClient,
|
||||||
|
signer signingFunc,
|
||||||
|
reg *ethpb.ValidatorRegistrationV1,
|
||||||
|
) error {
|
||||||
|
ctx, span := trace.StartSpan(ctx, "validator.ProposeBuilderValidatorRegistration")
|
||||||
|
defer span.End()
|
||||||
|
|
||||||
|
genesisResponse, err := nodeClient.GetGenesis(ctx, &emptypb.Empty{})
|
||||||
|
if err != nil {
|
||||||
|
return errors.Wrap(err, "gRPC call to get genesis time failed")
|
||||||
|
}
|
||||||
|
ts := time.Unix(int64(reg.Timestamp), 0)
|
||||||
|
secs := int64(ts.Second()) - genesisResponse.GenesisTime.Seconds
|
||||||
|
currentSlot := types.Slot(uint64(secs) / params.BeaconConfig().SecondsPerSlot)
|
||||||
|
|
||||||
|
sig, err := signBuilderValidatorRegistration(ctx, currentSlot, validatorClient, signer, reg)
|
||||||
|
if err != nil {
|
||||||
|
return errors.Wrap(err, "failed to sign builder validator registration obj")
|
||||||
|
}
|
||||||
|
|
||||||
|
signedReg := ðpb.SignedValidatorRegistrationV1{
|
||||||
|
Message: reg,
|
||||||
|
Signature: sig,
|
||||||
|
}
|
||||||
|
if _, err := validatorClient.SubmitValidatorRegistration(ctx, signedReg); err != nil {
|
||||||
|
return errors.Wrap(err, "could not submit signed registration to beacon node")
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Sings validator registration obj with proposer domain and private key.
|
||||||
|
func signBuilderValidatorRegistration(
|
||||||
|
ctx context.Context,
|
||||||
|
slot types.Slot,
|
||||||
|
validatorClient ethpb.BeaconNodeValidatorClient,
|
||||||
|
signer signingFunc,
|
||||||
|
reg *ethpb.ValidatorRegistrationV1,
|
||||||
|
) ([]byte, error) {
|
||||||
|
req := ðpb.DomainRequest{
|
||||||
|
Epoch: slots.ToEpoch(slot),
|
||||||
|
Domain: []byte{},
|
||||||
|
}
|
||||||
|
|
||||||
|
domain, err := validatorClient.DomainData(ctx, req)
|
||||||
|
if err != nil {
|
||||||
|
return nil, errors.Wrap(err, domainDataErr)
|
||||||
|
}
|
||||||
|
if domain == nil {
|
||||||
|
return nil, errors.New(domainDataErr)
|
||||||
|
}
|
||||||
|
|
||||||
|
exitRoot, err := signing.ComputeSigningRoot(reg, domain.SignatureDomain)
|
||||||
|
if err != nil {
|
||||||
|
return nil, errors.Wrap(err, signingRootErr)
|
||||||
|
}
|
||||||
|
|
||||||
|
sig, err := signer(ctx, &validatorpb.SignRequest{
|
||||||
|
PublicKey: reg.Pubkey,
|
||||||
|
SigningRoot: exitRoot[:],
|
||||||
|
SignatureDomain: domain.SignatureDomain,
|
||||||
|
Object: &validatorpb.SignRequest_Registration{Registration: reg},
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
return nil, errors.Wrap(err, signExitErr)
|
||||||
|
}
|
||||||
|
return sig.Marshal(), nil
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user