From d280491a9d6f14df92a49a48d97f79262a60a799 Mon Sep 17 00:00:00 2001 From: Sam Calder-Mason Date: Thu, 20 Jul 2023 14:00:41 +1000 Subject: [PATCH 1/2] refactor(duties): Simplify RequiredEpochDuties method --- pkg/sentry/ethereum/services/duties.go | 22 ++++++++-------------- 1 file changed, 8 insertions(+), 14 deletions(-) diff --git a/pkg/sentry/ethereum/services/duties.go b/pkg/sentry/ethereum/services/duties.go index a7dbbf86..c0a91952 100644 --- a/pkg/sentry/ethereum/services/duties.go +++ b/pkg/sentry/ethereum/services/duties.go @@ -75,7 +75,7 @@ func (m *DutiesService) Start(ctx context.Context) error { } }() - m.beacon.Wallclock().OnEpochChanged(func(epoch ethwallclock.Epoch) { + m.metadata.Wallclock().OnEpochChanged(func(epoch ethwallclock.Epoch) { if err := m.backFillEpochDuties(ctx); err != nil { m.log.WithError(err).Warn("Failed to fetch epoch duties") } @@ -104,25 +104,19 @@ func (m *DutiesService) Name() Name { return "duties" } -func (m *DutiesService) RequiredEpochDuties(ctx context.Context) []phase0.Epoch { - now := m.beacon.Wallclock().Epochs().Current() +func (m *DutiesService) RequiredEpochDuties() []phase0.Epoch { + now := m.metadata.Wallclock().Epochs().Current() epochNumber := now.Number() epochs := []phase0.Epoch{ + phase0.Epoch(epochNumber - 3), + phase0.Epoch(epochNumber - 2), + phase0.Epoch(epochNumber - 1), phase0.Epoch(epochNumber), phase0.Epoch(epochNumber + 1), } - // Lodestar does not support fetching beacon committees for older epochs. - if m.metadata.Client(ctx) != string(ClientLodestar) { - epochs = append(epochs, - phase0.Epoch(epochNumber-1), - phase0.Epoch(epochNumber-2), - phase0.Epoch(epochNumber-3), - ) - } - final := map[phase0.Epoch]struct{}{} // Deduplicate in case the current epoch is below epoch 3. @@ -139,7 +133,7 @@ func (m *DutiesService) RequiredEpochDuties(ctx context.Context) []phase0.Epoch } func (m *DutiesService) Ready(ctx context.Context) error { - for _, epoch := range m.RequiredEpochDuties(ctx) { + for _, epoch := range m.RequiredEpochDuties() { if duties := m.beaconCommittees.Get(epoch); duties == nil { return fmt.Errorf("duties for epoch %d are not ready", epoch) } @@ -153,7 +147,7 @@ func (m *DutiesService) backFillEpochDuties(ctx context.Context) error { return fmt.Errorf("metadata service is not ready") } - for _, epoch := range m.RequiredEpochDuties(ctx) { + for _, epoch := range m.RequiredEpochDuties() { if duties := m.beaconCommittees.Get(epoch); duties == nil { if err := m.fetchBeaconCommittee(ctx, epoch); err != nil { return err From d3f2464dbcb163721bdd0d9c7fde450aa6595604 Mon Sep 17 00:00:00 2001 From: Sam Calder-Mason Date: Thu, 20 Jul 2023 14:02:07 +1000 Subject: [PATCH 2/2] Fix bad merge --- pkg/sentry/ethereum/services/duties.go | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/pkg/sentry/ethereum/services/duties.go b/pkg/sentry/ethereum/services/duties.go index c0a91952..3bc1093c 100644 --- a/pkg/sentry/ethereum/services/duties.go +++ b/pkg/sentry/ethereum/services/duties.go @@ -104,19 +104,25 @@ func (m *DutiesService) Name() Name { return "duties" } -func (m *DutiesService) RequiredEpochDuties() []phase0.Epoch { +func (m *DutiesService) RequiredEpochDuties(ctx context.Context) []phase0.Epoch { now := m.metadata.Wallclock().Epochs().Current() epochNumber := now.Number() epochs := []phase0.Epoch{ - phase0.Epoch(epochNumber - 3), - phase0.Epoch(epochNumber - 2), - phase0.Epoch(epochNumber - 1), phase0.Epoch(epochNumber), phase0.Epoch(epochNumber + 1), } + // Lodestar does not support fetching beacon committees for older epochs. + if m.metadata.Client(ctx) != string(ClientLodestar) { + epochs = append(epochs, + phase0.Epoch(epochNumber-1), + phase0.Epoch(epochNumber-2), + phase0.Epoch(epochNumber-3), + ) + } + final := map[phase0.Epoch]struct{}{} // Deduplicate in case the current epoch is below epoch 3. @@ -133,7 +139,7 @@ func (m *DutiesService) RequiredEpochDuties() []phase0.Epoch { } func (m *DutiesService) Ready(ctx context.Context) error { - for _, epoch := range m.RequiredEpochDuties() { + for _, epoch := range m.RequiredEpochDuties(ctx) { if duties := m.beaconCommittees.Get(epoch); duties == nil { return fmt.Errorf("duties for epoch %d are not ready", epoch) } @@ -147,7 +153,7 @@ func (m *DutiesService) backFillEpochDuties(ctx context.Context) error { return fmt.Errorf("metadata service is not ready") } - for _, epoch := range m.RequiredEpochDuties() { + for _, epoch := range m.RequiredEpochDuties(ctx) { if duties := m.beaconCommittees.Get(epoch); duties == nil { if err := m.fetchBeaconCommittee(ctx, epoch); err != nil { return err