-
Notifications
You must be signed in to change notification settings - Fork 1k
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 GetDuties
VC action
#13789
Optimize GetDuties
VC action
#13789
Conversation
|
||
nextEpochDuties, err := c.getDutiesForEpoch(ctx, in.Epoch+1, known, fetchSyncDuties) | ||
var currentEpochDuties []*ethpb.DutiesResponse_Duty |
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.
Question:
Why using an errgroup
here for only one goroutine?
(In general errgroup
s are used when several goroutines run in parallel, and we want manage the case one of them returns an error.)
A pattern without errgroup
could be the following:
errCh := make(chan error) // Create a channel for errors
go faultyFunction(errCh) // Start the faulty function in a new goroutine
// Do other stuffs
err := <-errCh // Wait for an error
fmt.Println("Received an error:", err)
With faultyFunction
sending the error at the end in errCh
.
However, I admit errgroup
totally works here.
} | ||
slotCommittees[c.Slot] = n + 1 | ||
} | ||
var wg errgroup.Group |
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.
Just as a safety measure, I would define:
attesterDutiesMapping
,syncDutiesMapping
,proposerDutySlots
andcommitteeMapping
at the same place in the code, and add a commentary saying that the main routine cannot use these variables before wg.Wait()
.
(Such a fact sounds obvious now, but in a few months/years an other developer may want to use these variables before the wg.Wait()
and some bad things may happen in this case.)
var attesterSlot primitives.Slot | ||
var committeeIndex primitives.CommitteeIndex | ||
var committeeValidatorIndices []primitives.ValidatorIndex |
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.
var attesterSlot primitives.Slot | |
var committeeIndex primitives.CommitteeIndex | |
var committeeValidatorIndices []primitives.ValidatorIndex | |
var ( | |
attesterSlot primitives.Slot | |
committeeIndex primitives.CommitteeIndex | |
committeeValidatorIndices []primitives.ValidatorIndex | |
) |
What type of PR is this?
Other
What does this PR do? Why is it needed?
This PR reduces the time to fetch duties from ~8-9s to ~2.5s by utilizing wait groups and making concurrent requests. Concurrency is spread between two layers:
Another piece of this PR is a
getValidatorsForDuties
function that is used instead ofmultipleValidatorStatus
, This is because the latter does many things that we don't need for duties, including a call toGetValidatorCount
which currently takes around 250ms on Holesky.