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

add REST implementation for GetSyncSubcommitteeIndex #11971

Merged

Conversation

dB2510
Copy link
Contributor

@dB2510 dB2510 commented Feb 6, 2023

What type of PR is this?
Feature

Related issue
#11580

What does this PR do? Why is it needed?
It adds REST API implementation for GetSyncSubcommitteeIndex.

@dB2510 dB2510 requested a review from a team as a code owner February 6, 2023 18:13
Comment on lines 116 to 124
var indices []primitives.CommitteeIndex
for _, idx := range syncDuty.ValidatorSyncCommitteeIndices {
syncCommIdx, err := strconv.ParseUint(idx, 10, 64)
if err != nil {
return nil, errors.Wrap(err, "failed to parse validator sync committee index")
}

indices = append(indices, primitives.CommitteeIndex(syncCommIdx))
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
var indices []primitives.CommitteeIndex
for _, idx := range syncDuty.ValidatorSyncCommitteeIndices {
syncCommIdx, err := strconv.ParseUint(idx, 10, 64)
if err != nil {
return nil, errors.Wrap(err, "failed to parse validator sync committee index")
}
indices = append(indices, primitives.CommitteeIndex(syncCommIdx))
}
indices := make([]primitives.CommitteeIndex, len(syncDuty.ValidatorSyncCommitteeIndices))
for i, idx := range syncDuty.ValidatorSyncCommitteeIndices {
syncCommIdx, err := strconv.ParseUint(idx, 10, 64)
if err != nil {
return nil, errors.Wrap(err, "failed to parse validator sync committee index")
}
indices[i] = primitives.CommitteeIndex(syncCommIdx)
}

Copy link
Contributor Author

@dB2510 dB2510 Feb 8, 2023

Choose a reason for hiding this comment

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

Hi @nalepae !
Slice initialisation with make is recommended when the length of slice is constant or already known. In our case it length of indices depends on length syncDuty.ValidatorSyncCommitteeIndices slice. If syncDuty.ValidatorSyncCommitteeIndices slice is empty/nil then it doesn't make sense to pre-allocate indices slice. This makes zero value of slice useful, also recommended by Rob Pike: https://www.youtube.com/watch?v=PAAkCSZUG1c&t=385s

validator/client/beacon-api/sync_committee.go Outdated Show resolved Hide resolved

// TODO: Implement me
panic("beaconApiValidatorClient.GetSyncCommitteeContribution is not implemented. To use a fallback client, create this validator with NewBeaconApiValidatorClientWithFallback instead.")
return c.getSyncCommitteeContribution(ctx, in)
Copy link
Contributor

Choose a reason for hiding this comment

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

Nice catch

validator/client/beacon-api/sync_committee.go Outdated Show resolved Hide resolved
validator/client/beacon-api/sync_committee_test.go Outdated Show resolved Hide resolved
dB2510 and others added 2 commits February 8, 2023 18:24
Co-authored-by: Radosław Kapka <radek@prysmaticlabs.com>
@dB2510 dB2510 requested review from rkapka and removed request for prestonvanloon, saolyn and nisdas February 8, 2023 12:57
@prylabs-bulldozer prylabs-bulldozer bot merged commit 5092738 into prysmaticlabs:develop Feb 9, 2023
@dB2510 dB2510 deleted the get-sync-subcommittee branch February 9, 2023 11:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants