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

Register sync subnet when fetching sync committee duties through Beacon API #12972

Merged
merged 5 commits into from
Oct 16, 2023

Conversation

rkapka
Copy link
Contributor

@rkapka rkapka commented Sep 29, 2023

What type of PR is this?

Other

What does this PR do? Why is it needed?

When fetching validator duties through v1alpha1, we register sync subnets. This was never present in the Beacon API.

Registration logic is moved from beacon-chain/rpc/prysm/v1alpha1/validator/assignments.go to beacon-chain/rpc/core/validator.go. There are two pairs of functions, with and without Proto suffix, to deal with two different types representing the validator's status.

Which issues(s) does this PR fix?

Part of #12958

@rkapka rkapka added the API Api related tasks label Sep 29, 2023
@rkapka rkapka requested a review from a team as a code owner September 29, 2023 17:41
@rkapka rkapka added the Ready For Review A pull request ready for code review label Sep 29, 2023
@@ -978,15 +978,16 @@ func (s *Server) GetSyncCommitteeDuties(w http.ResponseWriter, r *http.Request)
return
}
nextSyncCommitteeFirstEpoch := currentSyncCommitteeFirstEpoch + params.BeaconConfig().EpochsPerSyncCommitteePeriod
currentCommitteeRequested := requestedEpoch < nextSyncCommitteeFirstEpoch
Copy link
Contributor

Choose a reason for hiding this comment

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

suggested rename to indicate a boolean isCurrentCommitteeRequested

@@ -997,11 +998,38 @@ func (s *Server) GetSyncCommitteeDuties(w http.ResponseWriter, r *http.Request)
pubkey48 := bytesutil.ToBytes48(pubkey)
committeePubkeys[pubkey48] = append(committeePubkeys[pubkey48], strconv.FormatUint(uint64(j), 10))
}
duties, err := syncCommitteeDuties(requestedValIndices, st, committeePubkeys)
duties, vals, err := syncCommitteeDutiesAndVals(requestedValIndices, st, committeePubkeys)
Copy link
Contributor

Choose a reason for hiding this comment

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

it might more readable if this function was duplicated instead of having the if statements duplicated
or you can set a function inside to alias the function like

var operation (s beaconState.BeaconState, epoch primitives.Epoch, pubKey []byte, status ethpb.ValidatorStatus) error

operation = core.RegisterSyncSubnetCurrentPeriod  or core.RegisterSyncSubnetNextPeriod
and use 

operation(st, requestedEpoch, pk[:], valStatus)

this way you can skip copying and pasting most of the loop or even put it in its own function.

@@ -1169,29 +1197,35 @@ func syncCommitteeDutiesLastValidEpoch(currentEpoch primitives.Epoch) primitives
return (currentSyncPeriodIndex+2)*params.BeaconConfig().EpochsPerSyncCommitteePeriod - 1
}

func syncCommitteeDuties(
func syncCommitteeDutiesAndVals(
Copy link
Contributor

Choose a reason for hiding this comment

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

this function seems to be doing a lot and taking in a bunch of different arguments to do its tasks, i wonder if we can do something about that..
maybe we can get rid of some of this and break some of this up by moving this logic into where request indices is processed

requestedValIndices := make([]primitives.ValidatorIndex, len(indices))
	for i, ix := range indices {
		valIx, valid := shared.ValidateUint(w, fmt.Sprintf("ValidatorIndices[%d]", i), ix)
		if !valid {
			return
		}
		requestedValIndices[i] = primitives.ValidatorIndex(valIx)
	}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's difficult to split this function without doing some of the work twice. I reordered params and added a comment, hope that's ok.

Comment on lines 558 to 560
// registerSyncSubnet checks the status and pubkey of a particular validator
// to discern whether persistent subnets need to be registered for them.
func registerSyncSubnetInternal(
Copy link
Contributor

Choose a reason for hiding this comment

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

This comment seems to belong to the function on line 532

@@ -483,3 +484,122 @@ func (s *Service) SubmitSyncMessage(ctx context.Context, msg *ethpb.SyncCommitte
// Wait for p2p broadcast to complete and return the first error (if any)
return errs.Wait()
}

// RegisterSyncSubnetCurrentPeriod registers a persistent subnet for the current sync committee period.
func RegisterSyncSubnetCurrentPeriod(s beaconState.BeaconState, epoch primitives.Epoch, pubKey []byte, status validator.ValidatorStatus) error {
Copy link
Contributor

Choose a reason for hiding this comment

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

Most of these added functions don't appear to have any unit tests.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The tests in validator_test.go already existed in v1alpha1. We don't add any new tests to the core service because the code is tested indirectly through handlers and v1alpha1 endpoints.

@prylabs-bulldozer prylabs-bulldozer bot merged commit b52baba into develop Oct 16, 2023
16 of 17 checks passed
@prylabs-bulldozer prylabs-bulldozer bot deleted the register-sync-subnet branch October 16, 2023 17:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
API Api related tasks Ready For Review A pull request ready for code review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants