From e699fb022c94c23068ef6797fcf80852ab8584fa Mon Sep 17 00:00:00 2001 From: Sam Calder-Mason Date: Wed, 27 Sep 2023 13:59:06 +1000 Subject: [PATCH] fix(cannon): Correct slot calculations (#210) * refactor(checkpoint_iterator): simplify getLookAheads loop * fix(cannon): Correct slot calculations * refactor(beacon_block): Remove debug log statement --- pkg/cannon/deriver/beacon/eth/v2/attester_slashing.go | 4 ++-- pkg/cannon/deriver/beacon/eth/v2/beacon_block.go | 4 ++-- pkg/cannon/deriver/beacon/eth/v2/bls_to_execution_change.go | 4 ++-- pkg/cannon/deriver/beacon/eth/v2/deposit.go | 4 ++-- pkg/cannon/deriver/beacon/eth/v2/execution_transaction.go | 4 ++-- pkg/cannon/deriver/beacon/eth/v2/proposer_slashing.go | 4 ++-- pkg/cannon/deriver/beacon/eth/v2/voluntary_exit.go | 4 ++-- pkg/cannon/deriver/beacon/eth/v2/withdrawal.go | 4 ++-- 8 files changed, 16 insertions(+), 16 deletions(-) diff --git a/pkg/cannon/deriver/beacon/eth/v2/attester_slashing.go b/pkg/cannon/deriver/beacon/eth/v2/attester_slashing.go index c54c6613..1b126575 100644 --- a/pkg/cannon/deriver/beacon/eth/v2/attester_slashing.go +++ b/pkg/cannon/deriver/beacon/eth/v2/attester_slashing.go @@ -164,7 +164,7 @@ func (a *AttesterSlashingDeriver) lookAheadAtLocations(ctx context.Context, loca return } - for i := uint64(0); i <= uint64(sp.SlotsPerEpoch); i++ { + for i := uint64(0); i <= uint64(sp.SlotsPerEpoch-1); i++ { slot := phase0.Slot(i + uint64(epoch)*uint64(sp.SlotsPerEpoch)) // Add the block to the preload queue so it's available when we need it @@ -181,7 +181,7 @@ func (a *AttesterSlashingDeriver) processEpoch(ctx context.Context, epoch phase0 allEvents := []*xatu.DecoratedEvent{} - for i := uint64(0); i <= uint64(sp.SlotsPerEpoch); i++ { + for i := uint64(0); i <= uint64(sp.SlotsPerEpoch-1); i++ { slot := phase0.Slot(i + uint64(epoch)*uint64(sp.SlotsPerEpoch)) events, err := a.processSlot(ctx, slot) diff --git a/pkg/cannon/deriver/beacon/eth/v2/beacon_block.go b/pkg/cannon/deriver/beacon/eth/v2/beacon_block.go index 544c75d9..71e722c7 100644 --- a/pkg/cannon/deriver/beacon/eth/v2/beacon_block.go +++ b/pkg/cannon/deriver/beacon/eth/v2/beacon_block.go @@ -167,7 +167,7 @@ func (b *BeaconBlockDeriver) lookAheadAtLocation(ctx context.Context, locations return } - for i := uint64(0); i <= uint64(sp.SlotsPerEpoch); i++ { + for i := uint64(0); i <= uint64(sp.SlotsPerEpoch-1); i++ { slot := phase0.Slot(i + uint64(epoch)*uint64(sp.SlotsPerEpoch)) // Add the block to the preload queue so it's available when we need it @@ -184,7 +184,7 @@ func (b *BeaconBlockDeriver) processEpoch(ctx context.Context, epoch phase0.Epoc allEvents := []*xatu.DecoratedEvent{} - for i := uint64(0); i <= uint64(sp.SlotsPerEpoch); i++ { + for i := uint64(0); i <= uint64(sp.SlotsPerEpoch-1); i++ { slot := phase0.Slot(i + uint64(epoch)*uint64(sp.SlotsPerEpoch)) events, err := b.processSlot(ctx, slot) diff --git a/pkg/cannon/deriver/beacon/eth/v2/bls_to_execution_change.go b/pkg/cannon/deriver/beacon/eth/v2/bls_to_execution_change.go index 22ae68c2..677ba471 100644 --- a/pkg/cannon/deriver/beacon/eth/v2/bls_to_execution_change.go +++ b/pkg/cannon/deriver/beacon/eth/v2/bls_to_execution_change.go @@ -167,7 +167,7 @@ func (b *BLSToExecutionChangeDeriver) lookAheadAtLocation(ctx context.Context, l return } - for i := uint64(0); i <= uint64(sp.SlotsPerEpoch); i++ { + for i := uint64(0); i <= uint64(sp.SlotsPerEpoch-1); i++ { slot := phase0.Slot(i + uint64(epoch)*uint64(sp.SlotsPerEpoch)) // Add the block to the preload queue so it's available when we need it @@ -184,7 +184,7 @@ func (b *BLSToExecutionChangeDeriver) processEpoch(ctx context.Context, epoch ph allEvents := []*xatu.DecoratedEvent{} - for i := uint64(0); i <= uint64(sp.SlotsPerEpoch); i++ { + for i := uint64(0); i <= uint64(sp.SlotsPerEpoch-1); i++ { slot := phase0.Slot(i + uint64(epoch)*uint64(sp.SlotsPerEpoch)) events, err := b.processSlot(ctx, slot) diff --git a/pkg/cannon/deriver/beacon/eth/v2/deposit.go b/pkg/cannon/deriver/beacon/eth/v2/deposit.go index d92451cf..bf1e7a13 100644 --- a/pkg/cannon/deriver/beacon/eth/v2/deposit.go +++ b/pkg/cannon/deriver/beacon/eth/v2/deposit.go @@ -165,7 +165,7 @@ func (b *DepositDeriver) lookAheadAtLocation(ctx context.Context, locations []*x return } - for i := uint64(0); i <= uint64(sp.SlotsPerEpoch); i++ { + for i := uint64(0); i <= uint64(sp.SlotsPerEpoch-1); i++ { slot := phase0.Slot(i + uint64(epoch)*uint64(sp.SlotsPerEpoch)) // Add the block to the preload queue so it's available when we need it @@ -182,7 +182,7 @@ func (b *DepositDeriver) processEpoch(ctx context.Context, epoch phase0.Epoch) ( allEvents := []*xatu.DecoratedEvent{} - for i := uint64(0); i <= uint64(sp.SlotsPerEpoch); i++ { + for i := uint64(0); i <= uint64(sp.SlotsPerEpoch-1); i++ { slot := phase0.Slot(i + uint64(epoch)*uint64(sp.SlotsPerEpoch)) events, err := b.processSlot(ctx, slot) diff --git a/pkg/cannon/deriver/beacon/eth/v2/execution_transaction.go b/pkg/cannon/deriver/beacon/eth/v2/execution_transaction.go index 4839309f..cdea1478 100644 --- a/pkg/cannon/deriver/beacon/eth/v2/execution_transaction.go +++ b/pkg/cannon/deriver/beacon/eth/v2/execution_transaction.go @@ -159,7 +159,7 @@ func (b *ExecutionTransactionDeriver) processEpoch(ctx context.Context, epoch ph allEvents := []*xatu.DecoratedEvent{} - for i := uint64(0); i <= uint64(sp.SlotsPerEpoch); i++ { + for i := uint64(0); i <= uint64(sp.SlotsPerEpoch-1); i++ { slot := phase0.Slot(i + uint64(epoch)*uint64(sp.SlotsPerEpoch)) events, err := b.processSlot(ctx, slot) @@ -186,7 +186,7 @@ func (b *ExecutionTransactionDeriver) lookAheadAtLocation(ctx context.Context, l return } - for i := uint64(0); i <= uint64(sp.SlotsPerEpoch); i++ { + for i := uint64(0); i <= uint64(sp.SlotsPerEpoch-1); i++ { slot := phase0.Slot(i + uint64(epoch)*uint64(sp.SlotsPerEpoch)) // Add the block to the preload queue so it's available when we need it diff --git a/pkg/cannon/deriver/beacon/eth/v2/proposer_slashing.go b/pkg/cannon/deriver/beacon/eth/v2/proposer_slashing.go index 9b0453cb..3bc1f92c 100644 --- a/pkg/cannon/deriver/beacon/eth/v2/proposer_slashing.go +++ b/pkg/cannon/deriver/beacon/eth/v2/proposer_slashing.go @@ -155,7 +155,7 @@ func (b *ProposerSlashingDeriver) processEpoch(ctx context.Context, epoch phase0 allEvents := []*xatu.DecoratedEvent{} - for i := uint64(0); i <= uint64(sp.SlotsPerEpoch); i++ { + for i := uint64(0); i <= uint64(sp.SlotsPerEpoch-1); i++ { slot := phase0.Slot(i + uint64(epoch)*uint64(sp.SlotsPerEpoch)) events, err := b.processSlot(ctx, slot) @@ -259,7 +259,7 @@ func (b *ProposerSlashingDeriver) lookAheadAtLocation(ctx context.Context, locat return } - for i := uint64(0); i <= uint64(sp.SlotsPerEpoch); i++ { + for i := uint64(0); i <= uint64(sp.SlotsPerEpoch-1); i++ { slot := phase0.Slot(i + uint64(epoch)*uint64(sp.SlotsPerEpoch)) // Add the block to the preload queue so it's available when we need it diff --git a/pkg/cannon/deriver/beacon/eth/v2/voluntary_exit.go b/pkg/cannon/deriver/beacon/eth/v2/voluntary_exit.go index 7b7ab072..b2bb1b67 100644 --- a/pkg/cannon/deriver/beacon/eth/v2/voluntary_exit.go +++ b/pkg/cannon/deriver/beacon/eth/v2/voluntary_exit.go @@ -165,7 +165,7 @@ func (b *VoluntaryExitDeriver) lookAheadAtLocation(ctx context.Context, location return } - for i := uint64(0); i <= uint64(sp.SlotsPerEpoch); i++ { + for i := uint64(0); i <= uint64(sp.SlotsPerEpoch-1); i++ { slot := phase0.Slot(i + uint64(epoch)*uint64(sp.SlotsPerEpoch)) // Add the block to the preload queue so it's available when we need it @@ -182,7 +182,7 @@ func (b *VoluntaryExitDeriver) processEpoch(ctx context.Context, epoch phase0.Ep allEvents := []*xatu.DecoratedEvent{} - for i := uint64(0); i <= uint64(sp.SlotsPerEpoch); i++ { + for i := uint64(0); i <= uint64(sp.SlotsPerEpoch-1); i++ { slot := phase0.Slot(i + uint64(epoch)*uint64(sp.SlotsPerEpoch)) events, err := b.processSlot(ctx, slot) diff --git a/pkg/cannon/deriver/beacon/eth/v2/withdrawal.go b/pkg/cannon/deriver/beacon/eth/v2/withdrawal.go index 3885b980..fbbbcdc2 100644 --- a/pkg/cannon/deriver/beacon/eth/v2/withdrawal.go +++ b/pkg/cannon/deriver/beacon/eth/v2/withdrawal.go @@ -152,7 +152,7 @@ func (b *WithdrawalDeriver) processEpoch(ctx context.Context, epoch phase0.Epoch allEvents := []*xatu.DecoratedEvent{} - for i := uint64(0); i <= uint64(sp.SlotsPerEpoch); i++ { + for i := uint64(0); i <= uint64(sp.SlotsPerEpoch-1); i++ { slot := phase0.Slot(i + uint64(epoch)*uint64(sp.SlotsPerEpoch)) events, err := b.processSlot(ctx, slot) @@ -218,7 +218,7 @@ func (b *WithdrawalDeriver) lookAheadAtLocation(ctx context.Context, locations [ return } - for i := uint64(0); i <= uint64(sp.SlotsPerEpoch); i++ { + for i := uint64(0); i <= uint64(sp.SlotsPerEpoch-1); i++ { slot := phase0.Slot(i + uint64(epoch)*uint64(sp.SlotsPerEpoch)) // Add the block to the preload queue so it's available when we need it