Skip to content

Commit

Permalink
Merge pull request #163 from attestantio/validator-registration-jitter
Browse files Browse the repository at this point in the history
Validator registration jitter
  • Loading branch information
mcdee authored Dec 30, 2023
2 parents fb432a2 + 66573ec commit ecd05a1
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ dev:
- fetch blinded and unblinded proposals in parallel to speed up block production
- support Deneb beta.3
- compose multiclients from clients, reducing connections to beacon nodes
- start validator registrations randomly in middle 80% of each epoch, to avoid overloading relays

1.7.6:
- add User-Agent header to HTTP requests
Expand Down
11 changes: 6 additions & 5 deletions services/blockrelay/standard/submitvalidatorregistrations.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
"context"
"encoding/json"
"fmt"
"math/rand"
"sync"
"time"

Expand Down Expand Up @@ -45,13 +46,13 @@ func (s *Service) submitValidatorRegistrationsRuntime(_ context.Context,
time.Time,
error,
) {
// Schedule for the middle of the slot, half-way through the next epoch.
// Schedule for an abitrary time in the middle 80% of the next epoch, to avoid overloading the relays
// with lots of simultaneous registrations.
currentEpoch := s.chainTime.CurrentEpoch()
epochDuration := s.chainTime.StartOfEpoch(currentEpoch + 1).Sub(s.chainTime.StartOfEpoch(currentEpoch))
currentSlot := s.chainTime.CurrentSlot()
slotDuration := s.chainTime.StartOfSlot(currentSlot + 1).Sub(s.chainTime.StartOfSlot(currentSlot))
offset := int(epochDuration.Seconds()/2.0 + slotDuration.Seconds()/2.0)
return s.chainTime.StartOfEpoch(currentEpoch + 1).Add(time.Duration(offset) * time.Second), nil
//nolint:gosec // Secure random number generation not required.
offset := ((10 + rand.Int63n(80)) * epochDuration.Milliseconds()) / 100
return s.chainTime.StartOfEpoch(currentEpoch + 1).Add(time.Duration(offset) * time.Millisecond), nil
}

// SubmitValidatorRegistrations submits validator registrations for the given accounts.
Expand Down

0 comments on commit ecd05a1

Please sign in to comment.