Skip to content

Commit

Permalink
Merge pull request #95 from ethpandaops/fix/inflight-wallclock-requests
Browse files Browse the repository at this point in the history
fix(sentry): handle inflight wallclock requests
  • Loading branch information
Savid authored Mar 6, 2023
2 parents eab06b8 + 9ee8b6e commit e6753f6
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
3 changes: 2 additions & 1 deletion pkg/sentry/ethereum/beacon.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package ethereum

import (
"context"
"fmt"
"time"

"github.com/ethpandaops/beacon/pkg/beacon"
Expand Down Expand Up @@ -100,7 +101,7 @@ func (b *BeaconNode) Synced(ctx context.Context) error {
currentSlot := wallclock.Slots().Current()

if currentSlot.Number()-uint64(syncState.HeadSlot) > 3 {
return errors.New("beacon node is too far behind head")
return fmt.Errorf("beacon node is too far behind head, head slot is %d, current slot is %d", syncState.HeadSlot, currentSlot.Number())
}

if !b.readyPublished {
Expand Down
21 changes: 12 additions & 9 deletions pkg/sentry/ethereum/metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,16 +100,19 @@ func (m *MetadataService) RefreshAll(ctx context.Context) error {
}

if m.Genesis != nil && m.Spec != nil {
m.mu.Lock()

if m.wallclock != nil {
m.wallclock.Stop()
m.wallclock = nil
if newWallclock := ethwallclock.NewEthereumBeaconChain(m.Genesis.GenesisTime, m.Spec.SecondsPerSlot.AsDuration(), uint64(m.Spec.SlotsPerEpoch)); newWallclock != nil {
m.mu.Lock()
if m.wallclock != nil {
// delay stopping the old wallclock to allow for any in-flight requests to complete
go func(oldWallclock *ethwallclock.EthereumBeaconChain) {
time.Sleep(1 * time.Minute)
oldWallclock.Stop()
}(m.wallclock)
}

m.wallclock = newWallclock
m.mu.Unlock()
}

m.wallclock = ethwallclock.NewEthereumBeaconChain(m.Genesis.GenesisTime, m.Spec.SecondsPerSlot.AsDuration(), uint64(m.Spec.SlotsPerEpoch))

m.mu.Unlock()
}

if err := m.DeriveNetwork(ctx); err != nil {
Expand Down

0 comments on commit e6753f6

Please sign in to comment.