Skip to content

Commit

Permalink
refactor: Simplify fetching current epoch in download functions
Browse files Browse the repository at this point in the history
  • Loading branch information
samcm committed Nov 28, 2024
1 parent e1f5901 commit e762af3
Showing 1 changed file with 9 additions and 12 deletions.
21 changes: 9 additions & 12 deletions pkg/beacon/download.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down Expand Up @@ -332,24 +329,24 @@ 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).
Warn("failed to download and store deposit snapshot")
}
}

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)
Expand Down

0 comments on commit e762af3

Please sign in to comment.