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

GetLiveness API endpoint #11617

Merged
merged 10 commits into from
Nov 23, 2022
Merged

GetLiveness API endpoint #11617

merged 10 commits into from
Nov 23, 2022

Conversation

rkapka
Copy link
Contributor

@rkapka rkapka commented Nov 4, 2022

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:

func (vs *Server) CheckDoppelGanger(ctx context.Context, req *ethpb.DoppelGangerRequest) (*ethpb.DoppelGangerResponse, error) {

@rkapka rkapka added Ready For Review A pull request ready for code review API Api related tasks labels Nov 4, 2022
@rkapka rkapka requested a review from a team as a code owner November 4, 2022 14:24
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))
Copy link
Contributor Author

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 {
Copy link
Contributor Author

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")
Copy link
Member

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

Suggested change
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")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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
Copy link
Member

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)
Copy link
Member

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

prestonvanloon
prestonvanloon previously approved these changes Nov 23, 2022
Copy link
Member

@prestonvanloon prestonvanloon left a 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

@prylabs-bulldozer prylabs-bulldozer bot merged commit f2399e2 into develop Nov 23, 2022
@delete-merged-branch delete-merged-branch bot deleted the get-liveness-api branch November 23, 2022 18:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
API Api related tasks Ready For Review A pull request ready for code review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants