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 a new slot ticker and use it on attestation aggregation #12377

Merged
merged 13 commits into from May 10, 2023

Conversation

potuz
Copy link
Contributor

@potuz potuz commented May 9, 2023

This PR adds:

  • It adds a SlotTickerWithIntervals that accepts a series of intervals between 0 and 12 seconds (not inclusive) so that the ticker ticks every slot at those offsets.
  • It adds feature flags that allow to customize the precise three spots where we aggregate attestations (they are done three times per slot).
  • Waits for init sync to complete before starting the attestation service

@potuz potuz added the Ready For Review A pull request ready for code review label May 9, 2023
@potuz potuz requested a review from a team as a code owner May 9, 2023 16:33
Copy link
Member

@terencechain terencechain left a comment

Choose a reason for hiding this comment

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

Please update the title. The PR is doing more than a new slot tickers

@potuz potuz changed the title Slot tickers Add a new slot ticker and use it on attestation aggregation May 9, 2023
terencechain
terencechain previously approved these changes May 9, 2023
@potuz potuz added the Blocked Blocked by research or external factors label May 9, 2023
@potuz
Copy link
Contributor Author

potuz commented May 9, 2023

Blocking for Preston to take a look, would like to deploy this 24 hours in the Prater fleet

slotDuration := time.Duration(params.BeaconConfig().SecondsPerSlot) * time.Second
// Adjust intervals for networks with a lower slot duration (Hive, e2e, etc)
for {
if intervals[len(intervals)-1] >= slotDuration {
Copy link
Member

Choose a reason for hiding this comment

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

Optional: This will panic if len(intervals) == 0. That might be OK, but consider a meaningful panic like

if len(intervals) == 0 {
  panic("unable to create timers for attestation aggregation with no intervals provided")
}

In my opinion, that is better than index out of range panic. Ideally, we never panic and simply return an error here though

If this code is temporary for the feature flag, then it might be OK as is. I'm thinking about future proofing so if there is not much future for this then you can dismiss this suggestion.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

panic is good here IMO since the intervals are hardcoded configuration constants with defaults. Someone would have to remove the code with the configuration constants for this to panic.

for {
if intervals[len(intervals)-1] >= slotDuration {
for i, offset := range intervals {
intervals[i] = offset / 2
Copy link
Member

Choose a reason for hiding this comment

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

Why is this halved?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

because the intervals are set by default to be something that works for 12 seconds per slot, but special networks use other parameters. We are halving them to deal with the most common scenario of 6 seconds per slot in Hive. If someone wants to try 4 seconds per slot (which doesn't work even on interop) at least this prevents the panic

Comment on lines 145 to 168
func NewSlotTickerWithIntervals(genesisTime time.Time, intervals []time.Duration) *SlotTicker {
if genesisTime.Unix() == 0 {
panic("zero genesis time")
}
if len(intervals) == 0 {
panic("at least one interval has to be entered")
}
slotDuration := time.Duration(params.BeaconConfig().SecondsPerSlot) * time.Second
lastOffset := time.Duration(0)
for _, offset := range intervals {
if offset < lastOffset {
panic("invalid decreasing offsets")
}
if offset >= slotDuration {
panic("invalid ticker offset")
}
}
ticker := &SlotTicker{
c: make(chan primitives.Slot),
done: make(chan struct{}),
}
ticker.startWithIntervals(genesisTime, prysmTime.Until, time.After, intervals)
return ticker
}
Copy link
Member

Choose a reason for hiding this comment

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

Consider returning an error instead of panicking.

Could you add tests for the input validation? Or is this more temporary feature testing logic?

@@ -51,10 +53,24 @@ func NewService(ctx context.Context, cfg *Config) (*Service, error) {

// Start an attestation pool service's main event loop.
func (s *Service) Start() {
if err := s.waitForSync(s.cfg.InitialSyncComplete); err != nil {
log.WithError(err)
Copy link
Member

Choose a reason for hiding this comment

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

This won't log anything. log.WithError(err) is an alias for log.WithField("error", err), you still have to call log.WithError(err).Error("Failed to wait for sync") or some other log method.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yeah sorry, forgot to add the message, pushing the fix

@potuz potuz added OK to merge and removed Blocked Blocked by research or external factors labels May 10, 2023
@prylabs-bulldozer prylabs-bulldozer bot merged commit f6764fe into develop May 10, 2023
16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Ready For Review A pull request ready for code review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants