-
Notifications
You must be signed in to change notification settings - Fork 1.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
Update Attester to Use Beacon Node RPC, Replacing SMC Completely #365
Conversation
Use ethereum prefix for proto package
client/BUILD.bazel
Outdated
@@ -18,34 +16,6 @@ go_library( | |||
], | |||
) | |||
|
|||
go_image( |
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 did you remove the docker image support for the client?
Please revert this change
client/attester/service.go
Outdated
activeValidators := crystallizedState.GetActiveValidators() | ||
validatorCount := len(activeValidators) | ||
|
||
validatorIndexSet := false |
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.
Please change to a Boolean like name: isValidatorIndexSet.
Otherwise I think of this as a set of validator indices.
client/attester/service.go
Outdated
for i, val := range activeValidators { | ||
// TODO: Check the public key instead of withdrawal address. This will | ||
// use BLS. | ||
if bytes.Equal(val.GetWithdrawalAddress(), []byte{}) { |
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.
Can you create a constant for this so it’s been easier to understand?
var ZERO_ADDRESS = []byte{}
Or something like that
And/or maybe a helper on ValidatorRecord IsWithdrawalAddressSet()
client/attester/service.go
Outdated
} | ||
for { | ||
block, err := stream.Recv() | ||
if err == io.EOF { |
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.
Please add comment for clarity. This means the stream was closed but it is not intuitive.
// its responsibilities. | ||
|
||
if at.isHeightAssigned && block.GetSlotNumber() == at.assignedHeight { | ||
log.Info("Assigned attestation height reached, performing attestation responsibility") |
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.
Should there be a TODO here?
beacon-chain/rpc/service.go
Outdated
@@ -67,8 +71,8 @@ func (s *Service) Stop() error { | |||
} | |||
|
|||
// ShuffleValidators shuffles the validators into attesters/proposers. | |||
func (s *Service) ShuffleValidators(req *pb.ShuffleRequest, stream pb.BeaconService_ShuffleValidatorsServer) error { | |||
return stream.Send(&pb.ShuffleResponse{IsProposer: true, IsAttester: false}) | |||
func (s *Service) ShuffleValidators(ctx context.Context, req *pb.ShuffleRequest) (*pb.ShuffleResponse, error) { |
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.
So why this no longer a stream? Are validators shuffled on demand or periodically? Doesn't a client want a stream of events?
Could you add some more detail on what this service method is supposed to do?
client/attester/service.go
Outdated
return | ||
} | ||
for { | ||
crystallizedState, err := stream.Recv() | ||
if err == io.EOF { |
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.
Can you add a comment here to clarify that this is a closed stream.
client/rpcclient/service.go
Outdated
log.Fatalf("Could not parse endpoint URL: %s, %v", s.endpoint, err) | ||
return | ||
} | ||
conn, err := grpc.Dial(fmt.Sprintf("localhost:%s", endpointURL.Port()), grpc.WithInsecure()) |
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.
Localhost?
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 move Travis file?
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.
Also, please do not generate a mock with the_test.go
suffix. Otherwise this leaks into the production binary.
client/rpcclient/service.go
Outdated
@@ -36,9 +38,14 @@ func NewRPCClient(ctx context.Context, cfg *Config) *Service { | |||
// Start the grpc connection. | |||
func (s *Service) Start() { | |||
log.Info("Starting service") | |||
conn, err := grpc.Dial(s.endpoint, grpc.WithInsecure()) | |||
endpointURL, err := url.Parse(s.endpoint) |
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.
Is this necessary?
Codecov Report
@@ Coverage Diff @@
## master #365 +/- ##
==========================================
+ Coverage 49.15% 52.12% +2.96%
==========================================
Files 35 34 -1
Lines 2836 2826 -10
==========================================
+ Hits 1394 1473 +79
+ Misses 1245 1163 -82
+ Partials 197 190 -7
Continue to review full report at Codecov.
|
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.
LGTM
I was hesitant about putting the mocks in internal as it might be used in production code, but that target is marked as test only so I am happy.
Thanks
func TestRPCMethods(t *testing.T) { | ||
s := &Service{} | ||
if _, err := s.FetchShuffledValidatorIndices(context.Background(), nil); err == nil { | ||
t.Error("Wanted error: unimplemented, received nil") |
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.
This is OK, but a better pattern is to check that the error returned was the error you expect.
This assertion is that any error returns.
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.
This will be changed very soon once we implement the logic of the beacon RPC server
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.
just one typo, we can fix it in the next pr.
// FetchShuffledValidatorIndices retrieves the shuffled validator indices, cutoffs, and | ||
// assigned attestation heights at a given crystallized state hash. | ||
// This function can be called by clients to fetch a historical list of shuffled | ||
// validators ata point in time corresponding to a certain crystallized state. |
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.
s/ata/at
Hi all,
This PR is part of the greater effort of #315 and we are beginning with updating the attester package in our client project to interact with the beacon chain completely via RPC for shuffling and determining attestation height responsibility. This eliminates the need for the Sharding Manager Contract and completely deprecates it within the attester package. Similar work will need to be done for the proposer package.
This PR ensures attester is aligned with the latest beacon chain + sharding specification.
Design Decisions
This package defines server-side RPC methods for the beacon chain and leverages gomock for testing the client side requests to these methods. The attester service has two responsibilities:
Mocks
This package leverages gRPC mocks through gomock and mockgen for testing. We check in the mocks into
client/internal
for now until we are able to generate them with Bazel. To regenerate the mocks, runmockgen github.com/prysmaticlabs/prysm/proto/beacon/rpc/v1 BeaconServiceClient,BeaconService_LatestBeaconBlockClient,BeaconService_LatestCrystallizedStateClient > ./client/internal/beacon_service_mock.go
Requirements for Merge