Skip to content

Commit

Permalink
fix: Panic on unhealthy node without an initialized wallclock
Browse files Browse the repository at this point in the history
  • Loading branch information
samcm committed Feb 20, 2024
1 parent 3f4b04d commit c17d72d
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 21 deletions.
25 changes: 6 additions & 19 deletions pkg/beacon/default.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,32 +112,19 @@ func (d *Default) Start(ctx context.Context) error {
d.log.WithError(err).Fatal("Failed to start crons")
}

// Check for new serving checkpoints after each epoch
node, err := d.nodes.Healthy(ctx).NotSyncing(ctx).RandomNode(ctx)
if err != nil {
d.log.WithError(err).Fatal("Failed to get a healthy, non-syncing node to subscribe to wallclock events")
}

node.Beacon.Wallclock().OnEpochChanged(func(epoch ethwallclock.Epoch) {
// Sleep for a bit to allow the beacon nodes to run their epoch transition.
time.Sleep(time.Second * 30)

if err := d.checkForNewServingCheckpoint(ctx); err != nil {
d.log.WithError(err).Error("Failed to check for new serving checkpoint after epoch change")
}
})

break
}
}()

// Subscribe to the nodes' finality updates.
for _, node := range d.nodes {
n := node

logCtx := d.log.WithFields(logrus.Fields{
"node": node.Config.Name,
"node": n.Config.Name,
})

node.Beacon.OnFinalityCheckpointUpdated(ctx, func(ctx context.Context, event *beacon.FinalityCheckpointUpdated) error {
n.Beacon.OnFinalityCheckpointUpdated(ctx, func(ctx context.Context, event *beacon.FinalityCheckpointUpdated) error {
logCtx.WithFields(logrus.Fields{
"epoch": event.Finality.Finalized.Epoch,
"root": fmt.Sprintf("%#x", event.Finality.Finalized.Root),
Expand All @@ -153,8 +140,8 @@ func (d *Default) Start(ctx context.Context) error {
return d.checkForNewServingCheckpoint(ctx)
})

node.Beacon.OnReady(ctx, func(ctx context.Context, _ *beacon.ReadyEvent) error {
node.Beacon.Wallclock().OnEpochChanged(func(epoch ethwallclock.Epoch) {
n.Beacon.OnReady(ctx, func(ctx context.Context, _ *beacon.ReadyEvent) error {
n.Beacon.Wallclock().OnEpochChanged(func(epoch ethwallclock.Epoch) {
time.Sleep(time.Second * 5)

if _, err := node.Beacon.FetchFinality(ctx, "head"); err != nil {
Expand Down
6 changes: 5 additions & 1 deletion pkg/beacon/download.go
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,7 @@ func (d *Default) downloadBlock(ctx context.Context, slot phase0.Slot, upstream
"slot": slot,
"root": eth.RootAsString(root),
"state_root": eth.RootAsString(stateRoot),
"node": upstream.Config.Name,
}).
Infof("Downloaded and stored block for slot %d", slot)

Expand Down Expand Up @@ -377,7 +378,10 @@ func (d *Default) downloadAndStoreDepositSnapshot(ctx context.Context, epoch pha
}

d.log.
WithFields(logrus.Fields{"epoch": epoch}).
WithFields(logrus.Fields{
"epoch": epoch,
"node": node.Config.Name,
}).
Infof("Downloaded and stored deposit snapshot for epoch %d", epoch)

return nil
Expand Down
3 changes: 2 additions & 1 deletion pkg/beacon/nodes.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"errors"
"math/rand"
"strings"
"time"

v1 "github.com/attestantio/go-eth2-client/api/v1"
Expand All @@ -25,7 +26,7 @@ func NewNodesFromConfig(log logrus.FieldLogger, configs []node.Config, namespace
for i, config := range configs {
sconfig := &sbeacon.Config{
Name: config.Name,
Addr: config.Address,
Addr: strings.TrimRight(config.Address, "/"),
Headers: config.Headers,
}

Expand Down

0 comments on commit c17d72d

Please sign in to comment.