Skip to content

Commit

Permalink
fix(cannon): Shift around where activation epoch is stored (#422)
Browse files Browse the repository at this point in the history
* fix(cannon): Shift around where activation epoch is stored

* feat: Add function to create epoch defaults from fork epochs

* docs: Remove unused epoch defaults iterator function

* fix: Correct error handling in backfilling_checkpoint_iterator

* style: Use strings.ToUpper for activation fork name

* fix: Handle phase0

* refactor: Update variable name for clarity
  • Loading branch information
samcm authored Dec 6, 2024
1 parent 33d6e01 commit 1b0fb17
Show file tree
Hide file tree
Showing 16 changed files with 39 additions and 79 deletions.
2 changes: 1 addition & 1 deletion pkg/cannon/deriver/beacon/eth/v1/beacon_blob.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ func (b *BeaconBlobDeriver) Start(ctx context.Context) error {

b.log.Info("Beacon blob deriver enabled")

if err := b.iterator.Start(ctx); err != nil {
if err := b.iterator.Start(ctx, b.ActivationFork()); err != nil {
return errors.Wrap(err, "failed to start iterator")
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/cannon/deriver/beacon/eth/v1/beacon_committee.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ func (b *BeaconCommitteeDeriver) Start(ctx context.Context) error {

b.log.Info("Beacon committee deriver enabled")

if err := b.iterator.Start(ctx); err != nil {
if err := b.iterator.Start(ctx, b.ActivationFork()); err != nil {
return errors.Wrap(err, "failed to start iterator")
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/cannon/deriver/beacon/eth/v1/beacon_validators.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ func (b *BeaconValidatorsDeriver) Start(ctx context.Context) error {

b.log.Info("Validator states deriver enabled")

if err := b.iterator.Start(ctx); err != nil {
if err := b.iterator.Start(ctx, b.ActivationFork()); err != nil {
return errors.Wrap(err, "failed to start iterator")
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/cannon/deriver/beacon/eth/v1/proposer_duty.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ func (b *ProposerDutyDeriver) Start(ctx context.Context) error {

b.log.Info("Proposer duty deriver enabled")

if err := b.iterator.Start(ctx); err != nil {
if err := b.iterator.Start(ctx, b.ActivationFork()); err != nil {
return errors.Wrap(err, "failed to start iterator")
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/cannon/deriver/beacon/eth/v2/attester_slashing.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ func (a *AttesterSlashingDeriver) Start(ctx context.Context) error {

a.log.Info("Attester slashing deriver enabled")

if err := a.iterator.Start(ctx); err != nil {
if err := a.iterator.Start(ctx, a.ActivationFork()); err != nil {
return errors.Wrap(err, "failed to start iterator")
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/cannon/deriver/beacon/eth/v2/beacon_block.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ func (b *BeaconBlockDeriver) Start(ctx context.Context) error {

b.log.Info("Beacon block deriver enabled")

if err := b.iterator.Start(ctx); err != nil {
if err := b.iterator.Start(ctx, b.ActivationFork()); err != nil {
return errors.Wrap(err, "failed to start iterator")
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ func (b *BLSToExecutionChangeDeriver) Start(ctx context.Context) error {

b.log.Info("BLS to execution change deriver enabled")

if err := b.iterator.Start(ctx); err != nil {
if err := b.iterator.Start(ctx, b.ActivationFork()); err != nil {
return errors.Wrap(err, "failed to start iterator")
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/cannon/deriver/beacon/eth/v2/deposit.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ func (b *DepositDeriver) Start(ctx context.Context) error {

b.log.Info("Deposit deriver enabled")

if err := b.iterator.Start(ctx); err != nil {
if err := b.iterator.Start(ctx, b.ActivationFork()); err != nil {
return errors.Wrap(err, "failed to start iterator")
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/cannon/deriver/beacon/eth/v2/elaborated_attestation.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ func (b *ElaboratedAttestationDeriver) Start(ctx context.Context) error {

b.log.Info("Elaborated attestation deriver enabled")

if err := b.iterator.Start(ctx); err != nil {
if err := b.iterator.Start(ctx, b.ActivationFork()); err != nil {
return errors.Wrap(err, "failed to start iterator")
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/cannon/deriver/beacon/eth/v2/execution_transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ func (b *ExecutionTransactionDeriver) Start(ctx context.Context) error {

b.log.Info("Execution transaction deriver enabled")

if err := b.iterator.Start(ctx); err != nil {
if err := b.iterator.Start(ctx, b.ActivationFork()); err != nil {
return errors.Wrap(err, "failed to start iterator")
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/cannon/deriver/beacon/eth/v2/proposer_slashing.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ func (b *ProposerSlashingDeriver) Start(ctx context.Context) error {

b.log.Info("Proposer slashing deriver enabled")

if err := b.iterator.Start(ctx); err != nil {
if err := b.iterator.Start(ctx, b.ActivationFork()); err != nil {
return errors.Wrap(err, "failed to start iterator")
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/cannon/deriver/beacon/eth/v2/voluntary_exit.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ func (b *VoluntaryExitDeriver) Start(ctx context.Context) error {

b.log.Info("Voluntary exit deriver enabled")

if err := b.iterator.Start(ctx); err != nil {
if err := b.iterator.Start(ctx, b.ActivationFork()); err != nil {
return errors.Wrap(err, "failed to start iterator")
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/cannon/deriver/beacon/eth/v2/withdrawal.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ func (b *WithdrawalDeriver) Start(ctx context.Context) error {

b.log.Info("Withdrawal deriver enabled")

if err := b.iterator.Start(ctx); err != nil {
if err := b.iterator.Start(ctx, b.ActivationFork()); err != nil {
return errors.Wrap(err, "failed to start iterator")
}

Expand Down
31 changes: 26 additions & 5 deletions pkg/cannon/iterator/backfilling_checkpoint_iterator.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ package iterator

import (
"context"
"fmt"
"time"

"github.com/attestantio/go-eth2-client/spec"
"github.com/attestantio/go-eth2-client/spec/phase0"
"github.com/ethpandaops/ethwallclock"
"github.com/ethpandaops/xatu/pkg/cannon/coordinator"
Expand All @@ -28,6 +30,7 @@ type BackfillingCheckpoint struct {
checkpointName string
lookAheadDistance int
config *BackfillingCheckpointConfig
activationFork spec.DataVersion
}

type BackfillingCheckpointDirection string
Expand Down Expand Up @@ -72,7 +75,9 @@ func NewBackfillingCheckpoint(
}
}

func (c *BackfillingCheckpoint) Start(ctx context.Context) error {
func (c *BackfillingCheckpoint) Start(ctx context.Context, activationFork spec.DataVersion) error {
c.activationFork = activationFork

// Check the backfill epoch is ok
if c.shouldBackfill(ctx) {
epoch, err := c.getEarliestPossibleBackfillEpoch()
Expand Down Expand Up @@ -210,9 +215,18 @@ func (c *BackfillingCheckpoint) Next(ctx context.Context) (rsp *BackFillingCheck
}
}

forkEpochForType := GetStartingEpochLocation(c.beaconNode.Metadata().Spec.ForkEpochs, c.cannonType)
targetEpoch := phase0.Epoch(0)

if c.activationFork != spec.DataVersionPhase0 {
forkEpoch, errr := c.beaconNode.Metadata().Spec.ForkEpochs.GetByName(c.activationFork.String())
if errr != nil {
return nil, errors.Wrap(errr, fmt.Sprintf("failed to get epoch for fork: %s", c.activationFork))
}

targetEpoch = forkEpoch.Epoch
}

if checkpoint.Epoch < forkEpochForType {
if checkpoint.Epoch < targetEpoch {
// The current finalized checkpoint is before the activation of this cannon, so we should sleep until the next epoch.
epoch := c.wallclock.Epochs().Current()

Expand Down Expand Up @@ -427,11 +441,18 @@ func (c *BackfillingCheckpoint) GetMarker(location *xatu.CannonLocation) (*xatu.
func (c *BackfillingCheckpoint) getEarliestPossibleBackfillEpoch() (phase0.Epoch, error) {
// earliestEpochForType is the earliest epoch for the type based on the fork epochs.
// For example, the blob_sidecar cannon type will have an earliest epoch of the DENEB fork.
earliestEpochForType := GetStartingEpochLocation(c.beaconNode.Metadata().Spec.ForkEpochs, c.cannonType)
if c.activationFork == spec.DataVersionPhase0 {
return 0, nil
}

forkEpoch, err := c.beaconNode.Metadata().Spec.ForkEpochs.GetByName(c.activationFork.String())
if err != nil {
return 0, errors.Wrap(err, "failed to get fork epoch")
}

if c.config.Backfill.ToEpoch == 0 {
// Use the default starting epoch for the type.
return earliestEpochForType, nil
return forkEpoch.Epoch, nil
}

return c.config.Backfill.ToEpoch, nil
Expand Down
24 changes: 0 additions & 24 deletions pkg/cannon/iterator/iterator.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,8 @@ package iterator

import (
"errors"

"github.com/attestantio/go-eth2-client/spec/phase0"
"github.com/ethpandaops/beacon/pkg/beacon/state"
"github.com/ethpandaops/xatu/pkg/proto/xatu"
)

var (
ErrLocationUpToDate = errors.New("location up to date")

SlotZero = phase0.Slot(0)
)

func GetDefaultSlotLocation(forkEpochs state.ForkEpochs, cannonType xatu.CannonType) phase0.Slot {
defaults := NewSlotDefaultsFromForkEpochs(forkEpochs)
if slot, exists := defaults[cannonType]; exists {
return slot
}

return SlotZero
}

func GetStartingEpochLocation(forkEpochs state.ForkEpochs, cannonType xatu.CannonType) phase0.Epoch {
defaults := NewSlotDefaultsFromForkEpochs(forkEpochs)
if slot, exists := defaults[cannonType]; exists {
return phase0.Epoch(slot / 32)
}

return 0
}
37 changes: 0 additions & 37 deletions pkg/cannon/iterator/slot_defaults.go

This file was deleted.

0 comments on commit 1b0fb17

Please sign in to comment.