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
Optimize List Validator Assignments #4456
Merged
Merged
Changes from 6 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
f164977
optimize
nisdas 8303697
Merge refs/heads/master into listValidatorAssingments
prylabs-bulldozer[bot] 6685065
Merge refs/heads/master into listValidatorAssingments
prylabs-bulldozer[bot] b5588ef
Merge refs/heads/master into listValidatorAssingments
prylabs-bulldozer[bot] df08fa7
Merge refs/heads/master into listValidatorAssingments
prylabs-bulldozer[bot] ffa1548
Merge refs/heads/master into listValidatorAssingments
prylabs-bulldozer[bot] 745e599
Merge refs/heads/master into listValidatorAssingments
prylabs-bulldozer[bot] da71060
Merge refs/heads/master into listValidatorAssingments
prylabs-bulldozer[bot] dd95fee
Merge refs/heads/master into listValidatorAssingments
prylabs-bulldozer[bot] 39b997c
Merge refs/heads/master into listValidatorAssingments
prylabs-bulldozer[bot] 963755a
terence's and preston's review
nisdas 46471bf
Merge branch 'listValidatorAssingments' of https://github.com/prysmat…
nisdas File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -101,42 +101,56 @@ func (bs *Server) ListValidatorAssignments( | |
|
||
shouldFetchFromArchive := requestedEpoch < bs.FinalizationFetcher.FinalizedCheckpt().Epoch | ||
|
||
// initialize all committee related data. | ||
committeeAssignments := map[uint64]*helpers.CommitteeAssignmentContainer{} | ||
proposerIndexToSlot := map[uint64]uint64{} | ||
archivedInfo := &pb.ArchivedCommitteeInfo{} | ||
archivedBalances := []uint64{} | ||
|
||
if shouldFetchFromArchive { | ||
archivedInfo, err = bs.BeaconDB.ArchivedCommitteeInfo(ctx, requestedEpoch) | ||
if err != nil { | ||
return nil, status.Errorf( | ||
codes.Internal, | ||
"Could not retrieve archived committee info for epoch %d", | ||
requestedEpoch, | ||
) | ||
} | ||
if archivedInfo == nil { | ||
return nil, status.Errorf( | ||
codes.NotFound, | ||
"Could not retrieve data for epoch %d, perhaps --archive in the running beacon node is disabled", | ||
requestedEpoch, | ||
) | ||
} | ||
archivedBalances, err = bs.BeaconDB.ArchivedBalances(ctx, requestedEpoch) | ||
if err != nil { | ||
return nil, status.Errorf( | ||
codes.Internal, | ||
"Could not retrieve archived balances for epoch %d", | ||
requestedEpoch, | ||
) | ||
} | ||
if archivedBalances == nil { | ||
return nil, status.Errorf( | ||
codes.NotFound, | ||
"Could not retrieve data for epoch %d, perhaps --archive in the running beacon node is disabled", | ||
requestedEpoch, | ||
) | ||
} | ||
} else { | ||
committeeAssignments, proposerIndexToSlot, err = helpers.CommitteeAssignments(headState, requestedEpoch) | ||
if err != nil { | ||
return nil, status.Errorf(codes.Internal, "Could not compute committee assignments: %v", err) | ||
} | ||
} | ||
|
||
for _, index := range filteredIndices[start:end] { | ||
if int(index) >= len(headState.Validators) { | ||
return nil, status.Errorf(codes.OutOfRange, "Validator index %d >= validator count %d", | ||
index, len(headState.Validators)) | ||
} | ||
if shouldFetchFromArchive { | ||
archivedInfo, err := bs.BeaconDB.ArchivedCommitteeInfo(ctx, requestedEpoch) | ||
if err != nil { | ||
return nil, status.Errorf( | ||
codes.Internal, | ||
"Could not retrieve archived committee info for epoch %d", | ||
requestedEpoch, | ||
) | ||
} | ||
if archivedInfo == nil { | ||
return nil, status.Errorf( | ||
codes.NotFound, | ||
"Could not retrieve data for epoch %d, perhaps --archive in the running beacon node is disabled", | ||
requestedEpoch, | ||
) | ||
} | ||
archivedBalances, err := bs.BeaconDB.ArchivedBalances(ctx, requestedEpoch) | ||
if err != nil { | ||
return nil, status.Errorf( | ||
codes.Internal, | ||
"Could not retrieve archived balances for epoch %d", | ||
requestedEpoch, | ||
) | ||
} | ||
if archivedBalances == nil { | ||
return nil, status.Errorf( | ||
codes.NotFound, | ||
"Could not retrieve data for epoch %d, perhaps --archive in the running beacon node is disabled", | ||
requestedEpoch, | ||
) | ||
} | ||
committee, committeeIndex, attesterSlot, proposerSlot, err := archivedValidatorCommittee( | ||
requestedEpoch, | ||
index, | ||
|
@@ -157,15 +171,12 @@ func (bs *Server) ListValidatorAssignments( | |
res = append(res, assign) | ||
continue | ||
} | ||
committee, committeeIndex, attesterSlot, proposerSlot, err := helpers.CommitteeAssignment(headState, requestedEpoch, index) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yikes, this was the really slow one! |
||
if err != nil { | ||
return nil, status.Errorf(codes.Internal, "Could not retrieve assignment for validator %d: %v", index, err) | ||
} | ||
comAssingnment := committeeAssignments[index] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Typo here |
||
assign := ðpb.ValidatorAssignments_CommitteeAssignment{ | ||
BeaconCommittees: committee, | ||
CommitteeIndex: committeeIndex, | ||
AttesterSlot: attesterSlot, | ||
ProposerSlot: proposerSlot, | ||
BeaconCommittees: comAssingnment.Committee, | ||
CommitteeIndex: comAssingnment.CommitteeIndex, | ||
AttesterSlot: comAssingnment.AttesterSlot, | ||
ProposerSlot: proposerIndexToSlot[index], | ||
PublicKey: headState.Validators[index].PublicKey, | ||
} | ||
res = append(res, assign) | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 know this is not new code, but can you refactor everything within
shouldFetchFromArchive
into its function?