From c17d72d51fc6af693b874894ed7fc0a9373625f3 Mon Sep 17 00:00:00 2001 From: Sam Calder-Mason Date: Tue, 20 Feb 2024 13:17:28 +1000 Subject: [PATCH] fix: Panic on unhealthy node without an initialized wallclock --- pkg/beacon/default.go | 25 ++++++------------------- pkg/beacon/download.go | 6 +++++- pkg/beacon/nodes.go | 3 ++- 3 files changed, 13 insertions(+), 21 deletions(-) diff --git a/pkg/beacon/default.go b/pkg/beacon/default.go index 41e96ea7..05b3b057 100644 --- a/pkg/beacon/default.go +++ b/pkg/beacon/default.go @@ -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), @@ -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 { diff --git a/pkg/beacon/download.go b/pkg/beacon/download.go index d4af983c..1224f084 100644 --- a/pkg/beacon/download.go +++ b/pkg/beacon/download.go @@ -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) @@ -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 diff --git a/pkg/beacon/nodes.go b/pkg/beacon/nodes.go index 496c1fdb..a98e0a15 100644 --- a/pkg/beacon/nodes.go +++ b/pkg/beacon/nodes.go @@ -4,6 +4,7 @@ import ( "context" "errors" "math/rand" + "strings" "time" v1 "github.com/attestantio/go-eth2-client/api/v1" @@ -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, }