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

Properly Return Finalized Epoch in GetValidatorParticipation Archival Endpoint #4091

Merged
merged 12 commits into from
Nov 25, 2019
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion beacon-chain/rpc/beacon/validators.go
Original file line number Diff line number Diff line change
@@ -371,7 +371,7 @@ func (bs *Server) GetValidatorParticipation(
}
return &ethpb.ValidatorParticipationResponse{
Epoch: requestedEpoch,
Finalized: true,
Copy link
Member

Choose a reason for hiding this comment

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

🤦‍♂️

Finalized: requestedEpoch <= headState.FinalizedCheckpoint.Epoch,
Participation: participation,
}, nil
} else if requestedEpoch > currentEpoch {
47 changes: 47 additions & 0 deletions beacon-chain/rpc/beacon/validators_test.go
Original file line number Diff line number Diff line change
@@ -1176,6 +1176,53 @@ func TestServer_GetValidatorParticipation_FromArchive(t *testing.T) {
}
}

func TestServer_GetValidatorParticipation_FromArchive_FinalizedEpoch(t *testing.T) {
db := dbTest.SetupDB(t)
defer dbTest.TeardownDB(t, db)
ctx := context.Background()
part := &ethpb.ValidatorParticipation{
GlobalParticipationRate: 1.0,
VotedEther: 20,
EligibleEther: 20,
}
epoch := uint64(1)
// We archive data for epoch 1.
if err := db.SaveArchivedValidatorParticipation(ctx, epoch, part); err != nil {
t.Fatal(err)
}

bs := &Server{
BeaconDB: db,
HeadFetcher: &mock.ChainService{
// 10 epochs into the future.
State: &pbp2p.BeaconState{
Slot: helpers.StartSlot(epoch + 10),
FinalizedCheckpoint: &ethpb.Checkpoint{
// We say there have been 5 epochs since finality.
Epoch: epoch + 5,
},
},
},
}
want := &ethpb.ValidatorParticipationResponse{
Epoch: epoch,
Finalized: true,
Participation: part,
}
// We request epoch 1.
res, err := bs.GetValidatorParticipation(ctx, &ethpb.GetValidatorParticipationRequest{
QueryFilter: &ethpb.GetValidatorParticipationRequest_Epoch{
Epoch: epoch,
},
})
if err != nil {
t.Fatal(err)
}
if !proto.Equal(want, res) {
t.Errorf("Wanted %v, received %v", want, res)
}
}

func TestServer_GetValidatorParticipation_CurrentEpoch(t *testing.T) {
helpers.ClearAllCaches()
db := dbTest.SetupDB(t)