-
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
GetLiveness
API endpoint
#11617
GetLiveness
API endpoint
#11617
Conversation
require.NoError(t, err) | ||
data0 := resp.Data[0] | ||
data1 := resp.Data[1] | ||
assert.Equal(t, true, (data0.Index == 0 && !data0.IsLive) || (data0.Index == 1 && !data0.IsLive)) |
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 don't assume any ordering
@@ -213,7 +213,7 @@ type SpecResponseJson struct { | |||
Data interface{} `json:"data"` | |||
} | |||
|
|||
type DutiesRequestJson struct { | |||
type ValidatorIndicesJson struct { |
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 changed the name to be more reusable.
@@ -37,6 +37,7 @@ import ( | |||
) | |||
|
|||
var errInvalidValIndex = errors.New("invalid validator index") | |||
var errParticipation = status.Errorf(codes.Internal, "Could not obtain epoch participation") |
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.
There is no format here, prefer status.Error
var errParticipation = status.Errorf(codes.Internal, "Could not obtain epoch participation") | |
var errParticipation = status.Error(codes.Internal, "Could not obtain epoch participation") |
} | ||
currEpoch := slots.ToEpoch(headSt.Slot()) | ||
if req.Epoch > currEpoch { | ||
return nil, status.Errorf(codes.InvalidArgument, "Requested epoch cannot be in the future") |
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.
return nil, status.Errorf(codes.InvalidArgument, "Requested epoch cannot be in the future") | |
return nil, status.Error(codes.InvalidArgument, "Requested epoch cannot be in the future") |
@@ -26,4 +27,5 @@ type Server struct { | |||
SyncCommitteePool synccommittee.Pool | |||
V1Alpha1Server *v1alpha1validator.Server | |||
ProposerSlotIndexCache *cache.ProposerPayloadIDsCache | |||
ReplayerBuilder stategen.ReplayerBuilder |
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.
What is this used for? I don't see it used in this PR.
@@ -1022,6 +1025,13 @@ func (vs *Server) GetLiveness(ctx context.Context, req *ethpbv2.GetLivenessReque | |||
Data: make([]*ethpbv2.GetLivenessResponse_Liveness, len(req.Index)), | |||
} | |||
for i, vi := range req.Index { | |||
_, err = st.ValidatorAtIndex(vi) |
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 a bit of an expensive operation. It makes a copy of the validator and if you are iterating over a large request then you might have a noticeable burden on the server.
I think you could simply check that vi
is less than len(participation)
and return the out of range error if it fails that check
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.
Nice, I think this would work.
I didn't test it locally, but the logic makes sense and the code is good. Nice work
d6261bf
to
46e35e2
Compare
What type of PR is this?
Feature
What does this PR do? Why is it needed?
Implements the https://ethereum.github.io/beacon-APIs/?urls.primaryName=dev#/Validator/getLiveness API endpoint.
Other notes for review
I got the idea of using participation bits from @nisdas. We already use them for doppelganger check in Prysm APIs:
prysm/beacon-chain/rpc/prysm/v1alpha1/validator/status.go
Line 101 in 8ade8af