Skip to content

Commit

Permalink
fix(cannon): Check sync status before deriving events (#182)
Browse files Browse the repository at this point in the history
  • Loading branch information
samcm committed Sep 6, 2023
1 parent fd241f0 commit 2ceac41
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 5 deletions.
4 changes: 0 additions & 4 deletions pkg/cannon/cannon.go
Original file line number Diff line number Diff line change
Expand Up @@ -247,10 +247,6 @@ func (c *Cannon) syncClockDrift(ctx context.Context) error {
}

func (c *Cannon) handleNewDecoratedEvent(ctx context.Context, event *xatu.DecoratedEvent) error {
if err := c.beacon.Synced(ctx); err != nil {
return err
}

for _, sink := range c.sinks {
if err := sink.HandleNewDecoratedEvent(ctx, event); err != nil {
c.log.
Expand Down
4 changes: 4 additions & 0 deletions pkg/cannon/deriver/beacon/eth/v2/attester_slashing.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,10 @@ func (a *AttesterSlashingDeriver) run(ctx context.Context) {
operation := func() error {
time.Sleep(100 * time.Millisecond)

if err := a.beacon.Synced(ctx); err != nil {
return err
}

// Get the next slot
location, err := a.iterator.Next(ctx)
if err != nil {
Expand Down
4 changes: 4 additions & 0 deletions pkg/cannon/deriver/beacon/eth/v2/bls_to_execution_change.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,10 @@ func (b *BLSToExecutionChangeDeriver) run(ctx context.Context) {
operation := func() error {
time.Sleep(100 * time.Millisecond)

if err := b.beacon.Synced(ctx); err != nil {
return err
}

// Get the next slot
location, err := b.iterator.Next(ctx)
if err != nil {
Expand Down
4 changes: 4 additions & 0 deletions pkg/cannon/deriver/beacon/eth/v2/deposit.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,10 @@ func (b *DepositDeriver) run(ctx context.Context) {
operation := func() error {
time.Sleep(100 * time.Millisecond)

if err := b.beacon.Synced(ctx); err != nil {
return err
}

// Get the next slot
location, err := b.iterator.Next(ctx)
if err != nil {
Expand Down
4 changes: 4 additions & 0 deletions pkg/cannon/deriver/beacon/eth/v2/execution_transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,10 @@ func (b *ExecutionTransactionDeriver) run(ctx context.Context) {
operation := func() error {
time.Sleep(100 * time.Millisecond)

if err := b.beacon.Synced(ctx); err != nil {
return err
}

// Get the next slot
location, err := b.iterator.Next(ctx)
if err != nil {
Expand Down
4 changes: 4 additions & 0 deletions pkg/cannon/deriver/beacon/eth/v2/proposer_slashing.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,10 @@ func (b *ProposerSlashingDeriver) run(ctx context.Context) {
operation := func() error {
time.Sleep(100 * time.Millisecond)

if err := b.beacon.Synced(ctx); err != nil {
return err
}

// Get the next slot
location, err := b.iterator.Next(ctx)
if err != nil {
Expand Down
4 changes: 4 additions & 0 deletions pkg/cannon/deriver/beacon/eth/v2/voluntary_exit.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,10 @@ func (b *VoluntaryExitDeriver) run(ctx context.Context) {
operation := func() error {
time.Sleep(100 * time.Millisecond)

if err := b.beacon.Synced(ctx); err != nil {
return err
}

// Get the next slot
location, err := b.iterator.Next(ctx)
if err != nil {
Expand Down
4 changes: 3 additions & 1 deletion pkg/cannon/ethereum/beacon.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,14 @@ type BeaconNode struct {
func NewBeaconNode(ctx context.Context, name string, config *Config, log logrus.FieldLogger) (*BeaconNode, error) {
opts := *beacon.
DefaultOptions().
EnableDefaultBeaconSubscription().
DisableEmptySlotDetection().
DisablePrometheusMetrics()

opts.HealthCheck.Interval.Duration = time.Second * 3
opts.HealthCheck.SuccessfulResponses = 1

opts.BeaconSubscription.Enabled = false

node := beacon.NewNode(log, &beacon.Config{
Name: name,
Addr: config.BeaconNodeAddress,
Expand Down

0 comments on commit 2ceac41

Please sign in to comment.