Skip to content

Commit

Permalink
Merge pull request #96 from ethpandaops/feat/delay-block
Browse files Browse the repository at this point in the history
feat(sentry): delay block lookup
  • Loading branch information
Savid authored Mar 7, 2023
2 parents e6753f6 + 52d79ef commit a5d4c0b
Showing 1 changed file with 25 additions and 15 deletions.
40 changes: 25 additions & 15 deletions pkg/sentry/sentry.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,26 +140,36 @@ func (s *Sentry) Start(ctx context.Context) error {
return err
}

beaconBlock, err := s.beacon.Node().FetchBlock(ctx, xatuethv1.RootAsString(block.Block))
if err != nil {
s.log.WithError(err).Error("Failed to fetch block")
} else {
beaconBlockMeta, err := s.createNewClientMeta(ctx)
go func() {
// some clients require a small delay before being able to fetch the block
time.Sleep(1 * time.Second)
beaconBlock, err := s.beacon.Node().FetchBlock(ctx, xatuethv1.RootAsString(block.Block))
if err != nil {
return err
}
s.log.WithError(err).Error("Failed to fetch block")
} else {
beaconBlockMeta, err := s.createNewClientMeta(ctx)
if err != nil {
s.log.WithError(err).Error("Failed to create client meta")

event := v2.NewBeaconBlock(s.log, beaconBlock, now, s.beacon, s.duplicateCache.BeaconETHV2BeaconBlock, beaconBlockMeta)
return
}

decoratedEvent, err := event.Decorate(ctx)
if err != nil {
return err
}
event := v2.NewBeaconBlock(s.log, beaconBlock, now, s.beacon, s.duplicateCache.BeaconETHV2BeaconBlock, beaconBlockMeta)

if err := s.handleNewDecoratedEvent(ctx, decoratedEvent); err != nil {
return err
decoratedEvent, err := event.Decorate(ctx)
if err != nil {
s.log.WithError(err).Error("Failed to decorate event")

return
}

if err := s.handleNewDecoratedEvent(ctx, decoratedEvent); err != nil {
s.log.WithError(err).Error("Failed to handle new decorated event")

return
}
}
}
}()

return nil
})
Expand Down

0 comments on commit a5d4c0b

Please sign in to comment.