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

Optimistic sync: prysm validator rpcs #10200

Merged
merged 14 commits into from
Feb 15, 2022
Merged
12 changes: 12 additions & 0 deletions beacon-chain/rpc/prysm/v1alpha1/validator/attester.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,18 @@ func (vs *Server) GetAttestationData(ctx context.Context, req *ethpb.Attestation
return nil, status.Errorf(codes.Unavailable, "Syncing to latest head, not ready to respond")
}

optimistic, err := vs.HeadFetcher.IsOptimistic(ctx)
if err != nil {
return nil, status.Errorf(codes.Internal, "Could not determine if the node is a optimistic node: %v", err)
}
if optimistic {
root, err := vs.HeadFetcher.HeadRoot(ctx)
if err != nil {
return nil, status.Errorf(codes.Internal, "Could not get head root: %v", err)
}
return nil, status.Errorf(codes.Unavailable, "The node is currently optimistic and cannot serve attestations. Head root: %#x", root)
}

if err := helpers.ValidateAttestationTime(req.Slot, vs.TimeFetcher.GenesisTime(),
params.BeaconNetworkConfig().MaximumGossipClockDisparity); err != nil {
return nil, status.Error(codes.InvalidArgument, fmt.Sprintf("invalid request: %v", err))
Expand Down
12 changes: 12 additions & 0 deletions beacon-chain/rpc/prysm/v1alpha1/validator/proposer.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,18 @@ func (vs *Server) GetBeaconBlock(ctx context.Context, req *ethpb.BlockRequest) (
return &ethpb.GenericBeaconBlock{Block: &ethpb.GenericBeaconBlock_Altair{Altair: blk}}, nil
}

optimistic, err := vs.HeadFetcher.IsOptimistic(ctx)
if err != nil {
return nil, status.Errorf(codes.Internal, "Could not determine if the node is a optimistic node: %v", err)
}
if optimistic {
root, err := vs.HeadFetcher.HeadRoot(ctx)
if err != nil {
return nil, status.Errorf(codes.Internal, "Could not get head root: %v", err)
}
return nil, status.Errorf(codes.Unavailable, "The node is currently optimistic and cannot serve blocks. Head root: %#x", root)
}

blk, err := vs.getBellatrixBeaconBlock(ctx, req)
if err != nil {
return nil, status.Errorf(codes.Internal, "Could not fetch Bellatrix beacon block: %v", err)
Expand Down
7 changes: 7 additions & 0 deletions beacon-chain/rpc/prysm/v1alpha1/validator/sync_committee.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,13 @@ func (vs *Server) GetSyncMessageBlockRoot(
if err != nil {
return nil, status.Errorf(codes.Internal, "Could not retrieve head root: %v", err)
}
optimistic, err := vs.HeadFetcher.IsOptimistic(ctx)
if err != nil {
return nil, status.Errorf(codes.Internal, "Could not determine if the node is a optimistic node: %v", err)
}
if optimistic {
return nil, status.Errorf(codes.Unavailable, "The node is currently optimistic and cannot serve blocks. Head root: %#x", r)
terencechain marked this conversation as resolved.
Show resolved Hide resolved
}

return &ethpb.SyncMessageBlockRootResponse{
Root: r,
Expand Down