Skip to content

Commit

Permalink
fix: refetch duties after metdata update (main) (#1429)
Browse files Browse the repository at this point in the history
* fix: refetch duties after metdata update (`main`)
* new metadata refresh mechanism
  • Loading branch information
moshe-blox authored Jul 2, 2024
1 parent 40eb334 commit cc6f7d1
Show file tree
Hide file tree
Showing 12 changed files with 291 additions and 150 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -228,4 +228,4 @@ replace github.com/google/flatbuffers => github.com/google/flatbuffers v1.11.0

replace github.com/dgraph-io/ristretto => github.com/dgraph-io/ristretto v0.1.1-0.20211108053508-297c39e6640f

replace github.com/attestantio/go-eth2-client => github.com/ssvlabs/go-eth2-client v0.0.0-20240623135036-ab92a705c625
replace github.com/attestantio/go-eth2-client => github.com/ssvlabs/go-eth2-client v0.0.0-20240702122821-2c345f4fc90f
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -754,8 +754,8 @@ github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
github.com/spf13/viper v1.0.0/go.mod h1:A8kyI5cUJhb8N+3pkfONlcEcZbueH6nhAm0Fq7SrnBM=
github.com/spf13/viper v1.3.2/go.mod h1:ZiWeW+zYFKm7srdB9IoDzzZXaJaI5eL9QjNiN/DMA2s=
github.com/ssvlabs/go-eth2-client v0.0.0-20240623135036-ab92a705c625 h1:JX8uEqeUtup8VmdCBWk7V/uZVRe3QY3/rVcCFu/5s6Y=
github.com/ssvlabs/go-eth2-client v0.0.0-20240623135036-ab92a705c625/go.mod h1:TTz7YF6w4z6ahvxKiHuGPn6DbQn7gH6HPuWm/DEQeGE=
github.com/ssvlabs/go-eth2-client v0.0.0-20240702122821-2c345f4fc90f h1:ZaokUqygFE81zqNd8mQmdrX2B8AkhYmt0i6gs9RDXi0=
github.com/ssvlabs/go-eth2-client v0.0.0-20240702122821-2c345f4fc90f/go.mod h1:TTz7YF6w4z6ahvxKiHuGPn6DbQn7gH6HPuWm/DEQeGE=
github.com/status-im/keycard-go v0.2.0 h1:QDLFswOQu1r5jsycloeQh3bVU8n/NatHHaZobtDnDzA=
github.com/status-im/keycard-go v0.2.0/go.mod h1:wlp8ZLbsmrF6g6WjugPAx+IzoLrkdf9+mHxBEeo3Hbg=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
Expand Down
5 changes: 4 additions & 1 deletion operator/duties/attester.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,15 @@ func (h *AttesterHandler) HandleDuties(ctx context.Context) {

h.fetchNextEpoch = true

next := h.ticker.Next()
for {
select {
case <-ctx.Done():
return

case <-h.ticker.Next():
case <-next:
slot := h.ticker.Slot()
next = h.ticker.Next()
currentEpoch := h.network.Beacon.EstimatedEpochAtSlot(slot)
buildStr := fmt.Sprintf("e%v-s%v-#%v", currentEpoch, slot, slot%32+1)
h.logger.Debug("🛠 ticker event", zap.String("epoch_slot_seq", buildStr))
Expand Down Expand Up @@ -188,6 +190,7 @@ func (h *AttesterHandler) fetchAndProcessDuties(ctx context.Context, epoch phase
indices := h.validatorController.CommitteeActiveIndices(epoch)

if len(indices) == 0 {
h.logger.Debug("no active validators for epoch", fields.Epoch(epoch))
return nil
}

Expand Down
5 changes: 4 additions & 1 deletion operator/duties/proposer.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,15 @@ func (h *ProposerHandler) Name() string {
func (h *ProposerHandler) HandleDuties(ctx context.Context) {
h.logger.Info("starting duty handler")

next := h.ticker.Next()
for {
select {
case <-ctx.Done():
return

case <-h.ticker.Next():
case <-next:
slot := h.ticker.Slot()
next = h.ticker.Next()
currentEpoch := h.network.Beacon.EstimatedEpochAtSlot(slot)
buildStr := fmt.Sprintf("e%v-s%v-#%v", currentEpoch, slot, slot%32+1)
h.logger.Debug("🛠 ticker event", zap.String("epoch_slot_seq", buildStr))
Expand Down Expand Up @@ -148,6 +150,7 @@ func (h *ProposerHandler) fetchAndProcessDuties(ctx context.Context, epoch phase

allIndices := h.validatorController.AllActiveIndices(epoch, false)
if len(allIndices) == 0 {
h.logger.Debug("no active validators for epoch", fields.Epoch(epoch))
return nil
}

Expand Down
5 changes: 4 additions & 1 deletion operator/duties/sync_committee.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,15 @@ func (h *SyncCommitteeHandler) HandleDuties(ctx context.Context) {
h.fetchNextPeriod = true
}

next := h.ticker.Next()
for {
select {
case <-ctx.Done():
return

case <-h.ticker.Next():
case <-next:
slot := h.ticker.Slot()
next = h.ticker.Next()
epoch := h.network.Beacon.EstimatedEpochAtSlot(slot)
period := h.network.Beacon.EstimatedSyncCommitteePeriodAtEpoch(epoch)
buildStr := fmt.Sprintf("p%v-%v-s%v-#%v", period, epoch, slot, slot%32+1)
Expand Down Expand Up @@ -196,6 +198,7 @@ func (h *SyncCommitteeHandler) fetchAndProcessDuties(ctx context.Context, period

allActiveIndices := h.validatorController.AllActiveIndices(firstEpoch, waitForInitial)
if len(allActiveIndices) == 0 {
h.logger.Debug("no active validators for period", fields.Epoch(currentEpoch), zap.Uint64("period", period))
return nil
}

Expand Down
4 changes: 3 additions & 1 deletion operator/duties/validatorregistration.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,15 @@ func (h *ValidatorRegistrationHandler) HandleDuties(ctx context.Context) {
// should be registered within validatorRegistrationEpochInterval epochs time in a corresponding slot
registrationSlotInterval := h.network.SlotsPerEpoch() * validatorRegistrationEpochInterval

next := h.ticker.Next()
for {
select {
case <-ctx.Done():
return

case <-h.ticker.Next():
case <-next:
slot := h.ticker.Slot()
next = h.ticker.Next()
epoch := h.network.Beacon.EstimatedEpochAtSlot(slot)
shares := h.validatorController.GetOperatorShares()

Expand Down
4 changes: 3 additions & 1 deletion operator/duties/voluntary_exit.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,15 @@ func (h *VoluntaryExitHandler) Name() string {
func (h *VoluntaryExitHandler) HandleDuties(ctx context.Context) {
h.logger.Info("starting duty handler")

next := h.ticker.Next()
for {
select {
case <-ctx.Done():
return

case <-h.ticker.Next():
case <-next:
currentSlot := h.ticker.Slot()
next = h.ticker.Next()

h.logger.Debug("🛠 ticker event", fields.Slot(currentSlot))

Expand Down
Loading

0 comments on commit cc6f7d1

Please sign in to comment.