Properly Return Finalized Epoch in GetValidatorParticipation Archival Endpoint (#4091)

* properly handle retrieving archived finalized epochs
* test passes for determining if epoch finalized
* Merge branch 'master' into archive-finality
* Merge refs/heads/master into archive-finality
* Merge refs/heads/master into archive-finality
* Merge refs/heads/master into archive-finality
* Merge refs/heads/master into archive-finality
* Merge refs/heads/master into archive-finality
* Merge branch 'master' into archive-finality
* prevent setup panic
* Merge branch 'archive-finality' of github.com:prysmaticlabs/prysm into archive-finality
* Merge refs/heads/master into archive-finality
This commit is contained in:
Raul Jordan 2019-11-25 09:26:32 -06:00 committed by prylabs-bulldozer[bot]
parent 7a9c297206
commit feb1267fee
2 changed files with 53 additions and 6 deletions

View File

@ -371,7 +371,7 @@ func (bs *Server) GetValidatorParticipation(
}
return &ethpb.ValidatorParticipationResponse{
Epoch: requestedEpoch,
Finalized: true,
Finalized: requestedEpoch <= headState.FinalizedCheckpoint.Epoch,
Participation: participation,
}, nil
} else if requestedEpoch > currentEpoch {

View File

@ -1134,11 +1134,11 @@ func TestServer_GetValidatorParticipation_FromArchive(t *testing.T) {
bs := &Server{
BeaconDB: db,
HeadFetcher: &mock.ChainService{
State: &pbp2p.BeaconState{Slot: helpers.StartSlot(epoch + 1)},
},
FinalizationFetcher: &mock.ChainService{
FinalizedCheckPoint: &ethpb.Checkpoint{
Epoch: epoch + 1,
State: &pbp2p.BeaconState{
Slot: helpers.StartSlot(epoch + 1),
FinalizedCheckpoint: &ethpb.Checkpoint{
Epoch: epoch + 1,
},
},
},
}
@ -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)