Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Register validator beacon api #11225

Merged
merged 34 commits into from
Aug 17, 2022
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
6b5b6a6
adding in beacon API request Object
james-prysm Aug 15, 2022
2b4f814
fixed proto generation
james-prysm Aug 15, 2022
e8183ff
fixing protos
james-prysm Aug 15, 2022
afdfa4c
adding new API logic and fixing linting
james-prysm Aug 15, 2022
183f0f9
adding work in progress unit test for validator registrations
james-prysm Aug 15, 2022
fa806ba
fixing unit test
james-prysm Aug 15, 2022
ed53030
fixing linting
james-prysm Aug 15, 2022
9c03190
Merge branch 'develop' into register-validator-beacon-api
james-prysm Aug 15, 2022
9780620
fixing function name to match interface
james-prysm Aug 15, 2022
ec83651
changing emptypb to empty.Empty
james-prysm Aug 15, 2022
90cd43c
fixing import complaint
james-prysm Aug 15, 2022
1f30526
removing unused import
james-prysm Aug 15, 2022
0f5422c
fixing import
james-prysm Aug 15, 2022
03d9e48
Update beacon-chain/rpc/eth/validator/validator.go
james-prysm Aug 15, 2022
630c9e3
adding emptypb.Empty back in
james-prysm Aug 15, 2022
a7c3d45
Merge branch 'develop' into register-validator-beacon-api
james-prysm Aug 15, 2022
4fc15e2
Update beacon-chain/rpc/eth/validator/validator.go
james-prysm Aug 16, 2022
5b3c210
Update beacon-chain/rpc/eth/validator/validator.go
james-prysm Aug 16, 2022
48249f5
Update beacon-chain/rpc/eth/validator/validator.go
james-prysm Aug 16, 2022
bdaba38
Merge branch 'develop' into register-validator-beacon-api
james-prysm Aug 16, 2022
53d77c3
adding validator registration API to apimiddleware
james-prysm Aug 16, 2022
df9753d
fixing import
james-prysm Aug 16, 2022
5c95bc6
Merge branch 'develop' into register-validator-beacon-api
james-prysm Aug 16, 2022
c5a4592
fixing import format
james-prysm Aug 16, 2022
33fbe3e
Merge branch 'develop' into register-validator-beacon-api
james-prysm Aug 16, 2022
84f1769
fixing protos
james-prysm Aug 16, 2022
5f54ef7
fixing goimports
james-prysm Aug 16, 2022
f70a556
removing duplicate import
james-prysm Aug 16, 2022
4a68a4e
Merge branch 'develop' into register-validator-beacon-api
james-prysm Aug 16, 2022
41954d9
fixing proto
james-prysm Aug 16, 2022
53e053e
Merge branch 'register-validator-beacon-api' of https://github.com/pr…
james-prysm Aug 16, 2022
7c59e5f
fixing error message in test
james-prysm Aug 16, 2022
563599c
Merge branch 'develop' into register-validator-beacon-api
james-prysm Aug 17, 2022
3118d97
Merge branch 'develop' into register-validator-beacon-api
rkapka Aug 17, 2022
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
2 changes: 2 additions & 0 deletions beacon-chain/rpc/eth/validator/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ go_library(
visibility = ["//beacon-chain:__subpackages__"],
deps = [
"//beacon-chain/blockchain:go_default_library",
"//beacon-chain/builder:go_default_library",
"//beacon-chain/cache:go_default_library",
"//beacon-chain/core/helpers:go_default_library",
"//beacon-chain/core/transition:go_default_library",
Expand Down Expand Up @@ -49,6 +50,7 @@ go_test(
embed = [":go_default_library"],
deps = [
"//beacon-chain/blockchain/testing:go_default_library",
"//beacon-chain/builder/testing:go_default_library",
"//beacon-chain/cache:go_default_library",
"//beacon-chain/core/altair:go_default_library",
"//beacon-chain/core/signing:go_default_library",
Expand Down
35 changes: 35 additions & 0 deletions beacon-chain/rpc/eth/validator/validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import (
"strconv"
"time"

"github.com/prysmaticlabs/prysm/beacon-chain/builder"

james-prysm marked this conversation as resolved.
Show resolved Hide resolved
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/hexutil"
"github.com/golang/protobuf/ptypes/empty"
Expand All @@ -25,6 +27,7 @@ import (
ethpbv1 "github.com/prysmaticlabs/prysm/proto/eth/v1"
ethpbv2 "github.com/prysmaticlabs/prysm/proto/eth/v2"
"github.com/prysmaticlabs/prysm/proto/migration"
ethpb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1"
ethpbalpha "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1"
"github.com/prysmaticlabs/prysm/time/slots"
log "github.com/sirupsen/logrus"
Expand Down Expand Up @@ -579,6 +582,38 @@ func (vs *Server) PrepareBeaconProposer(
return &emptypb.Empty{}, nil
}

// SubmitValidatorRegistration submits validator registrations.
func (vs *Server) SubmitValidatorRegistration(ctx context.Context, reg *ethpbv1.SubmitValidatorRegistrationsRequest) (*empty.Empty, error) {
ctx, span := trace.StartSpan(ctx, "validator.ValidatorRegistration")
james-prysm marked this conversation as resolved.
Show resolved Hide resolved
defer span.End()

if vs.V1Alpha1Server.BlockBuilder == nil || !vs.V1Alpha1Server.BlockBuilder.Configured() {
return &empty.Empty{}, status.Errorf(codes.InvalidArgument, "Could not register block builder: %v", builder.ErrNoBuilder)
james-prysm marked this conversation as resolved.
Show resolved Hide resolved
}
var registrations []*ethpb.SignedValidatorRegistrationV1
for i, registration := range reg.Registrations {
message := reg.Registrations[i].Message
registrations = append(registrations, &ethpb.SignedValidatorRegistrationV1{
Message: &ethpb.ValidatorRegistrationV1{
FeeRecipient: message.FeeRecipient,
GasLimit: message.GasLimit,
Timestamp: message.Timestamp,
Pubkey: message.Pubkey,
},
Signature: registration.Signature,
})
}
if len(registrations) == 0 {
return &empty.Empty{}, status.Errorf(codes.InvalidArgument, "validator registration request is empty")
james-prysm marked this conversation as resolved.
Show resolved Hide resolved
}

if err := vs.V1Alpha1Server.BlockBuilder.RegisterValidator(ctx, registrations); err != nil {
return nil, status.Errorf(codes.InvalidArgument, "Could not register block builder: %v", err)
}

return &empty.Empty{}, nil
}

// ProduceAttestationData requests that the beacon node produces attestation data for
// the requested committee index and slot based on the nodes current head.
func (vs *Server) ProduceAttestationData(ctx context.Context, req *ethpbv1.ProduceAttestationDataRequest) (*ethpbv1.ProduceAttestationDataResponse, error) {
Expand Down
62 changes: 62 additions & 0 deletions beacon-chain/rpc/eth/validator/validator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"github.com/ethereum/go-ethereum/common"
"github.com/prysmaticlabs/go-bitfield"
mockChain "github.com/prysmaticlabs/prysm/beacon-chain/blockchain/testing"
builderTest "github.com/prysmaticlabs/prysm/beacon-chain/builder/testing"
"github.com/prysmaticlabs/prysm/beacon-chain/cache"
"github.com/prysmaticlabs/prysm/beacon-chain/core/altair"
"github.com/prysmaticlabs/prysm/beacon-chain/core/signing"
Expand Down Expand Up @@ -3717,3 +3718,64 @@ func TestPrepareBeaconProposer(t *testing.T) {
})
}
}

func TestServer_SubmitValidatorRegistrations(t *testing.T) {
type args struct {
request *ethpbv1.SubmitValidatorRegistrationsRequest
}
tests := []struct {
name string
args args
wantErr string
}{
{
name: "Happy Path",
args: args{
request: &ethpbv1.SubmitValidatorRegistrationsRequest{
Registrations: []*ethpbv1.SubmitValidatorRegistrationsRequest_SignedValidatorRegistration{
{
Message: &ethpbv1.SubmitValidatorRegistrationsRequest_ValidatorRegistration{
FeeRecipient: make([]byte, fieldparams.BLSPubkeyLength),
GasLimit: 30000000,
Timestamp: uint64(time.Now().Unix()),
Pubkey: make([]byte, fieldparams.BLSPubkeyLength),
},
Signature: make([]byte, fieldparams.BLSSignatureLength),
},
},
},
},
wantErr: "",
},
{
name: "Empty Request",
args: args{
request: &ethpbv1.SubmitValidatorRegistrationsRequest{
Registrations: []*ethpbv1.SubmitValidatorRegistrationsRequest_SignedValidatorRegistration{},
},
},
wantErr: "validator registration request is empty",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
db := dbutil.SetupDB(t)
ctx := context.Background()
v1Server := &v1alpha1validator.Server{
BlockBuilder: &builderTest.MockBuilderService{
HasConfigured: true,
},
BeaconDB: db,
}
server := &Server{
V1Alpha1Server: v1Server,
}
_, err := server.SubmitValidatorRegistration(ctx, tt.args.request)
if tt.wantErr != "" {
require.ErrorContains(t, tt.wantErr, err)
return
}
require.NoError(t, err)
})
}
}
Loading