From e762af398582e43c664d837eb72d801062ca59e0 Mon Sep 17 00:00:00 2001 From: Sam Calder-Mason Date: Thu, 28 Nov 2024 16:26:51 +1000 Subject: [PATCH] refactor: Simplify fetching current epoch in download functions --- pkg/beacon/download.go | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/pkg/beacon/download.go b/pkg/beacon/download.go index b4cc8d01..5aa8189d 100644 --- a/pkg/beacon/download.go +++ b/pkg/beacon/download.go @@ -28,10 +28,7 @@ func (d *Default) downloadServingCheckpoint(ctx context.Context, checkpoint *v1. return fmt.Errorf("failed to fetch spec: %w", err) } - fork, err := sp.ForkEpochs.CurrentFork( - phase0.Slot(uint64(checkpoint.Finalized.Epoch)*uint64(sp.SlotsPerEpoch)), - sp.SlotsPerEpoch, - ) + fork, err := sp.ForkEpochs.CurrentFork(checkpoint.Finalized.Epoch) if err != nil { return fmt.Errorf("failed to get current fork: %w", err) } @@ -332,9 +329,14 @@ func (d *Default) fetchBundle(ctx context.Context, root phase0.Root, upstream *N } } - if slot != phase0.Slot(0) { - epoch := phase0.Epoch(slot / d.spec.SlotsPerEpoch) + sp, err := d.Spec() + if err != nil { + return nil, fmt.Errorf("failed to fetch spec: %w", err) + } + + epoch := phase0.Epoch(slot / sp.SlotsPerEpoch) + if slot != phase0.Slot(0) { // Download and store deposit snapshots if err = d.downloadAndStoreDepositSnapshot(ctx, epoch, upstream); err != nil { d.log.WithError(err). @@ -342,14 +344,9 @@ func (d *Default) fetchBundle(ctx context.Context, root phase0.Root, upstream *N } } - sp, err := d.Spec() - if err != nil { - return nil, fmt.Errorf("failed to fetch spec: %w", err) - } - denebFork, err := sp.ForkEpochs.GetByName("DENEB") if err == nil && denebFork != nil { - if denebFork.Active(slot, sp.SlotsPerEpoch) { + if denebFork.Active(epoch) { // Download and store blob sidecars if err := d.downloadAndStoreBlobSidecars(ctx, slot, upstream); err != nil { return nil, fmt.Errorf("failed to download and store blob sidecars: %w", err)