mirror of
https://github.com/OffchainLabs/prysm.git
synced 2026-01-10 13:58:09 -05:00
Optimize List Validator Assignments (#4456)
* optimize * Merge refs/heads/master into listValidatorAssingments * Merge refs/heads/master into listValidatorAssingments * Merge refs/heads/master into listValidatorAssingments * Merge refs/heads/master into listValidatorAssingments * Merge refs/heads/master into listValidatorAssingments * Merge refs/heads/master into listValidatorAssingments * Merge refs/heads/master into listValidatorAssingments * Merge refs/heads/master into listValidatorAssingments * Merge refs/heads/master into listValidatorAssingments * terence's and preston's review * Merge branch 'listValidatorAssingments' of https://github.com/prysmaticlabs/geth-sharding into listValidatorAssingments
This commit is contained in:
committed by
prylabs-bulldozer[bot]
parent
39b2570af5
commit
699e1c8a23
@@ -101,42 +101,30 @@ 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, archivedBalances, err = bs.archivedCommitteeData(ctx, requestedEpoch)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
} 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 +145,12 @@ func (bs *Server) ListValidatorAssignments(
|
||||
res = append(res, assign)
|
||||
continue
|
||||
}
|
||||
committee, committeeIndex, attesterSlot, proposerSlot, err := helpers.CommitteeAssignment(headState, requestedEpoch, index)
|
||||
if err != nil {
|
||||
return nil, status.Errorf(codes.Internal, "Could not retrieve assignment for validator %d: %v", index, err)
|
||||
}
|
||||
comAssignment := committeeAssignments[index]
|
||||
assign := ðpb.ValidatorAssignments_CommitteeAssignment{
|
||||
BeaconCommittees: committee,
|
||||
CommitteeIndex: committeeIndex,
|
||||
AttesterSlot: attesterSlot,
|
||||
ProposerSlot: proposerSlot,
|
||||
BeaconCommittees: comAssignment.Committee,
|
||||
CommitteeIndex: comAssignment.CommitteeIndex,
|
||||
AttesterSlot: comAssignment.AttesterSlot,
|
||||
ProposerSlot: proposerIndexToSlot[index],
|
||||
PublicKey: headState.Validators[index].PublicKey,
|
||||
}
|
||||
res = append(res, assign)
|
||||
@@ -228,6 +213,41 @@ func archivedValidatorCommittee(
|
||||
return nil, 0, 0, 0, fmt.Errorf("could not find committee for validator index %d", validatorIndex)
|
||||
}
|
||||
|
||||
func (bs *Server) archivedCommitteeData(ctx context.Context, requestedEpoch uint64) (*pb.ArchivedCommitteeInfo,
|
||||
[]uint64, error) {
|
||||
archivedInfo, err := bs.BeaconDB.ArchivedCommitteeInfo(ctx, requestedEpoch)
|
||||
if err != nil {
|
||||
return nil, nil, status.Errorf(
|
||||
codes.Internal,
|
||||
"Could not retrieve archived committee info for epoch %d",
|
||||
requestedEpoch,
|
||||
)
|
||||
}
|
||||
if archivedInfo == nil {
|
||||
return nil, 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, nil, status.Errorf(
|
||||
codes.Internal,
|
||||
"Could not retrieve archived balances for epoch %d",
|
||||
requestedEpoch,
|
||||
)
|
||||
}
|
||||
if archivedBalances == nil {
|
||||
return nil, nil, status.Errorf(
|
||||
codes.NotFound,
|
||||
"Could not retrieve data for epoch %d, perhaps --archive in the running beacon node is disabled",
|
||||
requestedEpoch,
|
||||
)
|
||||
}
|
||||
return archivedInfo, archivedBalances, nil
|
||||
}
|
||||
|
||||
// helpers.ComputeProposerIndex wrapper.
|
||||
func archivedProposerIndex(activeIndices []uint64, activeBalances []uint64, seed [32]byte) (uint64, error) {
|
||||
validators := make([]*ethpb.Validator, len(activeBalances))
|
||||
|
||||
Reference in New Issue
Block a user