Skip to content

Commit

Permalink
Optimize GetDuties to not call Eth1 functions (#5516)
Browse files Browse the repository at this point in the history
* Remove unneeded validator status calls for GetDuties
* Cleanup validator runner function
* Improvements
* Undo validator client changes
* Merge branch 'master' into optimize-getduties
* Revert "Undo validator client changes"

This reverts commit 4385181.
* Merge branch 'master' of https://github.com/prysmaticlabs/prysm into optimize-getduties
* Remove unneeded tests
* Merge branch 'optimize-getduties' of https://github.com/0xKiwi/Prysm into optimize-getduties
* Revert "Cleanup validator runner function"

This reverts commit f0c8c5e.
* Add back test
* Optimize getduties
* Merge branch 'master' of https://github.com/prysmaticlabs/prysm into optimize-getduties
* Merge branch 'master' into optimize-getduties
  • Loading branch information
0xKiwi committed Apr 20, 2020
1 parent 982d935 commit 60bf3ed
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 41 deletions.
16 changes: 7 additions & 9 deletions beacon-chain/rpc/validator/assignments.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func (vs *Server) GetDuties(ctx context.Context, req *ethpb.DutiesRequest) (*eth

var committeeIDs []uint64
var nextCommitteeIDs []uint64
var validatorAssignments []*ethpb.DutiesResponse_Duty
validatorAssignments := make([]*ethpb.DutiesResponse_Duty, 0, len(req.PublicKeys))
for _, pubKey := range req.PublicKeys {
if ctx.Err() != nil {
return nil, status.Errorf(codes.Aborted, "Could not continue fetching assignments: %v", ctx.Err())
Expand All @@ -58,14 +58,14 @@ func (vs *Server) GetDuties(ctx context.Context, req *ethpb.DutiesRequest) (*eth

idx, ok := s.ValidatorIndexByPubkey(bytesutil.ToBytes48(pubKey))
if ok {
assignment.ValidatorIndex = idx
assignment.Status = vs.assignmentStatus(idx, s)
assignment.ProposerSlots = proposerIndexToSlots[idx]

ca, ok := committeeAssignments[idx]
if ok {
assignment.Committee = ca.Committee
assignment.Status = vs.assignmentStatus(idx, s)
assignment.ValidatorIndex = idx
assignment.PublicKey = pubKey
assignment.AttesterSlot = ca.AttesterSlot
assignment.ProposerSlots = proposerIndexToSlots[idx]
assignment.CommitteeIndex = ca.CommitteeIndex
committeeIDs = append(committeeIDs, ca.CommitteeIndex)
}
Expand All @@ -74,13 +74,11 @@ func (vs *Server) GetDuties(ctx context.Context, req *ethpb.DutiesRequest) (*eth
if ok {
nextCommitteeIDs = append(nextCommitteeIDs, ca.CommitteeIndex)
}

} else {
vs := vs.validatorStatus(ctx, pubKey, s)
assignment.Status = vs.Status
// If the validator isn't in the beacon state, assume their status is unknown.
assignment.Status = ethpb.ValidatorStatus_UNKNOWN_STATUS
}
validatorAssignments = append(validatorAssignments, assignment)

}

return &ethpb.DutiesResponse{
Expand Down
32 changes: 0 additions & 32 deletions beacon-chain/rpc/validator/assignments_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,38 +28,6 @@ func pubKey(i uint64) []byte {
binary.LittleEndian.PutUint64(pubKey, uint64(i))
return pubKey
}

func TestGetDuties_NextEpoch_WrongPubkeyLength(t *testing.T) {
db := dbutil.SetupDB(t)
defer dbutil.TeardownDB(t, db)
ctx := context.Background()

beaconState, _ := testutil.DeterministicGenesisState(t, 8)
block := blk.NewGenesisBlock([]byte{})
if err := db.SaveBlock(ctx, block); err != nil {
t.Fatalf("Could not save genesis block: %v", err)
}
genesisRoot, err := ssz.HashTreeRoot(block.Block)
if err != nil {
t.Fatalf("Could not get signing root %v", err)
}

Server := &Server{
BeaconDB: db,
HeadFetcher: &mockChain.ChainService{State: beaconState, Root: genesisRoot[:]},
SyncChecker: &mockSync.Sync{IsSyncing: false},
Eth1InfoFetcher: &mockPOW.POWChain{},
DepositFetcher: depositcache.NewDepositCache(),
}
req := &ethpb.DutiesRequest{
PublicKeys: [][]byte{{1}},
Epoch: 0,
}
if _, err := Server.GetDuties(context.Background(), req); err != nil && !strings.Contains(err.Error(), "incorrect key length") {
t.Errorf("Expected \"incorrect key length\", received %v", err)
}
}

func TestGetDuties_NextEpoch_CantFindValidatorIdx(t *testing.T) {
db := dbutil.SetupDB(t)
defer dbutil.TeardownDB(t, db)
Expand Down

0 comments on commit 60bf3ed

Please sign in to comment.