Skip to content

Commit

Permalink
feat(sentry): wait for beacon node to sync
Browse files Browse the repository at this point in the history
  • Loading branch information
Savid committed Nov 16, 2022
1 parent 939c49e commit 90eb128
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
14 changes: 14 additions & 0 deletions pkg/sentry/ethereum/beacon.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,20 @@ func (b *BeaconNode) checkForReadyPublish(ctx context.Context) error {
return errors.Wrap(err, "metadata service is not ready")
}

status := b.beacon.GetStatus(ctx)
if status == nil {
return errors.New("failed to get beacon node status")
}

syncState := status.SyncState()
if syncState == nil {
return errors.New("missing beacon node status sync state")
}

if syncState.IsSyncing {
return errors.New("beacon node is syncing")
}

for _, callback := range b.onReadyCallbacks {
if err := callback(ctx); err != nil {
b.log.WithError(err).Error("failed to run on ready callback")
Expand Down
10 changes: 10 additions & 0 deletions pkg/sentry/sentry.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,16 @@ func (s *Sentry) syncClockDrift(ctx context.Context) error {
}

func (s *Sentry) handleNewDecoratedEvent(ctx context.Context, event *xatu.DecoratedEvent) error {
status := s.beacon.Node().GetStatus(ctx)
if status == nil {
return nil
}

syncState := status.SyncState()
if syncState == nil || syncState.IsSyncing {
return nil
}

for _, sink := range s.sinks {
if err := sink.HandleNewDecoratedEvent(ctx, event); err != nil {
s.log.WithError(err).WithField("sink", sink.Type()).Error("Failed to send event to sink")
Expand Down

0 comments on commit 90eb128

Please sign in to comment.