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

Optimize SubscribeCommitteeSubnets VC action #13702

Merged
merged 6 commits into from Mar 8, 2024

Conversation

rkapka
Copy link
Contributor

@rkapka rkapka commented Mar 7, 2024

What type of PR is this?

Other

What does this PR do? Why is it needed?

SubscribeCommitteeSubnets in the REST VC takes around 1-2 seconds. Almost all of this time is spend on fetching duties to get the number of committees in a slot, but we already return this value when fetching duties at the beginning of the epoch, we just need to pass it into the function. Adding committees_at_slot to the duty proto message allows us to have this value available.

This reduces the time needed to subscribe from 1-2 seconds to 1 millisecond.

@rkapka rkapka requested a review from a team as a code owner March 7, 2024 16:21
@rkapka rkapka force-pushed the optimize-SubscribeCommitteeSubnets branch from e8dc90a to 818d075 Compare March 7, 2024 16:33
@rkapka rkapka added Ready For Review A pull request ready for code review API Api related tasks Validator Client labels Mar 7, 2024
@@ -3899,7 +3899,7 @@ var file_proto_prysm_v1alpha1_beacon_block_proto_rawDesc = []byte{
0x64, 0x72, 0x61, 0x77, 0x61, 0x6c, 0x73, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x1a, 0x26, 0x70,
0x72, 0x6f, 0x74, 0x6f, 0x2f, 0x65, 0x6e, 0x67, 0x69, 0x6e, 0x65, 0x2f, 0x76, 0x31, 0x2f, 0x65,
0x78, 0x65, 0x63, 0x75, 0x74, 0x69, 0x6f, 0x6e, 0x5f, 0x65, 0x6e, 0x67, 0x69, 0x6e, 0x65, 0x2e,
0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0xf4, 0x05, 0x0a, 0x18, 0x47, 0x65, 0x6e, 0x65, 0x72, 0x69,
0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0xee, 0x05, 0x0a, 0x18, 0x47, 0x65, 0x6e, 0x65, 0x72, 0x69,
Copy link
Contributor

Choose a reason for hiding this comment

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

Why was this file changed if no proto changed?

@@ -537,6 +537,8 @@ message DutiesResponse {

// Whether the validator belongs in the sync committee and has to perform sync committee duty.
bool is_sync_committee = 8;

uint64 committees_at_slot = 9;
Copy link
Contributor

Choose a reason for hiding this comment

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

All other values in this file have a comment.

@@ -95,6 +95,11 @@ func (c beaconApiValidatorClient) getDutiesForEpoch(
if err != nil {
return nil, errors.Wrapf(err, "failed to get committees for epoch `%d`", epoch)
}
slotCommittees := make(map[string]uint64)
for _, c := range committees {
n := slotCommittees[c.Slot]
Copy link
Contributor

Choose a reason for hiding this comment

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

Even if this works correctly, I think it would be better to explicitly handle the case where c.Slot is not in slotCommittees, instead of relying on the default missing value of uint64.

Something like

	for _, c := range committees {
		n, ok := slotCommittees[c.Slot]
		if !ok {
			n = 0
		}
		slotCommittees[c.Slot] = n + 1
	}

validator/client/beacon-api/duties.go Show resolved Hide resolved
@nalepae nalepae self-requested a review March 8, 2024 15:36
@rkapka rkapka added this pull request to the merge queue Mar 8, 2024
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to no response for status checks Mar 8, 2024
@rkapka rkapka added this pull request to the merge queue Mar 8, 2024
Merged via the queue into develop with commit 9e73527 Mar 8, 2024
16 of 17 checks passed
@rkapka rkapka deleted the optimize-SubscribeCommitteeSubnets branch March 8, 2024 18:42
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 Validator Client
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants