-
Notifications
You must be signed in to change notification settings - Fork 1k
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
PrepareBeaconProposer API #10367
PrepareBeaconProposer API #10367
Changes from 25 commits
c5efcbd
18a4f96
ee65ad2
25ba6a3
294e117
6389e6e
b011ff2
655ac36
264304a
cc9e775
8398747
2a185c9
5ae640d
3c755d4
14024b8
088aa96
f7a388b
3dd1f06
c60602d
bde8d6e
2a27474
5e1b284
02c26ea
d75be76
a6c1795
acec392
700190d
40c2c70
4ee2847
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,7 @@ import ( | |
"strconv" | ||
"time" | ||
|
||
"github.com/ethereum/go-ethereum/common" | ||
"github.com/golang/protobuf/ptypes/empty" | ||
"github.com/pkg/errors" | ||
types "github.com/prysmaticlabs/eth2-types" | ||
|
@@ -325,11 +326,25 @@ func (vs *Server) ProduceBlockV2(ctx context.Context, req *ethpbv1.ProduceBlockR | |
return nil, status.Error(codes.InvalidArgument, "Unsupported block type") | ||
} | ||
|
||
// PrepareBeaconProposer -- | ||
// PrepareBeaconProposer caches and updates the fee recipient for the given proposer. | ||
func (vs *Server) PrepareBeaconProposer( | ||
_ context.Context, _ *ethpbv1.PrepareBeaconProposerRequest, | ||
ctx context.Context, request *ethpbv1.PrepareBeaconProposerRequest, | ||
) (*emptypb.Empty, error) { | ||
return &emptypb.Empty{}, status.Error(codes.Unimplemented, "Unimplemented") | ||
_, span := trace.StartSpan(ctx, "validator.PrepareBeaconProposer") | ||
defer span.End() | ||
var FeeRecipients []common.Address | ||
var ValidatorIndices []types.ValidatorIndex | ||
for _, recipientContainer := range request.Recipients { | ||
if len(recipientContainer.FeeRecipient) != fieldparams.FeeRecipientLength { | ||
return nil, status.Errorf(codes.InvalidArgument, "Invalid fee recipient length") | ||
} | ||
FeeRecipients = append(FeeRecipients, common.BytesToAddress(recipientContainer.FeeRecipient)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it's worth validating |
||
ValidatorIndices = append(ValidatorIndices, recipientContainer.ValidatorIndex) | ||
} | ||
if err := vs.V1Alpha1Server.BeaconDB.SaveFeeRecipientsByValidatorIDs(ctx, ValidatorIndices, FeeRecipients); err != nil { | ||
return nil, status.Errorf(codes.Internal, "Could not save fee recipients: %v", err) | ||
} | ||
return &emptypb.Empty{}, nil | ||
} | ||
|
||
// ProduceAttestationData requests that the beacon node produces attestation data for | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -45,6 +45,8 @@ import ( | |
"github.com/prysmaticlabs/prysm/testing/require" | ||
"github.com/prysmaticlabs/prysm/testing/util" | ||
"github.com/prysmaticlabs/prysm/time/slots" | ||
"google.golang.org/grpc/codes" | ||
"google.golang.org/grpc/status" | ||
"google.golang.org/protobuf/proto" | ||
) | ||
|
||
|
@@ -2011,3 +2013,62 @@ func TestSubmitContributionAndProofs(t *testing.T) { | |
require.DeepEqual(t, expectedContributions, savedMsgs) | ||
}) | ||
} | ||
|
||
func TestPrepareBeaconProposer(t *testing.T) { | ||
type args struct { | ||
request *ethpbv1.PrepareBeaconProposerRequest | ||
} | ||
tests := []struct { | ||
name string | ||
args args | ||
wantErr error | ||
}{ | ||
{ | ||
name: "Happy Path", | ||
args: args{ | ||
request: ðpbv1.PrepareBeaconProposerRequest{ | ||
Recipients: []*ethpbv1.PrepareBeaconProposerRequest_FeeRecipientContainer{ | ||
{ | ||
FeeRecipient: make([]byte, fieldparams.FeeRecipientLength), | ||
ValidatorIndex: 1, | ||
}, | ||
}, | ||
}, | ||
}, | ||
wantErr: nil, | ||
}, | ||
{ | ||
name: "invalid fee recipient length", | ||
args: args{ | ||
request: ðpbv1.PrepareBeaconProposerRequest{ | ||
Recipients: []*ethpbv1.PrepareBeaconProposerRequest_FeeRecipientContainer{ | ||
{ | ||
FeeRecipient: make([]byte, fieldparams.BLSPubkeyLength), | ||
ValidatorIndex: 1, | ||
}, | ||
}, | ||
}, | ||
}, | ||
wantErr: status.Errorf(codes.InvalidArgument, "Invalid fee recipient length"), | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This test should also read from the DB to ensure the expected data was saved |
||
db := dbutil.SetupDB(t) | ||
ctx := context.Background() | ||
v1Server := &v1alpha1validator.Server{ | ||
BeaconDB: db, | ||
} | ||
server := &Server{ | ||
V1Alpha1Server: v1Server, | ||
} | ||
_, err := server.PrepareBeaconProposer(ctx, tt.args.request) | ||
if tt.wantErr != nil { | ||
require.Equal(t, fmt.Sprint(tt.wantErr), fmt.Sprint(err)) | ||
return | ||
} | ||
require.NoError(t, err) | ||
}) | ||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,11 +6,14 @@ import ( | |
"fmt" | ||
"time" | ||
|
||
"github.com/ethereum/go-ethereum/common" | ||
emptypb "github.com/golang/protobuf/ptypes/empty" | ||
"github.com/pkg/errors" | ||
types "github.com/prysmaticlabs/eth2-types" | ||
"github.com/prysmaticlabs/prysm/beacon-chain/core/feed" | ||
blockfeed "github.com/prysmaticlabs/prysm/beacon-chain/core/feed/block" | ||
"github.com/prysmaticlabs/prysm/beacon-chain/core/transition" | ||
fieldparams "github.com/prysmaticlabs/prysm/config/fieldparams" | ||
"github.com/prysmaticlabs/prysm/config/params" | ||
"github.com/prysmaticlabs/prysm/encoding/bytesutil" | ||
ethpb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1" | ||
|
@@ -116,11 +119,25 @@ func (vs *Server) ProposeBlock(ctx context.Context, rBlk *ethpb.SignedBeaconBloc | |
return vs.proposeGenericBeaconBlock(ctx, blk) | ||
} | ||
|
||
// PrepareBeaconProposer -- | ||
// PrepareBeaconProposer caches and updates the fee recipient for the given proposer. | ||
func (vs *Server) PrepareBeaconProposer( | ||
_ context.Context, _ *ethpb.PrepareBeaconProposerRequest, | ||
ctx context.Context, request *ethpb.PrepareBeaconProposerRequest, | ||
) (*emptypb.Empty, error) { | ||
return &emptypb.Empty{}, status.Error(codes.Unimplemented, "Unimplemented") | ||
_, span := trace.StartSpan(ctx, "validator.PrepareBeaconProposer") | ||
defer span.End() | ||
var FeeRecipients []common.Address | ||
var ValidatorIndices []types.ValidatorIndex | ||
for _, recipientContainer := range request.Recipients { | ||
if len(recipientContainer.FeeRecipient) != fieldparams.FeeRecipientLength { | ||
return nil, status.Errorf(codes.InvalidArgument, "Invalid fee recipient length") | ||
} | ||
FeeRecipients = append(FeeRecipients, common.BytesToAddress(recipientContainer.FeeRecipient)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here. Worth validating |
||
ValidatorIndices = append(ValidatorIndices, recipientContainer.ValidatorIndex) | ||
} | ||
if err := vs.BeaconDB.SaveFeeRecipientsByValidatorIDs(ctx, ValidatorIndices, FeeRecipients); err != nil { | ||
return nil, status.Errorf(codes.Internal, "Could not save fee recipients: %v", err) | ||
} | ||
return &emptypb.Empty{}, nil | ||
} | ||
|
||
func (vs *Server) proposeGenericBeaconBlock(ctx context.Context, blk block.SignedBeaconBlock) (*ethpb.ProposeResponse, error) { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ package validator | |
|
||
import ( | ||
"context" | ||
"fmt" | ||
"math/big" | ||
"testing" | ||
"time" | ||
|
@@ -2431,6 +2432,59 @@ func TestProposer_GetSyncAggregate_OK(t *testing.T) { | |
require.DeepEqual(t, bitfield.NewBitvector512(), aggregate.SyncCommitteeBits) | ||
} | ||
|
||
func TestProposer_PrepareBeaconProposer(t *testing.T) { | ||
type args struct { | ||
request *ethpb.PrepareBeaconProposerRequest | ||
} | ||
tests := []struct { | ||
name string | ||
args args | ||
wantErr error | ||
}{ | ||
{ | ||
name: "Happy Path", | ||
args: args{ | ||
request: ðpb.PrepareBeaconProposerRequest{ | ||
Recipients: []*ethpb.PrepareBeaconProposerRequest_FeeRecipientContainer{ | ||
{ | ||
FeeRecipient: make([]byte, fieldparams.FeeRecipientLength), | ||
ValidatorIndex: 1, | ||
}, | ||
}, | ||
}, | ||
}, | ||
wantErr: nil, | ||
}, | ||
{ | ||
name: "invalid fee recipient length", | ||
args: args{ | ||
request: ðpb.PrepareBeaconProposerRequest{ | ||
Recipients: []*ethpb.PrepareBeaconProposerRequest_FeeRecipientContainer{ | ||
{ | ||
FeeRecipient: make([]byte, fieldparams.BLSPubkeyLength), | ||
ValidatorIndex: 1, | ||
}, | ||
}, | ||
}, | ||
}, | ||
wantErr: status.Errorf(codes.InvalidArgument, "Invalid fee recipient length"), | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
db := dbutil.SetupDB(t) | ||
ctx := context.Background() | ||
proposerServer := &Server{BeaconDB: db} | ||
_, err := proposerServer.PrepareBeaconProposer(ctx, tt.args.request) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. +1 here |
||
if tt.wantErr != nil { | ||
require.Equal(t, fmt.Sprint(tt.wantErr), fmt.Sprint(err)) | ||
return | ||
} | ||
require.NoError(t, err) | ||
}) | ||
} | ||
} | ||
|
||
func majorityVoteBoundaryTime(slot types.Slot) (uint64, uint64) { | ||
slots := params.BeaconConfig().SlotsPerEpoch.Mul(uint64(params.BeaconConfig().EpochsPerEth1VotingPeriod)) | ||
slotStartTime := uint64(mockPOW.GenesisTime) + uint64((slot - (slot % (slots))).Mul(params.BeaconConfig().SecondsPerSlot)) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not just do
IsHexAddress(common.BytesToAddress(recipientContainer.FeeRecipient)))
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can do it that way too will update then.